agentleFS
90184479018447/julia-pro-p/skills/catalyst-reactions/SKILL.md

catalyst-reactions

Skill0 starsChanged 4 days agoMITView on GitHub

Reaction networks with Catalyst.jl: mass-action and Michaelis-Menten kinetics, deterministic versus stochastic regime, conservation and balance checks, and SBML interop. Use when modelling kinetics or a mechanism.

The file

Files
SKILL.md

Reaction networks with Catalyst.jl

A reaction network is a claim about mechanism plus a claim about regime. The mechanism is the stoichiometry and the rate laws; the regime decides whether the ODE, the jump process, or the SDE is the honest description. Catalyst compiles one DSL into all three, which is exactly why the choice has to be made deliberately.

Depth

graph-theory — the network as a graph: adjacency and Laplacian, connected components (which species can never reach which), and stoichiometric centrality for locating the rate-limiting node.

Choose the regime

Population of the rarest speciesModelWhy
≳ 10⁴ per speciesODE (convert(ODESystem, rn))noise is smaller than every other error
10²–10⁴chemical Langevin (convert(SDESystem, rn))Gaussian noise around a smooth mean
≲ 10², or extinction and switching matterjump (JumpProblem(rn, dprob, Direct()) + SSAStepper())the discreteness is the phenomenon
continuous flow punctuated by rare eventsPDMPcheaper than SSA, and no Gaussian assumption

The regime is per species, not per network: a reactor with 10⁶ molecules of substrate and 5 of catalyst is a stiff ODE in the substrate and a jump process in the catalyst. Splitting by timescale (quasi-steady state for the fast subset) is usually the cheaper answer than either extreme.

Building the network

using Catalyst, DifferentialEquations

rn = @reaction_network begin
    k1, A + B --> C
    k2, C --> A + B
    d,  C --> ∅            # outflow: the reactor is open
end k1 k2 d

odesys = convert(ODESystem, rn)
prob = ODEProblem(odesys, [:A => 10.0, :B => 10.0, :C => 0.0], (0.0, 10.0), [:k1 => 0.1, :k2 => 0.05, :d => 0.01])
sol  = solve(prob, Tsit5())
  • Mass action unless stated. k, A + B --> C means rate k·[A]·[B]; the unit of k therefore depends on the order (M⁻¹s⁻¹ for second order, s⁻¹ for first) and a mechanism whose rate constants have inconsistent units is a modelling bug that no solver will report.
  • A custom rate law overrides the default: k*[A]^2/(K + [A]), A --> P for a saturating step. Write the law only when the mechanism requires it; mass action is the assumption you can defend.
  • Open versus closed. Without a flow term (--> ∅, ∅ --> X) the network conserves total mass and the conserved quantities are a check; with one, it does not, and expecting conservation will make a correct simulation look broken.
  • Michaelis-Menten is an approximation: mm, S + E --> E + P (kcat, Km) assumes E ≪ S and quasi-steady state. At S ~ Km or with comparable enzyme, simulate the elementary steps instead, or the fitted kcat absorbs the error.

Stochastic simulation

using Catalyst, JumpProcesses, DifferentialEquations

dprob = DiscreteProblem(rn, [:A => 100, :B => 100, :C => 0], (0.0, 50.0), [:k1 => 0.01, :k2 => 0.1, :d => 0.05])
jprob = JumpProblem(rn, dprob, Direct())      # exact SSA; DirectCR for large networks
sols  = solve(jprob, SSAStepper(), EnsembleThreads(); trajectories = 1000)

Rates must be propensities, meaning k·A·B counts reaction opportunities, not a concentration rate constant: the conversion from a deterministic k to a stochastic one involves volume, and ignoring it changes the mean of the process. Report ensemble statistics (mean ± sd across trajectories), never a single trajectory, and check that the mean of the jump process approaches the ODE solution as the population grows — if it does not, the units are wrong.

Conservation, balance, and steady state

  • Conserved quantities come from the stoichiometry: conservationlaws(rn) returns the linear combinations of species that no reaction changes. Check them in a simulation (drift should be at solver-tolerance level) and use them to reduce the system when the state is large.
  • Atom and charge balance is a stronger check at the mechanism level: every reaction must balance each element and the charge. A network that balances mass but not charge is missing an ion.
  • Steady state: SteadyStateDiffEq with SSProblem(odesys, DynamicSS(Tsit5())), or integrate long enough that ‖du‖ is below tolerance. A steady state that depends on the initial guess where the mechanism has multiple steady states is the interesting result, not a convergence failure — scan the initial conditions.
  • Sensitivity to rate constants tells you which parameter the answer needs: ForwardDiffSensitivity for a handful, adjoints for many — see ../differential-equations/SKILL.md.

SBML interop

NeedTool
read or write SBML, round-trip a published modelSBMLReader / SBMLWriter from SBML.jl
exact SSA, index reduction, symbolic Jacobians, one DSL to ODE/SDE/jumpCatalyst.jl

SBML is the interchange format for the mechanism, not for the analysis: round-trip it, then re-derive units and regime in the target tool, because SBML stores the model without the modelling decision.

Traps

  • Rate constants with inconsistent units. An order-2 reaction with k in s⁻¹ silently rescales the whole network.
  • Fitting a Michaelis-Menten kcat to data taken at S ≲ Km. The fit is good and the parameter means nothing outside that range.
  • Single stochastic trajectory presented as the result. The variance is the point of the stochastic model; one run is an anecdote.
  • Mass-action assumed for a catalysed step. Then the saturating kinetics appear as a bad fit and get attributed to the data.
  • Conservation expected in an open reactor. The flow term is the physics; check the balance with it, not against it.

Done when

A @reaction_network exists with every species, rate constant with its unit, and initial condition; the system type matches the regime argued from the rarest population (ODE, SDE, jump, or a split); the conserved quantities from conservationlaws are checked against the simulation and every reaction balances elements and charge; and the stochastic results are ensemble statistics with the deterministic limit verified as the population grows.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.