Section access forsec pop_section forall ifsec push_sectionSince sections share property names eg. a length called
L
it is always necessary to specify
which section is being discussed.
There are three methods of specifying which section a property refers to (with each being compact in some contexts and cumbersome in others). They are given below in order of precedence (highest first).
.
varname . Examples
are
This notation is necessary when one needs to refer to more than one section within a single statement.dendrite[2].L = dendrite[1].L + dendrite[0].L axon.v = soma.v print soma.gnabar axon.nseg = 2*axon.nseg
and means that the currently selected section during the execution of stmt is sectionname. This method is the most useful for programming since the user has explicit control over the scope of the section and can set several range variables. Notice that after the stmt is executed the currently selected section reverts to the name (if any) it had before sectionname was seen. The programmer is allowed to nest these statements to any level. Avoid the error:sectionname {stmt}
which setssoma L=10 diam=10
soma.L
, then pops the section stack and sets diam
for whatever section is then on the stack.
It is important that control flow reach the end of stmt in order to
automatically pop the section stack. Therefore, one cannot use
the continue, break, return
statements in stmt.
There is no explicit notion of a section variable in NEURON but the same effect can be obtained with the SectionRef class. The use of push_section for this purpose is not recommended except as a last resort.
Looping over sets of sections is done most often with the forall and forsec commands.
defines a default section name to be the currently selected section when the first two methods are not in effect. There is often a conceptually privileged section which gets most of the use and it is useful to declare that as the default section. e.g.access sectionname
With this, one can, with a minimum of typing, get values of voltage, etc at the command line level.access soma
In general, this statement should only be used once to give default access
to a privileged section. It's bad programming practice to change the
default access within anything other than an initialization procedure.
The ``sec { stmt }
'' form is almost always the right way to
use the section stack.
CurrentlyAccessedSection
access section
section stmt
which is lesser precedence than
section.var
Note:
The access statement should not be used within a procedure or function. In fact the best style is to execute it only once in a program to refer to a priviledged section such as "soma". It can be very confusing when a procedure has the side effect of permanently changing the default section.
create a, b, c, d access a print secname() b { print secname() access c // not recommended. The "go_to" of sections. print secname() d {print secname()} print secname() } // because the stack has more than one section, c is popped off print secname() // and the second "access" was not permanent!
CurrentlyAccessedSection
forall stmt
Within an object, forall
refers to all the sections
declared in the object. This is generally the right thing to do when a template
creates sections but is inconvenient when a template is constructed which
needs to compute using sections external to it. In this case, one can pass a collection
of sections into a template function as a SectionList object argument.
The forall
is relatively slow,
especially when used in conjunction with issection
and ismembrane selectors. If you are often iterating over the same
sets it is much faster to keep the sets in SectionList objects and use
the much faster forsec command.
The iteration sequence order is undefined but will remain the same for a given sequence of create statements.
prints the names of all the sections which have been created.create soma, axon, dend[3] forall { print secname() }
soma axon dend[0] dend[1] dend[2]
Note:
CurrentlyAccessedSection
ifsec string stmt
ifsec sectionlist stmt
CurrentlyAccessedSection
forsec string stmt
forsec sectionlist stmt
forall ifsec string stmt
but faster.
Note that forsec string is equivalent to
forall if (issection(".*string.*)) stmt
forall ifsec sectionlist stmt
but very fast.
create soma, dend[3], axon forsec "a" print secname()
create soma, dend[3], axon objref sl sl = new SectionList() for (i = 2; i >= 0; i = i - 1) dend[i] sl.append() forsec sl print secname()
CurrentlyAccessedSection
pop_section()
point_process.getloc()
.
create soma[5] objref stim[5] for i=0,4 soma[i] stim[i] = new IClamp(i/4) for i=0,4 { x = stim[i].get_loc() printf("location of %s is %s(%g)\n", stim[i], secname(), x) pop_section() }
CurrentlyAccessedSection
push_section(number)
push_section(section_name)
pop_section()
should only be used as a last resort.
It will place a specified section on the top of the section stack,
becoming the current section to which all operations apply. It is
probably always better to use SectionRef or SectionList .
push_section(number)