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.

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. Defaults to None.

  • **channels – Additional keyword arguments for specifying Channel instances to be included in this Ion object.

channels#

A dictionary of Channel instances associated with this ion.

Type:

Dict[str, Channel]

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:#

sizebrainstate.typing.Size

The size of the ion channel, typically representing the number of neurons or compartments.

nameOptional[str], default=None

The name of the Ion instance. If not provided, the instance will be unnamed.

**channels

Additional keyword arguments for specifying Channel instances to be included in this Ion object.

add(**elements)[source]#

Add new channel elements to the Ion instance.

This method adds new Channel instances to the Ion object. It checks the hierarchies of the new elements and updates the channels dictionary.

Parameters:

**elements (Any) – A dictionary of new elements to add. Each key-value pair represents a channel name and its corresponding Channel instance.

Raises:

TypeError – If the hierarchies of the new elements are incompatible with the current structure.

Notes

  • The method checks hierarchies using the check_hierarchies method.

  • New elements are formatted and added to the channels dictionary.

compute_derivative(V)[source]#

Compute derivatives for all channels.

This method calculates the derivatives of state variables for all Channel nodes.

Parameters:

V (array-like) – The membrane potential for all neurons/compartments.

current(V, include_external=False)[source]#

Generate ion channel current.

This method calculates the total current from all channels and optionally includes external currents.

Parameters:
  • V (array-like) – The membrane potential for all neurons/compartments.

  • include_external (bool) – If True, include external currents in the calculation. Default is False.

Returns:

The total current generated by all channels (and external currents if included).

Return type:

array-like

property external_currents: Dict[str, Callable]#

Get the dictionary of external currents.

Returns:

A dictionary where keys are strings identifying the external currents,

and values are callable functions representing those currents.

Return type:

Dict[str, Callable]

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

Initialize the state of all channels.

This method initializes the state variables for all Channel nodes.

Parameters:
  • V (array-like) – The membrane potential for all neurons/compartments.

  • batch_size (int) – The batch size for initialization. Default is None.

pack_info()[source]#

Pack the ion information into an IonInfo object.

This method collects the intracellular/extracellular concentrations (Ci/Co), reversal potential (E), and valence of the ion and packages them into an IonInfo named tuple.

Returns:

A named tuple containing:

  • Ci (array-like): The intracellular ion concentration.

  • Co (array-like): The extracellular ion concentration.

  • E (array-like): The reversal potential of the ion.

  • valence (array-like): The ionic valence.

Return type:

IonInfo

Notes

If an attribute is an instance of brainstate.State, its value attribute is used. Otherwise, the raw attribute value is used.

post_integral(V)[source]#

Perform post-integration operations for all channels.

This method is called after the integration step in simulations. It iterates through all Channel nodes and calls their post_integral methods.

Parameters:

V (array-like) – The membrane potential for all neurons/compartments.

pre_integral(V)[source]#

Perform pre-integration operations for all channels.

This method is called before the integration step in simulations. It iterates through all Channel nodes and calls their pre_integral methods.

Parameters:

V (array-like) – The membrane potential for all neurons/compartments.

register_external_current(key, fun)[source]#

Register an external current function.

This method adds a new external current function to the ion channel.

Parameters:
  • key (Hashable) – A unique identifier for the external current.

  • fun (Callable) – The function that computes the external current.

Raises:

ValueError – If the key already exists in the external currents’ dictionary.

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

Reset the state of all channels.

This method resets the state variables for all Channel nodes to their initial values.

Parameters:
  • V (array-like) – The membrane potential for all neurons/compartments.

  • batch_size (int) – The batch size for resetting. Default is None.

root_type#

alias of HHTypedNeuron