Esempio n. 1
0
class F5():
    def __init__(self, filename):
        # build plotting area
        #
        self.filename = filename
        self.iv = IVCurve()  # use standard IVCurve here...
        self.temperature = 34
        self.initdelay = 150.

    def run(self):
        self.post_cell = cells.Bushy.create(morphology=self.filename,
                                            decorator=Decorator,
                                            species='mouse',
                                            modelType='XM13')
        self.post_cell.set_temperature(float(self.temperature))
        self.post_cell.set_d_lambda(
            freq=2000.)  # necessary to ensure appropriate spatial
        self.iv.reset()
        irange = self.post_cell.i_test_range
        irange = {'pulse': (-0.6, 1.1, 0.2)}
        self.durs = (self.initdelay + 20., 100., 50.)
        self.iv.run(irange,
                    self.post_cell,
                    durs=self.durs,
                    temp=float(self.temperature),
                    initdelay=self.initdelay)

    def plot(self):
        pg.setConfigOption('background', 'w')  # set background to white
        pg.setConfigOption('foreground', 'k')
        self.app = pg.mkQApp()

        wintitle = 'test_decorator'
        self.view = pg.GraphicsView()
        self.layout = pg.GraphicsLayout()  #(border=(100,100,100))
        self.view.setCentralItem(self.layout)
        self.view.resize(800, 600)
        self.view.show()
        self.plots = {}
        nr1 = 6
        nc = 10
        for i in range(1, nr1):
            self.plots['p%d' % i] = None
        for i in range(1, nr1 + 1):
            self.layout.addLayout(row=i, col=nc)
        for i in range(1, nc + 1):
            self.layout.addLayout(row=nr1 + 2, col=i)

        self.plots['p1'] = self.layout.addPlot(row=1,
                                               col=1,
                                               rowspan=6,
                                               colspan=9,
                                               labels={
                                                   'left': 'V (mV)',
                                                   'bottom': 'Time (ms)'
                                               })
        self.plots['p2'] = self.layout.addPlot(row=7,
                                               col=1,
                                               rowspan=1,
                                               colspan=9,
                                               labels={
                                                   'left': 'I (nA)',
                                                   'bottom': 'Time (ms)'
                                               })

        for k in range(len(self.iv.voltage_traces)):
            self.plots['p1'].plot(self.iv.time_values,
                                  np.array(self.iv.voltage_traces[k]),
                                  pen=pg.mkPen('k', width=0.75))
            self.plots['p2'].plot(self.iv.time_values,
                                  np.array(self.iv.current_traces[k]),
                                  pen=pg.mkPen('k', width=0.75))
        self.plots['p1'].setRange(xRange=(0.,
                                          np.sum(self.durs) - self.initdelay),
                                  yRange=(-160., 40.))
        self.plots['p2'].setRange(xRange=(0.,
                                          np.sum(self.durs) - self.initdelay),
                                  yRange=(-1, 1))
        PH.noaxes(self.plots['p1'])
        PH.calbar(self.plots['p1'],
                  calbar=[125., -120., 10., 20.],
                  unitNames={
                      'x': 'ms',
                      'y': 'mV'
                  })
        PH.noaxes(self.plots['p2'])
        PH.calbar(self.plots['p2'],
                  calbar=[125, 0.1, 0., 0.5],
                  unitNames={
                      'x': 'ms',
                      'y': 'nA'
                  })

        text = (u"{0:2d}\u00b0C {1:.2f}-{2:.2f} nA".format(
            int(self.temperature), np.min(self.iv.current_cmd),
            np.max(self.iv.current_cmd)))
        ti = pg.TextItem(text, anchor=(1, 0))
        ti.setFont(pg.QtGui.QFont('Arial', 9))
        ti.setPos(120., -120.)
        self.plots['p1'].addItem(ti)
Esempio n. 2
0
class Toy(Protocol):
    """
    Calls to encapsulate the model runs
    Run a set of cells with defined parameters to show excitability patterns. 
    Note that cells from Rothman and Manis are run at 22C; others at various
    temperatures depending on how they were initially measured and defined.
    
    """
    def __init__(self):
        super(Toy, self).__init__()

    def current_name(self, name, n):
        """
        From the name of the current model, get the current injection information
        
        Parameters
        ---------
        name : str (no default)
            name of the cell type
        n : int (no default)
        """
        if len(self.celltypes[name][3]) > 2:
            injs = self.celltypes[name][3]
            injarr = np.linspace(injs[0], injs[1], injs[2], endpoint=True)
            return '%.3f' % injarr[n]
        else:
            return '%.3f' % self.celltypes[name][3][n]

    def getname(self, cell, ninj):
        name = self.make_name(cell)
        iname = self.current_name(name, ninj)
        nname = name + ' ' + iname
        return name, nname

    def make_name(self, cell):
        return cell + ', ' + self.celltypes[cell][1] + ':'

    def run(self):
        sre = re.compile(
            '(?P<cell>\w+)(?:[, ]*)(?P<type>[\w-]*)(?:[, ]*)(?P<species>[\w-]*)'
        )  # regex for keys in cell types
        self.celltypes = OrderedDict([
            ('Bushy, II', (cells.Bushy, "II", 'guineapig', (-0.5, 0.5, 11),
                           22)),
            ('Bushy, II-I', (cells.Bushy, "II-I", 'guineapig', (-0.5, 0.5, 11),
                             22)),
            ('DStellate, I-II', (cells.DStellate, 'I-II', 'guineapig',
                                 (-0.3, 0.3, 9), 22)),
            ('TStellate, I-c', (cells.TStellate, "I-c", 'guineapig',
                                (-0.15, 0.15, 9), 22)),
            ('TStellate, I-t', (cells.TStellate, "I-t", 'guineapig',
                                (-0.15, 0.15, 9), 22)),
            ('Octopus, II-o', (cells.Octopus, 'II-o', 'guineapig', (-2.5, 2.5,
                                                                    11), 22)),
            ('Bushy, II, Mouse', (cells.Bushy, "II", 'mouse', (-1, 1.2, 13),
                                  34)),
            ('TStellate, I-c, Mouse', (cells.TStellate, "I-c", 'mouse',
                                       (-1, 1, 9), 34)),
            ('DStellate, I-II, Mouse', (cells.DStellate, 'I-II', 'mouse',
                                        (-0.5, 0.5, 9), 34)),
            ('Pyramidal, I, Rat', (cells.Pyramidal, 'I', 'rat', (-0.3, 0.4,
                                                                 11), 34)),
            ('Cartwheel, I, Mouse', (cells.Cartwheel, 'I', 'mouse', (-0.5, 0.5,
                                                                     9), 34)),
            ('Tuberculoventral, I, Mouse', (cells.Tuberculoventral, 'I',
                                            'mouse', (-0.35, 1, 11), 34)),
            ('SGC, bm, Mouse', (cells.SGC, "bm", 'mouse', (-0.2, 0.6, 9), 34)),
            ('SGC, a, Mouse', (cells.SGC, "a", 'mouse', (-0.2, 0.6, 9), 34)),
        ])

        dt = 0.025
        h.dt = dt
        h.celsius = 22

        stim = {
            'NP': 1,
            'delay': 10,
            'dur': 100,
            'amp': 0.,
            'dt': h.dt,
        }
        tend = stim['delay'] + stim['dur'] + 20.

        netcells = {}
        for c in self.celltypes.keys():
            g = sre.match(c)
            cellname = g.group('cell')
            modelType = g.group('type')
            species = self.celltypes[c][2]
            if g.group('type') == '':
                netcells[c] = self.celltypes[c][0].create()
            else:
                netcells[c] = self.celltypes[c][0].create(modelType=modelType,
                                                          species=species,
                                                          debug=False)
        # dicts to hold data
        pl = OrderedDict([])
        pl2 = OrderedDict([])
        rvec = OrderedDict([])
        vec = OrderedDict([])
        istim = OrderedDict([])
        ncells = len(self.celltypes.keys())
        #
        # build plotting area
        #
        app = pg.mkQApp()
        self.win = pg.GraphicsWindow()
        self.win.setBackground('w')
        self.win.resize(800, 600)
        cols, rows = autorowcol(ncells)

        row = 0
        col = 0
        labelStyle = {'color': '#000', 'font-size': '9pt', 'weight': 'normal'}
        tickStyle = pg.QtGui.QFont('Arial', 9, pg.QtGui.QFont.Light)
        self.iv = IVCurve()  # use standard IVCurve here...
        for n, name in enumerate(self.celltypes.keys()):
            nrn_cell = netcells[
                name]  # get the Neuron object we are using for this cell class
            injcmds = list(self.celltypes[name][3])  # list of injections
            injcmds[2] = (injcmds[1] - injcmds[0]) / (
                float(injcmds[2] - 1))  # convert to pulse format for IVCurve
            temperature = self.celltypes[name][4]
            nrn_cell.set_temperature(float(temperature))
            ninjs = len(injcmds)
            print('cell: ', name)
            # print( 'injs: ', injcmds)
            pl[name] = self.win.addPlot(labels={
                'left': 'V (mV)',
                'bottom': 'Time (ms)'
            })
            PH.nice_plot(pl[name])
            pl[name].setTitle(title=name, font=pg.QtGui.QFont('Arial', 10))
            col += 1
            if col >= cols:
                col = 0
                self.win.nextRow()
                row += 1
            self.iv.reset()
            self.iv.run({'pulse': [injcmds]},
                        nrn_cell,
                        durs=(stim['delay'], stim['dur'], 20.),
                        sites=None,
                        reppulse=None,
                        temp=float(temperature))
            for k in range(len(self.iv.voltage_traces)):
                pl[name].plot(self.iv.time_values,
                              self.iv.voltage_traces[k],
                              pen=pg.mkPen('k', width=0.75))
            pl[name].setRange(xRange=(0., 130.), yRange=(-160., 40.))
            PH.noaxes(pl[name])
            PH.calbar(pl[self.celltypes.keys()[0]],
                      calbar=[0, -120., 10., 20.],
                      unitNames={
                          'x': 'ms',
                          'y': 'mV'
                      })
            text = (u"{0:2d}\u00b0C {1:.2f}-{2:.2f} nA".format(
                int(temperature), np.min(self.iv.current_cmd),
                np.max(self.iv.current_cmd)))
            ti = pg.TextItem(text, anchor=(1, 0))
            ti.setFont(pg.QtGui.QFont('Arial', 9))
            ti.setPos(120., -120.)
            pl[name].addItem(ti)
        # get overall Rin, etc; need to initialize all cells
        nrn_cell.cell_initialize()
        for n, name in enumerate(self.celltypes.keys()):
            nrn_cell = netcells[name]
            nrn_cell.vm0 = nrn_cell.soma.v
            pars = nrn_cell.compute_rmrintau(auto_initialize=False)
            print(
                u'{0:>14s} [{1:>24s}]   *** Rin = {2:6.1f} M\ohm  Tau = {3:6.1f} ms   Vm = {4:6.1f} mV'
                .format(nrn_cell.status['name'], name, pars['Rin'],
                        pars['tau'], pars['v']))