Package org.openscience.cdk.io
Class CMLWriter
java.lang.Object
org.openscience.cdk.io.ChemObjectIO
org.openscience.cdk.io.DefaultChemObjectWriter
org.openscience.cdk.io.CMLWriter
- All Implemented Interfaces:
Closeable
,AutoCloseable
,IChemObjectIO
,IChemObjectWriter
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:
Name Question Default CMLIDs Should the output use CML identifiers? true NamespacedOutput Should the output use namespaced output? true NamespacePrefix What should the namespace prefix be? [empty is no prefix] Indenting Should the output be indented? true SchemaInstance Should the output use the Schema-Instance attribute? false XMLDeclaration Should the output contain an XML declaration? true InstanceLocation Where is the schema found? - Belongs to CDK module:
- libiocml
- Keywords:
- file format, CML
- Requires:
- java1.5+
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
accepts
(Class<? extends IChemObject> classObject) Returns whether the givenIChemObject
can be read or written.void
close()
Flushes the output and closes this object.Returns theIResourceFormat
class for this IO class.void
registerCustomizer
(ICMLCustomizer customizer) void
setWriter
(OutputStream output) Sets the OutputStream from which this ChemObjectWriter should write the contents.void
Sets the Writer from which this ChemObjectWriter should write the contents.void
write
(IChemObject object) Serializes the IChemObject to CML and redirects it to the output Writer.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
-
Constructor Details
-
CMLWriter
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
-
CMLWriter
public CMLWriter()
-
-
Method Details
-
registerCustomizer
-
getFormat
Description copied from interface:IChemObjectIO
Returns theIResourceFormat
class for this IO class. -
setWriter
Description copied from interface:IChemObjectWriter
Sets the Writer from which this ChemObjectWriter should write the contents.- Throws:
CDKException
-
setWriter
Description copied from interface:IChemObjectWriter
Sets 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: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
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
-