def add_gap_junction_synapse(nml_doc, id, conductance): """ Adds a <gapJunction> element to the document. See the definition of the behaviour of this here: https://www.neuroml.org/NeuroML2CoreTypes/Synapses.html#gapJunction Returns the class created. """ syn0 = neuroml.GapJunction(id=id, conductance=conductance) nml_doc.gap_junctions.append(syn0) return syn0
def create_GoC_network(duration, dt, seed, runid, run=False): ### ---------- Load Params noPar = True pfile = Path('params_file.pkl') if pfile.exists(): print('Reading parameters from file:') file = open('params_file.pkl', 'rb') params_list = pkl.load(file) if len(params_list) > runid: p = params_list[runid] file.close() if noPar: p = inp.get_simulation_params(runid) ### ---------- Component types goc_filename = 'GoC.cell.nml' # Golgi cell with channels goc_file = pynml.read_neuroml2_file(goc_filename) goc_type = goc_file.cells[0] goc_ref = nml.IncludeType(href=goc_filename) gj = nml.GapJunction(id="GJ_0", conductance="426pS") # GoC synapse ### --------- Populations # Build network to specify cells and connectivity net = nml.Network(id="gocNetwork", type="networkWithTemperature", temperature="23 degC") # Create GoC population goc_pop = nml.Population(id=goc_type.id + "Pop", component=goc_type.id, type="populationList", size=p["nGoC"]) for goc in range(p["nGoC"]): inst = nml.Instance(id=goc) goc_pop.instances.append(inst) inst.location = nml.Location(x=p["GoC_pos"][goc, 0], y=p["GoC_pos"][goc, 1], z=p["GoC_pos"][goc, 2]) net.populations.append(goc_pop) # Create NML document for network specification net_doc = nml.NeuroMLDocument(id=net.id) net_doc.networks.append(net) net_doc.includes.append(goc_ref) net_doc.gap_junctions.append(gj) ### ------------ Connectivity ### 1. Input Current to one cell ctr = 0 for goc in p["Test_GoC"]: for jj in range(p["nSteps"]): input_id = 'stim_{}'.format(ctr) istep = nml.PulseGenerator( id=input_id, delay='{} ms'.format(p["iDuration"] * jj + p["iRest"] * (jj + 1)), duration='{} ms'.format(p["iDuration"]), amplitude='{} pA'.format(p["iAmp"][jj])) net_doc.pulse_generators.append(istep) input_list = nml.InputList(id='ilist_{}'.format(ctr), component=istep.id, populations=goc_pop.id) curr_inj = nml.Input('0', target="../%s[%i]" % (goc_pop.id, goc), destination="synapses") input_list.input.append(curr_inj) net.input_lists.append(input_list) ctr += 1 ### 2. Electrical coupling between GoCs GoCCoupling = nml.ElectricalProjection(id="gocGJ", presynaptic_population=goc_pop.id, postsynaptic_population=goc_pop.id) net.electrical_projections.append(GoCCoupling) dend_id = [1, 2, 5] for jj in range(p["GJ_pairs"].shape[0]): conn = nml.ElectricalConnectionInstanceW( id=jj, pre_cell='../{}/{}/{}'.format(goc_pop.id, p["GJ_pairs"][jj, 0], goc_type.id), pre_segment=dend_id[p["GJ_loc"][jj, 0]], pre_fraction_along='0.5', post_cell='../{}/{}/{}'.format(goc_pop.id, p["GJ_pairs"][jj, 1], goc_type.id), post_segment=dend_id[p["GJ_loc"][jj, 1]], post_fraction_along='0.5', synapse=gj.id, weight=p["GJ_wt"][jj]) GoCCoupling.electrical_connection_instance_ws.append(conn) ### -------------- Write files net_filename = 'gocNetwork.nml' pynml.write_neuroml2_file(net_doc, net_filename) simid = 'sim_gocnet_' + goc_type.id + '_run_{}'.format(runid) ls = LEMSSimulation(simid, duration=duration, dt=dt, simulation_seed=seed) ls.assign_simulation_target(net.id) ls.include_neuroml2_file(net_filename) ls.include_neuroml2_file(goc_filename) # Specify outputs eof0 = 'Events_file' ls.create_event_output_file(eof0, "%s.v.spikes" % simid, format='ID_TIME') for jj in range(goc_pop.size): ls.add_selection_to_event_output_file( eof0, jj, '{}/{}/{}'.format(goc_pop.id, jj, goc_type.id), 'spike') of0 = 'Volts_file' ls.create_output_file(of0, "%s.v.dat" % simid) ctr = 0 for jj in p["Test_GoC"]: ls.add_column_to_output_file( of0, jj, '{}/{}/{}/v'.format(goc_pop.id, ctr, goc_type.id)) ctr += 1 #Create Lems file to run lems_simfile = ls.save_to_file() if run: res = pynml.run_lems_with_jneuroml_neuron(lems_simfile, max_memory="2G", nogui=True, plot=False) else: res = pynml.run_lems_with_jneuroml_neuron(lems_simfile, max_memory="2G", only_generate_scripts=True, compile_mods=False, nogui=True, plot=False) return res
def create_GoC_network( duration, dt, seed, runid, run=False): ### ---------- Load Params noPar = True pfile = Path('params_file.pkl') if pfile.exists(): print('Reading parameters from file:') file = open('params_file.pkl','rb') params_list = pkl.load(file) if len(params_list)>runid: p = params_list[runid] file.close() if noPar: p = inp.get_simulation_params( runid ) ### ---------- Component types goc_filename = 'GoC.cell.nml' # Golgi cell with channels goc_file = pynml.read_neuroml2_file( goc_filename ) goc_type = goc_file.cells[0] goc_ref = nml.IncludeType( href=goc_filename ) MFSyn_filename = 'MF_GoC_Syn.nml' # small conductance synapse for background inputs mfsyn_file = pynml.read_neuroml2_file( MFSyn_filename ) MFSyn_type = mfsyn_file.exp_three_synapses[0] mfsyn_ref = nml.IncludeType( href=MFSyn_filename ) MF20Syn_filename = 'MF_GoC_SynMult.nml' # multi-syn conductance for strong/coincident transient input mf20syn_file = pynml.read_neuroml2_file( MF20Syn_filename ) MF20Syn_type = mf20syn_file.exp_three_synapses[0] mf20syn_ref = nml.IncludeType( href=MF20Syn_filename ) mf_type2 = 'spikeGeneratorPoisson' # Spike source for background inputs mf_poisson = nml.SpikeGeneratorPoisson( id = "MF_Poisson", average_rate="5 Hz" ) # Not tuned to any data - qqq ! mf_bursttype = 'transientPoissonFiringSynapse' # Burst of MF input (as explicit input) mf_burst = nml.TransientPoissonFiringSynapse( id="MF_Burst", average_rate="100 Hz", delay="2000 ms", duration="500 ms", synapse=MF20Syn_type.id, spike_target='./{}'.format(MF20Syn_type.id) ) gj = nml.GapJunction( id="GJ_0", conductance="426pS" ) # GoC synapse ### --------- Populations # Build network to specify cells and connectivity net = nml.Network( id="gocNetwork", type="networkWithTemperature" , temperature="23 degC" ) # Create GoC population goc_pop = nml.Population( id=goc_type.id+"Pop", component = goc_type.id, type="populationList", size=p["nGoC"] ) for goc in range( p["nGoC"] ): inst = nml.Instance( id=goc ) goc_pop.instances.append( inst ) inst.location = nml.Location( x=p["GoC_pos"][goc,0], y=p["GoC_pos"][goc,1], z=p["GoC_pos"][goc,2] ) net.populations.append( goc_pop ) ### MF population MF_Poisson_pop = nml.Population(id=mf_poisson.id+"_pop", component=mf_poisson.id, type="populationList", size=p["nMF"]) for mf in range( p["nMF"] ): inst = nml.Instance(id=mf) MF_Poisson_pop.instances.append( inst ) inst.location = nml.Location( x=p["MF_pos"][mf,0], y=p["MF_pos"][mf,1], z=p["MF_pos"][mf,2] ) net.populations.append( MF_Poisson_pop ) # Create NML document for network specification net_doc = nml.NeuroMLDocument( id=net.id ) net_doc.networks.append( net ) net_doc.includes.append( goc_ref ) net_doc.includes.append( mfsyn_ref ) net_doc.includes.append( mf20syn_ref ) net_doc.spike_generator_poissons.append( mf_poisson ) net_doc.transient_poisson_firing_synapses.append( mf_burst ) net_doc.gap_junctions.append(gj) ### ------------ Connectivity ### 1. Background excitatory inputs: MF to GoC populations MFProjection = nml.Projection(id="MFtoGoC", presynaptic_population=MF_Poisson_pop.id, postsynaptic_population=goc_pop.id, synapse=MFSyn_type.id) net.projections.append(MFProjection) # MF_> GoC synapses (with syn_count equivalent to integer scaling of Mf synapse strength) nMFSyn = p["MF_GoC_pairs"].shape[1] ctr=0 for syn in range( nMFSyn ): mf, goc = p["MF_GoC_pairs"][:, syn] for syn_count in range(p["MF_GoC_wt"][ctr]): conn2 = nml.Connection(id=ctr, pre_cell_id='../{}/{}/{}'.format(MF_Poisson_pop.id, mf, mf_poisson.id), post_cell_id='../{}/{}/{}'.format(goc_pop.id, goc, goc_type.id), post_segment_id='0', post_fraction_along="0.5") #on soma MFProjection.connections.append(conn2) ctr+=1 ### 2. Perturbation as High Freq MF Inputs ctr=0 for goc in p["Burst_GoC"]: for jj in range( p["nBurst"] ): # Each Perturbed GoC gets nBurst random Burst sources inst = nml.ExplicitInput( id=ctr, target='../{}/{}/{}'.format(goc_pop.id, goc, goc_type.id), input=mf_burst.id, synapse=MF20Syn_type.id, spikeTarget='./{}'.format(MF20Syn_type.id)) net.explicit_inputs.append( inst ) ctr += 1 ### 3. Electrical coupling between GoCs GoCCoupling = nml.ElectricalProjection( id="gocGJ", presynaptic_population=goc_pop.id, postsynaptic_population=goc_pop.id ) net.electrical_projections.append( GoCCoupling ) dend_id = [1,2,5] for jj in range( p["GJ_pairs"].shape[0] ): conn = nml.ElectricalConnectionInstanceW( id=jj, pre_cell='../{}/{}/{}'.format(goc_pop.id, p["GJ_pairs"][jj,0], goc_type.id), pre_segment=dend_id[p["GJ_loc"][jj,0]], pre_fraction_along='0.5', post_cell='../{}/{}/{}'.format(goc_pop.id, p["GJ_pairs"][jj,1], goc_type.id), post_segment=dend_id[p["GJ_loc"][jj,1]], post_fraction_along='0.5', synapse=gj.id, weight=p["GJ_wt"][jj] ) GoCCoupling.electrical_connection_instance_ws.append( conn ) ### -------------- Write files net_filename = 'gocNetwork.nml' pynml.write_neuroml2_file( net_doc, net_filename ) simid = 'sim_gocnet_'+goc_type.id+'_run_{}'.format(runid) ls = LEMSSimulation( simid, duration=duration, dt=dt, simulation_seed=seed ) ls.assign_simulation_target( net.id ) ls.include_neuroml2_file( net_filename) ls.include_neuroml2_file( goc_filename) ls.include_neuroml2_file( MFSyn_filename) ls.include_neuroml2_file( MF20Syn_filename) # Specify outputs eof0 = 'Events_file' ls.create_event_output_file(eof0, "%s.v.spikes"%simid,format='ID_TIME') for jj in range( goc_pop.size): ls.add_selection_to_event_output_file( eof0, jj, '{}/{}/{}'.format( goc_pop.id, jj, goc_type.id), 'spike' ) of0 = 'Volts_file' ls.create_output_file(of0, "%s.v.dat"%simid) for jj in range( goc_pop.size ): ls.add_column_to_output_file(of0, jj, '{}/{}/{}/v'.format( goc_pop.id, jj, goc_type.id)) #Create Lems file to run lems_simfile = ls.save_to_file() if run: res = pynml.run_lems_with_jneuroml_neuron( lems_simfile, max_memory="2G", nogui=True, plot=False) else: res = pynml.run_lems_with_jneuroml_neuron( lems_simfile, max_memory="2G", only_generate_scripts = True, compile_mods = False, nogui=True, plot=False) return res
def create_GoC_network(duration, dt, seed, N_goc=0, N_mf=15, run=False, prob_type='Boltzmann', GJw_type='Vervaeke2010'): ### ---------- Component types goc_filename = 'GoC.cell.nml' # Golgi cell with channels goc_file = pynml.read_neuroml2_file(goc_filename) goc_type = goc_file.cells[0] goc_ref = nml.IncludeType(href=goc_filename) MFSyn_filename = 'MF_GoC_Syn.nml' # small conductance synapse for background inputs mfsyn_file = pynml.read_neuroml2_file(MFSyn_filename) MFSyn_type = mfsyn_file.exp_three_synapses[0] mfsyn_ref = nml.IncludeType(href=MFSyn_filename) MF20Syn_filename = 'MF_GoC_SynMult.nml' # multi-syn conductance for strong/coincident transient input mf20syn_file = pynml.read_neuroml2_file(MF20Syn_filename) MF20Syn_type = mf20syn_file.exp_three_synapses[0] mf20syn_ref = nml.IncludeType(href=MF20Syn_filename) mf_type2 = 'spikeGeneratorPoisson' # Spike source for background inputs mf_poisson = nml.SpikeGeneratorPoisson( id="MF_Poisson", average_rate="5 Hz") # Not tuned to any data - qqq ! mf_bursttype = 'transientPoissonFiringSynapse' # Burst of MF input (as explicit input) mf_burst = nml.TransientPoissonFiringSynapse(id="MF_Burst", average_rate="100 Hz", delay="2000 ms", duration="500 ms", synapse=MF20Syn_type.id, spike_target='./{}'.format( MF20Syn_type.id)) gj = nml.GapJunction(id="GJ_0", conductance="426pS") # GoC synapse ### --------- Populations # Build network to specify cells and connectivity net = nml.Network(id="gocNetwork", type="networkWithTemperature", temperature="23 degC") ### Golgi cells if N_goc > 0: GoC_pos = nu.GoC_locate(N_goc) else: GoC_pos = nu.GoC_density_locate() N_goc = GoC_pos.shape[0] # Create GoC population goc_pop = nml.Population(id=goc_type.id + "Pop", component=goc_type.id, type="populationList", size=N_goc) for goc in range(N_goc): inst = nml.Instance(id=goc) goc_pop.instances.append(inst) inst.location = nml.Location(x=GoC_pos[goc, 0], y=GoC_pos[goc, 1], z=GoC_pos[goc, 2]) net.populations.append(goc_pop) ### MF population MF_Poisson_pop = nml.Population(id=mf_poisson.id + "_pop", component=mf_poisson.id, type="populationList", size=N_mf) MF_pos = nu.GoC_locate(N_mf) for mf in range(N_mf): inst = nml.Instance(id=mf) MF_Poisson_pop.instances.append(inst) inst.location = nml.Location(x=MF_pos[mf, 0], y=MF_pos[mf, 1], z=MF_pos[mf, 2]) net.populations.append(MF_Poisson_pop) # Create NML document for network specification net_doc = nml.NeuroMLDocument(id=net.id) net_doc.networks.append(net) net_doc.includes.append(goc_ref) net_doc.includes.append(mfsyn_ref) net_doc.includes.append(mf20syn_ref) net_doc.spike_generator_poissons.append(mf_poisson) net_doc.transient_poisson_firing_synapses.append(mf_burst) net_doc.gap_junctions.append(gj) ### ------------ Connectivity ### background excitatory inputs: MF to GoC populations MFProjection = nml.Projection(id="MFtoGoC", presynaptic_population=MF_Poisson_pop.id, postsynaptic_population=goc_pop.id, synapse=MFSyn_type.id) net.projections.append(MFProjection) #Get list of MF->GoC synapse mf_synlist = nu.randdist_MF_syn(N_mf, N_goc, pConn=0.3) # Not tuned to any data - qqq! nMFSyn = mf_synlist.shape[1] for syn in range(nMFSyn): mf, goc = mf_synlist[:, syn] conn2 = nml.Connection( id=syn, pre_cell_id='../{}/{}/{}'.format(MF_Poisson_pop.id, mf, mf_poisson.id), post_cell_id='../{}/{}/{}'.format(goc_pop.id, goc, goc_type.id), post_segment_id='0', post_fraction_along="0.5") #on soma MFProjection.connections.append(conn2) ### Add few burst inputs n_bursts = 4 gocPerm = np.random.permutation( N_goc) # change to central neurons later -qqq !!! ctr = 0 for gg in range(4): goc = gocPerm[gg] for jj in range(n_bursts): inst = nml.ExplicitInput( id=ctr, target='../{}/{}/{}'.format(goc_pop.id, goc, goc_type.id), input=mf_burst.id, synapse=MF20Syn_type.id, spikeTarget='./{}'.format(MF20Syn_type.id)) net.explicit_inputs.append(inst) ctr += 1 ### Electrical coupling between GoCs # get GJ connectivity GJ_pairs, GJWt = nu.GJ_conn(GoC_pos, prob_type, GJw_type) #tmp1, tmp2 = valnet.gapJuncAnalysis( GJ_pairs, GJWt ) #print("Number of gap junctions per cell: ", tmp1) #print("Net GJ conductance per cell:", tmp2) # Add electrical synapses GoCCoupling = nml.ElectricalProjection(id="gocGJ", presynaptic_population=goc_pop.id, postsynaptic_population=goc_pop.id) nGJ = GJ_pairs.shape[0] for jj in range(nGJ): conn = nml.ElectricalConnectionInstanceW( id=jj, pre_cell='../{}/{}/{}'.format(goc_pop.id, GJ_pairs[jj, 0], goc_type.id), pre_segment='1', pre_fraction_along='0.5', post_cell='../{}/{}/{}'.format(goc_pop.id, GJ_pairs[jj, 1], goc_type.id), post_segment='1', post_fraction_along='0.5', synapse=gj.id, weight=GJWt[jj]) GoCCoupling.electrical_connection_instance_ws.append(conn) net.electrical_projections.append(GoCCoupling) ### -------------- Write files net_filename = 'gocNetwork.nml' pynml.write_neuroml2_file(net_doc, net_filename) #lems_filename = 'instances.xml' #pynml.write_lems_file( lems_inst_doc, lems_filename, validate=False ) simid = 'sim_gocnet' + goc_type.id ls = LEMSSimulation(simid, duration=duration, dt=dt, simulation_seed=seed) ls.assign_simulation_target(net.id) ls.include_neuroml2_file(net_filename) ls.include_neuroml2_file(goc_filename) ls.include_neuroml2_file(MFSyn_filename) ls.include_neuroml2_file(MF20Syn_filename) #ls.include_lems_file( lems_filename, include_included=False) # Specify outputs eof0 = 'Events_file' ls.create_event_output_file(eof0, "%s.v.spikes" % simid, format='ID_TIME') for jj in range(goc_pop.size): ls.add_selection_to_event_output_file( eof0, jj, '{}/{}/{}'.format(goc_pop.id, jj, goc_type.id), 'spike') of0 = 'Volts_file' ls.create_output_file(of0, "%s.v.dat" % simid) for jj in range(goc_pop.size): ls.add_column_to_output_file( of0, jj, '{}/{}/{}/v'.format(goc_pop.id, jj, goc_type.id)) #Create Lems file to run lems_simfile = ls.save_to_file() if run: res = pynml.run_lems_with_jneuroml_neuron(lems_simfile, max_memory="2G", nogui=True, plot=False) else: res = pynml.run_lems_with_jneuroml_neuron(lems_simfile, max_memory="2G", only_generate_scripts=True, compile_mods=False, nogui=True, plot=False) return res
def Vervaeke_2010_model(pair_id,projection_id,prePop,prePop_listIndex,prePopSize,preCellType,preNML2Type,pre_cell_positions,\ postPop,postPop_listIndex,postPopSize,postCellType,postNML2Type,post_cell_positions,\ connectivity_parameters,seed_number,parentDir=None): random.seed(seed_number) if parentDir != None: preCellTypeFile=parentDir+"/NeuroML2"+"/"+preCellType postCellTypeFile=parentDir+"/NeuroML2"+"/"+postCellType else: preCellTypeFile=preCellType postCellTypeFile=postCellType nonempty_projection=False gapJ_object_array=[] gap_counter=0 ####### if 'prePoptargetGroup' in connectivity_parameters: pre_pop_target_segment_array=extract_morphology_information([preCellTypeFile],{preCellTypeFile:preNML2Type},\ ["segment groups", \ connectivity_parameters['prePoptargetGroup']['segmentGroupList']]) if 'postPoptargetGroup' in connectivity_parameters: post_pop_target_segment_array=extract_morphology_information([postCellTypeFile],{postCellTypeFile:postNML2Type},\ ["segment groups",connectivity_parameters['postPoptargetGroup']['segmentGroupList'] ] ) proj = neuroml.ElectricalProjection(id="proj%d"%projection_id,presynaptic_population=prePop,postsynaptic_population=postPop) conn_count = 0 conductance_scaling=1 conductance_array=[] conductance_array_spatial_scale1=[] make_conductance_array_no_spatial_scale=False if 'testingConductanceScale' in connectivity_parameters: conductance_scaling=connectivity_parameters['testingConductanceScale'] spatial_scale=1 if 'spatialScale' in connectivity_parameters: spatial_scale=connectivity_parameters['spatialScale'] if connectivity_parameters['normalizeConductances']: if spatial_scale != 1: make_conductance_array_no_spatial_scale=True one_population=False if prePop==postPop: one_population=True for Pre_cell in range(0,prePopSize): if one_population: post_index_array=range(0,postPopSize) post_index_array.remove(Pre_cell) else: post_index_array=range(0,postPopSize) for Post_cell in post_index_array: if Pre_cell <= Post_cell: distance_between_cells=distance(pre_cell_positions[Pre_cell],post_cell_positions[Post_cell])/spatial_scale if connectivity_parameters['normalizeConductances']: if make_conductance_array_no_spatial_scale: distance_between_cells_spatial_scale1=spatial_scale*distance_between_cells if random.random() <connection_probability_vervaeke_2010(distance_between_cells): nonempty_projection=True conductanceValue=synaptic_weight_vervaeke_2010(distance_between_cells) conductance_array.append(conductanceValue) if make_conductance_array_no_spatial_scale: conductanceValueN=synaptic_weight_vervaeke_2010(distance_between_cells_spatial_scale1) conductance_array_spatial_scale1.append(conductanceValueN) if 'prePoptargetGroup' in connectivity_parameters: pre_target_points=get_unique_target_points(pre_pop_target_segment_array,"segment groups and segments",\ [connectivity_parameters['prePoptargetGroup' ]['segmentGroupList'],\ connectivity_parameters['prePoptargetGroup']['segmentGroupProbabilities']],1) if 'postPoptargetGroup' in connectivity_parameters: post_targeting_mode="segment groups and segments" post_targeting_parameters=[connectivity_parameters['postPoptargetGroup']['segmentGroupList'],\ connectivity_parameters['postPoptargetGroup']['segmentGroupProbabilities']] if 'maximalConnDistance' in connectivity_parameters: x=0 while x==0: post_target_point=get_unique_target_points(post_pop_target_segment_array,post_targeting_mode,post_targeting_parameters,1) if get_3D_connection_length(preCellTypeFile,postCellTypeFile,preNML2Type,postNML2Type,pre_cell_positions,post_cell_positions,Pre_cell,\ Post_cell,pre_target_points[0,0],post_target_point[0,0],\ pre_target_points[0,1],post_target_point[0,1]) <=connectivity_parameters['maximalConnDistance']: x=1 else: post_target_point=get_unique_target_points(post_pop_target_segment_array,post_targeting_mode,\ post_targeting_parameters,1) Pre_segment_id=pre_target_points[0,0] Post_segment_id=post_target_point[0,0] Pre_fraction=pre_target_points[0,1] Post_fraction=post_target_point[0,1] conn =neuroml.ElectricalConnectionInstance(id=conn_count,\ pre_cell="../%s/%d/%s"%(prePop,Pre_cell,preCellType),\ post_cell="../%s/%d/%s"%(postPop,Post_cell,postCellType),synapse="gap_junction%d%d"%(pair_id,gap_counter),\ pre_segment="%d"%Pre_segment_id,post_segment="%d"%Post_segment_id,\ pre_fraction_along="%f"%Pre_fraction,post_fraction_along="%f"%Post_fraction) gap_counter+=1 proj.electrical_connection_instances.append(conn) conn_count+=1 ######## conductanceUnits=connectivity_parameters['units'] if len(conductance_array)==gap_counter: for GJ in range(0,len(conductance_array)): if make_conductance_array_no_spatial_scale: conductanceValue=conductance_array[GJ]*(sum(conductance_array_spatial_scale1)/sum(conductance_array)) gap_junction = neuroml.GapJunction(id="gap_junction%d%d"%(pair_id,GJ), conductance="%f%s"%(conductanceValue*conductance_scaling,conductanceUnits) ) gapJ_object_array.append(gap_junction) else: conductanceValue=conductance_array[GJ] gap_junction = neuroml.GapJunction(id="gap_junction%d%d"%(pair_id,GJ), conductance="%f%s"%(conductanceValue*conductance_scaling,conductanceUnits) ) gapJ_object_array.append(gap_junction) return proj, nonempty_projection,gapJ_object_array
def Vervaeke_2012_AND_explicit_conn_prob_model(pair_id,projection_id,prePop,prePop_listIndex,prePopSize,preCellType,preNML2Type,pre_cell_positions,\ postPop,postPop_listIndex,postPopSize,postCellType,postNML2Type,post_cell_positions,\ connectivity_parameters,seed_number,parentDir=None): random.seed(seed_number) nonempty_projection=False gapJ_object_array=[] gap_counter=0 ####### if parentDir != None: preCellTypeFile=parentDir+"/NeuroML2"+"/"+preCellType postCellTypeFile=parentDir+"/NeuroML2"+"/"+postCellType else: preCellTypeFile=preCellType postCellTypeFile=postCellType if connectivity_parameters['targetingModelprePop']['model']=="segment groups and segments": pre_pop_target_segment_array=extract_morphology_information([preCellTypeFile],{preCellTypeFile:preNML2Type},\ ["segment groups", \ connectivity_parameters['targetingModelprePop']['segmentGroupList']]) if connectivity_parameters['targetingModelprePop']['model']=="segments and subsegments": pre_pop_target_segment_array=extract_morphology_information([preCellTypeFile],{preCellTypeFile:preNML2Type}, \ ["segments",connectivity_parameters['targetingModelprePop']['segmentList']]) if connectivity_parameters['targetingModelpostPop']['model']=="segment groups and segments": post_pop_target_segment_array=extract_morphology_information([postCellTypeFile],{postCellTypeFile:postNML2Type},\ ["segment groups",connectivity_parameters['targetingModelpostPop']['segmentGroupList'] ] ) if connectivity_parameters['targetingModelpostPop']['model']=="segments and subsegments": post_pop_target_segment_array=extract_morphology_information([postCellTypeFile],{postCellTypeFile:postNML2Type}, \ ["segments",connectivity_parameters['targetingModelpostPop']['segmentGroupList']]) proj = neuroml.ElectricalProjection(id="proj%d"%projection_id,presynaptic_population=prePop,postsynaptic_population=postPop) conn_count = 0 variable_No_of_GJs=False if connectivity_parameters['gapJunctionModel']=="constant number of GJ contacts per pair": no_of_GJcon_per_pair=connectivity_parameters['numberGJ'] if connectivity_parameters['gapJunctionModel']=="variable number of GJ contacts per pair": variable_No_of_GJs=True if connectivity_parameters['distributionGJ']=="binomial": maxGJs=connectivity_parameters['maxNoGJs'] averageGJs=connectivity_parameters['averageNoGJs'] averageGJs=float(averageGJs) probGJs=averageGJs/maxGJs #### other models can be added in the future conductance_scaling=1 if 'testingConductanceScale' in connectivity_parameters: conductance_scaling=connectivity_parameters['testingConductanceScale'] if connectivity_parameters['conductanceModel']=="constant": conductance_value=connectivity_parameters['conductanceValue'] conductance_units=connectivity_parameters['units'] gap_junction = neuroml.GapJunction(id="gap_junction%d%d"%(pair_id,gap_counter),conductance="%f%s"%(conductance_value*conductance_scaling,conductance_units)) gap_id_per_pair="gap_junction%d"%gap_counter gapJ_object_array.append(gap_junction) gap_counter+=1 spatial_scale=1 if 'spatialScale' in connectivity_parameters: spatial_scale=connectivity_parameters['spatialScale'] one_population=False if prePop==postPop: one_population=True for Pre_cell in range(0,prePopSize): if one_population: post_index_array=range(0,postPopSize) post_index_array.remove(Pre_cell) else: post_index_array=range(0,postPopSize) for Post_cell in post_index_array: if Pre_cell <= Post_cell: if connectivity_parameters['electricalConnModel']=="explicit_connection_probabilities": connection_probability=connectivity_parameters['connProbability'] if connectivity_parameters['electricalConnModel']=="Vervaeke_2012_based": distance_between_cells=distance(pre_cell_positions[Pre_cell],post_cell_positions[Post_cell])/spatial_scale connection_probability=connection_probability_vervaeke_2010(distance_between_cells) if random.random() < connection_probability: nonempty_projection=True if variable_No_of_GJs: if connectivity_parameters['distributionGJ']=="binomial": no_of_GJcon_per_pair=np.random.binomial(maxGJs,probGJs) if connectivity_parameters['targetingModelprePop']['model']=="segment groups and segments": pre_target_points=get_unique_target_points(pre_pop_target_segment_array,"segment groups and segments",\ [connectivity_parameters['targetingModelprePop']['segmentGroupList'],\ connectivity_parameters['targetingModelprePop']['segmentGroupProbabilities']],no_of_GJcon_per_pair) if connectivity_parameters['targetingModelprePop']['model']=="segments and subsegments": pre_target_points=get_unique_target_points(pre_pop_target_segment_array,"segments and subsegments",\ [connectivity_parameters['targetingModelprePop']['segmentList'],\ connectivity_parameters['targetingModelprePop']['segmentProbabilities'],\ connectivity_parameters['targetingModelprePop']['fractionAlongANDsubsegProbabilities']],no_of_GJcon_per_pair) if connectivity_parameters['targetingModelpostPop']['model']=="segment groups and segments": post_targeting_mode="segment groups and segments" post_targeting_parameters=[connectivity_parameters['targetingModelpostPop']['segmentGroupList'],\ connectivity_parameters['targetingModelpostPop']['segmentGroupProbabilities']] if connectivity_parameters['targetingModelpostPop']['model']=="segments and subsegments": post_targeting_mode="segments and subsegments" post_targeting_parameters=[connectivity_parameters['targetingModelpostPop']['segmentList'],\ connectivity_parameters['targetingModelpostPop']['segmentProbabilities'],connectivity_parameters['targetingModelpostPop']['fractionAlongANDsubsegProbabilities']] for pre_target_point in range(0,len(pre_target_points)): if 'maximalConnDistance' in connectivity_parameters: x=0 while x==0: post_target_point=get_unique_target_points(post_pop_target_segment_array,post_targeting_mode,post_targeting_parameters,1) if get_3D_connection_length(preCellTypeFile,postCellTypeFile,preNML2Type,postNML2Type,pre_cell_positions,post_cell_positions,Pre_cell,\ Post_cell,pre_target_points[pre_target_point,0],post_target_point[0,0],\ pre_target_points[pre_target_point,1],post_target_point[0,1]) <=connectivity_parameters['maximalConnDistance']: x=1 else: post_target_point=get_unique_target_points(post_pop_target_segment_array,post_targeting_mode,\ post_targeting_parameters,1) Pre_segment_id=pre_target_points[pre_target_point,0] Post_segment_id=post_target_point[0,0] Pre_fraction=pre_target_points[pre_target_point,1] Post_fraction=post_target_point[0,1] if connectivity_parameters['conductanceModel']=="variable": if string.lower(connectivity_parameters['distribution'])=="gaussian": conductance=random.gauss(connectivity_parameters['averageConductance'],connectivity_parameters['stdDev']) conductanceUnits=connectivity_parameters['units'] gap_junction = neuroml.GapJunction(id="gap_junction%d%d"%(pair_id,gap_counter), conductance="%f%s"%(conductance*conductance_scaling,conductanceUnits) ) gapJ_object_array.append(gap_junction) gap_counter+=1 #other options can be added such as gamma distribution conn =neuroml.ElectricalConnectionInstance(id=conn_count,\ pre_cell="../%s/%d/%s"%(prePop,Pre_cell,preCellType),\ post_cell="../%s/%d/%s"%(postPop,Post_cell,postCellType),synapse=gap_junction.id,\ pre_segment="%d"%Pre_segment_id,post_segment="%d"%Post_segment_id,\ pre_fraction_along="%f"%Pre_fraction,post_fraction_along="%f"%Post_fraction) proj.electrical_connection_instances.append(conn) conn_count+=1 return proj, nonempty_projection,gapJ_object_array
def create_GoC_network( duration, dt, seed, N_goc=0, run=False, prob_type='Boltzmann', GJw_type='Vervaeke2010' ): goc_filename = 'GoC.cell.nml' goc_file = pynml.read_neuroml2_file( goc_filename ) goc_type = goc_file.cells[0] GJ_filename = 'GapJuncCML.nml' GJ_file = pynml.read_neuroml2_file( GJ_filename ) GJ_type = GJ_file.gap_junctions[0] MFSyn_filename = 'MF_GoC_Syn.nml' mfsyn_file = pynml.read_neuroml2_file( MFSyn_filename ) MFSyn_type = mfsyn_file.exp_three_synapses[0] MF20Syn_filename = 'MF_GoC_SynMult.nml' mf20syn_file = pynml.read_neuroml2_file( MF20Syn_filename ) MF20Syn_type = mf20syn_file.exp_three_synapses[0] # Distribute cells in 3D if N_goc>0: GoC_pos = nu.GoC_locate(N_goc) else: GoC_pos = nu.GoC_density_locate() N_goc = GoC_pos.shape[0] # get GJ connectivity GJ_pairs, GJWt = nu.GJ_conn( GoC_pos, prob_type, GJw_type ) tmp1, tmp2 = valnet.gapJuncAnalysis( GJ_pairs, GJWt ) print("Number of gap junctions per cell: ", tmp1) print("Net GJ conductance per cell:", tmp2) # Create pop List goc_pop = nml.Population( id=goc_type.id+"Pop", component = goc_type.id, type="populationList", size=N_goc ) # Create NML document for network specification net = nml.Network( id="gocNetwork", type="networkWithTemperature" , temperature="23 degC" ) net_doc = nml.NeuroMLDocument( id=net.id ) net_doc.networks.append( net ) net_doc.includes.append( goc_type ) net.populations.append( goc_pop ) #Add locations for GoC instances in the population: for goc in range(N_goc): inst = nml.Instance( id=goc ) goc_pop.instances.append( inst ) inst.location = nml.Location( x=GoC_pos[goc,0], y=GoC_pos[goc,1], z=GoC_pos[goc,2] ) # Define input spiketrains input_type = 'spikeGenerator'#'spikeGeneratorPoisson' lems_inst_doc = lems.Model() mf_inputs = lems.Component( "MF_Input", input_type) mf_inputs.set_parameter("period", "2000 ms" ) #mf_inputs.set_parameter("averageRate", "50 Hz") lems_inst_doc.add( mf_inputs ) #synapse_type = 'alphaCurrentSynapse' #alpha_syn = lems.Component( "AlphaSyn", synapse_type) #alpha_syn.set_parameter("tau", "30 ms" ) #alpha_syn.set_parameter("ibase", "200 pA") #lems_inst_doc.add( alpha_syn ) # Define MF input population N_mf = 15 #MF_pop = nml.Population(id=mf_inputs.id+"_pop", component=mf_inputs.id, type="populationList", size=N_mf) #net.populations.append( MF_pop ) mf_type2 = 'spikeGeneratorPoisson' #mf_poisson = lems.Component( "MF_Poisson", mf_type2) #mf_poisson.set_parameter("averageRate", "5 Hz") #lems_inst_doc.add( mf_poisson ) # adding in neuroml document instead of mf_poisson mf_poisson = nml.SpikeGeneratorPoisson( id = "MF_Poisson", average_rate="5 Hz" ) net_doc.spike_generator_poissons.append( mf_poisson ) net_doc.includes.append( goc_type ) MF_Poisson_pop = nml.Population(id=mf_poisson.id+"_pop", component=mf_poisson.id, type="populationList", size=N_mf) net.populations.append( MF_Poisson_pop ) MF_pos = nu.GoC_locate( N_mf ) for mf in range( N_mf ): inst = nml.Instance(id=mf) MF_Poisson_pop.instances.append( inst ) inst.location = nml.Location( x=MF_pos[mf,0], y=MF_pos[mf,1], z=MF_pos[mf,2] ) # Setup Mf->GoC synapses #MFprojection = nml.Projection(id="MFtoGoC", presynaptic_population=MF_pop.id, postsynaptic_population=goc_pop.id, synapse=alpha_syn.id) #net.projections.append(MFprojection) MF2projection = nml.Projection(id="MF2toGoC", presynaptic_population=MF_Poisson_pop.id, postsynaptic_population=goc_pop.id, synapse=MFSyn_type.id)#alpha_syn.id net.projections.append(MF2projection) #Get list of MF->GoC synapse mf_synlist = nu.randdist_MF_syn( N_mf, N_goc, pConn=0.3) nMFSyn = mf_synlist.shape[1] for syn in range( nMFSyn ): mf, goc = mf_synlist[:, syn] conn2 = nml.Connection(id=syn, pre_cell_id='../{}/{}/{}'.format(MF_Poisson_pop.id, mf, mf_poisson.id), post_cell_id='../{}/{}/{}'.format(goc_pop.id, goc, goc_type.id), post_segment_id='0', post_fraction_along="0.5") MF2projection.connections.append(conn2) # Burst of MF input (as explicit input) mf_bursttype = 'transientPoissonFiringSynapse' mf_burst = lems.Component( "MF_Burst", mf_bursttype) mf_burst.set_parameter( "averageRate", "100 Hz" ) mf_burst.set_parameter( "delay", "2000 ms" ) mf_burst.set_parameter( "duration", "500 ms" ) mf_burst.set_parameter( "synapse", MF20Syn_type.id ) mf_burst.set_parameter( "spikeTarget", './{}'.format(MF20Syn_type.id) ) lems_inst_doc.add( mf_burst ) # Add few burst inputs n_bursts = 4 gocPerm = np.random.permutation( N_goc ) ctr = 0 for gg in range(4): goc = gocPerm[gg] for jj in range( n_bursts ): inst = nml.ExplicitInput( id=ctr, target='../{}/{}/{}'.format(goc_pop.id, goc, goc_type.id), input=mf_burst.id, synapse=MF20Syn_type.id, spikeTarget='./{}'.format(MF20Syn_type.id)) net.explicit_inputs.append( inst ) ctr += 1 ''' one-to-one pairing of MF and GoC -> no shared inputs for goc in range(N_mf): #inst = nml.Instance(id=goc) #MF_pop.instances.append( inst ) #inst.location = nml.Location( x=GoC_pos[goc,0], y=GoC_pos[goc,1], z=GoC_pos[goc,2]+100 ) #conn = nml.Connection(id=goc, pre_cell_id='../{}/{}/{}'.format(MF_pop.id, goc, mf_inputs.id), post_cell_id='../{}/{}/{}'.format(goc_pop.id, goc, goc_type.id), post_segment_id='0', post_fraction_along="0.5") #MFprojection.connections.append(conn) goc2 = N_goc-goc-1 inst2 = nml.Instance(id=goc) MF_Poisson_pop.instances.append( inst2 ) inst2.location = nml.Location( x=GoC_pos[goc2,0], y=GoC_pos[goc2,1], z=GoC_pos[goc2,2]+100 ) conn2 = nml.Connection(id=goc, pre_cell_id='../{}/{}/{}'.format(MF_Poisson_pop.id, goc, mf_poisson.id), post_cell_id='../{}/{}/{}'.format(goc_pop.id, goc2, goc_type.id), post_segment_id='0', post_fraction_along="0.5") MF2projection.connections.append(conn2) ''' # Add electrical synapses GoCCoupling = nml.ElectricalProjection( id="gocGJ", presynaptic_population=goc_pop.id, postsynaptic_population=goc_pop.id ) #print(GJ_pairs) gj = nml.GapJunction( id="GJ_0", conductance="426pS" ) net_doc.gap_junctions.append(gj) nGJ = GJ_pairs.shape[0] for jj in range( nGJ ): #gj.append( lems.Component( "GJ_%d"%jj, 'gapJunction') ) #gj[jj].set_parameter( "conductance", "%fnS"%(GJWt[jj]) ) #gj = nml.GapJunction(id="GJ_%d"%jj, conductance="%fnS"%(GJWt[jj])) #net_doc.gap_junctions.append(gj) #lems_inst_doc.add( gj[jj] ) #print("%fnS"%(GJWt[jj]*0.426)) conn = nml.ElectricalConnectionInstanceW( id=jj, pre_cell='../{}/{}/{}'.format(goc_pop.id, GJ_pairs[jj,0], goc_type.id), pre_segment='1', pre_fraction_along='0.5', post_cell='../{}/{}/{}'.format(goc_pop.id, GJ_pairs[jj,1], goc_type.id), post_segment='1', post_fraction_along='0.5', synapse=gj.id, weight=GJWt[jj] )#synapse="GapJuncCML" synapse=gj.id , conductance="100E-9mS" # ------------ need to create GJ component GoCCoupling.electrical_connection_instance_ws.append( conn ) net.electrical_projections.append( GoCCoupling ) net_filename = 'gocNetwork.nml' pynml.write_neuroml2_file( net_doc, net_filename ) lems_filename = 'instances.xml' pynml.write_lems_file( lems_inst_doc, lems_filename, validate=False ) simid = 'sim_gocnet'+goc_type.id ls = LEMSSimulation( simid, duration=duration, dt=dt, simulation_seed=seed ) ls.assign_simulation_target( net.id ) #ls.include_lems_file( 'Synapses.xml', include_included=False) #ls.include_lems_file( 'Inputs.xml', include_included=False) ls.include_neuroml2_file( net_filename) ls.include_neuroml2_file( goc_filename) ls.include_neuroml2_file( GJ_filename) ls.include_neuroml2_file( MFSyn_filename) ls.include_neuroml2_file( MF20Syn_filename) ls.include_lems_file( lems_filename, include_included=False) # Specify outputs eof0 = 'Events_file' ls.create_event_output_file(eof0, "%s.v.spikes"%simid,format='ID_TIME') for jj in range( goc_pop.size): ls.add_selection_to_event_output_file( eof0, jj, '{}/{}/{}'.format( goc_pop.id, jj, goc_type.id), 'spike' ) of0 = 'Volts_file' ls.create_output_file(of0, "%s.v.dat"%simid) for jj in range( goc_pop.size ): ls.add_column_to_output_file(of0, jj, '{}/{}/{}/v'.format( goc_pop.id, jj, goc_type.id)) #Create Lems file to run lems_simfile = ls.save_to_file() #res = pynml.run_lems_with_jneuroml( lems_simfile, max_memory="1G",nogui=True, plot=False) #res = pynml.run_lems_with_jneuroml_neuron( lems_simfile, max_memory="2G", only_generate_scripts = True, compile_mods = False, nogui=True, plot=False) res = pynml.run_lems_with_jneuroml_neuron( lems_simfile, max_memory="2G", compile_mods = False,nogui=True, plot=False) #res=True return res