Package org.openscience.cdk.io
Class MDLV2000Writer
- java.lang.Object
-
- org.openscience.cdk.io.ChemObjectIO
-
- org.openscience.cdk.io.DefaultChemObjectWriter
-
- org.openscience.cdk.io.MDLV2000Writer
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,IChemObjectIO
,IChemObjectWriter
public class MDLV2000Writer extends DefaultChemObjectWriter
Writes MDL molfiles, which contains a single molecule (see [Dalby, A. et. al.. Journal of Chemical Information and Computer Sciences. 1992. 32]). For writing a MDL molfile you can this code: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.. CDK News. 2004. 1]. 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);
- Source code:
- main
- IO options:
Name Question Default ProgramName Program name to write at the top of the molfile header, should be exactly 8 characters long CDK ForceWriteAs2DCoordinates Should coordinates always be written as 2D? false WriteAromaticBondTypes Should aromatic bonds be written as bond type 4? false WriteMajorIsotopes Write atomic mass of any non-null atomic mass including major isotopes (e.g. [12]C) true WriteDefaultProperties Write trailing zero's on atom/bond property blocks even if they're not used. true WriteQueryFormatValencies Should valencies be written in the MDL Query format? (deprecated) false - Belongs to CDK module:
- io
- Keywords:
- file format, MDL molfile
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MDLV2000Writer.SPIN_MULTIPLICITY
Enumeration of all valid radical values.
-
Field Summary
Fields Modifier and Type Field Description static String
OptForceWriteAs2DCoordinates
static String
OptProgramName
static String
OptTruncateLongData
static String
OptWriteAromaticBondTypes
static String
OptWriteData
static String
OptWriteDefaultProperties
static String
OptWriteMajorIsotopes
static String
OptWriteQueryFormatValencies
-
Constructor Summary
Constructors Constructor Description MDLV2000Writer()
MDLV2000Writer(OutputStream output)
Constructs a new MDLWriter that can write anIAtomContainer
to a given OutputStream.MDLV2000Writer(Writer out)
Constructs a new MDLWriter that can write anIAtomContainer
to the MDL molfile format.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accepts(Class<? extends IChemObject> classObject)
Returns whether the givenIChemObject
can be read or written.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 x, int n)
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()
Returns theIResourceFormat
class for this IO class.void
setWriteAromaticBondTypes(boolean val)
Convenience method to set the option for writing aromatic bond types.void
setWriter(OutputStream output)
Sets the OutputStream from which this ChemObjectWriter should write the contents.void
setWriter(Writer out)
Sets the Writer from which this ChemObjectWriter should write the contents.void
write(IChemObject object)
Writes aIChemObject
to the MDL molfile formated output.void
writeMolecule(IAtomContainer container)
Writes a Molecule to an OutputStream in MDL sdf format.-
Methods inherited from class org.openscience.cdk.io.ChemObjectIO
addChemObjectIOListener, addSetting, addSettings, fireIOSettingQuestion, getIOSettings, getListeners, getSetting, getSetting, getSettings, hasSetting, removeChemObjectIOListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openscience.cdk.io.IChemObjectIO
addChemObjectIOListener, addSetting, addSettings, getIOSettings, getListeners, getSetting, getSetting, getSettings, hasSetting, removeChemObjectIOListener
-
-
-
-
Field Detail
-
OptForceWriteAs2DCoordinates
public static final String OptForceWriteAs2DCoordinates
- See Also:
- Constant Field Values
-
OptWriteMajorIsotopes
public static final String OptWriteMajorIsotopes
- See Also:
- Constant Field Values
-
OptWriteAromaticBondTypes
public static final String OptWriteAromaticBondTypes
- See Also:
- Constant Field Values
-
OptWriteQueryFormatValencies
public static final String OptWriteQueryFormatValencies
- See Also:
- Constant Field Values
-
OptWriteDefaultProperties
public static final String OptWriteDefaultProperties
- See Also:
- Constant Field Values
-
OptProgramName
public static final String OptProgramName
- See Also:
- Constant Field Values
-
OptWriteData
public static final String OptWriteData
- See Also:
- Constant Field Values
-
OptTruncateLongData
public static final String OptTruncateLongData
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MDLV2000Writer
public MDLV2000Writer(Writer out)
Constructs a new MDLWriter that can write anIAtomContainer
to the MDL molfile format.- Parameters:
out
- The Writer to write to
-
MDLV2000Writer
public MDLV2000Writer(OutputStream output)
Constructs a new MDLWriter that can write anIAtomContainer
to a given OutputStream.- Parameters:
output
- The OutputStream to write to
-
MDLV2000Writer
public MDLV2000Writer()
-
-
Method Detail
-
getFormat
public IResourceFormat getFormat()
Description copied from interface:IChemObjectIO
Returns theIResourceFormat
class for this IO class.
-
setWriter
public void setWriter(Writer out) throws CDKException
Description copied from interface:IChemObjectWriter
Sets the Writer from which this ChemObjectWriter should write the contents.- Throws:
CDKException
-
setWriter
public void setWriter(OutputStream output) throws CDKException
Description copied from interface:IChemObjectWriter
Sets the OutputStream from which this ChemObjectWriter should write the contents.- Throws:
CDKException
-
close
public void close() throws IOException
Flushes the output and closes this object.- Throws:
IOException
- when the wrapper IO class cannot be closed.
-
accepts
public boolean accepts(Class<? extends IChemObject> classObject)
Description copied from interface:IChemObjectIO
Returns whether the givenIChemObject
can be read or written.- Parameters:
classObject
-IChemObject
of which is tested if it can be handled.- Returns:
- true, if the
IChemObject
can be handled.
-
write
public void write(IChemObject object) throws CDKException
Writes aIChemObject
to the MDL molfile formated output. It can only output ChemObjects of typeIChemFile
,IChemObject
andIAtomContainer
.- Parameters:
object
-IChemObject
to write- Throws:
CDKException
- is thrown if the output does not support the data in the object- See Also:
accepts(Class)
-
writeMolecule
public void writeMolecule(IAtomContainer container) throws Exception
Writes a Molecule to an OutputStream in MDL sdf format.- Parameters:
container
- Molecule that is written to an OutputStream- Throws:
Exception
-
formatMDLInt
protected static String formatMDLInt(int x, int n)
Formats an integer to fit into the connection table and changes it to a String.- Parameters:
x
- The int to be formatedn
- Length of the String- Returns:
- The String to be written into the connectiontable
-
formatMDLFloat
protected static String formatMDLFloat(float fl)
Formats a float to fit into the connectiontable and changes it to a String.- Parameters:
fl
- The float to be formated- Returns:
- The String to be written into the connectiontable
-
formatMDLString
protected static String formatMDLString(String s, int le)
Formats a String to fit into the connectiontable.- Parameters:
s
- The String to be formatedle
- The length of the String- Returns:
- The String to be written in the connectiontable
-
setWriteAromaticBondTypes
public void setWriteAromaticBondTypes(boolean val)
Convenience method to set the option for writing aromatic bond types.- Parameters:
val
- the value.
-
customizeJob
public void customizeJob()
-
-