Object arguments (doesn't matter if HOC objects or Python objects) to HOC functions are accessed using positional notation with $o instead of just $. e.g. $o1 instead of $1.
A complete example, where for laziness I define the HOC function via h():
from neuron import h
# declare a HOC function that just invokes a Python object's method
h('proc printit() {$o1.go()}')
class Foo:
def go(self):
print 'hello world'
f = Foo()
print 'now invoking the HOC function'
h.printit(f)
hoc procs and funcs can accept objrefs as arguments. In the body of the proc or func, the name of the objref will be of the form
$oi
where i refers to the position of the objref in the argument list. Remember that the items in the argument list are numbered starting with 1.
Example: define func foo as
Unfortunately, sections created by statements of the form
name = h.Section()
end up with strange hoc names that are difficult to use in hoc statements or with the InterViews-based GUI.
This is why it can be better to define the properties of the cell with hoc code (at least the creation of sections). Then every section will have a valid, user-defined, meaningful section name and can be easily accessed from both hoc and Python.
Example:
Suppose a cell's properties are specified completely by a CellBuilder's ses file or by a hoc file. In Python just do
h.load_file(name_of_ses_or_hoc_file)
Now suppose you're particularly interested in what's going on at the 0.8 location in a section whose hoc name is dend.
Just do this in Python
dend = h.dend
and you can refer to any of this section's properties in either hoc or Python.
dend.nseg and h.dend.nseg are the section's discretization parameter
dend(0.8).v is the same variable as h.dend(0.8).v, but easier to type.
Ditto for dend(0.8).diam and h.dend(0.8).diam.
And you can do
g = h.Graph(0)
g.view(...)
g.addvar('dend.v(0.8)')
If you prefer your graph labels to remind you of the Python names for what is plotted, you could
g.addvar('py.dend(0.8).v')
assuming that you have already told hoc that py is an instance of the PythonObject class
i.e. by doing
h("objref py")
h("py = new PythonObject()")
ted wrote:Unfortunately, sections created by statements of the form
name = h.Section()
end up with strange hoc names that are difficult to use in hoc statements or with the InterViews-based GUI.
Definitely, I like defining cell objects from a Python Class that calls a h.load_file('morphologytemplate.hoc'). Call me silly, but I like seeing the results of the simulations with the Interviews GUI... matplotlib is for final results :P