Model¶
- class dendrotweaks.model.Model(path_to_model, simulator_name='NEURON')[source]¶
Bases:
object
A model object that represents a neuron model.
- 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 domains¶
The morphological or functional domains of the model. Reference to the domains in the section tree.
- property recordings¶
The recordings of the model. Reference to the recordings in the simulator.
- property groups¶
The dictionary of segment groups in the model.
- property groups_to_parameters¶
The dictionary mapping segment groups to parameters.
- property mechs_to_domains¶
The dictionary mapping mechanisms to domains where they are inserted.
- 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.
- list_biophys(extension='json')[source]¶
List the biophysical configurations available for the model.
- load_morphology(file_name, soma_notation='3PS', align=True, sort_children=True, force=False) None [source]¶
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).
- create_and_reference_sections_in_simulator()[source]¶
Create and reference sections in the simulator.
- 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.
- set_segmentation(d_lambda=0.1, f=100)[source]¶
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.
- add_default_mechanisms(recompile=False)[source]¶
Add default mechanisms to the model.
- Parameters:
recompile (bool, optional) – Whether to recompile the mechanisms.
- add_mechanisms(dir_name: str = 'mod', recompile=True) None [source]¶
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_mechanism(mechanism_name: str, python_template_name: str = 'default', load=True, dir_name: str = 'mod', recompile=True) None [source]¶
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.
- load_mechanisms(dir_name: str = 'mod', recompile=True) None [source]¶
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_mechanism(mechanism_name, dir_name='mod', recompile=False) None [source]¶
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.
- standardize_channel(channel_name, python_template_name=None, mod_template_name=None, remove_old=True)[source]¶
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.
- define_domain(domain_name: str, sections, distribute=True)[source]¶
Adds a new domain to the cell and ensures proper partitioning of the section tree graph.
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. However, if the domain already exists and is being extended, mechanisms will be inserted automatically into the newly added sections.
- Parameters:
domain_name (str) – The name of the domain to be added or extended.
sections (list[Section] or Callable) – The sections to include in the domain. If a callable is provided, it should be a filter function applied to the list of all sections in the model.
distribute (bool, optional) – Whether to re-distribute the parameters after defining the domain. Default is True.
- 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.
- add_iclamp(sec, loc, amp=0, delay=100, dur=100)[source]¶
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.
- remove_iclamp(sec, loc)[source]¶
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.
- add_population(segments, N, syn_type)[source]¶
Add a population of synapses to the model.
- Parameters:
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.
- update_population_kinetic_params(pop_name, **params)[source]¶
Update the kinetic parameters of a population of synapses.
- Parameters:
pop_name (str) – The name of the population.
params (dict) – The parameters to update.
- update_population_input_params(pop_name, **params)[source]¶
Update the input parameters of a population of synapses.
- Parameters:
pop_name (str) – The name of the population.
params (dict) – The parameters to update.
- remove_population(name)[source]¶
Remove a population of synapses from the model.
- Parameters:
name (str) – The name of the population
- add_recording(sec, loc, var='v')[source]¶
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’.
- remove_recording(sec, loc, var='v')[source]¶
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)[source]¶
Run the simulation for a specified duration.
- Parameters:
duration (float, optional) – The duration of the simulation. Default is 300.
- remove_subtree(sec)[source]¶
Remove a subtree from the model.
- Parameters:
sec (Section) – The root section of the subtree to remove.
- 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.
- 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.
- export_morphology(file_name)[source]¶
Write the SWC tree to an SWC file.
- Parameters:
version (str, optional) – The version of the morphology appended to the morphology name.
- to_dict()[source]¶
Return a dictionary representation of the model.
- Returns:
The dictionary representation of the model.
- Return type:
dict
- from_dict(data)[source]¶
Load the model from a dictionary.
- Parameters:
data (dict) – The dictionary representation of the model.
- export_biophys(file_name, **kwargs)[source]¶
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.
- load_biophys(file_name, recompile=True)[source]¶
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.
- stimuli_to_dict()[source]¶
Convert the stimuli to a dictionary representation.
- Returns:
The dictionary representation of the stimuli.
- Return type:
dict
- export_stimuli(file_name, **kwargs)[source]¶
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.