public class MolExporter extends Object
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.
Modifier and Type | Field and Description |
---|---|
static int |
C_CLOSE_STREAM
Close the underlying stream.
|
static int |
C_FLUSH_STREAM
Flush the output stream and force any buffered output bytes to be
written out.
|
static MolFilter |
FILTER_DIM0
Molecule filter for cleaning
0D molecules only. |
static int |
MULTIPLE
Use this flag to produce multiple output files.
|
static int |
TEXT
Use this flag to write text files with OS dependent line separators.
|
Constructor and Description |
---|
MolExporter(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.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the
MolExportModule and the underlying stream. |
void |
close(int opts)
Closes the
MolExportModule and, optionally, the underlying stream. |
static String |
convertToString(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 String |
exportToFormat(MDocument document,
String fmt)
Creates a string representation of the document.
|
static String |
exportToFormat(Molecule molecule,
String fmt)
Creates a string representation of the molecule.
|
static Object |
exportToObject(MDocument document,
String fmt)
Creates a String, byte[] array or Image representation of the document.
|
static Object |
exportToObject(Molecule[] mols,
String fmt,
MolExportModule cv)
Creates a String, byte[] array or Image representation of the given molecules.
|
static Object |
exportToObject(Molecule molecule,
String fmt)
Creates a String, byte[] array or Image representation of the molecule.
|
protected void |
finalize() |
void |
flush()
Flushes the output stream and forces any buffered output bytes
to be written out.
|
String |
getFormat()
Gets the output file format.
|
boolean |
isCleanable()
Tests whether cleaning is meaningful for the chosen output format.
|
void |
setClean(int cleanDim,
String cleanOpts)
Sets molecule cleaning in exporter.
|
void |
setClean(int cleanDim,
String cleanOpts,
MolFilter cleanFilter)
Sets molecule cleaning in exporter.
|
void |
setErrorProcessor(ErrorProcessor errorProcessor)
Sets the error handler interface for concurrent mode.
|
void |
setThreadCount(int threadCount)
Sets the number of threads for concurrent processing.
|
boolean |
write(Molecule m)
Writes a molecule into the stream.
|
public static final int TEXT
MolExporter(String, String, int, String[], String)
,
Constant Field Valuespublic static final int MULTIPLE
MolExporter(String, String, int, String[], String)
,
Constant Field Valuespublic static final int C_CLOSE_STREAM
close(int)
,
Constant Field Valuespublic static final int C_FLUSH_STREAM
close(int)
,
Constant Field Valuespublic static final MolFilter FILTER_DIM0
0D
molecules only.public MolExporter(String fname, String fmtWithOpts, int outflags, String[] incFields, String enc) throws MolExportException, IOException, IllegalArgumentException
fname
- the output filenamefmtWithOpts
- the output file format and the optionsoutflags
- output flags, it can be a combination of TEXT
and MULTIPLE
incFields
- SDF fields to include in table or nullenc
- charset name or nullMolExportException
- export error occuredIOException
- output error occurred when writing the headerIllegalArgumentException
- Invalid format string (fmtWithOpts).IllegalCharsetNameException
- if the encoding is illegalUnsupportedCharsetException
- if the encoding is unsupportedpublic MolExporter(String fname, String fmtWithOpts) throws IOException, IllegalArgumentException
fname
- the output filename with extensionfmtWithOpts
- the output file format and the optionsMolExportException
- export error occurredIOException
- output error occurred when writing the headerIllegalArgumentException
- Invalid format string (fmtWithOpts).IllegalCharsetNameException
- if the encoding is illegalUnsupportedCharsetException
- if the encoding is unsupportedpublic MolExporter(OutputStream out, String fmtWithOpts, boolean text, String[] incFields, String enc) throws MolExportException, IOException, IllegalArgumentException
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 nullMolExportException
- export error occuredIOException
- output error occurred when writing the headerIllegalArgumentException
- Invalid format string (fmtWithOpts).IllegalCharsetNameException
- if the encoding is illegalUnsupportedCharsetException
- if the encoding is unsupportedpublic MolExporter(OutputStream out, String fmtWithOpts) throws IOException, IllegalArgumentException
out
- the output streamfmtWithOpts
- the output file format and the optionsMolExportException
- export error occuredIOException
- output error occurred when writing the headerIllegalArgumentException
- Invalid format string (fmtWithOpts).IllegalCharsetNameException
- if the encoding is illegalUnsupportedCharsetException
- if the encoding is unsupportedpublic MolExporter(OutputStream out, String fmtWithOpts, boolean text, String[] incFields) throws MolExportException, IOException, IllegalArgumentException
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 nullMolExportException
- export error occuredIOException
- output error occurred when writing the headerIllegalArgumentException
- Invalid format string (fmtWithOpts).IllegalCharsetNameException
- if the encoding is illegalUnsupportedCharsetException
- if the encoding is unsupportedpublic MolExporter(OutputStream out, String fmtWithOpts, String enc) throws IOException, IllegalArgumentException
out
- the output streamfmtWithOpts
- the output file format and the optionsenc
- charset name or nullMolExportException
- export error occuredIOException
- output error occurred when writing the headerIllegalArgumentException
- Invalid format string (fmtWithOpts).IllegalCharsetNameException
- if the encoding is illegalUnsupportedCharsetException
- if the encoding is unsupportedpublic void setThreadCount(int threadCount) throws IllegalStateException
1
CPU.threadCount
- the number of threads, set 0
for the number of CPUs,
1
for single-threaded modeIllegalStateException
- if called after call to write(chemaxon.struc.Molecule)
public void setClean(int cleanDim, String cleanOpts) throws IllegalStateException
cleanDim
- the cleaning dimensioncleanOpts
- the cleaning optionsIllegalStateException
- if called after call to write(chemaxon.struc.Molecule)
setThreadCount(int)
public void setClean(int cleanDim, String cleanOpts, MolFilter cleanFilter) throws IllegalStateException
cleanDim
- the cleaning dimensioncleanOpts
- the cleaning optionscleanFilter
- 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)IllegalStateException
- if called after call to write(chemaxon.struc.Molecule)
setThreadCount(int)
public void setErrorProcessor(ErrorProcessor errorProcessor) throws IllegalStateException
close()
in concurrent mode. To change this, set specific ErrorProcessor
implementation 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 in close()
.
In single-threaded mode export errors are thrown in write(chemaxon.struc.Molecule)
,
separately for each molecule.IllegalStateException
- if called after call to write(chemaxon.struc.Molecule)
setThreadCount(int)
public String getFormat()
public boolean isCleanable()
public boolean write(Molecule m) throws MolExportException, IOException
m
- the moleculetrue
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 exporterMolExportException
- export errorIOException
public void close() throws MolExportException, IOException
MolExportModule
and the underlying stream.
IMPORTANT: call this or close(int)
at the end, after the last call to
write(chemaxon.struc.Molecule)
, because this method
flushes the output stream and closes concurrent processing properly.MolExportException
- on export error.IOException
- in case of any other I/O error.public void close(int opts) throws MolExportException, IOException
MolExportModule
and, optionally, the underlying stream.
IMPORTANT: call this or close()
at the end, after the last call to
write(chemaxon.struc.Molecule)
, because this method
flushes the output stream and closes concurrent processing properly.opts
- closing options, C_CLOSE_STREAM
or C_FLUSH_STREAM
.MolExportException
- export error.IOException
- in case of any other I/O error.public void flush() throws MolExportException, IOException
MolExportException
- on export error.IOException
- if an I/O error occurs.protected void finalize() throws MolExportException, IOException
finalize
in class Object
MolExportException
IOException
public static Object exportToObject(MDocument document, String fmt) throws IOException
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");
document
- the document to exportfmt
- the format descriptor stringIOException
- Export error.IllegalArgumentException
- Invalid format string.SecurityException
- Export module cannot be loaded because of security reasons
(firewall).exportToFormat(chemaxon.struc.MDocument, java.lang.String)
,
exportToBinFormat(chemaxon.struc.MDocument, java.lang.String)
public static String convertToString(MDocument document, String fmt, int flags) throws IOException
document
- the document to convertfmt
- the molecule file format or null
flags
- conversion optionsIOException
- Export errorpublic static final String exportToFormat(MDocument document, String fmt) throws IOException
s1 = MolExporter.exportToFormat(document, "mol"); s2 = MolExporter.exportToFormat(document, "smiles:a-H"); // aromatize and remove Hydrogens
document
- the document to exportfmt
- the format descriptor stringIOException
- Export errorIllegalArgumentException
- Invalid format string.SecurityException
- Export module cannot be loaded because of
security reasons (firewall).exportToBinFormat(chemaxon.struc.MDocument, java.lang.String)
,
exportToObject(chemaxon.struc.MDocument, java.lang.String)
public static final byte[] exportToBinFormat(MDocument document, String fmt) throws IOException
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");
document
- the document to exportfmt
- the format descriptor stringIOException
- Export error.IllegalArgumentException
- Invalid format string.SecurityException
- Export module cannot be loaded because of
security reasons (firewall).exportToFormat(chemaxon.struc.MDocument, java.lang.String)
,
exportToObject(chemaxon.struc.MDocument, java.lang.String)
public static final String exportToFormat(Molecule molecule, String fmt) throws IOException
s1 = MolExporter.exportToFormat(molecule, "mol"); s2 = MolExporter.exportToFormat(molecule, "smiles:a-H"); // aromatize and remove Hydrogens
molecule
- the molecule to exportfmt
- the format descriptor stringIOException
- Export error.IllegalArgumentException
- Invalid format string.SecurityException
- Export module cannot be loaded because of
security reasons (firewall).public static final byte[] exportToBinFormat(Molecule molecule, String fmt) throws IOException
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");
molecule
- the molecule to exportfmt
- the format descriptor stringIOException
- Export error.IllegalArgumentException
- Invalid format string.SecurityException
- Export module cannot be loaded because of
security reasons (firewall).public static Object exportToObject(Molecule molecule, String fmt) throws IOException
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");
molecule
- the molecule to exportfmt
- the format descriptor stringIOException
- Export error.IllegalArgumentException
- Invalid format string.SecurityException
- Export module cannot be loaded because of
security reasons (firewall).public static Object exportToObject(Molecule[] mols, String fmt, MolExportModule cv) throws IOException
mols
- the molecules to exportfmt
- the format descriptor stringcv
- the export moduleIOException
- export errorexportToObject(Molecule, String)