Use NEURON's native GUI tools with Python!
Posted: Tue Aug 08, 2017 2:48 pm
While there are many powerful Python packages for creating graphs, such as matplotlib and mayavi, there still isn't any substitute for NEURON's native GUI tools for managing models. The interactive nature of these tools make them far more convenient for development and debugging than any Python graphical library. And they work perfectly well, as long as you create your new sections with statements of the form
namestring = h.Section(name = 'namestring')
The workaround described below is no longer necessary! Skip to the post in this thread that is dated Fri Sep 27, 2019.
And they work perfectly well, as long as all sections are created in hoc. Why is it necessary for all sections to have been created in hoc? Consider this example:
So far so good. Now tryand you'll get something like thisThat second line is ugly and uninformative because hoc can only discover the internal, computer generated name for the Python object that refers to what you called "dend" in Python. It's also not a useful name because it's likely to be different the next time you start NEURON and execute the same commands.
It would be great if h.Section() had an optional argument that could be used to specify a meaningful hoc name, likebut unfortunately that feature doesn't yet exist.
So the use of NEURON's native GUI tools is limited to sections that were created by executing hoc code. But does this mean you actually have to embed hoc statements, likein your Python code?
Nope. Just insert this bit of Python in your program(those __ bits are pairs of underscore _ characters). Then you can do stuff like thisand now there will be a hoc section called axon, and there will also be a Python variable called axon that refers to the same section. What's nice about this is that
1. it enables use of NEURON's GUI tools (including Model View) to explore and manage your model's properties,
and
2. you don't have to sprinkle hoc statements all over your nice Python program. The only hoc stuff is in the Python procedure called Section.
Many thanks to Robert McDougal for this very useful tip!
namestring = h.Section(name = 'namestring')
The workaround described below is no longer necessary! Skip to the post in this thread that is dated Fri Sep 27, 2019.
And they work perfectly well, as long as all sections are created in hoc. Why is it necessary for all sections to have been created in hoc? Consider this example:
Code: Select all
from neuron import h,gui
h('create soma') # creates soma from hoc
dend = h.Section() # creates dend from Python
h.psection(h.soma) # works nicely
h.psection(dend) # also works nicely
Code: Select all
h('forall print secname()')
Code: Select all
soma
__nrnsec_0x8a7d9b0
It would be great if h.Section() had an optional argument that could be used to specify a meaningful hoc name, like
Code: Select all
dend = h.Section(hocname='dend')
So the use of NEURON's native GUI tools is limited to sections that were created by executing hoc code. But does this mean you actually have to embed hoc statements, like
Code: Select all
h('create axon')
Nope. Just insert this bit of Python in your program
Code: Select all
def Section(name):
h("create "+name)
return h.__getattribute__(name)
Code: Select all
axon = Section('axon')
1. it enables use of NEURON's GUI tools (including Model View) to explore and manage your model's properties,
and
2. you don't have to sprinkle hoc statements all over your nice Python program. The only hoc stuff is in the Python procedure called Section.
Many thanks to Robert McDougal for this very useful tip!