示例#1
0
 def __init__(self, post_cell, info):
     """
     info is a dict
     """
     pre_cells = []
     synapses = []
     j = 0
     xmtr = {}
     for nsgc, sgc in enumerate(range(info['n_sgc'])):
         pre_cells.append(cells.DummySGC(cf=info['cf'], sr=info['sr']))
         if synapseType == 'simple':
             synapses.append(pre_cells[-1].connect(post_cell, type=synapseType))
             synapses[-1].terminal.netcon.weight[0] =info['gmax']*2.0
         elif synapseType == 'multisite':
             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
         pre_cells[-1].set_sound_stim(info['stim'], seed = info['seed'] + nsgc, simulator=info['simulator'])
     Vm = h.Vector()
     Vm.record(post_cell.soma(0.5)._ref_v)
     rtime = h.Vector()
     rtime.record(h._ref_t)
     h.tstop = 1e3*info['run_duration'] # duration of a run
     h.celsius = info['temp']
     h.dt = info['dt']
     post_cell.cell_initialize()
     info['init']()
     h.t = 0.
     h.run()
     return {'time': np.array(rtime), 'vm': Vm.to_python(), 'xmtr': xmtr, 'pre_cells': pre_cells, 'post_cell': post_cell, 'synapses': synapses}
示例#2
0
    def run(self, temp=34.0, dt=0.025, seed=575982035, simulator=None):
        preCell = cells.DummySGC(cf=4000, sr=2)
        postCell = cells.Bushy.create()
        synapse = preCell.connect(postCell)
        self.pre_cell = preCell
        self.post_cell = postCell
        self.synapse = synapse

        self.stim = sound.TonePip(rate=100e3,
                                  duration=0.1,
                                  f0=4000,
                                  dbspl=80,
                                  ramp_duration=2.5e-3,
                                  pip_duration=0.04,
                                  pip_start=[0.02])

        preCell.set_sound_stim(self.stim, seed=seed, simulator=simulator)

        self['vm'] = postCell.soma(0.5)._ref_v
        #self['prevm'] = preCell.soma(0.5)._ref_v
        for i in range(30):
            self['xmtr%d' % i] = synapse.terminal.relsite._ref_XMTR[i]
            synapse.terminal.relsite.Dep_Flag = False
        self['t'] = h._ref_t

        h.tstop = 100.0  # duration of a run
        h.celsius = temp
        h.dt = dt

        custom_init()
        h.run()
示例#3
0
    def make_cells(self, cf=16e3, temp=34.0, dt=0.025):
        self.pre_cells = []
        for n in range(self.npre):
            self.pre_cells.append(cells.DummySGC(cf=cf, sr=3))

        self.post_cells = []
        for n in range(self.npost):
            self.post_cell = cells.Bushy.create(species=species)
            self.post_cells.append(self.post_cell)
        for n in range(self.npre):
            for m in range(self.npost):
                synapse = self.pre_cells[n].connect(self.post_cells[m])
                self.synapse = synapse
                synapse.terminal.relsite.Dep_Flag = False

        # make variations in the postsynaptic cells
        varsg = [0.5, 0.75, 1.0, 1.5, 2.0]
        for i, m in enumerate(range(self.npost)):
            refgbar_klt = self.post_cells[m].soma().klt.gbar
            refgbar_ih = self.post_cells[m].soma().ihvcn.gbar
            self.post_cells[m].soma().klt.gbar = refgbar_klt * varsg[i]
            self.post_cells[m].soma().ihvcn.gbar = refgbar_ih * varsg[i]
示例#4
0
    def runSound(self, parallelize=False):
        self.civ = {}
        self.iiv = []
        if not parallelize:
            pass

        if parallelize:
            nworker = 16
            varsg = np.linspace(
                0.25, 2.0,
                int((2.0 - 0.25) / 0.25) + 1
            )  #[0.5, 0.75, 1.0, 1.5, 2.0]  # covary Ih and gklt in constant ratio
            self.npost = len(varsg)
            nrep = 25
            tasks = range(self.npost)
            results = [None] * len(tasks)
            ivc = [None] * len(tasks)
            gklts = np.zeros(len(varsg))
            ghs = np.zeros(len(varsg))
            start = time.time()
            seed = 0
            cf = 16000.
            f0 = 16000.
            rundur = 0.25  # seconds
            pipdur = 0.1  # seconds
            dbspl = 50.
            fmod = 40.
            dmod = 0.
            stimulus = 'tone'
            #            with mp.Parallelize(enumerate(tasks), results=results, workers=nworker, progressDialog='processing in parallel..') as tasker:
            with mp.Parallelize(enumerate(tasks),
                                results=results,
                                workers=nworker) as tasker:
                for i, x in tasker:
                    post_cell = cells.Bushy.create(species=species)
                    h.celsius = 34
                    self.temp = h.celsius
                    refgbar_klt = post_cell.soma().klt.gbar
                    refgbar_ih = post_cell.soma().ihvcn.gbar
                    gklts[i] = refgbar_klt * varsg[i]
                    ghs[i] = refgbar_ih * varsg[i]
                    post_cell.soma().klt.gbar = gklts[i]
                    post_cell.soma().ihvcn.gbar = ghs[i]
                    post_cell.initial_mechanisms = None  # forget the mechanisms we set up initially
                    post_cell.save_all_mechs(
                    )  # and save new ones because we are explicitely varying them
                    self.make_stimulus(stimulus=stimulus,
                                       cf=cf,
                                       f0=f0,
                                       rundur=rundur,
                                       pipdur=pipdur,
                                       dbspl=50.,
                                       simulator=None,
                                       fmod=fmod,
                                       dmod=dmod)

                    pre_cells = []
                    synapses = []
                    for n in range(self.npre):
                        pre_cells.append(cells.DummySGC(cf=cf, sr=2))
                        synapses.append(pre_cells[n].connect(post_cell,
                                                             type=synapseType))
                    v_reps = []
                    i_reps = []
                    p_reps = []  # pre spike on 0'th sgc
                    for j in range(nrep):
                        for prec in range(len(pre_cells)):
                            pre_cells[prec].set_sound_stim(self.stim,
                                                           seed=seed)
                            seed += 1
                            # 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
                        #
                        # Run simulation
                        #
                        post_cell.vm0 = None
                        post_cell.cell_initialize()
                        # set starting voltage...
                        post_cell.soma(0.5).v = post_cell.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')
                        self['t'] = h._ref_t
                        # set up recordings
                        self['v_post%02d' % j] = post_cell.soma(0.5)._ref_v
                        h.finitialize()  # init and instantiate recordings
                        print 'running %d' % i
                        h.t = 0.
                        h.tstop = rundur * 1000.  # rundur is in seconds.
                        post_cell.check_all_mechs(
                        )  # make sure no further changes were introduced before run.
                        h.batch_run(h.tstop, h.dt, 'v.dat')
                        v_reps.append(self['v_post%02d' % j])
                        i_reps.append(0. * self['v_post%02d' % j])
                        p_reps.append(pre_cells[0]._stvec.to_python())
                    tasker.results[i] = {
                        'v': v_reps,
                        'i': i_reps,
                        't': self['t'],
                        'pre': pre_cells[0]._stvec.to_python()
                    }
            print("\nParallel time: %d workers,  %0.2f sec" %
                  (nworker, time.time() - start))
            cell_info = {'gklt': gklts, 'gh': ghs}
            stim_info = {
                'nreps': nrep,
                'cf': cf,
                'f0': f0,
                'rundur': rundur,
                'pipdur': pipdur,
                'dbspl': dbspl,
                'fmod': fmod,
                'dmod': dmod
            }
            res = {'cells': cell_info, 'stim': stim_info, 'results': results}
            if runname is not None:
                f = open(runname, 'w')
                pickle.dump(res, f)
                f.close()
    def run(self, temp=34.0, dt=0.025, seed=575982035, stimulus='tone', species='mouse'):
        assert stimulus in ['tone', 'SAM', 'clicks']  # cases available
        if self.cell == 'bushy':
            postCell = cells.Bushy.create(species=species)
        elif self.cell == 'tstellate':
            postCell = cells.TStellate.create(species=species)
        elif self.cell == 'octopus':
            postCell = cells.Octopus.create(species=species)
        elif self.cell == 'dstellate':
            postCell = cells.DStellate.create(species=species)
        else:
            raise ValueError('cell %s is not yet implemented for phaselocking' % self.cell)
        self.post_cell = postCell
        self.stimulus = stimulus
        self.run_duration = 1.  # in seconds
        self.pip_duration = 0.8  # in seconds
        self.pip_start = [0.02]  # in seconds
        self.Fs = 100e3  # in Hz
        self.f0 = 4000.  # stimulus in Hz
        self.cf = 4000.  # SGCs in Hz
        self.fMod = 100.  # mod freq, Hz
        self.dMod = 50.  # % mod depth, Hz
        self.dbspl = 60.
        if self.stimulus == 'SAM':
            self.stim = sound.SAMTone(rate=self.Fs, duration=self.run_duration, f0=self.f0, 
                          fmod=self.fMod, dmod=self.dMod, dbspl=self.dbspl,
                          ramp_duration=2.5e-3, pip_duration=self.pip_duration,
                          pip_start=self.pip_start)
        if self.stimulus == 'tone':
            self.f0 = 1000.
            self.cf = 1000.
            self.stim = sound.TonePip(rate=self.Fs, duration=self.run_duration, f0=self.f0, dbspl=self.dbspl,
                          ramp_duration=2.5e-3, pip_duration=self.pip_duration,
                          pip_start=self.pip_start)

        if self.stimulus == 'clicks':
            self.click_rate = 0.020  # msec
            self.stim = sound.ClickTrain(rate=self.Fs, duration=self.run_duration,
                        f0=self.f0, dbspl=self.dbspl, click_start=0.010, click_duration=100.e-6,
                        click_interval=self.click_rate, nclicks=int((self.run_duration-0.01)/self.click_rate),
                        ramp_duration=2.5e-3)
        
        n_sgc = data.get('convergence', species=species, post_type=postCell.type, pre_type='sgc')[0]
        self.n_sgc = int(np.round(n_sgc))

        self.pre_cells = []
        self.synapses = []
        j = 0
        for k in range(self.n_sgc):
            seed = seed + k
            preCell = cells.DummySGC(cf=self.cf, sr=2)
            synapse = preCell.connect(postCell)
            for i in range(synapse.terminal.n_rzones):
                self['xmtr%03d'%j] = synapse.terminal.relsite._ref_XMTR[i]
                j = j + 1
            synapse.terminal.relsite.Dep_Flag = False
            preCell.set_sound_stim(self.stim, seed=seed)
            self.pre_cells.append(preCell)
            self.synapses.append(synapse)
        
        self['vm'] = postCell.soma(0.5)._ref_v
        #self['prevm'] = preCell.soma(0.5)._ref_v
        self['t'] = h._ref_t
        postCell.cell_initialize()
        h.tstop = 1e3*self.run_duration # duration of a run
        h.celsius = temp
        h.dt = dt
        
        self.custom_init()
        h.run()
示例#6
0
def runTrial(cell, info):
    """
    info is a dict
    """
    if cell == 'bushy':
        post_cell = cells.Bushy.create(species=species)
    elif cell == 'tstellate':
        post_cell = cells.TStellate.create(species=species)
    elif cell == 'octopus':
        post_cell = cells.Octopus.create(species=species)
    elif cell == 'dstellate':
        post_cell = cells.DStellate.create(species=species)
    elif cell == 'tuberculoventral':
        post_cell = cells.DStellate.create(species=species)
    elif cell == 'pyramidal':
        post_cell = cells.DStellate.create(species=species)
    else:
        raise ValueError('cell %s is not yet implemented for PSTH testing' %
                         self.cell)
    pre_cells = []
    synapses = []
    j = 0
    xmtr = {}
    for nsgc, sgc in enumerate(range(info['n_sgc'])):
        pre_cells.append(cells.DummySGC(cf=info['cf'], sr=info['sr']))
        if synapseType == 'simple':
            synapses.append(pre_cells[-1].connect(post_cell, type=synapseType))
            synapses[-1].terminal.netcon.weight[0] = info['gmax']
        elif synapseType == 'multisite':
            synapses.append(pre_cells[-1].connect(post_cell,
                                                  post_opts={
                                                      'AMPAScale': 1.0,
                                                      'NMDAScale': 1.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
        pre_cells[-1].set_sound_stim(info['stim'],
                                     seed=info['seed'] + nsgc,
                                     simulator=info['simulator'])
    Vm = h.Vector()
    Vm.record(post_cell.soma(0.5)._ref_v)
    rtime = h.Vector()
    rtime.record(h._ref_t)
    h.tstop = 1e3 * info['run_duration']  # duration of a run
    h.celsius = info['temp']
    h.dt = info['dt']
    post_cell.cell_initialize()
    info['init']()
    h.t = 0.
    h.run()
    return {
        'time': np.array(rtime),
        'vm': Vm.to_python(),
        'xmtr': xmtr,
        'pre_cells': pre_cells,
        'post_cell': post_cell,
        'synapses': synapses
    }
示例#7
0
    def run(self, temp=38.0, dt=0.025, seed=575982035, simulator=None):
        ears = {'left': [500., 502, 498], 'right': [500., 502., 498]}
        
        self.beatfreq = 0.
        self.f0 = 500.
        f0 = {'left': self.f0, 'right': self.f0+self.beatfreq}
        nsgc = len(ears.keys())
        sgcCell = {}
        bushyCell = {}
        msoCell = {}
        synapse = {}
        self.stim = {}
        self.ears = ears
        self.stimdur = 0.2
        self.stimdelay = 0.02
        self.rundur = self.stimdelay + self.stimdur + 0.02

        for i, ear in enumerate(ears.keys()):
            nsgc = len(ears[ear])  # how many sgcs are specified for this ear
            sgcCell[ear] = [cells.DummySGC(cf=ears[ear][k], sr=2) for k in range(nsgc)]
            bushyCell[ear] = [cells.Bushy.create(temperature=temp)]
            synapse[ear] = [sgcCell[ear][k].connect(bushyCell[ear][0]) for k in range(nsgc)]
            self.stim[ear] = [sound.TonePip(rate=100e3, duration=self.stimdur+0.1, f0=f0[ear], dbspl=80,
                                  ramp_duration=2.5e-3, pip_duration=self.stimdur, 
                                  pip_start=[self.stimdelay]) for k in range(nsgc)]
            for k in range(len(self.stim[ear])):
                sgcCell[ear][k].set_sound_stim(self.stim[ear][k], seed=seed + i*seed + k, simulator=simulator)
            self['vm_bu_%s' % ear] = bushyCell[ear][0].soma(0.5)._ref_v
            for k in range(30):
                self['xmtr%d_%s'%(k, ear)] = synapse[ear][0].terminal.relsite._ref_XMTR[k]
            for k in range(len(synapse[ear])):
                synapse[ear][k].terminal.relsite.Dep_Flag = False  # turn off depression

        msoCell = cells.MSO.create(temperature=temp)  # one target MSO cell
        msosyn = {}
        for ear in ears:
            msosyn[ear] = bushyCell[ear][0].connect(msoCell)
        self.sgc_cells = sgcCell
        self.bushy_cells = bushyCell
        self.synapses = synapse
        self.msyns = msosyn
        self.msoCell = msoCell
        self.all_cells = []  # hold all "real" cells (DummySGC does not have mechanisms)
        for ear in ears.keys():
            self.all_cells.append([c for c in self.bushy_cells[ear]])
        self.all_cells.append([self.msoCell])
        
        self['vm_mso'] = self.msoCell.soma(0.5)._ref_v
        for k, ear in enumerate(ears.keys()):
            for i in range(30):
                self['mso_xmtr%d_%s'%(i, ear)] = msosyn[ear].terminal.relsite._ref_XMTR[i]
            msosyn[ear].terminal.relsite.Dep_Flag = False  # turn off depression

        self['t'] = h._ref_t
        
        h.tstop = self.rundur*1e3 # duration of a run
        h.celsius = temp
        h.dt = dt
        
        custom_init()
        # confirm that all cells are ok
        for cg in self.all_cells:
            for c in cg:
                c.check_all_mechs()
        while h.t < h.tstop:
            h.fadvance()