Kinetic Monte Carlo for reaction networks
The second half of the v2.x reactivity workflow is a stochastic solver for an elementary-step network. The existing kinetics module already evaluates HTST rates and integrates a deterministic microkinetic ODE; the new module propagates integer species counts with the Gillespie direct method.
Status. Implemented and exposed on the Rust, Python, WASM and CLI surfaces for an explicit network. Rule-based discovery that feeds it is documented in reaction networks; surface kMC is pending. See the v2.x roadmap.
Feature.
alpha-reaction-network(included inalpha-v2).
Why kMC
A deterministic ODE is the right tool for large, well-mixed populations. A surface reaction, a small cluster or a catalytic site can have populations of a few molecules, where fluctuations and rare events matter. kMC samples the same master equation stochastically:
with integer counts and a waiting time drawn from the total propensity.
Rates and propensities
Each irreversible step j has an HTST forward rate k_j. Its propensity is
where n_r is the count of reactant r and ν its stoichiometric coefficient. The binomial factor is the number of ways to choose the reacting molecules from the available population.
The total propensity is
The waiting time is
and the firing step is chosen with probability a_j / a_0.
Algorithm
- Evaluate every HTST rate at the requested temperature and pressure.
- Compute the propensity of every step from the current integer counts.
- Draw
τand the firing step. - Subtract reactants, add products, record the event.
- Repeat until
max_eventsormax_time_s.
Reversible chemistry is represented by two irreversible steps. The solver does not guess a reverse direction from a reaction free energy; that keeps the network explicit and auditable.
API
use sci_form::kinetics::{ElementaryStep, ThermodynamicState};
use sci_form::kmc::{KmcConfig, KmcSpecies, KmcStep};
use sci_form::run_kinetic_monte_carlo;
let config = KmcConfig {
species: vec![
KmcSpecies { id: "A".into(), initial_count: 100 },
KmcSpecies { id: "B".into(), initial_count: 0 },
],
steps: vec![KmcStep {
step: ElementaryStep {
step_id: "A->B".into(),
activation_free_energy_ev: 0.05,
reaction_free_energy_ev: -0.1,
prefactor_s_inv: Some(1.0e12),
},
reactants: vec![(0, 1)],
products: vec![(1, 1)],
}],
state: ThermodynamicState { temperature_k: 500.0, pressure_bar: 1.0 },
max_events: 10_000,
max_time_s: 10.0,
seed: 7,
frame_stride: 100,
};
let result = run_kinetic_monte_carlo(&config)?;
println!("{} events, final A={}, B={}",
result.events.len(), result.final_counts[0], result.final_counts[1]);Output
| Type | Meaning |
|---|---|
KmcEvent | Event index, time, firing step, propensity and counts |
KmcFrame | Sampled time, event index, species and counts |
KmcResult | Events, frames, final counts, final time, stop reason and notes |
Time is in seconds, rates in s⁻¹ and counts are dimensionless integers.
Validation
| Gate | Observable | Result |
|---|---|---|
| Mass conservation | A + B after irreversible conversion | unchanged |
| High barrier | Events in a 1 ps window | none; stops on time |
| Binomial coefficient | C(5,0), C(5,1), C(5,2), C(2,3) | 1, 5, 10, 0 |
| Invalid species index | Network validation | rejected |
| Curated networks | GRI-Mech/NIST/JPL five-network set | 5/5 recovered (F126) |
| kMC vs mean-field ODE | Five networks, 8 seeds | 0.11 % max error (F127) |
| Seed determinism | Same-seed replay + depth/species caps | 0 violations (F128) |
| Barrier accuracy | Experimental torsional/inversion barriers | MAE 0.575 kcal/mol (F133) |
Malformed configurations are input errors: Python raises ValueError for max_events=0, frame_stride=0, max_time_s<=0/NaN, empty species/steps, unknown species indices, zero coefficients and a non-positive/non-finite temperature or pressure. WASM returns the canonical {"error": "..."}.
F133 validates the barrier engine on torsional and inversion barriers; the bimolecular curated networks still use literature barriers as rule inputs.
Bindings
| Surface | Entry point |
|---|---|
| CLI | sci-form kmc '<KmcConfig-json>' |
| WASM | run_kinetic_monte_carlo(config_json) |
| Python | run_kinetic_monte_carlo(config_json) |
Python returns the JSON encoding of KmcResult.
Limitations
- The network is supplied by the caller; automatic reaction discovery is not implemented yet.
- Only irreversible steps are accepted. Encode reversible steps explicitly.
- Counts are integers; fractional populations and continuous concentrations belong to the deterministic solver.
- The propensity uses binomial consumption, not a continuum mass-action term.
- There is no spatial resolution, diffusion or surface lattice. A site-based kMC is a follow-up.
- The RNG is seeded and deterministic for a single thread; parallel trajectories need one seed per replica.
Next steps
- Add rule-based network generation from SMIRKS and graph transforms.
- Add site-based surface kMC with adsorption, desorption and diffusion.
- Add uncertainty propagation from the barrier distribution.
- Compare against the deterministic microkinetic solver in the fast-rate limit.
- Add a curated catalytic network benchmark.