Class CMLReader
java.lang.Object
org.episteme.core.io.AbstractResourceReader<AbstractCMLDocument>
org.episteme.natural.chemistry.loaders.cml.CMLReader
- All Implemented Interfaces:
ResourceIO<AbstractCMLDocument>, ResourceReader<AbstractCMLDocument>
Chemical Markup Language (CML) Reader.
CML is an XML-based format for representing molecular and chemical data including structures, reactions, spectra, and computational chemistry results.
Supported CML Elements:
- Molecules: molecule, atomArray, bondArray, atom, bond
- Reactions: reaction, reactionList, reactant, product
- Crystals: crystal, symmetry, cellParameter
- Spectra: spectrum, peakList, peak
- Properties: property, scalar, array, matrix
- Metadata: identifier, name, formula
Example:
CMLReader reader = new CMLReader();
AbstractCMLDocument doc = reader.read(new File("molecule.cml"));
Element root = doc.getDocumentElement();
* @see XML-CML- Since:
- 1.0
- Author:
- Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new CML reader with the default document factory.CMLReader(CMLDocumentFactory factory) Creates a new CML reader with a custom document factory. -
Method Summary
Modifier and TypeMethodDescriptionReturns the category for grouping.Returns a short description of this resource handler.Gets the document factory used to create CML documents.Returns a long description of this resource handler.getName()Returns the display name of this resource handler.Returns the base path where this resource is located.Returns the type of resource.String[]Returns the supported versions of the format this reader/writer handles.protected AbstractCMLDocumentloadFromInputStream(InputStream is, String id) protected AbstractCMLDocumentloadFromSource(String resourceId) Reads a CML document from a file.read(InputStream input) Reads a CML document from an input stream.Reads a CML document from a URL.readFromString(String cml) Reads a CML document from a string.voidsetDocumentFactory(CMLDocumentFactory factory) Sets the document factory used to create CML documents.Methods inherited from class AbstractResourceReader
clearCache, getMiniCatalog, getSampleDataPath, isUsingFallback, load, loadAll, loadAllFromSource, loadFromFallback, setCacheEnabledMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ResourceIO
getExpectedResourceFiles, getSupportedExtensions, isFileBased, isOutputMethods inherited from interface ResourceReader
isInput
-
Constructor Details
-
CMLReader
public CMLReader()Creates a new CML reader with the default document factory. -
CMLReader
Creates a new CML reader with a custom document factory.- Parameters:
factory- the document factory to use
-
-
Method Details
-
getResourcePath
Description copied from interface:ResourceIOReturns the base path where this resource is located. -
getResourceType
Description copied from interface:ResourceIOReturns the type of resource. -
getName
Description copied from interface:ResourceIOReturns the display name of this resource handler. MUST be implemented with I18N support.- Returns:
- the display name
-
getDescription
Description copied from interface:ResourceIOReturns a short description of this resource handler. MUST be implemented with I18N support.- Returns:
- the description
-
getLongDescription
Description copied from interface:ResourceIOReturns a long description of this resource handler. MUST be implemented with I18N support.- Returns:
- the long description
-
getCategory
Description copied from interface:ResourceIOReturns the category for grouping. MUST be implemented with I18N support.- Returns:
- the category name
-
getSupportedVersions
Description copied from interface:ResourceIOReturns the supported versions of the format this reader/writer handles.Each implementation MUST override this method to declare which versions of the underlying format are supported. The returned array should contain version strings in the format's standard notation (e.g., "3.0", "2.1", "Level 3 Version 2").
Examples:
- MathML: {"3.0", "2.0"}
- SBML: {"Level 3 Version 2", "Level 3 Version 1", "Level 2 Version 5"}
- PhyloXML: {"1.10", "1.00"}
- Returns:
- array of supported version strings, never null (empty array if version-agnostic)
-
loadFromSource
- Specified by:
loadFromSourcein classAbstractResourceReader<AbstractCMLDocument>- Throws:
Exception
-
loadFromInputStream
- Overrides:
loadFromInputStreamin classAbstractResourceReader<AbstractCMLDocument>- Throws:
Exception
-
setDocumentFactory
Sets the document factory used to create CML documents.- Parameters:
factory- the document factory
-
getDocumentFactory
Gets the document factory used to create CML documents.- Returns:
- the document factory
-
read
Reads a CML document from an input stream.- Parameters:
input- the input stream containing CML data- Returns:
- the parsed CML document
- Throws:
CMLException- if parsing fails
-
read
Reads a CML document from a file.- Parameters:
file- the file containing CML data- Returns:
- the parsed CML document
- Throws:
CMLException- if parsing fails
-
readFromString
Reads a CML document from a string.- Parameters:
cml- the CML content as a string- Returns:
- the parsed CML document
- Throws:
CMLException- if parsing fails
-
read
Reads a CML document from a URL.- Parameters:
url- the URL to read from- Returns:
- the parsed CML document
- Throws:
CMLException- if parsing fails
-