Defining 3D location information

Anything that doesn't fit elsewhere.
Post Reply
pascal
Posts: 106
Joined: Thu Apr 26, 2012 11:51 am

Defining 3D location information

Post by pascal »

I am having trouble with a very basic issue: getting NEURON to tell me the 3D location of a cell. The "Conceptual Overview of Sections" documentation has the following snippet of code to print out the 3D coordinates of a cell:

Code: Select all

forall delete_section()
create a, b, c, d, e
connect b(0), a(1)
connect c(1), b(1)
connect d(0), b(1)
connect e(0), a(0)
forall nseg=20
forall L=100
forall diam(0:1) = 10:40

objref s
s = new Shape()
s.show(0)
a s.color(2)
topology()
finitialize()
forall {
        print secname()
        for i=0,n3d()-1 print i, x3d(i), y3d(i), z3d(i), diam3d(i)
}
I tried to implement something similar in Python:

Code: Select all

from neuron import h, gui

soma=h.Section(name='soma') 
dend=h.Section(name='dend')

soma.diam = soma.L = 20 
dend.diam = 2
dend.L=200

#define connectivity between sections
dend.connect(soma,0,0) #connect 0 end of dend to 0 end of soma

#none of these lines of code helps solve the problem
#h.topology() 
#h.finitialize()
#h.define_shape()

for sec in h.allsec():
    print "section=",sec.name() 
    for i in xrange(int(h.n3d())): print i, h.x3d(i), h.y3d(i), h.z3d(i), h.diam3d(i)
    
The problem is that h.n3d() always returns 0 (actually 0.0, which is why I needed to force it to be an integer). On the one hand, I understand why this might be, since in the preceding code I did nothing to prescribe any 3D locations. But on the other hand, the code from "Conceptual Overview of Sections" does not prescribe any 3D locations before printing out such locations, leaving me to assume that NEURON assigns a default 3D location to a cell when it is created.

I am obviously missing something very basic here. Thanks in advance for the help.
pascal
Posts: 106
Joined: Thu Apr 26, 2012 11:51 am

Re: Defining 3D location information

Post by pascal »

Whoops, apparently this question has already been asked here: viewtopic.php?f=8&t=3627
(In my defense, I searched for n3d and n3d(), and nothing came up in either case.)

I thought I had tried calling define_shape() before printing out the 3D coordinates, but apparently not. Once I added this line in it worked fine:

Code: Select all

from neuron import h, gui

soma=h.Section(name='soma') 
dend=h.Section(name='dend')

soma.diam = soma.L = 20
dend.diam = 2 
dend.L=200

#define connectivity between sections
dend.connect(soma,0,0) #connect 0 end of Bdend to 0 end of soma

h.define_shape()

for sec in h.allsec():
    print "section=",sec.name() 
    h.psection()
    for i in xrange(int(h.n3d())): print i, h.x3d(i), h.y3d(i), h.z3d(i), h.diam3d(i)
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Defining 3D location information

Post by ted »

Thanks for posting the solution. Yes, define_shape() (in hoc) or h.define_shape(in Python) does the job.

About documentation of n3d(): you're right, using the "new" documentation's search function to look for n3d() finds nothing. However, searching for n3d without the paired parentheses turns up a direct link to documentation of n3d() (_with_ the parentheses!). The same appears to be true for the name of any built-in procedure or function. Strange and not very user-friendly.
Post Reply