src/context.jl

MEDYAN.MembraneSpeciesParams

Membrane protein physical parameters.

  • diffusion_coeff::Float64: Membrane diffusion coefficients (nm^2/s).
  • area::Float64: Protein area projected onto the surface (nm^2).
  • kbend::Float64: Bending rigidity (pN nm).
  • eqcurv::Float64: The protein’s own spontaneous mean curvature (/nm). Can be used in bending energy computations with curvatures.

Base.copy

Shallow copy, https://stackoverflow.com/questions/51956958/how-to-copy-a-struct-in-julia

MEDYAN.Context

Context(sys_def::SysDef, grid::CubicGrid; kwargs...)
  • agent_names::MEDYAN.AgentNames

  • sys_def::MEDYAN.SysDef

  • compartments::Vector{MEDYAN.Compartment}

  • grid::Any

  • time::Ref{Float64}: time (s)

  • stats::MEDYAN.PerformanceStats

  • β::Float64: inverse kT (1/(nm*pN))

  • base_diffusion_coeffs::Vector{Float64}: Diffusion coefficients indexed by diffusing species id (nm²/s)

  • membrane_species_params::StaticArraysCore.SVector{NUM_MEMBRANEDIFFUSINGSPECIES, MEDYAN.MembraneSpeciesParams} where NUM_MEMBRANEDIFFUSINGSPECIES: Membrane species parameters indexed by membrane diffusing species id.

  • min_compartment_volume_ratio::Float64: Smallest volume a compartment can have before being deactivated as a ratio to a full compartment volume.

  • chemistryengine::MEDYAN.RDMESampler: The reaction diffusion master equation sampler, contains the diffusing and regular fixed species state

  • largestfilamentid::Vector{Int64}: The largest filament id, indexed by filament type id

  • chem_cylinders::Vector{MEDYAN.ChemCylinders}: Data about filament cylinders, indexed by filament type id

  • membranes::Vector: All membrane meshes.

  • link_2mon_data::Tuple{Vararg{MEDYAN.Link2MonData}}: The linked link2mon parameters, indexed by link2mon type id, to give a Link2MonData

  • decimated_2mon_site_managers::Tuple{Vararg{MEDYAN.AbstractDecimated2MonSiteManager}}: Site managers, indexed by site id

  • linked_monomers::Dictionaries.Dictionary{MEDYAN.MonomerName, Vector{Vector{Int64}}}: Dictionary of all monomers that have a bound link2mon. indexed by monomer name, then link2montypeid, to give a vector of unique link2mon ids that reference the monomer name

  • filamentsites::Tuple{Vararg{Tuple{Vararg{MEDYAN.SiteData}}}}: The filament site definitions, indexed by filament type id, filament site id to get a SiteData with fields of id, site, fxsid

  • filamentendsites::Tuple{Vararg{Tuple{Vararg{MEDYAN.SiteData}}}}: The filamentend site definitions, indexed by filament type id, filamentend site id to get a SiteData with fields of id, site, fxsid

  • maxfilsite_plusrange::Vector{Int64}: The maximum plus range in monomers that any filament site or end site can see. Indexed by filament type id

  • maxfilsite_minusrange::Vector{Int64}: The maximum minus range in monomers that any filament site or end site can see. Indexed by filament type id

  • membranesites::Tuple{Vararg{MEDYAN.SiteData}}: Maps membrane site id to a SiteData with fields of id, site, fxsid.

  • map_membranediffusingspeciesindex_membranesiteindices::Tuple{Vararg{Vector{Int64}}}: Maps membrane diffusing species index to a list of membrane sites using this species as reactant. This is initialized during context init and should not be changed.

  • link_2mon_sites::Tuple{Vararg{Tuple{Vararg{MEDYAN.SiteData}}}}: Site definitions, indexed by link_2mon type id, site id to get a SiteData with fields of id, site, fxsid

  • mon_link_2mon_sites::Tuple{Vararg{Tuple{Vararg{MEDYAN.SiteData}}}}: Site definitions, indexed by link_2mon type id, site id to get a SiteData with fields of id, site, fxsid

  • chem_max_search_dist::Float64

  • decimated_2mon_sites::Tuple{Vararg{MEDYAN.SiteData}}: Site definitions, indexed by site id to get a SiteData with fields of id, site, fxsid

  • cadherinsites::Tuple{Vararg{Tuple{Vararg{MEDYAN.SiteData}}}}

  • cadherindata::Tuple{Vararg{MEDYAN.CadherinData}}

  • possiblecadherinsite_managers::Tuple{Vararg{MEDYAN.AbstractPossibleCadherinSiteManager}}: Site managers, indexed by site id

  • cadherinlinked_vertices::Dictionaries.Dictionary{MEDYAN.VertexName, Vector{Vector{Pair{MEDYAN.VertexName, MEDYAN.MonomerName}}}}: Dictionary of all vertices that have a bound cadherin. indexed by vertex name, then cadherintypeid, to give a vector of unique cadherin endnames that reference the monomer name and vertex name

  • check_sitecount_error::Bool: If true site counts are checked for errors on every chem update. This is extremely slow, but useful for testing chem update errors.

  • compartmentreactioncallbacks::Any

  • bulkreactioncallbacks::Any

  • memdiff_bulks_index::Int64: Mock bulk species index for membrane diffusion.

  • viscosity::Float64: viscosity (pNs/nm² or MPas) water is about 1E-9

  • g_tol::Float64: maximum force magnitude after minimization (pN)

  • shake_before_minimization::Bool: If true, add noise to coordinates before starting minimization.

  • iter_max_cg_minimization::Int64: Max number of steps in conjugate gradient minimization.

  • maxstep::Float64: max step to take during line search (nm)

  • max_cylinder_force::Float64: max cylinder force when two cylinders are at zero distance (pN)

  • check_neighborlist_error::Bool: If true neighborlists are checked for errors on every force calc. This is extremely slow, but useful for testing neighborlist errors.

  • nthreads::Int64: Experimental Set to more than 1 to enable multi threading. This is currently may result in non bitwise reproducable simulations. Results should be statistcally identical, but this is currently not well tested.

  • enable_cylinder_volume_exclusion::Ref{Bool}: Are cylinder volume exclusion forces calculated

  • enable_triangle_bead_volume_exclusion::Bool: Are triangle-bead volume exclusion forces calculated.

  • cylinder_skin_radius::Float64: Extra cell list cutoff radius in nm. The cell lists are reset after a bead moves over this amount

  • filamentmechparams::Vector{MEDYAN.FilamentMechParams}: The filament mechanical parameters, indexed by filament type id

  • membranemechparams::Vector{MEDYAN.MembraneMechParams}: Membrane mechanical parameters, indexed by membrane type id.

  • func_membranespeciespotentialenergy::Any: Membrane species potential energy function. See docs on default function for more info.

  • membranefilamentmechparams::MEDYAN.MembraneFilamentMechParams: Membrane-filament mechanical interaction parameters.

  • external_energy_forces!::Any: External energy/force expressions. This should be a mutating function taking a (fc::MEDYAN.ForceContext), which adds to fc.forces, fc.energies, and fc.energy. The energy and force must be consistent, and this is not checked. This can be used as ad-hoc solutions to experiment with uncommon forces, such as specifically designed attachments, etc. If this variable is used often, consider moving it into MEDYAN.

  • chemboundary::MEDYAN.Boundary: chemical boundary, updates compartment volumes and diffusion rates

  • meshindex_as_chemboundary::Ref{Int64}: The membrane index used as chemical boundary. If values other than 0 is used, the actual interior region of the chemical boundary is the intersection between

    • the interior of chemboundary, and
    • the interior of the membrane mesh at this index.

    Note: Since the membrane may change its shape often, set_chemboundary! might need to be called often accordingly to update volumes of compartments.

  • mechboundary::MEDYAN.Boundary: mechanical boundary

  • sharedtypedconfigs::MEDYAN.SharedTypedConfigs: Shared configurations stored in type parameters.

  • validflags::MEDYAN.ValidFlags: Interval system consistency validation flags.

  • fila_tip_tags::MEDYAN.TagManager{MEDYAN.FilaTipIdx}: Filament tip tags

MEDYAN.num_filtypes

num_filtypes(c::MEDYAN.Context) -> Int64

Return the number of filament types.

MEDYAN.filtype_fil_ids

filtype_fil_ids(
    c::MEDYAN.Context,
    ftid::Int64
) -> Vector{Int64}

Return a read only iterable of all filament ids of filament type ftid.

This can be invalid after any mutations to context, so collect if needed.

MEDYAN.fil_node_positions

fil_node_positions(
    c::MEDYAN.Context,
    ftid::Int64,
    fil_id::Int64
) -> Vector{StaticArraysCore.SVector{3, Float64}}

Return the node positions of the filament

MEDYAN.fil_node_mon_ids

fil_node_mon_ids(
    c::MEDYAN.Context,
    ftid::Int64,
    fil_id::Int64
) -> Vector{Int64}

Return the node monomer ids of the filament.

The fil_node_mon_ids are the monomer ids at (slightly plus side of) the fil_node_positions

                                 |
                      -----+-----|-----+-----
  minus end <----       M  |  M  | (M) |  M        ----> plus end
                      -----+-----|-----+-----
                                 |
                                 ^ A node position is indicated by the line.

The monomer id with parenthesis (M) will in `fil_node_mon_ids`

The first monomer id is the first monomer id on the filament. The last monomer id is the last monomer id on the filament + 1

MEDYAN.fil_mon_states

fil_mon_states(
    c::MEDYAN.Context,
    ftid::Int64,
    fil_id::Int64
) -> OffsetArrays.OffsetVector{UInt8, Vector{UInt8}}

Return a read only OffsetVector of monomer states on a filament.

This can be invalid after any mutations to context, so copy if needed.

MEDYAN.fil_num_unmin_ends

fil_num_unmin_ends(
    c::MEDYAN.Context,
    ftid::Int64,
    fil_id::Int64
) -> Tuple{Int64, Int64}

Return a tuple (minus, plus) of the number of unminimized monomers on the minus and plus end of a filament.

This will be reset to (0, 0) by minimize_energy!

When an end is depolymerized this will decrease, but saturate at 0. When an end is polymerized this will increase.

For example if after minimization a filament has a plus end depolymerization, this function will return (0, 0). Then if a plus end polymerization happens, this function will return (0, 1), even though the net change in filament length is zero.

MEDYAN.vertex_state

vertex_state(
    c::MEDYAN.Context,
    vertexname::MEDYAN.VertexName
) -> UInt8

Return the vertex state on a membrane.

MEDYAN.mon_exists

mon_exists(
    c::MEDYAN.Context,
    monomer::MEDYAN.MonomerName
) -> Bool

Return true iff the filament and monomer exists

MEDYAN.mon_minimized

mon_minimized(
    c::MEDYAN.Context,
    monomer::MEDYAN.MonomerName
) -> Bool

Return true iff the monomer has been minimized

MEDYAN.mon_3states

mon_3states(
    c::MEDYAN.Context,
    monomer::MEDYAN.MonomerName
) -> Tuple{UInt8, UInt8, UInt8}

Return a tuple of three monomer states centered at a monomer.

If a monomer doesn’t exist, its state will be zero. The filament must exist.

MEDYAN.mon_position

mon_position(
    c::MEDYAN.Context,
    monomer::MEDYAN.MonomerName
) -> StaticArraysCore.SVector{3, Float64}

Return the monomer position.

MEDYAN.mon_plusvector

mon_plusvector(
    c::MEDYAN.Context,
    monomer::MEDYAN.MonomerName
) -> StaticArraysCore.SVector{3, Float64}

Return the unit vector toward the plus end of the filament.

MEDYAN.mon_position_plusvector

mon_position_plusvector(
    c::MEDYAN.Context,
    monomer::MEDYAN.MonomerName
) -> Tuple{StaticArraysCore.SVector{3, Float64}, StaticArraysCore.SVector{3, Float64}}

Return a tuple of position and plusvector at a monomer.

MEDYAN.set_time!

set_time!(c::MEDYAN.Context, x::Float64) -> Float64

Time (s)

MEDYAN.set_enable_cylinder_volume_exclusion!

set_enable_cylinder_volume_exclusion!(
    c::MEDYAN.Context,
    x::Bool
) -> Bool

Are cylinder volume exclusion forces calculated.

MEDYAN.set_chemboundary!

set_chemboundary!(
    c::MEDYAN.Context;
    meshindex_as_chemboundary,
    kwargs...
) -> MEDYAN.Boundary

Set chemical boundary and update compartment volumes and diffusion rates. Note, the chemboundary should be outside the mechboundary so that it is rare for filaments to go outside the chemboundary

See also Boundary

Keywords

  • planes::Vector{SVector{4,Float64}} = []

Planes that make up the chemical boundary of the simulation

inside = signbit(pos ⋅ planes[bi][1:3] - planes[bi][4])

For example, a plane [1,0,0,3] is inside if x < 3 nm.

2.0*[1,0,0,3] is also inside if x < 3 nm.

  • capsules::Vector{SVector{8,Float64}} = []

Capsules that make up the chemical boundary of the simulation.

capsules[bi][1:3] is the starting point of the spine line segment (nm). capsules[bi][4:6] is the axis of the spine line segment (nm). capsules[bi][7] is the radius (nm). capsules[bi][8] is ignored.

if capsules[bi][4:6] is zero then the capsule is a sphere. Capsule boundaries can be combined with plane boundaries to create cylinder boundaries.

  • meshindex_as_chemboundary::Int = 0: Index of membrane mesh that further restricts the chem boundary. 0 for none.

The system geometry information must be up-to-date. This mesh index is not stored in the boundary object, but is directly set in the context.

MEDYAN.set_mechboundary!

set_mechboundary!(
    c::MEDYAN.Context;
    kwargs...
) -> MEDYAN.Boundary

See also Boundary

MEDYAN.chem_adddiffusingcount!

chem_adddiffusingcount!(c::Context, sid, cid, inccount)

Add inccount to diffusing species id sid in compartment id cid

MEDYAN.chem_addfixedcount!

chem_addfixedcount!(c::Context, sid, cid, inccount)

Add inccount to fixed species id sid in compartment id cid

MEDYAN.adddiffusingcount_rand!

adddiffusingcount_rand!(c::Context, dsid, inccount)

Distribute the added diffusing species count randomly to compartments weighted by volume.

  • dsid: diffusing species id.
  • inccount: amount to add.

MEDYAN.addmembranediffusingcount_rand!

addmembranediffusingcount_rand!(
    c::MEDYAN.Context,
    membraneindex::Int64,
    speciesindex::Int64,
    addcount::Int64
)

Distribute the added membrane species count randomly to membrane cells, ignoring cell area difference. Does NOT update propensity.

MEDYAN.newfilament_rand!

newfilament_rand!(c::Context, monomerstates; iterations = 10^9, ftid = 1)

Add a filament with type id ftid to the Context with random center position and direction.

Return the filament id of a new filament.

monomerstates is a collection of the MonomerState of the monomers in the new filament.

The filament will be inside the mech boundary.

Errors if it fails to add a filament.

The monomer are spaced by the value in the filament type’s mechanical parameters.

MEDYAN.run_chemistry!

run_chemistry!(c::Context, Δt)

Run chemistry for Δt time.

Update c.time.

MEDYAN.defer_chem_caching!

defer_chem_caching!(c::Context)::Nothing

This should only be used for advanced optimizations.

During chemistry, the context mutating functions will typically try to avoid invalidating various cached data needed to quickly sample sites.

However, if you want to mutate the context outside of chemistry, for example right before or after minimization, you may not want to pay the cost of revalidating all the caches because minimization will already invalidate the caches. Caching will be enabled again and caches will be made valid the next time chemistry is run. Caching can also be manually refreshed and reenabled with: refresh_chem_cache!

MEDYAN.refresh_chem_cache!

refresh_chem_cache!(c::Context)::Nothing

Normally this isn’t needed as it will happen automatically.

MEDYAN.is_chem_cache_valid

is_chem_cache_valid(c::Context)::Bool

Return true if the chemistry cache is valid, false otherwise.

Base.empty!

empty!(c::Context)

Remove all filaments, membranes, link_2mons, cadherins, diffusing species, fixed species, bulk species, chemboundary, and mechboundary.

MEDYAN.chem_setmonomerstate!

chem_setmonomerstate!(c::Context, name::MonomerName, state::MonomerState)

Update a monomer state.

MEDYAN.chem_polymerize!

chem_polymerize!(c::Context, ftid, fid, isminusend::Bool, newstate::MonomerState)

Add a monomer with state newstate to the end of the filament with type id ftid and id fid.

If isminusend is true add the monomer to the minus end of the filament, if false add it to the plus end of the filament.

This doesn’t affect the other monomer states, positions, linked link_2mons, or change any of the monomer names. New monomers are not linkable until after minimization.

MEDYAN.chem_depolymerize!

chem_depolymerize!(c::Context, ftid, fid, isminusend::Bool)

Remove a monomer from the end of the filament with type id ftid and id fid.

If isminusend is true remove the monomer from the minus end of the filament, if false remove it from the plus end of the filament.

This doesn’t affect the other monomer states, positions, linked link_2mons, or change any of the monomer names.

Error if the filament isn’t initially over 2 monomers long.

Warn if the old end monomer is referenced in a link2mon, and remove the link2mon.

The warning can be disabled by passing keyword argument warniflink_2mon_removed=false

MEDYAN.chem_newfilament!

chem_newfilament!(c::Context; ftid=1, monomerstates, node_mids, nodepositions)

Return the filament id of a new filament.

Error if the filament isn’t initially over 2 monomers long.

Newly added filaments don’t have decimated_2mon sites, until after minimization.

Keyword Arguments

  • ftid=1: filament type id.

  • monomerstates: Collection of the MonomerState of the monomers in the new filament. In order from minus end to plus end.

    length(monomerstates)>1

  • nodepositions: Collection of SVector{3,Float64}. The positions of the nodes, monomers are between nodes.

  • node_mids: Collection of Integer. The monomer ids at (slightly plus side of) the nodepositions

                                   |
                        -----+-----|-----+-----
    minus end <----       M  |  M  | (M) |  M        ----> plus end
                        -----+-----|-----+-----
                                   |
                                   ^ A nodeposition is indicated by the line.

    The monomer id with parenthesis (M) will in node_mids

    length(node_mids) == length(nodepositions) - 1

  • endloadforces=(0.0=>0.0): end load forces, usually don’t use this, because load forces will automatically get updated at the next minimization.

MEDYAN.chem_removefilament!

chem_removefilament!(c::Context; ftid=1, fid=maximum(filtype_fil_ids(c, ftid)))

Remove the filament with type id ftid and id fid.

By default the last added filament with type id ftid is removed.

Warn if any monomers on the filament are referenced by any link2mons, and remove those link2mons.

The warning can be disabled by passing keyword argument warniflink_2mon_removed=false

MEDYAN.newmembrane!

newmembrane!(c::MEDYAN.Context; type, meshinit)

Add a new membrane to the system.

Keyword arguments

  • meshinit is structure containing mesh shape initialization information, such as a named tuple (vertlist, trilist) containing vertex coordinates and triangle list, MeshInitEllipsoid, MeshInitPlane or a general MeshInitSurfaceFunc.