access the section after loading a morphology file

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

Moderator: hines

Post Reply
romain.caze

access the section after loading a morphology file

Post by romain.caze »

Hi all,
I would like to import a morphology (to be more precise this one : http://cns.iaf.cnrs-gif.fr/files/CELLS/ ... al264L.geo ) inside a python script, for that I tried to use h.file_load and h.xopen method.
The problem is I can't access sections from Ipython :
When I type somaA.diam or somA.v the python interpreter returns the exception " NameError: name 'somaA' is not defined ".
so my question is how can I load this morphology ? Should I first export it in morphML format ?
Cheers,
Romain Caze
ted
Site Admin
Posts: 6299
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: access the section after loading a morphology file

Post by ted »

Code: Select all

nrngui -python
>>> from neuron import h
>>> h.xopen("pyramidal264L.geo")
1.0
>>> h.psection()
soma { nseg=1  L=0.01  Ra=35.4
        /*location 0 attached to cell 0*/
        /* First segment only */
        insert morphology { diam=16.81}
        insert capacitance { cm=1}
}
1.0
>>> for sec in h.allsec():
...   sec.name()
... 
'soma'
'dend[0]'
'dend[1]'
 . . . etc. . . .
>>> for sec in h.allsec():
...   for seg in sec.allseg():
...     print seg.diam
... 
16.8099994659
16.8099994659
16.8099994659
2.97471848094
 . . . etc. . . .
So xopen worked, and the hoc statements in pyramidal264L.geo were read and executed, so that the model cell exists. The next problem is how to use Python to refer to its sections, which were created by executing hoc statements.
mctavish
Posts: 74
Joined: Tue Mar 14, 2006 6:10 pm
Location: New Haven, CT

Re: access the section after loading a morphology file

Post by mctavish »

the "for sec in h.allsec():" does the trick. Here is a loop that will make a list of tuples containing 3D points, the diameter, and the section name.

Code: Select all

points3d = []
for sec in h.allsec():
    num_points = int(h.n3d()) # Get the number of 3D points in the section
    for i in range(num_points):
        x = h.x3d(i)
        y = h.y3d(i)
        z = h.z3d(i)
        diam = h.diam3d(i)
        points3d.append((x, y, z, d, sec.name()))
hines
Site Admin
Posts: 1687
Joined: Wed May 18, 2005 3:32 pm

Re: access the section after loading a morphology file

Post by hines »

When I type somaA.diam or somA.v the python interpreter returns the exception " NameError: name 'somaA' is not defined ".
Use h.somaA.diam or h.somA.v to get the middle value
h.somaA(x).diam to get the value of the segment containing x.

(assumes a prior
from neuron import h
)
vellamike

Re: access the section after loading a morphology file

Post by vellamike »

I have a question on this,

Say I' ve loaded my *.geo file which has created sections by executing hoc statements, is there a way to insert a mechanism into one of its sections through python?

So for example if I've created an "axon" section by running "h.xopen('geometryfile.geo)" right now I can't do axon.insert('hh') can I? Is there a way around this or is the best thing to do to change the morphology (*.geo) file?
romain.caze

Re: access the section after loading a morphology file

Post by romain.caze »

To insert a mechanism I tried h.axon.insert('hh') and it worked well, it had also worked for pointprocesses.
I also want to thanks for the fast posted responses and for this great software !
Romain
vellamike

Re: access the section after loading a morphology file

Post by vellamike »

Thanks, I was missing the initial h.
Post Reply