ChemML provides a Chemical Markup Language (CML) object model for Ruby, built on lutaml-model[https://github.com/lutaml/lutaml-model].
Purpose
CML is the established XML standard for chemistry. Existing Ruby libraries either don’t exist or use hand-rolled XML manipulation that drifts from the CML schema. ChemML gives CML a proper model layer with declarative attribute/mapping definitions and framework-backed serialization.
Install
Add to your Gemfile:
gem "chemicalml"
Or install directly:
$ gem install chemicalml
Usage
Parse a CML document:
require "chemicalml"
doc = Chemicalml::Cml::Document.from_xml(File.read("ethanol.cml"))
doc.molecules.first.atoms.first.element_type # => "C"
Build a document programmatically:
atom = Chemicalml::Cml::Atom.new(id: "a1", element_type: "C")
mol = Chemicalml::Cml::Molecule.new(id: "m1", atoms: [atom])
doc = Chemicalml::Cml::Document.new(molecules: [mol])
doc.to_xml # => well-formed CML XML
Design
Each CML element is a Lutaml::Model::Serializable subclass with
declared attributes and an XML mapping block. Serialization goes
through lutaml-model — no hand-rolled XML.
The library is designed as a sibling model layer to other chemistry tooling. AsciiChem (https://www.asciichem.org) uses ChemML for CML round-trip support via a translator adapter.
Both Schema 2.4 and Schema 3 are supported via
Chemicalml::Cml::Schema3 and Chemicalml::Cml::Schema24 namespaces
(see lib/chemicalml/schema.rb).
The CML conventions (molecular, compchem, dictionary, unit-dictionary,
unitType-dictionary) are implemented as registered constraint sets in
Chemicalml::Convention. Built-in dictionaries ship as YAML under
data/dictionaries/.
Acknowledgements
CML is the work of the xml-cml.org community, edited by Sam Adams, Joe Townsend, Weerapong Phadungsukanan, and Jens Thomas, with originator Peter Murray-Rust and contributors Alex Wade, Nick England, Daniel Lowe, Hannah Barjat, and Egon Willighagen. The schema, conventions, dictionaries, and examples are licensed by xml-cml.org under CC-BY-3.0. See NOTICES.adoc for full attribution of upstream content redistributed in this gem.
License
BSD-2-Clause. See LICENSE.