@@ -185,21 +185,32 @@ def replace_axon(sim=None, icell=None, axon_stump_length=60, n_sections=2):
185185
186186 nsec = len ([sec for sec in icell .axonal ])
187187
188+ print (f"In replace_axon { nsec = } " )
189+
188190 if nsec == 0 :
189- ais_diams = [1 , 1 ]
191+ ais_diams = [1 ] * n_sections
190192 elif nsec == 1 :
191- ais_diams = [icell .axon [0 ].diam , icell .axon [0 ].diam ]
193+ sec_x = [min (1 , x / n_sections * axon_stump_length / icell .axon [0 ].L )
194+ for x in range (0 , n_sections )]
195+ ais_diams = [icell .axon [0 ](sx ).diam for sx in sec_x ]
192196 else :
193- ais_diams = [icell .axon [0 ].diam , icell . axon [ 0 ]. diam ]
197+ ais_diams = [icell .axon [0 ].diam ] * n_sections
194198 # Define origin of distance function
195199 sim .neuron .h .distance (0 , 0.5 , sec = icell .soma [0 ])
196200
201+ end_point_dist = np .arange (1 , n_sections + 1 ) \
202+ * axon_stump_length / n_sections
203+
204+ idx = 1
205+
197206 for section in icell .axonal :
198- # If distance to soma is larger than 60, store diameter
199- if sim .neuron .h .distance (1 , 0.5 , sec = section ) \
200- > axon_stump_length :
201- ais_diams [1 ] = section .diam
207+ if idx >= len (ais_diams ):
202208 break
209+ if sim .neuron .h .distance (1 , 0.5 , sec = section )\
210+ < end_point_dist [idx ]:
211+ ais_diams [idx :] = section .diam
212+ else :
213+ idx += 1
203214
204215 for section in icell .axonal :
205216 sim .neuron .h .delete_section (sec = section )
@@ -214,7 +225,7 @@ def replace_axon(sim=None, icell=None, axon_stump_length=60, n_sections=2):
214225 icell .axonal .append (sec = section )
215226 icell .all .append (sec = section )
216227
217- for index in enumerate ( icell .axon ):
228+ for index in range ( len ( icell .axon ) ):
218229 if index == 0 :
219230 icell .axon [0 ].connect (icell .soma [0 ], 1.0 , 0.0 )
220231 else :
@@ -223,6 +234,7 @@ def replace_axon(sim=None, icell=None, axon_stump_length=60, n_sections=2):
223234 logger .debug (f"Replace axon with AIS { axon_stump_length = } , "
224235 f"{ n_sections = } " )
225236
237+
226238 default_replace_axon_hoc = \
227239 '''
228240proc replace_axon(){ local nSec, D1, D2
0 commit comments