示例#1
0
 def make_new_synapse(self, syn_name, postcomp, syn_name_full):
     ## if channel does not exist in library load it from xml file
     if not moose.exists('/library/'+syn_name):
         cmlR = ChannelML(self.nml_params)
         cmlR.readChannelMLFromFile(syn_name+'.xml')
     #~ synid = self.context.deepCopy(self.context.pathToId('/library/'+syn_name),postcomp.id,syn_name_full)
     syn = moose.SynChan(synid)
     #### connect the post compartment to the synapse
     if syn.getField('mgblock')=='True': # If NMDA synapse based on mgblock, connect to mgblock
         mgblock = moose.Mg_block(syn.path+'/mgblock')
         moose.connect(postcomp,"channel", mgblock, "channel")
     else: # if SynChan or even NMDAChan, connect normally
         moose.connect(postcomp,"channel", syn, "channel")
示例#2
0
 def make_new_synapse(self, syn_name, postcomp, syn_name_full):
     ## if channel does not exist in library load it from xml file
     if not moose.exists('/library/'+syn_name):
         cmlR = ChannelML(self.nml_params)
         cmlR.readChannelMLFromFile(syn_name+'.xml')
     ## deep copies the library synapse to an instance under postcomp named as <arg3>
     synid = moose.copy(moose.Neutral('/library/'+syn_name),postcomp,syn_name_full)
     syn = moose.SynChan(synid)
     childmgblock = utils.get_child_Mstring(syn,'mgblock')
     #### connect the post compartment to the synapse
     if childmgblock.value=='True': # If NMDA synapse based on mgblock, connect to mgblock
         mgblock = moose.Mg_block(syn.path+'/mgblock')
         moose.connect(postcomp,"channel", mgblock, "channel")
     else: # if SynChan or even NMDAChan, connect normally
         moose.connect(postcomp,"channel", syn, "channel")
示例#3
0
    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().
        Returns (populationDict,projectionDict),
         see doc string of NetworkML.readNetworkML() for details.
        """
        print "Loading neuroml file ... ", 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 ) )
        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,
                '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={},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 ... "
        print self.cellsDict
        nmlR = NetworkML(self.nml_params)
        print self.cellsDict
        return nmlR.readNetworkML(root_element,self.cellsDict,params=params,lengthUnits=self.lengthUnits)
示例#4
0
    def set_compartment_param(self, compartment, name, value, mechanismname):
        """ Set the param for the compartment depending on name and mechanismname. """
        if name == 'CM':
            compartment.Cm = value*math.pi*compartment.diameter*compartment.length
        elif name == 'RM':
            compartment.Rm = value/(math.pi*compartment.diameter*compartment.length)
        elif name == 'RA':
            compartment.Ra = value*compartment.length/(math.pi*(compartment.diameter/2.0)**2)
        elif name == 'Em':
            compartment.Em = value
        elif name == 'initVm':
            compartment.initVm = value
        elif name == 'inject':
            print compartment.name, 'inject', value, 'A.'
            compartment.inject = value
        elif mechanismname is 'synapse': # synapse being added to the compartment
            ## these are potential locations, we do not actually make synapses.
            #synapse = self.context.deepCopy(self.context.pathToId('/library/'+value),\
            #    self.context.pathToId(compartment.path),value) # value contains name of synapse i.e. synapse_type
            #moose.connect(compartment,"channel", synapse, "channel")
            ## I assume below that compartment name has _segid at its end
            segid = string.split(compartment.name,'_')[-1] # get segment id from compartment name
            self.segDict[segid][5].append(value)
        elif mechanismname is 'spikegen': # spikegen being added to the compartment
            ## these are potential locations, we do not actually make the spikegens.
            ## spikegens for different synapses can have different thresholds,
            ## hence include synapse_type in its name
            ## value contains name of synapse i.e. synapse_type
            #spikegen = moose.SpikeGen(compartment.path+'/'+value+'_spikegen')
            #moose.connect(compartment,"VmSrc",spikegen,"Vm")
            pass
        elif mechanismname is not None:
            ## if mechanism is not present in compartment, deep copy from library
            if not moose.exists(compartment.path+'/'+mechanismname):
                ## if channel does not exist in library load it from xml file
                if not moose.exists("/library/"+mechanismname):
                    cmlR = ChannelML(self.nml_params)
                    model_filename = mechanismname+'.xml'
                    model_path = find_first_file(model_filename,self.model_dir)
                    if model_path is not None:
                        cmlR.readChannelMLFromFile(model_path)
                    else:
                        raise IOError(
                            'For mechanism {0}: files {1} not found under {2}.'.format(
                                mechanismname, model_filename, self.model_dir
                            )
                        )

                neutralObj = moose.Neutral("/library/"+mechanismname)
                if 'CaConc' == neutralObj.class_: # Ion concentration pool
                    libcaconc = moose.CaConc("/library/"+mechanismname)
                    ## deep copies the library caconc under the compartment
                    channel = moose.copy(libcaconc,compartment,mechanismname)
                    channel = moose.CaConc(channel)
                    ## CaConc connections are made later using connect_CaConc()
                    ## Later, when calling connect_CaConc,
                    ## B is set for caconc based on thickness of Ca shell and compartment l and dia.
                elif 'HHChannel2D' == neutralObj.class_ : ## HHChannel2D
                    libchannel = moose.HHChannel2D("/library/"+mechanismname)
                    ## deep copies the library channel under the compartment
                    channel = moose.copy(libchannel,compartment,mechanismname)
                    channel = moose.HHChannel2D(channel)
                    moose.connect(channel,'channel',compartment,'channel')
                elif 'HHChannel' == neutralObj.class_ : ## HHChannel
                    libchannel = moose.HHChannel("/library/"+mechanismname)
                    ## deep copies the library channel under the compartment
                    channel = moose.copy(libchannel,compartment,mechanismname)
                    channel = moose.HHChannel(channel)
                    moose.connect(channel,'channel',compartment,'channel')
            ## if mechanism is present in compartment, just wrap it
            else:
                neutralObj = moose.Neutral(compartment.path+'/'+mechanismname)
                if 'CaConc' == neutralObj.class_: # Ion concentration pool
                    caconc = moose.CaConc(compartment.path+'/'+mechanismname) # wraps existing channel
                elif 'HHChannel2D' == neutralObj.class_ : ## HHChannel2D
                    channel = moose.HHChannel2D(compartment.path+'/'+mechanismname) # wraps existing channel
                elif 'HHChannel' == neutralObj.class_ : ## HHChannel
                    channel = moose.HHChannel(compartment.path+'/'+mechanismname) # wraps existing channel
            if name == 'Gbar':
                channel.Gbar = value*math.pi*compartment.diameter*compartment.length
            elif name == 'Ek':
                channel.Ek = value
            elif name == 'thick':
                caconc.thick = value ## JUST THIS WILL NOT DO - HAVE TO SET B based on this thick!
                ## Later, when calling connect_CaConc,
                ## B is set for caconc based on thickness of Ca shell and compartment l and dia.
        if neuroml_debug: print "Setting ",name," for ",compartment.path," value ",value
示例#5
0
    def set_compartment_param(self, compartment, name, value, mechName):
        """ Set the param for the compartment depending on name and mechName. """
        if name == 'CM':
            compartment.Cm = value *math.pi*compartment.diameter*compartment.length
        elif name == 'RM':
            compartment.Rm = value/(math.pi*compartment.diameter*compartment.length)
        elif name == 'RA':
            compartment.Ra = value * compartment.length / \
                    (math.pi*(compartment.diameter/2.0)**2)
        elif name == 'Em':
            compartment.Em = value
        elif name == 'initVm':
            compartment.initVm = value
        elif name == 'inject':
            msg = " {0} inject {1} A.".format(compartment.name, value)
            debug.printDebug("INFO", msg)
            compartment.inject = value
        elif mechName is 'synapse':

           # synapse being added to the compartment
           # these are potential locations, we do not actually make synapses.
           # I assume below that compartment name has _segid at its end

           # get segment id from compartment name
           segid = moose_methods.getCompartmentId(compartment.name)
           self.segDict[segid][5].append(value)

        # spikegen being added to the compartment
        elif mechName is 'spikegen': 
            # these are potential locations, we do not actually make the
            # spikegens.  spikegens for different synapses can have different
            # thresholds, hence include synapse_type in its name value contains
            # name of synapse i.e. synapse_type
            #spikegen = moose.SpikeGen(compartment.path+'/'+value+'_spikegen')
            #moose.connect(compartment,"VmSrc",spikegen,"Vm")
            pass
        elif mechName is not None:

            # if mechanism is not present in compartment, deep copy from library
            if not moose.exists(compartment.path+'/'+mechName):

                # if channel does not exist in library load it from xml file
                if not moose.exists(self.libraryPath+"/"+mechName):
                    cmlR = ChannelML(self.nml_params)
                    model_filename = mechName+'.xml'
                    model_path = neuroml_utils.find_first_file(
                        model_filename
                        , self.model_dir
                    )
                    if model_path is not None:
                        cmlR.readChannelMLFromFile(model_path)
                    else:
                        msg = 'Mechanism {0}: files {1} not found under {2}'\
                                .format( mechName
                                        , model_filename
                                        , self.model_dir
                                        )
                        debug.printDebug("ERROR"
                                , msg
                                , frame = inspect.currentframe()
                                )
                        sys.exit(0)

                neutralObj = moose.Neutral(self.libraryPath+"/"+mechName)

                # Ion concentration pool
                if 'CaConc' == neutralObj.className:
                    libcaconc = moose.CaConc(self.libraryPath+"/"+mechName)

                    # deep copies the library caconc under the compartment
                    caconc = moose.copy(libcaconc,compartment,mechName)
                    caconc = moose.CaConc(caconc)

                    # CaConc connections are made later using connect_CaConc()
                    # Later, when calling connect_CaConc, B is set for caconc
                    # based on thickness of Ca shell and compartment l and dia
                    # OR based on the Mstring phi under CaConc path.
                    channel = None

                elif 'HHChannel2D' == neutralObj.className : ## HHChannel2D
                    libchannel = moose.HHChannel2D(self.libraryPath+"/"+mechName)
                    ## deep copies the library channel under the compartment
                    channel = moose.copy(libchannel,compartment,mechName)
                    channel = moose.HHChannel2D(channel)
                    moose.connect(channel,'channel',compartment,'channel')
                elif 'HHChannel' == neutralObj.className : ## HHChannel
                    libchannel = moose.HHChannel(self.libraryPath+"/"+mechName)

                    # deep copies the library channel under the compartment
                    channel = moose.copy(libchannel,compartment,mechName)
                    channel = moose.HHChannel(channel)
                    moose.connect(channel,'channel',compartment,'channel')
            # if mechanism is present in compartment, just wrap it
            else:
                neutralObj = moose.Neutral(compartment.path+'/'+mechName)
                # Ion concentration pool
                if 'CaConc' == neutralObj.className:
                    # wraps existing channel
                    caconc = moose.CaConc(compartment.path+'/'+mechName)
                    channel = None
                elif 'HHChannel2D' == neutralObj.className: ## HHChannel2D
                    # wraps existing channel
                    channel = moose.HHChannel2D(compartment.path+'/'+mechName)
                elif 'HHChannel' == neutralObj.className : ## HHChannel
                    # wraps existing channel
                    channel = moose.HHChannel(compartment.path+'/'+mechName)
            if name == 'Gbar':
                # if CaConc, neuroConstruct uses gbar for thickness or phi
                if channel is None:
                    # If child Mstring 'phi' is present, set gbar as phi BUT,
                    # value has been multiplied by Gfactor as a Gbar, SI or
                    # physiological not known here, ignoring Gbar for CaConc,
                    # instead of passing units here
                    child = moose_utils.get_child_Mstring(caconc,'phi')
                    if child is not None:
                        #child.value = value
                        pass
                    else:
                        #caconc.thick = value
                        pass
                else: # if ion channel, usual Gbar
                    channel.Gbar = value * math.pi * compartment.diameter \
                            * compartment.length
            elif name == 'Ek':
                channel.Ek = value

            # thick seems to be NEURON's extension to NeuroML level 2.
            elif name == 'thick':
                # JUST THIS WILL NOT DO - HAVE TO SET B based on this thick!
                caconc.thick = value
                # Later, when calling connect_CaConc, B is set for caconc based
                # on thickness of Ca shell and compartment l and dia.  OR based
                # on the Mstring phi under CaConc path.

        if neuroml_utils.neuroml_debug:
            msg = "Setting {0} for {1} value {2}".format(name, compartment.path
                                                         , value
                                                         )
            debug.printDebug("DEBUG", msg, frame=inspect.currentframe())
示例#6
0
 def createProjections(self):
     self.projectionDict={}
     projections = self.network.find(".//{"+nml_ns+"}projections")
     if projections is not None:
         if projections.attrib["units"] == 'Physiological Units': # see pg 219 (sec 13.2) of Book of Genesis
             Efactor = 1e-3 # V from mV
             Tfactor = 1e-3 # s from ms
         else:
             Efactor = 1.0
             Tfactor = 1.0
     for projection in self.network.findall(".//{"+nml_ns+"}projection"):
         projectionname = projection.attrib["name"]
         print "setting",projectionname
         source = projection.attrib["source"]
         target = projection.attrib["target"]
         self.projectionDict[projectionname] = (source,target,[])
         for syn_props in projection.findall(".//{"+nml_ns+"}synapse_props"):
             syn_name = syn_props.attrib['synapse_type']
             ## if synapse does not exist in library load it from xml file
             if not moose.exists("/library/"+syn_name):
                 cmlR = ChannelML(self.nml_params)
                 model_filename = syn_name+'.xml'
                 model_path = find_first_file(model_filename,self.model_dir)
                 if model_path is not None:
                     cmlR.readChannelMLFromFile(model_path)
                 else:
                     raise IOError(
                         'For mechanism {0}: files {1} not found under {2}.'.format(
                             mechanismname, model_filename, self.model_dir
                         )
                     )
             weight = float(syn_props.attrib['weight'])
             threshold = float(syn_props.attrib['threshold'])*Efactor
             if 'prop_delay' in syn_props.attrib:
                 prop_delay = float(syn_props.attrib['prop_delay'])*Tfactor
             elif 'internal_delay' in syn_props.attrib:
                 prop_delay = float(syn_props.attrib['internal_delay'])*Tfactor
             else: prop_delay = 0.0
             for connection in projection.findall(".//{"+nml_ns+"}connection"):
                 pre_cell_id = connection.attrib['pre_cell_id']
                 post_cell_id = connection.attrib['post_cell_id']
                 if 'file' not in pre_cell_id:
                     # source could be 'mitrals', self.populationDict[source][0] would be 'mitral'
                     pre_cell_name = self.populationDict[source][0]
                     if 'pre_segment_id' in connection.attrib:
                         pre_segment_id = connection.attrib['pre_segment_id']
                     else: pre_segment_id = "0" # assume default segment 0, usually soma
                     pre_segment_path = self.populationDict[source][1][int(pre_cell_id)].path+'/'+\
                         self.cellSegmentDict[pre_cell_name][pre_segment_id][0]
                 else:
                     # I've removed extra excitation provided via files, so below comment doesn't apply.
                     # 'file[+<glomnum>]_<filenumber>' # glomnum is
                     # for mitral_granule extra excitation from unmodelled sisters.
                     pre_segment_path = pre_cell_id+'_'+connection.attrib['pre_segment_id']
                 # target could be 'PGs', self.populationDict[target][0] would be 'PG'
                 post_cell_name = self.populationDict[target][0]
                 if 'post_segment_id' in connection.attrib:
                     post_segment_id = connection.attrib['post_segment_id']
                 else: post_segment_id = "0" # assume default segment 0, usually soma
                 post_segment_path = self.populationDict[target][1][int(post_cell_id)].path+'/'+\
                     self.cellSegmentDict[post_cell_name][post_segment_id][0]
                 self.projectionDict[projectionname][2].append((syn_name, pre_segment_path, post_segment_path))
                 properties = connection.findall('./{'+nml_ns+'}properties')
                 if len(properties)==0:
                     self.connect(syn_name, pre_segment_path, post_segment_path, weight, threshold, prop_delay)
                 else:
                     for props in properties:
                         synapse_type = props.attrib['synapse_type']
                         if syn_name in synapse_type:
                             weight_override = float(props.attrib['weight'])
                             if 'internal_delay' in props.attrib:
                                 delay_override = float(props.attrib['internal_delay'])
                             else: delay_override = prop_delay
                             if weight_override != 0.0:
                                 self.connect(syn_name, pre_segment_path, post_segment_path,\
                                     weight_override, threshold, delay_override)
示例#7
0
    def set_compartment_param(self, compartment, name, value, mechName):
        """ Set the param for the compartment depending on name and mechName. """
        if name == 'CM':
            compartment.Cm = value * math.pi * compartment.diameter * compartment.length
        elif name == 'RM':
            compartment.Rm = value / (math.pi * compartment.diameter *
                                      compartment.length)
        elif name == 'RA':
            compartment.Ra = value * compartment.length / \
                    (math.pi*(compartment.diameter/2.0)**2)
        elif name == 'Em':
            compartment.Em = value
        elif name == 'initVm':
            compartment.initVm = value
        elif name == 'inject':
            msg = " {0} inject {1} A.".format(compartment.name, value)
            debug.printDebug("INFO", msg)
            compartment.inject = value
        elif mechName is 'synapse':

            # synapse being added to the compartment
            # these are potential locations, we do not actually make synapses.
            # I assume below that compartment name has _segid at its end

            # get segment id from compartment name
            segid = moose_methods.getCompartmentId(compartment.name)
            self.segDict[segid][5].append(value)

        # spikegen being added to the compartment
        elif mechName is 'spikegen':
            # these are potential locations, we do not actually make the
            # spikegens.  spikegens for different synapses can have different
            # thresholds, hence include synapse_type in its name value contains
            # name of synapse i.e. synapse_type
            #spikegen = moose.SpikeGen(compartment.path+'/'+value+'_spikegen')
            #moose.connect(compartment,"VmSrc",spikegen,"Vm")
            pass
        elif mechName is not None:

            # if mechanism is not present in compartment, deep copy from library
            if not moose.exists(compartment.path + '/' + mechName):

                # if channel does not exist in library load it from xml file
                if not moose.exists(self.libraryPath + "/" + mechName):
                    cmlR = ChannelML(self.nml_params)
                    model_filename = mechName + '.xml'
                    model_path = neuroml_utils.find_first_file(
                        model_filename, self.model_dir)
                    if model_path is not None:
                        cmlR.readChannelMLFromFile(model_path)
                    else:
                        msg = 'Mechanism {0}: files {1} not found under {2}'\
                                .format( mechName
                                        , model_filename
                                        , self.model_dir
                                        )
                        debug.printDebug("ERROR",
                                         msg,
                                         frame=inspect.currentframe())
                        sys.exit(0)

                neutralObj = moose.Neutral(self.libraryPath + "/" + mechName)

                # Ion concentration pool
                if 'CaConc' == neutralObj.className:
                    libcaconc = moose.CaConc(self.libraryPath + "/" + mechName)

                    # deep copies the library caconc under the compartment
                    caconc = moose.copy(libcaconc, compartment, mechName)
                    caconc = moose.CaConc(caconc)

                    # CaConc connections are made later using connect_CaConc()
                    # Later, when calling connect_CaConc, B is set for caconc
                    # based on thickness of Ca shell and compartment l and dia
                    # OR based on the Mstring phi under CaConc path.
                    channel = None

                elif 'HHChannel2D' == neutralObj.className:  ## HHChannel2D
                    libchannel = moose.HHChannel2D(self.libraryPath + "/" +
                                                   mechName)
                    ## deep copies the library channel under the compartment
                    channel = moose.copy(libchannel, compartment, mechName)
                    channel = moose.HHChannel2D(channel)
                    moose.connect(channel, 'channel', compartment, 'channel')
                elif 'HHChannel' == neutralObj.className:  ## HHChannel
                    libchannel = moose.HHChannel(self.libraryPath + "/" +
                                                 mechName)

                    # deep copies the library channel under the compartment
                    channel = moose.copy(libchannel, compartment, mechName)
                    channel = moose.HHChannel(channel)
                    moose.connect(channel, 'channel', compartment, 'channel')
            # if mechanism is present in compartment, just wrap it
            else:
                neutralObj = moose.Neutral(compartment.path + '/' + mechName)
                # Ion concentration pool
                if 'CaConc' == neutralObj.className:
                    # wraps existing channel
                    caconc = moose.CaConc(compartment.path + '/' + mechName)
                    channel = None
                elif 'HHChannel2D' == neutralObj.className:  ## HHChannel2D
                    # wraps existing channel
                    channel = moose.HHChannel2D(compartment.path + '/' +
                                                mechName)
                elif 'HHChannel' == neutralObj.className:  ## HHChannel
                    # wraps existing channel
                    channel = moose.HHChannel(compartment.path + '/' +
                                              mechName)
            if name == 'Gbar':
                # if CaConc, neuroConstruct uses gbar for thickness or phi
                if channel is None:
                    # If child Mstring 'phi' is present, set gbar as phi BUT,
                    # value has been multiplied by Gfactor as a Gbar, SI or
                    # physiological not known here, ignoring Gbar for CaConc,
                    # instead of passing units here
                    child = moose_utils.get_child_Mstring(caconc, 'phi')
                    if child is not None:
                        #child.value = value
                        pass
                    else:
                        #caconc.thick = value
                        pass
                else:  # if ion channel, usual Gbar
                    channel.Gbar = value * math.pi * compartment.diameter \
                            * compartment.length
            elif name == 'Ek':
                channel.Ek = value

            # thick seems to be NEURON's extension to NeuroML level 2.
            elif name == 'thick':
                # JUST THIS WILL NOT DO - HAVE TO SET B based on this thick!
                caconc.thick = value
                # Later, when calling connect_CaConc, B is set for caconc based
                # on thickness of Ca shell and compartment l and dia.  OR based
                # on the Mstring phi under CaConc path.

        if neuroml_utils.neuroml_debug:
            msg = "Setting {0} for {1} value {2}".format(
                name, compartment.path, value)
            debug.printDebug("DEBUG", msg, frame=inspect.currentframe())