src/sys_def.jl
MEDYAN.add_diffusion_coeff!
MEDYAN.add_filament_params!
Add the filament parameters to the system. Return s.
MEDYAN.addfilamentsite!
MEDYAN.addfilamentendsite!
MEDYAN.add_decimated_2mon_site!
MEDYAN.addpossiblecadherinsite!
MEDYAN.addmembranesite!
MEDYAN.add_link_type!
Add a new link type to the system definition. Links represent connections between simulation elements (filament monomers, filament tips, anchors, membrane vertices) that can have associated mechanical bonds and chemical reactions.
Keyword Arguments
name::Symbol: Unique identifier for this link type.description::String="": Human-readable description of the link’s purpose.places::Vector{<:Place}: The places this link connects. Each place can be:FilaMonoIdx(): A filament monomerFilaTipIdx(): A filament tip (plus or minus end)Anchor(): A free-floating anchor point (e.g., membrane-bound protein)BallIdx(): A ball (spherical object)MembVertIdx(): A membrane vertex
bonds::Vector: Mechanical bonds between places. Each bond is aNamedTuplewith:bond: Bond type (e.g.,DistanceRestraint(), customBondsubtype)input::Tuple{Int...}: Which places the bond connectsparam::NamedTuple: Fixed parameters (e.g., spring constantk)state::NamedTuple: Mutable state (e.g., rest lengthL0)enabled::Bool=true: Whether bond is active by default
reactions::Vector{Vector}: Reactions at each place. Each reaction is aNamedTuple:Required fields:
name::Symbol: Unique identifier for this reaction within the place.affect!: Callback(c::Context; link, chem_voxel, reaction_id, place_idx, kwargs...) -> Intthat executes the reaction. Return 1 on success, 0 to reject. Forfila_cutoffreactions, also receivesplace(the nearby filament monomer).rate: Function(c::Context; link, link_data, place_idx, link_state, kwargs...) -> Float64returning the state-dependent rate factor. For multi-site binding, return the number of available sites (e.g.,NPF_MAX_ACTIN - link_state.num_actin).
Optional fields:
base_rate::Float64 = 1.0: Rate constant multiplier. For bimolecular reactions withinvvolumepower=1, use units of nm³/s (e.g., diffusion-limited rate k_D = 4πDR ≈ 1.57×10⁹ nm³/s for D=25 μm²/s, R=5 nm). Separating large rate constants from small integer multipliers inrateavoids overflow.invvolumepower::Int64 = 0: Volume scaling. Set to 1 for bimolecular (nm³/s), 0 for unimolecular (1/s).reactants_extra::String = "": Additional reactants like"diffusing.ARP23". Makes propensity proportional to these species counts.fila_cutoff::Tuple{Symbol, Float64} = nothing: If set, e.g.,(:actin, 50.0), rate is multiplied by nearby filament monomers within cutoff (nm), andaffect!receives one such monomer asplace.enabled::Bool = true: Whether reaction is active by default.
param::NamedTuple=(;): Fixed parameters for the link type.state::NamedTuple=(;): Initial mutable state (e.g.,(num_bound=Int32(0),)).
Example: Membrane-bound NPF cluster
MEDYAN.add_link_type!(s;
name=:npf_anchor,
description="Nucleation promoting factor anchored to membrane",
places=[Anchor()],
state=(;
num_arp23 = Int32(0), # bound ARP2/3 count
num_actin = Int32(0), # bound actin count
),
reactions=[
[
# Bimolecular binding: NPF + diffusing ARP2/3 → NPF·ARP2/3
(;
name = :arp23_bind,
affect! = (c; link, chem_voxel, kwargs...) -> let
link_state = get_state(c, link)
update_link!(c, link; state=(num_arp23=link_state.num_arp23 + Int32(1),))
add_diffusing_count!(c; species=:ARP23, chem_voxel, amount=-1)
1
end,
rate = (c; link_state, kwargs...) -> NPF_MAX_ARP23 - link_state.num_arp23,
base_rate = 5E7, # nm³/s
reactants_extra = "diffusing.ARP23",
invvolumepower = 1,
),
# Unimolecular unbinding: NPF·ARP2/3 → NPF + ARP2/3
(;
name = :arp23_unbind,
affect! = (c; link, chem_voxel, kwargs...) -> let
link_state = get_state(c, link)
update_link!(c, link; state=(num_arp23=link_state.num_arp23 - Int32(1),))
add_diffusing_count!(c; species=:ARP23, chem_voxel, amount=+1)
1
end,
rate = (c; link_state, kwargs...) -> link_state.num_arp23,
base_rate = 0.01, # 1/s per bound ARP2/3
),
],
],
)MEDYAN.addreaction!
Add a reaction to the system. Return s
reactionexpr is a string describing the reaction stoichiometry
reactionexpr is comprised of reactant and product parts seperated by a "-->"
All whitespace characters are ignored.
Each side is then split by "+" to get the species names.
Repeated or extra "+" are ignored.
A species name can be prepended by a positive integer to represent multiple copies.
rate::Float64: Base rate for the reaction. ((nm³)^(invvolumepower)/s) rate constants correspond to stochastic rate constants in the sense used by Gillespie (J. Comp. Phys., 1976, 22 (4)).invvolumepower::Int:volumefactor= (1/volume)^invvolumepowerwherevolumeis the volume of the compartment in nm³. Generally this is 0 for reactions without another diffusing reactant, and 1 if there is another diffusing reactant.
Example good reactionexpr
"diffusing.a + diffusing.b --> diffusing.c"
"diffusing.c --> diffusing.a + diffusing.b"
"+ + diffusing.c + --> + diffusing.a + + diffusing.b + +"
" --> diffusing.a + diffusing.b"
"diffusing.a + diffusing.b --> "
"diffusing.a + diffusing.a --> "
"2diffusing.a --> "
"2diffusing.a --> 20diffusing.a"
"diffusing.c + diffusing.b --> diffusing.c + diffusing.b"
"fixedspecies.rate1b --> fixedspecies.g"
"fixedspecies.rate1b + fixedspecies.g --> fixedspecies.g"
"fixedspecies.rate1b + 23fixedspecies.g --> fixedspecies.g"
"fixedspecies.g --> fixedspecies.rate1b + 23fixedspecies.g"
"fixedspecies.g + fixedspecies.rate1b--> 2fixedspecies.rate1b + 23fixedspecies.g"
"filamentsite.MT.d --> filamentsite.MT.d"
"filamentsite.MT.d + diffusing.a --> filamentsite.MT.d"
"fixedspecies.g --> diffusing.a"
"diffusing.a --> fixedspecies.g"
"filamentsite.actin.pm + diffusing.a --> filamentsite.actin.pm"MEDYAN.addreactioncallback!
Like addreaction! but also adds callback. callback is called when the reaction happens with input of MEDYAN.Context and Int the compartment id where the reaction happened.
The reaction should normally have no net stoichiometry because the callback should handle updating species counts. If an AbstractString is passed instead of a CompartmentReaction for the reaction, that string will be parsed to determine the reactants. The net stoichiometry will be zero.
MEDYAN.errorcheck_addcallback(callback,s::SysDef) can optionally be overloaded to add errorchecking when the callback is added.
Callback for bulk reactions: Context -> Nothing.
MEDYAN.addfilament_reaction!
Add filament reaction. Return s. Add a filamentsite and reaction with callback to change the monomer state. This can be used for filament aging, filament catalyzed reactions, or simple binding reactions.
Arguments
s::SysDef: the system to add to.filamenttypename::Symbol: the filament type name.filamentsitename::Symbol: the new name of thefilamentsiteadded. This can be used as a catalyst in other reactions.changedstatenames::Pair{Vector{Symbol}, Vector{Symbol}}: the changes to the monomer states, the first is the states to match. The second is the new monomer states after the reaction. both should be the same length. Ordered minus end first.center::Int: Which index ofchangedstatenames.firstis the actual location of thefilamentsite. Used for determining what compartment the reaction goes in.reactantexpr::AbstractString: Allows adding other reactants or products to the reaction." + filamentsite.$(filamenttypename).$(filamentsitename) + "gets added to both sides this to create the full reaction expression. Seeaddreaction!for syntax.rate::Float64: Base rate for the reaction. ((nm³)^(invvolumepower)/s)invvolumepower::Int:volumefactor= (1/volume)^invvolumepowerwherevolumeis the volume of the compartment in nm³.volumefactoronly applies to this reaction not any other reaction usingfilamentsitenameGenerally this is 0 for reactions without another diffusing reactant, and 1 if there is another diffusing reactant.
Examples
MEDYAN.addfilamentend_reaction!
Add filament end reaction. Return s. Add a filamentendsite and reaction with callback to change the filaments. This can be used for polymerization, depolymeriation, and changing end state.
Arguments
s::SysDef: the system to add to.filamenttypename::Symbol: the filament type name.filamentendsitename::Symbol: the new name of thefilamentendsiteadded. This can be used as a catalyst in other reactions.isminusend::Bool: true if changing the minus end, false if changing the plus end.changedendstatenames::Pair{Vector{Symbol}, Vector{Symbol}}: the changes to the end monomer states, the first is the states to match. The second is the new monomer states after the reaction. If the second has more states than the first, new monomers will be added, if the second has less, monomers will be removed. Ordered minus end first.spacing::Float64: Space needed at the filament end for this reaction. (nm)ratefactor= exp(-β*spacing*loadforce)where β is 1/kT,loadforceis the external force pushing axially on the end of the filament. andratefactoraffects this reaction propensity and any others usingfilamentendsitenamereactionexpr::AbstractString: Allows adding other reactants or products to the reaction." + filamentendsite.$(filamenttypename).$(filamentendsitename) + "gets added to both sides this to create the full reaction expression. Seeaddreaction!for syntax.rate::Float64: Base rate for the reaction. ((nm³)^(invvolumepower)/s)invvolumepower::Int:volumefactor= (1/volume)^invvolumepowerwherevolumeis the volume of the voxel in nm³.volumefactoronly applies to this reaction not any other reaction usingfilamentendsitenameGenerally this is 0 for reactions without another diffusing reactant, and 1 if there is another diffusing reactant.
Examples
using MEDYAN
agent_names = AgentNames(
diffusingspeciesnames= [:a,],
filamentnames= [(:filname,[
:plus,
:mid,
:minus,
]),
],
)
s= SysDef(agent_names)
monomerspacing= 2.7
#minus end polymerization
addfilamentend_reaction!(s, :filname, :pm, true,
[:minus]=>[:minus,:mid], monomerspacing,
"diffusing.a -->", 10E3, 1,
)
#plus end depolymerization
addfilamentend_reaction!(s, :filname, :dpp, false,
[:mid,:plus]=>[:plus], 0.0,
"--> diffusing.a", 1.75E-3, 0,
)MEDYAN.add_membranesitereaction!
Add a membrane site with the corresponding reaction with callback.
Keyword arguments:
- s: SysDef.
- name_newmembranesite: Symbol.
- membranediffusingreactants: Vector of symbols as membrane reactants. 0 or 1 reactant is currently supported.
- membranediffusingproducts: Vector of symbols as membrane products.
- reactionexpr_extra: Reaction expression for other species involved.
- rate: Float.
- changerage_bypotentialenergy: Whether the rate is affected by potential energy.
- invvolumepower: rate scaling with compartment volume.
Notes:
- If error occurs, this function does not ensure that s is unchanged.