ambit2.core.io
Class MDLWriter

Package class diagram package MDLWriter
java.lang.Object
  extended by org.openscience.cdk.io.DefaultChemObjectWriter
      extended by ambit2.core.io.MDLWriter
All Implemented Interfaces:
org.openscience.cdk.io.IChemObjectIO, org.openscience.cdk.io.IChemObjectWriter

public class MDLWriter
extends org.openscience.cdk.io.DefaultChemObjectWriter

Copied here from CDK source tree in order to handle the aromatic bond issue (this code writes 4 as aromatic bond code); until a proper fix is available. Writes MDL mol files and SD files.

A MDL mol file contains a single molecule, whereas a MDL SD file contains one or more molecules. This class is capable of writing both mol files and SD files. The correct format is automatically chosen:

Thus, to write several molecules to a single SD file you can either use write(IChemObject) and pass a MoleculeSet or you can repeatedly call one of the two writeMolecule methods.

For writing a MDL molfile you can this code:

 MDLWriter writer = new MDLWriter(new FileWriter(new File("output.mol")));
 writer.write((IMolecule)molecule);
 writer.close();
 
See {cdk.cite DAL92}. cdk.module io cdk.svnrev $Revision: 9587 $ cdk.keyword file format, MDL molfile cdk.bug 1524466


Field Summary
 java.util.Map sdFields
           
 
Constructor Summary
MDLWriter()
           
MDLWriter(java.io.OutputStream output)
          Contructs a new MDLWriter that can write an array of Molecules to a given OutputStream.
MDLWriter(java.io.Writer out)
          Contructs a new MDLWriter that can write an array of Molecules to a Writer.
 
Method Summary
 boolean accepts(java.lang.Class classObject)
           
 void close()
          Flushes the output and closes this object.
 void dontWriteAromatic()
          Method does not do anything until now.
 org.openscience.cdk.io.formats.IResourceFormat getFormat()
           
 void setSdFields(java.util.Map map)
          Here you can set a map which will be used to build sd fields in the file.
 void setWriter(java.io.OutputStream output)
           
 void setWriter(java.io.Writer out)
           
 void write(org.openscience.cdk.interfaces.IChemObject object)
          Writes a IChemObject to the MDL molfile formated output.
 void writeMolecule(org.openscience.cdk.interfaces.IMolecule container)
          Writes a Molecule to an OutputStream in MDL sdf format.
 
Methods inherited from class org.openscience.cdk.io.DefaultChemObjectWriter
addChemObjectIOListener, fireIOSettingQuestion, getIOSettings, removeChemObjectIOListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sdFields

public java.util.Map sdFields
Constructor Detail

MDLWriter

public MDLWriter(java.io.Writer out)
Contructs a new MDLWriter that can write an array of Molecules to a Writer.

Parameters:
out - The Writer to write to

MDLWriter

public MDLWriter(java.io.OutputStream output)
Contructs a new MDLWriter that can write an array of Molecules to a given OutputStream.

Parameters:
output - The OutputStream to write to

MDLWriter

public MDLWriter()
Method Detail

getFormat

public org.openscience.cdk.io.formats.IResourceFormat getFormat()

setWriter

public void setWriter(java.io.Writer out)
               throws org.openscience.cdk.exception.CDKException
Throws:
org.openscience.cdk.exception.CDKException

setWriter

public void setWriter(java.io.OutputStream output)
               throws org.openscience.cdk.exception.CDKException
Throws:
org.openscience.cdk.exception.CDKException

dontWriteAromatic

public void dontWriteAromatic()
Method does not do anything until now.


setSdFields

public void setSdFields(java.util.Map map)
Here you can set a map which will be used to build sd fields in the file. The entries will be translated to sd fields like this:
> <key>
> value
empty line

Parameters:
map - The map to be used, map of String-String pairs

close

public void close()
           throws java.io.IOException
Flushes the output and closes this object.

Throws:
java.io.IOException

accepts

public boolean accepts(java.lang.Class classObject)

write

public void write(org.openscience.cdk.interfaces.IChemObject object)
           throws org.openscience.cdk.exception.CDKException
Writes a IChemObject to the MDL molfile formated output. It can only output ChemObjects of type ChemFile, Molecule and MoleculeSet.

Parameters:
object - class must be of type ChemFile, Molecule or MoleculeSet.
Throws:
org.openscience.cdk.exception.CDKException
See Also:
ChemFile

writeMolecule

public void writeMolecule(org.openscience.cdk.interfaces.IMolecule container)
                   throws java.lang.Exception
Writes a Molecule to an OutputStream in MDL sdf format.

Parameters:
container - Molecule that is written to an OutputStream
Throws:
java.lang.Exception