Section creation

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

Moderator: hines

Post Reply
Krishna Chaitanya
Posts: 70
Joined: Wed Jan 18, 2012 12:25 am
Location: University of Pavia

Section creation

Post by Krishna Chaitanya » Tue Apr 17, 2012 12:46 am

Hi,

If I use,

self.hillock = [h.Section(cell=self)]

In the above syntax, why should we use "cell=self"? What is the importance of that? Thank you.

mctavish
Posts: 74
Joined: Tue Mar 14, 2006 6:10 pm
Location: New Haven, CT

Re: Section creation

Post by mctavish » Thu Apr 19, 2012 1:49 pm

A general idiom for Python cell objects is:

Code: Select all

from neuron import h
class Cell(object):
    def __init__(self):
        self.soma = h.Section(name='soma', cell=self)
The "cell=self" tells NEURON what Python object this section belongs to. To be honest, I'm not sure if it is really required or poses a problem if you are doing single-cell modeling and perhaps Michael Hines can give a better answer. For multiple cells, however, any specific reference to "soma" is quickly lost without it. For example:

Code: Select all

from neuron import h
class Cell(object):
    def __init__(self, id=0):
        self.soma = h.Section(name='soma')
        self.id = id
        if id == 0:
            self.soma.insert('hh')
cell1 = Cell(0)
cell2 = Cell(1)
h.psection(sec=cell1.soma)
print "**********"
h.psection(sec=cell2.soma)
This code produces the following:

Code: Select all

soma { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 0*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
	insert hh { gnabar_hh=0.12 gkbar_hh=0.036 gl_hh=0.0003 el_hh=-54.3}
	insert na_ion { ena=50}
	insert k_ion { ek=-77}
}
**********
soma { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 1*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
}
Notice that "soma" is not really descriptive in that there are two of them and they cannot be discriminated by name alone. Adding "cell=self" sort of helps.

Code: Select all

from neuron import h
class Cell(object):
    def __init__(self, id=0):
        self.soma = h.Section(name='soma', cell=self)
        self.id = id
        if id == 0:
            self.soma.insert('hh') 
cell1 = Cell(0)
cell2 = Cell(1)
h.psection(sec=cell1.soma)
print "**********"
h.psection(sec=cell2.soma)
Produces:

Code: Select all

<__main__.Cell object at 0x101995e50>.soma { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 0*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
	insert hh { gnabar_hh=0.12 gkbar_hh=0.036 gl_hh=0.0003 el_hh=-54.3}
	insert na_ion { ena=50}
	insert k_ion { ek=-77}
}
**********
<__main__.Cell object at 0x1019a3090>.soma { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 1*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
}
This is only helpful in that it tells me I have a "Cell" object. If I had two or more cell object types, I could then kind of differentiate at least what class the section belonged to. What I really recommend doing is modifying the name dynamically:

Code: Select all

from neuron import h
class Cell(object):
    def __init__(self, id=0):
        self.soma = h.Section(name='cell_%d_soma' %id, cell=self)
        self.id = id
        if id == 0:
            self.soma.insert('hh')
cell1 = Cell(0)
cell2 = Cell(1)
h.psection(sec=cell1.soma)
print "**********"
h.psection(sec=cell2.soma)
which produces

Code: Select all

<__main__.Cell object at 0x101995e50>.cell_0_soma { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 0*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
	insert hh { gnabar_hh=0.12 gkbar_hh=0.036 gl_hh=0.0003 el_hh=-54.3}
	insert na_ion { ena=50}
	insert k_ion { ek=-77}
}
**********
<__main__.Cell object at 0x1019a3090>.cell_1_soma { nseg=1  L=100  Ra=35.4
	/*location 0 attached to cell 1*/
	/* First segment only */
	insert morphology { diam=500}
	insert capacitance { cm=1}
}
Again, the first part might be a bit ugly, but the last part tells me explicitly what section of what cell I have.

Krishna Chaitanya
Posts: 70
Joined: Wed Jan 18, 2012 12:25 am
Location: University of Pavia

Re: Section creation

Post by Krishna Chaitanya » Fri Apr 20, 2012 6:26 am

Dear mctavish,

Thank you very much for your detailed explanation illustrated with examples. It helped me a lot in understanding the usage of "cell=self". Thank you once again.

Post Reply