according to the documentation for SectionList, there is a method called printnames that does what its name suggests. However, when I call it, all it returns is "1.0" (when I was expecting it to return 'soma', 'Bdend', and 'Adend' in the above example). How can I actually get this method to work?
Not sure how you invoked SectionList.printnames. When I call it, it works just fine
Code: Select all
>>> cell = Cell()
>>> cell.all.printnames()
<__main__.Cell object at 0xb732ddec>.soma
<__main__.Cell object at 0xb732ddec>.Bdend
<__main__.Cell object at 0xb732ddec>.Adend
as long as you don't mind the 1.0 that SectionList.printnames returns, and the ugliness of those section names. Note that the nice strings stipulated in the Python statements that created the sections become the Python names for the sections, but the hoc names also include the address of the Python Cell class instance.
To make a section have a nice name in both hoc and Python, the section must be created by executing a hoc statement. To make a top level model cell (one that is not an instance of some Cell class), one would do this
h("create soma, Adend, Bdend")
soma = h.soma
Adend = h.Adend
Bdend = h.Bdend
. . . other statements . . .
The easiest way to create a cell class definition so that each section's name will look nice in hoc AND Python is to write the cell class definition as a hoc template, and the easiest way to do that is by using a CellBuilder. I just now used the CellBuilder to create a model cell with the same topology as yours but with section names soma, adend, and bdend, and exported that as a cell class, with the hoc name Cell, to a file called cell.hoc. Then I executed
Code: Select all
nrngui -python
from neuron import h,gui
h('load_file("cell.hoc")')
cell = h.Cell()
That last statement should have created a new Python object called cell which is an instance of the model cell defined by the template in cell.hoc--but did it?
Code: Select all
>>> h('forall print secname()')
Cell[0].soma
Cell[0].adend
Cell[0].bdend
shows that hoc has an instance of the Cell class called Cell[0], and that instance has three sections with the desired names.
Code: Select all
>>> cell.all.printnames()
Cell[0].soma
Cell[0].adend
Cell[0].bdend
shows that the SectionList all contains three sections with the desired names.
Finally
Code: Select all
>>> h("topology()")
|-| Cell[0].soma(0-1)
`----------------------| Cell[0].adend(0-1)
`--------| Cell[0].bdend(0-1)
confirms the topology and spatial discretization of the model, and
Code: Select all
>>> h("forsec Cell[0].all psection()")
will confirm the geometry and biophysical properties of Cell[0]'s sections.