Ion#
- class braincell.Ion(size, name=None, **channels)#
The base class for modeling ion dynamics in neuronal simulations.
This class represents a specific type of ion (e.g., sodium, potassium) and manages the associated ion channels and their dynamics. It inherits from both IonChannel and Container, allowing it to handle ion-specific behaviors and contain multiple channel instances.
The Ion class serves as a crucial component in modeling the behavior of specific ion types within a neuron or neural network simulation. It manages the collective behavior of multiple ion channels of the same ion type and provides methods for initializing, updating, and querying the state of these channels throughout the simulation process.
- Parameters:
size (
int|Sequence[int] |integer|Sequence[integer]) – The size of the simulation target, typically representing the number of neurons or compartments.name (
str|None) – The name of the Ion instance. If not provided, the instance will be unnamed.channels – Additional keyword arguments (
**channels) specifying Channel instances to be included in this Ion object.
- Variables:
channels (Dict[str, Channel]) – A dictionary of Channel instances associated with this ion.
- compute_derivative(V, recursive_child=True)[source]#
Fill in the derivatives of this ion and its children.
- Parameters:
V (ArrayLike or brainunit.Quantity) – Membrane potential for all neurons and compartments.
recursive_child (
bool) – Whether to forward the call to child channels.
- Raises:
TypeError – If a child channel’s
root_typedoes not accept this ion.
Notes
Children run first and this ion’s own hook second, so a hook that reads a child-written derivative sees the updated value.
- current(V, include_external=False)[source]#
Sum the current carried by this ion across all its channels.
- Parameters:
V (ArrayLike or brainunit.Quantity) – Membrane potential for all neurons and compartments.
include_external (
bool) – Whether to add the callbacks inexternal_currents, which is how a mixed-ion channel reaches its owner ions.
- Returns:
The summed current, or
Nonewhen this pool has no channels and no external currents to add.- Return type:
brainunit.Quantity or None
Notes
A channel painted onto only some points carries a
_point_mask. Its voltage is replaced at the unpainted points before evaluation – rate expressions overflow on whatever junk is there otherwise – and its current is masked back to zero afterwards.
- property external_currents: Dict[str, Callable]#
Currents contributed by channels this pool does not own.
- Returns:
Callbacks registered by
register_external_current(), keyed by the identifier the registrant chose. A mixed-ion channel appears here on each of its owner ions.- Return type:
dict of str to Callable
- pack_info()[source]#
Snapshot this ion’s concentrations, reversal potential, and valence.
- Returns:
Named tuple of
Ci,Co,E, andvalence. This is what every child channel receives instead of the ion itself, so a channel cannot reach back into the pool.- Return type:
Notes
Each field goes through
brainstate.maybe_state(), so a field held as abrainstate.Stateis unwrapped to itsvalueand a plain array is passed through.
- post_integral(V, recursive_child=True)[source]#
Run this ion’s children’s post-integration hooks, then its own.
- Parameters:
V (ArrayLike or brainunit.Quantity) – Membrane potential for all neurons and compartments.
recursive_child (
bool) – Whether to forward the call to child channels.
- pre_integral(V, recursive_child=True)[source]#
Run this ion’s pre-integration hook, then its children’s.
- Parameters:
V (ArrayLike or brainunit.Quantity) – Membrane potential for all neurons and compartments.
recursive_child (
bool) – Whether to forward the call to child channels. The multi-compartment family phases passFalseand drive the children themselves.
- register_external_current(key, fun)[source]#
Register a current carried by this ion but owned elsewhere.
- Parameters:
- Raises:
ValueError – If
keyis already registered.
- reset_state(V, batch_size=None)[source]#
Return this ion and every child channel to its initial state.
- root_type#
alias of
HHTypedNeuron