def dpp_generation(model_data, cell_index, run_info, noise=True, HFI=False, HFI_delay=0, dur_and_amp=True, spike=False): ''' Provides clustered glutamatergic input to SPNs to generate the dendritic plateau potential in the absence of modulation. INPUT(S): - model_data: model paramaters (specification, cell type, model sets, and stimulation targets) [dict] - stim_data: stimulation parameters (number of inputs, time of inputs, input inter-spike intervals, time to stop simulating) [dict] - cell_index: cell specification being simulated [int] - run_info: information about the simulation run (this simulation and total number of simulations) [dict] - dur_and_amp: whether to calculate the duration and peak amplitude of the plateau potential (default True) [bool] OUTPUT(S): - data: simulated data including: simulation times; simulated voltages; distance of stimulated target to the soma; rheobase of the model; half-max width of the potential; peak amplitude of the potential; cell specification being simulated; cell type being simulated [dict] - ncon: NetCon object Thomas Binns (author), 26/01/21 ''' # ===== print simulation info to monitor progress ===== print('Simulating cell specification {} of {}'.format( \ run_info['curr_n']+1,run_info['tot_n']),flush = True) # ===== gets stimulation info ===== # clustered inputs clus_info = cf.params_for_input(model_data['cell_type'], 'clustered') clus_params = clus_info['clustered']['params'] # noise inputs if noise: noise_info = cf.params_for_input(model_data['cell_type'], 'noise') noise_params = noise_info['noise']['params'] # HFIs if HFI: HFI_info = cf.params_for_input(model_data['cell_type'], 'HFI') HFI_params = HFI_info['HFI']['params'] # ===== simulation ===== data = {} for i, tar in enumerate( clus_info['clustered']['target']): # for each simulation target clus_lab = clus_info['clustered']['label'][i] # label for input target # initiate cell cell = build.MSN( params=model_data['specs']['par'], morphology=model_data['specs']['morph'], variables=model_data['model_sets'][cell_index]['variables']) rheobase = model_data['model_sets'][cell_index]['rheobase'] # record vectors tm = h.Vector() tm.record(h._ref_t) vm = h.Vector() vm.record(cell.soma(0.5)._ref_v) # add clustered inputs clus_syn, clus_stim, clus_ncon, clus_d2soma = cf.set_clustered_stim( cell, tar, n=clus_params['stim_n'], act_time=clus_params['stim_t'], ISI=clus_params['isi']) # add background noise if noise: ''' noise_syn, noise_stim, noise_ncon = cf.set_noise(cell, model_data['cell_type'], freq_glut=noise_params['freq_glut'], freq_gaba=noise_params['freq_gaba'], n_glut=noise_params['n_glut'], n_gaba=noise_params['n_gaba'], only_dend=noise_params['only dend'], glut_delay=noise_params['stim_t'], gaba_delay=noise_params['stim_t']) ''' noise_syn, noise_stim, noise_ncon = cf.set_bg_noise( cell, model_data['cell_type'], fglut=noise_params['freq_glut'], fgaba=noise_params['freq_gaba'], dendOnly=noise_params['only dend']) # add high-frequency inputs if HFI: # adds HFI HFI_syn, HFI_stim, HFI_ncon, arrangement = cf.set_HFI( cell, model_data['cell_type'], freq=HFI_params['freq'], n_inputs=HFI_params['n_inputs'], delay=clus_params['stim_t'] + (clus_params['stim_n'] * clus_params['isi']) + HFI_delay, exclude=HFI_info['HFI']['exclude']) # collates data data['HFI'] = arrangement # run simulation h.finitialize(-80) while h.t < clus_params['stop_t'] + HFI_delay + ( clus_params['stim_n'] * clus_params['isi']): h.fadvance() tm = tm.to_python() vm = vm.to_python() # collate data data[clus_lab] = {'vm': vm} data['meta'] = { 'id': int(cell_index), 'round': run_info['round'], 'cell_type': model_data['cell_type'], 'tm': tm, 'rheo': rheobase } # calculate dpp duration and amplitude if dur_and_amp: base_t_start = tm.index( min(tm, key=lambda x: abs(x - (clus_params['stim_t'] + clus_params[ 'pre_t'])))) base_t_end = tm.index( min(tm, key=lambda x: abs(x - clus_params['stim_t']))) base_vm = np.mean(vm[base_t_start:base_t_end]) data[clus_lab]['dur'] = cf.dpp_dur(tm, vm, base_vm, clus_params['stim_t']) data[clus_lab]['amp'] = cf.dpp_amp(tm, vm, base_vm, clus_params['stim_t']) # get spike-related data if spike: spiked = 0 thresh = 0 # checks whether spike occured data[clus_lab]['spiked'] = 0 if max(vm) > thresh: data[clus_lab]['spiked'] = 1 spiked = 1 # checks time of first spike number of spikes that occured (if any) data[clus_lab]['first_spike'] = [] data[clus_lab]['spike_n'] = [] if spiked == 1: data[clus_lab]['first_spike'] = tm[next( i for i, x in enumerate(vm) if x > 0)] data[clus_lab]['spike_n'] = cf.spike_n(vm) return data
def run_model(cell_index, ci): # 1s low input; 0.3s ramping input; 0.2s high input tstop = 1500 modOnTime = 1000 nbg = 5 tau = 300 conditions = ['ACh+DA', 'ACh', 'DA', 'ctrl'] c = conditions[ci] # channel distribution parameter library path = '../Libraries' with open('{}/D2_34bestFit_updRheob.pkl'.format(path), 'rb') as f: model_sets = pickle.load(f, encoding="latin1") parameters = model_sets[cell_index]['variables'] par = '../params_iMSN.json' morphology = '../Morphologies/WT-dMSN_P270-20_1.02_SGA1-m24.swc' cell = build.MSN( params=par, \ morphology=morphology, \ variables=parameters ) # record vectors tm = h.Vector() vm = h.Vector() tm.record(h._ref_t) vm.record(cell.soma(0.5)._ref_v) # transient to play transient = h.Vector([ use.alpha(ht, modOnTime, 1, tau) if ht >= modOnTime else 0 for ht in np.arange(0, tstop, h.dt) ]) # result dict res = {} for i in range(20): res[i] = {} # draw random factors modulation_DA = { 'intr': { 'naf': np.random.uniform(0.95, 1.1), 'kaf': np.random.uniform(1.0, 1.1), 'kas': np.random.uniform(1.0, 1.1), 'kir': np.random.uniform(0.8, 1.0), 'can': np.random.uniform(0.9, 1.0), 'car': np.random.uniform(0.6, 0.8), 'cal12': np.random.uniform(0.7, 0.8), 'cal13': np.random.uniform(0.7, 0.8) }, 'syn': { 'NMDA': np.random.uniform(0.85, 1.05), 'AMPA': np.random.uniform(0.7, 0.9), 'GABA': np.random.uniform(0.90, 1.1) } } modulation_ACh = { 'intr': { 'naf': np.random.uniform(1.0, 1.2), 'kir': np.random.uniform(0.5, 0.7), 'can': np.random.uniform(0.65, 0.85), 'cal12': np.random.uniform(0.3, 0.7), 'cal13': np.random.uniform(0.3, 0.7), 'Im': np.random.uniform(0.0, 0.4) }, 'syn': { 'NMDA': np.random.uniform(1.0, 1.05), 'AMPA': np.random.uniform(0.99, 1.01), 'GABA': np.random.uniform(0.99, 1.01) } } res[i][ci] = {'factors': {'da': modulation_DA, 'ach': modulation_ACh}} # ACh factor sets used == 0 and 2 (since giving less inward rectification and higher excitability) V = {} for key in modulation_ACh['intr']: V[key] = transient for key in ['glut', 'gaba']: V[key] = transient # Master seed -> reset for all factor combinations #np.random.seed(seed=1000) # TODO no seed... will bg be different over workers? # set bg (constant+ramping). fgaba = 24.0 Syn, nc, ns, mapper = use.set_ramping_stimuli(cell, [], low=modOnTime, high=modOnTime + tau) RAMP = {'s': Syn.copy(), 'nc': nc.copy(), 'ns': ns.copy} Syn, nc, ns = use.set_bg_noise(cell, fglut=12.0, fgaba=fgaba) # Clean DA = modulate.DA(cell, modulation_DA['intr'], modulation='uniform', play=V, syn_dict=modulation_DA['syn']) ACh = modulate.ACh(cell, modulation_ACh['intr'], shift_kaf=0, play=V, syn_dict=modulation_ACh['syn']) for bg in range(nbg): print(cell_index, c, bg) # finalize and run h.finitialize(-80) while h.t < tstop: h.fadvance() # downsample data and store in array if not 'time' in res: res['time'] = [t for ind, t in enumerate(tm) if ind % 4 == 0] res[i][bg] = [vm[ind] for ind, t in enumerate(tm) if ind % 4 == 0] # save with open( 'inVivo_ramping_{}_{}_model{}.json'.format(conditions[ci], tag, cell_index), 'wt') as f: json.dump(res, f, indent=4)
def dpp_DA_modded(model_data, cell_index, run_info, noise=True, HFI=False, HFI_delay=0, dur_and_amp=True, spike=False, mod_tar='all'): ''' Provides clustered glutamatergic input to SPNs to generate the dendritic plateau potential in the absence of modulation. INPUT(S): - model_data: model paramaters (specification, cell type, model sets, and stimulation targets) [dict] - stim_data: stimulation parameters (number of inputs, time of inputs, input inter-spike intervals, time to stop simulating) [dict] - cell_index: cell specification being simulated [int] - run_info: information about the simulation run (this simulation and total number of simulations) [dict] - dur_and_amp: whether to calculate the duration and peak amplitude of the plateau potential (default True) [bool] OUTPUT(S): - data: simulated data including: simulation times; simulated voltages; distance of stimulated target to the soma; rheobase of the model; half-max width of the potential; peak amplitude of the potential; cell specification being simulated; cell type being simulated [dict] - ncon: NetCon object Thomas Binns (author), 13/02/21 ''' # ===== print simulation info to monitor progress ===== print('Simulating cell specification {} of {}'.format( \ run_info['curr_n']+1,run_info['tot_n']),flush = True) # ===== gets stimulation info ===== # clustered inputs clus_info = cf.params_for_input(model_data['cell_type'], 'clustered') clus_params = clus_info['clustered']['params'] # modulation inputs mod_factors = cf.draw_factors_DA(model_data['cell_type'], mode='random') DA_info = cf.params_for_input(model_data['cell_type'], 'DA') DA_params = DA_info['DA']['params'] # gets vector for modulation timing state = [1 if ht >= DA_params['stim_t'] and ht <= DA_params['stop_t'] \ else 0 for ht in np.arange(0,clus_params['stop_t'],h.dt)] state = h.Vector(state) # collates time-dependent mechanism modulation scaling mech_scale = {} for key in mod_factors: mech_scale[key] = state # noise inputs if noise: noise_info = cf.params_for_input(model_data['cell_type'], 'noise') noise_params = noise_info['noise']['params'] # HFIs if HFI: HFI_info = cf.params_for_input(model_data['cell_type'], 'HFI') HFI_params = HFI_info['HFI']['params'] # ===== simulation ===== data = {} for i, clus_tar in enumerate( clus_info['clustered']['target']): # for each simulation target clus_lab = clus_info['clustered']['label'][i] # label for input target data[clus_lab] = {} # get the targets for cholinergic input DA_targets = {} DA_targets['target'] = [clus_tar] DA_targets['label'] = [clus_lab] for j, DA_t in enumerate(DA_info['DA']['target']): DA_targets['target'].append(DA_t) DA_targets['label'].append(DA_info['DA']['label'][j]) target_x = .5 if mod_tar == 'all': DA_targets['target'] = ['all'] DA_targets['label'] = ['all'] target_x = 'all' for j, DA_t in enumerate( DA_targets['target']): # for each cholinergic input target DA_lab = DA_targets['label'][j] # initiate cell cell = build.MSN( params=model_data['specs']['par'], morphology=model_data['specs']['morph'], variables=model_data['model_sets'][cell_index]['variables']) rheobase = model_data['model_sets'][cell_index]['rheobase'] # record vectors tm = h.Vector() tm.record(h._ref_t) vm = h.Vector() vm.record(cell.soma(0.5)._ref_v) # add clustered inputs clus_syn, clus_stim, clus_ncon, clus_d2soma = cf.set_clustered_stim( cell, clus_tar, n=clus_params['stim_n'], act_time=clus_params['stim_t'], ISI=clus_params['isi']) # add background noise if noise: noise_syn, noise_stim, noise_ncon = cf.set_bg_noise( cell, model_data['cell_type'], fglut=noise_params['freq_glut'], fgaba=noise_params['freq_gaba'], dendOnly=noise_params['only dend']) # add high-frequency inputs if HFI: # adds HFI HFI_syn, HFI_stim, HFI_ncon, arrangement = cf.set_HFI( cell, model_data['cell_type'], freq=HFI_params['freq'], n_inputs=HFI_params['n_inputs'], delay=clus_params['stim_t'] + (clus_params['stim_n'] * clus_params['isi']) + HFI_delay, exclude=HFI_info['HFI']['exclude']) # collates data data['HFI'] = arrangement # get cholinergic modulation class modulation = modulate.set_DA(cell, mod_factors, [DA_t], target_x=target_x, play=mech_scale, dt=h.dt) # run simulation h.finitialize(-80) while h.t < clus_params['stop_t'] + HFI_delay + ( clus_params['stim_n'] * clus_params['isi']): h.fadvance() tm = tm.to_python() vm = vm.to_python() # collate data data[clus_lab][DA_lab] = {'vm': vm} data['meta'] = { 'id': int(cell_index), 'round': run_info['round'], 'cell_type': model_data['cell_type'], 'tm': tm, 'rheo': rheobase } # calculate dpp duration and amplitude if dur_and_amp: base_t_start = tm.index( min(tm, key=lambda x: abs(x - (clus_params['stim_t'] + clus_params['pre_t'])))) base_t_end = tm.index( min(tm, key=lambda x: abs(x - clus_params['stim_t']))) base_vm = np.mean(vm[base_t_start:base_t_end]) data[clus_lab][DA_lab]['dur'] = cf.dpp_dur( tm, vm, base_vm, clus_params['stim_t']) data[clus_lab][DA_lab]['amp'] = cf.dpp_amp( tm, vm, base_vm, clus_params['stim_t']) # get spike-related data if spike: thresh = 0 # checks whether spike occured data[clus_lab][DA_lab]['spiked'] = 0 if max(vm) > thresh: data[clus_lab][DA_lab]['spiked'] = 1 return data