def test_current_balance_synapse_at_section_end(): h('synapse.loc(0)') cell.initialize(dt=0.025) t, I = cell.integrate(1) coord = cell.get_seg_coords() assert (np.abs(total_current(coord, I))<1e-6).all()
def test_current_balance_synapse_at_section_end(): h('synapse.loc(0)') cell.initialize(dt=0.025) t, I = cell.integrate(1) coord = cell.get_seg_coords() assert (np.abs(total_current(coord, I)) < 1e-6).all()
def test_current_balance_synapse_in_segment(): h('synapse.loc(0.1)') h('soma {insert pas}') cell.initialize(dt=0.025) t, I = cell.integrate(1) coord = cell.get_seg_coords() assert (np.abs(total_current(coord, I))<1e-6).all()
def test_current_balance_synapse_in_segment(): h('synapse.loc(0.1)') h('soma {insert pas}') cell.initialize(dt=0.025) t, I = cell.integrate(1) coord = cell.get_seg_coords() assert (np.abs(total_current(coord, I)) < 1e-6).all()
def get_data(data_dir, simulate_new=True, run_original=True): ''' returns the data from the simulations, depending on the params, it either runs new simulations or not. run_original = True -> original Hallermann model, False -> reduced Nav model''' if run_original: save_file = 'data_hallerman_raw_original.npz' else: save_file = 'data_hallerman_raw_redNav.npz' save_file = os.path.join(data_dir, save_file) if simulate_new: # params dt = 0.0125 sim_len = 60 # ms stim_delay = 40 # ms stim_dur = 1 # ms postfix = '' det = True if run_original: simulate_original_model(data_dir) # to simulate original model else: simulate_reduced_Nav_model(data_dir) # to simulate reduced Nav model st = add_stimulation(st_delay=stim_delay,st_dur=stim_dur, stim_delay=stim_delay) vecs_ais, vec_soma, vec_st = get_recording_vecs(st) # simulate the cell cell.initialize(dt=dt) cell.h.finitialize(-85) t, I, I_axial = cell.integrate(sim_len, i_axial=True) # extract the data v_soma = np.array(vec_soma) h.define_shape() seg_coords = cell.get_seg_coords() #!!!! Need of current correction areas = [] for sec in cell.h.allsec(): areas += [seg.area() for seg in sec] surface = np.pi * coords['diam'] * coords['L'] currents_with_electrode = currents_with_electrode * areas / surface #!!!!! # save the data time = (np.arange(len(v_soma))*dt) np.savez(save_file, I=I, t=time, I_axial=I_axial, v_soma=v_soma, seg_coords=seg_coords,vecs_ais=vecs_ais, dt=h.dt, stim_delay=stim_delay) data = np.load(save_file) return data
def test_axial_currents(): h('soma {insert pas}') isim = h.IClamp(1, sec=h.cable) isim.delay = 0 isim.dur = 1 isim.amp = 2 #nA h.cable.Ra = 0.1 cell.initialize(0.1) t, imem_density, iax_density = cell.integrate(0.2, i_axial=True) coord = cell.get_seg_coords() iax = iax_density*coord['diam'][None,:]**2*1e-8/4.*h.PI #mA assert np.abs(iax[-1,1]*1e6 - isim.amp)<0.1*isim.amp
def test_axial_currents(): h('soma {insert pas}') isim = h.IClamp(1, sec=h.cable) isim.delay = 0 isim.dur = 1 isim.amp = 2 #nA h.cable.Ra = 0.1 cell.initialize(0.1) t, imem_density, iax_density = cell.integrate(0.2, i_axial=True) coord = cell.get_seg_coords() iax = iax_density * coord['diam'][None, :]**2 * 1e-8 / 4. * h.PI #mA assert np.abs(iax[-1, 1] * 1e6 - isim.amp) < 0.1 * isim.amp
def simulate_cells(all_params): #synapses, seg_coords_cells, cells, parameters_from_file): print 'record what is happening in the synapses' timestep = all_params['timestep'] vec_soma = cell.h.Vector() vec_soma.record(eval('h.soma[0]('+str(0.3)+')._ref_v'), sec = eval('h.soma[0]')) # vector for recording voltage at the soma # initialize it with the timestep cell.initialize(dt=timestep) # ms cell.h.finitialize(all_params['memb_pot']) # setting initial membrane potential # make calculations of I and I axial for each cell separately t_length = all_params['sim_len'] t, I, I_axial = cell.integrate(t_length, i_axial=True) results_sim = {'I': I, # transmembrane current 'I_axial': I_axial, # axial current 'v_soma': np.array(vec_soma)} return results_sim
# Parameters dist = 2.5 #mm rho = 3.5 #conductivity, Ohm.m alpha = 0. #angle, rad cutoff = 800. #high-pass cutoff, Hz order = 401 #filter order # Electrode position and filter pos = (dist*np.sin(alpha)*1000, dist*np.cos(alpha)*1000, 0) fir = field.hp_fir(order, cutoff, dt) # Simulation cell.load_model('models/Mainen/demo_ext.hoc', 'models/Mainen/%s/.libs/libnrnmech.so' % ARCH) cell.initialize(dt=dt) t, I = cell.integrate(tstop) coords = cell.get_seg_coords() # Select segments dend = field.select_sections(coords, "dend") soma = field.select_sections(coords, "soma") axon = field.select_sections(coords, "(node)|(myelin)") iseg = field.select_sections(coords, "iseg") hill = field.select_sections(coords, "hill") all = field.select_sections(coords, ".*") colors = {"dend": "r", "soma": "c", "axon": "b", "all" : "k", "iseg" : "g",
dt = 0.025 tstop=50 # Parameters rho = 3.5 #conductivity, Ohm.m cutoff = 800. #high-pass cutoff, Hz order = 401 #filter order Nsamp = 30 filter = None # Simulation cell.load_model('models/Mainen/demo_ext.hoc', 'models/Mainen/%s/.libs/libnrnmech.so' % ARCH) cell.initialize(dt=dt) t, I = cell.integrate(tstop) coords = cell.get_seg_coords() # Plots fig = plt.figure(figsize=(6,6), facecolor=(0.7, 0.7, 0.7)) fig.subplots_adjust(left=0.05, right=0.95) ax = plt.subplot(111, frameon=False) S = np.pi*coords['diam']*coords['L'] #segment surface p2p = np.abs(I).max(0)-np.abs(I).min(0) norm = colors.LogNorm(vmin=p2p.min(), vmax=p2p.max()) col = graph.plot_neuron(coords, p2p, norm=norm) plt.xticks([]) plt.yticks([]) plt.ylim((-200, 610)) plt.xlim((-550, 250))
stimlist[-1].interval = 1 stimlist[-1].noise = 0 nclist.append( cell.h.NetCon(stimlist[-1], syn, con_thresh=0, con_delay=1, con_weight=.25e-3)) init_synapse(cell_no=0, syn_start=0.1) init_synapse(cell_no=1, syn_start=0.5) # initialise and run neuron simulations cell.initialize(dt=dt) t, I_cell = cell.integrate(t_length, i_axial=False, neuron_cells=cells) # CALCULATION OF THE FIELD seg_coords = cell.get_seg_coords() n_samp = 40 x_range = [-210, 430] y_range = [-255, 725] # define grid xx, yy = field.calc_grid(x_range, y_range, n_samp) # join the currents together I = I_cell.swapaxes(0, 1).reshape(I_cell.shape[1], -1) v_ext = field.estimate_on_grid(seg_coords, I, xx, yy)