Skip to content

Commit

Permalink
Fixed loading point cell params from legacy models (iincl. ssue 607)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvbragin committed Oct 1, 2023
1 parent 5bbafa1 commit b75c109
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Version in development

**New features**

**Bug fixes**

- Fixed loading point cell params from legacy models (issue 607)

# Version 1.0.5

**New features**
Expand Down
7 changes: 7 additions & 0 deletions netpyne/cell/compartCell.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ def create(self, createNEURONObj=None):

# apply cell rules
for propLabel, prop in sim.net.params.cellParams.items(): # for each set of cell properties

# Try to catch a bug where the cell is designed to be PointCell but misclassfied as CompartCell in Pop._setCellClass()
# (may happen if .mod not compiled or mech name misspelled)
assert 'secs' in prop, \
f"""Cell rule labeled '{propLabel}' is a compartment cell, but it doesn't have required entry 'secs'.
If this cell is excpected to be a point cell instead, make sure the correspondent mechanism is included and compiled."""

conditionsMet = 1
if 'conds' in prop and len(prop['conds']) > 0:
for (condKey, condVal) in prop['conds'].items(): # check if all conditions are met
Expand Down
2 changes: 2 additions & 0 deletions netpyne/cell/pointCell.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self, gid, tags, create=True, associateGid=True):
if 'params' in self.tags:
dictParams = sim.replaceDictODict(self.tags.pop('params'))
self.params = deepcopy(dictParams)
else:
self.params = {}

if create and sim.cfg.createNEURONObj:
self.createNEURONObj() # create cell
Expand Down
62 changes: 34 additions & 28 deletions netpyne/network/pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,39 +498,48 @@ def _setCellClass(self):

else:
# set cell class: CompartCell for compartmental cells of PointCell for point neurons (NetStims, IntFire1,...)
try: # check if cellModel corresponds to an existing point process mechanism; if so, use PointCell
tmp = getattr(h, cellModel)
if cellModel and hasattr(h, cellModel):
# check if cellModel corresponds to an existing point process mechanism; if so, use PointCell
self.cellModelClass = sim.PointCell
excludeTags = [
'pop',
'cellModel',
'cellType',
'numCells',
'density',
'cellsList',
'gridSpacing',
'xRange',
'yRange',
'zRange',
'xnormRange',
'ynormRange',
'znormRange',
'vref',
'spkTimes',
'dynamicRates',
]
params = {k: v for k, v in self.tags.items() if k not in excludeTags}
self.tags['params'] = params
for k in self.tags['params']:
self.tags.pop(k)

if 'params' in self.tags and isinstance(self.tags['params'], dict):
# in some cases, params for point cell may already be grouped in the nested 'params' dict.
params = self.tags['params']
else:
# otherwise, try extracting them from the top level of tags dict
excludeTags = [
'pop',
'cellModel',
'cellType',
'numCells',
'density',
'cellsList',
'gridSpacing',
'xRange',
'yRange',
'zRange',
'xnormRange',
'ynormRange',
'znormRange',
'vref',
'spkTimes',
'dynamicRates',
]
params = {k: v for k, v in self.tags.items() if k not in excludeTags}
self.tags['params'] = params
for k in self.tags['params']:
self.tags.pop(k)
sim.net.params.popTagsCopiedToCells.append('params')

# if point cell params defined directly in pop params, need to scan them for string functions
if len(params):
from ..specs.netParams import CellParams

CellParams.updateStringFuncsWithPopParams(self.tags['pop'], params)
except:
else:
# otherwise assume has sections and some cellParam rules apply to it; use CompartCell
self.cellModelClass = sim.CompartCell

if getattr(self.tags, 'cellModel', None) in [
'NetStim',
'DynamicNetStim',
Expand All @@ -543,9 +552,6 @@ def _setCellClass(self):
'Warning: could not find %s point process mechanism required for population %s'
% (cellModel, self.tags['pop'])
)
self.cellModelClass = (
sim.CompartCell
) # otherwise assume has sections and some cellParam rules apply to it; use CompartCell

def calcRelativeSegCoords(self):
"""Calculate segment coordinates from 3d point coordinates
Expand Down

0 comments on commit b75c109

Please sign in to comment.