Пример #1
0
def make_kc_with_dynaclamp(kc_name,
                           kc_file,
                           inject,
                           tstart,
                           tend,
                           ggn_vm=None):
    """Read KC model from `kc_file`, inject current `inject` nA, apply
    dynamic clamp `ggn_vm`, which should be a 2D array with time (ms)
    in column 0, and voltage (mV) in column 1.

    """
    global model_dict
    kc = nu.create_cell(kc_name, filename=kc_file)
    model_dict[kc] = None
    iclamp = ephys.setup_current_clamp(kc.soma,
                                       pos=0.5,
                                       delay=Q_(tstart, 'ms'),
                                       duration=Q_((tend - tstart), 'ms'),
                                       amplitude=Q_(inject, 'nA'))
    model_dict[iclamp] = None
    ggn_g_vec = None
    if ggn_vm is not None:
        syn = h.GradedSyn(kc.soma(0.5))
        for attr, value in GGN_KC_SYN_PARAMS.items():
            setattr(syn, attr, value)
        model_dict[syn] = None
        ggn_comp = h.Section('ggn')
        model_dict[ggn_comp] = None
        h.setpointer(ggn_comp(0.5)._ref_v, 'vpre', syn)
        ggn_vm_vec = h.Vector(ggn_vm[:, 1])
        tvec = h.Vector(ggn_vm[:, 0])
        model_dict[tvec] = None
        # vec.play(var_reference, t, continuous) for interpolating
        ret = ggn_vm_vec.play(ggn_comp(0.5)._ref_v, tvec, 1)
        print('####', ret)
        model_dict[ggn_vm_vec] = None
        ggn_g_vec = h.Vector()
        ggn_g_vec.record(syn._ref_g)
        model_dict[ggn_g_vec] = None
    kc_vm_vec = h.Vector()
    kc_vm_vec.record(kc.soma(0.5)._ref_v)
    model_dict[kc_vm_vec] = None
    print('Built model')
    return (kc_vm_vec, ggn_g_vec)
Пример #2
0
    def __init__(self, filename, simtime, delta, stabilization_time=0):
        """Create spike times for IG using firing rate over time from
        filename.

        This disregards stimulus onset and duration, and only uses the
        information from the file.

        """
        spikerate = np.load(filename)
        interp = interpolate.interp1d(spikerate['t'], spikerate['Vm'])
        rate_fn = lambda t: interp(t)
        spike_times = nhpp.nhpp_thinning(rate_fn, simtime, delta) * 1e3  # second to millisecond
        spike_times = spike_times[spike_times > stabilization_time].copy()
        self.stimvec = h.Vector(spike_times)
        self.vecstim = h.VecStim()
        self.vecstim.play(self.stimvec)
Пример #3
0
def setup_mech_rec(cable, mechname, field):
    """Record the specified field of the mechanism `mechname` from all
    segments of the cable"""
    vecs = []
    for n in range(cable.nseg):
        vec = h.Vector()
        # https://www.neuron.yale.edu/phpBB2/viewtopic.php?f=8&t=1442 tells how nrn counts node pos
        pos = (0.5 + n) / cable.nseg
        print('Measuring {}.{} of segment {} at {}'.format(
            mechname, field, n, pos))
        if pos > 1.0:
            pos = 1.0
        mech = getattr(cable(pos), mechname)
        fieldref = getattr(mech, '_ref_{}'.format(field))
        vec.record(fieldref)
        vecs.append(vec)
    return vecs
Пример #4
0
def setup_sec_rec(cable, field, t=None):
    """Create and return a list of vectors to record `field` from every segment of
    the cable"""
    vecs = []
    for seg in cable:
        vec = h.Vector()
        # # https://www.neuron.yale.edu/phpBB2/viewtopic.php?f=8&t=1442 tells how nrn counts node pos
        # pos = (0.5 + n) / cable.nseg
        # print('Measuring Vm of segment', n, 'at', pos)
        # if pos > 1.0:
        #     pos = 1.0
        if t is None:
            vec.record(getattr(seg, '_ref_{}'.format(field)))
        else:
            vec.record(getattr(seg, '_ref_{}'.format(field)), t)
    vecs.append(vec)
    return vecs
        rec_nodes.append(synnode)

    synidx = rec_nodes.index(synnode)

    # alpha_syn = insert_alphasynapse(synsec(0.5), onset=args.onset, gmax=args.gsyn, tau=args.tau)
    clamp = ephys.setup_voltage_clamp(synsec,
                                      Q_('{}mV'.format(args.Em)),
                                      Q_('{}ms'.format(args.onset)),
                                      Q_('{}mV'.format(args.Em)),
                                      Q_('0ms'),
                                      Q_('{}mV'.format(args.vclamp)),
                                      Q_('{}ms'.format(args.simtime -
                                                       args.onset)),
                                      pos=0.5,
                                      rs=Q_('0.01ohm'))
    t_vec = h.Vector(np.arange(0, args.simtime,
                               h.dt * 10))  # record data every 10 timesteps
    tabs = [nu.setup_recording(sec, 0.5, 'v', t_vec) for sec in recsecs]
    ts = datetime.now()
    # Initialize and run
    h.tstop = args.simtime
    print('Setting Vm to {}'.format(args.Em))
    h.finitialize(args.Em)
    h.fcurrent()
    while h.t < h.tstop:
        h.fadvance()
    # h.init()
    # h.run()

    te = datetime.now()
    delta = te - ts
    print('Time for', h.tstop * 1e-3, 's simulation =',
Пример #6
0
        inject_solo = make_driving_current(kc_solo.soma, 0.5, args.amp[0], 1.0,
                                           tstart, tend)
    else:
        inject = ephys.setup_current_clamp(kc.soma,
                                           delay=Q_(tstart, 'ms'),
                                           duration=Q_((tend - tstart), 'ms'),
                                           amplitude=Q_(args.amp[0], 'nA'),
                                           pos=0.5)
        inject_solo = ephys.setup_current_clamp(kc_solo.soma,
                                                delay=Q_(tstart, 'ms'),
                                                duration=Q_((tend - tstart),
                                                            'ms'),
                                                amplitude=Q_(
                                                    args.amp[0], 'nA'),
                                                pos=0.5)
    tvec = h.Vector()
    kc_vvec = h.Vector()
    ggn_ca_vvec = h.Vector()
    ivec = h.Vector()
    kc_solo_vvec = h.Vector()
    ivec_solo = h.Vector()

    tvec.record(h._ref_t)
    kc_vvec.record(kc.soma(0.5)._ref_v)
    ggn_ca_vvec.record(model['ggn_pre'][0][0](model['ggn_pre'][0][1])._ref_v)
    ivec.record(inject._ref_i)

    kc_solo_vvec.record(kc_solo.soma(0.5)._ref_v)
    ivec_solo.record(inject_solo._ref_i)

    fb_dict = {'t': tvec, 'i': ivec, 'kc': kc_vvec, 'ca': ggn_ca_vvec}
Пример #7
0
def main():
    parser = make_parser()
    args = parser.parse_args()
    logger.info('Command line args: {}'.format(str(sys.argv)))
    print(args.ggn_vm_file)
    # KCs with GGN inhibition
    inhibited_vec = defaultdict(list)
    solo_vec_list = []
    tstart = Q_(args.tstart).to('ms').m
    tend = Q_(args.tend).to('ms').m
    istart = Q_(args.istart).to('nA').m
    iend = Q_(args.iend).to('nA').m
    di = Q_(args.di).to('nA').m
    irange = np.arange(istart, iend + di / 2.0, di)
    logger.info('Starting current: {} nA'.format(istart))
    logger.info('End current: {} nA'.format(iend))
    logger.info('Increment: {} nA'.format(di))
    logger.info('current range: {}'.format(irange))
    ggn_vm = {}
    for input_file in args.ggn_vm_file:
        ggn_vm[input_file] = np.loadtxt(input_file)
    for inject in irange:
        for input_file, vm in ggn_vm.items():
            kc_vvec, ggn_gvec = make_kc_with_dynaclamp(args.kc, args.kc_file,
                                                       inject, tstart, tend,
                                                       vm)
            inhibited_vec[input_file].append((kc_vvec, ggn_gvec))
        # KC without any inhibition
        kc_vvec, ggn_gvec = make_kc_with_dynaclamp(args.kc, args.kc_file,
                                                   inject, tstart, tend)
        solo_vec_list.append(kc_vvec)
    tvec = h.Vector()
    tvec.record(h._ref_t)
    h.tstop = tend
    print('Init')
    h.init()
    print('Run')
    h.run()
    print('Finished simulation')
    fig, ax = plt.subplots(nrows=len(irange) + 1,
                           ncols=len(ggn_vm) + 1,
                           sharex='all',
                           sharey='all')
    t = np.array(tvec.x)
    solo_data = []
    for ii, vvec in enumerate(solo_vec_list):
        ax[ii + 1, 0].plot(tvec, vvec, color='#e66101')
        solo_data.append(np.array(vvec.x))
    combined = np.vstack(solo_data)

    prefix = 'UTC' + timestamp.strftime('%Y%m%d_%H%M%S')
    fname = '{}_solo_kc.npz'.format(prefix)
    np.savez(fname, t=t, vm=combined, inject=irange)
    logger.info('Saved solo KC data in {}'.format(fname))
    for jj, input_file in enumerate(args.ggn_vm_file):
        fname = '{}_{}.npz'.format(prefix, os.path.basename(input_file))
        data = []
        kc_vm_list = inhibited_vec[input_file]
        for ii, (vvec, gvec) in enumerate(kc_vm_list):
            data.append(np.array(vvec.x))
            ax[ii + 1, jj + 1].plot(tvec, vvec, color='#e66101')
            ax[ii + 1, 0].set_ylabel('{} pA'.format(irange[ii] * 1e3))
            # ax[ii+1, 0].set_ylabel('{} pA'.format(int(np.round(irange[ii]*1e3))))  # to avoid decimal point when integer values
        # ax[0, jj+1].plot(tvec, gvec)
        # ax[0, jj+1].plot(ggn_vm[input_file][:,0], ggn_vm[input_file][:,1])
        ax[0, jj + 1].set_title(input_file)
        combined = np.vstack(data)
        np.savez(fname,
                 combined=combined,
                 irange=irange,
                 ggn_vm=ggn_vm[input_file])
        logger.info(
            'Saved data from dynamic clamp with input from {} in {}'.format(
                input_file, fname))
    for axis in ax.flat:
        axis.set_xlim(250, 1750)
        fig.set_size_inches(210 / 25.4, 290 / 25.4)
    fig.tight_layout()
    fig.savefig('{}_KC_dynamic_range_with_ggn_vm.svg'.format(prefix))
    plt.show()
    print('End')