Page 1 of 1

How to combine GUI with hoc programming

Posted: Sun Jun 09, 2019 12:24 pm
by guanbc
A very basic question, which may sound silly. Now I can only do simple modeling using Neuron GUI and recreate the model by writing simple init.hoc that contains loading ses file information. I am wondering how to combine GUI with hoc programming to get more flexibility. After opening nrngui and recreating the model, there is a black window entitled 'nrngui', showing the Neuron version and oc> . For combining GUI with hoc programming, where should the hoc lines be written, in the black window or just in a simple text editor, and how to combine them? Or just open the ses file using a text editor and modify it?

Re: How to combine GUI with hoc programming

Posted: Thu Jun 13, 2019 10:43 am
by ted
hoc and Python are programming languages. The typical workflow for working with a programming language is

Code: Select all

  write statements in the programming language
  execute the statements
  evaluate the results
UNTIL one has a collection of statements that do what one wants
The first step is done by writing the statements in a plain text editor (not Word) and saving them to a file.
The second step is done by using a program to execute the statements. Usually this involves entering a command in a terminal that makes a program such as NEURON or Python read a text file and execute the statements in that file. Examples:
nrngui foo.hoc # starts NEURON, which executes the contents of foo.hoc
python # starts Python, which executes the contents of

NEURON's GUI tools offer a way to avoid having to write code. They work by generating hoc statements that are interpreted by NEURON, so they can substitute for one or more hoc statements. Example: if is a session file for a PointProcessManager configured as an IClamp, then the hoc statement
will recreate that IClamp. The Python statement
h.load_file('') will do the same thing.

A ses file contains hoc statements that recreate not only the IClamp, but also the PointProcessManager (the graphical tool for managing the IClamp). Those hoc statements are generated by the computer, and they are not intended to be edited by users.

Re: How to combine GUI with hoc programming

Posted: Sat Jun 15, 2019 1:00 pm
by guanbc
Now that I have saved a workable ses. file for a simple GUI made model, and I want to change the ena from default by changing nao and nai. would you please give a concrete example; eg,I'd like nao and nai to be 44 mM and 50 mM respectively? the Neuron Book is still a bit too abstract. Should I write a hoc file like this?

USEION na READ nao nai
nao = 44
nai = 50

Re: How to combine GUI with hoc programming

Posted: Sat Jun 15, 2019 9:41 pm
by ted
Should I write a hoc file like this?
That will do nothing useful. It won't get past the second line, which is in NMODL, not hoc. The third and fourth lines will not affect intra- or extracellular sodium concentration because ionic concentrations only exist in the context of sections that contain channels or other mechanisms specified by NMODL code that contain relevant USEION statements. Furthermore, the equilibrium potential of an ionic species is calculated from its intra- and extracellular concentrations only in a section that has a mechanism that WRITEs the intra- and or extracellular concentration of that species, or if an ion_style() statement has been executed that tells NEURON it must calculate the equilibrium potential from concentration.

To sum up: the equilibrium potential and concentrations of an ion x do not exist in a section unless that section has a mechanism that uses that ionic species. And even if the equilibrium potential does exist, it is a simple constant independent of concentration unless there is a mechanism that writes one of the concentrations or you use ion_style() to tell NEURON that it must calculate the equilibrium potential from the ionic concentrations.