Page 1 of 1

Caveats when using neuron.h.SectionList()?

Posted: Tue Oct 02, 2012 10:45 am
by ehagen
I'm having some issues filling SectionList-objects from Python at the moment. Basically creating a SectionList inside the Cell-object fail to append the correct sections. It work however if I change it to use a neuron.h.List instead, in this short code example below.

Also, the "neuron.h('forall delete_section()')" do not work for this case, why is that?

Code: Select all

#!/usr/bin/env python
import neuron

class Cell:
    def __init__(self):
        self.soma = neuron.h.Section(name='soma', cell=self)
        self.soma.L = 30
        self.soma.diam = 30
        self.soma.nseg = 2
        self.dend = neuron.h.Section(name='dend', cell=self)
        self.dend.L = 1000
        self.dend.diam = 2
        self.dend.nseg = 20    
        self.dend.connect(self.soma, 1, 0)
        self.allseclist = self.create_seclist()
    def create_seclist(self):
        allseclist = neuron.h.SectionList()
        return allseclist

def print_secname(cell):
    for sec in cell.allseclist:

if __name__ == '__main__':    
    #this doesn't have an effect
    neuron.h('forall delete_section()')

    cell1 = Cell()
    print "this fails when using neuron.h.SectionList():"
    for sec in cell1.allseclist:

    print "same here:"
    print "This is what I want to be in the allseclist:"
    print "presumably correct sections" 
    print neuron.h.topology()

Script output with NEURON and python versions:

Code: Select all

imt-iw23013124:markram ehagen$ ipython
Python 2.7.3 (default, Sep 18 2012, 12:03:14) 
Type "copyright", "credits" or "license" for more information.

IPython 0.13 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: run
NEURON -- VERSION 7.3 (736+:19ad148877ff+) 19ad148877ff
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2012

this fails when using neuron.h.SectionList():
<__main__.Cell instance at 0x110a3bfc8>.soma
<__main__.Cell instance at 0x110a3bfc8>.soma
same here:
<__main__.Cell instance at 0x110a3bfc8>.soma
<__main__.Cell instance at 0x110a3bfc8>.soma
This is what I want to be in the allseclist:
<__main__.Cell instance at 0x110a3bfc8>.soma
<__main__.Cell instance at 0x110a3bfc8>.dend
presumably correct sections

|--|       <__main__.Cell instance at 0x110a3bfc8>.soma(0-1)
    `-------------------|       <__main__.Cell instance at 0x110a3bfc8>.dend(0-1)


I'm on mac OS X 10.8.2, x86_64, python installed using MacPorts.

Best regards,

Re: Caveats when using neuron.h.SectionList()?

Posted: Tue Oct 02, 2012 3:00 pm
by ted
SectionList's append() method appends the currently accessed section. This suggests that instead of
you might try
That approach seems to work when the sections are top level, as in this example (most returned values omitted):

Code: Select all

>>> from neuron import h
>>> soma=h.Section(name='soma')
>>> dend=h.Section(name='dend')
>>> allsec = h.SectionList()
>>> allsec.append(sec=soma)
>>> allsec.append(sec=dend)
>>> for sec in allsec:
...   print h.secname()