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 Summary
FieldsModifier 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 Summary
ConstructorsConstructorDescriptionMolExporter(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 Summary
Modifier 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
-
TEXT
public 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:
-
MULTIPLE
public static final int MULTIPLEUse this flag to produce multiple output files.- Since:
- Marvin 5.2.2, 04/20/2009
- See Also:
-
C_CLOSE_STREAM
public static final int C_CLOSE_STREAMClose the underlying stream.- Since:
- Marvin 5.1.1, 08/17/2008
- See Also:
-
C_FLUSH_STREAM
public 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_DIM0
Molecule filter for cleaning0Dmolecules only.- See Also:
-
-
Constructor Details
-
MolExporter
public MolExporter(String fname, String fmtWithOpts, int outflags, String[] incFields, String enc) throws IOException, IllegalArgumentException Creates a molecule exporter.- Parameters:
fname- the output filenamefmtWithOpts- the output file format and the optionsoutflags- output flags, it can be a combination ofTEXTandMULTIPLEincFields- SDF fields to include in table or nullenc- charset name or null- Throws:
MolExportException- export error occurredIOException- output error occurred when writing the headerIllegalArgumentException- Invalid format string (fmtWithOpts).IllegalCharsetNameException- if the encoding is illegalUnsupportedCharsetException- if the encoding is unsupported- Since:
- Marvin 5.2.2, 04/20/2009
-
MolExporter
Creates a molecule exporter.- Parameters:
fname- the output filename with extensionfmtWithOpts- the output file format and the options- Throws:
MolExportException- export error occurredIOException- output error occurred when writing the headerIllegalArgumentException- Invalid format string (fmtWithOpts).IllegalCharsetNameException- if the encoding is illegalUnsupportedCharsetException- if the encoding is unsupported- Since:
- Marvin 5.4.1, 01/10/2010
-
MolExporter
public MolExporter(OutputStream out, String fmtWithOpts, boolean text, String[] incFields, String enc) throws IOException, IllegalArgumentException Creates a molecule exporter.- Parameters:
out- the output streamfmtWithOpts- the output file format and the optionstext- write OS dependent line.separators instead of '\n'incFields- SDF fields to include in table or nullenc- charset name or null- Throws:
MolExportException- export error occurredIOException- output error occurred when writing the headerIllegalArgumentException- Invalid format string (fmtWithOpts).IllegalCharsetNameException- if the encoding is illegalUnsupportedCharsetException- if the encoding is unsupported
-
MolExporter
public MolExporter(OutputStream out, String fmtWithOpts) throws IOException, IllegalArgumentException Creates a molecule exporter.- Parameters:
out- the output streamfmtWithOpts- the output file format and the options- Throws:
MolExportException- export error occurredIOException- output error occurred when writing the headerIllegalArgumentException- Invalid format string (fmtWithOpts).IllegalCharsetNameException- if the encoding is illegalUnsupportedCharsetException- if the encoding is unsupported
-
MolExporter
public MolExporter(OutputStream out, String fmtWithOpts, boolean text, String[] incFields) throws IOException, IllegalArgumentException Creates a molecule exporter.- Parameters:
out- the output streamfmtWithOpts- the output file format and the optionstext- write OS dependent line.separators instead of '\n'incFields- SDF fields to include in table or null- Throws:
MolExportException- export error occurredIOException- output error occurred when writing the headerIllegalArgumentException- Invalid format string (fmtWithOpts).IllegalCharsetNameException- if the encoding is illegalUnsupportedCharsetException- if the encoding is unsupported
-
MolExporter
public MolExporter(OutputStream out, String fmtWithOpts, String enc) throws IOException, IllegalArgumentException Creates a molecule exporter.- Parameters:
out- the output streamfmtWithOpts- the output file format and the optionsenc- charset name or null- Throws:
MolExportException- export error occurredIOException- output error occurred when writing the headerIllegalArgumentException- Invalid format string (fmtWithOpts).IllegalCharsetNameException- if the encoding is illegalUnsupportedCharsetException- if the encoding is unsupported
-
-
Method Details
-
setThreadCount
Sets 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, set0for the number of CPUs,1for single-threaded mode- Throws:
IllegalStateException- if called after call towrite(chemaxon.struc.Molecule)- Since:
- Marvin 5.3
-
setClean
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 dimensioncleanOpts- the cleaning options- Throws:
IllegalStateException- if called after call towrite(chemaxon.struc.Molecule)- Since:
- Marvin 5.3
- See Also:
-
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 dimensioncleanOpts- the cleaning optionscleanFilter- the molecule filter to tell which molecule is to be cleaned, setFILTER_DIM0to clean only0Dmoleculesnullfor no filtering (cleaning all)- Throws:
IllegalStateException- if called after call towrite(chemaxon.struc.Molecule)- Since:
- Marvin 5.3
- See Also:
-
setErrorProcessor
Sets 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 towrite(chemaxon.struc.Molecule)- Since:
- Marvin 5.3
- See Also:
-
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
Writes 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, callclose()which will throw the error and close the exporter- Throws:
MolExportException- export errorIOException
-
close
Closes 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 interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
MolExportException- on export error.IOException- in case of any other I/O error.
-
close
Closes 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_STREAMorC_FLUSH_STREAM.- Throws:
MolExportException- export error.IOException- in case of any other I/O error.- Since:
- Marvin 5.1.1, 08/17/2008
-
flush
Flushes 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
-
exportToObject
Creates 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 exportfmt- 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:
-
convertToString
Converts the document to text format.- Parameters:
document- the document to convertfmt- the molecule file format ornullflags- conversion options- Returns:
- the string
- Throws:
IOException- Export error- Since:
- Marvin 5.8, 08/25/2011
-
exportToFormat
Creates 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 exportfmt- the format descriptor string- Returns:
- string representation of the document in the specified format
- Throws:
IOException- Export errorIllegalArgumentException- Invalid format string.SecurityException- Export module cannot be loaded because of security reasons (firewall).- Since:
- Marvin 5.8, 08/25/2011
- See Also:
-
exportToBinFormat
Creates 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 exportfmt- 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
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.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 exportfmt- 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:
-
exportToBinFormat
Creates 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 exportfmt- 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:
-
exportToObject
Creates 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 exportfmt- 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:
-
toFormat
Returns 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 exportformat- the format descriptor string- Returns:
- string representation of the molecule in the specified format
- Throws:
UncheckedIOException- on export errorIllegalArgumentException- for invalid format string- See Also:
-
toBinFormat
Returns 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 exportformat- the format descriptor string- Returns:
- a binary representation of the molecule in the specified format
- Throws:
UncheckedIOException- on export errorIllegalArgumentException- for invalid format string- See Also:
-
toObject
Returns 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 exportformat- the format descriptor string- Returns:
- a
String,byte[]orImagerepresentation of the molecule in the specified format - Throws:
UncheckedIOException- on export errorIllegalArgumentException- for invalid format string- See Also:
-
exportToObject
public static Object exportToObject(Molecule[] mols, String fmt, MolExportModule cv) throws IOException Creates aString,byte[]orImagerepresentation of the given molecules.- Parameters:
mols- the molecules to exportfmt- the format descriptor stringcv- the export module- Returns:
- a
String,byte[]orImagerepresentation of the molecules in the specified format - Throws:
IOException- export error- See Also:
-