Example #1
0
def create_LIF():
    neuromlR = NeuroML()
    neuromlR.readNeuroMLFromFile('cells_channels/LIF.morph.xml')
    libcell = moose.Neuron('/library/LIF')
    LIFCellid = moose.copy(libcell, moose.Neutral('/cells'), 'IF1')
    LIFCell = moose.LeakyIaF(LIFCellid)
    return LIFCell
Example #2
0
    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)
Example #3
0
    def readMorphML(self, cell, params={}, lengthUnits="micrometer"):
        """
        returns {cellName:segDict}
        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!
        """

        debug.printDebug("DEBUG", "Entered function readMorphML")
        if lengthUnits in ['micrometer', 'micron']:
            self.length_factor = 1e-6
        else:
            self.length_factor = 1.0
        cellName = cell.attrib["name"]

        if cellName == 'LIF':
            self.mooseCell = moose.LeakyIaF(self.cellPath + '/' + cellName)
            self.segDict = {}
        else:
            # using moose Neuron class - in previous version 'Cell' class
            # Chaitanya.
            self.mooseCell = moose.Neuron(self.cellPath + '/' + cellName)
            self.cellDictBySegmentId[cellName] = [self.mooseCell, {}]
            self.cellDictByCableId[cellName] = [self.mooseCell, {}]
            self.segDict = {}

            # load morphology and connections between compartments Many neurons
            # exported from NEURON have multiple segments in a section Combine
            # those segments into one Compartment / section assume segments of
            # a compartment/section are in increasing order and assume all
            # segments of a compartment/section have the same cableid findall()
            # returns elements in document order:

            self.running_cableid = ''
            running_segid = ''
            segments = cell.findall(".//{" + self.mml + "}segment")
            segmentstotal = len(segments)
            for segnum, segment in enumerate(segments):
                self.addSegment(cellName, segnum, segment)

        # load cablegroups into a dictionary
        self.cablegroupsDict = {}

        # Two ways of specifying cablegroups in neuroml 1.x
        # <cablegroup>s with list of <cable>s
        cablegroups = cell.findall(".//{" + self.mml + "}cablegroup")
        for cablegroup in cablegroups:
            cablegroupname = cablegroup.attrib['name']
            self.cablegroupsDict[cablegroupname] = []
            for cable in cablegroup.findall(".//{" + self.mml + "}cable"):
                cableid = cable.attrib['id']
                self.cablegroupsDict[cablegroupname].append(cableid)

        # <cable>s with list of <meta:group>s
        cables = cell.findall(".//{" + self.mml + "}cable")
        for cable in cables:
            cableid = cable.attrib['id']
            cablegroups = cable.findall(".//{" + self.meta + "}group")
            for cablegroup in cablegroups:
                cablegroupname = cablegroup.text
                if cablegroupname in list(self.cablegroupsDict.keys()):
                    self.cablegroupsDict[cablegroupname].append(cableid)
                else:
                    self.cablegroupsDict[cablegroupname] = [cableid]

        # Add bioPhysics to the cell
        self.addBiophysics(cell, cellName)

        # load connectivity / synapses into the compartments
        connectivity = cell.find(".//{" + self.neuroml + "}connectivity")
        if connectivity is not None:
            self.addConnectivity(cell, cellName, connectivity)
        return {cellName: self.segDict}