cell

class Cell(cell_file, config_override=None, **kwargs)[source]

Bases: object

Represents a NEURON cell loaded from a morphology file, with methods for simulation and analysis in NEURON.

Example usage:

import golding_mso as gmso
import matplotlib.pyplot as plt
from neuron import h

mso_cell = gmso.Cell(gmso.morphologies['151124_03'])
mso_cell.assign_channels()
mso_cell.attach_axon()

stim = h.IClamp(mso_cell.somatic[0](0.5))
stim.amp = 1.3
stim.dur = 10
stim.delay = 10

soma_v = h.Vector().record(mso_cell.somatic[0](0.5)._ref_v)
axon_v = h.Vector().record(mso_cell.nodes[-1](0.5)._ref_v)
t = h.Vector().record(h._ref_t)

h.finitialize(-58)
h.continuerun(10)
h.frecord_init()
h.continuerun(13)

plt.plot(t, soma_v, label='Soma', color='blue')
plt.plot(t, axon_v, label='Axon', color='orange')
plt.xlabel('Time (ms)')
plt.ylabel('Membrane Potential (mV)')
plt.title('MSO Cell Response to Current Injection')
plt.legend()
plt.show()

Parameters

cell_filestr

Filepath to a morphology file in .asc format from Neurolucida.

config_overrideConfig, optional

Overrides configuration with a custom Config or dictionary. Defaults to None.

assign_channels(parts=None, **kwargs)[source]

Inserts ion channels and sets their properties on specified parts of the cell, based on the current cell instance’s ‘channels’ attribute (ParamDict). kwargs input are formatted as part_channel_condlabel: conductancevalue.

Parameters

partslist of str, optional

List of cell parts to assign channels to. Options include ‘dendrite’, ‘soma’, ‘node’, ‘internode’, ‘tais’, ‘cais’. If None, assigns channels to all parts. Default is None.

kwargsdict

Additional keyword arguments specifying conductance values for specific channels and parts, formatted as ‘part_channel_condlabel’.

attach_axon(**kwargs)[source]

Attaches an artificial axon to the soma of the Cell instance.

The axon morphology is based on Lehnert et al. (2014) and includes a tapering initial segment, nodes, and internodes.

detach_axon()[source]

Disconnects the axon from the soma and removes it from the cell.

move(x, y, z, relative=True)[source]

Moves the cell to a new location in 3D space.

Parameters

xfloat

distance to translate or (if relative = False) new x-coordinate.

yfloat

distance to translate or (if relative = False) new y-coordinate.

zfloat

distance to translate or (if relative = False) new z-coordinate.

relativebool, optional

If True, moves the cell by the specified distances. If False, sets the cell’s position to the specified coordinates. Default is True.

psections(sections=None)[source]

Returns the specified sections’ properties.

Parameters

sectionslist of h.Section or h.Section, optional

Sections to retrieve properties for. If None, returns properties for all sections without filopodia. Default is None.

Returns

dict

A dictionary containing section properties.

reload_defaults(config_override=None)[source]

Resets the cell’s configuration to the default or a provided configuration.

Parameters

config_overrideConfig, optional

Configuration file path or dictionary to load cell parameters from. If None, uses current session’s config. Defaults to None.

restore_state(cell_state=None)[source]

Restores the cell’s mechanisms to a previously stored state.

set_artificial_resting_potential(resting_potential, current_limits=(-1, 1), current_step=0.1, current_override=None)[source]

Sets an artificial resting potential with a measured indefinite current injection at the soma.

Parameters

resting_potentialfloat

Desired artificial resting potential.

current_limitstuple, optional

Range of DC current sweeping test in nanoamps. Default is (-1, 1).

current_stepfloat, optional

Increment of applied DC current in nanoamps. Default is 0.1.

current_overridefloat, optional

If provided, directly sets the current without sweeping.

store_state()[source]

Stores the current state of all mechanisms in the cell for later restoration.

topology(subtree=None)[source]

Prints the topology of the cell in a human-readable format.

Parameters

subtreelist of h.Section, optional

Subtree of sections to represent. If None, uses all sections without filopodia.

unassign_channels()[source]

Unassigns all channels from the cell, resetting it to its initial state.

property input_capacitance: float
input_capacitance: float

The input capacitance (pF).

property input_resistance: float
input_resistancefloat

The input resistance (MΩ).

property membrane_resistance: float
membrane_resistancefloat

The membrane resistance (MΩ).

property potential_threshold: float
potential_threshold: float

The maximum subthreshold depolarization (mV).

property resting_potential: float
resting_potential: float

The resting potential (mV).

property rheobase: tuple[float, float]
rheobase: float

The current threshold (nA).

property surface_area: float
surface_area: float

The surface area in square micrometers (µm²).

property time_constant: float
time_constant: float

The measured cell’s time constant (ms)

_assign_channels(parts=None, **kwargs)[source]

Inserts ion channels and sets their properties on specified parts of the cell, based on the current cell instance’s ‘channels’ attribute (ParamDict). kwargs input are formatted as part_channel_condlabel: conductancevalue.

Parameters

partslist of str, optional

List of cell parts to assign channels to. Options include ‘dendrite’, ‘soma’, ‘node’, ‘internode’, ‘tais’, ‘cais’. If None, assigns channels to all parts. Default is None.

kwargsdict

Additional keyword arguments specifying conductance values for specific channels and parts, formatted as ‘part_channel_condlabel’.

_create_axon_sections(num_nodes=5, tais_max_diam=1.64, cais_diam=0.66)[source]
_current_step_analysis(current_range=(-3, 3), current_step=1, traces=False)[source]

Calculates membrane resistance, input resistance, and resting potential.

A current step is applied, and steady-state voltages are used to calculate resistances.

Parameters

current_rangetuple, optional

Range of current steps (in nanoamps) to apply. Default is (-3, 3).

current_stepfloat, optional

Size of each current step (in nanoamps). Default is 1 nA.

tracesbool, optional

Whether to return voltage and time traces. Default is False.

Returns

input_resistancefloat

Input resistance in MΩ.

membrane_resistancefloat

Membrane resistance in MΩ.

_define_section_lists(filopodia_maximum_length=None, filopodia_maximum_diameter=None, disconnect=True)[source]

Categorizes NEURON sections into various lists and culls filopodia.

Lists include `somatic, lateral, medial, dendrites, and their respective versions without filopodia (_nofilopodia).

Automatic categorization depends on labels assigned in Neurolucida:

Soma somatic Apical dendrites lateral Dendrites medial

Parameters

filopodia_maximum_lengthfloat

Maximum length (µm) of a section deemed filopodia.

filopodia_maximum_diameterfloat

Maximum diameter (µm) of a section deemed filopodia.

disconnectbool, optional

Whether to electrically disconnect filopodia from the cell. Default is True.

_get_threshold(current_range=(0, 10), relative_threshold_voltage=25, numloop=20, traces=False)[source]

Finds the current threshold for action potential generation.

A current clamp is applied at the soma, and the minimum current that generates an action potential is determined through binary search.

Parameters

current_rangetuple, optional

Range of current (in nanoamps) to search for threshold. Default is (0, 10).

relative_threshold_voltagefloat, optional

Voltage increase (in mV) above resting potential to define a spike. Default is 25 mV.

numloopint, optional

Maximum number of iterations for the binary search. Default is 20.

tracesbool, optional

Whether to record and return voltage traces. Default is False.

Returns

dict, optional

Dictionary containing traces if traces is True, otherwise None.

_get_time_constant(traces=False)[source]

Measures the time constant (tau) of the cell.

A current clamp is applied at the soma, and the return to resting potential is used to calculate tau.

Parameters

tracesbool, optional

Whether to return voltage and time traces. Default is False.

Returns

taufloat

Time constant in milliseconds.

trace_dictdict[str, Vector], optional

Dictionary containing time, voltage, and current vectors if traces is True.

_get_resting_potential()[source]

Runs a simulation to determine the cell’s resting potential.

Returns

resting_potentialfloat

The resting potential in millivolts (mV).

_initialize_cell(cell_file, **kwargs)[source]

Loads the morphology file and instantiates the cell in NEURON.

_load_default_values(config_override=None, **kwargs)[source]

Loads default channel attributes and conductance values into the cell instance’s attributes (conductances & channels).

Parameters

config_overrideConfig or dict, optional

Configuration file path or dictionary to load cell parameters from. If None, uses current session’s config. Defaults to None.

_reset_properties()[source]

Resets the cell’s measured properties to None (usually when cell properties are changed).

_set_channel_cond(seg, channel, mech, part, cond_label='gbar', input_cond=None, **kwargs)[source]

Sets the conductance of a specific channel in a segment.

Parameters

segSection Segment

The segment of the section where the channel conductance is to be set.

channelstr

The name of the channel whose conductance is to be set.

mechstr

The mechanism name associated with the channel.

partstr

The part of the cell (e.g., ‘soma’, ‘dendrite’) where the channel is located.

cond_labelstr, optional

The label of the conductance parameter in the mechanism. Default is ‘gbar’.

input_condfloat or bytes, optional

The conductance value to set. If None, uses the default from self.conductances. Default is None.

kwargsdict

Additional keyword arguments that may contain conductance values.

_remove_from_neuron()[source]

Removes the cell from NEURON simulation space.

_reset()[source]

Resets the cell’s properties and removes it from NEURON.

_set_compartments(compartment_size=None)[source]

Sets the number of segments in each section based on the compartment size.

Parameters

compartment_sizefloat, optional

Size of each compartment in microns. Default is the class attribute (loaded from config).

_topology_to_string(subtree=None)[source]

Generates a string representation of the cell’s topology.

Parameters

subtreelist of h.Section, optional

Subtree of sections to represent. If None, uses all sections without filopodia.

Returns

topo_stringstr

String representation of the cell’s topology.

class ParamDict(input_dict, cell)[source]

Bases: dict

A dictionary-like class that resets cell properties when cell attributes are changed, to force reevaluating old cell measurements with previous attributes.

convert_to_dict()[source]

Returns a dictionary representation of the ParamDict, recursively if necessary.