Skip to content

Ruby

Rubyyou are here
asciichem
gem install asciichemReference implementation.
TypeScript
asciichem-ts
npm install asciichemPowers this page.
Python
asciichem-py
pip install asciichem-pyZero runtime deps.
Terminal window
gem install asciichem
require "asciichem"
formula = AsciiChem.parse("2H_2 + O_2 ->[heat] 2H_2O")
formula.to_mathml # presentation MathML (L2 goldens)
formula.to_text # canonical AsciiChem text (round-trip)
formula.to_structural_svg # 2D structural diagram
# Structures from databases, straight into the same model
AsciiChem.parse_smiles("CC(=O)OC1=CC=CC=C1C(=O)O").to_structural_svg
mol = AsciiChem.parse_molfile(File.read("ethanol.mol")) # coordinates preserved
# Resolution: identifiers → substance records with provenance
substance = AsciiChem::Resolver.resolve(value: "50-78-2", convention: "cas")
substance.identifier_value("inchikey") # => "BSYNRYMUTXBXSQ-UHFFFAOYSA-N"
# Canonical wire form (asciichem-model v1)
AsciiChem.parse("H_2O").to_model_json

Parse / reject · L0 emission · L1 text · L2 MathML · SMILES · molfile · CML · linter — 100% of the shared corpus. See the Implementations matrix for the full table.

The reference implementation carries the long tail of features that make the contract concrete:

  • All formatters — MathML, Text (the canonicaliser), HTML, LaTeX, SVG (typographic), StructuralSvg (2D layout), CML via the chemicalml gem, SMILES and molfile writers, and the canonical wire JSON.

  • Opt-in Rust-core engine — the same grammar and transform over Parsanol’s parslet-compat layer, at ~2.4× parse speed; parslet stays the default:

    # Gemfile: gem "parsanol", "~> 1.3.16"
    require "asciichem/engine/parsanol_engine"
    AsciiChem::Engine.use(:parsanol)
  • Citations — AsciiChem::Citation.to_xml(substance) emits a dataset-type Relaton bibitem per resolved source. CLI: asciichem cite --cas 50-78-2. See Citing substances.

  • InChI identity — opt-in engine over the IUPAC inchi-1 binary with IdentityCrossCheck linter. CLI: asciichem identity -i .... See Structures and resolution.

  • Beyond formulas — crystals, spectra, computational results, Z-matrices, reaction mechanisms all parse into the semantic model and round-trip.

  • The CLI — convert, lint, validate, resolve, cite, identity, version. See CLI reference.

github.com/asciichem/asciichem-ruby — releases flow through trusted publishing (RubyGems OIDC, no stored credentials).

Play