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 deflection_error(weight, target, templateFile, trials=10, window=30e-3, ai=int(os.environ['AI_CHANNEL']), ao=int(os.environ['AO_CHANNEL'])): try: w = weight[0] except: w = weight lcg.substituteStrings( templateFile, 'psp.xml', { '<weight>0</weight>': '<weight>' + str(w) + '</weight>', 'AI': str(ai), 'AO': str(ao) }) sub.call(lcg.common.prog_name + ' -c psp.xml -V 4 -n ' + str(trials), shell=True) # get the file list files = glob.glob('*.h5') files.sort() files = files[-trials:] # read the first file to allocate memory entities, info = lcg.loadH5Trace(files[0]) for ntt in entities: if ntt['name'] == 'RealNeuron' or ntt['id'] == 4: post = ntt elif ntt['name'] == 'LIFNeuron': pre = ntt elif ntt['name'] == 'Waveform': t0 = ntt['metadata'][0][0] #if max(pre['data']) < -50: # no spike in the presynaptic # print('>>> No spike in the presynaptic neuron. <<<') # sys.exit(1) # allocate memory t = np.arange(0, info['dt'] * len(post['data']), info['dt']) idx = np.nonzero(t < t0)[0] dV = np.zeros((trials, len(post['data']))) dV[0, :] = post['data'] - np.mean(post['data'][idx]) for k in range(1, trials): entities, info = lcg.loadH5Trace(files[k]) for ntt in entities: if ntt['name'] == 'RealNeuron' or ntt['id'] == 4: dV[k, :] = ntt['data'] - np.mean(ntt['data'][idx]) break dV = np.mean(dV, 0) idx = np.intersect1d(np.nonzero(t > t0)[0], np.nonzero(t < t0 + window)[0]) deflection = np.max(np.abs(dV[idx])) print('weight = %.3f -> deflection = %.3f mV' % (weight, deflection)) return (deflection - target)**2
def deflection_error(weight, target, templateFile, trials=10, window=30e-3, ai=int(os.environ['AI_CHANNEL']), ao=int(os.environ['AO_CHANNEL'])): try: w = weight[0] except: w = weight lcg.substituteStrings(templateFile, 'psp.xml', {'<weight>0</weight>': '<weight>' + str(w) + '</weight>', 'AI': str(ai), 'AO': str(ao)}) sub.call(lcg.common.prog_name + ' -c psp.xml -V 4 -n ' + str(trials), shell=True) # get the file list files = glob.glob('*.h5') files.sort() files = files[-trials:] # read the first file to allocate memory entities,info = lcg.loadH5Trace(files[0]) for ntt in entities: if ntt['name'] == 'RealNeuron' or ntt['id'] == 4: post = ntt elif ntt['name'] == 'LIFNeuron': pre = ntt elif ntt['name'] == 'Waveform': t0 = ntt['metadata'][0][0] #if max(pre['data']) < -50: # no spike in the presynaptic # print('>>> No spike in the presynaptic neuron. <<<') # sys.exit(1) # allocate memory t = np.arange(0, info['dt']*len(post['data']), info['dt']) idx = np.nonzero(t < t0)[0] dV = np.zeros((trials,len(post['data']))) dV[0,:] = post['data'] - np.mean(post['data'][idx]) for k in range(1,trials): entities,info = lcg.loadH5Trace(files[k]) for ntt in entities: if ntt['name'] == 'RealNeuron' or ntt['id'] == 4: dV[k,:] = ntt['data'] - np.mean(ntt['data'][idx]) break dV = np.mean(dV,0) idx = np.intersect1d(np.nonzero(t>t0)[0], np.nonzero(t<t0+window)[0]) deflection = np.max(np.abs(dV[idx])) print('weight = %.3f -> deflection = %.3f mV' % (weight,deflection)) return (deflection - target)**2
if config_file == None: try: template_file = os.environ[ 'CONFIGURATIONS_PATH'] + '/reliability_disynaptic_current.xml' except: template_file = os.environ[ 'HOME'] + '/configurations/reliability_disynaptic_current.xml' if os.path.isfile(template_file): config_file = 'reliability_disynaptic.xml' lcg.substituteStrings( template_file, config_file, { '<weight>0</weight>': '<weight>' + str(weight) + '</weight>', '<E>-80</E>': '<E>' + str(E) + '</E>', '<tauRise>0</tauRise>': '<tauRise>' + str(tau_r) + '</tauRise>', '<tauDecay>0</tauDecay>': '<tauDecay>' + str(tau_d) + '</tauDecay>', '<tend>0</tend>': '<tend>' + str(np.sum(stimulus, 0)[0]) + '</tend>' }) else: print('Default configuration file [%s] missing.' % template_file) usage() sys.exit(2) writeStimFile('current.stim', stimulus) sub.call('lcg kernel -I ' + str(ai) + ' -O ' + str(ao), shell=True) sub.call(lcg.common.prog_name + ' -V 3 -c ' + config_file + ' -n ' + str(trials) + ' -i ' + str(interval),
print('Vmin must be smaller than Vmax.') usage() sys.exit(1) if configFile == None: try: templateFile = os.environ[ 'CONFIGURATIONS_PATH'] + '/in_vivo_like.xml' except: templateFile = os.environ[ 'HOME'] + '/configurations/in_vivo_like.xml' if os.path.isfile(templateFile): configFile = 'cv.xml' lcg.substituteStrings( templateFile, configFile, { '<maxCount>0</maxCount>': '<maxCount>' + str(nspikes) + '</maxCount>', '<tend>0</tend>': '<tend>' + str(duration) + '</tend>' }) else: print('Default configuration file [%s] missing.' % templateFile) usage() sys.exit(2) Vm = np.arange(Vmin, Vmax + Vstep / 2, Vstep) rates_exc = np.array([rate]) for i in range(repetitions): np.random.shuffle(Vm) sub.call('lcg kernel -I ' + str(ai) + ' -O ' + str(ao), shell=True) run(Vm, Rm, rates_exc, duration, interval, configFile)
[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,2,I_mean,I_std,I_tau,0,0,1,seed,0,0,1], [1,1,0,0,0,0,0,0,0,0,0,1]] if config_file == None: try: template_file = os.environ['CONFIGURATIONS_PATH'] + '/reliability_disynaptic_current.xml' except: template_file = os.environ['HOME'] + '/configurations/reliability_disynaptic_current.xml' if os.path.isfile(template_file): config_file = 'reliability_disynaptic.xml' lcg.substituteStrings(template_file, config_file, {'<weight>0</weight>': '<weight>'+str(weight)+'</weight>', '<E>-80</E>': '<E>'+str(E)+'</E>', '<tauRise>0</tauRise>': '<tauRise>'+str(tau_r)+'</tauRise>', '<tauDecay>0</tauDecay>': '<tauDecay>'+str(tau_d)+'</tauDecay>', '<tend>0</tend>': '<tend>'+str(np.sum(stimulus,0)[0])+'</tend>'}) else: print('Default configuration file [%s] missing.' % template_file) usage() sys.exit(2) writeStimFile('current.stim',stimulus) sub.call('lcg kernel -I ' + str(ai) + ' -O ' + str(ao), shell=True) sub.call(lcg.common.prog_name + ' -V 3 -c ' + config_file + ' -n ' + str(trials) + ' -i ' + str(interval), shell=True) if __name__ == '__main__': main()
sys.exit(1) if Vmin >= Vmax: print('Vmin must be smaller than Vmax.') usage() sys.exit(1) if configFile == None: try: templateFile = os.environ['CONFIGURATIONS_PATH'] + '/in_vivo_like.xml' except: templateFile = os.environ['HOME'] + '/configurations/in_vivo_like.xml' if os.path.isfile(templateFile): configFile = 'cv.xml' lcg.substituteStrings(templateFile, configFile, {'<maxCount>0</maxCount>': '<maxCount>'+str(nspikes)+'</maxCount>', '<tend>0</tend>': '<tend>'+str(duration)+'</tend>'}) else: print('Default configuration file [%s] missing.' % templateFile) usage() sys.exit(2) Vm = np.arange(Vmin,Vmax+Vstep/2,Vstep) rates_exc = np.array([rate]) for i in range(repetitions): np.random.shuffle(Vm) sub.call('lcg kernel -I ' + str(ai) + ' -O ' + str(ao), shell=True) run(Vm, Rm, rates_exc, duration, interval, configFile) if __name__ == '__main__': main()
stim_dur = lcg.writePulsesStimFile(f=stim_freq, dur=1, amp=stim_amp, N=15, delay=1, withRecovery=False) if os.path.isfile(template_file): lcg.substituteStrings( template_file, config_file, { 'WGT': str(weight), 'AI_PRE': str(ai[0]), 'AI_POST': str(ai[1]), 'AO_PRE': str(ao[0]), 'AO_POST': str(ao[1]), 'KERNEL_PRE': 'kernel-' + str(ai[0]) + '-' + str(ao[0]) + '.dat', 'KERNEL_POST': 'kernel-' + str(ai[1]) + '-' + str(ao[1]) + '.dat', 'TEND': str(stim_dur) }) else: os.remove('pulses.stim') print('Default configuration file [%s] missing.' % template_file) usage() sys.exit(1) if with_bg: ratio = lcg.computeRatesRatio(Vm=balanced_voltage, Rin=input_resistance)
usage() sys.exit(1) if with_bg and (not input_resistance or not bg_freq or not balanced_voltage): print('You need to specify the input resistance, the firing rate of the') print('excitatory background synaptic activity and the balanced voltage.') usage() sys.exit(1) stim_dur = lcg.writePulsesStimFile(f=stim_freq, dur=1, amp=stim_amp, N=15, delay=1, withRecovery=False) if os.path.isfile(template_file): lcg.substituteStrings(template_file, config_file, {'WGT': str(weight), 'AI_PRE': str(ai[0]), 'AI_POST': str(ai[1]), 'AO_PRE': str(ao[0]), 'AO_POST': str(ao[1]), 'KERNEL_PRE': 'kernel-'+str(ai[0])+'-'+str(ao[0])+'.dat', 'KERNEL_POST': 'kernel-'+str(ai[1])+'-'+str(ao[1])+'.dat', 'TEND': str(stim_dur)}) else: os.remove('pulses.stim') print('Default configuration file [%s] missing.' % template_file) usage() sys.exit(1) if with_bg: ratio = lcg.computeRatesRatio(Vm=balanced_voltage, Rin=input_resistance) Gm_exc,Gm_inh,Gs_exc,Gs_inh = lcg.computeSynapticBackgroundCoefficients(ratio, R_exc=bg_freq, Rin=input_resistance) lcg.writeGStimFiles({'m': Gm_exc, 's': Gs_exc, 'tau': 5, 'seed': 5061983}, {'m': Gm_inh, 's': Gs_inh, 'tau': 10, 'seed': 7051983}, stim_dur, 0, 0)
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)