Below are some common problems/puzzling behavior I have encountered when working with NEURON.
Understand the difference between Sections, Segments, and 3D Points
You will mostly be working with Sections which are subdivided into iso-potential compartments called Segments. NEURON takes care of the details of managing the compartments, but you can set the number of compartments in a Section with the nseg parameter. Furthermore, a Section can have a number of 3D points. Each point has (x,y,z) and diameter. However, the number of 3D points != number of Segments. NEURON will use the arclength and the diameters of the 3D points to compute the parent Section’s equivalent length and diameter and will use those two values in computing the membrane potential. Meanwhile, the nseg value is independent of the number of 3D points and needs to be set separately.
.MOD files need to be compiled before NEURON is launched
.mod files have to be compiled prior to launching of NEURON (via the nrngui / nrniv / from neuron import h commands) with nrnivmodl command. Simply cd to the folder with the .mod files and run nrnivmodl. If there are no errors, you can launch NEURON and it will load the .mod files correctly.
.MOD/channel files are loaded once, from the current working directory
When the from neuron import h line is executed, .mod files will be loaded that are in the current working directory (cwd). You can retrieve the cwd with:
import os os.getcwd()
you can change the cwd with:
There is no clean way to “unload” a model
There is no real clean way to unload a model from NEURON. Stopping the NEURON process or ending the Python session that started it, is the only way to ensure the model is completely unloaded. You could use the SaveState object to save/restore simulation states between NEURON restarts.
Frozen NEURON GUI can be closed with pkill command
Occasionally the NEURON process will freeze and the GUI will be non-responsive. You can quickly and reliably stop all NEURON processes with the following command:
pkill -9 nrn*
Always use h.cvode_active(1) method to enable variable step integration (CVODE)
Note that this is different from h.cvode.active(1). Using .active vs _active will result in all sorts of strange behaviors. See this post.
When using variable step integration (CVODE), always run the “Atol Scale Tool” before running the simulation
The tool discovers and sets the appropriate error tolerances for each state variable. Without this step, the simulation may contain weird oscillations. See this post for how to use the Atol Scale Tool.
Use SEClamp instead of VClamp
Both of these are voltage clamp classes, but VClamp will not work with variable step integration (CVODE). Furthermore, NEURON devs recommend to just always use SEClamp.
Use an odd number of Section.nseg and use the d-lambda rule to set the number of nsegs in a complex morphology
An odd number of section compartments ensures that there is a compartment at the default halfway (0.5) point of a section. Using the d-lambda rule takes out the guesswork from giving an appropriate number of compartments to sections.