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)
} kc = nu.create_cell(args.kc, filename=args.kcfile) kc_solo = nu.create_cell(args.kc, filename=args.kcfile) ggn = nu.create_cell(args.ggn, filename=args.ggnfile) model = make_ggn_kc_conn(ggn, kc, ggn_kc_syn_params) tstart = 0.5e3 tend = 3.1e3 if len(args.freq) > 1: inject = make_driving_current(kc.soma, 0.5, args.amp[0], 1.0, tstart, tend) 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()
def run_model(args): """setup and run a model with templates and other parameters specified in args (parsed arguments). List of arguments: template_filename: HDF5 file containing the network template and PN spike trains. These data should be at paths in constants specified at the top of this file. output_directory: directory to dump simulated data into. pn_shift: shift the assignment of spike trains to PNs by this amount, i.e., if pn_shift is 2, then the spike train of pn_0 is assigned to pn_2, and pn_{i+2} gets the spike train of pn_{i}, with wrapping around the edge. pn_dither: The maximum magnitude of time shift when dithering the PN spike times. n_kc_vm: number of KCs to record Vm from n_ggn_vm: number of GGN sections to record Vm from for each of basal, calyceal and alpha lobe regions. recstep: number of integration steps between each recording point. simtime: total simulation time """ global model_dict output_filename = os.path.join(args.output_directory, 'fixed_net_UTC{}-PID{}-JID{}.h5'.format( cfg.timestamp.strftime('%Y_%m_%d__%H_%M_%S'), cfg.mypid, cfg.myjobid)) ggn = create_ggn() ggn_name_sec_dict = {sec.name(): sec for sec in ggn.all} with h5.File(args.template_filename, 'r') as template_fd: config = yaml.load(template_fd.attrs['config'].decode()) pn_spikes = load_pn_spikes(template_fd) pns, spike_trains = zip(*pn_spikes) spike_trains = dither_spiketrain(spike_trains, cell_shift=args.pn_shift, dither=args.pn_dither) pn_spike_vecs, vecstims = create_pn_output(spike_trains) kcs = create_kcs(template_fd, config=config['kc']) if args.test_kc >= 0: delay = cfg.Q_(config['stimulus']['onset']) if 'delay' in config['pn_kc_syn']: delay += cfg.Q_(config['pn_kc_syn']['delay']) duration = cfg.Q_(config['stimulus']['duration']) amplitude = cfg.Q_(args.kc_current) iclamp = ephys.setup_current_clamp(kcs[args.test_kc].soma, delay=delay, duration=duration, amplitude=amplitude) # test_kc_vvec = ephys.setup_sec_rec(kcs[args.test_kc].soma, 'v')[0] # this is added in setup recording model_dict['kc_iclamp'] = iclamp model_dict['test_kc'] = kcs[args.test_kc] kc_name_sec_dict = {kc.soma.name(): kc.soma for kc in kcs} nc_pn_kc, syn_pn_kc = create_pn_kc_conn(template_fd, dict(zip(pns, vecstims)), kc_name_sec_dict, config=config['pn_kc_syn']) syn_ggn_kc = create_ggn_kc_conn(template_fd, kc_name_sec_dict, ggn_name_sec_dict, config=config['ggn_kc_syn']) syn_kc_ggn, nc_kc_ggn = create_kc_ggn_conn(template_fd, kc_name_sec_dict, ggn_name_sec_dict, config=config['kc_ggn_alphaL_syn']) setup_ig(template_fd, ggn_name_sec_dict, config=config) data = setup_recording(kcs, ggn, n_kc_vm=args.n_kc_vm, n_ggn_vm=args.n_ggn_vm, t=h.dt * args.recstep) h.tstop = args.simtime start = datetime.utcnow() h.init() for v in pn_spike_vecs: if np.any(np.array(v.x) <= 0): print('negative pn spike time', v) cfg.logger.info('Finished init. Starting simulation of {} ms'.format( h.tstop)) if h.tstop > 0: nu.block_run(logger=cfg.logger) else: cfg.logger.info('Dry run. Skipping simulation') end = datetime.utcnow() delta = end - start data['tstart'] = start data['tend'] = end data['pn_spikes'] = dict(zip(pns, spike_trains)) cfg.logger.info('Finished running simulation in {} s'.format( delta.days * 86400 + delta.seconds + delta.microseconds * 1e-6)) cfg.logger.info('Starting data save in {}'.format(output_filename)) ig_vm = model_dict.get('ig_vm', None) data['ig_vm'] = ig_vm save(args.template_filename, output_filename, data, model_dict, args.savesyn, config) cfg.logger.info('Finished')