def writeSinusoidsConfig(bg_current, modulating_current, G0_exc, sigma_exc, G0_inh, sigma_inh, ai=0, ao=0, duration=30, outfile='sinusoids.xml', infile=''): import shutil writeIPlusBgGConfig(0, {'m': G0_exc, 's': sigma_exc, 'tau': 5, 'seed': 5061983}, {'m': G0_inh, 's': sigma_inh, 'tau': 10, 'seed': 7051983}, ai, ao, duration, outfile, infile) if isinstance(bg_current, float) or isinstance(bg_current,int): if bg_current == 0: # we have only the sinusoidal modulating current current = [[duration,3,modulating_current,'F',0,0,0,0,0,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] else: # sinusoid on top of a DC current current = [[duration,-2,bg_current,0,0,0,0,0,0,1,0,1], [0,-2,modulating_current,'F',0,0,0,0,0,3,1,1], [1,1,0,0,0,0,0,0,0,0,0,1]] else: if bg_current['mean'] == 0 and bg_current['std'] == 0: # we have only the sinusoidal modulating current current = [[duration,3,modulating_current,'F',0,0,0,0,0,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] else: # sinusoid on top of a noisy (OU) current current = [[duration,-2,bg_current['mean'],bg_current['std'],bg_current['tau'],0,0,1,5061983,2,0,1], [0,-2,modulating_current,'F',0,0,0,0,0,3,1,1], [1,1,0,0,0,0,0,0,0,0,0,1]] os.remove('current.stim') shutil.move('gexc.stim','gexc_template.stim') shutil.move('ginh.stim','ginh_template.stim') lcg.writeStimFile('current_template.stim',current,True)
def writeFiles(options): # XML configuration file config = lcg.XMLConfigurationFile(options['sampling_rate'],options['duration']) config.add_entity(lcg.entities.H5Recorder(id=0, connections=(), compress=True)) config.add_entity(lcg.entities.RealNeuron(id=1, connections=(0,4), spikeThreshold=-20, V0=-65, deviceFile=os.environ['COMEDI_DEVICE'], inputSubdevice=os.environ['AI_SUBDEVICE'], outputSubdevice=os.environ['AO_SUBDEVICE'], readChannel=options['ai'], writeChannel=options['ao'], inputConversionFactor=os.environ['AI_CONVERSION_FACTOR_CC'], outputConversionFactor=os.environ['AO_CONVERSION_FACTOR_CC'], inputRange=os.environ['RANGE'], reference=os.environ['GROUND_REFERENCE'], kernelFile='kernel.dat')) config.add_entity(lcg.entities.PID(id=2, connections=(0,1), baseline=options['amplitude'], gp=options['gp'], gi=options['gi'], gd=options['gd'], units='pA')) config.add_entity(lcg.entities.Waveform(id=3, connections=(0,2), filename='frequency.stim', units='Hz')) config.add_entity(lcg.entities.FrequencyEstimator(id=4, connections=(0,2), tau=options['tau'], initial_frequency=options['min_freq'])) if 'current_std' in options: config.add_entity(lcg.entities.Waveform(id=5, connections=(0,1), filename='current.stim', units='pA')) # Noisy current stim-file current = [[options['duration'],2,0,options['current_std'],options['current_tau'],0,0,0,0,0,0,1]] lcg.writeStimFile('current.stim',current,False) config.write(config_file) # Frequency stim-file frequency=[[options['duration'],-2,options['min_freq'],0,0,0,0,0,0,1,0,1], [options['duration'],-2,options['max_freq']-options['min_freq'],0,0,0,0,0,0,7,1,1]] lcg.writeStimFile('frequency.stim',frequency,False)
def run_batch(repetitions, interval, stim_dur, stim_amp, hyperpolarizing_pulse, pre, post, ai, ao, pairing=False, offset=None): try: template_config_file = os.environ['CONFIGURATIONS_PATH'] + '/' + config_file except: template_config_file = os.environ['HOME'] + '/configurations/' + config_file lcg.substituteStrings(template_config_file, config_file, {'TEND': pre+post, 'AI': ai, 'AO_INTRA': ao['intra'], 'AO_EXTRA': ao['extra']}) extra_stim = [[pre,1,0,0,0,0,0,0,0,0,0,1], [stim_dur['extra'],1,stim_amp['extra'],0,0,0,0,0,0,0,0,1], [post-stim_dur['extra'],1,0,0,0,0,0,0,0,0,0,1]] lcg.writeStimFile(extracellular_stim_file, extra_stim, False) if pairing: intra_stim = [[pre+offset,1,0,0,0,0,0,0,0,0,0,1], [stim_dur['intra'],1,stim_amp['intra'],0,0,0,0,0,0,0,0,1], [post-offset-stim_dur['intra']-hyperpolarizing_pulse['dur']-0.1,1,0,0,0,0,0,0,0,0,0,1], [hyperpolarizing_pulse['dur'],1,hyperpolarizing_pulse['amp'],0,0,0,0,0,0,0,0,1], [0.1,1,0,0,0,0,0,0,0,0,0,1]] else: intra_stim = [[pre+post-hyperpolarizing_pulse['dur']-0.1,1,0,0,0,0,0,0,0,0,0,1], [hyperpolarizing_pulse['dur'],1,hyperpolarizing_pulse['amp'],0,0,0,0,0,0,0,0,1], [0.1,1,0,0,0,0,0,0,0,0,0,1]] lcg.writeStimFile(intracellular_stim_file, intra_stim, False) sub.call('lcg kernel -I ' + str(ai) + ' -O ' + str(ao['intra']), shell=True) sub.call(lcg.common.prog_name + ' -c '+ config_file + ' -n ' + str(repetitions) + ' -i ' + str(interval-(pre+post)), shell=True)
def writeGainModulationConfig(G0_exc, sigma_exc, G0_inh, sigma_inh, ai=0, ao=0, duration=5, outfile='gain_modulation.xml', infile=''): writeIPlusBgGConfig(0, { 'm': G0_exc, 's': sigma_exc, 'tau': 5 }, { 'm': G0_inh, 's': sigma_inh, 'tau': 10 }, ai, ao, duration + 3, outfile, infile) os.remove('current.stim') current = [[0.5, 1, 0, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [0.01, 1, -300, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [0.5, 1, 0, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [0.6, 1, -100, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [4, 1, 0, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [duration, 1, 'I', 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [1, 1, 0, 0, 0, 0, 0, 0, 3532765, 0, 0, 1]] lcg.writeStimFile('template.stim', current, None)
def writeSinusoidsConfig(bg_current, modulating_current, G0_exc, sigma_exc, G0_inh, sigma_inh, ai=0, ao=0, duration=30, outfile='sinusoids.xml', infile=''): import shutil writeIPlusBgGConfig(0, { 'm': G0_exc, 's': sigma_exc, 'tau': 5, 'seed': 5061983 }, { 'm': G0_inh, 's': sigma_inh, 'tau': 10, 'seed': 7051983 }, ai, ao, duration, outfile, infile) if isinstance(bg_current, float) or isinstance(bg_current, int): if bg_current == 0: # we have only the sinusoidal modulating current current = [[ duration, 3, modulating_current, 'F', 0, 0, 0, 0, 0, 0, 0, 1 ], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] else: # sinusoid on top of a DC current current = [[duration, -2, bg_current, 0, 0, 0, 0, 0, 0, 1, 0, 1], [ 0, -2, modulating_current, 'F', 0, 0, 0, 0, 0, 3, 1, 1 ], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] else: if bg_current['mean'] == 0 and bg_current['std'] == 0: # we have only the sinusoidal modulating current current = [[ duration, 3, modulating_current, 'F', 0, 0, 0, 0, 0, 0, 0, 1 ], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] else: # sinusoid on top of a noisy (OU) current current = [[ duration, -2, bg_current['mean'], bg_current['std'], bg_current['tau'], 0, 0, 1, 5061983, 2, 0, 1 ], [0, -2, modulating_current, 'F', 0, 0, 0, 0, 0, 3, 1, 1], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] os.remove('current.stim') shutil.move('gexc.stim', 'gexc_template.stim') shutil.move('ginh.stim', 'ginh_template.stim') lcg.writeStimFile('current_template.stim', current, True)
def writefIStim(Imin, Imax, Istep, noisy=False): A = [[0.5, 1, 0, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [0.01, 1, -300, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [0.5, 1, 0, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [0.6, 1, -100, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [1, 1, 0, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [5, 1, 500, 0, 0, 0, 0, 0, 3532765, 0, 0, 1], [0.1, 1, 0, 0, 0, 0, 0, 0, 3532765, 0, 0, 1]] if noisy: A[4, 0] = 4 for k, i in np.arange(Imin, Imax + Istep, Istep): A[5, 2] = i lcg.writeStimFile('fi_%02d.stim' % (k + 1), A, None)
def writeGainModulationConfig(G0_exc, sigma_exc, G0_inh, sigma_inh, ai=0, ao=0, duration=5, outfile='gain_modulation.xml', infile=''): writeIPlusBgGConfig(0, {'m': G0_exc, 's': sigma_exc, 'tau': 5}, {'m': G0_inh, 's': sigma_inh, 'tau': 10}, ai, ao, duration+3, outfile, infile) os.remove('current.stim') current = [[0.5,1,0,0,0,0,0,0,3532765,0,0,1], [0.01,1,-300,0,0,0,0,0,3532765,0,0,1], [0.5,1,0,0,0,0,0,0,3532765,0,0,1], [0.6,1,-100,0,0,0,0,0,3532765,0,0,1], [4,1,0,0,0,0,0,0,3532765,0,0,1], [duration,1,'I',0,0,0,0,0,3532765,0,0,1], [1,1,0,0,0,0,0,0,3532765,0,0,1]] lcg.writeStimFile('template.stim',current,None)
def writefIStim(Imin,Imax,Istep,noisy=False): A = [[0.5,1,0,0,0,0,0,0,3532765,0,0,1], [0.01,1,-300,0,0,0,0,0,3532765,0,0,1], [0.5,1,0,0,0,0,0,0,3532765,0,0,1], [0.6,1,-100,0,0,0,0,0,3532765,0,0,1], [1,1,0,0,0,0,0,0,3532765,0,0,1], [5,1,500,0,0,0,0,0,3532765,0,0,1], [0.1,1,0,0,0,0,0,0,3532765,0,0,1]] if noisy: A[4,0] = 4 for k,i in np.arange(Imin,Imax+Istep,Istep): A[5,2] = i lcg.writeStimFile('fi_%02d.stim' % (k+1), A, None)
def writeGStimFiles(Gexc, Ginh, duration, before, after, outfiles = ['gexc.stim','ginh.stim']): G = [[[before,1,0,0,0,0,0,0,0,0,0,1], [duration,2,Gexc['m'],Gexc['s'],Gexc['tau'],0,0,1,np.random.poisson(10000),0,0,1], [after,1,0,0,0,0,0,0,0,0,0,1]], [[before,1,0,0,0,0,0,0,0,0,0,1], [duration,2,Ginh['m'],Ginh['s'],Ginh['tau'],0,0,1,np.random.poisson(10000),0,0,1], [after,1,0,0,0,0,0,0,0,0,0,1]]] if 'seed' in Gexc: G[0][1][8] = Gexc['seed'] if 'seed' in Ginh: G[1][1][8] = Ginh['seed'] for i,filename in enumerate(outfiles): lcg.writeStimFile(filename,G[i],None)
def main(): opts = parseArgs() writeConfigurationFile(opts) ratio = lcg.computeRatesRatio(Vm=opts['balanced_voltage'], Rin=opts['input_resistance']) Gm_exc, Gm_inh, Gs_exc, Gs_inh = lcg.computeSynapticBackgroundCoefficients( ratio, R_exc=opts['R_exc'], Rin=opts['input_resistance']) gexc = [[opts['pre'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] ginh = [[opts['pre'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] for dr in opts['dR']: if opts['exc']: gm = Gm_exc * (1 + dr) gs = Gs_exc * np.sqrt(1 + dr) gexc.append([ opts['step_duration'], 2, gm, gs, 5, Gm_exc, 0, 0, int(np.random.uniform(high=10000)), 0, 0, 1 ]) ginh.append([ opts['step_duration'], 2, Gm_inh, Gs_inh, 10, Gm_inh, 0, 0, int(np.random.uniform(high=10000)), 0, 0, 1 ]) else: gm = Gm_inh * (1 + dr) gs = Gs_inh * np.sqrt(1 + dr) gexc.append([ opts['step_duration'], 2, Gm_exc, Gs_exc, 5, 0, 0, 0, int(np.random.uniform(high=10000)), 0, 0, 1 ]) ginh.append([ opts['step_duration'], 2, gm, gs, 10, Gm_inh, 0, 0, int(np.random.uniform(high=10000)), 0, 0, 1 ]) gexc.append([opts['post'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) ginh.append([opts['post'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) lcg.writeStimFile(gexc_file, gexc, False) lcg.writeStimFile(ginh_file, ginh, False) while opts['reps'] > 0: reps = min(opts['reps'], opts['kernel_frequency']) sub.call('lcg kernel -I ' + str(opts['ai']) + ' -O ' + str(opts['ao']), shell=True) sub.call(lcg.common.prog_name + ' -c ' + config_file + ' -n ' + str(reps) + ' -i ' + str(opts['interval']), shell=True) opts['reps'] -= reps if opts['reps'] > 0: pass sub.call(['sleep', str(opts['interval'])])
def writePulsesStimFile(f, dur, amp, N=10, delay=1, pulsesInBurst=1, withRecovery=True, filename='pulses.stim'): """ Writes a stimulation file containing a series of pulses, with an optional "recovery" pulse. Parameters: f - frequency of the stimulation dur - duration of the stimulation (!!! in ms !!!) amp - amplitude of the stimulation N - number of repetitions delay - initial and final delay pulsesInBurst - number of pulses in each group withRecovery - whether or not to include a recovery pulse filename - file to write to Returns: The duration of the stimulation. """ stimulus = [[delay,1,0,0,0,0,0,0,5061983,0,0,1]] if type(f) != list: f = [f] if len(f) == 1: f = f*2 stimulus.append([N/f[1],-2,amp,-f[0],dur,0,0,0,5061983,8,0,1]) stimulus.append([0,-2,1,-f[1],pulsesInBurst*(1000./f[0]),0,0,0,5061983,8,2,1]) if withRecovery: stimulus.append([0.5,1,0,0,0,0,0,0,5061983,0,0,1]) stimulus.append([dur,1,amp,0,0,0,0,0,5061983,0,0,1]) stimulus.append([delay,1,0,0,0,0,0,0,5061983,0,0,1]) dur = lcg.writeStimFile(filename, stimulus, None) return dur
def main(): if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help', 'help'): usage() sys.exit(0) opts = parseArgs() ncells = len(opts['ao']) stim_file = [] for ii in range(ncells): stim_file.append('ou_prot%d_%d.stim' % (opts['ai'][ii], opts['ao'][ii])) stimulus = create_ou_stimulus(opts['mean'], opts['std'], opts['tau'], opts['duration'], opts['tail'], opts['preamble']) lcg.writeStimFile(stim_file[ii], stimulus, opts['preamble']) if len(opts['holding']) < 2: opts['holding'] = opts['holding'] * 2 for ai, ao, stim in zip(opts['ai'], opts['ao'], stim_file): if opts['kernel']: sub.call('lcg output ' + str(opts['holding'][0]), shell=True) if not opts['holding'][0] in [0]: sleep(2) if ncells > 1: sub.call('lcg kernel -F ' + str(opts['srate']) + ' -H ' + str(opts['holding'][0]) + ' -a', shell=True) else: sub.call('lcg kernel -F ' + str(opts['srate']) + ' -H ' + str(opts['holding'][0]), shell=True) if not opts['holding'][0] == opts['holding'][1]: sleep(2) sub.call('lcg-stimulus -s ' + stim + ' -i ' + str(opts['interval']) + ' -F ' + str(opts['srate']) + ' -H ' + str(opts['holding'][1]), shell=True) if opts['report']: isim, cv, Vm, Vsd = analyse_last_file() print('Report from the last file') print('Mean firing rate: {0}'.format(1. / isim)) print('Coefficient of variation: {0}'.format(cv)) print('Mean membrane voltage (Vm): {0}'.format(Vm)) print('Standard deviation of Vm: {0}'.format(Vsd))
def main(): if len(sys.argv) < 1: print(help.format(os.path.basename(sys.argv[0]))) sys.exit(0) opts = parseArgs() if not (len(opts['amp']) == len(opts['pw']) == len(opts['freq'])): print( 'amplitude, pulsewidth and frequency must have the same number of arguments.' ) print(help.format(os.path.basename(sys.argv[0]))) sys.exit(1) N = len(opts['amp']) ntrials = np.ceil(opts['nreps'] / N) fnames = ['intra.stim', 'digi.stim'] filename = 'simultaneous.cfg' if not len(opts['ao']) == len(fnames): print('Must have 2 and only 2 AO.') sys.exit(1) cfgFile = createCfg(opts['ai'], opts['ao'], fnames) with open(filename, "w") as fd: fd.write(cfgFile) if opts['kernel']: sub.call('lcg kernel -I ' + str(opts['ai'][0]) + ' -O ' + str(opts['ao'][0]) + ' -F ' + str(opts['srate']) + ' -d 25 -s 150', shell=True) for ii in np.arange(ntrials): print('Trial {} of {}.'.format(int(ii), int(ntrials))) for nn in np.arange(N): lcg.writeStimFile(fnames[0], createIntraStim(opts['dur'], opts['amp'][nn], opts['freq'][nn], opts['pw'][nn], opts['r_in']), addDefaultPreamble=False) lcg.writeStimFile(fnames[1], createDigiStim(opts['dur'], opts['r_in']), addDefaultPreamble=False) sub.call('lcg-non-rt -c ' + filename + ' -F ' + str(opts['srate']), shell=True)
def writeFiles(options): stim_file = 'frequency.stim' config = lcg.XMLConfigurationFile(options['sampling_rate'],options['duration']) config.add_entity(lcg.entities.H5Recorder(id=0, connections=(), compress=True)) config.add_entity(lcg.entities.RealNeuron(id=1, connections=(0,4), spikeThreshold=-20, V0=-65, deviceFile=os.environ['COMEDI_DEVICE'], inputSubdevice=os.environ['AI_SUBDEVICE'], outputSubdevice=os.environ['AO_SUBDEVICE'], readChannel=options['ai'], writeChannel=options['ao'], inputConversionFactor=os.environ['AI_CONVERSION_FACTOR_CC'], outputConversionFactor=os.environ['AO_CONVERSION_FACTOR_CC'], inputRange=os.environ['RANGE'], reference=os.environ['GROUND_REFERENCE'], kernelFile='kernel.dat')) config.add_entity(lcg.entities.PID(id=2, connections=(0,1), baseline=options['I0'], gp=options['gp'], gi=options['gi'], gd=options['gd'])) config.add_entity(lcg.entities.Waveform(id=3, connections=(0,2), filename=stim_file, units='Hz')) config.add_entity(lcg.entities.FrequencyEstimator(id=4, connections=(0,2), tau=options['tau'], initial_frequency=options['target']/2)) if 'Gm_exc' in options and 'Gm_inh' in options and 'Gs_exc' in options and 'Gs_inh' in options: gexc_stim_file = 'gexc.stim' ginh_stim_file = 'ginh.stim' config.add_entity(lcg.entities.Waveform(id=5, connections=(0,7), filename=gexc_stim_file, units='nS')) config.add_entity(lcg.entities.Waveform(id=6, connections=(0,8), filename=ginh_stim_file, units='nS')) config.add_entity(lcg.entities.ConductanceStimulus(id=7, connections=(1), E=0)) config.add_entity(lcg.entities.ConductanceStimulus(id=8, connections=(1), E=-80)) lcg.writeStimFile(gexc_stim_file, [options['duration'],2,options['Gm_exc'],options['Gs_exc'],5,0,0,1,int(np.random.uniform(high=10000)),0,0,1], False) lcg.writeStimFile(ginh_stim_file, [options['duration'],2,options['Gm_inh'],options['Gs_inh'],10,0,0,1,int(np.random.uniform(high=10000)),0,0,1], False) config.write(config_file) lcg.writeStimFile(stim_file, [options['duration'],1,options['target'],0,0,0,0,0,0,0,0,1], False)
def writeGStimFiles(Gexc, Ginh, duration, before, after, outfiles=['gexc.stim', 'ginh.stim']): G = [[[before, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [ duration, 2, Gexc['m'], Gexc['s'], Gexc['tau'], 0, 0, 1, np.random.poisson(10000), 0, 0, 1 ], [after, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]], [[before, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [ duration, 2, Ginh['m'], Ginh['s'], Ginh['tau'], 0, 0, 1, np.random.poisson(10000), 0, 0, 1 ], [after, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]] if 'seed' in Gexc: G[0][1][8] = Gexc['seed'] if 'seed' in Ginh: G[1][1][8] = Ginh['seed'] for i, filename in enumerate(outfiles): lcg.writeStimFile(filename, G[i], None)
def main(): if len(sys.argv) < 2 or sys.argv[1] in ('-h','--help','help'): usage() sys.exit(0) opts = parseArgs() ncells = len(opts['ao']) stim_file = [] for ii in range(ncells): stim_file.append('ou_prot%d_%d.stim'%(opts['ai'][ii],opts['ao'][ii])) stimulus = create_ou_stimulus(opts['mean'],opts['std'], opts['tau'],opts['duration'], opts['tail'],opts['preamble']) lcg.writeStimFile(stim_file[ii], stimulus, opts['preamble']) if len(opts['holding']) < 2: opts['holding'] = opts['holding']*2 for ai,ao,stim in zip(opts['ai'],opts['ao'],stim_file): if opts['kernel']: sub.call('lcg output ' + str(opts['holding'][0]), shell=True) if not opts['holding'][0] in [0]: sleep(2) if ncells>1: sub.call('lcg kernel -F '+ str(opts['srate']) + ' -H ' + str(opts['holding'][0]) + ' -a', shell=True) else: sub.call('lcg kernel -F '+ str(opts['srate']) + ' -H ' + str(opts['holding'][0]), shell=True) if not opts['holding'][0] == opts['holding'][1]: sleep(2) sub.call('lcg-stimulus -s ' + stim + ' -i ' + str(opts['interval']) + ' -F ' + str(opts['srate']) + ' -H ' + str(opts['holding'][1]), shell=True) if opts['report']: isim,cv,Vm,Vsd = analyse_last_file() print('Report from the last file') print('Mean firing rate: {0}'.format(1./isim)) print('Coefficient of variation: {0}'.format(cv)) print('Mean membrane voltage (Vm): {0}'.format(Vm)) print('Standard deviation of Vm: {0}'.format(Vsd))
def main(): if len(sys.argv) < 1: print(help.format(os.path.basename(sys.argv[0]))) sys.exit(0) opts = parseArgs() if not (len(opts['amp']) == len(opts['pw']) == len(opts['freq'])): print('amplitude, pulsewidth and frequency must have the same number of arguments.') print(help.format(os.path.basename(sys.argv[0]))) sys.exit(1) N = len(opts['amp']) ntrials = np.ceil(opts['nreps']/N) fnames = ['intra.stim','digi.stim'] filename = 'simultaneous.cfg' if not len(opts['ao']) == len(fnames): print('Must have 2 and only 2 AO.') sys.exit(1) cfgFile = createCfg(opts['ai'],opts['ao'],fnames) with open(filename, "w") as fd: fd.write(cfgFile) if opts['kernel']: sub.call('lcg kernel -I ' + str(opts['ai'][0]) + ' -O ' + str(opts['ao'][0]) + ' -F '+ str(opts['srate']) + ' -d 25 -s 150', shell=True) for ii in np.arange(ntrials): print('Trial {} of {}.'.format(int(ii),int(ntrials))) for nn in np.arange(N): lcg.writeStimFile(fnames[0],createIntraStim(opts['dur'], opts['amp'][nn], opts['freq'][nn], opts['pw'][nn], opts['r_in']), addDefaultPreamble=False) lcg.writeStimFile(fnames[1],createDigiStim(opts['dur'], opts['r_in']), addDefaultPreamble=False) sub.call('lcg-non-rt -c ' + filename + ' -F '+ str(opts['srate']), shell=True)
def writePulsesStimFile(f, dur, amp, N=10, delay=1, pulsesInBurst=1, withRecovery=True, filename='pulses.stim'): """ Writes a stimulation file containing a series of pulses, with an optional "recovery" pulse. Parameters: f - frequency of the stimulation dur - duration of the stimulation (!!! in ms !!!) amp - amplitude of the stimulation N - number of repetitions delay - initial and final delay pulsesInBurst - number of pulses in each group withRecovery - whether or not to include a recovery pulse filename - file to write to Returns: The duration of the stimulation. """ stimulus = [[delay, 1, 0, 0, 0, 0, 0, 0, 5061983, 0, 0, 1]] if type(f) != list: f = [f] if len(f) == 1: f = f * 2 stimulus.append([N / f[1], -2, amp, -f[0], dur, 0, 0, 0, 5061983, 8, 0, 1]) stimulus.append([ 0, -2, 1, -f[1], pulsesInBurst * (1000. / f[0]), 0, 0, 0, 5061983, 8, 2, 1 ]) if withRecovery: stimulus.append([0.5, 1, 0, 0, 0, 0, 0, 0, 5061983, 0, 0, 1]) stimulus.append([dur, 1, amp, 0, 0, 0, 0, 0, 5061983, 0, 0, 1]) stimulus.append([delay, 1, 0, 0, 0, 0, 0, 0, 5061983, 0, 0, 1]) dur = lcg.writeStimFile(filename, stimulus, None) return dur
def writeIPlusBgGConfig(I, Gexc, Ginh, ai, ao, duration, sampling_rate, outfile): config = lcg.XMLConfigurationFile(sampling_rate, duration+3.61) config.add_entity(lcg.entities.H5Recorder(id=0, connections=(), compress=True)) config.add_entity(lcg.entities.RealNeuron(id=1, connections=(0), spikeThreshold=-20, V0=-65, deviceFile=os.environ['COMEDI_DEVICE'], inputSubdevice=os.environ['AI_SUBDEVICE'], outputSubdevice=os.environ['AO_SUBDEVICE'], readChannel=ai, writeChannel=ao, inputConversionFactor=os.environ['AI_CONVERSION_FACTOR_CC'], outputConversionFactor=os.environ['AO_CONVERSION_FACTOR_CC'], inputRange=os.environ['RANGE'], reference=os.environ['GROUND_REFERENCE'], kernelFile='kernel.dat')) config.add_entity(lcg.entities.Waveform(id=2, connections=(0,1), filename='current.stim', units='pA')) config.add_entity(lcg.entities.Waveform(id=3, connections=(0,5), filename='gexc.stim', units='nS')) config.add_entity(lcg.entities.Waveform(id=4, connections=(0,6), filename='ginh.stim', units='nS')) config.add_entity(lcg.entities.ConductanceStimulus(id=5, connections=(1), E=0.)) config.add_entity(lcg.entities.ConductanceStimulus(id=6, connections=(1), E=-80.)) config.write(outfile) current = [[0.5,1,0,0,0,0,0,0,0,0,0,1], [0.01,1,-300,0,0,0,0,0,0,0,0,1], [0.5,1,0,0,0,0,0,0,0,0,0,1], [0.6,1,-100,0,0,0,0,0,0,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1], [duration,1,I,0,0,0,0,0,0,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] conductance = [[2.61,1,0,0,0,0,0,0,0,0,0,1], [duration,2,1,1,1,0,0,1,0,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] lcg.writeStimFile('current.stim',current,None) conductance[1][2] = Gexc['m'] conductance[1][3] = Gexc['s'] conductance[1][4] = Gexc['tau'] if 'seed' in Gexc: conductance[1][8] = Gexc['seed'] else: conductance[1][8] = np.random.poisson(10000) lcg.writeStimFile('gexc.stim',conductance,None) conductance[1][2] = Ginh['m'] conductance[1][3] = Ginh['s'] conductance[1][4] = Ginh['tau'] if 'seed' in Ginh: conductance[1][8] = Ginh['seed'] else: conductance[1][8] = np.random.poisson(10000) lcg.writeStimFile('ginh.stim',conductance,None)
inputConversionFactor=os.environ['AI_CONVERSION_FACTOR_CC'], outputConversionFactor=os.environ['AO_CONVERSION_FACTOR_CC'], inputRange=os.environ['RANGE'], reference=os.environ['GROUND_REFERENCE'], kernelFile='kernel.dat')) config.add_entity(lcg.entities.Waveform(id=2, connections=(0,3), filename=gexc_stim_file, units='nS')) config.add_entity(lcg.entities.ConductanceStimulus(id=3, connections=(1), E=E_exc)) config.add_entity(lcg.entities.Waveform(id=4, connections=(0,5), filename=ginh_stim_file, units='nS')) config.add_entity(lcg.entities.ConductanceStimulus(id=5, connections=(1), E=E_inh)) config.add_entity(lcg.entities.Waveform(id=6, connections=(0,1), filename=stim_file, units='pA')) config.write(config_file) Gm_exc,Gm_inh,Gs_exc,Gs_inh = lcg.computeSynapticBackgroundCoefficients(R_exc/R_inh,R_exc,Rin=input_resistance) conductance[1][2] = Gm_exc conductance[1][3] = Gs_exc conductance[1][4] = tau_exc lcg.writeStimFile(gexc_stim_file, conductance, False) conductance[1][2] = Gm_inh conductance[1][3] = Gs_inh conductance[1][4] = tau_inh lcg.writeStimFile(ginh_stim_file, conductance, False) for _ in range(nreps): if kernel: sub.call('lcg kernel -I %d -O %d -F %g -H %g --rt yes' % (ai,ao,sampling_rate,holding), shell=True) for i,amp in enumerate(amplitudes): stimulus[row][2] = amp + holding lcg.writeStimFile(stim_file, stimulus, with_preamble, preamble_holding=holding) sub.call(lcg.common.prog_name + ' -V 4 -c ' + config_file, shell=True) if i < nreps*len(amplitudes)-1: sub.call(['sleep', str(interval)])
print e sys.exit(1) if with_preamble: stimulus = [[duration,1,holding,0,0,0,0,0,0,0,0,1], [tail,1,holding,0,0,0,0,0,0,0,0,1]] row = 0 else: stimulus = [[tail,1,holding,0,0,0,0,0,0,0,0,1], [duration,1,holding,0,0,0,0,0,0,0,0,1], [tail,1,holding,0,0,0,0,0,0,0,0,1]] row = 1 for i,amp in enumerate(amplitudes): stimulus[row][2] = amp + holding lcg.writeStimFile('%s/step_%02d.stim' % (stimuli_directory,i+1), stimulus, with_preamble, preamble_holding=holding) if kernel: sub.call('lcg kernel -I %d -O %d -F %g -H %g --rt %s' % (ai,ao,samplf,holding,realtime), shell=True) sub.call('lcg stimulus -d %s -i %g -I %d -O %d -n %d -F %g --rt %s %s' % (stimuli_directory, interval,ai,ao, nreps,samplf, realtime, model), shell=True) if __name__ == '__main__': main()
sys.exit(1) if withRecovery and pause <= 0: print('The interval between pulse train and recovery pulse must positive.') sys.exit(1) if computeKernel: sub.call('lcg kernel -F ' + str(samplingRate) + ' -I ' + str(analogInput[0]) + ' -O ' + str(analogOutput) + \ ' --input-factor ' + str(inputGains[0]) + ' --output-factor ' + str(outputGain) + \ ' --input-units ' + inputUnits[0] + ' --output-units ' + outputUnits + ' --non-rt', shell=True) stim = [[pre,1,0,0,0,0,0,0,0,0,0,1], [nPulses/stimulusFrequency,8,stimulusAmplitude,-stimulusFrequency,stimulusDuration,0,0,0,0,0,0,1]] if withRecovery: stim.append([pause-1./stimulusFrequency,1,0,0,0,0,0,0,0,0,0,1]) stim.append([stimulusDuration*1e-3,1,stimulusAmplitude,0,0,0,0,0,0,0,0,1]) stim.append([post,1,0,0,0,0,0,0,0,0,0,1]) totalDuration = lcg.writeStimFile(stimFile, stim, False) channels = [{'type':'input', 'channel':analogInput[0], 'factor':inputGains[0], 'units':inputUnits[0]}, {'type':'input', 'channel':analogInput[1], 'factor':inputGains[1], 'units':inputUnits[1]}, {'type':'output', 'channel':analogOutput, 'factor':outputGain, 'units':outputUnits, 'stimfile':stimFile}] lcg.writeIOConfigurationFile(configFile,samplingRate,totalDuration,channels) for i in range(nTrials): sub.call(lcg.common.prog_name + ' -c ' + configFile, shell=True) if i < nTrials-1: sub.call('sleep ' + str(interTrialInterval), shell=True) if __name__ == '__main__': main()
if with_preamble: stimulus = [[duration, 1, holding, 0, 0, 0, 0, 0, 0, 0, 0, 1], [tail, 1, holding, 0, 0, 0, 0, 0, 0, 0, 0, 1]] row = 0 else: stimulus = [ [tail, 1, holding, 0, 0, 0, 0, 0, 0, 0, 0, 1], [duration, 1, holding, 0, 0, 0, 0, 0, 0, 0, 0, 1], [tail, 1, holding, 0, 0, 0, 0, 0, 0, 0, 0, 1], ] row = 1 for i, amp in enumerate(amplitudes): stimulus[row][2] = amp + holding lcg.writeStimFile( "%s/step_%02d.stim" % (stimuli_directory, i + 1), stimulus, with_preamble, preamble_holding=holding ) if kernel: sub.call("lcg kernel -I %d -O %d -F %g -H %g --rt %s" % (ai, ao, samplf, holding, realtime), shell=True) sub.call( "lcg stimulus -d %s -i %g -I %d -O %d -n %d -F %g --rt %s %s" % (stimuli_directory, interval, ai, ao, nreps, samplf, realtime, model), shell=True, ) if __name__ == "__main__": main()
def writeFiles(options): stim_file = 'frequency.stim' config = lcg.XMLConfigurationFile(options['sampling_rate'], options['duration']) config.add_entity( lcg.entities.H5Recorder(id=0, connections=(), compress=True)) config.add_entity( lcg.entities.RealNeuron( id=1, connections=(0, 4), spikeThreshold=-20, V0=-65, deviceFile=os.environ['COMEDI_DEVICE'], inputSubdevice=os.environ['AI_SUBDEVICE'], outputSubdevice=os.environ['AO_SUBDEVICE'], readChannel=options['ai'], writeChannel=options['ao'], inputConversionFactor=os.environ['AI_CONVERSION_FACTOR_CC'], outputConversionFactor=os.environ['AO_CONVERSION_FACTOR_CC'], inputRange=os.environ['RANGE'], reference=os.environ['GROUND_REFERENCE'], kernelFile='kernel.dat')) config.add_entity( lcg.entities.PID(id=2, connections=(0, 1), baseline=options['I0'], gp=options['gp'], gi=options['gi'], gd=options['gd'])) config.add_entity( lcg.entities.Waveform(id=3, connections=(0, 2), filename=stim_file, units='Hz')) config.add_entity( lcg.entities.FrequencyEstimator(id=4, connections=(0, 2), tau=options['tau'], initial_frequency=options['target'] / 2)) if 'Gm_exc' in options and 'Gm_inh' in options and 'Gs_exc' in options and 'Gs_inh' in options: gexc_stim_file = 'gexc.stim' ginh_stim_file = 'ginh.stim' config.add_entity( lcg.entities.Waveform(id=5, connections=(0, 7), filename=gexc_stim_file, units='nS')) config.add_entity( lcg.entities.Waveform(id=6, connections=(0, 8), filename=ginh_stim_file, units='nS')) config.add_entity( lcg.entities.ConductanceStimulus(id=7, connections=(1), E=0)) config.add_entity( lcg.entities.ConductanceStimulus(id=8, connections=(1), E=-80)) lcg.writeStimFile(gexc_stim_file, [ options['duration'], 2, options['Gm_exc'], options['Gs_exc'], 5, 0, 0, 1, int(np.random.uniform(high=10000)), 0, 0, 1 ], False) lcg.writeStimFile(ginh_stim_file, [ options['duration'], 2, options['Gm_inh'], options['Gs_inh'], 10, 0, 0, 1, int(np.random.uniform(high=10000)), 0, 0, 1 ], False) config.write(config_file) lcg.writeStimFile( stim_file, [options['duration'], 1, options['target'], 0, 0, 0, 0, 0, 0, 0, 0, 1], False)
def main(): mode = None if len(sys.argv) < 2 or sys.argv[1] in ('-h','--help','help'): usage() sys.exit(0) mode = sys.argv[1] if mode != 'current' and mode != 'conductance': print('Unknown working mode: [%s].' % sys.argv[1]) sys.exit(1) opts = parseGlobalArgs() if mode == 'current': opts = dict(parseCurrentModeArgs(), **opts) if opts['separate'] and (type(opts['ao']) == int or type(opts['ai']) == int or \ len(opts['ao']) == 1 or len(opts['ai']) == 1): print('When using the --separate options, two channels must be specified (use the -I and -O options).') sys.exit(1) else: opts = dict(parseConductanceModeArgs(), **opts) if (mode == 'current' and opts['with_bg']) or mode == 'conductance': ratio = lcg.computeRatesRatio(Vm=opts['balanced_voltage'], Rin=opts['input_resistance']) Gm_exc,Gm_inh,Gs_exc,Gs_inh = lcg.computeSynapticBackgroundCoefficients(ratio, R_exc=opts['R_exc'], Rin=opts['input_resistance']) opts['Gm_exc'] = Gm_exc opts['Gm_inh'] = Gm_inh else: # no background conductances, it will be a current-clamp experiment gexc = None ginh = None if mode == 'current': if opts['with_bg']: # background conductances only gexc = [[2.61,1,0,0,0,0,0,0,0,0,0,1], [opts['duration'],2,Gm_exc,Gs_exc,5,0,0,1,random_seed,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] ginh = [[2.61,1,0,0,0,0,0,0,0,0,0,1], [opts['duration'],2,Gm_inh,Gs_inh,10,0,0,1,random_seed,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] if opts['mean'] == 0 and opts['std'] == 0 and opts['tau'] == 0: # sinusoidal modulating current only if opts['separate']: current = [[opts['duration'],1,0,0,0,0,0,1,random_seed,0,0,1], # OU current [1,1,0,0,0,0,0,0,0,0,0,1]] modulation = [[opts['duration'],3,opts['I_modul'],frequency_value,0,0,0,0,0,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] else: current = [[opts['duration'],3,opts['I_modul'],frequency_value,0,0,0,0,0,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] elif opts['tau'] == 0: # sinusoid on top of a DC current if opts['separate']: current = [[opts['duration'],1,opts['mean'],0,0,0,0,0,random_seed,0,0,1], # OU current [1,1,0,0,0,0,0,0,0,0,0,1]] modulation = [[opts['duration'],3,opts['I_modul'],frequency_value,0,0,0,0,0,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] else: current = [[opts['duration'],-2,opts['mean'],0,0,0,0,0,0,1,0,1], [0,-2,opts['I_modul'],frequency_value,0,0,0,0,0,3,1,1], [1,1,0,0,0,0,0,0,0,0,0,1]] else: # sinusoid on top of a noisy (OU) current if opts['separate']: current = [[opts['duration'],2,opts['mean'],opts['std'],opts['tau'],0,0,1,random_seed,0,0,1], # OU current [1,1,0,0,0,0,0,0,0,0,0,1]] modulation = [[opts['duration'],3,opts['I_modul'],frequency_value,0,0,0,0,0,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] else: current = [[opts['duration'],-2,opts['mean'],opts['std'],opts['tau'],0,0,1,random_seed,2,0,1], # OU current [0,-2,opts['I_modul'],frequency_value,0,0,0,0,0,3,1,1], [1,1,0,0,0,0,0,0,0,0,0,1]] else: # current just for the preamble current = [[opts['duration']+1,1,0,0,0,0,0,0,0,0,0,1]] # conductances opts['R_inh'] = opts['R_exc']/ratio if opts['exc']: gexc = createSinusoidallyModOU(frequency_value, 'exc', random_seed, opts) else: gexc = [{'matrix': [[2.61,1,0,0,0,0,0,0,0,0,0,1], [opts['duration'],2,Gm_exc,Gs_exc,5,0,0,1,random_seed,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]], 'filename': 'gexc.stim'}] if opts['inh']: ginh = createSinusoidallyModOU(frequency_value, 'inh', random_seed, opts) else: ginh = [{'matrix': [[2.61,1,0,0,0,0,0,0,0,0,0,1], [opts['duration'],2,Gm_inh,Gs_inh,10,0,0,1,random_seed,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]], 'filename': 'ginh.stim'}] if gexc and ginh: writeConfigurationFile(opts) cnt = 0 tot = opts['reps']*len(opts['frequencies']) for i in range(opts['reps']): np.random.shuffle(opts['frequencies']) for f in opts['frequencies']: if opts['compute_kernel'] and cnt%opts['kernel_frequency'] == 0: if 'separate' in opts and opts['separate']: # compute a kernel for each channel sub.call('lcg kernel -I ' + str(opts['ai'][0]) + ' -O ' + str(opts['ao'][0]) + ' -F '+ str(opts['sampling_rate']) + ' --non-rt --append', shell=True) sub.call('lcg kernel -I ' + str(opts['ai'][1]) + ' -O ' + str(opts['ao'][1]) + ' -F '+ str(opts['sampling_rate']) + ' --non-rt --append', shell=True) pass else: sub.call('lcg kernel -I ' + str(opts['ai']) + ' -O ' + str(opts['ao']) + ' -F '+ str(opts['sampling_rate']), shell=True) cnt = cnt+1 print('[%02d/%02d] F = %g Hz.' % (cnt,tot,f)) I = copy.deepcopy(current) replaceValue(I, random_seed) replaceValue(I, frequency_value, f) lcg.writeStimFile(current_file, I, preamble=True) if 'separate' in opts and opts['separate']: I = copy.deepcopy(modulation) replaceValue(I, frequency_value, f) lcg.writeStimFile(modulation_file, I, preamble=[0,0]) if gexc and ginh: for stimulus in gexc: G = copy.deepcopy(stimulus['matrix']) replaceValue(G, random_seed) replaceValue(G, frequency_value, f) lcg.writeStimFile(stimulus['filename'], G) for stimulus in ginh: G = copy.deepcopy(stimulus['matrix']) replaceValue(G, random_seed) replaceValue(G, frequency_value, f) lcg.writeStimFile(stimulus['filename'], G) sub.call(lcg.common.prog_name + ' -V 3 -c ' + config_file, shell=True) else: if 'separate' in opts and opts['separate']: channels = [{'type':'input', 'channel':opts['ai'][0]},{'type':'input', 'channel':opts['ai'][1]}, {'type':'output', 'channel':opts['ao'][0], 'stimfile':current_file}, {'type':'output', 'channel':opts['ao'][1], 'stimfile':modulation_file}] lcg.writeIOConfigurationFile(config_file,opts['sampling_rate'],opts['duration']+3.61,channels) sub.call(lcg.common.prog_name + ' -c ' + config_file, shell=True) else: sub.call('lcg stimulus -s ' + current_file + ' -F '+ str(opts['sampling_rate']), shell=True) if cnt != tot: sub.call(['sleep', str(opts['interval'])])
' --input-units ' + inputUnits[0] + ' --output-units ' + outputUnits + ' --non-rt', shell=True) stim = [[pre, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [ nPulses / stimulusFrequency, 8, stimulusAmplitude, -stimulusFrequency, stimulusDuration, 0, 0, 0, 0, 0, 0, 1 ]] if withRecovery: stim.append( [pause - 1. / stimulusFrequency, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) stim.append([ stimulusDuration * 1e-3, 1, stimulusAmplitude, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]) stim.append([post, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]) totalDuration = lcg.writeStimFile(stimFile, stim, False) channels = [{ 'type': 'input', 'channel': analogInput[0], 'factor': inputGains[0], 'units': inputUnits[0] }, { 'type': 'input', 'channel': analogInput[1], 'factor': inputGains[1], 'units': inputUnits[1] }, { 'type': 'output', 'channel': analogOutput, 'factor': outputGain, 'units': outputUnits,
def main(): mode = None if len(sys.argv) < 2 or sys.argv[1] in ('-h','--help','help'): usage() sys.exit(0) mode = sys.argv[1] if mode != 'current' and mode != 'conductance': print('Unknown working mode: [%s].' % sys.argv[1]) sys.exit(1) opts = parseGlobalArgs() if mode == 'current': opts = dict(parseCurrentModeArgs(), **opts) tot = len(opts['correlation_coefficients']) * opts['reps'] stim = [[opts['before'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [opts['duration'], -2, opts['current_mean'], 0, opts['current_tau'], 0, 0, 1, 0, 2, 0, 1], # indipendent part [0, -2, 0, 0, opts['current_tau'], 0, 0, 1, 0, 2, 1, 1], # common part [opts['after'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] I = {'m': 0, 's': 0, 'mc': 0, 'sc': 0} np.random.seed(5061983) I_seeds = map(int, np.random.uniform(low=0, high=10000, size=opts['reps'])) else: opts = dict(parseConductanceModeArgs(), **opts) writeConfigFile(opts) tot = len(opts['balanced_voltages']) * len(opts['correlation_coefficients']) * opts['reps'] stim = [[opts['before'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [opts['duration'], 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1], [opts['after'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] gampa = {'m': 0, 's': 0, 'mc': 0, 'sc': 0} ggaba = {'m': 0, 's': 0, 'mc': 0, 'sc': 0} np.random.seed(5061983) ampa_seeds = map(int, np.random.uniform(low=0, high=10000, size=opts['reps'])) np.random.seed(7051983) gaba_seeds = map(int, np.random.uniform(low=0, high=10000, size=opts['reps'])) if opts['with_nmda']: np.random.seed(723587) nmda_seeds = map(int, np.random.uniform(low=0, high=10000, size=opts['reps'])) np.random.seed(int(time.time())) np.random.shuffle(opts['correlation_coefficients']) cnt = 0 for c in opts['correlation_coefficients']: if mode == 'current': stim[1][3] = np.sqrt(1-c)*opts['current_std'] stim[2][3] = np.sqrt(c)*opts['current_std'] for k in range(opts['reps']): if cnt%opts['kernel_frequency'] == 0: sub.call('lcg kernel -I ' + str(opts['ai']) + ' -O ' + str(opts['ao']), shell=True) stim[1][8] = int(np.random.uniform(low=0, high=100*opts['reps'])) stim[2][8] = I_seeds[k] lcg.writeStimFile(stim_files['current'], stim, False) sub.call('lcg vcclamp -V 4 -f ' + stim_files['current'], shell=True) sub.call(['sleep', str(opts['interval'])]) cnt = cnt+1 if cnt%10 == 0: print('[%02d/%02d]' % (cnt,tot)) else: np.random.shuffle(opts['balanced_voltages']) for v in opts['balanced_voltages']: ratio = lcg.computeRatesRatio(Vm=v, Rin=opts['input_resistance']) gampa['m'],ggaba['m'],gampa['s'],ggaba['s'] = lcg.computeSynapticBackgroundCoefficients( ratio,R_exc=ratio*(1-c)*opts['R_inh'],Rin=opts['input_resistance']) gampa['mc'],ggaba['mc'],gampa['sc'],ggaba['sc'] = lcg.computeSynapticBackgroundCoefficients( ratio,R_exc=ratio*c*opts['R_inh'],Rin=opts['input_resistance']) for k in range(opts['reps']): current_ampa_seed = int(np.random.uniform(low=0, high=100*opts['reps'])) stim[1][2] = gampa['m'] stim[1][3] = gampa['s'] stim[1][4] = 5 stim[1][8] = current_ampa_seed lcg.writeStimFile(stim_files['gampa'], stim, False) stim[1][2] = ggaba['m'] stim[1][3] = ggaba['s'] stim[1][4] = 10 stim[1][8] = int(np.random.uniform(low=0, high=100*opts['reps'])) lcg.writeStimFile(stim_files['ggaba'], stim, False) stim[1][2] = gampa['mc'] stim[1][3] = gampa['sc'] stim[1][4] = 5 stim[1][8] = ampa_seeds[k] lcg.writeStimFile(stim_files['gampa_common'], stim, False) stim[1][2] = ggaba['mc'] stim[1][3] = ggaba['sc'] stim[1][4] = 10 stim[1][8] = gaba_seeds[k] lcg.writeStimFile(stim_files['ggaba_common'], stim, False) if opts['with_nmda']: stim[1][2] = gampa['m'] stim[1][3] = gampa['s'] stim[1][4] = opts['nmda_tau'] stim[1][8] = current_ampa_seed lcg.writeStimFile(stim_files['gnmda'], stim, False) stim[1][2] = gampa['m'] stim[1][3] = gampa['s'] stim[1][4] = opts['nmda_tau'] stim[1][8] = ampa_seeds[k] lcg.writeStimFile(stim_files['gnmda_common'], stim, False) if cnt%opts['kernel_frequency'] == 0: sub.call('lcg kernel -I ' + str(opts['ai']) + ' -O ' + str(opts['ao']), shell=True) cnt = cnt+1 sub.call(lcg.common.prog_name + ' -V 4 -c ' + config_file, shell=True) sub.call(['sleep', str(opts['interval'])]) if cnt%10 == 0: print('[%02d/%02d]' % (cnt,tot))
def writeIPlusBgGConfig(I, Gexc, Ginh, ai, ao, duration, sampling_rate, outfile): config = lcg.XMLConfigurationFile(sampling_rate, duration + 3.61) config.add_entity( lcg.entities.H5Recorder(id=0, connections=(), compress=True)) config.add_entity( lcg.entities.RealNeuron( id=1, connections=(0), spikeThreshold=-20, V0=-65, deviceFile=os.environ['COMEDI_DEVICE'], inputSubdevice=os.environ['AI_SUBDEVICE'], outputSubdevice=os.environ['AO_SUBDEVICE'], readChannel=ai, writeChannel=ao, inputConversionFactor=os.environ['AI_CONVERSION_FACTOR_CC'], outputConversionFactor=os.environ['AO_CONVERSION_FACTOR_CC'], inputRange=os.environ['RANGE'], reference=os.environ['GROUND_REFERENCE'], kernelFile='kernel.dat')) config.add_entity( lcg.entities.Waveform(id=2, connections=(0, 1), filename='current.stim', units='pA')) config.add_entity( lcg.entities.Waveform(id=3, connections=(0, 5), filename='gexc.stim', units='nS')) config.add_entity( lcg.entities.Waveform(id=4, connections=(0, 6), filename='ginh.stim', units='nS')) config.add_entity( lcg.entities.ConductanceStimulus(id=5, connections=(1), E=0.)) config.add_entity( lcg.entities.ConductanceStimulus(id=6, connections=(1), E=-80.)) config.write(outfile) current = [[0.5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0.01, 1, -300, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0.5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [0.6, 1, -100, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [duration, 1, I, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] conductance = [[2.61, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [duration, 2, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1], [1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] lcg.writeStimFile('current.stim', current, None) conductance[1][2] = Gexc['m'] conductance[1][3] = Gexc['s'] conductance[1][4] = Gexc['tau'] if 'seed' in Gexc: conductance[1][8] = Gexc['seed'] else: conductance[1][8] = np.random.poisson(10000) lcg.writeStimFile('gexc.stim', conductance, None) conductance[1][2] = Ginh['m'] conductance[1][3] = Ginh['s'] conductance[1][4] = Ginh['tau'] if 'seed' in Ginh: conductance[1][8] = Ginh['seed'] else: conductance[1][8] = np.random.poisson(10000) lcg.writeStimFile('ginh.stim', conductance, None)
def main(): mode = None if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help', 'help'): usage() sys.exit(0) mode = sys.argv[1] if mode != 'current' and mode != 'conductance': print('Unknown working mode: [%s].' % sys.argv[1]) sys.exit(1) opts = parseGlobalArgs() if mode == 'current': opts = dict(parseCurrentModeArgs(), **opts) tot = len(opts['correlation_coefficients']) * opts['reps'] stim = [ [opts['before'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [ opts['duration'], -2, opts['current_mean'], 0, opts['current_tau'], 0, 0, 1, 0, 2, 0, 1 ], # indipendent part [0, -2, 0, 0, opts['current_tau'], 0, 0, 1, 0, 2, 1, 1], # common part [opts['after'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] ] I = {'m': 0, 's': 0, 'mc': 0, 'sc': 0} np.random.seed(5061983) I_seeds = map(int, np.random.uniform(low=0, high=10000, size=opts['reps'])) else: opts = dict(parseConductanceModeArgs(), **opts) writeConfigFile(opts) tot = len(opts['balanced_voltages']) * len( opts['correlation_coefficients']) * opts['reps'] stim = [[opts['before'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [opts['duration'], 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1], [opts['after'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] gampa = {'m': 0, 's': 0, 'mc': 0, 'sc': 0} ggaba = {'m': 0, 's': 0, 'mc': 0, 'sc': 0} np.random.seed(5061983) ampa_seeds = map( int, np.random.uniform(low=0, high=10000, size=opts['reps'])) np.random.seed(7051983) gaba_seeds = map( int, np.random.uniform(low=0, high=10000, size=opts['reps'])) if opts['with_nmda']: np.random.seed(723587) gnmda = {'m': 0, 's': 0, 'mc': 0, 'sc': 0} nmda_seeds = map( int, np.random.uniform(low=0, high=10000, size=opts['reps'])) np.random.seed(int(time.time())) np.random.shuffle(opts['correlation_coefficients']) cnt = 0 for c in opts['correlation_coefficients']: if mode == 'current': stim[1][3] = np.sqrt(1 - c) * opts['current_std'] stim[2][3] = np.sqrt(c) * opts['current_std'] for k in range(opts['reps']): if cnt % opts['kernel_frequency'] == 0: sub.call('lcg kernel -I ' + str(opts['ai']) + ' -O ' + str(opts['ao']), shell=True) stim[1][8] = int( np.random.uniform(low=0, high=100 * opts['reps'])) stim[2][8] = I_seeds[k] lcg.writeStimFile(stim_files['current'], stim, False) sub.call('lcg vcclamp -V 4 -f ' + stim_files['current'], shell=True) sub.call(['sleep', str(opts['interval'])]) cnt = cnt + 1 if cnt % 10 == 0: print('[%02d/%02d]' % (cnt, tot)) else: np.random.shuffle(opts['balanced_voltages']) if opts['with_nmda']: gnmda['m'] = (1 - c) * opts['nmda_mean'] gnmda['mc'] = c * opts['nmda_mean'] gnmda['s'] = np.sqrt(1 - c) * opts['nmda_std'] gnmda['sc'] = np.sqrt(c) * opts['nmda_std'] for v in opts['balanced_voltages']: ratio = lcg.computeRatesRatio(Vm=v, Rin=opts['input_resistance']) gampa['m'], ggaba['m'], gampa['s'], ggaba[ 's'] = lcg.computeSynapticBackgroundCoefficients( ratio, R_exc=ratio * (1 - c) * opts['R_inh'], Rin=opts['input_resistance']) gampa['mc'], ggaba['mc'], gampa['sc'], ggaba[ 'sc'] = lcg.computeSynapticBackgroundCoefficients( ratio, R_exc=ratio * c * opts['R_inh'], Rin=opts['input_resistance']) Gm_ampa, Gm_gaba, Gs_ampa, Gs_gaba = lcg.computeSynapticBackgroundCoefficients( ratio, R_exc=ratio * opts['R_inh'], Rin=opts['input_resistance']) if opts['only_ampa_corr']: ggaba['m'] = ggaba['m'] + ggaba['mc'] ggaba['s'] = np.sqrt(ggaba['s']**2 + ggaba['sc']**2) ggaba['mc'] = 0 ggaba['sc'] = 0 for k in range(opts['reps']): stim[1][2] = gampa['m'] stim[1][3] = gampa['s'] stim[1][4] = 5 stim[1][8] = int( np.random.uniform(low=0, high=100 * opts['reps'])) lcg.writeStimFile(stim_files['gampa'], stim, False) stim[1][2] = ggaba['m'] stim[1][3] = ggaba['s'] stim[1][4] = 10 stim[1][8] = int( np.random.uniform(low=0, high=100 * opts['reps'])) lcg.writeStimFile(stim_files['ggaba'], stim, False) stim[1][2] = gampa['mc'] stim[1][3] = gampa['sc'] stim[1][4] = 5 stim[1][8] = ampa_seeds[k] lcg.writeStimFile(stim_files['gampa_common'], stim, False) if not opts['only_ampa_corr']: stim[1][2] = ggaba['mc'] stim[1][3] = ggaba['sc'] stim[1][4] = 10 stim[1][8] = gaba_seeds[k] lcg.writeStimFile(stim_files['ggaba_common'], stim, False) if opts['with_nmda']: stim[1][2] = gnmda['m'] stim[1][3] = gnmda['s'] stim[1][4] = opts['nmda_tau'] stim[1][8] = int( np.random.uniform(low=0, high=100 * opts['reps'])) lcg.writeStimFile(stim_files['gnmda'], stim, False) stim[1][2] = gnmda['m'] stim[1][3] = gnmda['s'] stim[1][4] = opts['nmda_tau'] stim[1][8] = nmda_seeds[k] lcg.writeStimFile(stim_files['gnmda_common'], stim, False) if cnt % opts['kernel_frequency'] == 0: sub.call('lcg kernel -I ' + str(opts['ai']) + ' -O ' + str(opts['ao']), shell=True) cnt = cnt + 1 sub.call(lcg.common.prog_name + ' -V 4 -c ' + config_file, shell=True) sub.call(['sleep', str(opts['interval'])]) if cnt % 10 == 0: print('[%02d/%02d]' % (cnt, tot))
if duration <= 0. or amplitude <= 0.: print('Duration and amplitude of the stimulation must be positive.') sys.exit(1) if ai < 0 or ao < 0: print('I/O channels must be non-negative.') sys.exit(1) if append: suffix = '-' + str(ai) + '-' + str(ao) else: suffix = '' stim = [[duration,11,0,amplitude,0,0,0,1,int(rnd.uniform(high=10000)),0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] lcg.writeStimFile(stim_file,stim,True) channels = [{'type':'input', 'channel':ai, 'factor':input_factor, 'units':input_units}, {'type':'output', 'channel':ao, 'factor':output_factor, 'units':output_units, 'stimfile':stim_file}] lcg.writeIOConfigurationFile(config_file,sampling_rate,duration+3.61,channels,realtime) oldfiles = glob.glob('*.h5') sub.call(lcg.common.prog_name + ' -c ' + config_file, shell=True) try: os.system('beep') except: pass files = glob.glob('*.h5') for ff in files: if ff not in oldfiles: data_file = ff lcg.computeElectrodeKernel(os.path.abspath(data_file)) try:
def run_batch(repetitions, interval, stim_dur, stim_amp, hyperpolarizing_pulse, pre, post, ai, ao, pairing=False, offset=None): try: template_config_file = os.environ[ 'CONFIGURATIONS_PATH'] + '/' + config_file except: template_config_file = os.environ[ 'HOME'] + '/configurations/' + config_file lcg.substituteStrings( template_config_file, config_file, { 'TEND': pre + post, 'AI': ai, 'AO_INTRA': ao['intra'], 'AO_EXTRA': ao['extra'] }) extra_stim = [[ pre, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ], [stim_dur['extra'], 1, stim_amp['extra'], 0, 0, 0, 0, 0, 0, 0, 0, 1], [post - stim_dur['extra'], 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] lcg.writeStimFile(extracellular_stim_file, extra_stim, False) if pairing: intra_stim = [[pre + offset, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], [ stim_dur['intra'], 1, stim_amp['intra'], 0, 0, 0, 0, 0, 0, 0, 0, 1 ], [ post - offset - stim_dur['intra'] - hyperpolarizing_pulse['dur'] - 0.1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ], [ hyperpolarizing_pulse['dur'], 1, hyperpolarizing_pulse['amp'], 0, 0, 0, 0, 0, 0, 0, 0, 1 ], [0.1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] else: intra_stim = [[ pre + post - hyperpolarizing_pulse['dur'] - 0.1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ], [ hyperpolarizing_pulse['dur'], 1, hyperpolarizing_pulse['amp'], 0, 0, 0, 0, 0, 0, 0, 0, 1 ], [0.1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]] lcg.writeStimFile(intracellular_stim_file, intra_stim, False) sub.call('lcg kernel -I ' + str(ai) + ' -O ' + str(ao['intra']), shell=True) sub.call(lcg.common.prog_name + ' -c ' + config_file + ' -n ' + str(repetitions) + ' -i ' + str(interval - (pre + post)), shell=True)