Class MolExporter

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    @PublicAPI
    public class MolExporter
    extends Object
    implements Closeable
    Molecule exporter class.

    The output file format can be specified as an argument to the constructor of this class. Many different output file formats are supported like "mol", "sdf", "smiles", "png", "jpeg", etc.

    By default, in case of machines with multiple processors processing is concurrent, otherwise single-threaded. By default, the number of worker threads is the number of processors - the number of concurrent threads can be set in setThreadCount(int). Experimental feature (may change in the future!): "chemaxon.struc.Molecule" format for testing Molecule serialization. In this case processing is single-threaded.

    • Method Detail

      • setThreadCount

        public void setThreadCount​(int threadCount)
                            throws IllegalStateException
        Sets the number of threads for concurrent processing. Default: the number of CPUs, single-threaded processing if there is 1 CPU.
        Parameters:
        threadCount - the number of threads, set 0 for the number of CPUs, 1 for single-threaded mode
        Throws:
        IllegalStateException - if called after call to write(chemaxon.struc.Molecule)
        Since:
        Marvin 5.3
      • setClean

        public void setClean​(int cleanDim,
                             String cleanOpts,
                             MolFilter cleanFilter)
                      throws IllegalStateException
        Sets molecule cleaning in exporter. Sets cleaning dimension and options. If processing is in concurrent mode, then cleaning is also performed concurrently.
        Parameters:
        cleanDim - the cleaning dimension
        cleanOpts - the cleaning options
        cleanFilter - the molecule filter to tell which molecule is to be cleaned, set FILTER_DIM0 to clean only 0D molecules null for no filtering (cleaning all)
        Throws:
        IllegalStateException - if called after call to write(chemaxon.struc.Molecule)
        Since:
        Marvin 5.3
        See Also:
        setThreadCount(int)
      • getFormat

        public String getFormat()
        Gets the output file format.
        Returns:
        the format
      • isCleanable

        public boolean isCleanable()
        Tests whether cleaning is meaningful for the chosen output format.
        Returns:
        true if cleaning is meaningful, false otherwise
        Since:
        Marvin 4.1, 02/12/2006
      • write

        public boolean write​(Molecule m)
                      throws MolExportException,
                             IOException
        Writes a molecule into the stream.
        Parameters:
        m - the molecule
        Returns:
        true on success, false if Molecule is not written due to a previous error in concurrent mode - in this case, call close() which will throw the error and close the exporter
        Throws:
        MolExportException - export error
        IOException
      • exportToObject

        public static Object exportToObject​(MDocument document,
                                            String fmt)
                                     throws IOException
        Creates a String, byte[] array or Image representation of the document. When creating an image, display options can also be specified in the format descriptor string. Format and options are separated by a colon, multiple options can be separated by commas. See the possible formats and their options on the File Formats in Marvin page. Examples:
         import java.awt.Image;
         ...
         String s1 = (String)MolExporter.exportToObject(document, "mol");
         String s2 = (String)MolExporter.exportToObject(document, "smiles:a-H"); // aromatize, remove H
         Image img = (Image)MolExporter.exportToObject(document, "image:w300,h300,#ffff00");
         byte[] d3 = (byte[])MolExporter.exportToObject(document, "png:w300,h300,b32,#00ffff00");
         byte[] d4 = (byte[])MolExporter.exportToObject(document, "jpeg:w300,h300,Q95,#ffff00,spacefill");
         
        Parameters:
        document - the document to export
        fmt - the format descriptor string
        Returns:
        a String, a byte[] array or an Image
        Throws:
        IOException - Export error.
        IllegalArgumentException - Invalid format string.
        SecurityException - Export module cannot be loaded because of security reasons (firewall).
        Since:
        Marvin 5.8, 08/25/2011
        See Also:
        exportToFormat(chemaxon.struc.MDocument, java.lang.String), exportToBinFormat(chemaxon.struc.MDocument, java.lang.String)
      • convertToString

        public static String convertToString​(MDocument document,
                                             String fmt,
                                             int flags)
                                      throws IOException
        Converts the document to text format.
        Parameters:
        document - the document to convert
        fmt - the molecule file format or null
        flags - conversion options
        Returns:
        the string
        Throws:
        IOException - Export error
        Since:
        Marvin 5.8, 08/25/2011
      • exportToBinFormat

        public static final byte[] exportToBinFormat​(MDocument document,
                                                     String fmt)
                                              throws IOException
        Creates a binary representation of the document. Works with all the text formats that are supported by the exportToFormat method, and also with the binary image formats (jpeg, msbmp, png). When creating an image, display options can also be specified in the format descriptor string. Format and options are separated by a colon, multiple options can be separated by commas. See the possible formats and their options on the File Formats in Marvin page. Examples:
         byte[] d1 = MolExporter.exportToBinFormat(document, "mrv");
         byte[] d2 = MolExporter.exportToBinFormat(document, "smiles:a-H"); // aromatize and remove H
         byte[] d3 = MolExporter.exportToBinFormat(document, "png:w300,h300,b32,#00ffff00");
         byte[] d4 = MolExporter.exportToBinFormat(document, "jpeg:w300,h300,Q95,#ffff00,spacefill");
         
        Parameters:
        document - the document to export
        fmt - the format descriptor string
        Returns:
        a binary representation of the document in the specified format
        Throws:
        IOException - Export error.
        IllegalArgumentException - Invalid format string.
        SecurityException - Export module cannot be loaded because of security reasons (firewall).
        Since:
        Marvin 5.8, 08/25/2011
        See Also:
        exportToFormat(chemaxon.struc.MDocument, java.lang.String), exportToObject(chemaxon.struc.MDocument, java.lang.String)
      • exportToFormat

        public static final String exportToFormat​(Molecule molecule,
                                                  String fmt)
                                           throws IOException
        Creates a string representation of the molecule. The format descriptor string can also contain export options. Format and options are separated by a colon, multiple options can be separated by commas. The line separator is '\n'. See the text formats and their options on the File Formats in Marvin page. Examples:
         s1 = MolExporter.exportToFormat(molecule, "mol");
         s2 = MolExporter.exportToFormat(molecule, "smiles:a-H"); // aromatize and remove Hydrogens
         
        Parameters:
        molecule - the molecule to export
        fmt - the format descriptor string
        Returns:
        string representation of the molecule in the specified format
        Throws:
        IOException - Export error.
        IllegalArgumentException - Invalid format string.
        SecurityException - Export module cannot be loaded because of security reasons (firewall).
        Since:
        Marvin 5.8, 08/25/2011
      • exportToBinFormat

        public static final byte[] exportToBinFormat​(Molecule molecule,
                                                     String fmt)
                                              throws IOException
        Creates a binary representation of the molecule. Works with all the text formats that are supported by the exportToFormat method, and also with the binary image formats (jpeg, msbmp, png). When creating an image, display options can also be specified in the format descriptor string. Format and options are separated by a colon, multiple options can be separated by commas. See the possible formats and their options on the File Formats in Marvin page. Examples:
         byte[] d1 = MolExporter.exportToBinFormat(molecule, "mol");
         byte[] d2 = MolExporter.exportToBinFormat(molecule, "smiles:a-H"); // aromatize and remove H
         byte[] d3 = MolExporter.exportToBinFormat(molecule, "png:w300,h300,b32,#00ffff00");
         byte[] d4 = MolExporter.exportToBinFormat(molecule, "jpeg:w300,h300,Q95,#ffff00,spacefill");
         
        Parameters:
        molecule - the molecule to export
        fmt - the format descriptor string
        Returns:
        a binary representation of the molecule in the specified format
        Throws:
        IOException - Export error.
        IllegalArgumentException - Invalid format string.
        SecurityException - Export module cannot be loaded because of security reasons (firewall).
        Since:
        Marvin 5.8, 08/25/2011
      • exportToObject

        public static Object exportToObject​(Molecule molecule,
                                            String fmt)
                                     throws IOException
        Creates a String, byte[] array or Image representation of the molecule. When creating an image, display options can also be specified in the format descriptor string. Format and options are separated by a colon, multiple options can be separated by commas. See the possible formats and their options on the File Formats in Marvin page. Examples:
         import java.awt.Image;
         ...
         String s1 = (String)MolExporter.exportToObject(molecule, "mol");
         String s2 = (String)MolExporter.exportToObject(molecule, "smiles:a-H"); // aromatize, remove H
         Image img = (Image)MolExporter.exportToObject(molecule, "image:w300,h300,#ffff00");
         byte[] d3 = (byte[])MolExporter.exportToObject(molecule, "png:w300,h300,b32,#00ffff00");
         byte[] d4 = (byte[])MolExporter.exportToObject(molecule, "jpeg:w300,h300,Q95,#ffff00,spacefill");
         
        Parameters:
        molecule - the molecule to export
        fmt - the format descriptor string
        Returns:
        a String, a byte[] array or an Image
        Throws:
        IOException - Export error.
        IllegalArgumentException - Invalid format string.
        SecurityException - Export module cannot be loaded because of security reasons (firewall).
        Since:
        Marvin 5.8, 08/25/2011