Beispiel #1
0
    def readNeuroMLFromFile(self,filename,params={},cellsDict={}):
        """
        For the format of params required to tweak what cells are loaded,
         refer to the doc string of NetworkML.readNetworkMLFromFile().
        Returns (populationDict,projectionDict),
         see doc string of NetworkML.readNetworkML() for details.
        """
        pu.info("Loading neuroml file %s " % filename)

        moose.Neutral('/library') # creates /library in MOOSE tree; elif present, wraps
        tree = ET.parse(filename)
        root_element = tree.getroot()
        self.model_dir = path.dirname( path.abspath( filename ) )
        if 'lengthUnits' in list(root_element.attrib.keys()):
            self.lengthUnits = root_element.attrib['lengthUnits']
        else:
            self.lengthUnits = 'micrometer'
        
        ## lots of gymnastics to check if temperature meta tag is present
        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'):
            ## tag can be an attrib or an element
            if 'tag' in list(meta_property.attrib.keys()): # tag is an attrib
                tagname = meta_property.attrib['tag']
                if 'temperature' in tagname:
                    self.temperature = float(meta_property.attrib['value'])
                    self.temperature_default = False
            else: # tag is a separate element
                tag = meta_property.find('.//{'+meta_ns+'}tag')
                tagname = tag.text
                if 'temperature' in tagname:
                    ## value can be a tag or an element 
                    if 'value' in list(tag.attrib.keys()): # value is an attrib
                        self.temperature = float(tag.attrib['value'])
                        self.temperature_default = False
                    else: # value is a separate element
                        self.temperature = float(tag.find('.//{'+meta_ns+'}value').text)
                        self.temperature_default = False
        if self.temperature_default:
            print(("Using default temperature of", self.temperature,"degrees Celsius."))
        self.nml_params = {
                'temperature':self.temperature,
                'model_dir':self.model_dir,
        }

        #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=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 = cellsDict
        for cells in root_element.findall('.//{'+neuroml_ns+'}cells'):
            for cell in cells.findall('.//{'+neuroml_ns+'}cell'):
                cellDict = mmlR.readMorphML(cell,params=params,lengthUnits=self.lengthUnits)
                self.cellsDict.update(cellDict)

        ## check if there are populations in this NML files,
        ## if not, it's a MorphML or ChannelML file, not NetworkML, so skip.
        if root_element.find('.//{'+neuroml_ns+'}populations') is None \
            and root_element.find('.//{'+nml_ns+'}populations') is None:
            return (self.cellsDict,'no populations (L3 NetworkML) found.')
        else:
            #print "Loading individual cells into MOOSE root ... "
            nmlR = NetworkML(self.nml_params)
            return nmlR.readNetworkML(root_element,self.cellsDict,\
                    params=params,lengthUnits=self.lengthUnits)
        ## cellsDict = { cellname: (segDict, cableDict), ... } # multiple cells
        ## where segDict = { segid1 : [ segname,(proximalx,proximaly,proximalz),
        ##     (distalx,distaly,distalz),diameter,length,[potential_syn1, ... ] ] , ... }
        ## segname is "<name>_<segid>" because 1) guarantees uniqueness,
        ##     & 2) later scripts obtain segid from the compartment's name!
        ## and cableDict = { cablegroupname : [campartment1name, compartment2name, ... ], ... }
        self.cellsDict = nmlR.cellSegmentDict
Beispiel #2
0
    def readNeuroMLFromFile(self, filename, params={}, cellsDict={}):
        """
        For the format of params required to tweak what cells are loaded,
         refer to the doc string of NetworkML.readNetworkMLFromFile().
        Returns (populationDict,projectionDict),
         see doc string of NetworkML.readNetworkML() for details.
        """
        pu.info("Loading neuroml file %s " % filename)

        moose.Neutral(
            '/library')  # creates /library in MOOSE tree; elif present, wraps
        tree = ET.parse(filename)
        root_element = tree.getroot()
        self.model_dir = path.dirname(path.abspath(filename))
        if 'lengthUnits' in list(root_element.attrib.keys()):
            self.lengthUnits = root_element.attrib['lengthUnits']
        else:
            self.lengthUnits = 'micrometer'

        ## lots of gymnastics to check if temperature meta tag is present
        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'):
            ## tag can be an attrib or an element
            if 'tag' in list(meta_property.attrib.keys()):  # tag is an attrib
                tagname = meta_property.attrib['tag']
                if 'temperature' in tagname:
                    self.temperature = float(meta_property.attrib['value'])
                    self.temperature_default = False
            else:  # tag is a separate element
                tag = meta_property.find('.//{' + meta_ns + '}tag')
                tagname = tag.text
                if 'temperature' in tagname:
                    ## value can be a tag or an element
                    if 'value' in list(
                            tag.attrib.keys()):  # value is an attrib
                        self.temperature = float(tag.attrib['value'])
                        self.temperature_default = False
                    else:  # value is a separate element
                        self.temperature = float(
                            tag.find('.//{' + meta_ns + '}value').text)
                        self.temperature_default = False
        if self.temperature_default:
            print(("Using default temperature of", self.temperature,
                   "degrees Celsius."))
        self.nml_params = {
            'temperature': self.temperature,
            'model_dir': self.model_dir,
        }

        #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=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 = cellsDict
        for cells in root_element.findall('.//{' + neuroml_ns + '}cells'):
            for cell in cells.findall('.//{' + neuroml_ns + '}cell'):
                cellDict = mmlR.readMorphML(cell,
                                            params=params,
                                            lengthUnits=self.lengthUnits)
                self.cellsDict.update(cellDict)

        ## check if there are populations in this NML files,
        ## if not, it's a MorphML or ChannelML file, not NetworkML, so skip.
        if root_element.find('.//{'+neuroml_ns+'}populations') is None \
            and root_element.find('.//{'+nml_ns+'}populations') is None:
            return (self.cellsDict, 'no populations (L3 NetworkML) found.')
        else:
            #print "Loading individual cells into MOOSE root ... "
            nmlR = NetworkML(self.nml_params)
            return nmlR.readNetworkML(root_element,self.cellsDict,\
                    params=params,lengthUnits=self.lengthUnits)
        ## cellsDict = { cellname: (segDict, cableDict), ... } # multiple cells
        ## where segDict = { segid1 : [ segname,(proximalx,proximaly,proximalz),
        ##     (distalx,distaly,distalz),diameter,length,[potential_syn1, ... ] ] , ... }
        ## segname is "<name>_<segid>" because 1) guarantees uniqueness,
        ##     & 2) later scripts obtain segid from the compartment's name!
        ## and cableDict = { cablegroupname : [campartment1name, compartment2name, ... ], ... }
        self.cellsDict = nmlR.cellSegmentDict
Beispiel #3
0
    def readNeuroMLFromFile(self, filename: Path, params={}, cellsDict={}):
        """
        For the format of params required to tweak what cells are loaded,
         refer to the doc string of NetworkML.readNetworkMLFromFile().
        Returns (populationDict,projectionDict),
         see doc string of NetworkML.readNetworkML() for details.
        """
        mu.info("Loading neuroml file %s " % filename)
        moose.Neutral(
            "/library")  # creates /library in MOOSE tree; elif present, wraps
        assert filename.exists(), f'{filename} does not exists or not readable'
        tree = ET.parse(str(filename))
        root_element = tree.getroot()

        # if model_path is given in params, use it else use the directory of NML
        # as model_dir.
        self.model_dir: Path = params.get("model_dir",
                                          filename.parent.resolve())

        if "lengthUnits" in list(root_element.attrib.keys()):
            self.lengthUnits = root_element.attrib["lengthUnits"]
        else:
            self.lengthUnits = "micrometer"

        ## lots of gymnastics to check if temperature meta tag is present
        self.temperature = (
            MNU.CELSIUS_default
        )  # gets replaced below if tag for temperature is present
        self.temperature_default = True
        for meta_property in root_element.findall(".//{" + MNU.meta_ns +
                                                  "}property"):
            ## tag can be an attrib or an element
            if "tag" in list(meta_property.attrib.keys()):  # tag is an attrib
                tagname = meta_property.attrib["tag"]
                if "temperature" in tagname:
                    self.temperature = float(meta_property.attrib["value"])
                    self.temperature_default = False
            else:  # tag is a separate element
                tag = meta_property.find(".//{" + MNU.meta_ns + "}tag")
                tagname = tag.text
                if "temperature" in tagname:
                    ## value can be a tag or an element
                    if "value" in list(
                            tag.attrib.keys()):  # value is an attrib
                        self.temperature = float(tag.attrib["value"])
                        self.temperature_default = False
                    else:  # value is a separate element
                        self.temperature = float(
                            tag.find(".//{" + MNU.meta_ns + "}value").text)
                        self.temperature_default = False
        if self.temperature_default:
            mu.info("Using default temperature of %s degree Celsius" %
                    self.temperature)
        self.nml_params = {
            "temperature": self.temperature,
            "model_dir": str(self.model_dir),
        }

        mu.info("Loading channels and synapses into MOOSE /library ...")
        cmlR = ChannelML(self.nml_params)
        for channels in root_element.findall(".//{" + MNU.neuroml_ns +
                                             "}channels"):
            self.channelUnits = channels.attrib["units"]
            for channel in channels.findall(".//{" + MNU.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=params,
                                   units=self.channelUnits)
            for synapse in channels.findall(".//{" + MNU.cml_ns +
                                            "}synapse_type"):
                cmlR.readSynapseML(synapse, units=self.channelUnits)
            for ionConc in channels.findall(".//{" + MNU.cml_ns +
                                            "}ion_concentration"):
                cmlR.readIonConcML(ionConc, units=self.channelUnits)

        mu.info("Loading cell definitions into MOOSE /library ...")
        mmlR = MorphML(self.nml_params)
        self.cellsDict = cellsDict
        for cells in root_element.findall(".//{" + MNU.neuroml_ns + "}cells"):
            for cell in cells.findall(".//{" + MNU.neuroml_ns + "}cell"):
                cellDict = mmlR.readMorphML(cell,
                                            params=params,
                                            lengthUnits=self.lengthUnits)
                self.cellsDict.update(cellDict)

        ## check if there are populations in this NML files,
        ## if not, it's a MorphML or ChannelML file, not NetworkML, so skip.
        if (root_element.find(".//{" + MNU.neuroml_ns + "}populations") is None
                and root_element.find(".//{" + MNU.nml_ns + "}populations") is
                None):
            return (self.cellsDict, "no populations (L3 NetworkML) found.")
        else:
            mu.info("Loading individual cells into MOOSE root ... ")
            nmlR = NetworkML(self.nml_params)
            return nmlR.readNetworkML(
                root_element,
                self.cellsDict,
                params=params,
                lengthUnits=self.lengthUnits,
            )
        ## cellsDict = { cellname: (segDict, cableDict), ... } # multiple cells
        ## where segDict = { segid1 : [ segname,(proximalx,proximaly,proximalz),
        ##     (distalx,distaly,distalz),diameter,length,[potential_syn1, ... ] ] , ... }
        ## segname is "<name>_<segid>" because 1) guarantees uniqueness,
        ##     & 2) later scripts obtain segid from the compartment's name!
        ## and cableDict = { cablegroupname : [campartment1name, compartment2name, ... ], ... }
        self.cellsDict = nmlR.cellSegmentDict