Mechanism
A reaction mechanism: ordered steps with optional spectator ions.
Fields
Section titled “Fields”| Field | Type | Example |
|---|---|---|
steps | Array<Step> | See below |
spectators | Array<String> | ["Na+"] |
Step struct
Section titled “Step struct”Mechanism::Step = Struct.new(:label, :reaction, :flows, keyword_init: true)Mechanism::Flow = Struct.new(:source, :target, keyword_init: true)reaction is the step’s reaction text (the round-trip source);
flows are the electron-flow markers written on the step
(| flow: SOURCE > TARGET, semicolon-separated) — verbatim source
and target names, and part of the wire form (steps[].flows).
See Reaction mechanisms syntax for input format.
Step graph
Section titled “Step graph”The entries stay verbatim in the model; MechanismGraph derives the
pathway the text implies:
graph = AsciiChem::MechanismGraph.for(AsciiChem.parse(source).nodes.first)graph.links.map { |link| [link.from, link.to, link.species] }# => [["s1", "s2", ["B"]]]- Each step value is parsed as a reaction (cascades included); a
prose step keeps a
nilreaction and takes part in no links. - A species on both sides of one step is a catalyst.
- Steps link when a product species of an earlier step is a
reactant of a later one — matched coefficient-free via
Reaction#stoichiometry.
Because everything is computed, the canonical text, wire form, and CML round-trip are unchanged.