def traceSelect(self): print_v("traceSelect button was clicked. Traces shown: %s; colours: %s"%(self.current_traces_shown,self.current_traces_colours)) dialog = QDialog(self) dialog.setWindowTitle("Select which traces to plot") QBtn = QDialogButtonBox.Ok # | QDialogButtonBox.Cancel buttonBox = QDialogButtonBox(QBtn) buttonBox.accepted.connect(dialog.accept) layout = QGridLayout() dialog.setLayout(layout) count = 0 self.all_cbs = {} for key in sorted(self.current_traces.keys()): if key != 't': self.all_cbs[key] = QCheckBox(key) self.all_cbs[key].setChecked(self.current_traces_shown[key]) self.all_cbs[key].stateChanged.connect(partial(self.traceSelectClicked,key)) color_button = QPushButton("%s"%self.current_traces_colours[key]) style = 'QPushButton {background-color: %s; color: black;}'%self.current_traces_colours[key] color_button.setStyleSheet(style) layout.addWidget(color_button,count,0) layout.addWidget(self.all_cbs[key],count,1) count+=1 layout.addWidget(buttonBox,count,1) dialog.exec_() self.replotSimResults()
def handle_connection(self, projName, id, prePop, postPop, synapseType, \ preCellId, \ postCellId, \ preSegId = 0, \ preFract = 0.5, \ postSegId = 0, \ postFract = 0.5, \ delay = 0, \ weight = 1): #self.print_connection_information(projName, id, prePop, postPop, synapseType, preCellId, postCellId, weight) print_v(">>>>>> Src cell: %d, seg: %f, fract: %f -> Tgt cell %d, seg: %f, fract: %f; weight %s, delay: %s ms" % (preCellId,preSegId,preFract,postCellId,postSegId,postFract, weight, delay)) pre_node_id = '%s_%i'%(prePop, preCellId) post_node_id = '%s_%i'%(postPop, postCellId) edge_id = 'Edge %s to %s'%(pre_node_id,post_node_id) edge = {} edge['name'] = edge_id edge['type'] = {} edge['type']['NeuroML'] = synapseType edge['parameters'] = {} edge['functions'] = {} edge['sender_port'] = 'OutputPort' edge['receiver_port'] = 'InputPort' edge['sender'] = pre_node_id edge['receiver'] = post_node_id edge['weight'] = weight edge['type'] = { "PNL": "MappingProjection", "generic": None } self.bids_mdf_graph['edges'][edge_id] = edge
def showLemsView(self): """Generate lemsView button has been pressed""" print_v("lemsView button was clicked.") self.update_net_sim() self.tabs.setCurrentWidget(self.all_tabs[self.LEMS_VIEW_TAB]) self.update_net_sim() from neuromllite.NetworkGenerator import generate_neuroml2_from_network from neuromllite.NetworkGenerator import generate_and_run lems_file_name = generate_and_run(self.simulation, simulator='jNeuroML_norun', network=self.network, return_results=True, base_dir=self.sim_base_dir) post_args = "-graph" from pyneuroml.pynml import run_jneuroml run_jneuroml("", lems_file_name, post_args, verbose = True) lems_view_file = lems_file_name.replace('.xml','.png') self.add_image(lems_view_file, self.LEMS_VIEW_TAB)
def show3Dimage(self): """Generate 3D view button has been pressed""" print_v("image3D button was clicked.") self.update_net_sim() self.tabs.setCurrentWidget(self.all_tabs[self.IMAGE_3D_TAB]) from neuromllite.NetworkGenerator import generate_neuroml2_from_network nml_file_name, nml_doc = generate_neuroml2_from_network(self.network, print_summary=True, format='xml', base_dir=None, copy_included_elements=False, target_dir=None, validate=False, simulation=self.simulation) post_args = "-png" from pyneuroml.pynml import run_jneuroml run_jneuroml("", nml_file_name, post_args, verbose = True) nml_view_file = nml_file_name.replace('.nml','.png') self.add_image(nml_view_file, self.IMAGE_3D_TAB)
def num_cells(self): ncells = sum([ len(self.pop_indices_vs_gids[pop_id]) for pop_id in self.pop_indices_vs_gids ]) print_v("Getting num cells: %s" % (ncells)) return ncells
def connections_on(self, gid): # Todo: optimise!! pop_id, index = self.get_pop_index(gid) conns = [] for proj in self.nl_network.projections: if pop_id == proj.postsynaptic: w = self.proj_weights[proj.id] in_w = w.T[index] d = self.proj_delays[proj.id] in_d = d.T[index] print_v( "Incoming connections for gid %i (%s[%s]), w: %s; d: %s" % (gid, pop_id, index, in_w, in_d)) for src_index in range(len(in_w)): if in_w[src_index] > 0: src_gid = self.get_gid(proj.presynaptic, src_index) conns.append( arbor.connection( (src_gid, "detector"), "syn", in_w[src_index], in_d[src_index], )) print_v("Making connections for gid %i (%s[%s]): %s" % (gid, pop_id, index, conns)) return conns
def __init__(self, level=10, engine='dot', nl_network=None, include_ext_inputs=True, include_input_pops=True, scale_by_post_pop_size=True, scale_by_post_pop_cond=True, show_chem_conns=True, show_elect_conns=True, show_cont_conns=True, min_weight_to_show=0, output_format='png', view_on_render=True): self.nl_network = nl_network self.level = level self.engine = engine self.include_ext_inputs = include_ext_inputs self.include_input_pops = include_input_pops self.scale_by_post_pop_size = scale_by_post_pop_size self.scale_by_post_pop_cond = scale_by_post_pop_cond self.min_weight_to_show = min_weight_to_show self.show_chem_conns = show_chem_conns self.show_elect_conns = show_elect_conns self.show_cont_conns = show_cont_conns self.output_format = output_format self.view_on_render = view_on_render self.rng, seed = _get_rng_for_network(self.nl_network) print_v("Initiating GraphViz handler, level %i, engine: %s, seed: %s" % (level, engine, seed))
def finalise_document(self): print_v("Writing file for...: %s" % self.id) save_to_json_file(self.mdf_info, "%s.mdf.json" % self.id, indent=4) save_to_yaml_file(self.mdf_info, "%s.mdf.yaml" % self.id, indent=4) """save_to_json_file(self.mdf_info_hl, '%s.bids-mdf.highlevel.json'%self.id, indent=4)"""
def generateNeuroML2(self): """Generate NeuroML 2 representation of network""" print_v("Generate NeuroML 2 button was clicked.") self.update_net_sim() from neuromllite.NetworkGenerator import generate_neuroml2_from_network nml_file_name, nml_doc = generate_neuroml2_from_network( self.network, print_summary=True, format="xml", base_dir=None, copy_included_elements=False, target_dir=None, validate=False, simulation=self.simulation, ) with open(nml_file_name, "r") as reader: nml_txt = reader.read() self.nml2Text.clear() self.nml2Text.insertPlainText(nml_txt) self.tabs.setCurrentWidget(self.nml2Tab)
def showMatrix(self): """Generate matrix buttom has been pressed""" print_v("Matrix button was clicked.") if len(self.network.projections) == 0: self.dialog_popup( "No projections present in network, and so no matrix to show" ) return self.update_net_sim() self.tabs.setCurrentWidget(self.matrixTab) from neuromllite.MatrixHandler import MatrixHandler level = 2 handler = MatrixHandler(level, nl_network=self.network) from neuromllite.NetworkGenerator import generate_network generate_network(self.network, handler, always_include_props=True, base_dir=".") print_("Done with MatrixHandler...", self.verbose)
def __init__(self, **parameters): print_v("Creating PsyNeuLinkReader with %s..." % parameters) self.parameters = parameters self.current_population = None self.pre_pop = None self.post_pop = None
def run_once(self, job_dir, ** kwargs): from neuromllite.utils import print_v from neuromllite.utils import load_simulation_json,load_network_json from neuromllite.NetworkGenerator import generate_and_run from pyneuroml.pynml import get_value_in_si print_v('Running NeuroMLlite simulation in dir: %s...'%job_dir) sim = load_simulation_json(self.nmllite_sim) import random sim.id = '%s%s'%(sim.id, '_%s'%kwargs['reference'] if 'reference' in kwargs else '') network = load_network_json(self.base_dir+'/'+sim.network) for a in kwargs: if a in network.parameters: print_v(' Setting %s to %s in network...'%(a, kwargs[a])) network.parameters[a] = kwargs[a] elif a in sim.fields: print_v(' Setting %s to %s in simulator...'%(a, kwargs[a])) setattr(sim,a,kwargs[a]) else: print_v(' Cannot set parameter %s to %s in network or simulator...'%(a, kwargs[a])) traces, events = generate_and_run(sim, simulator = self.simulator, network = network, return_results = True, base_dir = self.base_dir, target_dir = job_dir) print_v("Returned traces: %s, events: %s"%(traces.keys(), events.keys())) return traces, events
def handleConnection( self, projName, id, prePop, postPop, synapseType, preCellId, postCellId, preSegId=0, preFract=0.5, postSegId=0, postFract=0.5, delay=0, weight=1, ): # self.printConnectionInformation(projName, id, prePop, postPop, synapseType, preCellId, postCellId, localWeight) print_v( "\n --------------------------------------------------------------" ) print_v("Going to create a connection of type " + projName + ", id: " + str(id) + ", synapse type: " + synapseType) print_v("From: " + prePop + ", id: " + str(preCellId) + ", segment: " + str(preSegId) + ", fraction: " + str(preFract)) print_v("To : " + postPop + ", id: " + str(postCellId) + ", segment: " + str(postSegId) + ", fraction: " + str(postFract)) print_v(" **** Connectivity not yet implemented!! **** ")
def executeHoc(self, command): cmdPrefix = "hoc >>>>>>>>>>: " if len(command) > 0: print_v(cmdPrefix + command) self.h(command)
def __init__(self, level=10, engine='dot', nl_network=None, include_inputs=True, scale_by_post_pop_size=True, scale_by_post_pop_cond=True, show_chem_conns=True, show_elect_conns=True, show_cont_conns=True, min_weight_to_show=0): self.nl_network = nl_network self.level = level self.engine = engine self.include_inputs = include_inputs self.scale_by_post_pop_size = scale_by_post_pop_size self.scale_by_post_pop_cond = scale_by_post_pop_cond self.min_weight_to_show = min_weight_to_show self.show_chem_conns = show_chem_conns self.show_elect_conns = show_elect_conns self.show_cont_conns = show_cont_conns print_v("Initiating GraphViz handler, level %i, engine: %s" % (level, engine))
def handle_projection( self, projName, prePop, postPop, synapse, hasWeights=False, hasDelays=False, type="projection", synapse_obj=None, pre_synapse_obj=None, ): synInfo = "" if synapse_obj: synInfo += " (syn: %s)" % synapse_obj.__class__.__name__ if pre_synapse_obj: synInfo += " (pre comp: %s)" % pre_synapse_obj.__class__.__name__ print_v("Projection: " + projName + " (" + type + ") from " + prePop + " to " + postPop + " with syn: " + synapse + synInfo) self.proj_weights[projName] = np.zeros(( len(self.pop_indices_vs_gids[prePop]), len(self.pop_indices_vs_gids[postPop]), )) self.proj_delays[projName] = np.zeros(( len(self.pop_indices_vs_gids[prePop]), len(self.pop_indices_vs_gids[postPop]), )) """
def __init__(self, **parameters): print_v("Creating BBPConnectomeReader with %s..." % parameters) self.parameters = parameters self.current_population = None self.pre_pop = None self.post_pop = None
def handle_connection( self, projName, id, prePop, postPop, synapseType, preCellId, postCellId, preSegId=0, preFract=0.5, postSegId=0, postFract=0.5, delay=0, weight=1, ): self.print_connection_information(projName, id, prePop, postPop, synapseType, preCellId, postCellId, weight) print_v( "Src cell: %d, seg: %f, fract: %f -> Tgt cell %d, seg: %f, fract: %f; weight %s, delay: %s ms" % ( preCellId, preSegId, preFract, postCellId, postSegId, postFract, weight, delay, )) self.proj_weights[projName][preCellId][postCellId] = weight self.proj_delays[projName][preCellId][postCellId] = delay
def finalise_document(self): print_v("Writing file...: %s" % id) self.sonata_nodes.close() node_type_filename = "%s_node_types.csv" % self.network_id self.circuit_file_info["networks"]["nodes"][0]["node_types_file"] = ( "$NETWORK_DIR/%s" % node_type_filename) node_type_file = open( os.path.join(self.circuit_file_info["manifest"]["$NETWORK_DIR"], node_type_filename), "w", ) header = "" for var in self.node_type_csv_info[self.node_type_csv_info.keys()[0]]: header += "%s " % var node_type_file.write(header + "\n") for pop_id in self.node_type_csv_info: line = "" for var in self.node_type_csv_info[pop_id]: line += "%s " % self.node_type_csv_info[pop_id][var] node_type_file.write(line + "\n") node_type_file.close() save_to_json_file(self.config_file_info, "config.json", indent=2) save_to_json_file(self.circuit_file_info, "circuit_config.json", indent=2)
def handle_document_start(self, id, notes): print_v("Parsing for Sonata export: %s" % id) self.config_file_info = {} self.config_file_info["network"] = "./circuit_config.json" self.config_file_info["simulation"] = "./simulation_config.json" self.circuit_file_info = {} self.circuit_file_info["manifest"] = {} self.circuit_file_info["manifest"]["$NETWORK_DIR"] = "./network" if not os.path.exists( self.circuit_file_info["manifest"]["$NETWORK_DIR"]): os.mkdir(self.circuit_file_info["manifest"]["$NETWORK_DIR"]) self.circuit_file_info["manifest"]["$COMPONENT_DIR"] = "./components" if not os.path.exists( self.circuit_file_info["manifest"]["$COMPONENT_DIR"]): os.mkdir(self.circuit_file_info["manifest"]["$COMPONENT_DIR"]) self.circuit_file_info["components"] = {} self.circuit_file_info["components"][ "synaptic_models_dir"] = "$COMPONENT_DIR/synaptic_models" if not os.path.exists("./components/synaptic_models"): os.mkdir("./components/synaptic_models") self.circuit_file_info["components"][ "point_neuron_models_dir"] = "$COMPONENT_DIR/point_neuron_models_dir" if not os.path.exists("./components/point_neuron_models_dir"): os.mkdir("./components/point_neuron_models_dir") self.circuit_file_info["networks"] = {} self.circuit_file_info["networks"]["nodes"] = [] self.circuit_file_info["networks"]["nodes"].append({})
def handle_population(self, population_id, component, size=-1, component_obj=None, properties={}): sizeInfo = " as yet unspecified size" if size >= 0: sizeInfo = ", size: " + str(size) + " cells" if component_obj: compInfo = " (%s)" % component_obj.__class__.__name__ else: compInfo = "" print_v("Population: " + population_id + ", component: " + component + compInfo + sizeInfo) self.sonata_nodes.create_group("nodes/%s" % population_id) self.sonata_nodes.create_group("nodes/%s/0" % population_id) node_type_id = 100 + len(self.pop_type_ids) self.pop_type_ids[population_id] = node_type_id self.node_type_csv_info[population_id] = {} self.node_type_csv_info[population_id]["node_type_id"] = node_type_id self.node_type_csv_info[population_id]["pop_name"] = population_id self.node_type_csv_info[population_id]["model_name"] = component ##self.node_type_csv_info[population_id]['location'] = '???' self.node_type_csv_info[population_id][ "model_template"] = "nest:iaf_psc_alpha" self.node_type_csv_info[population_id]["model_type"] = "point_process" self.node_type_csv_info[population_id]["dynamics_params"] = ( "%s.json" % component)
def handleLocation(self, id, population_id, component, x, y, z): self.printLocationInformation(id, population_id, component, x, y, z) newCellName = population_id + "_" + str(id) createCall = ("new " + component + '("' + newCellName + '", "' + component + '", "New Cell: ' + newCellName + " of type: " + component + '")') cellInArray = "a_" + population_id + "[" + str(id) + "]" setupCreate = ("obfunc newCell() { {" + cellInArray + " = " + createCall + "} return " + cellInArray + " }") self.executeHoc(setupCreate) newCell = self.h.newCell() newCell.position(float(x), float(y), float(z)) self.executeHoc("{n_" + population_id + "_local = n_" + population_id + "_local + 1}") print_v("Have just created cell: " + component + " at (" + str(x) + ", " + str(y) + ", " + str(z) + ")")
def handle_population(self, population_id, component, size=-1, component_obj=None, properties={}): sizeInfo = " as yet unspecified size" if size>=0: sizeInfo = ", size: "+ str(size)+ " cells" if component_obj: compInfo = " (%s)"%component_obj.__class__.__name__ else: compInfo="" print_v("Population: "+population_id+", component: "+component+compInfo+sizeInfo) self.sonata_nodes.create_group("nodes/%s"%population_id) self.sonata_nodes.create_group("nodes/%s/0"%population_id) node_type_id = 100+len(self.pop_type_ids) self.pop_type_ids[population_id] = node_type_id self.node_type_csv_info[population_id] = {} self.node_type_csv_info[population_id]['node_type_id'] = node_type_id self.node_type_csv_info[population_id]['model_name'] = component self.node_type_csv_info[population_id]['location'] = '???' self.node_type_csv_info[population_id]['model_template'] = component self.node_type_csv_info[population_id]['model_type'] = component self.node_type_csv_info[population_id]['dynamics_params'] = 'None'
def __init__(self, simulator, dt, reference): print_v("Initiating PyNN with simulator %s"%simulator) self.sim = import_module("pyNN.%s" % simulator) self.dt = dt self.sim.setup(timestep=self.dt, debug=True, reference=reference, save_format='xml')
def finalise_document(self): print_v("Writing file for...: %s" % self.id) save_to_json_file(self.bids_mdf_info, '%s.bids-mdf.json' % self.id, indent=4) '''save_to_json_file(self.bids_mdf_info_hl, '%s.bids-mdf.highlevel.json'%self.id, indent=4)'''
def __init__(self, model, conn, **parameters): print_v("Creating TVBReader with %s..." % parameters) self.parameters = parameters self.model = model self.conn = conn self.population_ids = []
def print_input_information(self, inputName, population_id, component, size=-1): sizeInfo = " size: " + str(size) + " cells" print_v("Input Source: " + inputName + ", on population: " + population_id + sizeInfo + " with component: " + component)
def finalise_projection(self, projName, prePop, postPop, synapse=None, type="projection"): print_v("Projection finalising: " + projName + " from " + prePop + " to " + postPop + " completed")
def handle_network(self, network_id, notes, temperature=None): print_v("Network: %s" % network_id) self.network_id = network_id self.f = Digraph(network_id, filename='%s.gv' % network_id, engine=self.engine, format='png')
def __init__(self, nmllite_sim, simulator='jNeuroML'): real_sim = os.path.realpath(nmllite_sim) print_v('Created NeuroMLliteRunner to run %s in %s' % (real_sim, simulator)) self.base_dir = os.path.dirname(real_sim) self.nmllite_sim = nmllite_sim self.simulator = simulator