#reaction #deterministic #stochastic #simulation #rate #count #parameters

crn

Stochastic and deterministic simulation of chemical reaction networks

3 releases

0.1.2 Aug 13, 2023
0.1.1 Aug 10, 2023
0.1.0 Aug 8, 2023

#851 in Science

MIT license

250KB
630 lines

crn

Crates.io Documentation

crn can simulate both stochastic and deterministic CRNs with StoCrn and DetCrn, respectively.

To create your own CRN, first declare the initial counts of each molecule, and then add the reactions, each optionally followed by a rate parameter (10 in the first reaction):

let crn_string = "
a = 10;
b = 5;
c = 0;
a + b -> 2c : 10;
c -> 3b;
";

Pass the whole string to the parser:

let mut crn = StoCrn::parse(crn_string).unwrap()

Now let's simulate it for 3 seconds of virtual time:

let data = crn.simulate_history(3.0);

Some premade CRNs can be found in the presets module.

Run this for a graphical demonstration!

cargo run --release --example gui

Note: deterministic simulations tend to be unstable with large numbers -- I'm still working on this. Try scaling down all initial amounts (can be noninteger, unlike stochastic simulations) if you're having issues.

gui demo

Dependencies

~8–27MB
~391K SLoC