asciichemGetting started
AsciiChem is a language for chemistry. It has four implementations — Rust (the authoritative one), Ruby, TypeScript, and Python — that parse through the same parsanol engine over the same PARG artifact and pass the same shared corpus. Pick the one that ships in your stack; the syntax and the model are identical everywhere.
-
Install the gem
Terminal window gem install asciichem -
Parse and render
require "asciichem"formula = AsciiChem.parse("H_2O")formula.to_mathml # => "<math>...</math>"formula.to_text # => "H_2O" (round trip)formula.to_structural_svg # 2D diagram -
Use the CLI
Terminal window asciichem convert -i "2H_2 + O_2 -> 2H_2O" -t mathmlasciichem lint -i "H_2 + O_2 -> H_2O"asciichem resolve --cas 50-78-2asciichem cite --cas 50-78-2
Full reference: Ruby API.
-
Install the package
Terminal window npm install asciichem -
Parse and render
import { parse, renderMathml } from "asciichem";const formula = parse("H_2O");formula.toText(); // "H_2O" (round trip)formula.toStructuralSvg(); // 2D diagramrenderMathml(formula); // "<math>...</math>" -
Ingest database chemistry
import { parseSmiles } from "asciichem";parseSmiles("CC(=O)OC1=CC=CC=C1C(=O)O") // aspirin, same model.toStructuralSvg();
Full reference: TypeScript API.
-
Install the package
Terminal window pip install asciichem -
Parse and render
from asciichem import parse_textfrom asciichem.text import renderfrom asciichem.mathml import render_mathmlformula = parse_text("H_2O")render(formula) # "H_2O" (round trip)render_mathml(formula) # "<math>...</math>" -
Wire form for pipelines
from asciichem.wire import to_model_json, from_model_jsonwire = to_model_json(formula) # asciichem-model v1 JSONback = from_model_json(wire) # ...and back, losslessly
Full reference: Python API.
-
Build from source (the crate is not yet on crates.io; the release pipeline — release-plz + trusted publishing — is in place)
Terminal window git clone https://github.com/asciichem/asciichem-rscd asciichem-rs && cargo build --release -
Parse and render
asciichem::parse("2H_2 + O_2 -> 2H_2O")?; // semantic modelasciichem::parse_to_text("H_2O")?; // canonical textasciichem::mathml::render("^14C")?; // byte-exact MathMLasciichem::svg::render("C1-C-C-C-C-C1")?; // structural SVG -
Use the CLI
Terminal window target/release/asciichem convert -i "2H_2 + O_2 -> 2H_2O" -t mathmltarget/release/asciichem lint -i "H_2 + O_2 -> H_2O"target/release/asciichem identity -i "CCO" --from smiles
Full reference: Rust.
asciichemasciichemWhat’s in a parse?
Section titled “What’s in a parse?”AsciiChem parses text into a model tree. Each node has typed fields — chemistry semantics, not just typography. The tree is the same whether you parsed in Rust, Ruby, TypeScript, or Python.
| Source | Model |
|---|---|
H_2O | Molecule[Atom(H, sub:"2"), Atom(O)] |
^14C | Molecule[Atom(C, isotope:"14")] |
Ca^2+ | Molecule[Atom(Ca, charge:"2+")] |
Ca(OH)_2 | Molecule[Atom(Ca), Group(...,mult:"2")] |
2H_2+O_2 -> 2H_2O | Reaction(reactants:[...], products:[...], arrow::forward) |
Where to next?
Section titled “Where to next?”- Implementations — the four packages, side by side.
- Atoms — elements, isotopes, charges, oxidation states.
- Molecules — stoichiometry, groups, brackets.
- Reactions — forward, equilibrium, conditions.
- Structures and resolution — bring in SMILES/molfile, resolve identifiers, derive InChI identity.
- Citing substances — turn resolved records into dataset-type bibitems.