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, A0 = 1 M: [A](10 s) = exp(-3), [B] = 1 - exp(-3), half-life ln2/k (closed form, rel 1e-6)passed
final_mol_per_L.A{"value": 0.049787068367863944, "rel_tol": 1e-06}final_mol_per_L.B{"value": 0.950212931632136, "rel_tol": 1e-06}half_life_s.A{"value": 2.3104906018664844, "rel_tol": 1e-06}mass_balance_drift_rel≤ 1e-096.66134e-16lockedinside the ranger0002consecutive A -> B -> C, k1 = 2, k2 = 1 /s (Bateman): B peaks at ln(k1/k2)/(k1-k2) = ln 2 s at A0 (k2/k1)^(k2/(k1-k2)) = 0.5 M; [B](5 s) = 2(exp(-5) - exp(-10)) M (closed form, rel 1e-6)passed
peak_time_s.B{"value": 0.6931471805599453, "rel_tol": 1e-06}peak_mol_per_L.B{"value": 0.5, "rel_tol": 1e-06}peak_kind.B= interiormisseddiffersfinal_mol_per_L.B{"value": 0.013385094138645965, "rel_tol": 1e-06}r0003reversible 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 1e-6)passed
final_mol_per_L.A{"value": 0.2, "rel_tol": 1e-06}final_mol_per_L.B{"value": 0.8, "rel_tol": 1e-06}half_life_s.A{"value": 0.39233170120469046, "rel_tol": 1e-06}steady= truetruelockedexact matchr0004second order 2A -> B, rate k[A]^2 per reaction, k = 0.5 L/(mol s): 1/[A] = 1/A0 + 2kt gives [A](9 s) = 0.1 M, half-life 1/(2 k A0) = 1 s; [A] + 2[B] conserved (closed form, rel 1e-6)passed
final_mol_per_L.A{"value": 0.1, "rel_tol": 1e-06}final_mol_per_L.B{"value": 0.45, "rel_tol": 1e-06}half_life_s.A{"value": 1.0, "rel_tol": 1e-06}conserved.0.name= [A] + 2 [B]misseddiffersconserved.0.final_mol_per_L{"value": 1.0, "rel_tol": 1e-09}r0005N2O4 <=> 2 NO2, kf = 4, kr = 1 (Kc = 4 M): (2x)^2/(1-x) = 4 gives x = (sqrt5-1)/2, [NO2] = sqrt5 - 1, [N2O4] = (3 - sqrt5)/2 M; N and O atom totals exact (closed form, rel 1e-6; drift 1e-9)passed
final_mol_per_L.NO2{"value": 1.2360679774997898, "rel_tol": 1e-06}final_mol_per_L.N2O4{"value": 0.3819660112501051, "rel_tol": 1e-06}atoms_balanced= truetruelockedexact matchatoms.N.final_mol_per_L{"value": 2.0, "rel_tol": 1e-09}atoms.O.final_mol_per_L{"value": 4.0, "rel_tol": 1e-09}mass_balance_drift_rel≤ 1e-094.44089e-16lockedinside the ranger0006stiff A -> B -> C, k1 = 1e4, k2 = 1 /s (Bateman, stiffness ratio 1e4): peak at ln(1e4)/9999 s, [B](5 s) = (1e4/9999)(exp(-5) - exp(-5e4)) M (closed form, rel 1e-6)passed
peak_time_s.B{"value": 0.0009211261498125996, "rel_tol": 1e-06}peak_mol_per_L.B{"value": 0.9990792979566508, "rel_tol": 1e-06}final_mol_per_L.B{"value": 0.0067386208611715835, "rel_tol": 1e-06}stiffness_index≥ 1000050005lockedinside the ranger0007source and sink 0 -> A (k = 1 M/s), A -> 0 (k = 2 /s) from A0 = 0: [A] = (1 - exp(-2t))/2, [A](10 s) = 0.5(1 - exp(-20)) M (closed form, rel 1e-6)passed
final_mol_per_L.A{"value": 0.4999999989694232, "rel_tol": 1e-06}mass_balance_drift_rel= lockedexact matchr0008Robertson (1966) stiff test A -> B (0.04), 2B -> C + B (3e7), B + C -> A + C (1e4) at t = 40 s: y1 = 0.7158270687, y2 = 9.185534765e-6, y3 = 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 1e-6 covers the adaptive integrator's accumulated errorpassed
final_mol_per_L.A{"value": 0.7158270687, "rel_tol": 1e-06}final_mol_per_L.B{"value": 9.185534765e-06, "rel_tol": 1e-06}final_mol_per_L.C{"value": 0.2841637457, "rel_tol": 1e-06}conserved.0.drift_rel{"max": 1e-09}
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: 'N2O4 <=> 2 NO2; 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 1e6); 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 (H2O, N2O4, CH3OH; 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 1e-8 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 1e-6 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 ~1e3 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.