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!
Templates with a variable number of sections
-
- Site Admin
- Posts: 6299
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Templates with a variable number of sections
That is a reasonable strategy. Don't try to rewrite the model cell in Python.vilim wrote:The model is currently a template written in hoc with the simulation control in Python.
Also a reasonable strategy.I considered having a template with the number of dendrites as a parameter and deleting the model for every run
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 followingfor some reason the create statements have to be outside the init() procedure . . .
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
Well, not really. Note that hoc allows arrays of objrefs and sections. . . which prevents me from using a function parameter to initialize the length of the dendrite array.
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
Code: Select all
begintemplate Foo
public dend
create dend
. . .
proc init() {
. . . specify properties of dend . . .
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] . . .
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]
Re: Templates with a variable number of sections
Thank you for the quick and extensive reply! It was exactly what I was looking for.