def get_cell_muscle_names_and_connection(test=False): spreadsheet_location = os.path.dirname(os.path.abspath(__file__))+"/../../../" mneurons, all_muscles, muscle_conns = SpreadsheetDataReader.readMuscleDataFromSpreadsheet() return mneurons, all_muscles, muscle_conns
def get_cell_muscle_names_and_connection(test=False): spreadsheet_location = "../../../../" if test else "../../../" mneurons, all_muscles, muscle_conns = SpreadsheetDataReader.readMuscleDataFromSpreadsheet(spreadsheet_location) return mneurons, all_muscles, muscle_conns
def generate(net_id, params, cells = None, cells_to_plot = None, cells_to_stimulate = None, include_muscles=False, conn_number_override = None, conn_number_scaling = None, duration = 500, dt = 0.01, vmin = -75, vmax = 20, seed = 1234, validate=True, test=False): random.seed(seed) info = "\n\nParameters and setting used to generate this network:\n\n"+\ " Cells: %s\n" % (cells if cells is not None else "All cells")+\ " Cell stimulated: %s\n" % (cells_to_stimulate if cells_to_stimulate is not None else "All cells")+\ " Connection numbers overridden: %s\n" % (conn_number_override if conn_number_override is not None else "None")+\ " Connection numbers scaled: %s\n" % (conn_number_scaling if conn_number_scaling is not None else "None")+\ " Include muscles: %s\n" % include_muscles info += "\n%s\n"%(bioparameter_info(" ")) nml_doc = NeuroMLDocument(id=net_id, notes=info) nml_doc.iaf_cells.append(params.generic_cell) net = Network(id=net_id) nml_doc.networks.append(net) nml_doc.pulse_generators.append(params.offset_current) # Use the spreadsheet reader to give a list of all cells and a list of all connections # This could be replaced with a call to "DatabaseReader" or "OpenWormNeuroLexReader" in future... # If called from unittest folder ammend path to "../../../../" spreadsheet_location = "../../../../" if test else "../../../" cell_names, conns = SpreadsheetDataReader.readDataFromSpreadsheet(spreadsheet_location, include_nonconnected_cells=True) cell_names.sort() # To hold all Cell NeuroML objects vs. names all_cells = {} # lems_file = "" lems_info = {"comment": info, "reference": net_id, "duration": duration, "dt": dt, "vmin": vmin, "vmax": vmax, "cell_component": params.generic_cell.id} lems_info["plots"] = [] lems_info["activity_plots"] = [] lems_info["muscle_plots"] = [] lems_info["muscle_activity_plots"] = [] lems_info["to_save"] = [] lems_info["activity_to_save"] = [] lems_info["muscles_to_save"] = [] lems_info["muscles_activity_to_save"] = [] lems_info["cells"] = [] lems_info["muscles"] = [] lems_info["includes"] = [] if hasattr(params.generic_cell, 'custom_component_type_definition'): lems_info["includes"].append(params.generic_cell.custom_component_type_definition) backers_dir = "../../../../OpenWormBackers/" if test else "../../../OpenWormBackers/" sys.path.append(backers_dir) import backers cells_vs_name = backers.get_adopted_cell_names(backers_dir) populations_without_location = isinstance(params.elec_syn, GapJunction) count = 0 for cell in cell_names: if cells is None or cell in cells: inst = Instance(id="0") if not populations_without_location: # build a Population data structure out of the cell name pop0 = Population(id=cell, component=params.generic_cell.id, type="populationList") pop0.instances.append(inst) else: # build a Population data structure out of the cell name pop0 = Population(id=cell, component=params.generic_cell.id, size="1") # put that Population into the Network data structure from above net.populations.append(pop0) if cells_vs_name.has_key(cell): p = Property(tag="OpenWormBackerAssignedName", value=cells_vs_name[cell]) pop0.properties.append(p) # also use the cell name to grab the morphology file, as a NeuroML data structure # into the 'all_cells' dict cell_file_path = "../../../" if test else "../../" #if running test cell_file = cell_file_path+'generatedNeuroML2/%s.nml'%cell doc = loaders.NeuroMLLoader.load(cell_file) all_cells[cell] = doc.cells[0] location = doc.cells[0].morphology.segments[0].proximal print("Loaded morphology file from: %s, with id: %s, location: (%s, %s, %s)"%(cell_file, all_cells[cell].id, location.x, location.y, location.z)) inst.location = Location(float(location.x), float(location.y), float(location.z)) target = "%s/0/%s"%(pop0.id, params.generic_cell.id) if populations_without_location: target = "%s[0]" % (cell) exp_input = ExplicitInput(target=target, input=params.offset_current.id) if cells_to_stimulate is None or cell in cells_to_stimulate: net.explicit_inputs.append(exp_input) if cells_to_plot is None or cell in cells_to_plot: plot = {} plot["cell"] = cell plot["colour"] = get_random_colour_hex() plot["quantity"] = "%s/0/%s/v" % (cell, params.generic_cell.id) if populations_without_location: plot["quantity"] = "%s[0]/v" % (cell) lems_info["plots"].append(plot) if hasattr(params.generic_cell, 'custom_component_type_definition'): plot = {} plot["cell"] = cell plot["colour"] = get_random_colour_hex() plot["quantity"] = "%s/0/%s/activity" % (cell, params.generic_cell.id) if populations_without_location: plot["quantity"] = "%s[0]/activity" % (cell) lems_info["activity_plots"].append(plot) save = {} save["cell"] = cell save["quantity"] = "%s/0/%s/v" % (cell, params.generic_cell.id) if populations_without_location: save["quantity"] = "%s[0]/v" % (cell) lems_info["to_save"].append(save) if hasattr(params.generic_cell, 'custom_component_type_definition'): save = {} save["cell"] = cell save["quantity"] = "%s/0/%s/activity" % (cell, params.generic_cell.id) if populations_without_location: save["quantity"] = "%s[0]/activity" % (cell) lems_info["activity_to_save"].append(save) lems_info["cells"].append(cell) count+=1 print("Finished loading %i cells"%count) mneurons, all_muscles, muscle_conns = SpreadsheetDataReader.readMuscleDataFromSpreadsheet(spreadsheet_location) muscles = get_muscle_names() if include_muscles: muscle_count = 0 for muscle in muscles: inst = Instance(id="0") if not populations_without_location: # build a Population data structure out of the cell name pop0 = Population(id=muscle, component=params.generic_cell.id, type="populationList") pop0.instances.append(inst) else: # build a Population data structure out of the cell name pop0 = Population(id=muscle, component=params.generic_cell.id, size="1") # put that Population into the Network data structure from above net.populations.append(pop0) if cells_vs_name.has_key(muscle): # No muscles adopted yet, but just in case they are in future... p = Property(tag="OpenWormBackerAssignedName", value=cells_vs_name[muscle]) pop0.properties.append(p) inst.location = Location(100, 10*muscle_count, 100) target = "%s/0/%s"%(pop0.id, params.generic_cell.id) if populations_without_location: target = "%s[0]" % (muscle) plot = {} plot["cell"] = muscle plot["colour"] = get_random_colour_hex() plot["quantity"] = "%s/0/%s/v" % (muscle, params.generic_cell.id) if populations_without_location: plot["quantity"] = "%s[0]/v" % (muscle) lems_info["muscle_plots"].append(plot) if hasattr(params.generic_cell, 'custom_component_type_definition'): plot = {} plot["cell"] = muscle plot["colour"] = get_random_colour_hex() plot["quantity"] = "%s/0/%s/activity" % (muscle, params.generic_cell.id) if populations_without_location: plot["quantity"] = "%s[0]/activity" % (muscle) lems_info["muscle_activity_plots"].append(plot) save = {} save["cell"] = muscle save["quantity"] = "%s/0/%s/v" % (muscle, params.generic_cell.id) if populations_without_location: save["quantity"] = "%s[0]/v" % (muscle) lems_info["muscles_to_save"].append(save) if hasattr(params.generic_cell, 'custom_component_type_definition'): save = {} save["cell"] = muscle save["quantity"] = "%s/0/%s/activity" % (muscle, params.generic_cell.id) if populations_without_location: save["quantity"] = "%s[0]/activity" % (muscle) lems_info["muscles_activity_to_save"].append(save) lems_info["muscles"].append(muscle) muscle_count+=1 print("Finished creating %i muscles"%muscle_count) for conn in conns: if conn.pre_cell in lems_info["cells"] and conn.post_cell in lems_info["cells"]: # take information about each connection and package it into a # NeuroML Projection data structure proj_id = get_projection_id(conn.pre_cell, conn.post_cell, conn.synclass, conn.syntype) elect_conn = False syn0 = params.exc_syn if 'GABA' in conn.synclass: syn0 = params.inh_syn if '_GJ' in conn.synclass: syn0 = params.elec_syn elect_conn = isinstance(params.elec_syn, GapJunction) number_syns = conn.number conn_shorthand = "%s-%s"%(conn.pre_cell, conn.post_cell) if conn_number_override is not None and (conn_number_override.has_key(conn_shorthand)): number_syns = conn_number_override[conn_shorthand] elif conn_number_scaling is not None and (conn_number_scaling.has_key(conn_shorthand)): number_syns = conn.number*conn_number_scaling[conn_shorthand] ''' else: print conn_shorthand print conn_number_override print conn_number_scaling''' if number_syns != conn.number: magnitude, unit = split_neuroml_quantity(syn0.gbase) cond0 = "%s%s"%(magnitude*conn.number, unit) cond1 = "%s%s"%(magnitude*number_syns, unit) print(">> Changing number of effective synapses connection %s -> %s: was: %s (total cond: %s), becomes %s (total cond: %s)" % \ (conn.pre_cell, conn.post_cell, conn.number, cond0, number_syns, cond1)) syn_new = create_n_connection_synapse(syn0, number_syns, nml_doc) if not elect_conn: if not populations_without_location: proj0 = Projection(id=proj_id, \ presynaptic_population=conn.pre_cell, postsynaptic_population=conn.post_cell, synapse=syn_new.id) net.projections.append(proj0) # Add a Connection with the closest locations pre_cell_id="../%s/0/%s"%(conn.pre_cell, params.generic_cell.id) post_cell_id="../%s/0/%s"%(conn.post_cell, params.generic_cell.id) conn0 = Connection(id="0", \ pre_cell_id=pre_cell_id, post_cell_id=post_cell_id) proj0.connections.append(conn0) if populations_without_location: # <synapticConnection from="hh1pop[0]" to="hh2pop[0]" synapse="syn1exp" destination="synapses"/> pre_cell_id="%s[0]"%(conn.pre_cell) post_cell_id="%s[0]"%(conn.post_cell) conn0 = SynapticConnection(from_=pre_cell_id, to=post_cell_id, synapse=syn_new.id, destination="synapses") net.synaptic_connections.append(conn0) else: proj0 = ElectricalProjection(id=proj_id, \ presynaptic_population=conn.pre_cell, postsynaptic_population=conn.post_cell) net.electrical_projections.append(proj0) # Add a Connection with the closest locations conn0 = ElectricalConnection(id="0", \ pre_cell="0", post_cell="0", synapse=syn_new.id) proj0.electrical_connections.append(conn0) if include_muscles: for conn in muscle_conns: if conn.pre_cell in lems_info["cells"] and conn.post_cell in muscles: # take information about each connection and package it into a # NeuroML Projection data structure proj_id = get_projection_id(conn.pre_cell, conn.post_cell, conn.synclass, conn.syntype) elect_conn = False syn0 = params.exc_syn if 'GABA' in conn.synclass: syn0 = params.inh_syn if '_GJ' in conn.synclass: syn0 = params.elec_syn elect_conn = isinstance(params.elec_syn, GapJunction) number_syns = conn.number conn_shorthand = "%s-%s"%(conn.pre_cell, conn.post_cell) if conn_number_override is not None and (conn_number_override.has_key(conn_shorthand)): number_syns = conn_number_override[conn_shorthand] elif conn_number_scaling is not None and (conn_number_scaling.has_key(conn_shorthand)): number_syns = conn.number*conn_number_scaling[conn_shorthand] ''' else: print conn_shorthand print conn_number_override print conn_number_scaling''' if number_syns != conn.number: magnitude, unit = split_neuroml_quantity(syn0.gbase) cond0 = "%s%s"%(magnitude*conn.number, unit) cond1 = "%s%s"%(magnitude*number_syns, unit) print(">> Changing number of effective synapses connection %s -> %s: was: %s (total cond: %s), becomes %s (total cond: %s)" % \ (conn.pre_cell, conn.post_cell, conn.number, cond0, number_syns, cond1)) syn_new = create_n_connection_synapse(syn0, number_syns, nml_doc) if not elect_conn: if not populations_without_location: proj0 = Projection(id=proj_id, \ presynaptic_population=conn.pre_cell, postsynaptic_population=conn.post_cell, synapse=syn_new.id) net.projections.append(proj0) # Add a Connection with the closest locations pre_cell_id="../%s/0/%s"%(conn.pre_cell, params.generic_cell.id) post_cell_id="../%s/0/%s"%(conn.post_cell, params.generic_cell.id) conn0 = Connection(id="0", \ pre_cell_id=pre_cell_id, post_cell_id=post_cell_id) proj0.connections.append(conn0) if populations_without_location: # <synapticConnection from="hh1pop[0]" to="hh2pop[0]" synapse="syn1exp" destination="synapses"/> pre_cell_id="%s[0]"%(conn.pre_cell) post_cell_id="%s[0]"%(conn.post_cell) conn0 = SynapticConnection(from_=pre_cell_id, to=post_cell_id, synapse=syn_new.id, destination="synapses") net.synaptic_connections.append(conn0) else: proj0 = ElectricalProjection(id=proj_id, \ presynaptic_population=conn.pre_cell, postsynaptic_population=conn.post_cell) net.electrical_projections.append(proj0) # Add a Connection with the closest locations conn0 = ElectricalConnection(id="0", \ pre_cell="0", post_cell="0", synapse=syn_new.id) proj0.electrical_connections.append(conn0) # import pprint # pprint.pprint(lems_info) template_path = '../' if test else '' # if running test write_to_file(nml_doc, lems_info, net_id, template_path, validate=validate) return nml_doc
def generate(net_id, params, cells = None, cells_to_plot = None, cells_to_stimulate = None, include_muscles=False, conn_number_override = None, conn_number_scaling = None, duration = 500, dt = 0.01, vmin = None, vmax = None, seed = 1234, validate=True, test=False, verbose=True, target_directory='./'): params.create_models() if vmin==None: if params.level == 'A': vmin=-72 elif params.level == 'B': vmin=-52 elif params.level == 'C': vmin=-60 if vmax==None: if params.level == 'A': vmax=-48 elif params.level == 'B': vmax=-28 elif params.level == 'C': vmax=25 random.seed(seed) info = "\n\nParameters and setting used to generate this network:\n\n"+\ " Cells: %s\n" % (cells if cells is not None else "All cells")+\ " Cell stimulated: %s\n" % (cells_to_stimulate if cells_to_stimulate is not None else "All cells")+\ " Connection numbers overridden: %s\n" % (conn_number_override if conn_number_override is not None else "None")+\ " Connection numbers scaled: %s\n" % (conn_number_scaling if conn_number_scaling is not None else "None")+\ " Include muscles: %s\n" % include_muscles info += "\n%s\n"%(params.bioparameter_info(" ")) nml_doc = NeuroMLDocument(id=net_id, notes=info) if params.level == "A" or params.level == "B": nml_doc.iaf_cells.append(params.generic_cell) elif params.level == "C": nml_doc.cells.append(params.generic_cell) net = Network(id=net_id) nml_doc.networks.append(net) nml_doc.pulse_generators.append(params.offset_current) # Use the spreadsheet reader to give a list of all cells and a list of all connections # This could be replaced with a call to "DatabaseReader" or "OpenWormNeuroLexReader" in future... # If called from unittest folder ammend path to "../../../../" spreadsheet_location = "../../../../" if test else "../../../" cell_names, conns = SpreadsheetDataReader.readDataFromSpreadsheet(spreadsheet_location, include_nonconnected_cells=True) cell_names.sort() # To hold all Cell NeuroML objects vs. names all_cells = {} # lems_file = "" lems_info = {"comment": info, "reference": net_id, "duration": duration, "dt": dt, "vmin": vmin, "vmax": vmax, "cell_component": params.generic_cell.id} lems_info["plots"] = [] lems_info["activity_plots"] = [] lems_info["muscle_plots"] = [] lems_info["muscle_activity_plots"] = [] lems_info["to_save"] = [] lems_info["activity_to_save"] = [] lems_info["muscles_to_save"] = [] lems_info["muscles_activity_to_save"] = [] lems_info["cells"] = [] lems_info["muscles"] = [] lems_info["includes"] = [] if params.custom_component_types_definitions: lems_info["includes"].append(params.custom_component_types_definitions) if target_directory != './': def_file = "%s/%s"%(os.path.dirname(__file__), params.custom_component_types_definitions) shutil.copy(def_file, target_directory) backers_dir = "../../../../OpenWormBackers/" if test else "../../../OpenWormBackers/" sys.path.append(backers_dir) import backers cells_vs_name = backers.get_adopted_cell_names(backers_dir) populations_without_location = isinstance(params.elec_syn, GapJunction) count = 0 for cell in cell_names: if cells is None or cell in cells: inst = Instance(id="0") if not populations_without_location: # build a Population data structure out of the cell name pop0 = Population(id=cell, component=params.generic_cell.id, type="populationList") pop0.instances.append(inst) else: # build a Population data structure out of the cell name pop0 = Population(id=cell, component=params.generic_cell.id, size="1") # put that Population into the Network data structure from above net.populations.append(pop0) if cells_vs_name.has_key(cell): p = Property(tag="OpenWormBackerAssignedName", value=cells_vs_name[cell]) pop0.properties.append(p) # also use the cell name to grab the morphology file, as a NeuroML data structure # into the 'all_cells' dict cell_file_path = "../../../" if test else "../../" #if running test cell_file = cell_file_path+'generatedNeuroML2/%s.cell.nml'%cell doc = loaders.NeuroMLLoader.load(cell_file) all_cells[cell] = doc.cells[0] location = doc.cells[0].morphology.segments[0].proximal if verbose: print("Loaded morphology file from: %s, with id: %s, location: (%s, %s, %s)"%(cell_file, all_cells[cell].id, location.x, location.y, location.z)) inst.location = Location(float(location.x), float(location.y), float(location.z)) target = "%s/0/%s"%(pop0.id, params.generic_cell.id) if populations_without_location: target = "%s[0]" % (cell) exp_input = ExplicitInput(target=target, input=params.offset_current.id) if cells_to_stimulate is None or cell in cells_to_stimulate: net.explicit_inputs.append(exp_input) if cells_to_plot is None or cell in cells_to_plot: plot = {} plot["cell"] = cell plot["colour"] = get_random_colour_hex() plot["quantity"] = "%s/0/%s/v" % (cell, params.generic_cell.id) if populations_without_location: plot["quantity"] = "%s[0]/v" % (cell) lems_info["plots"].append(plot) if params.generic_cell.__class__.__name__ == 'IafActivityCell': plot = {} plot["cell"] = cell plot["colour"] = get_random_colour_hex() plot["quantity"] = "%s/0/%s/activity" % (cell, params.generic_cell.id) if populations_without_location: plot["quantity"] = "%s[0]/activity" % (cell) lems_info["activity_plots"].append(plot) if params.generic_cell.__class__.__name__ == 'Cell': plot = {} plot["cell"] = cell plot["colour"] = get_random_colour_hex() plot["quantity"] = "%s/0/%s/caConc" % (cell, params.generic_cell.id) if populations_without_location: plot["quantity"] = "%s[0]/caConc" % (cell) lems_info["activity_plots"].append(plot) save = {} save["cell"] = cell save["quantity"] = "%s/0/%s/v" % (cell, params.generic_cell.id) if populations_without_location: save["quantity"] = "%s[0]/v" % (cell) lems_info["to_save"].append(save) if params.generic_cell.__class__.__name__ == 'IafActivityCell': save = {} save["cell"] = cell save["quantity"] = "%s/0/%s/activity" % (cell, params.generic_cell.id) if populations_without_location: save["quantity"] = "%s[0]/activity" % (cell) lems_info["activity_to_save"].append(save) lems_info["cells"].append(cell) count+=1 if verbose: print("Finished loading %i cells"%count) mneurons, all_muscles, muscle_conns = SpreadsheetDataReader.readMuscleDataFromSpreadsheet(spreadsheet_location) muscles = get_muscle_names() if include_muscles: muscle_count = 0 for muscle in muscles: inst = Instance(id="0") if not populations_without_location: # build a Population data structure out of the cell name pop0 = Population(id=muscle, component=params.generic_cell.id, type="populationList") pop0.instances.append(inst) else: # build a Population data structure out of the cell name pop0 = Population(id=muscle, component=params.generic_cell.id, size="1") # put that Population into the Network data structure from above net.populations.append(pop0) if cells_vs_name.has_key(muscle): # No muscles adopted yet, but just in case they are in future... p = Property(tag="OpenWormBackerAssignedName", value=cells_vs_name[muscle]) pop0.properties.append(p) inst.location = Location(100, 10*muscle_count, 100) target = "%s/0/%s"%(pop0.id, params.generic_cell.id) if populations_without_location: target = "%s[0]" % (muscle) plot = {} plot["cell"] = muscle plot["colour"] = get_random_colour_hex() plot["quantity"] = "%s/0/%s/v" % (muscle, params.generic_cell.id) if populations_without_location: plot["quantity"] = "%s[0]/v" % (muscle) lems_info["muscle_plots"].append(plot) if params.generic_cell.__class__.__name__ == 'IafActivityCell': plot = {} plot["cell"] = muscle plot["colour"] = get_random_colour_hex() plot["quantity"] = "%s/0/%s/activity" % (muscle, params.generic_cell.id) if populations_without_location: plot["quantity"] = "%s[0]/activity" % (muscle) lems_info["muscle_activity_plots"].append(plot) save = {} save["cell"] = muscle save["quantity"] = "%s/0/%s/v" % (muscle, params.generic_cell.id) if populations_without_location: save["quantity"] = "%s[0]/v" % (muscle) lems_info["muscles_to_save"].append(save) if params.generic_cell.__class__.__name__ == 'IafActivityCell': save = {} save["cell"] = muscle save["quantity"] = "%s/0/%s/activity" % (muscle, params.generic_cell.id) if populations_without_location: save["quantity"] = "%s[0]/activity" % (muscle) lems_info["muscles_activity_to_save"].append(save) lems_info["muscles"].append(muscle) muscle_count+=1 if verbose: print("Finished creating %i muscles"%muscle_count) existing_synapses = {} for conn in conns: if conn.pre_cell in lems_info["cells"] and conn.post_cell in lems_info["cells"]: # take information about each connection and package it into a # NeuroML Projection data structure proj_id = get_projection_id(conn.pre_cell, conn.post_cell, conn.synclass, conn.syntype) elect_conn = False syn0 = params.exc_syn if 'GABA' in conn.synclass: syn0 = params.inh_syn if '_GJ' in conn.synclass: syn0 = params.elec_syn elect_conn = isinstance(params.elec_syn, GapJunction) number_syns = conn.number conn_shorthand = "%s-%s"%(conn.pre_cell, conn.post_cell) if conn_number_override is not None and (conn_number_override.has_key(conn_shorthand)): number_syns = conn_number_override[conn_shorthand] elif conn_number_scaling is not None and (conn_number_scaling.has_key(conn_shorthand)): number_syns = conn.number*conn_number_scaling[conn_shorthand] ''' else: print conn_shorthand print conn_number_override print conn_number_scaling''' if number_syns != conn.number: magnitude, unit = bioparameters.split_neuroml_quantity(syn0.gbase) cond0 = "%s%s"%(magnitude*conn.number, unit) cond1 = "%s%s"%(magnitude*number_syns, unit) if verbose: print(">> Changing number of effective synapses connection %s -> %s: was: %s (total cond: %s), becomes %s (total cond: %s)" % \ (conn.pre_cell, conn.post_cell, conn.number, cond0, number_syns, cond1)) syn_new = create_n_connection_synapse(syn0, number_syns, nml_doc, existing_synapses) if not elect_conn: if not populations_without_location: proj0 = Projection(id=proj_id, \ presynaptic_population=conn.pre_cell, postsynaptic_population=conn.post_cell, synapse=syn_new.id) net.projections.append(proj0) # Add a Connection with the closest locations pre_cell_id="../%s/0/%s"%(conn.pre_cell, params.generic_cell.id) post_cell_id="../%s/0/%s"%(conn.post_cell, params.generic_cell.id) conn0 = Connection(id="0", \ pre_cell_id=pre_cell_id, post_cell_id=post_cell_id) proj0.connections.append(conn0) if populations_without_location: # <synapticConnection from="hh1pop[0]" to="hh2pop[0]" synapse="syn1exp" destination="synapses"/> pre_cell_id="%s[0]"%(conn.pre_cell) post_cell_id="%s[0]"%(conn.post_cell) conn0 = SynapticConnection(from_=pre_cell_id, to=post_cell_id, synapse=syn_new.id, destination="synapses") net.synaptic_connections.append(conn0) else: proj0 = ElectricalProjection(id=proj_id, \ presynaptic_population=conn.pre_cell, postsynaptic_population=conn.post_cell) net.electrical_projections.append(proj0) # Add a Connection with the closest locations conn0 = ElectricalConnection(id="0", \ pre_cell="0", post_cell="0", synapse=syn_new.id) proj0.electrical_connections.append(conn0) if include_muscles: for conn in muscle_conns: if conn.pre_cell in lems_info["cells"] and conn.post_cell in muscles: # take information about each connection and package it into a # NeuroML Projection data structure proj_id = get_projection_id(conn.pre_cell, conn.post_cell, conn.synclass, conn.syntype) elect_conn = False syn0 = params.exc_syn if 'GABA' in conn.synclass: syn0 = params.inh_syn if '_GJ' in conn.synclass: syn0 = params.elec_syn elect_conn = isinstance(params.elec_syn, GapJunction) number_syns = conn.number conn_shorthand = "%s-%s"%(conn.pre_cell, conn.post_cell) if conn_number_override is not None and (conn_number_override.has_key(conn_shorthand)): number_syns = conn_number_override[conn_shorthand] elif conn_number_scaling is not None and (conn_number_scaling.has_key(conn_shorthand)): number_syns = conn.number*conn_number_scaling[conn_shorthand] ''' else: print conn_shorthand print conn_number_override print conn_number_scaling''' if number_syns != conn.number: magnitude, unit = bioparameters.split_neuroml_quantity(syn0.gbase) cond0 = "%s%s"%(magnitude*conn.number, unit) cond1 = "%s%s"%(magnitude*number_syns, unit) if verbose: print(">> Changing number of effective synapses connection %s -> %s: was: %s (total cond: %s), becomes %s (total cond: %s)" % \ (conn.pre_cell, conn.post_cell, conn.number, cond0, number_syns, cond1)) syn_new = create_n_connection_synapse(syn0, number_syns, nml_doc, existing_synapses) if not elect_conn: if not populations_without_location: proj0 = Projection(id=proj_id, \ presynaptic_population=conn.pre_cell, postsynaptic_population=conn.post_cell, synapse=syn_new.id) net.projections.append(proj0) # Add a Connection with the closest locations pre_cell_id="../%s/0/%s"%(conn.pre_cell, params.generic_cell.id) post_cell_id="../%s/0/%s"%(conn.post_cell, params.generic_cell.id) conn0 = Connection(id="0", \ pre_cell_id=pre_cell_id, post_cell_id=post_cell_id) proj0.connections.append(conn0) if populations_without_location: # <synapticConnection from="hh1pop[0]" to="hh2pop[0]" synapse="syn1exp" destination="synapses"/> pre_cell_id="%s[0]"%(conn.pre_cell) post_cell_id="%s[0]"%(conn.post_cell) conn0 = SynapticConnection(from_=pre_cell_id, to=post_cell_id, synapse=syn_new.id, destination="synapses") net.synaptic_connections.append(conn0) else: proj0 = ElectricalProjection(id=proj_id, \ presynaptic_population=conn.pre_cell, postsynaptic_population=conn.post_cell) net.electrical_projections.append(proj0) # Add a Connection with the closest locations conn0 = ElectricalConnection(id="0", \ pre_cell="0", post_cell="0", synapse=syn_new.id) proj0.electrical_connections.append(conn0) # import pprint # pprint.pprint(lems_info) template_path = '../' if test else '' # if running test write_to_file(nml_doc, lems_info, net_id, template_path, validate=validate, verbose=verbose, target_directory=target_directory) return nml_doc