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!