def prepare_simulation(prep_workspace=True): """ Do the whole process of preparing a simulation """ # Prepare the necessary variables from the configuration files if prep_workspace: prepare_workspace() # Shortenings stimmethod = ws.settings["stimulation"]["method"] nervemodel = ws.settings["nerve model"] # Create the NERVE TOPOLOGY. Cross-section only anatomy.create_nerve() # BIOPHYSICS # LOAD NEURON HOC CODE AND DEFINE FUNCTIONS # Load NEURON code h.load_file(os.path.join(ws.folders["src/hoc"], "ephap.hoc")) h.load_file(os.path.join(ws.folders["src/hoc"], "wire.hoc")) for m in ws.axonmodel_settings.values(): h.load_file(m['hoc file']) # BUILD ALL THE WIRES with all their length bio.build_cables() # Finish setting up information for the fascicles if nervemodel == "resistor network": bio.finish_fascicles() # Create electrodes # This needs to be after the creation of the cables and before # connecting the ephapses if stimmethod == "from electrodes": ws.log("Creating the electrodes") electrodes.create_electrodes() # elif stimmethod == "pre-computed": # pass # EPHAPSES if ws.EC["presence"]: if nervemodel == "resistor network": # Create an instance of the Resistor Network ws.log("Creating the Resistor Network") ws.rnet = bio.ResistorNetwork() # Get the resistances of the connections for each pair ws.log("\tGetting resistor values") ws.rnet.get_resistances() # Connect resistors with ephapses in NEURON ws.log("\tConnecting resistors") ws.rnet.connect_resistors() # OTHER CONNECTIONS ws.log("Preparing connections to ground on the boundaries and xraxial") # Prepare connections to ground in the system if stimmethod == "from electrodes": electrodes.prepare_ground_paths() # Set xraxial and make the connections to ground if nervemodel == "resistor network": bio.electrics() # STIMULATION ws.log("Setting up stimulation") # Inject currents from the cuff electrode # Add injected currents, delays and durations if stimmethod == "from electrodes": # if nervemodel == "resistor network": electrodes.set_stimulation() elif stimmethod == "pre-computed": bio.set_direct_extracellular_stimulation() # RECORDINGS ws.log("Setting up recordings") # Time als.set_time_recording() # From electrodes # Flag: presence of electrode recordings # Set it to False by default; it will become True if a recording # electrode is created ws.settings["electrode recordings"] = False if stimmethod == "from electrodes": if nervemodel == "resistor network": electrodes.set_recordings() # Directly on the cables/axons als.record_cables()
save=True, xyzunits=r'$\rm \mu m$', vunits='mV', cmap=plt.cm.jet, show_intp_points=False, logscale=True, zorder=zorder, ) zorder += 1 # Include the contours # Prepare the necessary stuff for the simulation import simcontrol # simcontrol.prepare_simulation() simcontrol.prepare_workspace(remove_previous=False) anatomy.create_nerve() # Draw contours if False: ws.nvt.draw_axons_and_points(ax, facecolor='none', edgecolor='k', zorder=zorder) if False: ws.nvt.draw_triangulation( ax, c='white', lw=0.5, alpha=0.4, zorder=zorder, ) zorder += 1