Пример #1
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()
Пример #2
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)
Пример #3
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')
Пример #4
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()