Accessing all sections of a particular cell from a list

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

Moderator: hines

Post Reply
sgratiy
Posts: 41
Joined: Tue Mar 30, 2010 5:33 pm

Accessing all sections of a particular cell from a list

Post by sgratiy »

I have a python class which defines the population via a list

Code: Select all

class PL2PC:
    def __init__(self, morph_fname, n_cells):
        self.cell = []
        for ic in range(0,n_cells):
            self.cell.append(h.L2_PC(morph_fname))
First question: Is this the proper way of defining a list of cells?

Now the main question:
I want to access sections of a particular cell from a member function of this class. I am not sure how to do that. Do I understand correctly that

Code: Select all

       for sec in h.allsec():

will go over all sections of all cells and cannot be applied to a particular cell from the list?
The only thing I can think of is to define

Code: Select all

allsections = new SectionList()
in my hoc definition of each cell and then do the following in Python:

Code: Select all

 cell0 = self.cell[0]    # get at a particular cell
for sec in cell0.allsections
Is this the right way for doing this? I am very new to this.
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Accessing all sections of a particular cell from a list

Post by ted »

sgratiy wrote:First question: Is this the proper way of defining a list of cells?
It may work, but it's good to move even farther away from "subscripted object names." Better to append each new instance at the time that you create it. In pseudocode, if you need N cells,

Code: Select all

for i=0,ncells-1
  create a new cell instance
  append this to the list of cells
or better yet, create a function makecell that returns an instance of the class, and

Code: Select all

for i=0,ncells-1
  cells.append(makecell)
where cells is the name of the list of cells.
I want to access sections of a particular cell from a member function of this class.
A well-written cell class definition will have a member called "all". During creation of a new instance of such a class, each section that belongs to the new instance is appended to "all". So if foo is the name of an instance of that class, you can iterate over the contents of foo.all.

If you use the CellBuilder to make a toy model cell (ball & stick will do), then use its Management page to export a "Cell Type" you'll get a hoc file that will show you exactly how the "all" set is created and configured.
Do I understand correctly that

Code: Select all

       for sec in h.allsec():
will go over all sections of all cells and cannot be applied to a particular cell from the list?
I believe that is the case. It's easy enough to test--just make two instances of a class and then see what for sec in h.allsec() does.
The only thing I can think of is . . .
You're on the right track. Use the CellBuilder, as suggested above, to generate some hoc code that will show you exactly how to structure your template.
Post Reply