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>

public class CMLReader extends AbstractResourceReader<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 Details

    • CMLReader

      public CMLReader()
      Creates a new CML reader with the default document factory.
    • CMLReader

      public CMLReader(CMLDocumentFactory factory)
      Creates a new CML reader with a custom document factory.
      Parameters:
      factory - the document factory to use
  • Method Details

    • getResourcePath

      public String getResourcePath()
      Description copied from interface: ResourceIO
      Returns the base path where this resource is located.
    • getResourceType

      public Class<AbstractCMLDocument> getResourceType()
      Description copied from interface: ResourceIO
      Returns the type of resource.
    • getName

      public String getName()
      Description copied from interface: ResourceIO
      Returns the display name of this resource handler. MUST be implemented with I18N support.
      Returns:
      the display name
    • getDescription

      public String getDescription()
      Description copied from interface: ResourceIO
      Returns a short description of this resource handler. MUST be implemented with I18N support.
      Returns:
      the description
    • getLongDescription

      public String getLongDescription()
      Description copied from interface: ResourceIO
      Returns a long description of this resource handler. MUST be implemented with I18N support.
      Returns:
      the long description
    • getCategory

      public String getCategory()
      Description copied from interface: ResourceIO
      Returns the category for grouping. MUST be implemented with I18N support.
      Returns:
      the category name
    • getSupportedVersions

      public String[] getSupportedVersions()
      Description copied from interface: ResourceIO
      Returns 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

      protected AbstractCMLDocument loadFromSource(String resourceId) throws Exception
      Specified by:
      loadFromSource in class AbstractResourceReader<AbstractCMLDocument>
      Throws:
      Exception
    • loadFromInputStream

      protected AbstractCMLDocument loadFromInputStream(InputStream is, String id) throws Exception
      Overrides:
      loadFromInputStream in class AbstractResourceReader<AbstractCMLDocument>
      Throws:
      Exception
    • setDocumentFactory

      public void setDocumentFactory(CMLDocumentFactory factory)
      Sets the document factory used to create CML documents.
      Parameters:
      factory - the document factory
    • getDocumentFactory

      public CMLDocumentFactory getDocumentFactory()
      Gets the document factory used to create CML documents.
      Returns:
      the document factory
    • read

      public AbstractCMLDocument read(InputStream input) throws CMLException
      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

      public AbstractCMLDocument read(File file) throws CMLException
      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

      public AbstractCMLDocument readFromString(String cml) throws CMLException
      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

      public AbstractCMLDocument read(URL url) throws CMLException
      Reads a CML document from a URL.
      Parameters:
      url - the URL to read from
      Returns:
      the parsed CML document
      Throws:
      CMLException - if parsing fails