Caveats when using neuron.h.SectionList()?

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

Moderator: hines

Post Reply
ehagen

Caveats when using neuron.h.SectionList()?

Post by ehagen » Tue Oct 02, 2012 10:45 am

Hi,
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()
        allseclist.append(self.soma)
        allseclist.append(self.dend)
        
        return allseclist

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

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 sec.name()

    print "same here:"
    print_secname(cell1)
    
    print "This is what I want to be in the allseclist:"
    print cell1.soma.name()
    print cell1.dend.name()
    
    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 seclistfail.py
NEURON -- VERSION 7.3 (736+:19ad148877ff+) 19ad148877ff
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2012
See http://www.neuron.yale.edu/credits.html

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)

1.0

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

Best regards,
Espen

ted
Site Admin
Posts: 5567
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

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

Post by ted » Tue Oct 02, 2012 3:00 pm

SectionList's append() method appends the currently accessed section. This suggests that instead of
allseclist.append(self.soma)
allseclist.append(self.dend)
you might try
allseclist.append(sec=self.soma)
allseclist.append(sec=self.dend)
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()
... 
soma
dend

Post Reply