Mechanisms at terminal nodes in hoc vs. Python

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
csh
Posts: 52
Joined: Mon Feb 06, 2006 12:45 pm
Location: University College London
Contact:

Mechanisms at terminal nodes in hoc vs. Python

Post by csh »

There is a slight inconsistency regarding how mechanisms in terminal nodes are handled from hoc and Python. Consider the following hoc code:

Code: Select all

create s
s { 
    nseg = 1
    insert pas
    for (x) print x, g_pas(x)
}
This will print:

Code: Select all

0 0.001 
0.5 0.001 
1 0.001
Obviously, calling g_pas(0) or g_pas(1) will return its value at the adjacent internal node. Trying to do the same from python:

Code: Select all

import neuron
if __name__ == "__main__":
    h = neuron.hoc.HocObject()
    s = h.Section()
    s.nseg = 1
    s.insert("pas")
    for seg in s:
        print seg.x, seg.pas.g
results in:

Code: Select all

Traceback (most recent call last):
  File "test_term.py", line 8, in <module>
    print seg.x, seg.pas.g
NameError: pas, the mechanism does not exist at PySec_b7d3c050(0)
I would have to explicitly do:

Code: Select all

    for seg in s:
        if not(seg.x == 0 or seg.x == 1): print seg.x, seg.pas.g
to avoid this. I understand that it doesn't make any sense to assign a value to a range variable at a terminal node, since no mechanisms are attached to it, but it would be nice if one could print range variables using the "for seg in section" syntax without checking for terminal nodes. For instance, would it be possible to print out the value of the range variable at the adjacent internal node when seg.x == 0 or seg.x == 1, as it is done from hoc? One could still emit an error message when trying to assign to range vars at terminal nodes.
Best
Christoph
csh
Posts: 52
Joined: Mon Feb 06, 2006 12:45 pm
Location: University College London
Contact:

Re: Mechanisms at terminal nodes in hoc vs. Python

Post by csh »

I just saw the changes to the "for seg in sec" and "for seg in sec.allseg()" syntax in http://www.neuron.yale.edu/cgi-bin/trac ... geset/2195. That fixes the problem, thank you very much!
Christoph
Post Reply