reaction_network
Mass-action kinetics of a reaction network written as text ('A + B → C; k = 0.5', 'A ≤> B; kf = 2; kr = 0.5', sources '0 → A', sinks 'A → 0'), integrated by 3-stage Radau IIA (order 5, L-stable) with an exact Jacobian and step-doubling error control.
Gives concentration histories, final state, half-lives, times and heights of maxima, the conserved totals (left null space of the stoichiometric matrix) and their drift, and an atom balance from formulas or a given composition.
Rate of a reaction = k times the product of reactant concentrations raised to their coefficients; k is in (mol/L)^(1-order)/s.
- Field
- Chemistry
- Version
- 0.1.0
- Runs as
- Compiled (Rust)
- Typical run
- 0.1 s
Compiled from source: run sh packs/install.sh once before admitting it.
Known answers it must pass
r0001first order A → B, k = 0.3 /s, A₀ = 1 M: [A](10 s) = exp(-3), [B] = 1 - exp(-3), half-life ln2/k (closed form, rel 10⁻⁶)passed
final_mol_per_L.A= 0.049787, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagefinal_mol_per_L.B= 0.950213, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagehalf_life_s.A= 2.310491, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagemass_balance_drift_rel≤ 10⁻⁹6.66134 × 10⁻¹⁶lockedinside the ranger0002consecutive A → B → C, k₁ = 2, k₂ = 1 /s (Bateman): B peaks at ln(k₁/k₂)/(k₁-k₂) = ln 2 s at A₀ (k₂/k₁)^(k₂/(k₁-k₂)) = 0.5 M; [B](5 s) = 2(exp(-5) - exp(-10)) M (closed form, rel 10⁻⁶)passed
peak_time_s.B= 0.693147, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagepeak_mol_per_L.B= 0.5, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagepeak_kind.B= interiormisseddiffersfinal_mol_per_L.B= 0.013385, within 1.000000 × 10⁻⁶ relativereading not recorded on this pager0003reversible A ≤> B, kf = 2, kr = 0.5 /s: equilibrium [B]/[A] = kf/kr = 4 so [A] = 0.2, [B] = 0.8 M; [A] falls to half at ln(8/3)/(kf+kr) s (closed form, rel 10⁻⁶)passed
final_mol_per_L.A= 0.2, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagefinal_mol_per_L.B= 0.8, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagehalf_life_s.A= 0.392332, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagesteady= truetruelockedexact matchr0004second order 2A → B, rate k[A]² per reaction, k = 0.5 L/(mol s): 1/[A] = 1/A₀ + 2kt gives [A](9 s) = 0.1 M, half-life 1/(2 k A₀) = 1 s; [A] + 2[B] conserved (closed form, rel 10⁻⁶)passed
final_mol_per_L.A= 0.1, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagefinal_mol_per_L.B= 0.45, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagehalf_life_s.A= 1, within 1.000000 × 10⁻⁶ relativereading not recorded on this pageconserved.0.name= [A] + 2 [B]misseddiffersconserved.0.final_mol_per_L= 1, within 1.000000 × 10⁻⁹ relativereading not recorded on this pager0005N₂O₄ ≤> 2 NO₂, kf = 4, kr = 1 (Kc = 4 M): (2x)²/(1-x) = 4 gives x = (sqrt5-1)/2, [NO₂] = sqrt5 - 1, [N₂O₄] = (3 - sqrt5)/2 M; N and O atom totals exact (closed form, rel 10⁻⁶; drift 10⁻⁹)passed
final_mol_per_L.NO2= 1.236068, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagefinal_mol_per_L.N2O4= 0.381966, within 1.000000 × 10⁻⁶ relativereading not recorded on this pageatoms_balanced= truetruelockedexact matchatoms.N.final_mol_per_L= 2, within 1.000000 × 10⁻⁹ relativereading not recorded on this pageatoms.O.final_mol_per_L= 4, within 1.000000 × 10⁻⁹ relativereading not recorded on this pagemass_balance_drift_rel≤ 10⁻⁹4.44089 × 10⁻¹⁶lockedinside the ranger0006stiff A → B → C, k₁ = 10⁴, k₂ = 1 /s (Bateman, stiffness ratio 10⁴): peak at ln(10⁴)/9999 s, [B](5 s) = (10⁴/9999)(exp(-5) - exp(-5 × 10⁴)) M (closed form, rel 10⁻⁶)passed
peak_time_s.B= 9.211261 × 10⁻⁴, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagepeak_mol_per_L.B= 0.999079, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagefinal_mol_per_L.B= 0.006739, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagestiffness_index≥ 1000050005lockedinside the ranger0007source and sink 0 → A (k = 1 M/s), A → 0 (k = 2 /s) from A₀ = 0: [A] = (1 - exp(-2t))/2, [A](10 s) = 0.5(1 - exp(-20)) M (closed form, rel 10⁻⁶)passed
final_mol_per_L.A= 0.5, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagemass_balance_drift_rel= lockedexact matchr0008Robertson (1966) stiff test A → B (0.04), 2B → C + B (3 × 10⁷), B + C → A + C (10⁴) at t = 40 s: y₁ = 0.7158270687, y₂ = 9.185534765 × 10⁻⁶, y₃ = 0.2841637457, from an independent fixed-grid 3-stage Radau IIA integration in plain Python that agrees to 13 digits at three step sizes (
packs/science2/refs/reaction_network_robertson.py) and matches the 7 digits usually quoted for this benchmark; rel 10⁻⁶ covers the adaptive integrator's accumulated errorpassedfinal_mol_per_L.A= 0.715827, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagefinal_mol_per_L.B= 9.185535 × 10⁻⁶, within 1.000000 × 10⁻⁶ relativereading not recorded on this pagefinal_mol_per_L.C= 0.284164, within 1.000000 × 10⁻⁶ relativereading not recorded on this pageconserved.0.drift_relat most 1.000000 × 10⁻⁹reading not recorded on this page
Each line is one reading the kernel checked. The bright band is the tolerance; the needle is the value the instrument actually returned when it was admitted. A needle near the centre line used little of its tolerance.
Inputs
| Name | Unit | Default | Meaning |
|---|---|---|---|
network | A -> B; k = 2 B -> C; k = 1 | Reactions and their rate constants, separated by ';' or new lines. One way: 'A + B → C; k = 0.5'. Both ways: 'N₂O₄ ≤> 2 NO₂; kf = 4; kr = 1'. Source '0 → A', sink 'A → 0'. Whole coefficients 1 to 6; at most 40 species and 200 one-way steps; '#' starts a comment. k is in (mol/L)^(1-order)/s, order = sum of the reactant coefficients. | |
initial | {"A": 1.0} | Starting concentration of each species in mol/L (0 to 10⁶); species left out start at 0. | |
t_end_s | s | 10.0 | Length of the run. |
n_out | 1 | 201 | Rows of the history written to out/concentrations.csv (equal intervals, end points included). |
rel_tol | 1 | 1e-09 | Relative error allowed per step. |
abs_tol_mol_per_L | mol/L | 1e-12 | Concentrations below this are not resolved. |
formulas | false | Read species names as plain formulas (H₂O, N₂O₄, CH₃OH; no brackets or charges) and check that every reaction balances its atoms and that the atom totals stay put. | |
composition | Atoms of each species, for an atom balance with names that are not formulas: {"E": {"X": 1}, "ES": {"X": 1, "S": 1}}. Overrides formulas. |
Readings
| Name | Unit | Meaning |
|---|---|---|
ok | 1 | No negative concentration beyond the tolerance, no conserved total drifting by more than both 10⁻⁸ of its size and abs_tol times its coefficient sum, every reaction balances its atoms. |
warnings | 1 | |
species | 1 | |
n_species | 1 | |
n_reactions | 1 | One-way steps; a reversible reaction counts twice. |
reactions | k is in (mol/L)^(1-order)/s. | |
t_end_s | s | |
initial_mol_per_L | ||
final_mol_per_L | ||
final_rate_mol_per_L_per_s | ||
half_life_s | First time a species falls to half its starting concentration; null if it never does or starts at 0. | |
peak_time_s | Time of the largest concentration: an interior maximum, the start, or the end. | |
peak_mol_per_L | ||
peak_kind | 1 | |
maxima_s | Every interior maximum of each species. | |
species_table | ||
conserved | Integer combinations of concentrations no reaction changes (computed from the stoichiometric matrix). | |
mass_balance_drift_rel | 1 | Largest drift of a conserved total or atom total over the run, relative to its size; null if there is none to check. |
mass_balance_drift_mol_per_L | mol/L | Largest absolute drift of a conserved total or atom total over the run. |
atoms | ||
atoms_balanced | 1 | |
steady | 1 | The largest net rate times t_end is below 10⁻⁶ of the total concentration. |
residual_rate_per_s | 1/s | |
stiffness_index | 1 | Largest row sum of |Jacobian| times t_end over the output grid: above ~10³ an explicit method would struggle. |
most_negative_mol_per_L | mol/L | |
n_steps | 1 | |
n_rejected | 1 | |
files | 1 | out/concentrations.csv (t_s and one column per species, mol/L), out/species.csv (one row per species). |
Try the call
Change a value and the command updates. Nothing runs here; paste it into your terminal or give it to your agent.