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
public class CMLWriter extends DefaultChemObjectWriter
Serializes aIAtomContainerSet
or aIAtomContainer
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 likeStringWriter
andFileWriter
. 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:
FileWriter
,StringWriter
- 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 Constructor Description CMLWriter()
CMLWriter(OutputStream output)
CMLWriter(Writer writer)
Constructs a new CMLWriter class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accepts(Class<? extends IChemObject> classObject)
Returns whether the givenIChemObject
can be read or written.void
close()
Flushes the output and closes this object.IResourceFormat
getFormat()
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
setWriter(Writer writer)
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 Detail
-
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 Detail
-
registerCustomizer
public void registerCustomizer(ICMLCustomizer customizer)
-
getFormat
public IResourceFormat getFormat()
Description copied from interface:IChemObjectIO
Returns theIResourceFormat
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 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
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
-
-