Page 1 of 1

access the section after loading a morphology file

Posted: Fri Oct 29, 2010 7:31 am
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

Re: access the section after loading a morphology file

Posted: Fri Oct 29, 2010 11:58 am
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.

Re: access the section after loading a morphology file

Posted: Fri Oct 29, 2010 3:18 pm
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()))

Re: access the section after loading a morphology file

Posted: Sat Oct 30, 2010 5:27 pm
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
)

Re: access the section after loading a morphology file

Posted: Mon Nov 08, 2010 11:52 am
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?

Re: access the section after loading a morphology file

Posted: Tue Nov 09, 2010 10:47 am
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

Re: access the section after loading a morphology file

Posted: Tue Nov 09, 2010 11:51 am
by vellamike
Thanks, I was missing the initial h.