Skip to content

Commit f917df1

Browse files
authored
Merge pull request #319 from dilawar/master
Hotfix NML2. If self.network not found, sett the temperate to 25 deg C.
2 parents b4637b2 + 6375834 commit f917df1

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

python/moose/moose.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,15 @@ def mergeChemModel(src, des):
222222
return False
223223

224224
# NML2 reader and writer function.
225-
def mooseReadNML2( modelpath ):
225+
def mooseReadNML2( modelpath, verbose = False ):
226226
"""Read NeuroML model (version 2) and return reader object.
227227
"""
228228
global nml2Import_
229229
if not nml2Import_:
230230
mu.warn( nml2ImportError_ )
231231
raise RuntimeError( "Could not load NML2 support." )
232232

233-
reader = _neuroml2.NML2Reader( )
233+
reader = _neuroml2.NML2Reader( verbose = verbose )
234234
reader.read( modelpath )
235235
return reader
236236

python/moose/neuroml2/reader.py

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def __init__(self, verbose=False):
127127
self.pop_to_cell_type = {}
128128
self.seg_id_to_comp_name = {}
129129
self.paths_to_chan_elements = {}
130+
self.network = None
130131

131132
def read(self, filename, symmetric=True):
132133
filename = os.path.realpath( filename )
@@ -139,9 +140,9 @@ def read(self, filename, symmetric=True):
139140

140141
if len(self.doc.networks)>=1:
141142
self.network = self.doc.networks[0]
142-
143143
moose.celsius = self._getTemperature()
144144

145+
145146
self.importConcentrationModels(self.doc)
146147
self.importIonChannels(self.doc)
147148
self.importInputs(self.doc)
@@ -156,10 +157,13 @@ def read(self, filename, symmetric=True):
156157
mu.info("Read all from %s"%filename)
157158

158159
def _getTemperature(self):
159-
if self.network.type=="networkWithTemperature":
160-
return SI(self.network.temperature)
161-
else:
162-
return 0 # Why not, if there's no temp dependence in nml..?
160+
if self.network is not None:
161+
if self.network.type=="networkWithTemperature":
162+
return SI(self.network.temperature)
163+
else:
164+
# Why not, if there's no temp dependence in nml..?
165+
return 0
166+
return SI('25')
163167

164168
def getCellInPopulation(self, pop_id, index):
165169
return self.cells_in_populations[pop_id][index]
@@ -400,11 +404,8 @@ def calculateRateFn(self, ratefn, vmin, vmax, tablen=3000, vShift='0mV'):
400404
mu.info("Using %s to evaluate rate"%ct.name)
401405
rate = []
402406
for v in tab:
403-
vals = pynml.evaluate_component(ct
404-
, req_variables =
405-
{'v':'%sV'%v,'vShift':vShift,'temperature':self._getTemperature()}
406-
)
407-
# mu.info vals
407+
req_vars = {'v':'%sV'%v,'vShift':vShift,'temperature':self._getTemperature()}
408+
vals = pynml.evaluate_component(ct, req_variables = req_vars)
408409
if 'x' in vals:
409410
rate.append(vals['x'])
410411
if 't' in vals:
@@ -413,6 +414,9 @@ def calculateRateFn(self, ratefn, vmin, vmax, tablen=3000, vShift='0mV'):
413414
rate.append(vals['r'])
414415
return np.array(rate)
415416

417+
print( "[WARN ] Could not determine rate: %s %s %s" %(ratefn.type,vmin,vmax))
418+
return np.array([])
419+
416420
def importChannelsToCell(self, nmlcell, moosecell, membrane_properties):
417421
sg_to_segments = self._cell_to_sg[nmlcell]
418422
for chdens in membrane_properties.channel_densities + membrane_properties.channel_density_v_shifts:
@@ -480,10 +484,11 @@ def _is_standard_nml_rate(self, rate):
480484
def createHHChannel(self, chan, vmin=-150e-3, vmax=100e-3, vdivs=5000):
481485
mchan = moose.HHChannel('%s/%s' % (self.lib.path, chan.id))
482486
mgates = [moose.element(x) for x in [mchan.gateX, mchan.gateY, mchan.gateZ]]
483-
assert(len(chan.gate_hh_rates) <= 3) # We handle only up to 3 gates in HHCHannel
487+
assert len(chan.gate_hh_rates)<=3, "We handle only up to 3 gates in HHCHannel"
484488

485489
if self.verbose:
486490
mu.info('== Creating channel: %s (%s) -> %s (%s)'%(chan.id, chan.gate_hh_rates, mchan, mgates))
491+
487492
all_gates = chan.gates + chan.gate_hh_rates
488493
for ngate, mgate in zip(all_gates,mgates):
489494
if mgate.name.endswith('X'):
@@ -505,9 +510,7 @@ def createHHChannel(self, chan, vmin=-150e-3, vmax=100e-3, vdivs=5000):
505510
# refering to tau_inf and m_inf??
506511
fwd = ngate.forward_rate
507512
rev = ngate.reverse_rate
508-
509513
self.paths_to_chan_elements['%s/%s'%(chan.id,ngate.id)] = '%s/%s'%(chan.id,mgate.name)
510-
511514
q10_scale = 1
512515
if ngate.q10_settings:
513516
if ngate.q10_settings.type == 'q10Fixed':
@@ -529,6 +532,7 @@ def createHHChannel(self, chan, vmin=-150e-3, vmax=100e-3, vdivs=5000):
529532
if (fwd is not None) and (rev is not None):
530533
alpha = self.calculateRateFn(fwd, vmin, vmax, vdivs)
531534
beta = self.calculateRateFn(rev, vmin, vmax, vdivs)
535+
532536
mgate.tableA = q10_scale * (alpha)
533537
mgate.tableB = q10_scale * (alpha + beta)
534538

@@ -547,8 +551,9 @@ def createHHChannel(self, chan, vmin=-150e-3, vmax=100e-3, vdivs=5000):
547551
tau = 1 / (alpha + beta)
548552
if inf is not None:
549553
inf = self.calculateRateFn(inf, vmin, vmax, vdivs)
550-
mgate.tableA = q10_scale * (inf / tau)
551-
mgate.tableB = q10_scale * (1 / tau)
554+
if len(inf) > 0:
555+
mgate.tableA = q10_scale * (inf / tau)
556+
mgate.tableB = q10_scale * (1 / tau)
552557

553558
if self.verbose:
554559
mu.info('%s: Created %s for %s'%(self.filename,mchan.path,chan.id))
@@ -582,7 +587,7 @@ def importInputs(self, doc):
582587

583588
def importIonChannels(self, doc, vmin=-150e-3, vmax=100e-3, vdivs=5000):
584589
if self.verbose:
585-
mu.info('%s : Importing the ion channels' % self.filename )
590+
mu.info('%s: Importing the ion channels' % self.filename )
586591

587592
for chan in doc.ion_channel+doc.ion_channel_hhs:
588593
if chan.type == 'ionChannelHH':
@@ -596,7 +601,7 @@ def importIonChannels(self, doc, vmin=-150e-3, vmax=100e-3, vdivs=5000):
596601
self.nml_to_moose[chan] = mchan
597602
self.proto_chans[chan.id] = mchan
598603
if self.verbose:
599-
mu.info( self.filename + ' : Created ion channel %s for %s %s'%(
604+
mu.info( self.filename + ': Created ion channel %s for %s %s'%(
600605
mchan.path, chan.type, chan.id))
601606

602607
def importConcentrationModels(self, doc):

0 commit comments

Comments
 (0)