Model¶
- class dendrotweaks.model.Model(path_to_model, simulator_name='NEURON')[source]¶
Bases:
IOMixin,SimulationMixinA model object that represents a neuron model.
The class incorporates various mixins to separate concerns while maintaining a flat interface.
- Parameters:
name (str) – The name of the model.
simulator_name (str) – The name of the simulator to use (either ‘NEURON’ or ‘Jaxley’).
path_to_data (str) – The path to the data files where swc and mod files are stored.
- path_to_model¶
The path to the model directory.
- Type:
str
- path_manager¶
The path manager for the model.
- Type:
- mod_loader¶
The MOD file loader.
- Type:
- simulator_name¶
The name of the simulator to use. Default is ‘NEURON’.
- Type:
str
- sec_tree¶
The section tree representing the morphology on the section level.
- Type:
- mechanisms¶
A dictionary of mechanisms available for the model.
- Type:
dict
- domains_to_mechs¶
A dictionary mapping domains to mechanisms inserted in them.
- Type:
dict
- params¶
A dictionary mapping parameters to their distributions.
- Type:
dict
- d_lambda¶
The spatial discretization parameter.
- Type:
float
- seg_tree¶
The segment tree representing the morphology on the segment level.
- Type:
- iclamps¶
A dictionary of current clamps in the model.
- Type:
dict
- populations¶
A dictionary of “virtual” populations forming synapses on the model.
- Type:
dict
- simulator¶
The simulator object to use.
- Type:
Simulator
- property name¶
The name of the directory containing the model.
- property verbose¶
Whether to print verbose output.
- property mechs_to_domains¶
The dictionary mapping mechanisms to domains where they are inserted.
- property groups¶
The dictionary of segment groups in the model.
- property groups_to_parameters¶
The dictionary mapping segment groups to parameters.
- property parameters_to_groups¶
The dictionary mapping parameters to groups where they are distributed.
- property params_to_mechs¶
The dictionary mapping parameters to mechanisms to which they belong.
- property mechs_to_params¶
The dictionary mapping mechanisms to parameters they contain.
- property conductances¶
A filtered dictionary of parameters that represent conductances.
- property df_params¶
A DataFrame of parameters and their distributions.
- add_domain(name, type_idx, color, sections, distribute=True)[source]¶
Adds a new empty domain to the model.
- Parameters:
name (str) – The name of the domain.
color (str) – The color assigned to the domain.
type_idx (int) – The type index of the domain.
sections (list[Section]) – The sections to include in the domain.
distribute (bool, optional) – Whether to re-distribute the parameters after defining the domain. Default is True.
Notes
This method does not automatically insert mechanisms into the newly created domain. It is the user’s responsibility to insert mechanisms into the domain after its creation.
- Suggested type indices and colors:
1: soma: orange 2: axon: gold 3: dend: forestgreen 31: basal: seagreen 4: apic: steelblue 41: trunk: skyblue 42: tuft: plum 43: oblique: rosybrown
- update_domain_name(old_name, new_name)[source]¶
Update the name of a domain.
- Parameters:
old_name (str) – The current name of the domain.
new_name (str) – The new name to assign to the domain.
- update_domain_type_idx(name, new_type_idx)[source]¶
Update the type index of a domain.
Notes
- Suggested type indices:
1: soma 2: axon 3: dend 31: basal 4: apic 41: trunk 42: tuft 43: oblique
- update_domain_color(name, new_color, force=False)[source]¶
Update the color of a domain.
Notes
- Suggested colors:
soma: orange axon: gold dend: forestgreen basal: seagreen apic: steelblue trunk: skyblue tuft: plum oblique: rosybrown
- extend_domain(name, sections, distribute=True)[source]¶
Extends an existing domain by adding sections to it.
- Parameters:
name (str) – The name of the domain to extend.
sections (list[Section]) – The sections to add to the domain.
distribute (bool, optional) – Whether to re-distribute the parameters after extending the domain. Default is True.
Notes
If the domain already exists and is being extended, mechanisms will be inserted automatically into the newly added sections.
- insert_mechanism(mechanism_name: str, domain_name: str, distribute=True)[source]¶
Insert a mechanism into all sections in a domain.
- Parameters:
mechanism_name (str) – The name of the mechanism to insert.
domain_name (str) – The name of the domain to insert the mechanism into.
distribute (bool, optional) – Whether to distribute the parameters after inserting the mechanism.
- uninsert_mechanism(mechanism_name: str, domain_name: str)[source]¶
Uninsert a mechanism from all sections in a domain
- Parameters:
mechanism_name (str) – The name of the mechanism to uninsert.
domain_name (str) – The name of the domain to uninsert the mechanism from.
- add_group(name, domains, select_by=None, min_value=None, max_value=None)[source]¶
Add a group of sections to the model.
- Parameters:
name (str) – The name of the group.
domains (list[str]) – The domains to include in the group.
select_by (str, optional) – The parameter to select the sections by. Can be ‘diam’, ‘distance’, ‘domain_distance’.
min_value (float, optional) – The minimum value of the parameter.
max_value (float, optional) – The maximum value of the
- remove_group(group_name)[source]¶
Remove a group from the model.
- Parameters:
group_name (str) – The name of the group to remove.
- move_group_down(name)[source]¶
Move a group down in the list of groups.
- Parameters:
name (str) – The name of the group to move down.
- move_group_up(name)[source]¶
Move a group up in the list of groups.
- Parameters:
name (str) – The name of the group to move up.
- set_param(param_name: str, group_name: str = 'all', distr_type: str = 'constant', **distr_params)[source]¶
Set a parameter for a group of segments.
- Parameters:
param_name (str) – The name of the parameter to set.
group_name (str, optional) – The name of the group to set the parameter for. Default is ‘all’.
distr_type (str, optional) – The type of the distribution to use. Default is ‘constant’.
distr_params (dict) – The parameters of the distribution.
- set_distribution(param_name: str, group_name: None, distr_type: str = 'constant', **distr_params)[source]¶
Set a distribution for a parameter.
- Parameters:
param_name (str) – The name of the parameter to set.
group_name (str, optional) – The name of the group to set the parameter for. Default is ‘all’.
distr_type (str, optional) – The type of the distribution to use. Default is ‘constant’.
distr_params (dict) – The parameters of the distribution.
- distribute(param_name: str, precomputed_groups=None)[source]¶
Distribute a parameter to the segments.
- Parameters:
param_name (str) – The name of the parameter to distribute.
precomputed_groups (dict, optional) – A dictionary mapping group names to segments. Default is None.
- remove_distribution(param_name, group_name)[source]¶
Remove a distribution for a parameter.
- Parameters:
param_name (str) – The name of the parameter to remove the distribution for.
group_name (str) – The name of the group to remove the distribution for.
- plot_param(param_name, ax=None, show_nan=True)[source]¶
Plot the distribution of a parameter in the model.
- Parameters:
param_name (str) – The name of the parameter to plot.
ax (matplotlib.axes.Axes, optional) – The axes to plot on. Default is None.
show_nan (bool, optional) – Whether to show NaN values. Default is True.
- get_sections(filter_function)[source]¶
Filter sections using a lambda function.
- Parameters:
filter_function (Callable) – The lambda function to filter sections.
- get_segments(group_names=None)[source]¶
Get the segments in specified groups.
- Parameters:
group_names (List[str]) – The names of the groups to get segments from.
- remove_subtree(section)[source]¶
Remove a subtree from the model.
- Parameters:
section (Section) – The root section of the subtree to remove.
- add_default_mechanisms(recompile=False)¶
Add default mechanisms to the model.
- Parameters:
recompile (bool, optional) – Whether to recompile the mechanisms.
- add_iclamp(sec, loc, amp=0, delay=100, dur=100)¶
Add an IClamp to a section.
- Parameters:
sec (Section) – The section to add the IClamp to.
loc (float) – The location of the IClamp in the section.
amp (float, optional) – The amplitude of the IClamp. Default is 0.
delay (float, optional) – The delay of the IClamp. Default is 100.
dur (float, optional) – The duration of the IClamp. Default is 100.
- add_mechanism(mechanism_name: str, python_template_name: str = 'default', load=True, dir_name: str = 'mod', recompile=True) None¶
Create a Mechanism object from the MOD file (or LeakChannel).
- Parameters:
mechanism_name (str) – The name of the mechanism to add.
python_template_name (str, optional) – The name of the Python template to use. Default is ‘default’.
load (bool, optional) – Whether to load the mechanism using neuron.load_mechanisms.
- add_mechanisms(dir_name: str = 'mod', recompile=True) None¶
Add a set of mechanisms from an archive to the model.
- Parameters:
dir_name (str, optional) – The name of the archive to load mechanisms from. Default is ‘mod’.
recompile (bool, optional) – Whether to recompile the mechanisms.
- add_population(name, segments, N, syn_type)¶
Add a population of synapses to the model.
- Parameters:
name (str) – The name of the population.
segments (list[Segment]) – The segments to add the synapses to.
N (int) – The number of synapses to add.
syn_type (str) – The type of synapse to add.
- add_recording(sec, loc, var='v')¶
Add a recording to the model.
- Parameters:
sec (Section) – The section to record from.
loc (float) – The location along the normalized section length to record from.
var (str, optional) – The variable to record. Default is ‘v’.
- create_and_reference_sections_in_simulator()¶
Create and reference sections in the simulator.
- export_biophys(file_name, **kwargs)¶
Export the biophysical properties of the model to a JSON file.
- Parameters:
file_name (str) – The name of the file to write to.
**kwargs (dict) – Additional keyword arguments to pass to json.dump.
- export_morphology(file_name)¶
Write the SWC tree to an SWC file.
- Parameters:
version (str, optional) – The version of the morphology appended to the morphology name.
- export_stimuli(file_name, **kwargs)¶
Export the stimuli to a JSON and CSV file.
- Parameters:
file_name (str) – The name of the file to write to.
**kwargs (dict) – Additional keyword arguments to pass to json.dump.
- export_to_Jaxley(file_name)¶
- export_to_NEURON(file_name, include_kinetic_params=True)¶
Export the model to a python file with plain NEURON code to reproduce the model.
- Parameters:
file_name (str) – The name of the file to write to.
- from_dict(data)¶
Load the model from a dictionary.
- Parameters:
data (dict) – The dictionary representation of the model.
- get_traces()¶
- list_biophys(extension='json')¶
List the biophysical configurations available for the model.
- list_mechanisms(extension='mod')¶
List the mechanisms available for the model.
- list_morphologies(extension='swc')¶
List the morphologies available for the model.
- list_stimuli(extension='json')¶
List the stimuli configurations available for the model.
- load_biophys(file_name, recompile=True)¶
Load the biophysical properties of the model from a JSON file.
- Parameters:
file_name (str) – The name of the file to read from.
recompile (bool, optional) – Whether to recompile the mechanisms after loading. Default is True.
- load_mechanism(mechanism_name, dir_name='mod', recompile=False) None¶
Load a mechanism from the specified archive.
- Parameters:
mechanism_name (str) – The name of the mechanism to load.
dir_name (str, optional) – The name of the directory to load the mechanism from. Default is ‘mod’.
recompile (bool, optional) – Whether to recompile the mechanism.
- load_mechanisms(dir_name: str = 'mod', recompile=True) None¶
Load mechanisms from an archive.
- Parameters:
dir_name (str, optional) – The name of the archive to load mechanisms from.
recompile (bool, optional) – Whether to recompile the mechanisms.
- load_morphology(file_name, soma_notation='3PS', align=True, sort_children=True, force=False) None¶
Read an SWC file and build the SWC and section trees.
- Parameters:
file_name (str) – The name of the SWC file to read.
soma_notation (str, optional) – The notation of the soma in the SWC file. Can be ‘3PS’ (three-point soma) or ‘1PS’. Default is ‘3PS’.
align (bool, optional) – Whether to align the morphology to the soma center and align the apical dendrite (if present).
sort_children (bool, optional) – Whether to sort the children of each node by increasing subtree size in the tree sorting algorithms. If True, the traversal visits children with shorter subtrees first and assigns them lower indices. If False, children are visited in their original SWC file order (matching NEURON’s behavior).
- load_stimuli(file_name, load_legacy=False)¶
Load the stimuli from a JSON file.
- Parameters:
file_name (str) – The name of the file to read from.
- plot(*args, **kwargs)¶
- print_directory_tree(*args, **kwargs)¶
Print the directory tree.
- property recordings¶
The recordings of the model. Reference to the recordings in the simulator.
- remove_all_iclamps()¶
Remove all IClamps from the model.
- remove_all_populations()¶
Remove all populations of synapses from the model.
- remove_all_recordings(var=None)¶
Remove all recordings from the model.
- remove_all_stimuli()¶
Remove all stimuli from the model.
- remove_iclamp(sec, loc)¶
Remove an IClamp from a section.
- Parameters:
sec (Section) – The section to remove the IClamp from.
loc (float) – The location of the IClamp in the section.
- remove_population(name)¶
Remove a population of synapses from the model.
- Parameters:
name (str) – The name of the population
- remove_recording(sec, loc, var='v')¶
Remove a recording from the model.
- Parameters:
sec (Section) – The section to remove the recording from.
loc (float) – The location along the normalized section length to remove the recording from.
- run(duration=300, prerun_time=0, truncate=True)¶
Run the simulation for a specified duration, optionally preceded by a prerun period to stabilize the model.
- Parameters:
duration (float) – Duration of the main simulation (excluding prerun).
prerun_time (float) – Optional prerun period to run before the main simulation.
truncate (bool) – Whether to truncate prerun data after the simulation.
- set_segmentation(d_lambda=0.1, f=100)¶
Set the number of segments in each section based on the geometry.
- Parameters:
d_lambda (float) – The lambda value to use.
f (float) – The frequency value to use.
- standardize_channel(channel_name, python_template_name=None, mod_template_name=None, remove_old=True)¶
Standardize a channel by creating a new channel with the same kinetic properties using the standard equations.
- Parameters:
channel_name (str) – The name of the channel to standardize.
python_template_name (str, optional) – The name of the Python template to use.
mod_template_name (str, optional) – The name of the MOD template to use.
remove_old (bool, optional) – Whether to remove the old channel from the model. Default is True.
- stimuli_to_dict()¶
Convert the stimuli to a dictionary representation.
- Returns:
The dictionary representation of the stimuli.
- Return type:
dict
- to_dict()¶
Return a dictionary representation of the model.
- Returns:
The dictionary representation of the model.
- Return type:
dict
- update_population_input_params(pop_name, **params)¶
Update the input parameters of a population of synapses.
- Parameters:
pop_name (str) – The name of the population.
params (dict) – The parameters to update.
- update_population_kinetic_params(pop_name, **params)¶
Update the kinetic parameters of a population of synapses.
- Parameters:
pop_name (str) – The name of the population.
params (dict) – The parameters to update.
- reduce_subtree(root, reduction_frequency=0, total_segments_manual=-1, fit=True)[source]¶
Reduce a subtree to a single section.
- Parameters:
root (Section) – The root section of the subtree to reduce.
reduction_frequency (float, optional) – The frequency of the reduction. Default is 0.
total_segments_manual (int, optional) – The number of segments in the reduced subtree. Default is -1 (automatic).
fit (bool, optional) – Whether to create distributions for the reduced subtree by fitting the calculated average values. Default is True.