Molecule converter

SplitMultiMolecules.javaThe MolConverter helper class converts molecules between various file formats.

The detailed documentation about the supported file formats can be found in the Molecule File Conversion document.

Here we present some examples:

Simple conversion

Simple SDfile to SMILES conversion:

MolConverter.Builder mcbld = new MolConverter.Builder();
mcbld.addInput("examples/plugin-api/example_mols.sdf", "");
mcbld.setOutput("out.smiles", "smiles");
mcbld.setOutputFlags(MolExporter.TEXT);
MolConverter mc = mcbld.build();
while(mc.convert());
mc.close();
 

For a complete source code, please see MoleculeConverter.java.

Splitting multi-molecule input

To split a multi-molecule input file into multiple Molfiles named out1.mol, out2.mol etc., use the following settings:

MolConverter.Builder mcbld = new MolConverter.Builder();
mcbld.addInput("examples/plugin-api/example_mols.sdf", "");
mcbld.setOutput("out.mol", "mol");
mcbld.setOutputFlags(MolExporter.TEXT|MolExporter.MULTIPLE);
MolConverter mc = mcbld.build();
while(mc.convert());
mc.close();
 

For a complete source code, please see SplitMultiMolecules.java.

Merging more molecules

To merge more molecule input files into a multi-molecule file, use the following settings:

MolConverter.Builder mcbld = new MolConverter.Builder();
mcbld.addInput("in1.mol", "");
mcbld.addInput("in2.mol", "");
mcbld.addInput("in3.mol", "");
mcbld.setOutput("out.sdf", "sdf");
mcbld.setOutputFlags( MolExporter.TEXT );
MolConverter mc = mcbld.build();
while(mc.convert());
mc.close();

For a complete source code, please see MergeMultiMolecules.java.