Class CMLWriter

All Implemented Interfaces:
Closeable, AutoCloseable, IChemObjectIO, IChemObjectWriter

public class CMLWriter extends DefaultChemObjectWriter
Serializes a IAtomContainerSet or a IAtomContainer object to CML 2 code. Chemical Markup Language is an XML-based file format [Murray-Rust, P. and Rzepa, H.S.. Journal of Chemical Information and Computer Sciences. 1999. 39]. Output can be redirected to other Writer objects like StringWriter and FileWriter. An example:
   StringWriter output = new StringWriter();
   boolean makeFragment = true;
   CMLWriter cmlwriter = new CMLWriter(output, makeFragment);
   cmlwriter.write(molecule);
   cmlwriter.close();
   String cmlcode = output.toString();
 

Output to a file called "molecule.cml" can done with:

   FileWriter output = new FileWriter("molecule.cml");
   CMLWriter cmlwriter = new CMLWriter(output);
   cmlwriter.write(molecule);
   cmlwriter.close();
 

For atoms it outputs: coordinates, element type and formal charge. For bonds it outputs: order, atoms (2, or more) and wedges.

Author:
Egon Willighagen
See Also:
This class is affected by these bug(s):
1565563
Source code:
main
IO options:
NameQuestionDefault
CMLIDsShould the output use CML identifiers?true
NamespacedOutputShould the output use namespaced output?true
NamespacePrefixWhat should the namespace prefix be? [empty is no prefix]
IndentingShould the output be indented?true
SchemaInstanceShould the output use the Schema-Instance attribute?false
XMLDeclarationShould the output contain an XML declaration?true
InstanceLocationWhere is the schema found?
Belongs to CDK module:
libiocml
Keywords:
file format, CML
Requires:
java1.5+
  • Constructor Details

    • CMLWriter

      public CMLWriter(Writer writer)
      Constructs a new CMLWriter class. Output will be stored in the Writer class given as parameter. The CML code will be valid CML code with a XML header. Only one object can be stored.
      Parameters:
      writer - Writer to redirect the output to.
    • CMLWriter

      public CMLWriter(OutputStream output)
    • CMLWriter

      public CMLWriter()
  • Method Details

    • registerCustomizer

      public void registerCustomizer(ICMLCustomizer customizer)
    • getFormat

      public IResourceFormat getFormat()
      Description copied from interface: IChemObjectIO
      Returns the IResourceFormat class for this IO class.
    • setWriter

      public void setWriter(Writer writer) 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 given IChemObject 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
      Serializes the IChemObject to CML and redirects it to the output Writer.
      Parameters:
      object - A Molecule of AtomContaineSet object
      Throws:
      CDKException - is thrown if the output does not support the data in the object