Templates with a variable number of sections

The basics of how to develop, test, and use models.
Post Reply
vilim
Posts: 2
Joined: Fri Aug 22, 2014 5:23 am

Templates with a variable number of sections

Post by vilim »

Hello,
I would like to have a model with a variable number of single-section dendrites (which could be changed between simulation runs). What would be the best way to accomplish this? The model is currently a template written in hoc with the simulation control in Python. I considered having a template with the number of dendrites as a parameter and deleting the model for every run, but for some reason the create statements have to be outside the init() procedure, which prevents me from using a function parameter to initialize the length of the dendrite array.
Thanks!
ted
Site Admin
Posts: 5810
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Templates with a variable number of sections

Post by ted »

vilim wrote:The model is currently a template written in hoc with the simulation control in Python.
That is a reasonable strategy. Don't try to rewrite the model cell in Python.
I considered having a template with the number of dendrites as a parameter and deleting the model for every run
Also a reasonable strategy.
for some reason the create statements have to be outside the init() procedure . . .
The rule is simple. hoc is a typed language with a single-pass parse, and each user-declared token (variable name that is not a keyword) will be treated as a scalar unless it is first used in a "top level" statement that has the effect of declaring that it refers to "something other than a scalar." "Top level" means "at the top level of the interpreter's stack", or in plain english, "outside of any proc or func." A statement that declares that a token is not a scalar is one of the following

Code: Select all

strdef name // name refers to a string 
double name[n] // name refers to an array of scalars called name[0]..name[n-1]
objref name // name can be used to refer to an instance of a class, i.e. to an object instance
create name // name refers to a section
. . . which prevents me from using a function parameter to initialize the length of the dendrite array.
Well, not really. Note that hoc allows arrays of objrefs and sections

Code: Select all

objref name[n] // name[0]..name[n-1] can be used to refer to object instances
  // this isn't really very useful; it's far better to use Lists to manage collections of objects
create name[n] // name[0]..name[n-1] refer to sections
  // now, this _is_ potentially useful
So let's say your template looks like this

Code: Select all

begintemplate Foo
  public dend
  create dend
  . . . 
  proc init() {
    . . . specify properties of dend . . .
and you want to be able to have a model with more than one section whose base name is dend, just to this

Code: Select all

begintemplate Foo
  public dend
  create dend[1] // an array of sections with base name dend
    // only one element in that array right now, called dend[0]
  . . . 
  proc init() { local i
    create dend[$1] // legal because hoc already knows that dend is the name of an array of sections
      // so all we're doing is resizing that array
    for i=0,$1-1 dend[i] {
      . . . specify properties of dend[i] . . .
and you will be able to do this
objref bar
bar = new Foo(27)
which will give you a new instance of the Foo class that has 27 instances of dend, whose top level names are bar.dend[0]..bar.dend[26]
vilim
Posts: 2
Joined: Fri Aug 22, 2014 5:23 am

Re: Templates with a variable number of sections

Post by vilim »

Thank you for the quick and extensive reply! It was exactly what I was looking for.
Post Reply