- SectionRef
- child · exists · has_parent · has_trueparent · is_cas · nchild · parent · root · sec · trueparent
SectionRef
Note
Much of this functionality is available in Python through Section
methods in
recent versions of NEURON. It is, however, sometimes necessary to use this class to
interoperate with legacy code.
- class SectionRef
- Syntax:
sref = n.SectionRef(sec=section)
- Description:
SectionRef keeps a pointer/reference to section. If the
sec=
argument is omitted, the reference is to the currently accessed section.This class overcomes a HOC limitation where sections were not treated as objects.
- Syntax:
section sref = new SectionRef()
- Description:
SectionRef keeps a pointer/reference to a section The reference is to the currently accessed section at the time the object was created.
This class allows sections to be referenced as normal object variables for assignment and passing as arguments.
- SectionRef.sec
- Syntax:
sref.sec
- Description:
Returns the
Section
theSectionRef
references.from neuron import n s = n.Section("s") s2 = n.Section("s2") sref = n.SectionRef(sec=s2) print(sref.sec==s) # False print(sref.sec==s2) # True
- Syntax:
sref.sec
- Description:
special syntax that makes the reference the currently accessed section. This class allows sections to be referenced as normal object variables for assignment and passing as arguments. The usage is
create soma, axon axon.diam=2 soma.diam=10 access axon objref s1, s2 soma s1 = new SectionRef() // s1 holds a reference to the soma print s1.sec.diam // print the diameter of the soma s2 = s1 // s2 also holds a reference to the soma s2.sec { psection() } // print all info about soma axon s2 = new SectionRef() proc c() { $o1.sec connect $o2.sec(0), 1 } c(s1, s2) topology()
This last is a procedure that takes two SectionRef args and connects them end to end.
- SectionRef.parent
- Syntax:
sref.parent
Description:
Returns the parent of
sref.sec
.Warning
If there is a chance that a section does not have a parent then
SectionRef.has_parent()
should be called first to avoid an execution error. Note that the parent is the current parent of sref.sec, not necessarily the parent when the SectionRef was created.- Syntax:
sref.parent
- Description:
parent of sref.sec becomes the currently accessed section. Generally it is used in a context like
sref.parent { statement }
just like a normal section name and does NOT need a section_pop If there is a chance that a section does not have a parent thenSectionRef.has_parent()
should be called first to avoid an execution error. Note that the parent is the current parent of sref.sec, not necessarily the parent when the SectionRef was created.
- SectionRef.trueparent
- Syntax:
sref.trueparent
- Description:
Returns the trueparent of
sref.sec
.This is normally identical to
SectionRef.parent()
except when the parent’sparent_connection()
is equal to the parent’ssection_orientation()
.If there is a chance that a section does not have a trueparent then
SectionRef.has_trueparent()
should be called first to avoid an execution error.
- Syntax:
sref.trueparent
- Description:
trueparent of sref.sec becomes the currently accessed section. This is normally identical to
SectionRef.parent()
except when the parent’sparent_connection()
is equal to the parent’ssection_orientation()
. If there is a chance that a section does not have a trueparent thenSectionRef.has_trueparent()
should be called first to avoid an execution error.
- SectionRef.child
- Syntax:
sref.child[i]
- Description:
Returns the ith child of
sref.sec
. Generally it is used in a context likefor child in sref.child: print(child)
Note that the children are the current children of sref.sec, not necessarily the same as when the SectionRef was created since sections may be deleted or re-connected subsequent to the instantiation of the SectionRef.
- Syntax:
sref.child[i]
- Description:
the ith child of sref.sec becomes the currently accessed section. Generally it is used in a context like
for i=0, sref.nchild-1 sref.child[i] { statement }
Note that the children are the current children of sref.sec, not necessarily the same as when the SectionRef was created since sections may be deleted or re-connected subsequent to the instantiation of the SectionRef.
- SectionRef.root
- Syntax:
sref.root
Description:
Returns the root of
sref.sec
.- Syntax:
sref.root
- Description:
root of sref.sec becomes the currently accessed section.
- SectionRef.has_parent()
- Syntax:
boolean = sref.has_parent()
- Description:
Returns
True
if sref.sec has a parent andFalse
if sref.sec is a root section. Invoking sref.parent when sref.sec is a root section will print an error message and halt execution.
Note:
If
sec
is a Section, thensec.parentseg()
is either the segment the section is attached to orNone
ifsec
does not have a parent.- Syntax:
boolean = sref.has_parent
- Description:
returns 1 if sref.sec has a parent and 0 if sref.sec is a root section. Invoking sref.parent when sref.sec is a root section will print an error message and halt execution.
- SectionRef.has_trueparent()
- Syntax:
boolean = sref.has_trueparent()
- Description:
returns
True
if the sref.sec parent node is not the root node andFalse
otherwise. Invoking sref.trueparent when it is the root node will print an error message and halt execution.
- Syntax:
boolean = sref.has_trueparent
- Description:
returns 1 if the sref.sec parent node is not the root node and 0 otherwise. Invoking sref.trueparent when it is the root node will print an error message and halt execution.
- SectionRef.nchild()
- Syntax:
num = sref.nchild()
- Description:
Return the number of child sections connected to sref.sec as a float.
Note
To get the number of child sections as an int, use:
num = len(sref.child)
- Syntax:
integer = sref.nchild
- Description:
Return the number of child sections connected to sref.sec
- SectionRef.is_cas()
- Syntax:
boolean = sref.is_cas()
- Description:
Returns True if this section reference is the currently accessed (default) section, False otherwise.
Note
An equivalent expression is
(sref.sec == n.cas())
.- Syntax:
boolean = sref.is_cas()
- Description:
Returns 1 if this section reference is the currently accessed section, 0 otherwise.
- SectionRef.exists()
- Syntax:
boolean = sref.exists()
- Description:
Returns True if the referenced section has not been deleted, False otherwise.
See also
- Syntax:
boolean = sref.exists()
- Description:
Returns 1 if the section has not been deleted, 0 otherwise.
See also