Macro rebop::define_system

source ·
macro_rules! define_system {
    (
      $($param:ident)*;
      $name:ident { $($species:ident),* }
      $($rname:ident:
          $($($nr:literal)? $r:ident)? $(+ $($tnr:literal)? $tr:ident)* =>
          $($($np:literal)? $p:ident)? $(+ $($tnp:literal)? $tp:ident)*
          @ $rate:expr)*
      ) => { ... };
}
Expand description

Definition of a chemical reaction network.

This macro creates a struct containing state variables, parameter values and a pseudo-random number generator. The state variables and parameter values can be modified directly. It implements three functions: new, with_parameters and advance_until.

The function new creates a new instance of the structure with all state variables set to 0 and all parameter values set to f64:NAN. The parameter values have then to be initialized manually. If a NAN remains at the time of the simulation, no reaction will happen.

The function with_parameters is an alternate initializer that allows to give directly all the parameter values.

The function advance_until simulates the system until the specified time.

§Example

use rebop::define_system;

define_system! {
    rtx rtl rdi rdm rdp;
    Dimers { gene, mRNA, protein, dimer }
    transcription   : gene      => gene + mRNA      @ rtx
    translation     : mRNA      => mRNA + protein   @ rtl
    dimerization    : 2 protein => dimer            @ rdi
    decay_mRNA      : mRNA      =>                  @ rdm
    decay_prot      : protein   =>                  @ rdp
}
let mut dimers = Dimers::with_parameters(25., 1000., 0.001, 0.1, 1.);
//                                       rtx,   rtl,   rdi, rdm,rdp
// but we could also have done
// let mut dimers = Dimers::new();
// dimers.rtx = 25.;
// etc.
dimers.gene = 1;
dimers.advance_until(1.);
println!("t = {}, dimer = {}", dimers.t, dimers.dimer);