MEDYAN.def_reaction!

Tuple{MEDYAN.SysDef, AbstractString}

def_reaction!(s::SysDef, reaction_expr::AbstractString; base_rate, invvolumepower=0, affect!=nothing)

Add a chem_voxel reaction to the system definition. Returns s.

reaction_expr is a string describing the reaction. The format depends on whether affect! is provided:

  • Without affect!: reaction_expr must contain "-->" to separate reactants from products. Stoichiometry is computed automatically.
  • With affect!: reaction_expr lists only the reactants (no "-->"). Net stoichiometry is zero; the callback handles all state changes.

reaction_expr is comprised of reactant and product parts separated by "-->". All whitespace is ignored. Each side is split by "+" to get species names. Repeated or extra "+" are ignored. A species name can be prepended by a positive integer to represent multiple copies (e.g., "2diffusing.A").

Species name prefixes:

  • diffusing.X — diffusing species
  • fixedspecies.X — fixed (non-diffusing) species
  • filamentsite.T.N — filament monomer site
  • filamentendsite.T.N — filament end site
  • decimated_2mon_site.N — decimated two-monomer site

Keyword Arguments

Rate

  • base_rate::Float64: Rate constant. Units: (nm³)^invvolumepower / s. Rate constants are stochastic rate constants in the sense of Gillespie (1976).
  • invvolumepower::Int = 0: volumefactor = (1/volume)^invvolumepower where volume is the chem_voxel volume in nm³. Typically 0 for unimolecular, 1 for bimolecular, 2 for trimolecular.

Callback (optional)

  • affect!: Callback fired when the reaction occurs. Signature: (c::Context; chem_voxel::Int, kwargs...) -> Any. When provided, reaction_expr must not contain "-->".

Examples

using MEDYAN
s = MEDYAN.SysDef()
def_diffusing_species!(s, :A; coeff=2.5e7)
def_diffusing_species!(s, :B; coeff=2.5e7)
def_diffusing_species!(s, :C; coeff=2.5e7)

# Bimolecular: A + B → C
def_reaction!(s, "diffusing.A + diffusing.B --> diffusing.C";
    base_rate = 1.5e6,
    invvolumepower = 1,
)

# Unimolecular: C → A + B
def_reaction!(s, "diffusing.C --> diffusing.A + diffusing.B";
    base_rate = 1.75,
)

# Zero-order creation
def_reaction!(s, " --> diffusing.A + diffusing.B";
    base_rate = 1.75,
)

# With a callback (reactants only, no "-->")
def_reaction!(s, "diffusing.A + diffusing.B";
    base_rate = 1e8,
    invvolumepower = 1,
    affect! = (c; chem_voxel, kwargs...) -> begin
        # custom logic here
        nothing
    end,
)