Creating plots from GUI while running Python model

Using the graphical user interface to build and exercise models. Includes customizing the GUI by writing a little bit of hoc.
Post Reply
bll5z6
Posts: 16
Joined: Thu May 26, 2016 10:27 am

Creating plots from GUI while running Python model

Post by bll5z6 » Thu May 26, 2016 12:39 pm

Hello,

I'm new to NEURON and Python but I've managed to make a couple of simple models. The problem is when I try to create a new plot from the GUI, the variable I want isn't available. For example, if I click "current axis" to generate a new graph and then right click and select "Plot What?", I select "All" from the dropdown but my cell (say, CellA) isn't available in the first column as it would be if the model were written with HOC.

I can get it to plot if I type, for instance, ina(0.5) directly into the "Plot What?" prompt but something like CellA.soma.ina(0.5) creates an error. I hope I've explained the problem sufficiently, any help would be greatly appreciated!

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

Re: Creating plots from GUI while running Python model

Post by ted » Thu May 26, 2016 6:45 pm

Create all sections in hoc, even if you're using Python. Then you can do anything you like in Python OR hoc. And that means you can also use NEURON's native GUI tools to work with the model--which in many ways are far more convenient (because they're very interactive) than fooling around with Python's graphical libraries (which, for many development and debugging tasks, seem quite crippled by comparison).

Example:

Code: Select all

nrngui -python
 . . . neuron prints its banner, then shows the >>> prompt . . .
>>> from neuron import h
>>> h.execute("create soma")
>>> h.execute("forall print secname()")
soma
>>> h.execute("psection()")
soma { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 0*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
}
So h.execute("create soma") created a section with the hoc name soma.

At this point you have a choice: refer to this section by taking advantage of the fact that hoc variables are accessible to Python via the h object, as in

Code: Select all

>>> h.soma.L
100.0
>>> h.soma.diam
500.0
or create a Python alias for h.soma so you don't have to type "h." every time you want to refer to an attribute of the soma section, as in

Code: Select all

>>> soma = h.soma
>>> soma.L
100.0
>>> soma.diam
500.0
And of course, since hoc knows that the name of this section is soma, you can use all of NEURON's GUI tools to refer to any of its attributes, e.g. membrane potential, or if you add the hh mechanism to it by executing the Python statement

Code: Select all

>>> soma.insert("hh")
you can then verify that soma really does have hh by

Code: Select all

>>> h.psection("soma")
soma { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 0*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
	insert hh { gnabar_hh=0.12 gkbar_hh=0.036 gl_hh=0.0003 el_hh=-54.3}
	insert na_ion { ena=50}
	insert k_ion { ek=-77}
}
Alternatively you can refer to the hh mechanism's parameters by their Python names, e.g.

Code: Select all

>>> soma(0.5).hh.gnabar
0.12
>>> soma.nseg = 3
>>> soma(0.1).hh.gnabar = 11.1
>>> for seg in soma:
...   print seg.x, soma(seg.x).hh.gnabar
... 
0.166666666667 11.1
0.5 0.12
0.833333333333 0.12

bll5z6
Posts: 16
Joined: Thu May 26, 2016 10:27 am

Re: Creating plots from GUI while running Python model

Post by bll5z6 » Fri May 27, 2016 1:00 pm

That's incredibly helpful, thank you!

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

Re: Creating plots from GUI while running Python model

Post by ted » Fri May 27, 2016 1:31 pm

Just throw money. Or, barring that, make sure to inform us when you publish something that reports work done with NEURON, so we can add it to the Bibliography page.

Post Reply