def generate(reference = "Balanced", scalePops = 1, scalex=1, scaley=1, scalez=1, connections=True, connections_scaling=1, duration = 1000, global_delay = 2, max_in_pop_to_plot_and_save = 5, gen_spike_saves_for_all_somas = True, deterministic = True, format='xml'): num_exc = scale_pop_size(80,scalePops) num_inh = scale_pop_size(40,scalePops) if scalePops!=1: reference += '_%s'%scalePops nml_doc, network = oc.generate_network(reference) oc.include_opencortex_cell(nml_doc, 'AllenInstituteCellTypesDB_HH/HH_477127614.cell.nml') oc.include_opencortex_cell(nml_doc, 'AllenInstituteCellTypesDB_HH/HH_476686112.cell.nml') xDim = 400*scalex yDim = 500*scaley zDim = 300*scalez xs = -200 ys = -150 zs = 100 ##### Synapses synAmpa1 = oc.add_exp_two_syn(nml_doc, id="synAmpa1", gbase="1nS", erev="0mV", tau_rise="0.5ms", tau_decay="5ms") synGaba1 = oc.add_exp_two_syn(nml_doc, id="synGaba1", gbase="2nS", erev="-80mV", tau_rise="1ms", tau_decay="20ms") ##### Input types if not deterministic: pfs1 = oc.add_poisson_firing_synapse(nml_doc, id="psf1", average_rate="150 Hz", synapse_id=synAmpa1.id) ##### Populations popExc = oc.add_population_in_rectangular_region(network, 'popExc', 'HH_477127614', num_exc, xs,ys,zs, xDim,yDim,zDim) popInh = oc.add_population_in_rectangular_region(network, 'popInh', 'HH_476686112', num_inh, xs,ys,zs, xDim,yDim,zDim) ##### Projections total_conns = 0 if connections: proj = oc.add_probabilistic_projection(network, "proj0", popExc, popExc, synAmpa1.id, connections_scaling*0.3, delay = global_delay) total_conns += len(proj.connection_wds) proj = oc.add_probabilistic_projection(network, "proj1", popExc, popInh, synAmpa1.id, connections_scaling*0.5, delay = global_delay) total_conns += len(proj.connection_wds) proj = oc.add_probabilistic_projection(network, "proj3", popInh, popExc, synGaba1.id, connections_scaling*0.7, delay = global_delay) total_conns += len(proj.connection_wds) proj = oc.add_probabilistic_projection(network, "proj4", popInh, popInh, synGaba1.id, connections_scaling*0.5, delay = global_delay) total_conns += len(proj.connection_wds) ##### Inputs if not deterministic: oc.add_inputs_to_population(network, "Stim0", popExc, pfs1.id, all_cells=True) else: for i in range(num_exc): pg = oc.add_pulse_generator(nml_doc, id="pg_%i"%i, delay="0ms", duration="10000ms", amplitude="%snA"%(random()*0.5)) oc.add_inputs_to_population(network, "Stim_%i"%i, popExc, pg.id, all_cells=False, only_cells=[i]) ##### Save NeuroML and LEMS Simulation files nml_file_name = '%s%s.net.%s'%('XH_' if format == 'xml_hdf5' else '', network.id,'nml.h5' if format == 'hdf5' else 'nml') oc.save_network(nml_doc, nml_file_name, validate=(format=='xml'), format = format) plot_v = {popExc.id:[],popInh.id:[]} save_v = {'%s_v.dat'%popExc.id:[],'%s_v.dat'%popInh.id:[]} for i in range(min(max_in_pop_to_plot_and_save,num_exc)): plot_v[popExc.id].append("%s/%i/%s/v"%(popExc.id,i,popExc.component)) save_v['%s_v.dat'%popExc.id].append("%s/%i/%s/v"%(popExc.id,i,popExc.component)) for i in range(min(max_in_pop_to_plot_and_save,num_inh)): plot_v[popInh.id].append("%s/%i/%s/v"%(popInh.id,i,popInh.component)) save_v['%s_v.dat'%popInh.id].append("%s/%i/%s/v"%(popInh.id,i,popInh.component)) lems_file_name = "LEMS_%s.xml"%network.id if format != 'xml': lems_file_name = "LEMS_%s_%s.xml"%(network.id,format) lems_file_name = oc.generate_lems_simulation(nml_doc, network, nml_file_name, duration = duration, dt = 0.025, gen_plots_for_all_v = False, gen_plots_for_quantities = plot_v, gen_saves_for_all_v = False, gen_saves_for_quantities = save_v, gen_spike_saves_for_all_somas = gen_spike_saves_for_all_somas, lems_file_name = lems_file_name) return nml_doc, nml_file_name, lems_file_name
proj0 = oc.add_targeted_projection(network, prefix="proj0", presynaptic_population=popStim, postsynaptic_population=popPyr, targeting_mode="convergent", synapse_list=[synAmpa1.id], number_conns_per_cell=2, pre_segment_group=None, post_segment_group="dendrite_group", delays_dict={synAmpa1.id:3}, weights_dict={synAmpa1.id:1}) proj1 = oc.add_probabilistic_projection(network, "proj1", popIaf, popIzh, synAmpa1.id, 0.5) proj2 = oc.add_targeted_projection(network, prefix="proj2", presynaptic_population=popPyr, postsynaptic_population=popPyrS, targeting_mode="convergent", synapse_list=[synAmpa1.id], number_conns_per_cell=2, pre_segment_group="soma_group", post_segment_group="soma_group", delays_dict={synAmpa1.id:3}, weights_dict={synAmpa1.id:'3*random()'})
def generate(reference="Balanced", scalePops=1, scalex=1, scaley=1, scalez=1, connections=True, connections_scaling=1, duration=1000, global_delay=2, max_in_pop_to_plot_and_save=5, gen_spike_saves_for_all_somas=True, deterministic=True, format='xml'): num_exc = scale_pop_size(80, scalePops) num_inh = scale_pop_size(40, scalePops) if scalePops != 1: reference += '_%s' % scalePops nml_doc, network = oc.generate_network(reference) oc.include_opencortex_cell( nml_doc, 'AllenInstituteCellTypesDB_HH/HH_477127614.cell.nml') oc.include_opencortex_cell( nml_doc, 'AllenInstituteCellTypesDB_HH/HH_476686112.cell.nml') xDim = 400 * scalex yDim = 500 * scaley zDim = 300 * scalez xs = -200 ys = -150 zs = 100 ##### Synapses synAmpa1 = oc.add_exp_two_syn(nml_doc, id="synAmpa1", gbase="1nS", erev="0mV", tau_rise="0.5ms", tau_decay="5ms") synGaba1 = oc.add_exp_two_syn(nml_doc, id="synGaba1", gbase="2nS", erev="-80mV", tau_rise="1ms", tau_decay="20ms") ##### Input types if not deterministic: pfs1 = oc.add_poisson_firing_synapse(nml_doc, id="psf1", average_rate="150 Hz", synapse_id=synAmpa1.id) ##### Populations popExc = oc.add_population_in_rectangular_region(network, 'popExc', 'HH_477127614', num_exc, xs, ys, zs, xDim, yDim, zDim) popInh = oc.add_population_in_rectangular_region(network, 'popInh', 'HH_476686112', num_inh, xs, ys, zs, xDim, yDim, zDim) ##### Projections total_conns = 0 if connections: proj = oc.add_probabilistic_projection(network, "proj0", popExc, popExc, synAmpa1.id, connections_scaling * 0.3, delay=global_delay) total_conns += len(proj.connection_wds) proj = oc.add_probabilistic_projection(network, "proj1", popExc, popInh, synAmpa1.id, connections_scaling * 0.5, delay=global_delay) total_conns += len(proj.connection_wds) proj = oc.add_probabilistic_projection(network, "proj3", popInh, popExc, synGaba1.id, connections_scaling * 0.7, delay=global_delay) total_conns += len(proj.connection_wds) proj = oc.add_probabilistic_projection(network, "proj4", popInh, popInh, synGaba1.id, connections_scaling * 0.5, delay=global_delay) total_conns += len(proj.connection_wds) ##### Inputs if not deterministic: oc.add_inputs_to_population(network, "Stim0", popExc, pfs1.id, all_cells=True) else: for i in range(num_exc): pg = oc.add_pulse_generator(nml_doc, id="pg_%i" % i, delay="0ms", duration="10000ms", amplitude="%snA" % (random() * 0.5)) oc.add_inputs_to_population(network, "Stim_%i" % i, popExc, pg.id, all_cells=False, only_cells=[i]) ##### Save NeuroML and LEMS Simulation files nml_file_name = '%s%s.net.%s' % ('XH_' if format == 'xml_hdf5' else '', network.id, 'nml.h5' if format == 'hdf5' else 'nml') oc.save_network(nml_doc, nml_file_name, validate=(format == 'xml'), format=format) plot_v = {popExc.id: [], popInh.id: []} save_v = {'%s_v.dat' % popExc.id: [], '%s_v.dat' % popInh.id: []} for i in range(min(max_in_pop_to_plot_and_save, num_exc)): plot_v[popExc.id].append("%s/%i/%s/v" % (popExc.id, i, popExc.component)) save_v['%s_v.dat' % popExc.id].append("%s/%i/%s/v" % (popExc.id, i, popExc.component)) for i in range(min(max_in_pop_to_plot_and_save, num_inh)): plot_v[popInh.id].append("%s/%i/%s/v" % (popInh.id, i, popInh.component)) save_v['%s_v.dat' % popInh.id].append("%s/%i/%s/v" % (popInh.id, i, popInh.component)) lems_file_name = "LEMS_%s.xml" % network.id if format != 'xml': lems_file_name = "LEMS_%s_%s.xml" % (network.id, format) lems_file_name = oc.generate_lems_simulation( nml_doc, network, nml_file_name, duration=duration, dt=0.025, gen_plots_for_all_v=False, gen_plots_for_quantities=plot_v, gen_saves_for_all_v=False, gen_saves_for_quantities=save_v, gen_spike_saves_for_all_somas=gen_spike_saves_for_all_somas, lems_file_name=lems_file_name) return nml_doc, nml_file_name, lems_file_name
def generate(scalePops=1, percentage_exc_detailed=0, scalex=1, scaley=1, scalez=1, ratio_inh_exc=2, connections=True, duration=1000, input_rate=150, global_delay=2, max_in_pop_to_plot_and_save=5, format='xml', run_in_simulator=None): reference = ("Multiscale__g%s__i%s" % (ratio_inh_exc, input_rate)).replace( '.', '_') num_exc = scale_pop_size(80, scalePops) num_exc2 = int(0.5 + num_exc * percentage_exc_detailed / 100.0) num_exc -= num_exc2 num_inh = scale_pop_size(40, scalePops) nml_doc, network = oc.generate_network(reference) oc.include_opencortex_cell( nml_doc, 'AllenInstituteCellTypesDB_HH/HH_477127614.cell.nml') oc.include_opencortex_cell( nml_doc, 'AllenInstituteCellTypesDB_HH/HH_476686112.cell.nml') oc.include_opencortex_cell(nml_doc, 'L23Pyr_SmithEtAl2013/L23_NoHotSpot.cell.nml') xDim = 1000 * scalex yDim = 300 * scaley zDim = 1000 * scalez xs = -200 ys = -150 zs = 100 ##### Synapses exc_syn_nS = 1. synAmpa1 = oc.add_exp_two_syn(nml_doc, id="synAmpa1", gbase="%snS" % exc_syn_nS, erev="0mV", tau_rise="0.5ms", tau_decay="5ms") synGaba1 = oc.add_exp_two_syn(nml_doc, id="synGaba1", gbase="%snS" % (exc_syn_nS * ratio_inh_exc), erev="-80mV", tau_rise="1ms", tau_decay="20ms") ##### Input types pfs1 = oc.add_poisson_firing_synapse(nml_doc, id="psf1", average_rate="%s Hz" % input_rate, synapse_id=synAmpa1.id) ##### Populations popExc = oc.add_population_in_rectangular_region(network, 'popExc', 'HH_477127614', num_exc, xs, ys, zs, xDim, yDim, zDim, color='0 0 1') popExc2 = oc.add_population_in_rectangular_region(network, 'popExc2', 'L23_NoHotSpot', num_exc2, xs, ys, zs, xDim, yDim, zDim, color='0 1 0') allExc = [popExc, popExc2] popInh = oc.add_population_in_rectangular_region(network, 'popInh', 'HH_476686112', num_inh, xs, ys, zs, xDim, yDim, zDim, color='1 0 0') ##### Projections if connections: for pop1 in allExc: for pop2 in allExc: proj = oc.add_probabilistic_projection(network, "proj0", pop1, pop2, synAmpa1.id, 0.5, delay=global_delay) proj = oc.add_probabilistic_projection(network, "proj1", pop1, popInh, synAmpa1.id, 0.7, delay=global_delay) proj = oc.add_probabilistic_projection(network, "proj2", popInh, pop1, synGaba1.id, 0.7, delay=global_delay) proj = oc.add_probabilistic_projection(network, "proj3", popInh, popInh, synGaba1.id, 0.5, delay=global_delay) ##### Inputs for pop in allExc: oc.add_inputs_to_population(network, "Stim_%s" % pop.id, pop, pfs1.id, all_cells=True) ##### Save NeuroML and LEMS Simulation files target_dir = './temp/' nml_file_name = '%s.net.%s' % (network.id, 'nml.h5' if format == 'hdf5' else 'nml') oc.save_network(nml_doc, nml_file_name, validate=(format == 'xml'), format=format, target_dir=target_dir) if format == 'xml': plot_v = {popExc.id: [], popExc2.id: [], popInh.id: []} exc_traces = '%s_%s_v.dat' % (network.id, popExc.id) exc2_traces = '%s_%s_v.dat' % (network.id, popExc2.id) inh_traces = '%s_%s_v.dat' % (network.id, popInh.id) save_v = {exc_traces: [], inh_traces: [], exc2_traces: []} for i in range(min(max_in_pop_to_plot_and_save, num_exc)): plot_v[popExc.id].append("%s/%i/%s/v" % (popExc.id, i, popExc.component)) save_v[exc_traces].append("%s/%i/%s/v" % (popExc.id, i, popExc.component)) for i in range(min(max_in_pop_to_plot_and_save, num_exc2)): plot_v[popExc2.id].append("%s/%i/%s/v" % (popExc2.id, i, popExc2.component)) save_v[exc2_traces].append("%s/%i/%s/v" % (popExc2.id, i, popExc2.component)) for i in range(min(max_in_pop_to_plot_and_save, num_inh)): plot_v[popInh.id].append("%s/%i/%s/v" % (popInh.id, i, popInh.component)) save_v[inh_traces].append("%s/%i/%s/v" % (popInh.id, i, popInh.component)) gen_spike_saves_for_all_somas = run_in_simulator != 'jNeuroML_NetPyNE' lems_file_name = oc.generate_lems_simulation( nml_doc, network, target_dir + nml_file_name, duration=duration, dt=0.025, gen_plots_for_all_v=False, gen_plots_for_quantities=plot_v, gen_saves_for_all_v=False, gen_saves_for_quantities=save_v, gen_spike_saves_for_all_somas=gen_spike_saves_for_all_somas, target_dir=target_dir) if run_in_simulator: print("Running %s in %s" % (lems_file_name, run_in_simulator)) traces, events = oc.simulate_network(lems_file_name, run_in_simulator, max_memory='4000M', nogui=True, load_saved_data=True, reload_events=True, plot=False, verbose=False) print("Reloaded traces: %s" % traces.keys()) #print("Reloaded events: %s"%events.keys()) use_events_for_rates = False exc_rate = 0 inh_rate = 0 if use_events_for_rates: if (run_in_simulator == 'jNeuroML_NetPyNE'): raise ( 'Saving of spikes (and so calculation of rates) not yet supported in jNeuroML_NetPyNE' ) for ek in events.keys(): rate = 1000 * len(events[ek]) / float(duration) print("Cell %s has rate %s Hz" % (ek, rate)) if 'popExc' in ek: exc_rate += rate / num_exc if 'popInh' in ek: inh_rate += rate / num_inh else: tot_exc_rate = 0 exc_cells = 0 tot_inh_rate = 0 inh_cells = 0 tt = [t * 1000 for t in traces['t']] for tk in traces.keys(): if tk != 't': rate = get_rate_from_trace( tt, [v * 1000 for v in traces[tk]]) print("Cell %s has rate %s Hz" % (tk, rate)) if 'popExc' in tk: tot_exc_rate += rate exc_cells += 1 if 'popInh' in tk: tot_inh_rate += rate inh_cells += 1 exc_rate = tot_exc_rate / exc_cells inh_rate = tot_inh_rate / inh_cells print("Run %s: Exc rate: %s Hz; Inh rate %s Hz" % (reference, exc_rate, inh_rate)) return exc_rate, inh_rate, traces else: lems_file_name = None return nml_doc, nml_file_name, lems_file_name
pfs = oc.add_poisson_firing_synapse(nml_doc, id="poissonFiringSyn", average_rate="150 Hz", synapse_id=syn0.id) oc.add_inputs_to_population(network, "Stim0", pop_pre, pfs.id, all_cells=True) oc.add_probabilistic_projection(network, "proj0", pop_pre, pop_post, syn1.id, 0.3, weight=0.05, delay=5) duration = 1000 dt = 0.01 nml_file_name = '%s.net.nml'%network.id oc.save_network(nml_doc, nml_file_name, validate=True) oc.generate_lems_simulation(nml_doc, network, nml_file_name, duration = duration, dt = dt,
def generate(reference = "Weights", num_each = 6, connections=True, duration = 1000, format='xml'): nml_doc, network = oc.generate_network(reference) cell_id = 'HH_477127614' cell = oc.include_opencortex_cell(nml_doc, 'AllenInstituteCellTypesDB_HH/%s.cell.nml'%cell_id) xDim = 500 yDim = 500 zDim = 30 pop_pre = oc.add_population_in_rectangular_region(network, 'pop_pre', cell_id, num_each, 0,0,0, xDim,yDim,zDim, color='.8 0 0') pop_post_chem_exc = oc.add_population_in_rectangular_region(network, 'pop_post_chem_exc', cell_id, num_each+1, 0,yDim,0, xDim,yDim,zDim, color='0 0 .8') pop_post_chem_inh = oc.add_population_in_rectangular_region(network, 'pop_post_chem_inh', cell_id, num_each+2, xDim,yDim,0, xDim,yDim,zDim, color='0 .8 .8') pop_post_cont = oc.add_population_in_rectangular_region(network, 'pop_post_cont', cell_id, num_each+3, xDim,0,0, xDim,yDim,zDim, color='0 .8 0') ampa_syn = oc.add_exp_two_syn(nml_doc, id="AMPA_syn", gbase="10nS", erev="0mV", tau_rise="2ms", tau_decay="10ms") gaba_syn = oc.add_exp_two_syn(nml_doc, id="GABA_syn", gbase="10nS", erev="-80mV", tau_rise="3ms", tau_decay="30ms") gj_syn = oc.add_gap_junction_synapse(nml_doc, id="gj0", conductance=".05nS") analog_syn = GradedSynapse(id='analog_syn', conductance="10nS", delta="5mV", Vth="-35mV", k="0.025per_ms", erev="0mV") silent_syn = SilentSynapse(id="silent1") nml_doc.graded_synapses.append(analog_syn) nml_doc.silent_synapses.append(silent_syn) pfs = oc.add_poisson_firing_synapse(nml_doc, id="poissonFiringSyn", average_rate="10 Hz", synapse_id=ampa_syn.id) oc.add_inputs_to_population(network, "Stim0", pop_pre, pfs.id, all_cells=True) if connections: proj_chem_exc = oc.add_probabilistic_projection(network, "proj_chem_exc", pop_pre, pop_post_chem_exc, ampa_syn.id, 0.7, weight=1, delay=5) for conn in proj_chem_exc.connection_wds: if conn.get_pre_cell_id() < 3 and conn.get_post_cell_id() < 3: conn.weight = 0.5 proj_chem_inh = oc.add_probabilistic_projection(network, "proj_chem_inh", pop_pre, pop_post_chem_inh, gaba_syn.id, 0.7, weight=1, delay=5) for conn in proj_chem_inh.connection_wds: if conn.get_pre_cell_id() < 3 and conn.get_post_cell_id() < 3: conn.weight = 2 proj_cont = ContinuousProjection(id='proj_cont', \ presynaptic_population=pop_pre.id, postsynaptic_population=pop_post_cont.id) network.continuous_projections.append(proj_cont) for i in range(pop_pre.get_size()): for j in range(pop_post_cont.get_size()): conn0 = ContinuousConnectionInstanceW(id='%s'%(j+i*pop_pre.get_size()), \ pre_cell='../%s/%s/%s'%(pop_pre.id,i,cell_id), post_cell='../%s/%s/%s'%(pop_post_cont.id,j,cell_id), pre_component=silent_syn.id, post_component=analog_syn.id, weight=(i+j)/10.0) proj_cont.continuous_connection_instance_ws.append(conn0) gj_pops = [pop_pre, pop_post_chem_exc, pop_post_chem_inh, pop_post_cont] for pre in gj_pops: for post in gj_pops: proj_gap = oc.add_targeted_electrical_projection(nml_doc, network, "proj_", pre, post, targeting_mode='convergent', synapse_list=[gj_syn.id], pre_segment_group = 'soma_group', post_segment_group = 'soma_group', number_conns_per_cell=3) for conn in network.electrical_projections[-1].electrical_connection_instance_ws: conn.weight = conn.get_pre_cell_id() + conn.get_post_cell_id() nml_file_name = '%s.net.%s'%(network.id,'nml.h5' if format == 'hdf5' else 'nml') target_dir = 'HDF5/' if format == 'hdf5' else './' oc.save_network(nml_doc, nml_file_name, validate=(format=='xml'), format = format, target_dir=target_dir) if format=='xml': lems_file_name = oc.generate_lems_simulation(nml_doc, network, nml_file_name, duration = duration, dt = 0.025, gen_plots_for_all_v = True, gen_saves_for_all_v = True) else: lems_file_name = None return nml_doc, nml_file_name, lems_file_name
'pop0', 'pyr_4_sym', 5, 0, offset, 0, xDim, yDim, zDim, color='0 .8 0') offset += yDim ##### Projections oc.add_probabilistic_projection(network, "proj0", pop0, pop0, synAmpa1.id, 0.5) ##### Inputs oc.add_inputs_to_population(network, "Stim0", pop0, pg0.id, only_cells=[0]) oc.add_inputs_to_population(network, "Stim1", pop0, pg1.id, only_cells=[1]) oc.add_inputs_to_population(network, "Stim2", pop0, pfs.id, all_cells=True) nml_file_name = '%s.net.nml' % network.id oc.save_network(nml_doc, nml_file_name, validate=True) oc.generate_lems_simulation(nml_doc, network, nml_file_name,
def generate(reference="Balanced", num_bbp=1, scalePops=1, scalex=1, scaley=1, scalez=1, connections=True, duration=1000, input_rate=150, global_delay=0, max_in_pop_to_plot_and_save=5, gen_spike_saves_for_all_somas=True, format='xml'): num_exc = scale_pop_size(80, scalePops) num_inh = scale_pop_size(40, scalePops) nml_doc, network = oc.generate_network(reference) oc.include_opencortex_cell( nml_doc, 'AllenInstituteCellTypesDB_HH/HH_477127614.cell.nml') oc.include_opencortex_cell( nml_doc, 'AllenInstituteCellTypesDB_HH/HH_476686112.cell.nml') if num_bbp > 0: oc.include_opencortex_cell( nml_doc, 'BlueBrainProject_NMC/cADpyr229_L23_PC_5ecbf9b163_0_0.cell.nml') xDim = 400 * scalex yDim = 500 * scaley zDim = 300 * scalez xs = -200 ys = -150 zs = 100 ##### Synapses synAmpa1 = oc.add_exp_two_syn(nml_doc, id="synAmpa1", gbase="1nS", erev="0mV", tau_rise="0.5ms", tau_decay="5ms") synGaba1 = oc.add_exp_two_syn(nml_doc, id="synGaba1", gbase="2nS", erev="-80mV", tau_rise="1ms", tau_decay="20ms") ##### Input types pfs1 = oc.add_poisson_firing_synapse(nml_doc, id="psf1", average_rate="%s Hz" % input_rate, synapse_id=synAmpa1.id) ##### Populations popExc = oc.add_population_in_rectangular_region(network, 'popExc', 'HH_477127614', num_exc, xs, ys, zs, xDim, yDim, zDim, color='.8 0 0') popInh = oc.add_population_in_rectangular_region(network, 'popInh', 'HH_476686112', num_inh, xs, ys, zs, xDim, yDim, zDim, color='0 0 .8') if num_bbp == 1: popBBP = oc.add_single_cell_population( network, 'popBBP', 'cADpyr229_L23_PC_5ecbf9b163_0_0', z=200, color='0 .8 0') elif num_bbp > 1: popBBP = oc.add_population_in_rectangular_region( network, 'popBBP', 'cADpyr229_L23_PC_5ecbf9b163_0_0', num_bbp, xs, ys, zs, xDim, yDim, zDim, color='0 .8 0') ##### Projections total_conns = 0 if connections: proj = oc.add_probabilistic_projection(network, "proj0", popExc, popExc, synAmpa1.id, 0.5, delay=global_delay) total_conns += len(proj.connection_wds) proj = oc.add_probabilistic_projection(network, "proj1", popExc, popInh, synAmpa1.id, 0.7, delay=global_delay) total_conns += len(proj.connection_wds) proj = oc.add_probabilistic_projection(network, "proj3", popInh, popExc, synGaba1.id, 0.7, delay=global_delay) total_conns += len(proj.connection_wds) proj = oc.add_probabilistic_projection(network, "proj4", popInh, popInh, synGaba1.id, 0.5, delay=global_delay) total_conns += len(proj.connection_wds) if num_bbp > 0: proj = oc.add_probabilistic_projection(network, "proj5", popExc, popBBP, synAmpa1.id, 0.5, delay=global_delay) total_conns += len(proj.connection_wds) ##### Inputs oc.add_inputs_to_population(network, "Stim0", popExc, pfs1.id, all_cells=True) ##### Save NeuroML and LEMS Simulation files if num_bbp != 1: new_reference = 'Balanced_%scells_%sconns' % (num_bbp + num_exc + num_inh, total_conns) network.id = new_reference nml_doc.id = new_reference nml_file_name = '%s.net.%s' % (network.id, 'nml.h5' if format == 'hdf5' else 'nml') oc.save_network(nml_doc, nml_file_name, validate=(format == 'xml'), format=format) if format == 'xml': plot_v = {popExc.id: [], popInh.id: []} save_v = {'%s_v.dat' % popExc.id: [], '%s_v.dat' % popInh.id: []} if num_bbp > 0: plot_v[popBBP.id] = [] save_v['%s_v.dat' % popBBP.id] = [] for i in range(min(max_in_pop_to_plot_and_save, num_exc)): plot_v[popExc.id].append("%s/%i/%s/v" % (popExc.id, i, popExc.component)) save_v['%s_v.dat' % popExc.id].append( "%s/%i/%s/v" % (popExc.id, i, popExc.component)) for i in range(min(max_in_pop_to_plot_and_save, num_inh)): plot_v[popInh.id].append("%s/%i/%s/v" % (popInh.id, i, popInh.component)) save_v['%s_v.dat' % popInh.id].append( "%s/%i/%s/v" % (popInh.id, i, popInh.component)) for i in range(min(max_in_pop_to_plot_and_save, num_bbp)): plot_v[popBBP.id].append("%s/%i/%s/v" % (popBBP.id, i, popBBP.component)) save_v['%s_v.dat' % popBBP.id].append( "%s/%i/%s/v" % (popBBP.id, i, popBBP.component)) lems_file_name = oc.generate_lems_simulation( nml_doc, network, nml_file_name, duration=duration, dt=0.025, gen_plots_for_all_v=False, gen_plots_for_quantities=plot_v, gen_saves_for_all_v=False, gen_saves_for_quantities=save_v, gen_spike_saves_for_all_somas=gen_spike_saves_for_all_somas) else: lems_file_name = None return nml_doc, nml_file_name, lems_file_name
offset+=yDim pop1 = oc.add_population_in_rectangular_region(network, 'pop1', 'RS', scale_pop_size(1), 0,offset,0, xDim,yDim,zDim) ##### Projections oc.add_probabilistic_projection(network, "proj1", pop0, pop1, 'AMPA_NMDA', 0.7) ##### Inputs oc.add_inputs_to_population(network, "Stim0", pop0, pfs100.id, all_cells=True, number_per_cell=5) oc.add_inputs_to_population(network, "Stim1", pop0,
def generate(reference="L23TraubDemo", num_rs=DEFAULT_RS_POP_SIZE, num_bask=DEFAULT_BASK_POP_SIZE, scalex=1, scaley=1, scalez=1, connections=False, poisson_inputs=True, offset_curent_range_pA=None, global_delay=0, duration=300, segments_to_plot_record={ 'pop_rs': [0], 'pop_bask': [0] }, format='xml'): nml_doc, network = oc.generate_network(reference) #oc.add_cell_and_channels(nml_doc, 'acnet2/pyr_4_sym.cell.nml','pyr_4_sym') oc.include_opencortex_cell(nml_doc, 'Thalamocortical/L23PyrRS.cell.nml') oc.include_opencortex_cell(nml_doc, 'Thalamocortical/SupBasket.cell.nml') xDim = 500 * scalex yDim = 200 * scaley zDim = 500 * scalez pop_rs = oc.add_population_in_rectangular_region(network, 'pop_rs', 'L23PyrRS', num_rs, 0, 0, 0, xDim, yDim, zDim) pop_bask = oc.add_population_in_rectangular_region(network, 'pop_bask', 'SupBasket', num_bask, 0, 0, 0, xDim, yDim, zDim) syn0 = oc.add_exp_two_syn(nml_doc, id="syn0", gbase="1nS", erev="0mV", tau_rise="0.5ms", tau_decay="10ms") syn1 = oc.add_exp_two_syn(nml_doc, id="syn1", gbase="2nS", erev="0mV", tau_rise="1ms", tau_decay="15ms") if poisson_inputs: pfs = oc.add_poisson_firing_synapse(nml_doc, id="poissonFiringSyn", average_rate="150 Hz", synapse_id=syn0.id) oc.add_inputs_to_population(network, "Stim0", pop_rs, pfs.id, all_cells=True) ''' oc.add_inputs_to_population(network, "Stim1", pop_bask, pfs.id, all_cells=True)''' if offset_curent_range_pA: for pop_id in offset_curent_range_pA: pop = next(p for p in network.populations if p.id == pop_id) pg0 = oc.add_pulse_generator(nml_doc, id="offset_current_%s" % pop.id, delay="0ms", duration="%sms" % duration, amplitude="1pA") import neuroml import random input_list = neuroml.InputList(id="inputs_offset_current_%s" % pop.id, component=pg0.id, populations=pop.id) network.input_lists.append(input_list) min_, max_ = offset_curent_range_pA[pop_id] for i in range(pop.get_size()): input = neuroml.InputW( id=i, target="../%s/%i/%s" % (pop.id, i, pop.component), destination="synapses", weight=(min_ + (max_ - min_) * random.random())) input_list.input_ws.append(input) total_conns = 0 if connections: proj = oc.add_probabilistic_projection(network, "proj0", pop_rs, pop_bask, syn1.id, 1, weight=1, delay=global_delay) ''' proj = oc.add_targeted_projection(nml_doc, network, "proj0", presynaptic_population = pop_rs, postsynaptic_population = pop_bask, targeting_mode = 'convergent', synapse_list = [syn1.id], number_conns_per_cell = 1, pre_segment_group = 'axon_group', post_segment_group = 'dendrite_group', delays_dict = {syn1.id:2}, weights_dict = {syn1.id:1})''' if proj: total_conns += len(proj.connection_wds) if num_rs != DEFAULT_RS_POP_SIZE or num_bask != DEFAULT_BASK_POP_SIZE: new_reference = '%s_%scells_%sconns' % (nml_doc.id, num_rs + num_bask, total_conns) network.id = new_reference nml_doc.id = new_reference nml_file_name = '%s.net.%s' % (network.id, 'nml.h5' if format == 'hdf5' else 'nml') oc.save_network(nml_doc, nml_file_name, validate=(format == 'xml'), format=format) if format == 'xml': gen_plots_for_quantities = { } # Dict with displays vs lists of quantity paths gen_saves_for_quantities = { } # Dict with file names vs lists of quantity paths for pop in segments_to_plot_record.keys(): pop_nml = network.get_by_id(pop) if pop_nml is not None and pop_nml.size > 0: for i in range(int(pop_nml.size)): gen_plots_for_quantities['Display_%s_%i_v' % (pop, i)] = [] gen_saves_for_quantities['Sim_%s.%s.%i.v.dat' % (nml_doc.id, pop, i)] = [] for seg in segments_to_plot_record[pop]: quantity = '%s/%i/%s/%i/v' % (pop, i, pop_nml.component, seg) gen_plots_for_quantities['Display_%s_%i_v' % (pop, i)].append(quantity) gen_saves_for_quantities['Sim_%s.%s.%i.v.dat' % (nml_doc.id, pop, i)].append(quantity) lems_file_name = oc.generate_lems_simulation( nml_doc, network, nml_file_name, duration=duration, dt=0.025, gen_plots_for_all_v=False, gen_plots_for_quantities=gen_plots_for_quantities, gen_saves_for_all_v=False, gen_saves_for_quantities=gen_saves_for_quantities) else: lems_file_name = None return nml_doc, nml_file_name, lems_file_name