Skip to content
AsciiC6hem

Molecules

A molecule is an ordered sequence of atoms and groups, with an optional leading stoichiometric coefficient, optional stereo prefix, and optional CML annotations.

Source Rendered
H_2O
H 2 O
CO_2
C O 2
C_6H_12O_6
C 6 H 12 O 6

Each atom carries its own subscript. The model is Molecule(nodes: [Atom, Atom, ...]).

Molecules can carry CML metadata via the @key("value") suffix:

Source Rendered
H_2O @name("Water")@inchi("InChI=1/H2O/h1H2")
H 2 O

Supported annotations:

  • @name("...") — molecule name
  • @inchi("..."), @smiles("..."), @cas("...") — identifiers
  • @title("...") — molecule title
  • @formula("H 2 O 1") — concise formula
  • @label("solvent") — label
  • @mw("18.015") — any custom property
  • @meta("key","value") — metadata key-value pair

See Annotations for details.

Leading digits on a molecule are its coefficient:

Source Rendered
2H_2O
2 H 2 O
3H_2
3 H 2

The Molecule#coefficient field holds the string. The MathML renderer emits it as an <mn> before the atoms.

Parenthesised sub-formulas are groups. A group can carry an outer multiplicity.

Source Rendered
Ca(OH)_2
Ca ( O H ) 2
(NH_4)_2SO_4
( N H 4 ) 2 S O 4

For Ca(OH)_2:

  • Atom Ca
  • Group OH with multiplicity 2, bracket :paren

For (NH_4)_2SO_4:

  • Group NH_4 with multiplicity 2
  • Atoms S, O with subscripts 4

AsciiChem supports three bracket kinds:

BracketOpen / CloseUse
Paren( )Generic grouping (Ca(OH)_2)
Square[ ]Coordination complexes ([Fe(CN)_6]^4-)
Brace{ }Optional / rare

The bracket kind is preserved through round-trip — (OH)_2 stays as (OH)_2, not [OH]_2.

Square brackets wrap coordination complexes. The complex’s charge sits outside the brackets.

Source Rendered
[Fe(CN)_6]^4-
Install the asciichem gem to see this rendered.
[Co(NH_3)_6]^3+
Install the asciichem gem to see this rendered.

These are parsed as Group(bracket: :square, nodes: [...]) followed by an Atom with the charge. (In v1, the charge attaches to the last atom; v2 may promote it to a complex-level attribute.)

Play