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.. 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);
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.
|
Modifier and Type | Field and Description |
---|---|
static String |
OptForceWriteAs2DCoordinates |
static String |
OptWriteAromaticBondTypes |
static String |
OptWriteDefaultProperties |
static String |
OptWriteMajorIsotopes |
static String |
OptWriteQueryFormatValencies |
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)
Returns whether the given
IChemObject 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 the
IResourceFormat 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 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, removeChemObjectIOListener
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addChemObjectIOListener, addSetting, addSettings, getIOSettings, getListeners, getSetting, getSetting, getSettings, hasSetting, removeChemObjectIOListener
public static final String OptForceWriteAs2DCoordinates
public static final String OptWriteMajorIsotopes
public static final String OptWriteAromaticBondTypes
public static final String OptWriteQueryFormatValencies
public static final String OptWriteDefaultProperties
public 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()
IChemObjectIO
IResourceFormat
class for this IO class.public void setWriter(Writer out) throws CDKException
IChemObjectWriter
CDKException
public void setWriter(OutputStream output) throws CDKException
IChemObjectWriter
CDKException
public void close() throws IOException
IOException
- when the wrapper IO class cannot be closed.public boolean accepts(Class<? extends IChemObject> classObject)
IChemObjectIO
IChemObject
can be read or written.classObject
- IChemObject
of which is tested if it can be handled.IChemObject
can be handled.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 writeCDKException
- is thrown if the output
does not support the data in the objectaccepts(Class)
public void writeMolecule(IAtomContainer container) throws Exception
container
- Molecule that is written to an OutputStreamException
protected static String formatMDLInt(int x, int n)
x
- The int to be formatedn
- 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 © 2018. All Rights Reserved.