Class MolExporter
- All Implemented Interfaces:
- Closeable,- AutoCloseable
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.
 The processing is single-threaded by default. Concurrent mode can be enabled using setThreadCount(int).
 
Experimental feature (may change in the future!): "chemaxon.struc.Molecule" format for testing Molecule serialization. In this case, processing is always single-threaded, regardless of the configured thread count.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intClose the underlying stream.static final intFlush the output stream and force any buffered output bytes to be written out.static final MolFilterMolecule filter for cleaning0Dmolecules only.static final intUse this flag to produce multiple output files.static final intUse this flag to write text files with OS dependent line separators.
- 
Constructor SummaryConstructorsConstructorDescriptionMolExporter(OutputStream out, String fmtWithOpts) Creates a molecule exporter.MolExporter(OutputStream out, String fmtWithOpts, boolean text, String[] incFields) Creates a molecule exporter.MolExporter(OutputStream out, String fmtWithOpts, boolean text, String[] incFields, String enc) Creates a molecule exporter.MolExporter(OutputStream out, String fmtWithOpts, String enc) Creates a molecule exporter.MolExporter(String fname, String fmtWithOpts) Creates a molecule exporter.MolExporter(String fname, String fmtWithOpts, int outflags, String[] incFields, String enc) Creates a molecule exporter.
- 
Method SummaryModifier and TypeMethodDescriptionvoidclose()Closes theMolExportModuleand the underlying stream.voidclose(int opts) Closes theMolExportModuleand, optionally, the underlying stream.static StringconvertToString(MDocument document, String fmt, int flags) Converts the document to text format.static byte[]exportToBinFormat(MDocument document, String fmt) Creates a binary representation of the document.static byte[]exportToBinFormat(Molecule molecule, String fmt) Creates a binary representation of the molecule.static StringexportToFormat(MDocument document, String fmt) Creates a string representation of the document.static StringexportToFormat(Molecule molecule, String fmt) Creates a string representation of the molecule.static ObjectexportToObject(MDocument document, String fmt) Creates aString,byte[]orImagerepresentation of the document.static ObjectexportToObject(Molecule[] mols, String fmt, MolExportModule cv) Creates aString,byte[]orImagerepresentation of the given molecules.static ObjectexportToObject(Molecule molecule, String fmt) Creates aString,byte[]orImagerepresentation of the molecule.voidflush()Flushes the output stream and forces any buffered output bytes to be written out.Gets the output file format.booleanTests whether cleaning is meaningful for the chosen output format.voidSets molecule cleaning in exporter.voidSets molecule cleaning in exporter.voidsetErrorProcessor(ErrorProcessor errorProcessor) Sets the error handler interface for concurrent mode.voidsetThreadCount(int threadCount) Sets the number of threads for concurrent processing.static byte[]toBinFormat(Molecule molecule, String format) Returns a binary representation of the given molecule.static StringReturns a string representation of the given molecule.static ObjectReturns aString,byte[]orImagerepresentation of the given molecule.booleanWrites a molecule into the stream.
- 
Field Details- 
TEXTpublic static final int TEXTUse this flag to write text files with OS dependent line separators. If not specified, then LF ('\n') is used as in Unix.- Since:
- Marvin 5.2.2, 04/20/2009
- See Also:
 
- 
MULTIPLEpublic static final int MULTIPLEUse this flag to produce multiple output files.- Since:
- Marvin 5.2.2, 04/20/2009
- See Also:
 
- 
C_CLOSE_STREAMpublic static final int C_CLOSE_STREAMClose the underlying stream.- Since:
- Marvin 5.1.1, 08/17/2008
- See Also:
 
- 
C_FLUSH_STREAMpublic static final int C_FLUSH_STREAMFlush the output stream and force any buffered output bytes to be written out.- Since:
- Marvin 5.1.1, 08/17/2008
- See Also:
 
- 
FILTER_DIM0Molecule filter for cleaning0Dmolecules only.- See Also:
 
 
- 
- 
Constructor Details- 
MolExporterpublic MolExporter(String fname, String fmtWithOpts, int outflags, String[] incFields, String enc) throws IOException, IllegalArgumentException Creates a molecule exporter.- Parameters:
- fname- the output filename
- fmtWithOpts- the output file format and the options
- outflags- output flags, it can be a combination of- TEXTand- MULTIPLE
- incFields- SDF fields to include in table or null
- enc- charset name or null
- Throws:
- MolExportException- export error occurred
- IOException- output error occurred when writing the header
- IllegalArgumentException- Invalid format string (fmtWithOpts).
- IllegalCharsetNameException- if the encoding is illegal
- UnsupportedCharsetException- if the encoding is unsupported
- Since:
- Marvin 5.2.2, 04/20/2009
 
- 
MolExporterCreates a molecule exporter.- Parameters:
- fname- the output filename with extension
- fmtWithOpts- the output file format and the options
- Throws:
- MolExportException- export error occurred
- IOException- output error occurred when writing the header
- IllegalArgumentException- Invalid format string (fmtWithOpts).
- IllegalCharsetNameException- if the encoding is illegal
- UnsupportedCharsetException- if the encoding is unsupported
- Since:
- Marvin 5.4.1, 01/10/2010
 
- 
MolExporterpublic MolExporter(OutputStream out, String fmtWithOpts, boolean text, String[] incFields, String enc) throws IOException, IllegalArgumentException Creates a molecule exporter.- Parameters:
- out- the output stream
- fmtWithOpts- the output file format and the options
- text- write OS dependent line.separators instead of '\n'
- incFields- SDF fields to include in table or null
- enc- charset name or null
- Throws:
- MolExportException- export error occurred
- IOException- output error occurred when writing the header
- IllegalArgumentException- Invalid format string (fmtWithOpts).
- IllegalCharsetNameException- if the encoding is illegal
- UnsupportedCharsetException- if the encoding is unsupported
 
- 
MolExporterpublic MolExporter(OutputStream out, String fmtWithOpts) throws IOException, IllegalArgumentException Creates a molecule exporter.- Parameters:
- out- the output stream
- fmtWithOpts- the output file format and the options
- Throws:
- MolExportException- export error occurred
- IOException- output error occurred when writing the header
- IllegalArgumentException- Invalid format string (fmtWithOpts).
- IllegalCharsetNameException- if the encoding is illegal
- UnsupportedCharsetException- if the encoding is unsupported
 
- 
MolExporterpublic MolExporter(OutputStream out, String fmtWithOpts, boolean text, String[] incFields) throws IOException, IllegalArgumentException Creates a molecule exporter.- Parameters:
- out- the output stream
- fmtWithOpts- the output file format and the options
- text- write OS dependent line.separators instead of '\n'
- incFields- SDF fields to include in table or null
- Throws:
- MolExportException- export error occurred
- IOException- output error occurred when writing the header
- IllegalArgumentException- Invalid format string (fmtWithOpts).
- IllegalCharsetNameException- if the encoding is illegal
- UnsupportedCharsetException- if the encoding is unsupported
 
- 
MolExporterpublic MolExporter(OutputStream out, String fmtWithOpts, String enc) throws IOException, IllegalArgumentException Creates a molecule exporter.- Parameters:
- out- the output stream
- fmtWithOpts- the output file format and the options
- enc- charset name or null
- Throws:
- MolExportException- export error occurred
- IOException- output error occurred when writing the header
- IllegalArgumentException- Invalid format string (fmtWithOpts).
- IllegalCharsetNameException- if the encoding is illegal
- UnsupportedCharsetException- if the encoding is unsupported
 
 
- 
- 
Method Details- 
setThreadCountSets the number of threads for concurrent processing. The default value is 1 (single-threaded mode).In concurrent mode, multiple threads are started in the background, which adds a considerable overhead to the processing, so only use this mode if the number of molecules is huge. In single-threaded mode, no background thread is used, every action is done on the caller thread. - Parameters:
- threadCount- the number of threads, set- 0for the number of CPUs,- 1for single-threaded mode
- Throws:
- IllegalStateException- if called after call to- write(chemaxon.struc.Molecule)
- Since:
- Marvin 5.3
 
- 
setCleanSets 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
- Throws:
- IllegalStateException- if called after call to- write(chemaxon.struc.Molecule)
- Since:
- Marvin 5.3
- See Also:
 
- 
setCleanpublic 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_DIM0to clean only- 0Dmolecules- nullfor no filtering (cleaning all)
- Throws:
- IllegalStateException- if called after call to- write(chemaxon.struc.Molecule)
- Since:
- Marvin 5.3
- See Also:
 
- 
setErrorProcessorSets the error handler interface for concurrent mode. By default, export is stopped on first error and this error is thrown inclose()in concurrent mode. To change this, set specificErrorProcessorimplementation which can handle each error individually during the writing process and can decide whether to continue the export or not. If the export is stopped on an error then this error is always thrown inclose(). In single-threaded mode export errors are thrown inwrite(chemaxon.struc.Molecule), separately for each molecule.- Throws:
- IllegalStateException- if called after call to- write(chemaxon.struc.Molecule)
- Since:
- Marvin 5.3
- See Also:
 
- 
getFormatGets the output file format.- Returns:
- the format
 
- 
isCleanablepublic 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
 
- 
writeWrites a molecule into the stream.- Parameters:
- m- the molecule
- Returns:
- trueon success,- falseif 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
 
- 
closeCloses theMolExportModuleand the underlying stream. IMPORTANT: call this orclose(int)at the end, after the last call towrite(chemaxon.struc.Molecule), because this method flushes the output stream and closes concurrent processing properly.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Throws:
- MolExportException- on export error.
- IOException- in case of any other I/O error.
 
- 
closeCloses theMolExportModuleand, optionally, the underlying stream. IMPORTANT: call this orclose()at the end, after the last call towrite(chemaxon.struc.Molecule), because this method flushes the output stream and closes concurrent processing properly.- Parameters:
- opts- closing options,- C_CLOSE_STREAMor- C_FLUSH_STREAM.
- Throws:
- MolExportException- export error.
- IOException- in case of any other I/O error.
- Since:
- Marvin 5.1.1, 08/17/2008
 
- 
flushFlushes the output stream and forces any buffered output bytes to be written out.- Throws:
- MolExportException- on export error.
- IOException- if an I/O error occurs.
- Since:
- Marvin 5.1.1, 08/15/2008
 
- 
exportToObjectCreates aString,byte[]orImagerepresentation 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[] d1 = (byte[]) MolExporter.exportToObject(document, "png:w300,h300,b32,#00ffff00"); byte[] d2 = (byte[]) MolExporter.exportToObject(document, "jpeg:w300,h300,Q95,#ffff00,spacefill"); - Parameters:
- document- the document to export
- fmt- the format descriptor string
- Returns:
- a String,byte[]orImagerepresentation 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
- See Also:
 
- 
convertToStringConverts 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
 
- 
exportToFormatCreates a string representation of the document. 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: String s1 = MolExporter.exportToFormat(document, "mol"); String s2 = MolExporter.exportToFormat(document, "smiles:a-H"); // aromatize and remove Hydrogens - Parameters:
- document- the document to export
- fmt- the format descriptor string
- Returns:
- string 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:
 
- 
exportToBinFormatCreates a binary representation of the document. Works with all the text formats that are supported by theexportToFormatmethod, and also with the binary image formats (png, jpeg, etc.). 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:
 
- 
exportToFormatCreates 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.For a similar method that does not throw checked exceptions, see toFormat(Molecule, String).Examples: String s1 = MolExporter.exportToFormat(molecule, "mol"); String 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
- See Also:
 
- 
exportToBinFormatCreates a binary representation of the molecule. Works with all the text formats that are supported by theexportToFormatmethod, and also with the binary image formats (png, jpeg, etc.). 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.For a similar method that does not throw checked exceptions, see toBinFormat(Molecule, String).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
- See Also:
 
- 
exportToObjectCreates aString,byte[]orImagerepresentation 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.For a similar method that does not throw checked exceptions, see toObject(Molecule, String).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[] d1 = (byte[]) MolExporter.exportToObject(molecule, "png:w300,h300,b32,#00ffff00"); byte[] d2 = (byte[]) MolExporter.exportToObject(molecule, "jpeg:w300,h300,Q95,#ffff00,spacefill"); - Parameters:
- molecule- the molecule to export
- fmt- the format descriptor string
- Returns:
- a String,byte[]orImagerepresentation 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
- See Also:
 
- 
toFormatReturns a string representation of the given 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.This method works the same way as exportToFormat(Molecule, String), with the only exception that an unchecked exception is thrown on export error.Examples: String s1 = MolExporter.toFormat(molecule, "mol"); String s2 = MolExporter.toFormat(molecule, "smiles:a-H"); // aromatize and remove Hydrogens - Parameters:
- molecule- the molecule to export
- format- the format descriptor string
- Returns:
- string representation of the molecule in the specified format
- Throws:
- UncheckedIOException- on export error
- IllegalArgumentException- for invalid format string
- See Also:
 
- 
toBinFormatReturns a binary representation of the given molecule. Works with all the text formats that are supported by thetoFormatmethod, and also with the binary image formats (png, jpeg, etc.). 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.This method works the same way as exportToBinFormat(Molecule, String), with the only exception that an unchecked exception is thrown on export error.Examples: byte[] d1 = MolExporter.toBinFormat(molecule, "mol"); byte[] d2 = MolExporter.toBinFormat(molecule, "smiles:a-H"); // aromatize and remove H byte[] d3 = MolExporter.toBinFormat(molecule, "png:w300,h300,b32,#00ffff00"); byte[] d4 = MolExporter.toBinFormat(molecule, "jpeg:w300,h300,Q95,#ffff00,spacefill"); - Parameters:
- molecule- the molecule to export
- format- the format descriptor string
- Returns:
- a binary representation of the molecule in the specified format
- Throws:
- UncheckedIOException- on export error
- IllegalArgumentException- for invalid format string
- See Also:
 
- 
toObjectReturns aString,byte[]orImagerepresentation of the given 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.This method works the same way as exportToObject(Molecule, String), with the only exception that an unchecked exception is thrown on export error.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[] d1 = (byte[]) MolExporter.exportToObject(molecule, "png:w300,h300,b32,#00ffff00"); byte[] d2 = (byte[]) MolExporter.exportToObject(molecule, "jpeg:w300,h300,Q95,#ffff00,spacefill"); - Parameters:
- molecule- the molecule to export
- format- the format descriptor string
- Returns:
- a String,byte[]orImagerepresentation of the molecule in the specified format
- Throws:
- UncheckedIOException- on export error
- IllegalArgumentException- for invalid format string
- See Also:
 
- 
exportToObjectpublic static Object exportToObject(Molecule[] mols, String fmt, MolExportModule cv) throws IOException Creates aString,byte[]orImagerepresentation of the given molecules.- Parameters:
- mols- the molecules to export
- fmt- the format descriptor string
- cv- the export module
- Returns:
- a String,byte[]orImagerepresentation of the molecules in the specified format
- Throws:
- IOException- export error
- See Also:
 
 
-