public class MDLV2000Writer extends DefaultChemObjectWriter
MDLV2000Writer writer = new MDLV2000Writer(
new FileWriter(new File("output.mol"))
);
writer.write((IAtomContainer)molecule);
writer.close();
The writer has two IO settings: one for writing 2D coordinates, even if 3D coordinates are given for the written data; the second writes aromatic bonds as bond type 4, which is, strictly speaking, a query bond type, but my many tools used to reflect aromaticity. The full IO setting API is explained in CDK News [Willighagen, E.L., Customizing file IO, CDK News, 2004, 1:2-4]. One programmatic option to set the option for writing 2D coordinates looks like:
Properties customSettings = new Properties(); customSettings.setProperty( "ForceWriteAs2DCoordinates", "true" ); PropertiesListener listener = new PropertiesListener(customSettings); writer.addChemObjectIOListener(listener);
| Name | Question | Default |
|---|---|---|
| ForceWriteAs2DCoordinates | Should coordinates always be written as 2D? | false |
| WriteAromaticBondTypes | Should aromatic bonds be written as bond type 4? | false |
| WriteQueryFormatValencies | Should valencies be written in the MDL Query format? (deprecated) | false |
| Modifier and Type | Class and Description |
|---|---|
static class |
MDLV2000Writer.SPIN_MULTIPLICITY
Enumeration of all valid radical values.
|
| Constructor and Description |
|---|
MDLV2000Writer() |
MDLV2000Writer(OutputStream output)
Constructs a new MDLWriter that can write an
IAtomContainer
to a given OutputStream. |
MDLV2000Writer(Writer out)
Constructs a new MDLWriter that can write an
IAtomContainer
to the MDL molfile format. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
accepts(Class<? extends IChemObject> classObject) |
void |
close()
Flushes the output and closes this object.
|
void |
customizeJob() |
protected static String |
formatMDLFloat(float fl)
Formats a float to fit into the connectiontable and changes it
to a String.
|
protected static String |
formatMDLInt(int i,
int l)
Formats an integer to fit into the connection table and changes it
to a String.
|
protected static String |
formatMDLString(String s,
int le)
Formats a String to fit into the connectiontable.
|
IResourceFormat |
getFormat() |
void |
setWriteAromaticBondTypes(boolean val)
Convenience method to set the option for writing aromatic bond types.
|
void |
setWriter(OutputStream output) |
void |
setWriter(Writer out) |
void |
write(IChemObject object)
Writes a
IChemObject to the MDL molfile formated output. |
void |
writeMolecule(IAtomContainer container)
Writes a Molecule to an OutputStream in MDL sdf format.
|
addChemObjectIOListener, addSetting, addSettings, fireIOSettingQuestion, getIOSettings, getListeners, getSetting, getSetting, getSettings, hasSetting, removeChemObjectIOListenerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddChemObjectIOListener, addSetting, addSettings, getIOSettings, getListeners, getSetting, getSetting, getSettings, hasSetting, removeChemObjectIOListenerpublic MDLV2000Writer(Writer out)
IAtomContainer
to the MDL molfile format.out - The Writer to write topublic MDLV2000Writer(OutputStream output)
IAtomContainer
to a given OutputStream.output - The OutputStream to write topublic MDLV2000Writer()
public IResourceFormat getFormat()
public void setWriter(Writer out) throws CDKException
CDKExceptionpublic void setWriter(OutputStream output) throws CDKException
CDKExceptionpublic void close()
throws IOException
IOExceptionpublic boolean accepts(Class<? extends IChemObject> classObject)
public void write(IChemObject object) throws CDKException
IChemObject to the MDL molfile formated output.
It can only output ChemObjects of type IChemFile,
IChemObject and IAtomContainer.object - IChemObject to writeCDKExceptionaccepts(Class)public void writeMolecule(IAtomContainer container) throws Exception
container - Molecule that is written to an OutputStreamExceptionprotected static String formatMDLInt(int i, int l)
i - The int to be formatedl - Length of the Stringprotected static String formatMDLFloat(float fl)
fl - The float to be formatedprotected static String formatMDLString(String s, int le)
s - The String to be formatedle - The length of the Stringpublic void setWriteAromaticBondTypes(boolean val)
val - the value.public void customizeJob()
Copyright © 2017. All rights reserved.