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
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);
- IO options:
Name Question Default 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 writeProperties Should molecule properties be written as non-structural data false WriteQueryFormatValencies Should valencies be written in the MDL Query format? (deprecated) false TruncateLongData Truncate long data files >200 characters false 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 WriteDefaultProperties Write trailing zero's on atom/bond property blocks even if they're not used. true - Keywords:
- file format, MDL molfile
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration of all valid radical values. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionMDLV2000Writer(OutputStream output) Constructs a new MDLWriter that can write anIAtomContainerto a given OutputStream.MDLV2000Writer(Writer out) Constructs a new MDLWriter that can write anIAtomContainerto the MDL molfile format. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaccepts(Class<? extends IChemObject> classObject) Returns whether the givenIChemObjectcan be read or written.voidclose()Flushes the output and closes this object.voidprotected static StringformatMDLFloat(float fl) Formats a float to fit into the connectiontable and changes it to a String.protected static StringformatMDLInt(int x, int n) Formats an integer to fit into the connection table and changes it to a String.protected static StringformatMDLString(String s, int le) Formats a String to fit into the connectiontable.Returns theIResourceFormatclass for this IO class.voidsetWriteAromaticBondTypes(boolean val) Convenience method to set the option for writing aromatic bond types.voidsetWriter(OutputStream output) Sets the OutputStream from which this ChemObjectWriter should write the contents.voidSets the Writer from which this ChemObjectWriter should write the contents.voidwrite(IChemObject object) Writes aIChemObjectto the MDL molfile formated output.voidwriteMolecule(IAtomContainer container) Writes a Molecule to an OutputStream in MDL sdf format.Methods inherited from class ChemObjectIO
addChemObjectIOListener, addSetting, addSettings, fireIOSettingQuestion, getIOSettings, getListeners, getSetting, getSetting, getSettings, hasSetting, removeChemObjectIOListenerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IChemObjectIO
addChemObjectIOListener, addSetting, addSettings, getIOSettings, getListeners, getSetting, getSetting, getSettings, hasSetting, removeChemObjectIOListener
-
Field Details
-
OptForceWriteAs2DCoordinates
- See Also:
-
OptWriteMajorIsotopes
- See Also:
-
OptWriteAromaticBondTypes
- See Also:
-
OptWriteQueryFormatValencies
- See Also:
-
OptWriteDefaultProperties
- See Also:
-
OptProgramName
- See Also:
-
OptWriteData
- See Also:
-
OptTruncateLongData
- See Also:
-
-
Constructor Details
-
MDLV2000Writer
Constructs a new MDLWriter that can write anIAtomContainerto the MDL molfile format.- Parameters:
out- The Writer to write to
-
MDLV2000Writer
Constructs a new MDLWriter that can write anIAtomContainerto a given OutputStream.- Parameters:
output- The OutputStream to write to
-
MDLV2000Writer
public MDLV2000Writer()
-
-
Method Details
-
getFormat
Description copied from interface:IChemObjectIOReturns theIResourceFormatclass for this IO class. -
setWriter
Description copied from interface:IChemObjectWriterSets the Writer from which this ChemObjectWriter should write the contents.- Throws:
CDKException
-
setWriter
Description copied from interface:IChemObjectWriterSets the OutputStream from which this ChemObjectWriter should write the contents.- Throws:
CDKException
-
close
Flushes the output and closes this object.- Throws:
IOException- when the wrapper IO class cannot be closed.
-
accepts
Description copied from interface:IChemObjectIOReturns whether the givenIChemObjectcan be read or written.- Parameters:
classObject-IChemObjectof which is tested if it can be handled.- Returns:
- true, if the
IChemObjectcan be handled.
-
write
Writes aIChemObjectto the MDL molfile formated output. It can only output ChemObjects of typeIChemFile,IChemObjectandIAtomContainer.- Parameters:
object-IChemObjectto write- Throws:
CDKException- is thrown if the output does not support the data in the object- See Also:
-
writeMolecule
Writes a Molecule to an OutputStream in MDL sdf format.- Parameters:
container- Molecule that is written to an OutputStream- Throws:
Exception
-
formatMDLInt
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
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
-
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()
-