Expand description
§tpt-sci-reaction-network
A species / rate / stoichiometry DSL for compartmental models — the
Rust equivalent of Julia’s Catalyst.jl
— built from scratch for the tpt-science pillar.
Given a chemical reaction network (species, reactions, and rate laws), the crate compiles the law of mass action into the deterministic ODE
dy/dt = S · r(y, p)where S is the stoichiometry matrix and r the per-reaction rate vector,
and hands the result to tpt_sci_ode for integration. It also exposes the
stoichiometry matrix and rate vector directly for inspection, parameter
estimation, or coupling into a larger multi-scale model.
In addition to the deterministic mass-action ODE, the crate provides three
stochastic backends operating on the same IR: exact trajectories via
ReactionSystem::simulate_ssa (Gillespie’s direct method), approximate
but much faster trajectories via ReactionSystem::simulate_tau_leaping
(explicit tau-leaping, Poisson-distributed reaction counts per step), and
the diffusion-limit ReactionSystem::simulate_cle (the Chemical
Langevin Equation, Euler–Maruyama with Gaussian noise) — see
crate::tau_leap for the tradeoffs between them.
Beyond simulation, ReactionSystem::conservation_laws finds linear
conservation laws (the left null space of the stoichiometry matrix) for
structural analysis of a network, and ReactionNetwork::from_sbml reads
a practical subset of SBML XML directly into this crate’s IR (see
crate::sbml for exactly what subset).
This is the v1 scope from spec.txt / registry.toml: a CRN IR, a
mass-action ODE builder, exact/tau-leaping/CLE stochastic backends, a
minimal SBML reader, and conservation-law detection. (The previous plan
deferred the stochastic backend to wrapping rebop; it is now implemented
from scratch instead.)
§Building models
Two equivalent ways to define a model:
- Programmatically with
ReactionNetwork, registering species and parameters by name and appending reactions with explicit indices. - Textually with the Catalyst.jl-style
ReactionNetwork::from_dsl, e.g.kB, S + E --> SE.
§Example
Michaelis–Menten enzyme kinetics (S + E ⇌ SE → P + E):
use tpt_sci_ode::Method;
use tpt_sci_reaction_network::ReactionNetwork;
let model = ReactionNetwork::from_dsl(
"kB, S + E --> SE
kD, SE --> S + E
kP, SE --> P + E",
).unwrap();
let mut model = model;
model.set_parameter("kB", 0.01).unwrap();
model.set_parameter("kD", 0.1).unwrap();
model.set_parameter("kP", 0.1).unwrap();
// E + SE is conserved: total enzyme stays at its initial 10.
let y0 = model.initial_state(&[("S", 50.0), ("E", 10.0)]).unwrap();
let prob = model.to_ode_problem(&y0, 0.0).unwrap();
let y = prob.solve(Method::Bdf, 200.0).unwrap();
let e = model.species_index("E").unwrap();
let se = model.species_index("SE").unwrap();
assert!((y[e] + y[se] - 10.0).abs() < 1e-6);Licensed under either of MIT or Apache-2.0 at your option.
Re-exports§
pub use error::ReactionNetworkError;pub use model::RateLaw;pub use model::Reaction;pub use model::ReactionNetwork;pub use model::ReactionSystem;pub use model::Term;pub use sbml::SbmlModel;pub use ssa::SsaTrajectory;pub use tau_leap::TauLeapConfig;
Modules§
- analysis
- Stoichiometric network analysis: linear conservation-law detection.
- error
- model
- ode
- sbml
- Minimal SBML (Systems Biology Markup Language) reader.
- ssa
- Stochastic simulation (Gillespie’s direct method) for reaction networks.
- tau_
leap - Explicit tau-leaping and the Chemical Langevin Equation (CLE): two
approximate stochastic integrators that complement the exact SSA in
crate::ssa.