Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 9483a91

Browse files
committed
replace_axon now allows the axon length and numbr of sections to be set
1 parent 4fcf47a commit 9483a91

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

bluepyopt/ephys/morphologies.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ def __init__(
5757
do_set_nseg=True,
5858
comment='',
5959
replace_axon_hoc=None,
60+
axon_stump_length=60,
61+
axon_stump_nsec=2,
6062
nseg_frequency=40,
6163
morph_modifiers=None,
6264
morph_modifiers_hoc=None,
@@ -74,6 +76,8 @@ def __init__(
7476
python, replace_axon is used instead. Must include
7577
'proc replace_axon(){ ... }
7678
If None,the default replace_axon is used
79+
axon_stump_length (float): Length of replacement axon
80+
axon_stump_nsec (int): Number of sections in replacement axon
7781
nseg_frequency (float): frequency of nseg
7882
do_set_nseg (bool): if True, it will use nseg_frequency
7983
morph_modifiers (list): list of functions to modify the icell
@@ -90,6 +94,8 @@ def __init__(
9094
morphology_path = str(morphology_path)
9195
self.morphology_path = morphology_path
9296
self.do_replace_axon = do_replace_axon
97+
self.axon_stump_length = axon_stump_length
98+
self.axon_stump_nsec = axon_stump_nsec
9399
self.do_set_nseg = do_set_nseg
94100
self.nseg_frequency = nseg_frequency
95101
self.morph_modifiers = morph_modifiers
@@ -155,7 +161,9 @@ def instantiate(self, sim=None, icell=None):
155161
self.set_nseg(icell)
156162

157163
if self.do_replace_axon:
158-
self.replace_axon(sim=sim, icell=icell)
164+
self.replace_axon(sim=sim, icell=icell,
165+
axon_stump_length=self.axon_stump_length,
166+
n_sections=self.axon_stump_nsec)
159167

160168
if self.morph_modifiers is not None:
161169
for morph_modifier in self.morph_modifiers:
@@ -172,7 +180,7 @@ def set_nseg(self, icell):
172180
section.nseg = 1 + 2 * int(section.L / self.nseg_frequency)
173181

174182
@staticmethod
175-
def replace_axon(sim=None, icell=None):
183+
def replace_axon(sim=None, icell=None, axon_stump_length=60, n_sections=2):
176184
"""Replace axon"""
177185

178186
nsec = len([sec for sec in icell.axonal])
@@ -188,27 +196,30 @@ def replace_axon(sim=None, icell=None):
188196

189197
for section in icell.axonal:
190198
# If distance to soma is larger than 60, store diameter
191-
if sim.neuron.h.distance(1, 0.5, sec=section) > 60:
199+
if sim.neuron.h.distance(1, 0.5, sec=section) > axon_stump_length:
192200
ais_diams[1] = section.diam
193201
break
194202

195203
for section in icell.axonal:
196204
sim.neuron.h.delete_section(sec=section)
197205

198206
# Create new axon array
199-
sim.neuron.h.execute('create axon[2]', icell)
207+
sim.neuron.h.execute(f"create axon[{n_sections}]", icell)
200208

201209
for index, section in enumerate(icell.axon):
202210
section.nseg = 1
203-
section.L = 30
211+
section.L = axon_stump_length/n_sections
204212
section.diam = ais_diams[index]
205213
icell.axonal.append(sec=section)
206214
icell.all.append(sec=section)
207215

208-
icell.axon[0].connect(icell.soma[0], 1.0, 0.0)
209-
icell.axon[1].connect(icell.axon[0], 1.0, 0.0)
216+
for index in enumerate(icell.axon):
217+
if index == 0:
218+
icell.axon[0].connect(icell.soma[0], 1.0, 0.0)
219+
else:
220+
icell.axon[index].connect(icell.axon[index-1], 1.0, 0.0)
210221

211-
logger.debug('Replace axon with AIS')
222+
logger.debug(f"Replace axon with AIS {axon_stump_length = }, {n_sections =}")
212223

213224
default_replace_axon_hoc = \
214225
'''

0 commit comments

Comments
 (0)