Exemplo n.º 1
0
def measure_fi (gid, pop_name, v_init, env, cell_dict={}):

    biophys_cell = init_biophys_cell(env, pop_name, gid, register_cell=False, cell_dict=cell_dict)
    hoc_cell = biophys_cell.hoc_cell

    soma = list(hoc_cell.soma)[0]
    h.dt = 0.025

    prelength = 1000.0
    mainlength = 2000.0

    tstop = prelength+mainlength
    
    stimdur = 1000.0

    
    stim1 = h.IClamp(soma(0.5))
    stim1.delay = prelength
    stim1.dur   = stimdur
    stim1.amp   = 0.2

    h('objref tlog, Vlog, spikelog')

    h.tlog = h.Vector()
    h.tlog.record (h._ref_t)

    h.Vlog = h.Vector()
    h.Vlog.record (soma(0.5)._ref_v)

    h.spikelog = h.Vector()
    nc = biophys_cell.spike_detector
    nc.record(h.spikelog)
    
    h.tstop = tstop

    frs = []
    stim_amps = [stim1.amp]
    for it in range(1, 9):

        neuron_utils.simulate(v_init, prelength, mainlength)
        
        logger.info("fi_test: stim1.amp = %g spikelog.size = %d\n" % (stim1.amp, h.spikelog.size()))
        stim1.amp = stim1.amp + 0.1
        stim_amps.append(stim1.amp)
        frs.append(h.spikelog.size())
        h.spikelog.clear()
        h.tlog.clear()
        h.Vlog.clear()


    results = {'FI_curve_amplitude': np.asarray(stim_amps, dtype=np.float32),
               'FI_curve_frequency': np.asarray(frs, dtype=np.float32) }

    env.synapse_attributes.del_syn_id_attr_dict(gid)
    if gid in env.biophys_cells[pop_name]:
        del env.biophys_cells[pop_name][gid]

    return results
Exemplo n.º 2
0
def measure_passive (gid, pop_name, v_init, env, prelength=1000.0, mainlength=2000.0, stimdur=500.0, cell_dict={}):


    biophys_cell = init_biophys_cell(env, pop_name, gid, register_cell=False, cell_dict=cell_dict)
    hoc_cell = biophys_cell.hoc_cell

    h.dt = env.dt

    tstop = prelength+mainlength
    
    soma = list(hoc_cell.soma)[0]
    stim1 = h.IClamp(soma(0.5))
    stim1.delay = prelength
    stim1.dur   = stimdur
    stim1.amp   = -0.1

    h('objref tlog, Vlog')
    
    h.tlog = h.Vector()
    h.tlog.record (h._ref_t)

    h.Vlog = h.Vector()
    h.Vlog.record (soma(0.5)._ref_v)
    
    h.tstop = tstop

    Rin = h.rn(hoc_cell)
    
    neuron_utils.simulate(v_init, prelength, mainlength)

    ## compute membrane time constant
    vrest  = h.Vlog.x[int(h.tlog.indwhere(">=",prelength-1))]
    vmin   = h.Vlog.min()
    vmax   = vrest
    
    ## the time it takes the system's step response to reach 1-1/e (or
    ## 63.2%) of the peak value
    amp23  = 0.632 * abs (vmax - vmin)
    vtau0  = vrest - amp23
    tau0   = h.tlog.x[int(h.Vlog.indwhere ("<=", vtau0))] - prelength

    results = {'Rin': np.asarray([Rin], dtype=np.float32),
               'vmin': np.asarray([vmin], dtype=np.float32),
               'vmax': np.asarray([vmax], dtype=np.float32),
               'vtau0': np.asarray([vtau0], dtype=np.float32),
               'tau0': np.asarray([tau0], dtype=np.float32)
               }

    env.synapse_attributes.del_syn_id_attr_dict(gid)
    if gid in env.biophys_cells[pop_name]:
        del env.biophys_cells[pop_name][gid]
        
    return results
Exemplo n.º 3
0
def fi_test(template_class, tree, v_init):

    cell = cells.make_neurotree_cell(template_class, neurotree_dict=tree)
    soma = list(cell.soma)[0]
    h.dt = 0.025

    prelength = 1000.0
    mainlength = 2000.0

    tstop = prelength + mainlength

    stimdur = 1000.0

    stim1 = h.IClamp(soma(0.5))
    stim1.delay = prelength
    stim1.dur = stimdur
    stim1.amp = 0.2

    h.tlog = h.Vector()
    h.tlog.record(h._ref_t)

    h.Vlog = h.Vector()
    h.Vlog.record(soma(0.5)._ref_v)

    h.spikelog = h.Vector()
    nc = h.NetCon(soma(0.5)._ref_v, h.nil)
    nc.threshold = -20.0
    nc.record(h.spikelog)

    h.tstop = tstop

    frs = []
    stim_amps = [stim1.amp]
    for it in range(1, 9):

        neuron_utils.simulate(v_init, prelength, mainlength)

        print("fi_test: stim1.amp = %g spikelog.size = %d\n" %
              (stim1.amp, h.spikelog.size()))
        stim1.amp = stim1.amp + 0.1
        stim_amps.append(stim1.amp)
        frs.append(h.spikelog.size())
        h.spikelog.clear()
        h.tlog.clear()
        h.Vlog.clear()

    f = open("HIPPCell_fi_results.dat", 'w')

    for (fr, stim_amp) in zip(frs, stim_amps):
        f.write("%g %g\n" % (stim_amp, fr))

    f.close()
Exemplo n.º 4
0
def passive_test(template_class, tree, v_init):

    cell = cells.make_neurotree_cell(template_class, neurotree_dict=tree)
    h.topology()

    h.dt = 0.025

    prelength = 1000
    mainlength = 2000

    tstop = prelength + mainlength

    stimdur = 500.0
    soma = list(cell.soma)[0]
    stim1 = h.IClamp(soma(0.5))
    stim1.delay = prelength
    stim1.dur = stimdur
    stim1.amp = -0.1

    h.tlog = h.Vector()
    h.tlog.record(h._ref_t)

    h.Vlog = h.Vector()
    h.Vlog.record(soma(0.5)._ref_v)

    h.tstop = tstop

    neuron_utils.simulate(v_init, prelength, mainlength)

    ## compute membrane time constant
    vrest = h.Vlog.x[int(h.tlog.indwhere(">=", prelength - 1))]
    vmin = h.Vlog.min()
    vmax = vrest

    ## the time it takes the system's step response to reach 1-1/e (or
    ## 63.2%) of the peak value
    amp23 = 0.632 * abs(vmax - vmin)
    vtau0 = vrest - amp23
    tau0 = h.tlog.x[int(h.Vlog.indwhere("<=", vtau0))] - prelength

    f = open("HIPPCell_passive_results.dat", 'w')

    f.write("DC input resistance: %g MOhm\n" % h.rn(cell))
    f.write("vmin: %g mV\n" % vmin)
    f.write("vtau0: %g mV\n" % vtau0)
    f.write("tau0: %g ms\n" % tau0)

    f.close()
Exemplo n.º 5
0
def measure_psp(gid,
                pop_name,
                presyn_name,
                syn_mech_name,
                swc_type,
                env,
                v_init,
                erev,
                syn_layer=None,
                weight=1,
                syn_count=1,
                load_weights=False,
                cell_dict={}):

    biophys_cell = init_biophys_cell(env,
                                     pop_name,
                                     gid,
                                     register_cell=False,
                                     load_weights=load_weights,
                                     cell_dict=cell_dict)
    synapses.config_biophys_cell_syns(env,
                                      gid,
                                      pop_name,
                                      insert=True,
                                      insert_netcons=True,
                                      insert_vecstims=True)

    hoc_cell = biophys_cell.hoc_cell

    h.dt = env.dt

    prelength = 200.0
    mainlength = 50.0

    rules = {'sources': [presyn_name]}
    if swc_type is not None:
        rules['swc_types'] = [swc_type]
    if syn_layer is not None:
        rules['layers'] = [syn_layer]
    syn_attrs = env.synapse_attributes
    syn_filters = get_syn_filter_dict(env, rules=rules, convert=True)
    syns = syn_attrs.filter_synapses(biophys_cell.gid, **syn_filters)

    print("total number of %s %s synapses: %d" %
          (presyn_name, swc_type if swc_type is not None else "", len(syns)))
    stimvec = h.Vector()
    stimvec.append(prelength + 1.)
    count = 0
    target_syn_pps = None
    for target_syn_id, target_syn in iter(syns.items()):

        target_syn_pps = syn_attrs.get_pps(gid, target_syn_id, syn_mech_name)
        target_syn_nc = syn_attrs.get_netcon(gid, target_syn_id, syn_mech_name)
        target_syn_nc.weight[0] = weight
        setattr(target_syn_pps, 'e', erev)
        vs = target_syn_nc.pre()
        vs.play(stimvec)
        if syn_count <= count:
            break
        count += 1

    if target_syn_pps is None:
        raise RuntimeError(
            "measure_psp: Unable to find %s %s synaptic point process" %
            (presyn_name, swc_type))

    sec = target_syn_pps.get_segment().sec

    v_rec = make_rec('psp',
                     pop_name,
                     gid,
                     biophys_cell.hoc_cell,
                     sec=sec,
                     dt=env.dt,
                     loc=0.5,
                     param='v')

    h.tstop = mainlength + prelength
    h('objref nil, tlog, ilog')

    h.tlog = h.Vector()
    h.tlog.record(h._ref_t)

    h.ilog = h.Vector()
    h.ilog.record(target_syn_pps._ref_i)

    neuron_utils.simulate(v_init, prelength, mainlength)

    vec_v = np.asarray(v_rec['vec'].to_python())
    vec_i = np.asarray(h.ilog.to_python())
    vec_t = np.asarray(h.tlog.to_python())
    idx = np.where(vec_t >= prelength)[0]
    vec_v = vec_v[idx][1:]
    vec_t = vec_t[idx][1:]
    vec_i = vec_i[idx][1:]

    i_peak_index = np.argmax(np.abs(vec_i))
    i_peak = vec_i[i_peak_index]
    v_peak = vec_v[i_peak_index]

    amp_v = abs(v_peak - vec_v[0])
    amp_i = abs(i_peak - vec_i[0])

    print("measure_psp: v0 = %f v_peak = %f (at t %f)" %
          (vec_v[0], v_peak, vec_t[i_peak_index]))
    print("measure_psp: i_peak = %f (at t %f)" % (i_peak, vec_t[i_peak_index]))
    print("measure_psp: amp_v = %f amp_i = %f" % (amp_v, amp_i))

    results = {
        '%s %s PSP' % (presyn_name, syn_mech_name):
        np.asarray([amp_v], dtype=np.float32),
        '%s %s PSP i' % (presyn_name, syn_mech_name):
        np.asarray(vec_i, dtype=np.float32),
        '%s %s PSP v' % (presyn_name, syn_mech_name):
        np.asarray(vec_v, dtype=np.float32),
        '%s %s PSP t' % (presyn_name, syn_mech_name):
        np.asarray(vec_t, dtype=np.float32)
    }

    env.synapse_attributes.del_syn_id_attr_dict(gid)
    if gid in env.biophys_cells[pop_name]:
        del env.biophys_cells[pop_name][gid]

    return results
Exemplo n.º 6
0
def measure_psc(gid,
                pop_name,
                presyn_name,
                env,
                v_init,
                v_holding,
                load_weights=False,
                cell_dict={}):

    biophys_cell = init_biophys_cell(env,
                                     pop_name,
                                     gid,
                                     register_cell=False,
                                     load_weights=load_weights,
                                     cell_dict=cell_dict)
    hoc_cell = biophys_cell.hoc_cell

    h.dt = env.dt

    stimdur = 1000.0
    tstop = stimdur
    tstart = 0.

    soma = list(hoc_cell.soma)[0]
    se = h.SEClamp(soma(0.5))
    se.rs = 10
    se.dur = stimdur
    se.amp1 = v_holding

    h('objref nil, tlog, ilog, Vlog')

    h.tlog = h.Vector()
    h.tlog.record(h._ref_t)

    h.Vlog = h.Vector()
    h.Vlog.record(soma(0.5)._ref_v)

    h.ilog = h.Vector()
    ilog.record(se._ref_i)

    h.tstop = tstop

    neuron_utils.simulate(v_init, 0., stimdur)

    vec_i = h.ilog.to_python()
    vec_v = h.Vlog.to_python()
    vec_t = h.tlog.to_python()

    idx = np.where(vec_t > tstart)[0]
    vec_i = vec_i[idx]
    vec_v = vec_v[idx]
    vec_t = vec_t[idx]

    t_holding = vec_t[0]
    i_holding = vec_i[0]

    i_peak = np.max(np.abs(vec_i[1:]))
    peak_index = np.where(np.abs(vec_i) == i_peak)[0][0]
    t_peak = vec_t[peak_index]

    logger.info("measure_psc: t_peak = %f i_holding = %f i_peak = %f" %
                (t_peak, i_holding, i_peak))

    amp_i = abs(i_peak - i_holding) * 1000

    logger.info("measure_psc: amp_i = %f" % amp_i)

    return amp_i
Exemplo n.º 7
0
def measure_ap_rate(gid,
                    pop_name,
                    v_init,
                    env,
                    prelength=1000.0,
                    mainlength=3000.0,
                    stimdur=1000.0,
                    stim_amp=0.2,
                    minspikes=50,
                    maxit=5,
                    cell_dict={}):

    biophys_cell = init_biophys_cell(env,
                                     pop_name,
                                     gid,
                                     register_cell=False,
                                     cell_dict=cell_dict)

    hoc_cell = biophys_cell.hoc_cell

    tstop = prelength + mainlength

    soma = list(hoc_cell.soma)[0]
    stim1 = h.IClamp(soma(0.5))
    stim1.delay = prelength
    stim1.dur = stimdur
    stim1.amp = stim_amp

    h('objref nil, tlog, Vlog, spikelog')

    h.tlog = h.Vector()
    h.tlog.record(h._ref_t)

    h.Vlog = h.Vector()
    h.Vlog.record(soma(0.5)._ref_v)

    h.spikelog = h.Vector()
    nc = biophys_cell.spike_detector
    nc.record(h.spikelog)
    logger.info(f"ap_rate_test: spike threshold is {nc.threshold}")

    h.tstop = tstop

    it = 1
    ## Increase the injected current until at least maxspikes spikes occur
    ## or up to maxit steps
    while (h.spikelog.size() < minspikes):

        logger.info(f"ap_rate_test: iteration {it}")

        h.dt = env.dt

        neuron_utils.simulate(v_init, prelength, mainlength)

        if ((h.spikelog.size() < minspikes) & (it < maxit)):
            logger.info(
                f"ap_rate_test: stim1.amp = {stim1.amp:.2f} spikelog.size = {h.spikelog.size()}"
            )
            stim1.amp = stim1.amp + 0.1
            h.spikelog.clear()
            h.tlog.clear()
            h.Vlog.clear()
            it += 1
        else:
            break

    logger.info(
        f"ap_rate_test: stim1.amp = {stim1.amp:.2f} spikelog.size = {h.spikelog.size()}"
    )

    isivect = h.Vector(h.spikelog.size() - 1, 0.0)
    tspike = h.spikelog.x[0]
    for i in range(1, int(h.spikelog.size())):
        isivect.x[i - 1] = h.spikelog.x[i] - tspike
        tspike = h.spikelog.x[i]

    isimean = isivect.mean()
    isivar = isivect.var()
    isistdev = isivect.stdev()

    isilast = int(isivect.size()) - 1
    if (isivect.size() > 10):
        isi10th = 10
    else:
        isi10th = isilast

    ## Compute the last spike that is largest than the first one.
    ## This is necessary because some models generate spike doublets,
    ## (i.e. spike with very short distance between them, which confuse the ISI statistics.
    isilastgt = int(isivect.size()) - 1
    while (isivect.x[isilastgt] < isivect.x[1]):
        isilastgt = isilastgt - 1

    if (not (isilastgt > 0)):
        isivect.printf()
        raise RuntimeError("Unable to find ISI greater than first ISI")

    results = {
        'spike_count':
        np.asarray([h.spikelog.size()], dtype=np.uint32),
        'FR_mean':
        np.asarray([1.0 / isimean], dtype=np.float32),
        'ISI_mean':
        np.asarray([isimean], dtype=np.float32),
        'ISI_var':
        np.asarray([isivar], dtype=np.float32),
        'ISI_stdev':
        np.asarray([isistdev], dtype=np.float32),
        'ISI_adaptation_1':
        np.asarray([isivect.x[0] / isimean], dtype=np.float32),
        'ISI_adaptation_2':
        np.asarray([isivect.x[0] / isivect.x[isilast]], dtype=np.float32),
        'ISI_adaptation_3':
        np.asarray([isivect.x[0] / isivect.x[isi10th]], dtype=np.float32),
        'ISI_adaptation_4':
        np.asarray([isivect.x[0] / isivect.x[isilastgt]], dtype=np.float32)
    }

    env.synapse_attributes.del_syn_id_attr_dict(gid)
    if gid in env.biophys_cells[pop_name]:
        del env.biophys_cells[pop_name][gid]

    return results
Exemplo n.º 8
0
def ap_rate_test(template_class, tree, v_init):

    cell = cells.make_neurotree_cell(template_class, neurotree_dict=tree)
    h.dt = 0.025

    prelength = 1000.0
    mainlength = 2000.0

    tstop = prelength + mainlength

    stimdur = 1000.0
    soma = list(cell.soma)[0]
    stim1 = h.IClamp(soma(0.5))
    stim1.delay = prelength
    stim1.dur = stimdur
    stim1.amp = 0.2

    h.tlog = h.Vector()
    h.tlog.record(h._ref_t)

    h.Vlog = h.Vector()
    h.Vlog.record(soma(0.5)._ref_v)

    h.spikelog = h.Vector()
    nc = h.NetCon(soma(0.5)._ref_v, h.nil)
    nc.threshold = -20.0
    nc.record(h.spikelog)

    h.tstop = tstop

    it = 1
    ## Increase the injected current until at least 60 spikes occur
    ## or up to 5 steps
    while (h.spikelog.size() < 50):

        neuron_utils.simulate(v_init, prelength, mainlength)

        if ((h.spikelog.size() < 50) & (it < 5)):
            print("ap_rate_test: stim1.amp = %g spikelog.size = %d\n" %
                  (stim1.amp, h.spikelog.size()))
            stim1.amp = stim1.amp + 0.1
            h.spikelog.clear()
            h.tlog.clear()
            h.Vlog.clear()
            it += 1
        else:
            break

    print("ap_rate_test: stim1.amp = %g spikelog.size = %d\n" %
          (stim1.amp, h.spikelog.size()))

    isivect = h.Vector(h.spikelog.size() - 1, 0.0)
    tspike = h.spikelog.x[0]
    for i in range(1, int(h.spikelog.size())):
        isivect.x[i - 1] = h.spikelog.x[i] - tspike
        tspike = h.spikelog.x[i]

    print("ap_rate_test: isivect.size = %d\n" % isivect.size())
    isimean = isivect.mean()
    isivar = isivect.var()
    isistdev = isivect.stdev()

    isilast = int(isivect.size()) - 1
    if (isivect.size() > 10):
        isi10th = 10
    else:
        isi10th = isilast

    ## Compute the last spike that is largest than the first one.
    ## This is necessary because some variants of the model generate spike doublets,
    ## (i.e. spike with very short distance between them, which confuse the ISI statistics.
    isilastgt = int(isivect.size()) - 1
    while (isivect.x[isilastgt] < isivect.x[1]):
        isilastgt = isilastgt - 1

    if (not (isilastgt > 0)):
        isivect.printf()
        raise RuntimeError(
            "Unable to find ISI greater than first ISI: forest_path = %s gid = %d"
            % (forest_path, gid))

    f = open("HIPPCell_ap_rate_results.dat", 'w')

    f.write("## number of spikes: %g\n" % h.spikelog.size())
    f.write("## FR mean: %g\n" % (1.0 / isimean))
    f.write("## ISI mean: %g\n" % isimean)
    f.write("## ISI variance: %g\n" % isivar)
    f.write("## ISI stdev: %g\n" % isistdev)
    f.write("## ISI adaptation 1: %g\n" % (isivect.x[0] / isimean))
    f.write("## ISI adaptation 2: %g\n" % (isivect.x[0] / isivect.x[isilast]))
    f.write("## ISI adaptation 3: %g\n" % (isivect.x[0] / isivect.x[isi10th]))
    f.write("## ISI adaptation 4: %g\n" %
            (isivect.x[0] / isivect.x[isilastgt]))

    f.close()

    f = open("HIPPCell_voltage_trace.dat", 'w')
    for i in range(0, int(h.tlog.size())):
        f.write('%g %g\n' % (h.tlog.x[i], h.Vlog.x[i]))
    f.close()