MTKNeuralToolkit
Documentation for MTKNeuralToolkit.
MTKNeuralToolkit.CalciumTrackerMTKNeuralToolkit.CalciumTrackerMTKNeuralToolkit.CompartmentMTKNeuralToolkit.CouplingSpecMTKNeuralToolkit.NetworkMTKNeuralToolkit.NoCalciumMTKNeuralToolkit.SynapseSpecMTKNeuralToolkit.SynapseSpecMTKNeuralToolkit.AlphaSynapseMTKNeuralToolkit.CholSynapseMTKNeuralToolkit.ExpSynapseMTKNeuralToolkit.FixedReversalMTKNeuralToolkit.GlutSynapseMTKNeuralToolkit.NMDASynapseMTKNeuralToolkit.STDPSynapseMTKNeuralToolkit.SpikingCapacitorMTKNeuralToolkit.SynapsePortMTKNeuralToolkit.VectorizedExpSynapseMTKNeuralToolkit.build_acausal_networkMTKNeuralToolkit.build_compartmentMTKNeuralToolkit.build_synapse_blockMTKNeuralToolkit.wire_ions!MTKNeuralToolkit.wire_synapses!
MTKNeuralToolkit.CalciumTracker — Type
CalciumTrackerA configuration struct enabling Calcium dynamics within a compartment. When passed to build_compartment, it instantiates a CalciumPool and connects it to all channels that expose a ca_port.
Fields
decay::Union{Float64, Function}: Either a time constant for linear decay, or a function that takes the current Calcium concentration and returns the decay rate.Ca_init::Float64: The initial intracellular Calcium concentration.
MTKNeuralToolkit.CalciumTracker — Method
Keyword argument constructor for CalciumTracker.
MTKNeuralToolkit.Compartment — Type
CompartmentA struct representing a single neural compartment (e.g., a soma, axon hillock, or dendritic segment). It wraps the generated ModelingToolkit System along with metadata about its physical and electrical properties, and exposes a tuple of interfaces for acausal network connections.
Fields
sys::System: The underlying MTK system representing the compartment's equations.interfaces::NamedTuple: Exposed boundary variables and pins (e.g.,V,p_pin,n_pin,I_ext,I_syn).V_init::F: The initial membrane voltage.topology::Union{Scalar, Vectorized}: The electrical topology of the compartment.geometry::G: The physical geometry used for scaling biophysical parameters.morphology::M: The spatial morphology used for rendering or spatial simulations.
MTKNeuralToolkit.CouplingSpec — Type
CouplingSpecA specification struct used to wire an acausal coupling (e.g., a Gap Junction) between two compartments.
Fields
comp_i::Compartment: The first compartment to be coupled.comp_j::Compartment: The second compartment to be coupled.coupling::System: The MTK coupling system component (e.g.,GapJunction).
MTKNeuralToolkit.Network — Type
NetworkA struct representing the complete assembled neural network. It encapsulates the fully connected MTK System and a vector of input variables for simulation drivers.
Fields
sys::System: The final compiled MTK system representing the entire network.inputs::Vector{Any}: A collection of symbolic input variables for external stimulation.
MTKNeuralToolkit.NoCalcium — Type
NoCalciumA configuration struct indicating that a compartment has no Calcium dynamics. When passed to build_compartment, it bypasses the creation of a CalciumPool.
MTKNeuralToolkit.SynapseSpec — Type
SynapseSpecA specification struct used to wire a synapse between a presynaptic voltage and a postsynaptic current. It provides the mapping needed by wire_synapses! to inject currents into the correct compartments.
Fields
pre_V: The symbolic voltage variable of the presynaptic compartment.post_V: The symbolic voltage variable of the postsynaptic compartment.post_I_syn: The symbolic current variable of the postsynaptic compartment where the synapse will inject.synapse::System: The MTK synapse system component (e.g.,ExpSynapse,CholSynapse).post_comp::Union{Compartment, Nothing}: The postsynaptic compartment struct (used for block synapse grounding logic).
MTKNeuralToolkit.SynapseSpec — Method
Outer constructor for SynapseSpec that defaults post_comp to nothing. Useful for scalar synapses where block grounding logic is not required.
MTKNeuralToolkit.AlphaSynapse — Method
AlphaSynapse(; name, g_max=1.0, τ=5.0, E_rev=0.0, V_th=-20.0, slope=2.0)An alpha-function synapse implemented via a cascade of two first-order filters (s1 and s2). This produces the classic unimodal alpha-function response in synaptic conductance following a sustained presynaptic depolarization.
The current injected into the postsynaptic compartment is: I_syn = g_max * s2 * (E_rev - V_post)
Arguments
g_max: Maximum synaptic conductance.τ: Time constant for both cascaded filters.E_rev: Reversal potential of the synapse.V_th: Threshold voltage for presynaptic activation.slope: Slope of the presynaptic sigmoid activation.
MTKNeuralToolkit.CholSynapse — Method
CholSynapse(; name, g_max=30.0, E_rev=-80.0, k_minus=0.01, V_th=-35.0, delta=5.0, geometry=NoGeometry())A continuous cholinergic synapse model. The synaptic state variable s represents the fraction of open receptors. It rises towards a steady-state s_inf governed by the presynaptic voltage, and decays exponentially.
The synaptic current is calculated as the current injected into the postsynaptic membrane: I_syn = g_max * s * (E_rev - V_post)
Arguments
g_max: Maximum synaptic conductance (scaled by geometry if provided).E_rev: Reversal potential of the synapse (e.g., -80 mV for inhibitory).k_minus: Rate constant for receptor unbinding (controls decay time).V_th: Half-activation voltage for the presynaptic sigmoid.delta: Slope of the presynaptic sigmoid activation.geometry: AbstractGeometry struct for scalingg_max.
MTKNeuralToolkit.ExpSynapse — Method
ExpSynapse(; name, g_max=1.0, τ=5.0, E_rev=0.0, V_th=-20.0, slope=2.0)A simple exponential decay synapse. The synaptic gating variable s is driven by a continuous sigmoidal function of the presynaptic voltage and decays exponentially with time constant τ.
The current injected into the postsynaptic compartment is: I_syn = g_max * s * (E_rev - V_post)
Arguments
g_max: Maximum synaptic conductance.τ: Decay time constant of the synapse.E_rev: Reversal potential of the synapse.V_th: Threshold voltage for presynaptic activation.slope: Slope of the presynaptic sigmoid activation.
MTKNeuralToolkit.FixedReversal — Method
fixed_reversal Component: A pure constant voltage source (Nernst battery).
MTKNeuralToolkit.GlutSynapse — Method
GlutSynapse(; name, g_max=30.0, E_rev=-70.0, k_minus=0.025, V_th=-35.0, delta=5.0, geometry=NoGeometry())A continuous glutamatergic synapse model. Behaves identically to CholSynapse but uses default parameters typical for fast excitatory glutamatergic receptors.
Arguments
g_max: Maximum synaptic conductance (scaled by geometry if provided).E_rev: Reversal potential of the synapse (e.g., -70 mV or higher for excitatory).k_minus: Rate constant for receptor unbinding.V_th: Half-activation voltage for the presynaptic sigmoid.delta: Slope of the presynaptic sigmoid activation.geometry: AbstractGeometry struct for scalingg_max.
MTKNeuralToolkit.NMDASynapse — Method
NMDASynapse(; name, g_max=1.0, τ=100.0, E_rev=0.0, V_th=-20.0, Mg_conc=1.0, slope=2.0)An N-Methyl-D-Aspartate (NMDA) receptor synapse. It includes the classic voltage-dependent Magnesium block that reduces conductance at hyperpolarized potentials. The gating variable s decays with a slow time constant τ.
The current injected into the postsynaptic compartment is: I_syn = g_max * s * mg_block(V_post) * (E_rev - V_post)
Arguments
g_max: Maximum synaptic conductance.τ: Slow decay time constant typical of NMDA receptors.E_rev: Reversal potential of the synapse (usually near 0 mV).V_th: Threshold voltage for presynaptic activation.Mg_conc: Extracellular Magnesium concentration determining block strength.slope: Slope of the presynaptic sigmoid activation.
MTKNeuralToolkit.STDPSynapse — Method
STDPSynapse(; name, g_max=1.0, E_rev=0.0, V_th=0.0, slope=2.0, τ_s=5.0,
τ_plus=20.0, τ_minus=20.0, A_plus=0.1, A_minus=0.1,
w_init=0.5, w_max=1.0, w_min=0.0)A continuous, smooth approximation of Spike-Timing-Dependent Plasticity (STDP) with soft bounds. It uses a continuous spike-detector function (sigmoid) and trace variables (x for pre, y for post) to approximate the relative timing of spikes without requiring discrete event handling.
The weight w evolves continuously according to: dw/dt = A_plus * (w_max - w) * x * σ(V_post) - A_minus * (w - w_min) * y * σ(V_pre)
where x and y are exponentially decaying traces, and σ(V) is a sigmoid acting as a continuous spike detector. This formulation is purely acausal and ODE-based, making it incredibly robust for standard differential equation solvers while demonstrating classic STDP behavior.
MTKNeuralToolkit.SpikingCapacitor — Method
SpikingCapacitor Component: Capacitor that automatically resets its voltage when a threshold is crossed
MTKNeuralToolkit.SynapsePort — Method
SynapsePortA boundary connector that exposes the postsynaptic current variable (I_syn) and binds it to the positive pin (p.i) of a standard electrical port.
This component is typically used internally by compartment builders to route synaptic currents into a postsynaptic compartment's CurrentSource.
MTKNeuralToolkit.VectorizedExpSynapse — Method
VectorizedExpSynapse(; name, N_pre, N_post, W, g_max=1.0, τ=5.0, E_rev=0.0, V_th=-20.0, slope=2.0)A vectorized block of exponential synapses representing a dense N_post by N_pre projection. It accepts an entire weight matrix W mapping presynaptic gating variables to postsynaptic currents.
The synaptic state s is a vector of length N_pre. The postsynaptic current vector is computed via: I_syn[i] = g_max * sum_j(W[i, j] * s[j]) * (E_rev - V_post[i])
Arguments
N_pre: Number of presynaptic elements.N_post: Number of postsynaptic elements.W: A matrix of connection weights (dimensionsN_postxN_pre).g_max: Maximum global synaptic conductance.τ: Decay time constant.E_rev: Reversal potential of the synapse.V_th: Threshold voltage for presynaptic activation.slope: Slope of the presynaptic sigmoid activation.
MTKNeuralToolkit.build_acausal_network — Method
build_acausal_network(compartments; coupling_specs, synapse_specs, drivers, name)Assembles a collection of Compartments into a complete Network system. It handles grounding, wiring driving stimuli, gap junctions (via CouplingSpec), and chemical synapses (via SynapseSpec).
Arguments
compartments::Vector{<:Compartment}: The compartments making up the network.coupling_specs: A vector ofCouplingSpecstructs for acausal electrical connections.synapse_specs: A vector ofSynapseSpecstructs for directed chemical synapses.drivers: A vector of(target, stim)tuples, wheretargetis a compartment or index, andstimis an MTK block, vector, or number.name::Symbol: The name of the overall network system.
Returns
- A
Networkstruct containing the assembled MTKSystem.
MTKNeuralToolkit.build_compartment — Method
build_compartment(capacitor, channels; name, V_init, topology, ion_config, geometry, morphology)Builds a Compartment by connecting a Capacitor, current injectors, and a collection of ion channels. This forms the fundamental electrical unit of a neuron. All positive terminals (p) are connected together to the membrane potential, and all negative terminals (n) are connected to ground.
Arguments
capacitor: ACapacitorsystem defining the membrane capacitance.channels: A vector of ion channel systems (e.g.,GenericChannel,CaVChannel).name::Symbol: The name of the compartment system.V_init::Float64: Initial membrane voltage (default -65.0 mV).topology:Scalar()orVectorized(N)(defaultScalar()).ion_config:NoCalcium()orCalciumTracker()to handle ion pools.geometry: Geometry struct for biophysical scaling (defaultNoGeometry()).morphology: Morphology struct for spatial data (defaultNoMorphology()).
Returns
- A
Compartmentstruct containing the assembledSystemand its exposedinterfaces.
MTKNeuralToolkit.build_synapse_block — Method
build_synapse_block(pre_comp, post_comp, W; name, synapse_type, kwargs...)Helper function to create a SynapseSpec using a vectorized synapse block. It automatically determines the pre- and postsynaptic dimensions based on the weight matrix W and binds it to the provided compartments.
Arguments
pre_comp::Compartment: The presynaptic compartment.post_comp::Compartment: The postsynaptic compartment.W: The weight matrix (dimensionsN_postxN_pre).name::Symbol: The name for the synapse block system.synapse_type: The vectorized synapse component to use (defaults toVectorizedExpSynapse).kwargs...: Additional keyword arguments passed tosynapse_type(e.g.,g_max,E_rev).
Returns
- A
SynapseSpecconfigured for the network builder.
MTKNeuralToolkit.wire_ions! — Method
wire_ions!(eqs, systems, channels, config, topology, name)Internal helper function to wire ion dynamics into a compartment's equations and systems list. Uses multiple dispatch to handle different ion configurations.
- If
configisNoCalcium, it does nothing. - If
configisCalciumTracker, it creates aCalciumPooland connects it to all channels in the compartment that expose aca_port.
MTKNeuralToolkit.wire_synapses! — Method
wire_synapses!(eqs, systems, specs)Internal helper function that wires a collection of SynapseSpecs into the network equations. It binds the presynaptic and postsynaptic voltage variables to the synapse, and pre-collects convergent synapses by their target current variable to write a single summed equation per target.
Returns a tuple of (driven_syn_targets, block_driven_targets) used for grounding unconnected inputs.