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.

MEDYAN.Context

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

  • sys_def::MEDYAN.SysDef

  • compartments::Vector{MEDYAN.Compartment}

  • grid::MEDYAN.CubicGrid

  • time::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_chem_voxel_volume_ratio::Float64: Smallest volume a chem voxel can have before being deactivated as a ratio to a full chem voxel volume.

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

  • chem_voxel_volumes::Array{Float64, 3}: Volume of each chemical voxel

  • chem_voxel_areas::Array{Float64, 4}: Areas of (-x, -y, -z) faces of each chemical voxel

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

  • balls::StructArrays.StructVector{MEDYAN.Ball, @NamedTuple{position::Vector{StaticArraysCore.SVector{3, Float64}}, radius::Vector{Float32}, stiffness::Vector{Float32}, state::Vector{StaticArraysCore.SVector{3, Int64}}}, Int64}

  • membranes::Vector: All membrane meshes.

  • next_membid::Ref{MEDYAN.MembId}: Next memb id

  • membid2membidx::Dict{MEDYAN.MembId, UInt32}: map from memb id to index memb indexes can change whenever a memb is removed, but id’s are stable

  • membidx2membid::Vector{MEDYAN.MembId}: map from memb index to id

  • link_manager::MEDYAN.LinkManager

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

  • 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.

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

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

  • 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)

  • nforce_fractbit::Int64: number of fractional bits used to scale force values into Int64

  • nenergy_fractbit::Int64: number of fractional bits used to scale energy values into Int64

  • shake_before_minimization::Float64: Standard deviation of noise added 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)

  • 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_collision::Ref{Bool}: Are collision forces calculated

  • collision_skin::Float64: Extra collision neighbor list cutoff radius in nm. The neighbor lists are reset after something moves over this amount

  • collision_switchover_scale_unitless::Float32: Smoothing scale to avoid sharp forces when two cylinders are collinear

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

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

  • external_energy_forces!::Any: External energy/force expressions. This should be a mutating function taking a (fc::MEDYAN.ForceContext, vectorized_x), 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

  • chem_boundary_oversampling_factor::Int64: Oversampling factor for chem boundary TSDF computation. Default is 4.

  • chem_boundary_tsdf_max_distance::Float64: Maximum distance for TSDF truncation (nm). Actual max is max(this, 2.5*grid_spacing). Default is 312.5 nm.

  • chem_boundary_tsdf_cache::Union{Nothing, Array{Float64, 3}}: Cached truncated signed distance field for chem boundary. nothing means cache is invalid.

  • mechboundary::MEDYAN.Boundary: mechanical boundary

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

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

  • profiler::ZoneProfilers.Profiler

MEDYAN.set_time!

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

Time (s)

MEDYAN.get_time

get_time(c::MEDYAN.Context) -> Float64

Time (s)

MEDYAN.set_enable_collision!

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

Are repulsive forces calculated.

MEDYAN.set_chem_boundary!

set_chem_boundary!(
    c::MEDYAN.Context,
    boundary::MEDYAN.Boundary
)

Set chemical boundary Note, the chem boundary should be outside the mech boundary so that it is rare for filaments to go outside the chem boundary.

Make sure to call apply_chem_boundary! to update the chem voxels.

See also Boundary

MEDYAN.is_chem_boundary_tsdf_cache_valid

is_chem_boundary_tsdf_cache_valid(c::MEDYAN.Context) -> Bool

Return true if the chem boundary TSDF cache is valid.

MEDYAN.get_chem_boundary_oversampling_factor

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

Get the oversampling factor used for chem boundary TSDF computation.

MEDYAN.get_chem_boundary_grid_spacing

get_chem_boundary_grid_spacing(c::MEDYAN.Context) -> Float64

Get the grid spacing used for chem boundary TSDF computation.

MEDYAN.set_chem_boundary_oversampling_factor!

set_chem_boundary_oversampling_factor!(
    c::MEDYAN.Context,
    factor::Int64
)

Set the oversampling factor for chem boundary TSDF computation. This will invalidate the TSDF cache.

MEDYAN.get_chem_boundary_tsdf_max_distance

get_chem_boundary_tsdf_max_distance(
    c::MEDYAN.Context
) -> Float64

Get the user-specified maximum distance for TSDF truncation (nm). The actual max distance used is max(this, 2.5*grid_spacing).

MEDYAN.set_chem_boundary_tsdf_max_distance!

set_chem_boundary_tsdf_max_distance!(
    c::MEDYAN.Context,
    max_distance::Float64
)

Set the maximum distance for TSDF truncation (nm). The actual max distance used is max(this, 2.5*grid_spacing). This will invalidate the TSDF cache.

MEDYAN.get_chem_boundary_tsdf_actual_max_distance

get_chem_boundary_tsdf_actual_max_distance(
    c::MEDYAN.Context
) -> Float64

Get the actual maximum distance used for TSDF truncation (nm). This is max(userspecifiedmaxdistance, 2.5grid*spacing).

MEDYAN.get_chem_boundary_tsdf!

get_chem_boundary_tsdf!(
    c::MEDYAN.Context
) -> Array{Float64, 3}

Get the cached chem boundary TSDF, computing it if necessary. The TSDF is a 3D grid of signed distances where inside the boundary is negative and outside is positive. Values are clamped to ±max(usermaxdistance, 2.5*grid_spacing).

MEDYAN.is_inside_chem_boundary!

is_inside_chem_boundary!(
    c::MEDYAN.Context,
    position::StaticArraysCore.SVector{3, Float64},
    min_distance::Float64
) -> Bool

Conservatively check if a position is inside the chem boundary by at least min_distance nm.

Uses the cached TSDF to provide a conservative (never false-positive) estimate. Returns true only if we can guarantee the point is inside by at least min_distance. Returns false if the point might be outside or within min_distance of the boundary.

The algorithm uses the TSDF values at the 8 vertices of the containing voxel. For each vertex with TSDF value t_v (negative = inside), and distance r from the query point to that vertex, the boundary is between t_v + r and t_v - r away from the point.

If the point is outside the TSDF grid, returns false (conservative).

The TSDF grid spacing defaults to the chem voxel spacing / 4. The oversampling factor can be increased with set_chem_boundary_oversampling_factor!. The TSDF max distance can be increased with set_chem_boundary_tsdf_max_distance!. If min_distance > max_distance - sqrt(3)*grid_spacing an error is thrown.

MEDYAN.apply_chem_boundary!

apply_chem_boundary!(c::Context)::Nothing

Update chem voxel volumes and diffusion rates.

The chem boundary is the intersection of any boundary set by set_chem_boundary! and membranes with chem_boundary=true.

set_chem_boundary_oversampling_factor! can be used to increase the boundary sampling resolution at the expense of increased memory use.

Calling this will invalidate the chem cache.

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.add_diffusing_count!

add_diffusing_count!(c::Context; species, chem_voxel, inccount)

Add inccount to diffusing species id sid in chem_voxel

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.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, links, diffusing species, fixed species, bulk species, chemboundary, and mechboundary.