コード例 #1
0
    def run(self, cell, cmd, temp=22, dt=0.025):
        """
        Run a single current-clamp recording on *section*.
        
        Parameters:
        cell : Cell
            The Cell instance to test. IClamp will be attached to 
            cell.soma(0.5).
        cmd : array
            Array of current command values
        temp : 
            temperature of simulation (22)
        dt : 
            timestep of simulation (0.025)
        """
        self.reset()
        self.cell = cell
        self.current_cmd = cmd
        self.dt = dt
        self.temp = temp

        tend = len(cmd) * dt

        # Configure IClamp
        istim = h.iStim(0.5, sec=cell.soma)
        istim.delay = 0
        istim.dur = 1e9  # these actually do not matter...
        istim.iMax = 0.0
        i_stim = h.Vector(cmd)
        i_stim.play(istim._ref_i, h.dt, 0)

        # Connect recording vectors
        self['vm'] = cell.soma(0.5)._ref_v
        self['i_inj'] = istim._ref_i
        self['time'] = h._ref_t

        # GO
        h.dt = dt
        h.celsius = temp
        h.tstop = tend
        cell.initialize()
        h.frecord_init()
        while h.t < h.tstop:
            h.fadvance()
コード例 #2
0
 def run(self):
     """
     Perform a simulation run on the little network we built,
     and plot the results
     """
     sites = [x for x in self.cell.all_sections['axonnode']]
     ptype = 'pulses'
     self.default_durs=[10., 100., 25.]
     stimdict = {  # set up the stimulus parameters
             'NP': 20,
             'Sfreq': 500.0,
             'delay': self.default_durs[0],
             'dur': 0.5,
             'amp': 2.0,
             'PT': 0.0,
             'dt': self.dt,
             }
     istim = h.iStim(0.5, sec=self.cell.soma)
     istim.delay = 0.
     istim.dur = 1e9 # these actually do not matter...
     istim.iMax = 0.0
     self.run_one(istim, stimdict, sites=sites) #do one simulation
コード例 #3
0
    def run(self,
            pops,
            cf=16e3,
            temp=34.0,
            dt=0.025,
            stim='sound',
            simulator='cochlea'):
        """ 
        1. Connect pop1 => pop2
        2. Instantiate a single cell in pop2
        3. Automatically generate presynaptic cells and synapses from pop1
        4. Stimulate presynaptic cells and record postsynaptically
        """

        pre_pop, post_pop = pops
        pre_pop.connect(post_pop)
        self.pre_pop = pre_pop
        self.post_pop = post_pop

        # start with one cell, selected from the user-selected population, that has
        # a cf close to the center CF
        post_cell_ind = post_pop.select(1, cf=cf, create=True)[0]
        post_cell = post_pop.get_cell(post_cell_ind)
        post_pop.resolve_inputs(depth=1)
        post_sec = post_cell.soma
        self.post_cell_ind = post_cell_ind
        self.post_cell = post_cell

        pre_cell_inds = post_pop.cell_connections(post_cell_ind)[pre_pop]
        pre_cells = [pre_pop.get_cell(i) for i in pre_cell_inds]
        pre_secs = [cell.soma for cell in pre_cells]
        self.pre_cells = pre_cells
        self.pre_cell_inds = pre_cell_inds
        self.stim = sound.TonePip(rate=100e3,
                                  duration=0.1,
                                  f0=cf,
                                  dbspl=60,
                                  ramp_duration=2.5e-3,
                                  pip_duration=0.05,
                                  pip_start=[0.02])

        ##
        ## voltage clamp the target cell
        ##
        #clampV = 40.0
        #vccontrol = h.VClamp(0.5, sec=post_cell.soma)
        #vccontrol.dur[0] = 10.0
        #vccontrol.amp[0] = clampV
        #vccontrol.dur[1] = 100.0
        #vccontrol.amp[1] = clampV
        #vccontrol.dur[2] = 20.0
        #vccontrol.amp[2] = clampV

        #
        # set up stimulation of the presynaptic cells
        #
        self.stim_params = []
        self.istim = []
        for i, pre_cell in enumerate(pre_cells):
            if stim == 'sound':
                pre_cell.set_sound_stim(self.stim, seed=i, simulator=simulator)
                amp = 0.0
            else:
                amp = 3.0
                istim = h.iStim(0.5, sec=pre_cell.soma)
                stim = {}
                stim['NP'] = 10
                stim['Sfreq'] = 100.0  # stimulus frequency
                stim['delay'] = 10.0
                stim['dur'] = 0.5
                stim['amp'] = amp
                stim['PT'] = 0.0
                stim['dt'] = dt
                (secmd, maxt, tstims) = util.make_pulse(stim)
                self.stim_params.append(stim)

                # istim current pulse train
                i_stim_vec = h.Vector(secmd)
                i_stim_vec.play(istim._ref_i, dt, 0, pre_cell.soma(0.5))
                self.istim.append((istim, i_stim_vec))
                self['istim'] = istim._ref_i

            # record presynaptic Vm
            self['v_pre%d' % i] = pre_cell.soma(0.5)._ref_v

        self['t'] = h._ref_t
        self['v_post'] = post_cell.soma(0.5)._ref_v

        #
        # Run simulation
        #
        h.dt = dt
        self.dt = dt
        h.celsius = post_cell.status['temperature']
        self.temp = h.celsius
        post_cell.cell_initialize()  # proper initialization.
        h.dt = self.dt
        custom_init(v_init=post_cell.vm0)
        h.t = 0.
        h.tstop = 200.0
        while h.t < h.tstop:
            h.fadvance()
コード例 #4
0
    def run(self,
            mode='IV',
            cf=16e3,
            temp=34.0,
            dt=0.025,
            stimamp=0,
            iinj=[1.0]):
        self.dt = dt
        self.temp = temp

        self.make_cells(cf, temp, dt)
        print dir(self.pre_cells[0])
        seed = 0
        j = 0
        if mode == 'sound':
            self.make_stimulus(stimulus='tone')

            for np in range(len(self.pre_cells)):
                self.pre_cells[np].set_sound_stim(self.stim, seed=seed)
                seed += 1
                synapses.append(pre_cells[-1].connect(post_cell,
                                                      post_opts={
                                                          'AMPAScale': 2.0,
                                                          'NMDAScale': 2.0
                                                      },
                                                      type=synapseType))
                for i in range(synapses[-1].terminal.n_rzones):
                    xmtr['xmtr%04d' % j] = h.Vector()
                    xmtr['xmtr%04d' % j].record(
                        synapses[-1].terminal.relsite._ref_XMTR[i])
                j = j + 1
                synapses[
                    -1].terminal.relsite.Dep_Flag = False  # no depression in these simulations

        print 'setup to run'
        self.stim_params = []
        self.istim = []
        self.istims = []
        if mode == 'pulses':
            for i, pre_cell in enumerate(self.pre_cells):
                stim = {}
                stim['NP'] = 10
                stim['Sfreq'] = 100.0  # stimulus frequency
                stim['delay'] = 10.0
                stim['dur'] = 0.5
                stim['amp'] = stimamp
                stim['PT'] = 0.0
                stim['dt'] = dt
                (secmd, maxt, tstims) = make_pulse(stim)
                self.stim_params.append(stim)
                stim['amp'] = 0.
                (secmd2, maxt2, tstims2) = make_pulse(stim)

                # istim current pulse train
                istim = h.iStim(0.5, sec=pre_cell.soma)
                i_stim_vec = h.Vector(secmd)
                self.istim.append((istim, i_stim_vec))
                self['istim%02d' % i] = istim._ref_i

        self.postpars = []
        self.poststims = []
        if mode == 'IV':
            for i, post_cell in enumerate(self.post_cells):
                pstim = {}
                pstim['NP'] = 1
                pstim['Sfreq'] = 100.0  # stimulus frequency
                pstim['delay'] = 10.0
                pstim['dur'] = 100
                pstim['amp'] = iinj[0]
                pstim['PT'] = 0.0
                pstim['dt'] = dt
                (secmd, maxt, tstims) = make_pulse(pstim)
                self.postpars.append(pstim)

                # istim current pulse train
                pistim = h.iStim(0.5, sec=post_cell.soma)
                pi_stim_vec = h.Vector(secmd)
                self.poststims.append((pistim, pi_stim_vec))
                self['poststim%02d' % i] = pistim._ref_i
        #
        # Run simulation
        #
        h.celsius = temp
        self.temp = temp

        # first find rmp for each cell
        for m in range(self.npost):
            self.post_cells[m].vm0 = None
            self.post_cells[m].cell_initialize()
            # set starting voltage...
            self.post_cells[m].soma(0.5).v = self.post_cells[m].vm0
        h.dt = 0.02
        h.t = 0  # run a bit to find true stable rmp
        h.tstop = 20.
        h.batch_save()
        h.batch_run(h.tstop, h.dt, 'v.dat')

        # order matters: don't set these up until we need to
        self['t'] = h._ref_t
        # set up recordings
        if mode == 'pulses':
            for i in range(self.npre):
                self.istim[i][1].play(self.istim[i][0]._ref_i, dt, 0)
                self['v_pre%02d' % i] = self.pre_cells[i].soma(0.5)._ref_v
        for m in range(self.npost):
            if mode == 'IV':
                self.poststims[m][1].play(self.poststims[m][0]._ref_i, dt, 0)
            self['v_post%02d' % m] = self.post_cells[m].soma(0.5)._ref_v
        h.finitialize()  # init and instantiate recordings
        print 'running'
        h.t = 0.
        h.tstop = 200.
        h.batch_run(h.tstop, h.dt, 'v.dat')
コード例 #5
0
def run_democlamp(cell, dend, vsteps=[-60,-70,-60], tsteps=[10,50,100]):
    """
    Does some stuff.
    
    """
    f1 = pylab.figure(1)
    gs = GS.GridSpec(2, 2,
                       width_ratios=[1, 1],
                       height_ratios=[1, 1])

    # note numbering for insets goes from 1 (upper right) to 4 (lower right)
    # counterclockwise
    pA = f1.add_subplot(gs[0])
    pAi = INSETS.inset_axes(pA, width="66%", height="40%", loc=2)
    pB = f1.add_subplot(gs[1])
    pBi = INSETS.inset_axes(pB, width="66%", height="40%", loc=4)
    pC = f1.add_subplot(gs[2])
    pCi = INSETS.inset_axes(pC, width="66%", height="40%", loc=2)
    pD = f1.add_subplot(gs[3])
    pDi = INSETS.inset_axes(pD, width="66%", height="40%", loc=1)
    #h.topology()
    
    Ld = 0.5
    Ld2 = 1.0
    
    VClamp = h.SEClamp(0.5, cell)
    VClamp.dur1 = tsteps[0]
    VClamp.amp1 = vsteps[0]
    VClamp.dur2 = tsteps[1]
    VClamp.amp2 = vsteps[1]
    VClamp.dur3 = tsteps[2]
    VClamp.amp3 = vsteps[2]
    Rs0 = 10.
    VClamp.rs = Rs0
    compensation = [0., 70., 95.]
    cms = [cell.cm*(100.-c)/100. for c in compensation]
    
    vrec = h.iStim(Ld, sec=dend[0])
    vrec.delay = 0
    vrec.dur = 1e9 # these actually do not matter...
    vrec.iMax = 0.0
    vrec2 = h.iStim(Ld2, sec=dend[0])
    vrec2.delay = 0
    vrec2.dur = 1e9 # these actually do not matter...
    vrec2.iMax = 0.0

    stim = {}
    stim['NP'] = 1
    stim['Sfreq'] = 20 # stimulus frequency
    stim['delay'] = tsteps[0]
    stim['dur'] = tsteps[1]
    stim['amp'] = vsteps[1]
    stim['PT'] = 0.0
    stim['hold'] = vsteps[0]
#    (secmd, maxt, tstims) = make_pulse(stim)
    tend = 79.5
    linetype = ['-', '-', '-']
    linethick = [0.5, 0.75, 1.25]
    linecolor = [[0.66, 0.66, 0.66], [0.4, 0.4, 0.3], 'k'] 
    n = 0
    vcmds = [-70, -20]
    vplots = [(pA, pAi, pC, pCi), (pB, pBi, pD, pDi)]
    for m,  VX in enumerate(vcmds):
        stim['amp'] = VX
        pl = vplots[m]
        print m, VX
        (secmd, maxt, tstims) = make_pulse(stim)
        for n, rsc in enumerate(compensation):
            vec={}
            for var in ['VCmd', 'i_inj', 'time', 'Vsoma', 'Vdend',
                        'Vdend2', 'VCmdR']:
                vec[var] = h.Vector()
            VClamp.rs = Rs0*(100.-rsc)/100.
            cell.cm = cms[n]
           # print VClamp.rs, cell.cm, VClamp.rs*cell.cm
            vec['VCmd'] = h.Vector(secmd)
            vec['Vsoma'].record(cell(0.5)._ref_v, sec=cell)
            vec['Vdend'].record(dend[0](Ld)._ref_v, sec=dend[0])
            vec['time'].record(h._ref_t)
            vec['i_inj'].record(VClamp._ref_i, sec=cell)

            vec['VCmdR'].record(VClamp._ref_vc, sec=cell)
            VClamp.amp2 = VX
            #            vec['VCmd'].play(VClamp.amp2, h.dt, 0, sec=cell)

            h.tstop = tend
            h.init()
            h.finitialize(-60)
            h.run()
            vc = np.asarray(vec['Vsoma'])
            tc = np.asarray(vec['time'])
            
            # now plot the data, raw and as insets
            for k in [0, 1]:
                pl[k].plot(vec['time'], vec['i_inj'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n])
                yl = pl[k].get_ylim()
                if k == 0:
                    pass
                    #pl[k].set_ylim([1.5*yl[0], -1.5*yl[1]])
                else:
                    pass
            
            for k in [2,3]:
                pl[k].plot(vec['time'], vec['Vsoma'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n])
                pl[k].plot(vec['time'], vec['VCmdR'], color=linecolor[n], linestyle = '--', linewidth=1, dashes=(1,1))
                pl[k].plot(vec['time'], vec['Vdend'], color=linecolor[n], linestyle = linetype[n], linewidth=linethick[n], dashes=(3,3))
                if VX < vsteps[0]:
                    pl[k].set_ylim([-72, -40])
                else:
                    pl[k].set_ylim([-62,VX+30])

    ptx = 10.8
    pBi.set_xlim([9.8, ptx])
    pAi.set_xlim([9.8, ptx])
    PH.setX(pAi, pCi)
    PH.setX(pBi, pDi)
    pD.set_ylim([-65, 10])
#    PH.setY(pC, pCi) # match Y limits
    PH.cleanAxes([pA, pAi, pB, pBi, pC, pCi, pD, pDi])
    PH.formatTicks([pA, pB, pC, pD], axis='x', fmt='%d')
    PH.formatTicks([pC, pD], axis='y', fmt='%d')
    PH.calbar(pAi, [ptx-1, 0, 0.2, 2.])
    PH.calbar(pCi, [ptx-1, -50., 0.2, 10])
    PH.calbar(pBi, [ptx-1, 0, 0.2, 10])
    PH.calbar(pDi, [ptx-1, -50., 0.2, 20])
    pylab.draw()
    pylab.show()    
コード例 #6
0
    def run(self, pre_sec, post_sec, n_synapses, temp=34.0, dt=0.025, 
            vclamp=40.0, iterations=1, tstop=240.0, stim_params=None, synapsetype='multisite', **kwds):
        """ 
        Basic synapse test. Connects sections of two cells with *n_synapses*.
        The cells are allowed to negotiate the details of the connecting 
        synapse. The presynaptic soma is then driven with a pulse train
        followed by a recovery pulse of varying delay.
        
        *stim_params* is an optional dictionary with keys 'NP', 'Sfreq', 'delay',
        'dur', 'amp'.
        
        Analyses:
        
        * Distribution of PSG amplitude, kinetics, and latency
        * Synaptic depression / facilitation and recovery timecourses
        """
        Protocol.run(self, **kwds)
        
        pre_cell = cells.cell_from_section(pre_sec)
        post_cell = cells.cell_from_section(post_sec)
        synapses = []
        for i in range(n_synapses):
            synapses.append(pre_cell.connect(post_cell, type=synapsetype))
        
        self.synapses = synapses
        self.pre_sec = synapses[0].terminal.section
        self.post_sec = synapses[0].psd.section
        self.pre_cell = pre_cell
        self.post_cell = post_cell
        self.plots={}  # store plot information here
        #
        # voltage clamp the target cell
        #
        clampV = vclamp
        vccontrol = h.VClamp(0.5, sec=post_cell.soma)
        vccontrol.dur[0] = 10.0
        vccontrol.amp[0] = clampV
        vccontrol.dur[1] = 100.0
        vccontrol.amp[1] = clampV
        vccontrol.dur[2] = 20.0
        vccontrol.amp[2] = clampV

        #
        # set up stimulation of the presynaptic axon/terminal
        #
        
        istim = h.iStim(0.5, sec=pre_cell.soma)
        stim = {
            'NP': 10,
            'Sfreq': 100.0,
            'delay': 10.0,
            'dur': 0.5,
            'amp': 10.0,
            'PT': 0.0,
            'dt': dt,
        }
        if stim_params is not None:
            stim.update(stim_params)
        (secmd, maxt, tstims) = util.make_pulse(stim)
        self.stim = stim

        if tstop is None:
            tstop = len(secmd) * dt
        
        istim.delay = 0
        istim.dur = 1e9 # these actually do not matter...
        istim.iMax = 0.0

        # istim current pulse train
        i_stim_vec = h.Vector(secmd)
        i_stim_vec.play(istim._ref_i, dt, 0)

        # create hoc vectors for each parameter we wish to monitor and display
        synapse = synapses[0]
        self.all_psd = []
        if isinstance(synapses[0].psd, GlyPSD) or isinstance(synapses[0].psd, GluPSD):
            for syn in synapses:
                self.all_psd.extend(syn.psd.all_psd)
        elif isinstance(synapses[0].psd, Exp2PSD):
            for syn in synapses:
                self.all_psd.append(syn)

        #for i, cleft in enumerate(synapse.psd.clefts):
            #self['cleft_xmtr%d' % i] = cleft._ref_CXmtr
            #self['cleft_pre%d' % i] = cleft._ref_pre
            #self['cleft_xv%d' % i] = cleft._ref_XV
            #self['cleft_xc%d' % i] = cleft._ref_XC
            #self['cleft_xu%d' % i] = cleft._ref_XU

        #
        # Run simulation
        #
        h.tstop = tstop # duration of a run
        h.celsius = temp
        h.dt = dt
        self.temp = temp
        self.dt = dt
        self.isoma = []
        self.currents = {'ampa': [], 'nmda': []}
        self.all_releases = []
        self.all_release_events = []
        start_time = timeit.default_timer()
        for nrep in xrange(iterations): # could do multiple runs.... 
            self.reset()
            self['v_pre'] = pre_cell.soma(0.5)._ref_v
            self['t'] = h._ref_t
            self['v_soma'] = pre_cell.soma(0.5)._ref_v
            if not isinstance(synapse.psd, Exp2PSD):
                self['relsite_xmtr'] = synapse.terminal.relsite._ref_XMTR[0]

            if isinstance(synapse.psd, GluPSD):
                # make a synapse monitor for each release zone
                self.all_nmda = []
                self.all_ampa = []
                for syn in synapses:
                    # collect all PSDs across all synapses
                    self.all_ampa.extend(syn.psd.ampa_psd)
                    self.all_nmda.extend(syn.psd.nmda_psd)
                    
                    # Record current through all PSDs individually
                    syn.psd.record('i', 'g', 'Open')
            
                #for k,p in enumerate(self.all_nmda):
                    #self['iNMDA%03d' % k] = p._ref_i
                    #self['opNMDA%03d' % k] = p._ref_Open
                #for k,p in enumerate(self.all_ampa):
                    #self['iAMPA%03d' % k] = p._ref_i
                    #self['opAMPA%03d' % k] = p._ref_Open
        
            elif isinstance(synapse.psd, GlyPSD):
                #  Record current through all PSDs individually
                for k,p in enumerate(self.all_psd):
                    self['iGLY%03d' % k] = p._ref_i
                    self['opGLY%03d' % k] = p._ref_Open
                
                psd = self.all_psd
                if synapse.psd.psdType == 'glyslow':
                    nstate = 7
                    self['C0'] = psd[0]._ref_C0
                    self['C1'] = psd[0]._ref_C1
                    self['C2'] = psd[0]._ref_C2
                    self['O1'] = psd[0]._ref_O1
                    self['O2'] = psd[0]._ref_O2
                    self['D1'] = psd[0]._ref_D1
                    #self['D3'] = psd[0]._ref_D3
                    #self['O1'] = psd[0]._ref_O1
                elif synapse.psd.psdType == 'glyfast':
                    nstate = 7
                    self['C0'] = psd[0]._ref_C0
                    self['C1'] = psd[0]._ref_C1
                    self['C2'] = psd[0]._ref_C2
                    self['C3'] = psd[0]._ref_C3
                    self['O1'] = psd[0]._ref_O1
                    self['O2'] = psd[0]._ref_O2
            elif isinstance(synapse.psd, Exp2PSD):
                self['iPSD'] = self.all_psd[0].psd.syn._ref_i

            if not isinstance(synapse.psd, Exp2PSD):
                for i, s in enumerate(synapses):
                    s.terminal.relsite.rseed = util.random_seed.current_seed() + nrep
            util.custom_init()
            h.run()

            # add up psd current across all runs
            if isinstance(synapse.psd, GluPSD):
                iampa = np.zeros_like(synapse.psd.get_vector('ampa', 'i'))
                inmda = iampa.copy()
                for syn in self.synapses:
                    for i in range(syn.psd.n_psd):
                        iampa += syn.psd.get_vector('ampa', 'i', i)
                        inmda += syn.psd.get_vector('nmda', 'i', i)
                isoma = iampa + inmda
                self.currents['ampa'].append(iampa)
                self.currents['nmda'].append(inmda)
            elif isinstance(synapse.psd, GlyPSD):
                isoma = np.zeros_like(self['iGLY000'])
                for k in range(len(self.all_psd)):
                    isoma += self['iGLY%03d'%k]
            elif isinstance(synapse.psd, Exp2PSD):
                 isoma = self['iPSD']
            self.isoma.append(isoma)
            self.all_releases.append(self.release_timings())
            self.all_release_events.append(self.release_events())

        elapsed = timeit.default_timer() - start_time
        print 'Elapsed time for %d Repetions: %f' % (iterations, elapsed)
コード例 #7
0
ファイル: iv_curve.py プロジェクト: rcrowder/cnmodel
    def run(self, ivrange, cell, durs=None, sites=None, reppulse=None, temp=22,
            dt=0.025, initdelay=0.):
        """
        Run a current-clamp I/V curve on *cell*.
        
        Parameters
        ----------
        ivrange : dict of list of tuples
            Each item in the list is (min, max, step) describing a range of 
            levels to test. Range values are inclusive, so the max value may
            appear in the test values. Using multiple ranges allows finer 
            measurements in some ranges.
            For example::
            
                {'pulse': [(-1., 0., 1.), (-0.1, 0., 0.02)], 'prepulse': [(-0.5, 0, 0.1)]}
         
                Optional keys include 'pulsedur' : the duration of the pulse, in ms
                                      'prepulsecur: the duration of the prepulse, in ms
                The prepulse or the pulse can have a single value if the other is ranged.
        cell : Cell
            The Cell instance to test.
        durs : tuple
            durations of (pre, pulse, post) regions of the command
        sites : list
            Sections to add recording electrodes
        reppulse : 
            stimulate with pulse train
        temp : 
            temperature of simulation (32)
        dt : 
            timestep of simulation (0.025)
            
        """
        self.reset()
        self.cell = cell
        self.initdelay = initdelay
        self.dt = dt
        self.temp = temp
        # Calculate current pulse levels
        icur = []
        precur = [0.]
        self.pre_current_cmd = []
        npresteps = 0
        if isinstance(ivrange['pulse'], tuple):
            icmd = [ivrange['pulse']]  # convert to a list with tuple(s) embedded
        else:
            icmd = ivrange['pulse']  # was already a list with multiple tuples
        for c in icmd:  # unpack current levels for the main pulse
            try:
                (imin, imax, istep) = c # unpack a tuple... or list
            except:
                raise TypeError("run_iv arguments must be a dict with tuples {'pulse': (imin, imax, istep), 'prepulse': ...}")
            nstep = np.floor((imax-imin)/istep) + 1
            icur.extend(imin + istep * np.arange(nstep))  # build the list
        self.current_cmd = np.array(sorted(icur))
        nsteps = self.current_cmd.shape[0]
        # Configure IClamp
        if durs is None:
            durs = [10.0, 100.0, 50.0]  # set default durs

        if 'prepulse' in ivrange.keys():
            if isinstance(ivrange['prepulse'], tuple):
                icmd = [ivrange['prepulse']]  # convert to a list with tuple(s) embedded
            else:
                icmd = ivrange['prepulse']  # was already a list with multiple tuples
            precur=[]
            for c in icmd:
                try:
                    (imin, imax, istep) = c # unpack a tuple... or list
                except:
                    raise TypeError("run_iv arguments must be a dict with tuples {'pulse': (imin, imax, istep), 'prepulse': ...}")
                nstep = np.floor((imax-imin)/istep) + 1
                precur.extend(imin + istep * np.arange(nstep))  # build the list
            self.pre_current_cmd = np.array(sorted(precur))
            npresteps = self.pre_current_cmd.shape[0]
            durs.insert(1, 50.)
        
        self.durs = durs
        # set up stimulation with a pulse train
        if reppulse is not None:
            stim = {
                'NP': 10,
                'Sfreq': 50.0,
                'delay': 10.0,
                'dur': 2,
                'amp': 1.0,
                'PT': 0.0,
                'dt': self.dt,
                }
        elif 'prepulse' in ivrange.keys():
            stim = {
                'NP': 2,
                'delay': durs[0],
                'predur': durs[1],
                'dur': durs[2],
                'amp': 1.0,
                'preamp': 0.0,
                'dt': self.dt,
                }
            self.p_start = durs[0]+durs[1]
            self.p_end = self.p_start + durs[2]
            self.p_dur = durs[2]
        else:
            stim = {
                'NP': 1,
                'delay': durs[0],
                'dur': durs[1],
                'amp': 1.0,
                'dt': self.dt,
                }
            self.p_start = durs[0]
            self.p_end = self.p_start + durs[1]
            self.p_dur = durs[1]
        # print stim
        # print('p_: ', self.p_start, self.p_end, self.p_dur)
        istim = h.iStim(0.5, sec=cell.soma)
        istim.delay = 5.
        istim.dur = 1e9 # these actually do not matter...
        istim.iMax = 0.0
        self.tend = np.sum(durs) # maxt + len(iextend)*stim['dt']

        self.cell = cell
        for i in range(nsteps):
            # Generate current command for this level
            stim['amp'] = self.current_cmd[i]
            if npresteps > 0:
                for j in range(npresteps):
                    stim['preamp'] = self.pre_current_cmd[j]
                    self.run_one(istim, stim, initflag=(i==0 and j==0))
            else:
                self.run_one(istim, stim, initflag=(i==0))
コード例 #8
0
    def run(self,
            pre_sec,
            post_sec,
            temp=34.0,
            dt=0.025,
            vclamp=-65.0,
            iterations=1,
            tstop=200.0,
            stim_params=None,
            **kwds):
        """ 
        """
        Protocol.run(self, **kwds)

        pre_cell = cells.cell_from_section(pre_sec)
        post_cell = cells.cell_from_section(post_sec)
        synapse = pre_cell.connect(post_cell, type='simple')

        self.synapse = synapse
        self.pre_sec = synapse.terminal.section
        self.post_sec = synapse.psd.section
        self.pre_cell = pre_cell
        self.post_cell = post_cell

        #
        # voltage clamp the target cell
        #
        vccontrol = h.VClamp(0.5, sec=post_cell.soma)
        vccontrol.dur[0] = tstop
        vccontrol.amp[0] = vclamp
        #vccontrol.dur[1] = 100.0
        #vccontrol.amp[1] = clampV
        #vccontrol.dur[2] = 20.0
        #vccontrol.amp[2] = clampV

        #
        # set up stimulation of the presynaptic axon/terminal
        #

        istim = h.iStim(0.5, sec=pre_cell.soma)
        stim = {
            'NP': 10,
            'Sfreq': 100.0,
            'delay': 10.0,
            'dur': 0.5,
            'amp': 10.0,
            'PT': 0.0,
            'dt': dt,
        }
        if stim_params is not None:
            stim.update(stim_params)
        (secmd, maxt, tstims) = util.make_pulse(stim)
        self.stim = stim

        if tstop is None:
            tstop = len(secmd) * dt

        istim.delay = 0
        istim.dur = 1e9  # these actually do not matter...
        istim.iMax = 0.0

        # istim current pulse train
        i_stim_vec = h.Vector(secmd)
        i_stim_vec.play(istim._ref_i, dt, 0)

        #
        # Run simulation
        #
        h.tstop = tstop  # duration of a run
        h.celsius = temp
        h.dt = dt
        self.temp = temp
        self.dt = dt
        for nrep in xrange(iterations):  # could do multiple runs....
            self.reset()
            self['v_pre'] = pre_cell.soma(0.5)._ref_v
            self['t'] = h._ref_t
            self['v_soma'] = post_cell.soma(0.5)._ref_v
            self['i_soma'] = vccontrol._ref_i
            util.custom_init()
            h.run()