def createPopulations(self): self.populationDict = {} for population in self.network.findall(".//{"+nml_ns+"}population"): cellname = population.attrib["cell_type"] populationname = population.attrib["name"] print "loading", populationname ## if channel does not exist in library load it from xml file if not self.context.exists('/library/'+cellname): mmlR = MorphML(self.nml_params) cellDict = mmlR.readMorphMLFromFile(cellname+'.morph.xml') self.cellSegmentDict.update(cellDict) libcell = moose.Cell('/library/'+cellname) self.populationDict[populationname] = (cellname,{}) for instance in population.findall(".//{"+nml_ns+"}instance"): instanceid = instance.attrib['id'] location = instance.find('./{'+nml_ns+'}location') rotationnote = instance.find('./{'+meta_ns+'}notes') if rotationnote is not None: ## the text in rotationnote is zrotation=xxxxxxx zrotation = float(string.split(rotationnote.text,'=')[1]) else: zrotation = 0 ## deep copies the library cell to an instance cell = moose.Cell(libcell,"/"+populationname+"_"+instanceid) self.populationDict[populationname][1][int(instanceid)]=cell x = float(location.attrib['x'])*self.length_factor y = float(location.attrib['y'])*self.length_factor z = float(location.attrib['z'])*self.length_factor self.translate_rotate(cell,x,y,z,zrotation)
def createPopulations(self): self.populationDict = {} for population in self.network.findall(".//{" + nml_ns + "}population"): cellname = population.attrib["cell_type"] populationname = population.attrib["name"] print "loading", populationname ## if channel does not exist in library load it from xml file if not self.context.exists('/library/' + cellname): mmlR = MorphML(self.nml_params) cellDict = mmlR.readMorphMLFromFile(cellname + '.morph.xml') self.cellSegmentDict.update(cellDict) libcell = moose.Cell('/library/' + cellname) self.populationDict[populationname] = (cellname, {}) for instance in population.findall(".//{" + nml_ns + "}instance"): instanceid = instance.attrib['id'] location = instance.find('./{' + nml_ns + '}location') rotationnote = instance.find('./{' + meta_ns + '}notes') if rotationnote is not None: ## the text in rotationnote is zrotation=xxxxxxx zrotation = float(string.split(rotationnote.text, '=')[1]) else: zrotation = 0 ## deep copies the library cell to an instance cell = moose.Cell(libcell, "/" + populationname + "_" + instanceid) self.populationDict[populationname][1][int(instanceid)] = cell x = float(location.attrib['x']) * self.length_factor y = float(location.attrib['y']) * self.length_factor z = float(location.attrib['z']) * self.length_factor self.translate_rotate(cell, x, y, z, zrotation)
def readNeuroMLFromFile(self,filename,params={}): """ For the format of params required to tweak what cells are loaded, refer to the doc string of NetworkML.readNetworkMLFromFile(). """ print "Loading neuroml file ... ", filename tree = ET.parse(filename) root_element = tree.getroot() self.lengthUnits = root_element.attrib['lengthUnits'] self.temperature = CELSIUS_default # gets replaced below if tag for temperature is present self.temperature_default = True for meta_property in root_element.findall('.//{'+meta_ns+'}property'): tagname = meta_property.attrib['tag'] if 'temperature' in tagname: self.temperature = float(meta_property.attrib['value']) self.temperature_default = False if self.temperature_default: print "Using default temperature of", self.temperature,"degrees Celsius." self.nml_params = {'temperature':self.temperature} #print "Loading channels and synapses into MOOSE /library ..." cmlR = ChannelML(self.nml_params) for channels in root_element.findall('.//{'+neuroml_ns+'}channels'): self.channelUnits = channels.attrib['units'] for channel in channels.findall('.//{'+cml_ns+'}channel_type'): ## ideally I should read in extra params ## from within the channel_type element and put those in also. ## Global params should override local ones. cmlR.readChannelML(channel,params={},units=self.channelUnits) for synapse in channels.findall('.//{'+cml_ns+'}synapse_type'): cmlR.readSynapseML(synapse,units=self.channelUnits) for ionConc in channels.findall('.//{'+cml_ns+'}ion_concentration'): cmlR.readIonConcML(ionConc,units=self.channelUnits) #print "Loading cell definitions into MOOSE /library ..." mmlR = MorphML(self.nml_params) self.cellsDict = {} for cells in root_element.findall('.//{'+neuroml_ns+'}cells'): for cell in cells.findall('.//{'+neuroml_ns+'}cell'): cellDict = mmlR.readMorphML(cell,params={},lengthUnits=self.lengthUnits) self.cellsDict.update(cellDict) #print "Loading individual cells into MOOSE root ... " nmlR = NetworkML(self.nml_params) self.populationDict, self.projectionDict = \ nmlR.readNetworkML(root_element,self.cellsDict,params=params,lengthUnits=self.lengthUnits)
def readNeuroMLFromFile(self,filename,params={}): """ For the format of params required to tweak what cells are loaded, refer to the doc string of NetworkML.readNetworkMLFromFile(). """ tree = ET.parse(filename) root_element = tree.getroot() self.length_units = root_element.attrib['length_units'] print filename mmlR = MorphML() self.cellsList = [] for cells in root_element.findall('.//{'+self.neuroml_ns+'}cells'): print 'found a cell' for cell in cells.findall('.//{'+self.neuroml_ns+'}cell'): cellList = mmlR.readMorphML(cell,params={},length_units=self.length_units) self.cellsList.extend(cellList) return self.cellsList
def createPopulations(self): """ Create population dictionary. """ populations = self.network.findall(".//{" + nmu.nml_ns + "}population") if not populations: utils.dump("WARN", [ "No population find in model", "Searching in namespace {}".format(nmu.nml_ns) ], frame=inspect.currentframe()) for population in populations: cellname = population.attrib["cell_type"] populationName = population.attrib["name"] utils.dump("INFO", "Loading population `{0}`".format(populationName)) # if cell does not exist in library load it from xml file if not moose.exists(self.libraryPath + '/' + cellname): utils.dump( "DEBUG", "Searching in subdirectories for cell types" + " in `{0}.xml` and `{0}.morph.xml` ".format(cellname)) mmlR = MorphML.MorphML(self.nml_params) model_filenames = (cellname + '.xml', cellname + '.morph.xml') success = False for modelFile in model_filenames: model_path = nmu.find_first_file(modelFile, self.modelDir) if model_path is not None: cellDict = mmlR.readMorphMLFromFile(model_path) success = True break if not success: raise IOError( 'For cell {0}: files {1} not found under {2}.'.format( cellname, model_filenames, self.modelDir)) self.cellSegmentDict.update(cellDict) if cellname == 'LIF': cellid = moose.LeakyIaF(self.libraryPath + '/' + cellname) else: # added cells as a Neuron class. cellid = moose.Neuron(self.libraryPath + '/' + cellname) self.populationDict[populationName] = (cellname, {}) for instance in population.findall(".//{" + nmu.nml_ns + "}instance"): instanceid = instance.attrib['id'] location = instance.find('./{' + nmu.nml_ns + '}location') rotationnote = instance.find('./{' + nmu.meta_ns + '}notes') if rotationnote is not None: # the text in rotationnote is zrotation=xxxxxxx zrotation = float(rotationnote.text.split('=')[1]) else: zrotation = 0 if cellname == 'LIF': cell = moose.LeakyIaF(cellid) self.populationDict[populationName][1][int( instanceid)] = cell else: # No Cell class in MOOSE anymore! :( addded Neuron class - # Chaitanya cell = moose.Neuron(cellid) self.populationDict[populationName][1][int( instanceid)] = cell x = float(location.attrib['x']) * self.length_factor y = float(location.attrib['y']) * self.length_factor z = float(location.attrib['z']) * self.length_factor self.translate_rotate(cell, x, y, z, zrotation)