Skip to content

Commit

Permalink
Added existing section lists to instantiated cell to prevent crash on…
Browse files Browse the repository at this point in the history
… iterating over deleted myelin section
  • Loading branch information
lukasgd committed Aug 5, 2022
1 parent f2ca1ed commit 2c67258
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions bluepyopt/ephys/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def __init__(

# Cell instantiation in simulator
self.icell = None
self.icell_existing_secs = None

self.param_values = None
self.gid = gid
Expand Down Expand Up @@ -240,6 +241,10 @@ def instantiate_morphology(self, sim=None):

self.morphology.instantiate(sim=sim, icell=self.icell)

self.icell_existing_secs = [
sec for sec in self.secarray_names
if sim.neuron.h.section_exists(sec, self.icell)]

def instantiate(self, sim=None):
"""Instantiate model in simulator"""

Expand Down Expand Up @@ -268,6 +273,7 @@ def destroy(self, sim=None): # pylint: disable=W0613
sim.neuron.h.Vector().size()

self.icell = None
self.icell_existing_secs = None

self.morphology.destroy(sim=sim)
for mechanism in self.mechanisms:
Expand All @@ -289,7 +295,8 @@ def _create_sim_desc(self, param_values,
ignored_globals=(), template=None,
disable_banner=False,
template_dir=None,
sim_desc_creator=None):
sim_desc_creator=None,
sim=None):
"""Create simulator description for this model"""

to_unfreeze = []
Expand Down Expand Up @@ -324,17 +331,15 @@ def _create_sim_desc(self, param_values,
replace_axon += morph_modifier_hoc
elif sim_desc_creator is create_acc.create_acc:
if self.morphology.do_replace_axon:
replace_axon = [dict(nseg=section.nseg,
length=section.L,
radius=0.5 * section.diam,
tag=morphologies._arb_tags['axon'])
for section in self.icell.axon]
# Requires safe iteration over myelin section
# replace_axon += [dict(nseg=section.nseg,
# length=section.L,
# radius=0.5 * section.diam,
# tag=morphologies._arb_tags['myelin'])
# for section in self.icell.myelin]
replace_axon = []
for sec in ['axon', 'myelin']:
if sec in self.icell_existing_secs:
replace_axon += \
[dict(nseg=section.nseg,
length=section.L,
radius=0.5 * section.diam,
tag=morphologies._arb_tags[sec])
for section in getattr(self.icell, sec)]
else:
replace_axon = None
else:
Expand Down

0 comments on commit 2c67258

Please sign in to comment.