Skip to content

Stereochemistry

AsciiChem captures configuration stereochemistry via prefix markers on the molecule. Stereo bonds (wedge / hash) are documented in Bonds.

MarkerSource formUse
R(R)-Rectus configuration (CIP)
S(S)-Sinister configuration (CIP)
E(E)-Entgegen (trans alkene, CIP)
Z(Z)-Zusammen (cis alkene, CIP)
α / alpha(α)-/(a)-/(alpha)-Alpha anomer (sugars)
β / beta(β)-/(b)-/(beta)-Beta anomer (sugars)

Three spellings are accepted for the Greek letters: typed alpha / beta (AsciiMath-style), short a / b, and Unicode α / β. The Text formatter canonicalises to Unicode on output.

(R)-CH(OH)COOH
(R)- C H ( O H ) C O O H
(S)-CH(OH)COOH
(S)- C H ( O H ) C O O H

Lactic acid’s two enantiomers.

(alpha)-C
(alpha)- C
(beta)-C
(beta)- C
(α)-C
(alpha)- C
(β)-C
(beta)- C
(E)-CH=CH
(E)- C H = C H
(Z)-CH=CH
(Z)- C H = C H

The stereo prefix attaches to the molecule, not to a specific atom. The chemist reads (R)-CH(OH)COOH and knows which carbon the R refers to; AsciiChem stores it as metadata on the molecule.

mol = AsciiChem.parse("(R)-CH(OH)COOH").nodes.first
mol.stereo # => :R
mol.stereo_letter # => "R"

(OH) is a parenthesised group, not a stereo prefix. The grammar distinguishes via the closed letter set: R/S/E/Z and the alpha/beta spellings are the only valid stereo letters. Anything else inside the parens falls through to the regular group parse.

Ca(OH)_2
Ca ( O H ) 2

Parses as Atom(Ca) followed by Group(OH) with multiplicity 2. No stereo is set.

AsciiChem.parse("(R)-CH_3").to_text # => "(R)-CH_3"
AsciiChem.parse("(alpha)-CH_3").to_text # => "(α)-CH_3" (canonical)
AsciiChem.parse("(a)-CH_3").to_text # => "(α)-CH_3" (canonical)

The Text formatter emits the Unicode form for alpha/beta. The ASCII spellings are accepted on input but not emitted on output — this is the canonicaliser’s job.