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.

add(**elements)[source]#

Add channels to this ion pool after construction.

Parameters:

**elements – Channel instances to add, keyed by attribute name.

Raises:

TypeError – If an element’s root_type does not accept this ion, or if it is not a Channel.

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_type does 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 in external_currents, which is how a mixed-ion channel reaches its owner ions.

Returns:

The summed current, or None when 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

init_state(V, batch_size=None)[source]#

Allocate the state of this ion and every child channel.

Parameters:
  • V (ArrayLike or brainunit.Quantity) – Membrane potential for all neurons and compartments.

  • batch_size (int) – Leading batch dimension to allocate states with.

Raises:

TypeError – If a child channel’s root_type does not accept this ion.

pack_info()[source]#

Snapshot this ion’s concentrations, reversal potential, and valence.

Returns:

Named tuple of Ci, Co, E, and valence. This is what every child channel receives instead of the ion itself, so a channel cannot reach back into the pool.

Return type:

IonInfo

Notes

Each field goes through brainstate.maybe_state(), so a field held as a brainstate.State is unwrapped to its value and 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 pass False and drive the children themselves.

register_external_current(key, fun)[source]#

Register a current carried by this ion but owned elsewhere.

Parameters:
  • key (Hashable) – Unique identifier for the current. MixIons uses the channel’s id, optionally paired with a component key.

  • fun (Callable) – Callback with signature fun(V, ion_info) returning a current.

Raises:

ValueError – If key is already registered.

reset_state(V, batch_size=None)[source]#

Return this ion and every child channel to its initial state.

Parameters:
  • V (ArrayLike or brainunit.Quantity) – Membrane potential for all neurons and compartments.

  • batch_size (int) – Leading batch dimension to reset states with.

Raises:

TypeError – If a child channel’s root_type does not accept this ion.

root_type#

alias of HHTypedNeuron