@TestClass(value="org.openscience.cdk.io.CML2WriterTest") public class CMLWriter extends DefaultChemObjectWriter
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., Chemical markup, XML, and the Worldwide Web. 1. Basic
principles, Journal of Chemical Information and Computer
Sciences, 1999, 39:928-942].
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.
FileWriter
,
StringWriter
Constructor and Description |
---|
CMLWriter() |
CMLWriter(OutputStream output) |
CMLWriter(Writer writer)
Constructs a new CMLWriter class.
|
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.
|
IResourceFormat |
getFormat()
Returns the
IResourceFormat 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.
|
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 CMLWriter(Writer writer)
writer
- Writer to redirect the output to.public CMLWriter(OutputStream output)
public CMLWriter()
public void registerCustomizer(ICMLCustomizer customizer)
@TestMethod(value="testGetFormat") public IResourceFormat getFormat()
IChemObjectIO
IResourceFormat
class for this IO class.public void setWriter(Writer writer) throws CDKException
IChemObjectWriter
CDKException
public void setWriter(OutputStream output) throws CDKException
IChemObjectWriter
CDKException
@TestMethod(value="testClose") public void close() throws IOException
IOException
@TestMethod(value="testAccepts") 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
object
- A Molecule of AtomContaineSet objectCDKException
- is thrown if the output
does not support the data in the objectCopyright © 2014. All Rights Reserved.