Secrets of NEURON: the hoc library

A collection of noteworthy items selected by our moderators from discussions about making and using models with NEURON.

Moderators: ted, wwlytton, tom_morse

Post Reply
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Secrets of NEURON: the hoc library

Post by ted »

The hoc interpreter has many built-in features, and these are described in the Programmer's Reference (see the Programmer's Reference link at http://www.neuron.yale.edu/neuron/docs). But did you know that NEURON also has a library of hoc code that adds an enormous amount of powerful functionality to NEURON?

You'll find the hoc library in c:\nrnxx\lib\hoc (MSWin) or nrn/share/nrn/lib/hoc (UNIX/Linux).

Here's an example of the kind of stuff you can discover from browsing through the hoc library:

When you double click on the nrngui icon (or type nrngui at the system prompt in UNIX/Linux), or use NEURON to execute a file that starts with the statement
load_file("nrngui.hoc")
the first thing that NEURON does is read and execute the contents of nrngui.hoc in the hoc library. nrngui.hoc contains these statements:

Code: Select all

{load_file("stdgui.hoc")}
nrnmainmenu()
so stdgui.hoc is read and executed.

The stdgui.hoc file (which is in the hoc library, of course) contains these statements:

Code: Select all

{
load_file("stdlib.hoc")
load_file("family.hoc")
load_file("shapebox.hoc")
load_file("pointbsr.hoc", "PointBrowser")
load_file("wingroup.hoc")
load_file("stdrun.hoc")
load_file("inserter.hoc")
load_file("pointman.hoc")
}
Of these files the two that deserve your special attention are stdlib.hoc and stdrun.hoc.

stdlib.hoc is rather short. Among other things, it defines
  • func lambda_f() which is used by some code in the CellBuilder that automatically decides what value to use for nseg
    the String class
    the case iterator
    the procs clipboard.set() and clipboard_get(), for copying Vectors to and from NEURON's clipboard
stdrun.hoc contains the code that defines the standard run system. It contains a lot of useful and interesting things, including the definition of proc nrnmainmenu(), which is called by the last statement in nrngui.hoc

You're not going to want to change the contents of any of these files yourself (except perhaps for a few very knowledgable and/or brave (reckless?) souls), but they are well worth browsing through. You may discover helpful programming clues and might even find some bits and pieces that you can call or reuse with slight modification in your own programs. Also, if you ever run across something that looks like a hoc keyword but it's not in the Programmer's Reference, that may be because it is defined in one of the files in the hoc library--look there instead to discover what it does and how to use it.
Post Reply