maya wrote:1. How can I subtree() in python?
In hoc it is:
Code: Select all
apical = new SectionList()
access apic[0]
apical.subtree()
First, a comment about your hoc code:
Don't use access this way. You'll sabotage all graphs and hoc statements that use "naked range variables" (e.g. v, ina(0.7), ek(0.1)) to refer to a value in the default section--because access changes the section that is the default section. So if the first access statement executed in your hoc code is
access soma
then all graphs etc. that refer to v will really refer to soma.v(0.5). And when your program executes
access apic[0]
then, all of a sudden, all of your graphs etc. that refer to v will now refer to apic[0].v(0.5) instead. Got it?
You should use access only once--use it to specify the section in the model that is most important (usually soma)--and use either dot notation or section stack syntax whenever it is necessary to specify some other section. The fix for your particular hoc code is
Code: Select all
apical = new SectionList()
apic[0] apical.subtree() // apic[0] is the "currently accessed section" when apical.subtree() is called
Here's how to make a SectionList that contains the subtree whose root section is apic
apical = h.SectionList()
apical.subtree(sec=apic)
2. How can do a distance() function?
In hoc it is:
Code: Select all
distapic = new SectionList()
access soma
distance()
forsec apical {
if (distance(0)>=350) {
distapic.append()
}
}
So here's another example of "access abuse." The fix, of course, is to replace lines 2 and 3 with this:
See if this bit of Python helps with your question about how to use distance to select a particular set of sections. It iterates over all members of the apical SectionList, and for each section will print the section name followed by the range of each internal node (i.e. normalized distance from the 0 end of the currently accessed section) and its path distance from the origin for path distances:
Code: Select all
for sec in apical:
print h.secname()
for seg in sec:
print seg.x, h.distance(seg.x)
Now a question for you: don't you really want to build a set of sections whose _proximal_ ends (nodes at 0) are at some specified distance from the soma?
3. Why can't I set the values "global_ra" and "celsius" as I do with "nseg" and "cm"?
Because global_ra and celsius are global variables. They are not section variables or range variables, so syntax that tries to assocate them with an individual section will not work. And that's what the error message
Code: Select all
AttributeError: 'nrn.Section' object has no attribute 'global_ra'
was trying to tell you. Instead, they pertain to all sections, so they are known to Python as h.global_ra and h.celsius.