Sometimes, in NEURON one needs a NULLObject, for example, when creating a NetCon with a source, but no target, or vice versa. (In the following toy example, I create a NetCon with no source *and* no target, which is legal, 'though useless.)
Code: Select all
oc>objref nil,nc
oc>nc = new NetCon(nil,nil)
oc>nc.event(5)
0
oc>
The normal way to crate a NULLObject (according to the NetCon documentation in the Programmer's Reference) is to declare an object reference, and not bind it to anything, as in the example above.
The problem is, how do I create an unbound objref in Python.
The following does not work:
Code: Select all
>>> import nrn
>>> import neuron
>>> h = neuron.h
>>> h("objref nil")
1
>>> nc = h.NetCon(h.nil,h.nil)
/Applications/NEURON-6.2/nrn/i686/bin/nrniv: if arg 1 is an object it must be a point process or NULLObject
<snip>
RuntimeError: hoc error
>>> print h.nil
None
>>> h.NetCon(None,None)
/Applications/NEURON-6.2/nrn/i686/bin/nrniv: if arg 1 is an object it must be a point process or NULLObject
<snip>
RuntimeError: hoc error
>>>
A hoc unbound objref is translated to Python None object, but apparently translation does not occur in the other direction (i.e. Python None object is not converted to hoc unbound objref)
Here's a workaround:
Code: Select all
>>> import nrn
>>> import neuron
>>> h = neuron.h
>>> h("objref nil,nc")
1
>>> h("nc = new NetCon(nil,nil)")
1
>>> nc = h.nc
>>> nc.event(5)
0.0
>>>
Since there's a workaround, this isn't a top priority, but ideally, hoc.NULLObject <=> Python.None conversion would be bidirectional. A cheaper fix would be to create a neuron.h.NULLObject object. (or singleton class) Then one would write:
Code: Select all
>>> nc = h.NetCon(h.NULLObject,h.NULLObject)
Not supremely elegant, but still an improvement.