Module: AsciiChem::Cml

Defined in:
lib/asciichem/cml.rb,
lib/asciichem/cml/extensions.rb,
lib/asciichem/cml/translator.rb,
lib/asciichem/cml/group_extensions.rb

Overview

CML (Chemical Markup Language) support for AsciiChem.

Bidirectional conversion between the AsciiChem text world and the CML XML world. The pipeline is:

AsciiChem::Model <-> AsciiChem::ModelAdapter <-> Chemicalml::Model
                                                   ^
                                                   |
                                         Chemicalml::Cml::Translator
                                                   |
                                                   v
                                         Chemicalml::Cml::* (wire)

The canonical model (Chemicalml::Model) is the format-agnostic hub. AsciiChem and CML each have their own adapter; the adapters never talk to each other directly. Adding a new format (SMILES, InChI, MOL) is a new adapter — none of the existing code changes.

Public API:

AsciiChem::Cml.from_asciichem(formula)  # => CML XML string
AsciiChem::Cml.parse(xml)               # => AsciiChem::Model::Formula

Defined Under Namespace

Modules: Extensions, GroupExtensions Classes: Translator

Class Method Summary collapse

Class Method Details

.from_asciichem(formula) ⇒ Object

Serialise an AsciiChem::Model::Formula to CML XML.



31
32
33
# File 'lib/asciichem/cml.rb', line 31

def self.from_asciichem(formula)
  Translator.from_asciichem(formula)
end

.parse(xml) ⇒ Object

Parse CML XML into an AsciiChem::Model::Formula.



36
37
38
# File 'lib/asciichem/cml.rb', line 36

def self.parse(xml)
  Translator.to_asciichem(xml)
end