def make_syaptic_stimuli(cell, input_idx):
    # Define synapse parameters
    synapse_parameters = {
        'idx': input_idx,
        'e': 0.,                   # reversal potential
        'syntype': 'ExpSyn',       # synapse type
        'tau': 10.,                # syn. time constant
        'weight': 0.0001,            # syn. weight
        'record_current': True,
    }
    synapse = LFPy.Synapse(cell, **synapse_parameters)
    synapse.set_spike_times(np.array([80.]))

    # Define synapse parameters
    synapse_parameters = {
        'idx': input_idx,
        'e': -100.,                   # reversal potential
        'syntype': 'ExpSyn',       # synapse type
        'tau': 10.,                # syn. time constant
        'weight': 0.0001,            # syn. weight
        'record_current': True,
    }
    synapse = LFPy.Synapse(cell, **synapse_parameters)
    synapse.set_spike_times(np.array([5.]))


    return cell, synapse
Beispiel #2
0
    def test_Synapse_01(self):
        cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                                 'ball_and_sticks.hoc'))
        syn0 = LFPy.Synapse(cell=cell,
                            idx=0,
                            syntype='ExpSynI',
                            weight=1.,
                            tau=5.,
                            record_current=True,
                            record_potential=True)
        syn0.set_spike_times(np.array([10.]))

        syn1 = LFPy.Synapse(cell=cell,
                            idx=1,
                            syntype='ExpSynI',
                            weight=1.,
                            tau=5.,
                            record_current=True,
                            record_potential=False)
        syn1.set_spike_times(np.array([20.]))

        syn2 = LFPy.Synapse(cell=cell,
                            idx=2,
                            syntype='ExpSynI',
                            weight=1.,
                            tau=5.,
                            record_current=False,
                            record_potential=True)
        syn2.set_spike_times(np.array([30.]))

        syn3 = LFPy.Synapse(cell=cell,
                            idx=3,
                            syntype='ExpSynI',
                            weight=1.,
                            tau=5.,
                            record_current=False,
                            record_potential=False)
        syn3.set_spike_times(np.array([40.]))

        cell.simulate()

        i = np.zeros(cell.tvec.size)
        i[cell.tvec > 10.] = -np.exp(-np.arange(
            (cell.tvec > 10.).sum()) * cell.dt / 5.)

        np.testing.assert_allclose(i, syn0.i, rtol=1E-1)
        np.testing.assert_equal(cell.somav, syn0.v)

        self.assertTrue(hasattr(syn1, 'i'))
        i = np.zeros(cell.tvec.size)
        i[cell.tvec > 20.] = -np.exp(-np.arange(
            (cell.tvec > 20.).sum()) * cell.dt / 5.)
        self.assertFalse(hasattr(syn1, 'v'))
        np.testing.assert_allclose(i, syn1.i, rtol=1E-1)

        self.assertFalse(hasattr(syn2, 'i'))
        self.assertTrue(hasattr(syn2, 'v'))

        self.assertFalse(hasattr(syn3, 'i'))
        self.assertFalse(hasattr(syn3, 'v'))
Beispiel #3
0
    def createSynapse(self, cell, location, distal, spikes):

        if (distal == True):
            syn = LFPy.Synapse(cell, idx=location, **self.DISTAL_SYN)
        else:
            syn = LFPy.Synapse(cell, idx=location, **self.PROXIMAL_SYN)

        syn.set_spike_times(spikes)

        cell._loadspikes()

        return syn
    def createSynapse(self, cell, location, locked, spikes, delay=1.0):

        if (locked == True):
            syn = LFPy.Synapse(cell, idx=location, **self.LOCKED_SYN)
            syn.set_spike_times(spikes + delay)
        else:
            syn = LFPy.Synapse(cell, idx=location, **self.RGC_SYN)
            syn.set_spike_times(spikes)

        cell._loadspikes()

        return syn
Beispiel #5
0
    def test_cell_simulate_current_dipole_moment_02(self):
        stickParams = {
            'morphology': os.path.join(LFPy.__path__[0], 'test', 'stick.hoc'),
            'cm': 1,
            'Ra': 150,
            'v_init': -65,
            'passive': True,
            'passive_parameters': {
                'g_pas': 1. / 30000,
                'e_pas': -65
            },
            'tstart': -100,
            'tstop': 100,
            'dt': 2**-4,
            'nsegs_method': 'lambda_f',
            'lambda_f': 100,
        }

        stimParams = {
            'e': 0,  # reversal potential
            'syntype': 'Exp2Syn',  # synapse type
            'tau1': 0.1,  # syn. time constant
            'tau2': 2.,  # syn. time constant
            'weight': 0.01,
        }

        for idx in range(31):  #31 segments
            if idx != 15:  # no net dipole moment because of stick symmetry
                stick = LFPy.Cell(**stickParams)
                synapse = LFPy.Synapse(stick, idx=idx, **stimParams)
                synapse.set_spike_times(np.array([10., 20., 30., 40., 50.]))
                stick.simulate(rec_imem=True, rec_current_dipole_moment=True)
                p = np.dot(stick.imem.T, np.c_[stick.xmid, stick.ymid,
                                               stick.zmid])
                np.testing.assert_allclose(p, stick.current_dipole_moment)
Beispiel #6
0
def insert_synapses(synparams, section, n, heights, cell):
    soma_h = heights['soma']
    if section == 'bas':
        sec = 'dend'
        maxim = heights['basal_max']
        minim = heights['min']
    if section == 'apic':
        sec = 'apic'
        maxim = heights['max']
        minim = heights['apical_min']
    if section == 'allsec':
        sec = 'allsec'
        maxim = heights['max']
        minim = heights['min']
    if section == 'soma':
        sec = 'soma'
        maxim = 0
        minim = 0
    '''find n compartments to insert synapses onto'''
    idx = cell.get_rand_idx_area_norm(section=sec,
                                      nidx=n,
                                      z_min=soma_h + minim,
                                      z_max=soma_h + maxim)
    # Insert synapses in an iterative fashion
    for i in idx:
        synparams.update({'idx': int(i)})
        #     # Create synapse(s) and setting times using the Synapse class in LFPy
        s = LFPy.Synapse(cell, **synparams)
        s.set_spike_times(np.array([np.random.normal(loc=25, scale=1)]))
Beispiel #7
0
    def test_Network_04(self):
        cellParameters = dict(
            morphology=os.path.join(LFPy.__path__[0], 'test',
                                    'ball_and_sticks_w_lists.hoc'),
            templatefile=os.path.join(LFPy.__path__[0], 'test',
                                      'ball_and_stick_template.hoc'),
            templatename='ball_and_stick_template',
            templateargs=None,
            passive=True,
            dt=2**-3,
            tstop=100,
            delete_sections=False,
        )

        synapseParameters = dict(idx=0,
                                 syntype='Exp2Syn',
                                 weight=0.002,
                                 tau1=0.1,
                                 tau2=0.1,
                                 e=0)

        populationParameters = dict(
            CWD=None,
            CELLPATH=None,
            Cell=LFPy.NetworkCell,
            cell_args=cellParameters,
            pop_args=dict(radius=100, loc=0., scale=20.),
            rotation_args=dict(x=0, y=0),
            POP_SIZE=1,
            name='test',
        )
        networkParameters = dict(dt=2**-3,
                                 tstart=0.,
                                 tstop=100.,
                                 v_init=-70.,
                                 celsius=6.3,
                                 OUTPUTPATH='tmp_testNetworkPopulation')
        # set up
        network = LFPy.Network(**networkParameters)
        network.create_population(**populationParameters)

        cell = network.populations['test'].cells[0]

        # create synapses
        synlist = []
        numsynapses = 2
        for i in range(numsynapses):
            synlist.append(LFPy.Synapse(cell=cell, **synapseParameters))
            synlist[-1].set_spike_times(np.array([10 + (i * 10)]))

        network.simulate()

        # test that the input results in the correct amount of PSPs
        np.testing.assert_equal(
            ss.argrelextrema(cell.somav, np.greater)[0].size, numsynapses)

        # clean up
        network.pc.gid_clear()
        os.system('rm -r tmp_testNetworkPopulation')
        neuron.h('forall delete_section()')
Beispiel #8
0
def simulate(cell_parameters, synapse_parameters, grid_electrode_parameters, syninds, x_rot=0, y_rot=0, z_rot=0, active=False):
    """set synapse location. simulate cell, synapse and electrodes for input synapse location"""

    # create cell with parameters in dictionary
    if not active:
        cell = LFPy.Cell(**cell_parameters)
    else:
        cell = LFPy.TemplateCell(**cell_parameters)

    # rotate cell
    cell.set_rotation(x=x_rot)
    cell.set_rotation(y=y_rot)
    cell.set_rotation(z=z_rot)

    # insert synapses
    if type(syninds) == int:
        syninds = [syninds]
    for idx in syninds:
        synapse_parameters['idx'] = idx
        synapse = LFPy.Synapse(cell, **synapse_parameters)
        synapse.set_spike_times(np.array([20.]))

    # simulate cell
    cell.simulate(rec_imem = True,
                  rec_vmem = True,
                  rec_current_dipole_moment=True)

    #create grid electrodes
    grid_electrode = LFPy.RecExtElectrode(cell, **grid_electrode_parameters)
    grid_electrode.calc_lfp()

    return cell, synapse, grid_electrode
Beispiel #9
0
def cell_thread(task_queue, done_queue):
    '''thread function for simulation of single neuron process'''
    for n in iter(task_queue.get, 'STOP'):
        print 'Cell number %s out of %d.' % (n, pop_params['n'] - 1)
        cell = LFPy.Cell(**cellparams)

        cell.set_pos(**soma_pos[withsyn_i[n]])
        cell.set_rotation(**rotation[withsyn_i[n]])
        cell.color = 'g'

        #synapses
        e_synparams = e_synparams_init.copy()
        for idx in allidx_e[n]:
            e_synparams = e_synparams_init.copy()
            e_synparams.update({'idx': int(idx), 'color': 'r'})
            e_spiketimes = [pl.array([spiketime])]

            s_e = LFPy.Synapse(cell, **e_synparams)
            s_e.set_spike_times(e_spiketimes[0])

        cell.simulate(**simparams)

        cell.strip_hoc_objects()

        done_queue.put([e_synparams, cell])
Beispiel #10
0
def cell_w_synapse_from_sections(morphology):
    '''
    Make cell and synapse objects, set spike, simulate and return cell
    '''
    cellParams = {
        'morphology': morphology,
        'cm': 1,
        'Ra': 150,
        'v_init': -65,
        'passive': True,
        'passive_parameters': {
            'g_pas': 1. / 30000,
            'e_pas': -65
        },
        'dt': 2**-6,
        'tstart': -50,
        'tstop': 50,
        'delete_sections': False
    }

    synapse_parameters = {
        'e': 0.,
        'syntype': 'ExpSyn',
        'tau': 5.,
        'weight': .001,
        'record_current': True,
        'idx': 1
    }

    cell = LFPy.Cell(**cellParams)
    synapse = LFPy.Synapse(cell, **synapse_parameters)
    synapse.set_spike_times(np.array([1.]))
    cell.simulate(rec_current_dipole_moment=True, rec_vmem=True)
    return cell
Beispiel #11
0
 def cosine_current_injection(self, tstop=850):
     pre_syn_sptimes = self.stationary_poisson(nsyn=self.n_pre_syn,
                                               lambd=2,
                                               tstart=0,
                                               tstop=400)
     l = np.arange(self.n_pre_syn)
     pre_syn_pick = np.random.permutation(l)[0:self.n_synapses]
     self.synapse_parameters['weight'] = 0.05
     pars = {}
     for i_syn in range(self.n_synapses):
         syn_idx = int(self.cell.get_rand_idx_area_norm())
         spike_times = pre_syn_sptimes[pre_syn_pick[i_syn]]
         if syn_idx in pars:
             pars[syn_idx].extend(list(spike_times))
         else:
             pars[syn_idx] = list(spike_times)
     for syn_idx in pars:
         self.synapse_parameters.update({'idx': syn_idx})
         synapse = LFPy.Synapse(self.cell, **self.synapse_parameters)
         synapse.set_spike_times(np.array(pars[syn_idx]))
     self.point_process['dur'] = 1
     TimesStim = np.arange(tstop)
     stim = np.array(3.6e-1 * np.sin(2. * 3.141 * 6.5 * TimesStim / 1000.))
     for istim in range(tstop):
         self.point_process['amp'] = stim[istim]
         self.point_process['delay'] = istim
         stimulus = LFPy.StimIntElectrode(self.cell, **self.point_process)
Beispiel #12
0
 def distal_cosine_current_injection(self, tstop=850):
     pre_syn_sptimes = self.stationary_poisson(nsyn=self.n_pre_syn,
                                               lambd=2,
                                               tstart=0,
                                               tstop=400)
     l = np.arange(self.n_pre_syn)
     pre_syn_pick = np.random.permutation(l)[0:self.n_synapses]
     pars = {}
     for i_syn in range(self.n_synapses):
         syn_idx = int(self.cell.get_rand_idx_area_norm())
         spike_times = pre_syn_sptimes[pre_syn_pick[i_syn]]
         if syn_idx in pars:
             pars[syn_idx].extend(list(spike_times))
         else:
             pars[syn_idx] = list(spike_times)
     for syn_idx in pars:
         self.synapse_parameters.update({'idx': syn_idx})
         synapse = LFPy.Synapse(self.cell, **self.synapse_parameters)
         synapse.set_spike_times(np.array(pars[syn_idx]))
    
     TimesStim = np.arange(850)
     stim = np.array(3.6*np.sin(2.*3.141*6.5*TimesStim/1000.))
     all_idxs = self.cell.get_idx()
     
     for istim in range(tstop):
         pointprocess = {
             'idx' : max(all_idxs),
             'pptype': 'IClamp',
             'record_current' : True,
             'amp': stim[istim],
             'dur' : 1.,
             'delay': istim,
             }
         stimulus = LFPy.StimIntElectrode(self.cell, **pointprocess)
Beispiel #13
0
def return_cell():

    neuron.load_mechanisms("HallermannEtAl2012")
    # Define cell parameters
    cell_parameters = {          # various cell parameters,
        'morphology' : 'unmyelinated_axon_Hallermann.hoc', # Mainen&Sejnowski, 1996
        'v_init' : -80.,    # initial crossmembrane potential
        'passive' : False,   # switch off passive mechs
        'nsegs_method' : 'lambda_f',
        'lambda_f' : 1000.,
        'dt' : 2.**-7,   # [ms] dt's should be in powers of 2
        'tstart' : -200.,    # start time of simulation, recorders start at t=0
        'tstop' : 2.,   # stop simulation at 2 ms.
    }

    cell = LFPy.Cell(**cell_parameters)
    cell.set_pos(x=-np.max(cell.xmid) / 2, z=2.5)

    #  To induce a spike:
    synapseParameters = {
        'idx' : 0,               # insert synapse on index "0", the soma
        'e' : 0.,                # reversal potential of synapse
        'syntype' : 'Exp2Syn',   # conductance based double-exponential synapse
        'tau1' : 0.1,            # Time constant, decay
        'tau2' : 0.1,            # Time constant, decay
        'weight' : 0.004,         # Synaptic weight
        'record_current' : False, # Will enable synapse current recording
    }

    # attach synapse with parameters and input time
    synapse = LFPy.Synapse(cell, **synapseParameters)
    synapse.set_spike_times(np.array([0.1]))

    cell.simulate(rec_vmem=True, rec_imem=True)
    return cell
Beispiel #14
0
def insert_synapses(synparams, section, n, spTimesFun, args):
    '''find n compartments to insert synapses onto'''
    spk_times_save = []
    idx = cell.get_rand_idx_area_norm(section=section, nidx=n)

    mu_wgt = synparams['weight']
    #Insert synapses in an iterative fashion
    for i in idx:

        # make synaptic weights vary around the mean
        rand_wgt = numpy.random.normal(mu_wgt, mu_wgt / 10)
        synparams['weight'] = rand_wgt
        wgts.append(synparams['weight'])
        synparams.update({'idx': int(i)})

        # Some input spike train using the function call
        [spiketimes] = spTimesFun(**args)

        # Create synapse(s) and setting times using the Synapse class in LFPy
        s = LFPy.Synapse(cell, **synparams)
        s.set_spike_times(spiketimes)

        spk_times_save.append(spiketimes)

    return spk_times_save
Beispiel #15
0
def cell_thread_PSC(task_queue, done_queue):
    '''thread function for simulation of single neuron process'''
    for n in iter(task_queue.get, 'STOP'):
        print 'Cell number %s out of %d.' % (n, pop_params['n'] - 1)
        cell = LFPy.Cell(**cellparams)

        e_synparams = e_synparams_init.copy()
        for idx in allidx_e[n]:
            e_synparams = e_synparams_init.copy()
            e_synparams.update({'idx': int(idx), 'color': (0.8, 0.8, 0.8)})
            e_spiketimes = [pl.array([spiketime])]

            s_e = LFPy.Synapse(cell, **e_synparams)
            s_e.set_spike_times(e_spiketimes[0])

        e_synparams = e_synparams_init.copy()

        LFPy.StimIntElectrode(cell, **pointprocparams)

        cell.simulate(**simparams2)
        cell.tvec = pl.arange(
            -1, cellparams['timeres_python'] * len(cell.tvec) - 1,
            cellparams['timeres_python'])

        cell.strip_hoc_objects()

        done_queue.put(cell)
Beispiel #16
0
 def set_input_spiketrain(self, cell, cell_input_idxs, spike_trains, synapse_params):
     synapse_list = []
     for number, comp_idx in enumerate(cell_input_idxs):
         synapse_params.update({'idx': int(comp_idx)})
         s = LFPy.Synapse(cell, **synapse_params)
         s.set_spike_times(spike_trains[number])
         synapse_list.append(s)
     return synapse_list
Beispiel #17
0
    def test_Synapse_05(self):
        cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                                 'ball_and_sticks.hoc'))
        t0 = 10.
        t1 = 30.
        tau = 5.
        syn0 = LFPy.Synapse(cell=cell,
                            idx=0,
                            syntype='ExpSynI',
                            weight=1.,
                            tau=tau,
                            record_current=True,
                            record_potential=True)

        syn1 = LFPy.Synapse(cell=cell,
                            idx=0,
                            syntype='ExpSynI',
                            weight=1.,
                            tau=tau,
                            record_current=True,
                            record_potential=True)

        syn1.set_spike_times(np.array([t1]))
        syn0.set_spike_times_w_netstim(noise=0., start=t0 - 1,
                                       number=1)  # -1 to acct for delay

        cell.simulate()

        i0 = np.zeros(cell.tvec.size)
        i0[cell.tvec > t0] = -np.exp(-np.arange(
            (cell.tvec > t0).sum()) * cell.dt / tau)

        i1 = np.zeros(cell.tvec.size)
        i1[cell.tvec > t1] = -np.exp(-np.arange(
            (cell.tvec > t1).sum()) * cell.dt / tau)

        np.testing.assert_allclose(i0, syn0.i, rtol=1E-1)
        np.testing.assert_equal(cell.somav, syn0.v)

        np.testing.assert_allclose(i1, syn1.i, rtol=1E-1)
        np.testing.assert_equal(cell.somav, syn1.v)

        cell.__del__()
        '''for attr in cell.__dict__.keys():
Beispiel #18
0
    def y_shaped_symmetric_input(self):
        self.synapse_parameters['idx'] = 0
        pre_syn_sptimes = [np.array([5., 25., 60.]), np.array([5., 45., 60.])]
        syn_no = [65, 33]

        for i, i_syn in enumerate(syn_no):
            new_pars = self.synapse_parameters.copy()
            new_pars['idx'] = i_syn
            synapse = LFPy.Synapse(self.cell, **new_pars)
            synapse.set_spike_times(pre_syn_sptimes[i])
Beispiel #19
0
def insert_synapses(synparams, section, n, netstimParameters):
    '''find n compartments to insert synapses onto'''
    idx = cell.get_rand_idx_area_norm(section=section, nidx=n)

    #Insert synapses in an iterative fashion
    for i in idx:
        synparams.update({'idx' : int(i)})

        # Create synapse(s) and setting times using the Synapse class in LFPy
        s = LFPy.Synapse(cell, **synparams)
        s.set_spike_times_w_netstim(**netstimParameters)
Beispiel #20
0
def insert_synapses(synparams, cell, section, n, spTimesFun, args):
    ''' find n compartments to insert synapses onto '''
    idx = cell.get_rand_idx_area_norm(section=section, nidx=n)
    #Insert synapses in an iterative fashion
    for i in idx:
        synparams.update({'idx': int(i)})
        # Some input spike train using the function call
        spiketimes = spTimesFun(args[0], args[1], args[2], args[3], args[4])
        # Create synapse(s) and setting times using the Synapse class in LFPy
        s = LFPy.Synapse(cell, **synparams)
        s.set_spike_times(spiketimes)
def simulate_cell(index,morphologyPath,folderPath):
    # simulation parameters
    neuron.h.celsius = 24 # Celsius, experiment temperature
    upsideDown = True
    inputSign = 0 # 0 for excitatory input, -90 for inhibitory
    soma_z = 150
    passiveMechanism = True
    
    cell = make_cell(morphologyPath,soma_z,upsideDown)       
    cell = set_membrane_mechanism(cell, isPassive = passiveMechanism)
    
    elec_x, elec_y, elec_z = make_MEA(xStart=-600,xEnd=600,xResolution=30,
             yStart=-600,yEnd=600,yResolution=30,
             zStart=120,zEnd=150,zResolution=10)
    elec_params = {'slice_thickness': soma_z+np.max(cell.zend), # keep cell contact with the saline layer on the top
                   'elec_radius': 1.,
                   'elec_x': elec_x,
                   'elec_y': elec_y,
                   'elec_z': elec_z,
                   }
    MEA = Electrode(**elec_params)
    ext_sim_dict = {'use_line_source': False,
                    'n_elecs': MEA.num_elecs,
                    #'n_avrg_points': 100,
                    #'elec_radius': MEA.elec_radius,
                    'moi_steps': 20,
                    'elec_x': MEA.elec_x,
                    'elec_y': MEA.elec_y,
                    'elec_z': MEA.elec_z,
                    'slice_thickness': MEA.slice_thickness,
                    'include_elec': False,
                    'neural_input': '.',
                    }
    # insert the synapse
    synPos = get_syn_pos(cell)
    synIdx = cell.get_closest_idx(x=synPos[index,0], y=synPos[index,1], z=synPos[index,2],section='dend')    
    synapse_parameters = {
        'idx': synIdx,
        'e': inputSign, #  Change to -90 for inhibitory input, and 0 for excitatory
        'syntype': 'Exp2Syn',
        'tau1': 1.,
        'tau2': 1.,
        'weight': 0.005, # 0.005 for passive membrane
        'record_current': True,
    }
    synapse = LFPy.Synapse(cell, **synapse_parameters)
    synapse.set_spike_times(np.array([10.]))  # Set time(s) of synaptic input
        
    #print "Simulating cell"
    cell.simulate(rec_imem=True, rec_vmem=True, rec_isyn=True)   
    phi = make_mapping(cell, MEA, ext_sim_dict)
    phiProfile = average_phi_radically(phi,MEA,[synPos[index,0],synPos[index,1]],folderPath,rResolution=30)
    np.save(join(folderPath, 'phiProfile'+str(index)+'.npy'),phiProfile)
Beispiel #22
0
    def random_synaptic_input(self, lambd=2, tstart=0, tstop=70):

        self.synapse_parameters['idx'] = 0
        pre_syn_sptimes = self.stationary_poisson(self.n_pre_syn, lambd,
                                                  tstart, tstop)
        l = np.arange(self.n_pre_syn)
        self.pre_syn_pick = np.random.permutation(l)[0:self.n_synapses]

        for i_syn in range(self.n_synapses):
            syn_idx = int(self.cell.get_rand_idx_area_norm())
            self.synapse_parameters.update({'idx': syn_idx})
            synapse = LFPy.Synapse(self.cell, **self.synapse_parameters)

            synapse.set_spike_times(pre_syn_sptimes[self.pre_syn_pick[i_syn]])
Beispiel #23
0
def make_synapse(cell, weight, input_idx):

    input_spike_train = np.array([10.])
    synapse_parameters = {
        'idx': input_idx,
        'e': 0.,
        'syntype': 'ExpSyn',
        'tau': 10.,
        'weight': weight,
        'record_current': True,
    }
    synapse = LFPy.Synapse(cell, **synapse_parameters)
    synapse.set_spike_times(input_spike_train)
    return cell, synapse
Beispiel #24
0
def make_synapse(cell, weight, input_idx, input_spike_train, e=0.,
                 syntype='Exp2Syn'):
    synapse_parameters = {
        'idx': input_idx,
        'e': e,
        'syntype': syntype,
        'tau1': 1.,                   #Time constant, rise
        'tau2': 3., #5                #Time constant, decay
        'weight': weight,
        'record_current': False,
    }

    synapse = LFPy.Synapse(cell, **synapse_parameters)
    synapse.set_spike_times(np.array([input_spike_train]))
    return cell, synapse
Beispiel #25
0
def simulate(cell, synapse_parameters, synidx, input_time=20.):
    """set synapse location. simulate cell, synapse and electrodes for input synapse location"""

    for idx in synidx:
        synapse_parameters['idx'] = idx  #
        # create synapse with parameters in dictionary
        synapse = LFPy.Synapse(cell, **synapse_parameters)
        synapse.set_spike_times(np.array([input_time]))

    cell.simulate(rec_imem=True, rec_vmem=True, rec_current_dipole_moment=True)

    #create grid electrodes
    electrode_array = LFPy.RecExtElectrode(cell, **electrodeParams)
    electrode_array.calc_lfp()

    return cell, synapse, electrode_array
Beispiel #26
0
def cell_w_synapse_from_sections_w_electrode(morphology, electrode_locs):
    '''
    Make cell and synapse objects, set spike, simulate and return cell
    '''
    cellParams = {
        'morphology': morphology,
        'cm': 1,
        'Ra': 150,
        'v_init': -65,
        'passive': True,
        'passive_parameters': {
            'g_pas': 1. / 30000,
            'e_pas': -65
        },
        'dt': 2**-6,
        'tstart': -50,
        'tstop': 50,
        'delete_sections': False
    }

    electrodeParams = {
        'sigma': 0.3,
        'x': electrode_locs[:, 0],
        'y': electrode_locs[:, 1],
        'z': electrode_locs[:, 2],
    }
    cell = LFPy.Cell(**cellParams)
    electrode = LFPy.RecExtElectrode(cell, **electrodeParams)

    synapse_parameters = {
        'e': 0.,
        'syntype': 'ExpSyn',
        'tau': 5.,
        'weight': .1,
        'record_current': True,
        'idx': cell.totnsegs - 1
    }

    synapse = LFPy.Synapse(cell, **synapse_parameters)
    synapse.set_spike_times(np.array([1.]))
    cell.simulate(electrode=[electrode],
                  rec_current_dipole_moment=True,
                  rec_vmem=True)
    return cell, electrode
Beispiel #27
0
def insert_synapses(cell, synparams, section, n, spTimesFun, args, z_min=-1e9, z_max=1e9):
    '''find n compartments to insert synapses onto'''
    idx = cell.get_rand_idx_area_norm(section=section, nidx=n, z_min=z_min, z_max=z_max)
    # idx = cell.get_rand_idx_area_and_distribution_norm(section=section,
    #                                    funargs=dict(loc=500, scale=150),
    #                                        nidx=n, z_min=z_min, z_max=z_max)
    synapses = []
    #Insert synapses in an iterative fashion
    for i in idx:
        synparams.update({'idx' : int(i)})

        # Some input spike train using the function call
        [spiketimes] = spTimesFun(**args)

        # Create synapse(s) and setting times using the Synapse class in LFPy
        s = LFPy.Synapse(cell, **synparams)
        s.set_spike_times(np.array([spiketimes]))
        synapses.append(s)
    return synapses
Beispiel #28
0
    def test_Synapse_00(self):
        cell = LFPy.Cell(morphology=os.path.join(LFPy.__path__[0], 'test',
                                                 'ball_and_sticks.hoc'))
        syn = LFPy.Synapse(cell=cell,
                           idx=0,
                           syntype='ExpSynI',
                           weight=1.,
                           tau=5.,
                           record_current=True,
                           record_potential=True)
        syn.set_spike_times(np.array([10.]))
        cell.simulate()

        i = np.zeros(cell.tvec.size)
        i[cell.tvec > 10.] = -np.exp(-np.arange(
            (cell.tvec > 10.).sum()) * cell.dt / 5.)

        np.testing.assert_allclose(i, syn.i, rtol=1E-1)
        np.testing.assert_equal(cell.somav, syn.v)
Beispiel #29
0
def insert_synapses(centerpos, radius, dryrun, synparams, section, n,
                    spTimesFun, args):
    if section is None:
        idx = cell.get_rand_idx_area_norm(nidx=n)
    else:
        idx = cell.get_rand_idx_area_norm(nidx=n, section=section)

    inserted = 0
    for i in idx:
        if (cell.xmid[i] -
                centerpos[0])**2 + (cell.ymid[i] - centerpos[1])**2 + (
                    cell.zmid[i] - centerpos[2])**2 <= radius**2:
            inserted += 1
            if not dryrun:
                synparams.update({'idx': int(i)})
                spiketimes = spTimesFun(args[0], args[1], args[2], args[3],
                                        args[4])
                s = LFPy.Synapse(cell, **synparams)
                s.set_spike_times(spiketimes)
    return inserted
Beispiel #30
0
def run_sim(morphology='patdemo/cells/j4a.hoc',
            cell_rotation=dict(x=4.99, y=-4.33, z=3.14),
            closest_idx=dict(x=-200., y=0., z=800.)):
    '''set up simple cell simulation with LFPs in the plane'''

    # Create cell
    cell = LFPy.Cell(morphology=morphology, **cell_parameters)
    # Align cell
    cell.set_rotation(**cell_rotation)
    
    # Define synapse parameters
    synapse_parameters = {
        'idx' : cell.get_closest_idx(**closest_idx),
        'e' : 0.,                   # reversal potential
        'syntype' : 'ExpSynI',       # synapse type
        'tau' : 0.5,                 # synaptic time constant
        'weight' : 0.0878,            # synaptic weight
        'record_current' : True,    # record synapse current
    }
    
    # Create synapse and set time of synaptic input
    synapse = LFPy.Synapse(cell, **synapse_parameters)
    synapse.set_spike_times(np.array([1.]))

    
    # Create electrode object
    
    # Run simulation, electrode object argument in cell.simulate
    print "running simulation..."
    cell.simulate(rec_imem=True,rec_isyn=True)
    
    grid_electrode = LFPy.RecExtElectrode(cell,**grid_electrode_parameters)
    point_electrode = LFPy.RecExtElectrode(cell,**point_electrode_parameters)
    
    grid_electrode.calc_lfp()
    point_electrode.calc_lfp()
    
    print "done"
    
    return cell, synapse, grid_electrode, point_electrode