Beispiel #1
0
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()
Beispiel #2
0
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()
Beispiel #3
0
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()
Beispiel #4
0
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()
Beispiel #5
0
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
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
def init_cell(all_params, cell_params):
    #uses the .hoc template

    # load your model cell
    morpho_dir = all_params['dir_morpho_vertical']
    morpho_file = cell_params['morpho_file']+'.swc' #''.hoc'

    #cell.load_model(str(os.path.join(morpho_dir, morpho_file)))
    cell.load_model_swc(str(os.path.join(morpho_dir, morpho_file)))
    # define number of segments
    for sec in cell.h.allsec():
        if sec.name() == 'soma':
            sec.nseg = 5
        else:
            sec.nseg = max(int((sec.L / (0.1 * lambda_f(100, sec.diam, sec.Ra, sec.cm)) + 0.9) / 2.) * 2 + 1, 5) # set at least 3 segments

    # get coordinates of the segments of your cell(s)
    seg_coords = cell.get_seg_coords()
    return seg_coords
Beispiel #9
0
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",
          "hill" : "m"}
Beispiel #10
0
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))

# scalebar