diff --git a/python/moose/moose.py b/python/moose/moose.py index 069d43b999..94a664f886 100644 --- a/python/moose/moose.py +++ b/python/moose/moose.py @@ -222,7 +222,7 @@ def mergeChemModel(src, des): return False # NML2 reader and writer function. -def mooseReadNML2( modelpath ): +def mooseReadNML2( modelpath, verbose = False ): """Read NeuroML model (version 2) and return reader object. """ global nml2Import_ @@ -230,7 +230,7 @@ def mooseReadNML2( modelpath ): mu.warn( nml2ImportError_ ) raise RuntimeError( "Could not load NML2 support." ) - reader = _neuroml2.NML2Reader( ) + reader = _neuroml2.NML2Reader( verbose = verbose ) reader.read( modelpath ) return reader diff --git a/python/moose/neuroml2/reader.py b/python/moose/neuroml2/reader.py index 3473943d04..2f2e2d85c8 100644 --- a/python/moose/neuroml2/reader.py +++ b/python/moose/neuroml2/reader.py @@ -127,6 +127,7 @@ def __init__(self, verbose=False): self.pop_to_cell_type = {} self.seg_id_to_comp_name = {} self.paths_to_chan_elements = {} + self.network = None def read(self, filename, symmetric=True): filename = os.path.realpath( filename ) @@ -139,9 +140,9 @@ def read(self, filename, symmetric=True): if len(self.doc.networks)>=1: self.network = self.doc.networks[0] - moose.celsius = self._getTemperature() + self.importConcentrationModels(self.doc) self.importIonChannels(self.doc) self.importInputs(self.doc) @@ -156,10 +157,13 @@ def read(self, filename, symmetric=True): mu.info("Read all from %s"%filename) def _getTemperature(self): - if self.network.type=="networkWithTemperature": - return SI(self.network.temperature) - else: - return 0 # Why not, if there's no temp dependence in nml..? + if self.network is not None: + if self.network.type=="networkWithTemperature": + return SI(self.network.temperature) + else: + # Why not, if there's no temp dependence in nml..? + return 0 + return SI('25') def getCellInPopulation(self, pop_id, index): return self.cells_in_populations[pop_id][index] @@ -400,11 +404,8 @@ def calculateRateFn(self, ratefn, vmin, vmax, tablen=3000, vShift='0mV'): mu.info("Using %s to evaluate rate"%ct.name) rate = [] for v in tab: - vals = pynml.evaluate_component(ct - , req_variables = - {'v':'%sV'%v,'vShift':vShift,'temperature':self._getTemperature()} - ) - # mu.info vals + req_vars = {'v':'%sV'%v,'vShift':vShift,'temperature':self._getTemperature()} + vals = pynml.evaluate_component(ct, req_variables = req_vars) if 'x' in vals: rate.append(vals['x']) if 't' in vals: @@ -413,6 +414,9 @@ def calculateRateFn(self, ratefn, vmin, vmax, tablen=3000, vShift='0mV'): rate.append(vals['r']) return np.array(rate) + print( "[WARN ] Could not determine rate: %s %s %s" %(ratefn.type,vmin,vmax)) + return np.array([]) + def importChannelsToCell(self, nmlcell, moosecell, membrane_properties): sg_to_segments = self._cell_to_sg[nmlcell] for chdens in membrane_properties.channel_densities + membrane_properties.channel_density_v_shifts: @@ -480,10 +484,11 @@ def _is_standard_nml_rate(self, rate): def createHHChannel(self, chan, vmin=-150e-3, vmax=100e-3, vdivs=5000): mchan = moose.HHChannel('%s/%s' % (self.lib.path, chan.id)) mgates = [moose.element(x) for x in [mchan.gateX, mchan.gateY, mchan.gateZ]] - assert(len(chan.gate_hh_rates) <= 3) # We handle only up to 3 gates in HHCHannel + assert len(chan.gate_hh_rates)<=3, "We handle only up to 3 gates in HHCHannel" if self.verbose: mu.info('== Creating channel: %s (%s) -> %s (%s)'%(chan.id, chan.gate_hh_rates, mchan, mgates)) + all_gates = chan.gates + chan.gate_hh_rates for ngate, mgate in zip(all_gates,mgates): if mgate.name.endswith('X'): @@ -505,9 +510,7 @@ def createHHChannel(self, chan, vmin=-150e-3, vmax=100e-3, vdivs=5000): # refering to tau_inf and m_inf?? fwd = ngate.forward_rate rev = ngate.reverse_rate - self.paths_to_chan_elements['%s/%s'%(chan.id,ngate.id)] = '%s/%s'%(chan.id,mgate.name) - q10_scale = 1 if ngate.q10_settings: if ngate.q10_settings.type == 'q10Fixed': @@ -529,6 +532,7 @@ def createHHChannel(self, chan, vmin=-150e-3, vmax=100e-3, vdivs=5000): if (fwd is not None) and (rev is not None): alpha = self.calculateRateFn(fwd, vmin, vmax, vdivs) beta = self.calculateRateFn(rev, vmin, vmax, vdivs) + mgate.tableA = q10_scale * (alpha) mgate.tableB = q10_scale * (alpha + beta) @@ -547,8 +551,9 @@ def createHHChannel(self, chan, vmin=-150e-3, vmax=100e-3, vdivs=5000): tau = 1 / (alpha + beta) if inf is not None: inf = self.calculateRateFn(inf, vmin, vmax, vdivs) - mgate.tableA = q10_scale * (inf / tau) - mgate.tableB = q10_scale * (1 / tau) + if len(inf) > 0: + mgate.tableA = q10_scale * (inf / tau) + mgate.tableB = q10_scale * (1 / tau) if self.verbose: mu.info('%s: Created %s for %s'%(self.filename,mchan.path,chan.id)) @@ -582,7 +587,7 @@ def importInputs(self, doc): def importIonChannels(self, doc, vmin=-150e-3, vmax=100e-3, vdivs=5000): if self.verbose: - mu.info('%s : Importing the ion channels' % self.filename ) + mu.info('%s: Importing the ion channels' % self.filename ) for chan in doc.ion_channel+doc.ion_channel_hhs: if chan.type == 'ionChannelHH': @@ -596,7 +601,7 @@ def importIonChannels(self, doc, vmin=-150e-3, vmax=100e-3, vdivs=5000): self.nml_to_moose[chan] = mchan self.proto_chans[chan.id] = mchan if self.verbose: - mu.info( self.filename + ' : Created ion channel %s for %s %s'%( + mu.info( self.filename + ': Created ion channel %s for %s %s'%( mchan.path, chan.type, chan.id)) def importConcentrationModels(self, doc):