Skip to content

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 CO_2 C_6H_12O_6
H 2 O C O 2 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 3H_2
2 H 2 O 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 (NH_4)_2SO_4
Ca ( O H ) 2 ( 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])
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, and a subscript can apply to the bracketed group:

Source Rendered
[Fe(CN)_6] [OH]_2 [Fe(CN)_6]_3
[ Fe ( C N ) 6 ] [ O H ] 2 [ Fe ( C N ) 6 ] 3

These are parsed as Group(bracket: :square, nodes: [...]) with the subscript as the group multiplicity.

Play