コード例 #1
0
ファイル: utils.py プロジェクト: saeedsh/async_gpu
def create(modelroot, element,field):
        """Create table to record `field` from element `element`

        Tables are created under `dataRoot`, the names are generally
        created by removing `/model` in the beginning of `elementPath`
        and replacing `/` with `_`. If this conflicts with an existing
        table, the id value of the target element (elementPath) is
        appended to the name.
        """
        dataroot = modelroot+"/" + "data"
        if not _moose.exists(dataroot):
            _moose.Neutral(dataroot)
        '''
        if len(field) == 0 or ((element, field) in self._recordDict):
            return
        '''
        field = lst = [word[0].upper() + word[1:] for word in field.split()]
        field = " ".join(lst)
        
        if len(field) == 0 or len(element.neighbors['get%s'%(field)]) > 0:
            return
        # The table path is not foolproof - conflict is
        # possible: e.g. /model/test_object and
        # /model/test/object will map to same table. So we
        # check for existing table without element field
        # path in recording dict.
        relativePath = element.path.partition(modelroot)[-1]
        if relativePath.startswith('/'):
            relativePath = relativePath[1:]

        #Convert to camelcase
        
        tablePath =  relativePath.replace('/', '_') + '.' + field
        tablePath = re.sub('.', lambda m: {'[':'_', ']':'_'}.get(m.group(), m.group()),tablePath)
        
        if tablePath.startswith("_0__"):
            tablePath = tablePath[4:]
        
        #tablePath = dataroot + '/' +tablePath
        tablePath = dataroot+'/'+element.name+'.'+field[:2]
        if _moose.exists(tablePath):
            tablePath = '%s_%d' % (tablePath, element.getId().value)
        
        if not _moose.exists(tablePath):
            table = _moose.Table(tablePath)
            print 'Created', table.path, 'for plotting', '%s.%s' % (element.path, field)
            target = element
            _moose.connect(table, 'requestOut', target, 'get%s' % (field))
            
            tableEmitter.emit(QtCore.SIGNAL('tableCreated()'))
            #tableCreated.emit()
            return True
            #self.emit(QtCore.SIGNAL('tableCreated(PyQt_PyObject)'))
            #self.created.emit()
            
        return False
コード例 #2
0
ファイル: utils.py プロジェクト: praveenv253/moose
def setupTable(name, obj, qtyname, tables_path=None):
    """ Sets up a table with 'name' which stores 'qtyname' field from 'obj'.
    The table is created under tables_path if not None, else under obj.path . """
    if tables_path is None:
        tables_path = obj.path + "/data"
    ## in case tables_path does not exist, below wrapper will create it
    _moose.Neutral(tables_path)
    vmTable = _moose.Table(tables_path + "/" + name)
    ## stepMode no longer supported, connect to 'input'/'spike' message dest to record Vm/spiktimes
    # vmTable.stepMode = TAB_BUF
    _moose.connect(vmTable, "requestData", obj, "get_" + qtyname)
    return vmTable
コード例 #3
0
def create_table(tablePath, element, field, tableType):
    """Create table to record `field` from element `element`

    Tables are created under `dataRoot`, the names are generally
    created by removing `/model` in the beginning of `elementPath`
    and replacing `/` with `_`. If this conflicts with an existing
    table, the id value of the target element (elementPath) is
    appended to the name.
    """
    if _moose.exists(tablePath):
        table = _moose.element(tablePath)
    else:
        if tableType == "Table2":
            table = _moose.Table2(tablePath)
        elif tableType == "Table":
            table = _moose.Table(tablePath)
        _moose.connect(table, 'requestOut', element, 'get%s' % (field))
    return table
コード例 #4
0
ファイル: utils.py プロジェクト: iampritishpatil/moose
def create_table(tablePath, element, field,tableType):
    """Create table to record `field` from element `element`

    Tables are created under `dataRoot`, the names are generally
    created by removing `/model` in the beginning of `elementPath`
    and replacing `/` with `_`. If this conflicts with an existing
    table, the id value of the target element (elementPath) is
    appended to the name.
    """
    if _moose.exists(tablePath):
        table = _moose.element(tablePath)
    else:
        if tableType == "Table2":
            table = _moose.Table2(tablePath)            
        elif tableType == "Table":
            table = _moose.Table(tablePath)
        _moose.connect(table, 'requestOut', element, 'get%s' % (field))
    return table
コード例 #5
0
    def test_autoposition(self):
        """Simple check for automatic generation of positions.

        A spherical soma is created with 20 um diameter. A 100
        compartment cable is created attached to it with each
        compartment of length 100 um.

        """
        testid = 'test%s' % (uuid.uuid4())
        container = _moose.Neutral('/test')
        model = _moose.Neuron('/test/%s' % (testid))
        soma = _moose.Compartment('%s/soma' % (model.path))
        soma.diameter = 20e-6
        soma.length = 0.0
        parent = soma
        comps = []
        for ii in range(100):
            comp = _moose.Compartment('%s/comp_%d' % (model.path, ii))
            comp.diameter = 10e-6
            comp.length = 100e-6
            _moose.connect(parent, 'raxial', comp, 'axial')
            comps.append(comp)
            parent = comp
        soma = autoposition(model)
        sigfig = 8
        self.assertAlmostEqual(soma.x0, 0.0, sigfig)
        self.assertAlmostEqual(soma.y0, 0.0, sigfig)
        self.assertAlmostEqual(soma.z0, 0.0, sigfig)
        self.assertAlmostEqual(soma.x, 0.0, sigfig)
        self.assertAlmostEqual(soma.y, 0.0, sigfig)
        self.assertAlmostEqual(soma.z, soma.diameter / 2.0, sigfig)
        for ii, comp in enumerate(comps):
            print comp.path, ii
            self.assertAlmostEqual(comp.x0, 0, sigfig)
            self.assertAlmostEqual(comp.y0, 0.0, sigfig)
            self.assertAlmostEqual(comp.z0, soma.diameter / 2.0 + ii * 100e-6,
                                   sigfig)
            self.assertAlmostEqual(comp.x, 0.0, sigfig)
            self.assertAlmostEqual(comp.y, 0.0, sigfig)
            self.assertAlmostEqual(comp.z,
                                   soma.diameter / 2.0 + (ii + 1) * 100e-6,
                                   sigfig)
コード例 #6
0
ファイル: utils.py プロジェクト: csiki/moose-csiki
def setupTable(name, obj, qtyname, tables_path=None, threshold=None, spikegen=None):
    """ Sets up a table with 'name' which stores 'qtyname' field from 'obj'.
    The table is created under tables_path if not None, else under obj.path . """
    if tables_path is None:
        tables_path = obj.path+'/data'
    ## in case tables_path does not exist, below wrapper will create it
    tables_path_obj = _moose.Neutral(tables_path)
    qtyTable = _moose.Table(tables_path_obj.path+'/'+name)
    ## stepMode no longer supported, connect to 'input'/'spike' message dest to record Vm/spiktimes
    # qtyTable.stepMode = TAB_BUF 
    if spikegen is None:
        if threshold is None:
            ## below is wrong! reads qty twice every clock tick!
            #_moose.connect( obj, qtyname+'Out', qtyTable, "input")
            ## this is the correct method
            _moose.connect( qtyTable, "requestOut", obj, 'get'+qtyname)
        else:
            ## create new spikegen
            spikegen = _moose.SpikeGen(tables_path_obj.path+'/'+name+'_spikegen')
            ## connect the compartment Vm to the spikegen
            _moose.connect(obj,"VmOut",spikegen,"Vm")
            ## spikegens for different synapse_types can have different thresholds
            spikegen.threshold = threshold
            spikegen.edgeTriggered = 1 # This ensures that spike is generated only on leading edge.
    else:
        _moose.connect(spikegen,'spikeOut',qtyTable,'input') ## spikeGen gives spiketimes
    return qtyTable
コード例 #7
0
def setupTable(name,
               obj,
               qtyname,
               tables_path=None,
               threshold=None,
               spikegen=None):
    """ Sets up a table with 'name' which stores 'qtyname' field from 'obj'.
    The table is created under tables_path if not None, else under obj.path . """
    if tables_path is None:
        tables_path = obj.path + '/data'
    ## in case tables_path does not exist, below wrapper will create it
    tables_path_obj = _moose.Neutral(tables_path)
    qtyTable = _moose.Table(tables_path_obj.path + '/' + name)
    ## stepMode no longer supported, connect to 'input'/'spike' message dest to record Vm/spiktimes
    # qtyTable.stepMode = TAB_BUF
    if spikegen is None:
        if threshold is None:
            ## below is wrong! reads qty twice every clock tick!
            #_moose.connect( obj, qtyname+'Out', qtyTable, "input")
            ## this is the correct method
            _moose.connect(qtyTable, "requestOut", obj, 'get' + qtyname)
        else:
            ## create new spikegen
            spikegen = _moose.SpikeGen(tables_path_obj.path + '/' + name +
                                       '_spikegen')
            ## connect the compartment Vm to the spikegen
            _moose.connect(obj, "VmOut", spikegen, "Vm")
            ## spikegens for different synapse_types can have different thresholds
            spikegen.threshold = threshold
            spikegen.edgeTriggered = 1  # This ensures that spike is generated only on leading edge.
    else:
        _moose.connect(spikegen, 'spikeOut', qtyTable,
                       'input')  ## spikeGen gives spiketimes
    return qtyTable
コード例 #8
0
ファイル: utils.py プロジェクト: csiki/moose-csiki
    def test_autoposition(self):
        """Simple check for automatic generation of positions.
        
        A spherical soma is created with 20 um diameter. A 100
        compartment cable is created attached to it with each
        compartment of length 100 um.

        """
        testid = 'test%s' % (uuid.uuid4())
        container = _moose.Neutral('/test')
        model = _moose.Neuron('/test/%s' % (testid))
        soma = _moose.Compartment('%s/soma' % (model.path))
        soma.diameter = 20e-6
        soma.length = 0.0
        parent = soma
        comps = []
        for ii in range(100):
            comp = _moose.Compartment('%s/comp_%d' % (model.path, ii))
            comp.diameter = 10e-6
            comp.length = 100e-6
            _moose.connect(parent, 'raxial', comp, 'axial')
            comps.append(comp)
            parent = comp
        soma = autoposition(model)
        sigfig = 8
        self.assertAlmostEqual(soma.x0, 0.0, sigfig)
        self.assertAlmostEqual(soma.y0, 0.0, sigfig)
        self.assertAlmostEqual(soma.z0, 0.0, sigfig)
        self.assertAlmostEqual(soma.x, 0.0, sigfig)
        self.assertAlmostEqual(soma.y, 0.0, sigfig)
        self.assertAlmostEqual(soma.z, soma.diameter/2.0, sigfig)
        for ii, comp in enumerate(comps):
            print comp.path, ii
            self.assertAlmostEqual(comp.x0, 0, sigfig)
            self.assertAlmostEqual(comp.y0, 0.0, sigfig)
            self.assertAlmostEqual(comp.z0, soma.diameter/2.0 + ii * 100e-6, sigfig)
            self.assertAlmostEqual(comp.x, 0.0, sigfig)
            self.assertAlmostEqual(comp.y, 0.0, sigfig)
            self.assertAlmostEqual(comp.z, soma.diameter/2.0 + (ii + 1) * 100e-6, sigfig)
コード例 #9
0
ファイル: utils.py プロジェクト: praveenv253/moose
def connect_CaConc(compartment_list):
    """ Connect the Ca pools and channels within each of the compartments in compartment_list
     Ca channels should have a child Mstring named 'ion' with value set in MOOSE.
     Ca dependent channels like KCa should have a child Mstring called 'ionDependency' with value set in MOOSE.
     Call this only after instantiating cell so that all channels and pools have been created. """
    for compartment in compartment_list:
        caconc = None
        for child in compartment.children:
            neutralwrap = _moose.Neutral(child)
            if neutralwrap.class_ == "CaConc":
                caconc = _moose.CaConc(child)
                break
        if caconc is not None:
            ## B has to be set for caconc based on thickness of Ca shell and compartment l and dia.
            ## I am using a translation from Neuron, hence this method.
            ## In Genesis, gmax / (surfacearea*thick) is set as value of B!
            caconc.B = 1 / (2 * FARADAY) / (math.pi * compartment.diameter * compartment.length * caconc.thick)
            for child in compartment.children:
                neutralwrap = _moose.Neutral(child)
                if neutralwrap.class_ == "HHChannel":
                    channel = _moose.HHChannel(child)
                    ## If child Mstring 'ion' is present and is Ca, connect channel current to caconc
                    for childid in channel.children:
                        child = _moose.Neutral(childid)
                        if child.class_ == "Mstring" and child.name == "ion":
                            child = _moose.Mstring(child)
                            if child.value in ["Ca", "ca"]:
                                _moose.connect(channel, "IkOut", caconc, "current")
                                print "Connected IkOut of", channel.path, "to current of", caconc.path
                if neutralwrap.class_ == "HHChannel2D":
                    channel = _moose.HHChannel2D(child)
                    ## If child Mstring 'ionDependency' is present, connect caconc Ca conc to channel
                    for childid in channel.children:
                        child = _moose.Neutral(childid)
                        if child.class_ == "Mstring" and child.name == "ionDependency":
                            child = _moose.Mstring(child)
                            if child.value in ["Ca", "ca"]:
                                _moose.connect(caconc, "concOut", channel, "concen")
                                print "Connected concOut of", caconc.path, "to concen of", channel.path
コード例 #10
0
ファイル: utils.py プロジェクト: csiki/moose-csiki
def connect_CaConc(compartment_list, temperature=None):
    """ Connect the Ca pools and channels within each of the compartments in compartment_list
     Ca channels should have a child Mstring named 'ion' with value set in MOOSE.
     Ca dependent channels like KCa should have a child Mstring called 'ionDependency' with value set in MOOSE.
     Call this only after instantiating cell so that all channels and pools have been created. """
    for compartment in compartment_list:
        caconc = None
        for child in compartment.children:
            neutralwrap = _moose.Neutral(child)
            if neutralwrap.className == 'CaConc':
                caconc = _moose.CaConc(child)
                break
        if caconc is not None:
            child = get_child_Mstring(caconc,'phi')
            if child is not None:
                caconc.B = float(child.value) # B = phi by definition -- see neuroml 1.8.1 defn
            else:
                ## B has to be set for caconc based on thickness of Ca shell and compartment l and dia,
                ## OR based on the Mstring phi under CaConc path.
                ## I am using a translation from Neuron for mitral cell, hence this method.
                ## In Genesis, gmax / (surfacearea*thick) is set as value of B!
                caconc.B = 1 / (2*FARADAY) / \
                    (math.pi*compartment.diameter*compartment.length * caconc.thick)
            for child in compartment.children:
                neutralwrap = _moose.Neutral(child)
                if neutralwrap.className == 'HHChannel':
                    channel = _moose.HHChannel(child)
                    ## If child Mstring 'ion' is present and is Ca, connect channel current to caconc
                    for childid in channel.children:
                        # in async13, gates which have not been created still 'exist'
                        # i.e. show up as a child, but cannot be wrapped.
                        try:
                            child = _moose.element(childid)
                            if child.className=='Mstring':
                                child = _moose.Mstring(child)
                                if child.name=='ion':
                                    if child.value in ['Ca','ca']:
                                        _moose.connect(channel,'IkOut',caconc,'current')
                                        print 'Connected IkOut of',channel.path,'to current of',caconc.path
                                ## temperature is used only by Nernst part here...
                                if child.name=='nernst_str':
                                    nernst = _moose.Nernst(channel.path+'/nernst')
                                    nernst_params = string.split(child.value,',')
                                    nernst.Cout = float(nernst_params[0])
                                    nernst.valence = float(nernst_params[1])
                                    nernst.Temperature = temperature
                                    _moose.connect(nernst,'Eout',channel,'setEk')
                                    _moose.connect(caconc,'concOut',nernst,'ci')
                                    print 'Connected Nernst',nernst.path
                        except TypeError:
                            pass
                            
                if neutralwrap.className == 'HHChannel2D':
                    channel = _moose.HHChannel2D(child)
                    ## If child Mstring 'ionDependency' is present, connect caconc Ca conc to channel
                    for childid in channel.children:
                        # in async13, gates which have not been created still 'exist'
                        # i.e. show up as a child, but cannot be wrapped.
                        try:
                            child = _moose.element(childid)
                            if child.className=='Mstring' and child.name=='ionDependency':
                                child = _moose.Mstring(child)
                                if child.value in ['Ca','ca']:
                                    _moose.connect(caconc,'concOut',channel,'concen')
                                    print 'Connected concOut of',caconc.path,'to concen of',channel.path
                        except TypeError:
                            pass
コード例 #11
0
def connect_CaConc(compartment_list, temperature=None):
    """ Connect the Ca pools and channels within each of the compartments in compartment_list
     Ca channels should have a child Mstring named 'ion' with value set in MOOSE.
     Ca dependent channels like KCa should have a child Mstring called 'ionDependency' with value set in MOOSE.
     Call this only after instantiating cell so that all channels and pools have been created. """
    for compartment in compartment_list:
        caconc = None
        for child in compartment.children:
            neutralwrap = _moose.Neutral(child)
            if neutralwrap.className == 'CaConc':
                caconc = _moose.CaConc(child)
                break
        if caconc is not None:
            child = get_child_Mstring(caconc, 'phi')
            if child is not None:
                caconc.B = float(
                    child.value
                )  # B = phi by definition -- see neuroml 1.8.1 defn
            else:
                ## B has to be set for caconc based on thickness of Ca shell and compartment l and dia,
                ## OR based on the Mstring phi under CaConc path.
                ## I am using a translation from Neuron for mitral cell, hence this method.
                ## In Genesis, gmax / (surfacearea*thick) is set as value of B!
                caconc.B = 1 / (2*FARADAY) / \
                    (math.pi*compartment.diameter*compartment.length * caconc.thick)
            for child in compartment.children:
                neutralwrap = _moose.Neutral(child)
                if neutralwrap.className == 'HHChannel':
                    channel = _moose.HHChannel(child)
                    ## If child Mstring 'ion' is present and is Ca, connect channel current to caconc
                    for childid in channel.children:
                        # in async13, gates which have not been created still 'exist'
                        # i.e. show up as a child, but cannot be wrapped.
                        try:
                            child = _moose.element(childid)
                            if child.className == 'Mstring':
                                child = _moose.Mstring(child)
                                if child.name == 'ion':
                                    if child.value in ['Ca', 'ca']:
                                        _moose.connect(channel, 'IkOut',
                                                       caconc, 'current')
                                        #print 'Connected IkOut of',channel.path,'to current of',caconc.path
                                ## temperature is used only by Nernst part here...
                                if child.name == 'nernst_str':
                                    nernst = _moose.Nernst(channel.path +
                                                           '/nernst')
                                    nernst_params = string.split(
                                        child.value, ',')
                                    nernst.Cout = float(nernst_params[0])
                                    nernst.valence = float(nernst_params[1])
                                    nernst.Temperature = temperature
                                    _moose.connect(nernst, 'Eout', channel,
                                                   'setEk')
                                    _moose.connect(caconc, 'concOut', nernst,
                                                   'ci')
                                    #print 'Connected Nernst',nernst.path
                        except TypeError:
                            pass

                if neutralwrap.className == 'HHChannel2D':
                    channel = _moose.HHChannel2D(child)
                    ## If child Mstring 'ionDependency' is present, connect caconc Ca conc to channel
                    for childid in channel.children:
                        # in async13, gates which have not been created still 'exist'
                        # i.e. show up as a child, but cannot be wrapped.
                        try:
                            child = _moose.element(childid)
                            if child.className == 'Mstring' and child.name == 'ionDependency':
                                child = _moose.Mstring(child)
                                if child.value in ['Ca', 'ca']:
                                    _moose.connect(caconc, 'concOut', channel,
                                                   'concen')
                                    #print 'Connected concOut of',caconc.path,'to concen of',channel.path
                        except TypeError:
                            pass