NEURON Programming Tutorial #2

Back to Tutorial Home Page


NEURON Programming Tutorial #2

The graphical user interface

NEURON's graphical user interface (GUI) is based on InterViews (developed by Silicon Graphics Inc. and Stanford University). This GUI allows NEURON to easily display and print graphs, create menus, buttons, and other GUI tools.

In this tutorial, we will build on the program that we started last time. Start NEURON with your program from tutorial #1 by double-clicking on your local copy of prog1.hoc (click this link to save it now, if you need to).

In NEURON's GUI, many of the most useful functions have been placed into the standard run library. To start the GUI, enter the following at the oc> prompt:

nrnmainmenu()
This will open the NEURON Main Menu window.

The NEURON Main Menu

The NEURON Main Menu is entry point into NEURON's graphical user interface. Many of the most useful features of the GUI are either directly or indirectly accessible from the NEURON Main Menu. Below we describe many of these features.

The Tools submenu contains functions that you can use to control and customize your simulation. The RunControl button opens up the RunControl panel from which you can run and control different simulations. See the next section for a description of the RunControl panel. !-- BPG 11-9-98 --> The Point Processes and Distributed Mechanisms menus allow you to view, create and manipulate the point processes and distributed mechanisms used in your model.

From the Graph submenu, you can create different types of plots including plotting variables vs. time or vs. space, or plotting variables in a phase plane. See below for information on plotting variables vs. time, and see the next tutorial for more information on plotting variables vs. both space and time.

<

The Run Control Window

In the previous tutorial, we ran simulations using the run() function. If we needed to change one of the simulation control parameters (e.g., tstop), we had to do this by typing some code:

tstop = 10
which was rather tedious. The RunControl panel was created to allow easy access to NEURON's simulation control parameters, and to allow people to easily start and stop their simulations.

To start a simulation, press the Init & Run button in the RunControl panel. This will initialize all of the simulation parameters, and start the simulation. It is equivalent to the run() command we used in the previous tutorial. The Stop button will halt a simulation, but it can be resumed by using either the Continue til button to continue the simulation until t reaches the value in the Continue til field editor, or the Continue for button to continue the simulation for the number of milliseconds in the Continue for field editor. If you would like to continue the simulation for one time step, you can press the Single Step button.

The actual simulation time, t, is displayed in milliseconds, and at each time step, it is incremented by dt. The time the simulation normally terminates, Tstop, is also displayed in milliseconds.

Complex simulations can require a small dt for accurate results. If we are also generating graphs during the simulation run, this could slow the simulation down even further. To moderate this, we can set the number of times NEURON updates the graphs per millisecond in the Plots/ms field editor. Choosing a value for Plots/ms that is greater than 1/dt will change dt to accommodate the increased plot resolution.

Since we can now run the simulation using the Run Control Window buttons, we will no longer need to use our rununtil() procedure.

Creating and using graphs

Graphs are an integral part of NEURON's user interface, and are designed to allow users to generate simulation results which can be directly incorporated into papers. With the Print button or Print to file menu in the Print & File Window Manager, you can save graphs in PostScript[TM] format.

From the Graph menu in the NEURON Main Menu, you can select several different types of graphs. In this section, we will explore plotting different variables vs. time, and as examples, we will create two graphs, one plot of voltage vs. time and one plot of the different somatic currents vs. time.

There are several different axes available when plotting variables vs. time (Voltage axis, Current axis and State axis). Each of these require their own graph since the method used to solve the cable equations, developed by Mike Hines, calculates each of these variables at different times. For example, voltages are calculated at each time step, but currents are calculated at the half time step before voltage and the state variables are calculated at the half time step after the voltage. For more information on the numerical method used to solve these equations see (Hines & Carnevale, 1997).

To create our voltage vs. time graph, we can select a Voltage axis from the New Graph menu in the NEURON Main Panel. This opens a new graph window with voltage axes (-80 mV to +40 mV on the Y axis and 0 to tstop on the X axis), and by default, the voltage in the middle of the currently accessed section is selected to plot. In our program, the soma is the currently accessed section, so the default voltage graph will plot the desired function. Running the simulation (via the Init & Run button) will run the simulation and plot the voltage in the middle of the soma vs. time.

To create our currents vs. time graph, we can select a Current axis from the Graph menu in the NEURON Main Menu. This opens a new graph window with current axes (-1 nA to +1 nA on the Y axis and 0 to tstop on the X axis). For current graphs, no variable is selected to plot by default, so we must choose what to plot from the graph menu.

Each graph has its own menu that can be accessed with the right mouse button. Plot what? in the graph menu will pop up a window that allows us to choose what current variable to plot. The variables can be either directly typed in if we know the exact name of the variable we want to plot, or they can be selected from the list of variables in the selection boxes.

We want to plot the somatic currents, so we need to select soma in the first selection box, and then select one of the currents from the second box. The available currents are ik, ina and il_hh. We can select a variable by either double clicking with the left mouse button on the variable name, or we can click once on the variable name and the press the Accept button. First select soma to bring up the list of variables to plot in the second box. For our current graph, we want to plot all of the soma currents, so we need to select soma.ik(0.5), soma.ina(0.5) and soma.il_hh(0.5). First select soma.ik(0.5) and press Accept. The variable name should appear on the graph and, unfortunately, the selection box goes away. You need to reselect the Plot what? menu option to select the other two currents for plotting. Run the simulation (via the Init & Run button) to see the currents.

Please see the Help Reference for an explanation of how to use the other options in the graph menu and how to create other types of graphs.

Saving and retrieving sessions

After creating several graphs, you may want to save the windows you have created (i.e., graphs and panels) to a file so that you can recall them at a later time. NEURON allows you to save windows to a session by selecting the save session option of the File menu in the NEURON Main Menu. This will pop up a window in which you can enter the filename of your save session. Try saving your windows to a file (DO NOT overwrite any of the existing session files!).

If we save our session to a file, we can either load the session each time we load our program by selecting the load session option of the File menu, or we can have our program automatically load our session for us. To do this, we need to add the following to our program:

xopen("prog2.ses")
where prog2.ses is the name of the session we saved (Note: the name must be in quotes). The next time we start our program, the session with our graphs and menus will automatically be loaded into NEURON.

Here is our program so far:

xopen("$(NEURONHOME)/lib/hoc/noload.hoc")

create soma
access soma

nseg = 1
diam = 100
L = 100

insert hh

objectvar stim

stim = new IClamp(0.5)

stim.del = 0
stim.dur = 0.1
stim.amp = 30

xopen("prog2.ses")
Get a local copy of this code by storing prog2.hoc and the session file prog2.ses for you to use in the next tutorial.

What's next

In the next tutorial we will explore how to build cells with more complex morphologies and how to create a new dynamic type of graph, a space plot.


Kevin E. Martin (martin@cs.unc.edu)

Modified by Bruce Graham (b.graham@cs.stir.ac.uk)