Molecule export is the operation when Molecule objects are converted to targets in various formats.
When exporting structures via ChemAxon tools, we will refer to different target of the data to be written:
The most frequently used API for molecule export is defined in chemaxon.formats.MolExporter. MolExporter has lots of utility functions.
Exporting one molecule to String:
Please note that some features, for example R-groups cannot be exported to all formats. Here the SMILES export for R-groups throws an exception because the SMILES format doesn't support R-groups!
For a complete source code, please see ExportingMolecules.java.
Writing more molecules into one target is also possible:
For a complete source code, please see AppendMolecules.java.
Additional options of MolExporter allow to refine behavior further. Options can be general or dependent on file formats. Options can be set in the constructor
MolExporter(InputStream is, String opts) or during import with static method
MolExporter.exportToFormat. The most important option is the file format option which specifies the expected file format. General or file format dependent options are separated by a colon from the file format option and by a comma from each other. In the code example below the molecule is exported without the explicit hydrogens with the general
-H option. This is a general export option and can be applied in case of any file format. File format option is
mol for MDL MOL file format and file format specific option is
V3 to export the file in extended MOL format.
For a complete source code, please see ImportExportOptions.java.