Skip to content

Commit

Permalink
Added axon diameter as option, using legacy replace axon code
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjorthmedh committed Dec 19, 2024
1 parent d153cc9 commit 6140ade
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
21 changes: 14 additions & 7 deletions snudda/neurons/neuron_model_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def __init__(self,
modulation_key=None,
use_rxd_neuromodulation=True,
replace_axon_length=60e-6,
replace_axon_nseg_frequency=40e-6):
replace_axon_nseg_frequency=40e-6,
replace_axon_hoc=None):

"""
Constructor
Expand All @@ -52,7 +53,7 @@ def __init__(self,
parameter_key (str): parameter key for lookup in parameter.json
morphology_key (str): morphology key, together with parameter_key lookup in meta.json
modulation_key (str): modulation key, lookup in modulation.json
replace_axon_hoc (str): replacement axon, hoc format
"""

# OBS, modulation_id is not used. morphology_id, parameter_id and modulation_id will be deprecated
Expand Down Expand Up @@ -105,7 +106,8 @@ def __init__(self,

morph = self.define_morphology(replace_axon=True, morph_file=morph_file,
replace_axon_length=replace_axon_length,
replace_axon_nseg_frequency=replace_axon_nseg_frequency)
replace_axon_nseg_frequency=replace_axon_nseg_frequency,
replace_axon_hoc=replace_axon_hoc)

mechs = self.define_mechanisms(mechanism_config=mech_file)
params = self.define_parameters(param_file, parameter_id, parameter_key)
Expand Down Expand Up @@ -299,20 +301,23 @@ def define_parameters(self, parameter_config, parameter_id=None, parameter_key=N

def define_morphology(self, replace_axon=True, morph_file=None,
replace_axon_length=60e-6,
replace_axon_nseg_frequency=40e-6): # This only supported by hoc replacement
replace_axon_nseg_frequency=40e-6,
replace_axon_hoc=None): # This only supported by hoc replacement
"""
Define morphology. Handles SWC and ASC.
Args:
replace_axon (bool): Is axon replaced with a stump for simulation, default True
morph_file (str): Path to morphology
replace_axon_hoc (str): Override the axon hoc
"""

assert (morph_file is not None)

return ephys.morphologies.NrnFileMorphology(morph_file, do_replace_axon=replace_axon,
axon_stub_length=replace_axon_length*1e6,
axon_nseg_frequency=replace_axon_nseg_frequency*1e6)
axon_nseg_frequency=replace_axon_nseg_frequency*1e6,
replace_axon_hoc=replace_axon_hoc)

##############################################################################

Expand Down Expand Up @@ -471,9 +476,11 @@ def instantiate(self, sim=None):

############################################################################

def get_replacement_axon(self, axon_length=60e-6, axon_diameter=None, axon_nseg=None):
@staticmethod
def get_replacement_axon(axon_length=60e-6, axon_diameter=None, axon_nseg=None):

raise DeprecationWarning("This function is now orphaned. Might need to re-update it if we switch to using hoc")
# Legacy code is now used again
# raise DeprecationWarning("This function is now orphaned. Might need to re-update it if we switch to using hoc")

"""
If axon_length is given as a scalar, then the code is similar to the BluePyOpt hoc, with the modification
Expand Down
21 changes: 20 additions & 1 deletion snudda/simulate/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ def setup_neurons(self):
meta_file = snudda_parse_path(os.path.join(neuron_path, "meta.json"), self.snudda_data)
axon_length = 60e-6
axon_nseg_frequency = 40e-6
replace_axon_hoc = None # Use default axon

if os.path.isfile(meta_file):
with open(meta_file, "r") as mf:
Expand All @@ -744,6 +745,23 @@ def setup_neurons(self):
axon_length = replace_info.get("axon_length", 60e-6)
axon_nseg_frequency = replace_info.get("axon_nseg_frequency", 40e-6)

if "axon_diameter" in meta_data[meta_parameter_key][meta_morphology_key]:
axon_diameter = meta_data[meta_parameter_key][meta_morphology_key]["axon_diameter"]

if "axon_nseg" in meta_data[meta_parameter_key][meta_morphology_key]:
axon_nseg = meta_data[meta_parameter_key][meta_morphology_key]["axon_nseg"]
else:
axon_nseg = [1]*len(axon_diameter)

# We need to use the old legacy code
replace_axon_hoc = NeuronModel.get_replacement_axon(axon_length=axon_length,
axon_diameter=axon_diameter,
axon_nseg=axon_nseg)

print(f"Using legacy replace axon hoc for neuron "
f"{self.network_info['neurons'][ID]['name']} {ID}, "
f"{axon_length = }, {axon_diameter}, {axon_nseg = }")

# Obs, neurons is a dictionary
if self.network_info["neurons"][ID]["virtual_neuron"]:

Expand Down Expand Up @@ -789,7 +807,8 @@ def setup_neurons(self):
modulation_key=modulation_key,
use_rxd_neuromodulation=self.use_rxd_neuromodulation,
replace_axon_length=axon_length,
replace_axon_nseg_frequency=axon_nseg_frequency)
replace_axon_nseg_frequency=axon_nseg_frequency,
replace_axon_hoc=replace_axon_hoc)

# Register ID as belonging to this worker node
try:
Expand Down

0 comments on commit 6140ade

Please sign in to comment.