Example #1
0
def get_cell(output_folder, do_simulation=True):
    def insert_synapses(synparams, section, n, spTimesFun, args):
        # find n compartments to insert synapses onto
        # idx = [clamp_1['idx'], clamp_2['idx']]#
        idx = cell.get_rand_idx_area_norm(section=section, nidx=n)
        # spiketimes = [np.array([15, 25]), np.array([16,26])]
        # Insert synapses in an iterative fashion
        for count, index in enumerate(idx):
            synparams.update({"idx": int(index)})
            s = LFPy.Synapse(cell, **synparams)
            spiketimes = spTimesFun(args[0], args[1], args[2], args[3])
            s.set_spike_times(spiketimes)
            # s.set_spike_times(spiketimes[count])

    cell = LFPy.Cell(**cellParameters)
    cell.set_rotation(x=-pl.pi / 2)
    cell.set_rotation(y=pl.pi / 2)
    # find_sec_from_comp(cell, 756)
    cell.set_pos(xpos=-25)
    # cell.set_rotation(x = pl.pi/2)
    # cell.set_rotation(y = -pl.pi/2)
    # cell.set_rotation(y = pl.pi/10)
    cell.set_rotation(z=-pl.pi / 165)

    # find_sec_from_comp(cell, 644)
    # find_sec_from_comp(cell, 801)
    # plot_sec(cell, 'apic[76]')
    # sys.exit()
    def insert_glutamate_stim(cell, section="apic[63]", site=0.5):
        gmaxS = 10
        neuron.h("access %s" % section)
        glut_syn = neuron.h.glutamate(site)
        glut_syn.delay = 50
        glut_syn.ntar = 1.3
        glut_syn.gmax = gmaxS
        glut_syn.Nspike = 3
        glut_syn.Tspike = 20
        return glut_syn

    def insert_many_glutamate_stim(cell, nSyn=500):
        import random

        gmaxS = 1
        syn_array = []
        i = 0
        while i < nSyn:
            apic_sec = random.randint(0, 108)
            section = "apic[%d]" % apic_sec
            comps = cell.get_idx_section(section)
            idx = random.choice(comps)
            if cell.ymid[idx] > 600:
                # syns_positions.append(
                neuron.h("access %s" % section)
                syn_array.append(neuron.h.glutamate(random.uniform(0.1, 0.95)))
                syn_array[-1].delay = 50
                syn_array[-1].ntar = 1
                syn_array[-1].gmax = gmaxS
                syn_array[-1].Nspike = 3
                syn_array[-1].Tspike = 20
                i += 1
        return syn_array  # , syns_positions

    if do_simulation:
        os.system("cp %s %s" % (sys.argv[0], output_folder))
        np.save(output_folder + "x_start.npy", cell.xstart)
        np.save(output_folder + "y_start.npy", cell.ystart)
        np.save(output_folder + "z_start.npy", cell.zstart)
        np.save(output_folder + "x_end.npy", cell.xend)
        np.save(output_folder + "y_end.npy", cell.yend)
        np.save(output_folder + "z_end.npy", cell.zend)
        np.save(output_folder + "diam.npy", cell.diam)

        syn1 = insert_glutamate_stim(cell, section=find_sec_from_comp(cell, 615), site=0.5)
        syn2 = insert_glutamate_stim(cell, section=find_sec_from_comp(cell, 646), site=0.59)
        syn3 = insert_glutamate_stim(cell, section=find_sec_from_comp(cell, 671), site=0.5)
        syn4 = insert_glutamate_stim(cell, section=find_sec_from_comp(cell, 623), site=0.2)
        syn5 = insert_glutamate_stim(cell, section=find_sec_from_comp(cell, 628), site=0.9)
        syn6 = insert_glutamate_stim(cell, section=find_sec_from_comp(cell, 657), site=0.8)
        # currentClamp_1 = LFPy.StimIntElectrode(cell, **clamp_1)
        # currentClamp_2 = LFPy.StimIntElectrode(cell, **clamp_2)
        # insert_synapses(synapseParameters_AMPA, **insert_synapses_AMPA_args)
        # insert_synapses(synapseParameters_NMDA, **insert_synapses_NMDA_args)
        # insert_synapses(synapseParameters_GABA_A, **insert_synapses_GABA_A_args)
        # syn_array = insert_many_glutamate_stim(cell, nSyn = 100)
        # neuron.h('objref n_vec')
        # neuron.h('n_vec = new Vector()')
        # neuron.h('n_vec.record(&soma.m_hh(0.5))')

        cell.simulate(**simulationParameters)
        np.save(output_folder + "imem.npy", cell.imem)
        np.save(output_folder + "vmem.npy", cell.vmem)
        np.save(output_folder + "tvec.npy", cell.tvec)
        plotstuff(cell, clamp_1, clamp_2)
        os.system("cp %s %s" % ("example_fig.png", output_folder))
    else:
        cell.vmem = np.load(output_folder + "vmem.npy")
        cell.imem = np.load(output_folder + "imem.npy")
        cell.tvec = np.load(output_folder + "tvec.npy")
    return cell
Example #2
0
def get_cell(output_folder, do_simulation = True):
    def insert_synapses(synparams, name, section, n, spTimesFun, args):
        #find n compartments to insert synapses onto
        #idx = [clamp_1['idx'], clamp_2['idx']]#
        idx = cell.get_rand_idx_area_norm(section=section, nidx=n)
        #if name == 'NMDA':
        #    idx_tuft = []
       #     for i in idx:
       #         if cell.zmid[i] > 500:
       #             idx_tuft.append(i)
       #     idx = idx_tuft
        #spiketimes = [np.array([15, 25]), np.array([16,26])]
        #Insert synapses in an iterative fashion
        for count, i in enumerate(idx):
            synparams.update({'idx' : int(i)})
            s = LFPy.Synapse(cell,**synparams)
            spiketimes = spTimesFun(args[0], args[1], args[2], args[3])
            s.set_spike_times(spiketimes)
            #s.set_spike_times(spiketimes[count])

    def insert_glutamate_stim(cell, section = 'apic[63]', site = 0.5):
        gmaxS=20
        neuron.h('access %s' %section)
        glut_syn = neuron.h.glutamate(site)
        glut_syn.delay = 50
        glut_syn.ntar = 1
        glut_syn.gmax = gmaxS
        glut_syn.Nspike=2
        glut_syn.Tspike=20
        return glut_syn

    def insert_many_glutamate_stim(cell, nSyn = 500):
	import random
        gmaxS=1
	syn_array = []
	i = 0
	while i < nSyn:
	    apic_sec = random.randint(0,115)
	    section = 'apic[%d]' % apic_sec
	    comps = cell.get_idx_section(section)
	    idx = random.choice(comps)
	    if cell.ymid[idx] > 800:
	        #syns_positions.append(
		neuron.h('access %s' % section)
		syn_array.append(neuron.h.glutamate(random.uniform(0.5,0.95)))
		syn_array[-1].delay = 50
		syn_array[-1].ntar = 1
		syn_array[-1].gmax = gmaxS
		syn_array[-1].Nspike=3
		syn_array[-1].Tspike=20
		i += 1
        return syn_array#, syns_positions

    cell = LFPy.Cell(**cellParameters)
    cell.apic_11 = cell.get_closest_idx(x=52.52, y=441.92, z=0.75)
    cell.apic_58 = cell.get_closest_idx(x=29.05, y=742.84, z=-34.05)
    cell.apic_59 = cell.get_closest_idx(x = 20.9, y = 825.51, z = -40.25)
  
    cell.set_pos(xpos = -45)
    cell.set_rotation(y = -pl.pi/2)
    cell.set_rotation(y = pl.pi/10)
    cell.set_rotation(z = +pl.pi/65)
    
    if do_simulation:
        os.system('cp %s %s' %(sys.argv[0], output_folder))
        np.save(output_folder + 'x_start.npy', cell.xstart)
        np.save(output_folder + 'y_start.npy', cell.ystart)
        np.save(output_folder + 'z_start.npy', cell.zstart)
        np.save(output_folder + 'x_end.npy', cell.xend)
        np.save(output_folder + 'y_end.npy', cell.yend)
        np.save(output_folder + 'z_end.npy', cell.zend)
        np.save(output_folder + 'diam.npy', cell.diam)
        try:
             np.save(output_folder + 'ica.npy',cell.rec_variables['ica'])
             np.save(output_folder + 'cai.npy',cell.rec_variables['cai'])
        except:
            pass
        #currentClamp_1 = LFPy.StimIntElectrode(cell, **clamp_1)
        #currentClamp_2 = LFPy.StimIntElectrode(cell, **clamp_2)
        #currentClamp_3 = LFPy.StimIntElectrode(cell, **clamp_3)
        #insert_synapses(synapseParameters_AMPA, **insert_synapses_AMPA_args)
        #insert_synapses(synapseParameters_NMDA, **insert_synapses_NMDA_args)
	#insert_synapses(synapseParameters_GABA_A, **insert_synapses_GABA_A_args)
        #glut_syn = insert_glutamate_stim(cell, section = 'apic[63]')
	#glut_syn2 = insert_glutamate_stim(cell, section = 'apic[45]')
	#glut_syn = insert_many_glutamate_stim(cell, 100)
        #glut_syn1 = insert_glutamate_stim(cell, section = 'apic[63]', site = 0.59)
        #glut_syn2 = insert_glutamate_stim(cell, section = 'apic[71]', site = 0.59)
	#glut_syn3 = insert_glutamate_stim(cell, section = 'apic[71]', site = 0.31)
        cell.simulate(**simulationParameters)
        np.save(output_folder + 'imem.npy', cell.imem)
        np.save(output_folder + 'vmem.npy', cell.vmem)
        np.save(output_folder + 'tvec.npy', cell.tvec)
        plotstuff(cell, clamp_1, clamp_2)
        os.system('cp %s %s' %('example_fig.png', output_folder))
    else:
        cell.vmem = np.load(output_folder + 'vmem.npy')
        cell.imem = np.load(output_folder + 'imem.npy')
        cell.tvec = np.load(output_folder + 'tvec.npy')
        try:
             cell.rec_variables['ica'] = np.load(output_folder + 'ica.npy')
             cell.rec_variables['cai'] = np.load(output_folder + 'cai.npy')
        except:
            pass
    return cell