Rule-based reaction-network discovery
The v2.x reactivity prototype adds a rule-based discovery engine on top of the existing SMILES canonicalisation and Gillespie kMC solver. The engine applies explicit rules, deduplicates canonical species, records directed elementary edges and converts the result into a kMC configuration.
Status. Implemented with explicit template rules, a SMARTS/SMIRKS adapter for mapped atom charge, hydrogen, element, bond-order and atom creation/removal changes, and GSM barrier refinement, exposed on the Rust, Python, WASM and CLI surfaces. Multi-component
SmirksRuleproducts and MBH refinement remain follow-ups. See the v2.x roadmap.Feature. Core since 2.1.0;
alpha-reaction-networkremains as an empty compatibility alias.
flowchart LR
A[Initial species] --> B[Template/SMIRKS rules]
B --> C[BFS closure]
C --> D[Canonical species]
D --> E[Directed edges + barriers]
E --> F[kMC configuration]
E --> G[Mean-field ODE]
F --> H[kMC trace]
G --> I[ODE trace]
H --> J[Compare populations]
I --> J
Why explicit rules
Automatic reaction discovery has two separate parts:
- deciding which transformations are chemically plausible;
- closing the graph over species and deduplicating.
This prototype implements part 2 and a clean rule contract. A rule owns the chemistry; the engine owns canonicalisation, BFS closure, depth and species limits. That makes a curated mechanism testable without hiding a heuristic.
Rule contract
ReactionRule exposes:
| Method | Meaning |
|---|---|
name | Stable rule identifier |
reactant_count | 1 or 2 in the current engine |
barrier_ev | Activation barrier |
prefactor_s_inv | Optional prefactor |
apply | Return canonical product sets |
TemplateRule is the built-in explicit implementation:
use sci_form::networks::TemplateRule;
let rule = TemplateRule::new(
"C1",
&["C"],
&["CC"],
0.05,
Some(1.0e12),
)?;Reactants and products are canonicalised at construction, so "CCO" and "OCC" are the same species.
SMARTS/SMIRKS adapter
SmirksRule applies a one-component SMIRKS transform through the existing matcher:
use sci_form::networks::SmirksRule;
let rule = SmirksRule::new(
"deprotonate",
"[C:1](=O)[OH:2]>>[C:1](=O)[O-:2]",
0.10,
None,
)?;apply_smirks copies the matched reactant graph and applies the product template: mapped element, formal-charge, hydrogen-count and bond-order changes, product-only mapped atoms and deletion of reactant-only mapped atoms. The result is canonicalised and round-tripped back through the SMILES parser as a consistency check. SmirksRule accepts one-component transforms; multi-component product templates are rejected by the rule adapter, although the public apply_smirks accepts dot-separated reactants.
flowchart LR
A["[C:1](=O)[OH:2]"] --> B["match + atom map<br/>1 → C, 2 → O"]
B --> C["product template<br/>[C:1](=O)[O-:2]"]
C --> D["apply element / charge / H / bonds"]
D --> E["canonical product<br/>C([O-])(C)=O"]
GSM barrier refinement
refine_barrier_with_gsm wraps the existing Growing String Method on a same-atom-count reactant/product pair:
use sci_form::networks::refine_barrier_with_gsm;
let refined = refine_barrier_with_gsm(
"CCO",
&reactant_coords,
&product_coords,
"uff",
&sci_form::gsm::GsmConfig::default(),
)?;
println!("{:.3} eV", refined.barrier_ev);The barrier is E(TS) − E(reactant) in kcal/mol converted to eV. The caller must supply matching atom counts and a backend supported by neb_backend_energy_kcal. Empty/malformed SMILES, non-finite or wrong-length coordinates, an unknown backend and invalid GsmConfig controls are rejected before the string run; backend evaluation failures are propagated instead of becoming an infinite barrier. H₂ with UFF (max_nodes=3, max_iter=2, step_size=0.1, 0.74→1.20 Å) gives barrier 0.05800377327557044 eV (1.337598848091681 kcal/mol), TS 1.8233085007320669 kcal/mol, 3 nodes and 276 energy evaluations. MBH refinement is not yet wired into the network edge.
Discovery
use sci_form::networks::{NetworkDiscoveryConfig, discover_reaction_network};
let config = NetworkDiscoveryConfig {
initial_species: vec!["C".into()],
rules: vec![Box::new(rule)],
max_depth: 3,
max_species: 10,
};
let network = discover_reaction_network(&config)?;The engine runs BFS for max_depth layers. At each layer it applies unimolecular rules to every species and bimolecular rules to every unordered pair. New products are canonicalised, deduplicated and added until no new species appear or max_species is reached.
Result
| Type | Meaning |
|---|---|
NetworkSpecies | Index and canonical SMILES |
NetworkEdge | Reactants, products, rule, barrier and prefactor |
ReactionNetwork | Species, edges and discovery notes |
kMC integration
use sci_form::kinetics::ThermodynamicState;
let kmc = network.to_kmc_config(
&[100, 0, 0],
ThermodynamicState { temperature_k: 500.0, pressure_bar: 1.0 },
1_000,
10.0,
7,
)?;
let result = sci_form::run_kinetic_monte_carlo(&kmc)?;Every edge becomes an irreversible ElementaryStep. The reaction free energy is set to zero because the discovery layer has no thermodynamic data; the barrier and prefactor come from the rule.
Bindings
| Surface | Entry point |
|---|---|
| CLI | sci-form network '<TemplateNetworkConfig-json>' |
| WASM | discover_reaction_network(config_json) |
| Python | discover_reaction_network(config_json), refine_barrier_with_gsm(...) |
Validation
| Gate | Observable | Result |
|---|---|---|
| Linear network | C → CC → CCC | 3 species, 2 edges |
| Canonicalisation | "CCO" vs "OCC" | one species |
| kMC integration | 100 C, 1,000 events | population conserved |
| Invalid product | "Q" | rejected |
| SMIRKS deprotonation | Acetic acid → acetate | [O-] product |
| GSM geometry guard | Mismatched atom counts | rejected |
| Curated networks | Five gas-phase mechanisms | 5/5 recovered (F126) |
| kMC vs ODE | Five networks, 8 seeds | 0.11 % max error (F127) |
| Seed determinism | Replay + depth/species caps | 0 violations (F128) |
| Barrier accuracy | Experimental torsional/inversion barriers | MAE 0.575 kcal/mol (F133) |
Malformed discovery input is an input error: Python raises ValueError for an empty initial-species list, no rules, zero depth/species caps, negative barriers, zero prefactors, empty reactants/products and invalid SMILES. WASM returns {"error": "..."}. Deserialized template rules are canonicalised before matching, so OCC matches the canonical CCO species and an invalid fragment is rejected instead of silently producing no match.
Template-network validation
TemplateNetworkConfig::discover (also exported on the JSON surfaces as discover_template_network, with discover_reaction_network kept as a compatibility name) rejects empty initial-species SMILES, empty rule reactant/product SMILES, duplicate rule names, a non-finite/negative barrier, a non-positive prefactor, and empty rule lists. max_depth is capped at 64 and max_species at 100,000; larger values are validation errors rather than unbounded BFS allocations. Rule SMILES are canonicalised before matching, so OCC and CCO are the same reactant.
Limitations
- Template rules are explicit;
SmirksRulesupports one-component mapped transforms, including atom creation/removal and element changes. - Multi-component
SmirksRuleproduct templates are rejected. - Only unimolecular and bimolecular rules.
- GSM refinement needs the caller to supply same-atom-count 3D geometries.
- MBH refinement is not wired into the network edge.
- No automatic barrier estimation or thermodynamic consistency.
- No reaction free energies, so kMC uses
ΔG_reaction = 0. - The species limit can truncate the network; skipped products are recorded in
notes. - Bimolecular enumeration is combinatorial but bounded by
max_species. - No curated multi-step mechanism benchmark yet.
Next steps
- Extend
SmirksRuleto multi-component products (the publicapply_smirksalready accepts them). - Wire MBH refinement into the network edge.
- Add thermodynamic cycles and reverse rates.
- Add a published multi-step mechanism benchmark.
- Add site-based surface kMC.