Skip to content

Reaction

A reaction captures a chemical transformation: reactants, an arrow type, products, and optional conditions rendered above and below the arrow per IUPAC.

FieldTypeSourceExample
reactantsArray of Moleculeleft of arrow2H_2 + O_2
productsArray of Moleculeright of arrow2H_2O
arrowSymbolarrow token:forward, :equilibrium, …
conditionsConditions struct[above][below]Conditions(above: "Fe", below: "400°C")
SymbolASCIIUnicodeUse
:forward->→Net forward
:reverse<-←Net reverse
:equilibrium<=>⇌Equilibrium (Haber, acid/base)
:resonance<->↔Resonance structures
┌───────────────┐
│ Reaction │
│ │
reactants[0] ─┐ │
reactants[1] ─┤── left │ above
... ─┘ │ ▲
──────────►│ ──── ⇌ ────
│ ▼
products[0] ─┐ │ below
products[1] ─┤── right │
... ─┘ │
└───────────────┘

Conditions sit in bracketed groups immediately after the arrow. The first bracket is the above condition (catalyst), the second is the below condition (temperature / pressure / solvent).

Source Rendered
N_2 + 3H_2 <=>[Fe][400°C] 2NH_3
Install the asciichem gem to see this rendered.

produces Conditions(above: "Fe", below: "400°C").

A condition entry may name its role explicitly — the bracket text stays verbatim, and the model derives typed entries from it:

Source Rendered
C_6H_5Br + C_6H_5B(OH)_2 ->[cat: Pd; base: Na_2CO_3][solv: THF] C_12H_10
Install the asciichem gem to see this rendered.
  • Recognised prefixes: cat/catalyst, solv/solvent, reag/reagent.
  • ; separates entries inside one bracket; an entry without a recognised prefix stays free text (base: Na_2CO_3 above keeps its full text as a free entry).
  • Conditions#entries returns Entry(role:, value:, side:); the bracket text itself remains the canonical round-trip source, so the wire form is unchanged.
  • ReactionRoles.roles_for prefers explicit roles and falls back to the above/below convention only for free text.

Coefficients are model data: Reaction#stoichiometry returns the normalized per-side mapping of coefficient-free species text to integer coefficient (2H_2 + O_2 -> 2H_2O → { reactants: { "H_2" => 2, "O_2" => 1 }, products: { "H_2O" => 2 } }). Molecule#stoichiometric_coefficient is the single coefficient rule shared by the reaction, the balance check, and composition counting.

reaction := terms arrow terms
terms := molecule ("+" molecule)*
arrow := "<=>" | "<->" | "->" | "<-"
(with optional [above] and [below] conditions)
FormatterArrow renderingConditions
MathML<mo>⇌</mo> (or <mover>/<munderover> with conditions)<mtext>
TextASCII spelling[above][below]
HTMLUnicode arrow<sup> / <sub> around the arrow
LaTeXmhchem arrow[above][below] (mhchem native)
SVGASCII arrow[above][below]
AsciiChem.parse("2H_2 + O_2 -> 2H_2O").to_text # => "2H_2 + O_2 -> 2H_2O"
AsciiChem.parse("N_2 + 3H_2 <=>[Fe][400°C] 2NH_3").to_text # => same
AsciiChem.parse("HAc <=> Ac^- + H^+").to_text # => same
  • BalanceCheck — atom counts must match on both sides, respecting coefficients and group multiplicities.

Single-step reactions stay as Reaction. Two or more reactions chained (A -> B -> C) promote to a ReactionCascade.

Play