copy and use object reference (SectionRef) in function

The basics of how to develop, test, and use models.
Post Reply
rlindroos
Posts: 17
Joined: Thu Jan 02, 2014 2:23 pm

copy and use object reference (SectionRef) in function

Post by rlindroos » Tue Jan 07, 2014 10:57 am

Hi all,
I want to make a function that calculates the somatic distance of a section similar to this thread:

http://www.neuron.yale.edu/phpbb/viewto ... =15&t=2892

something like:

Code: Select all

    func cableDist() {local dist
    
		$o1.sec print secname()			// checking imported section
		$o1.parent print secname()    // checking that section has parent
		
		
		objref s								// this works
		$o1 s = new SectionRef()		// this don't work! (syntax error)
				
    	// This is basically what I would like to do
    	while (s.has_parent) {
			dist += L
			s.parent {
				s = new SectionRef()	
				if (s.has_parent) {
					dist += L // don't count length of soma
				}		
			}
		}

		
		return dist
    }
run from the example model:

Code: Select all

// cell 1

create soma, dend[2]
access soma
connect dend[0](0), soma(1)
connect dend[1](0), dend[0](1)
 
load_file("functions.hoc")

objref s1
dend[1] s1 = new SectionRef() 
cableDist(s1)
from the same thread as above.

Similar code (see thread above) works fine if I use it "on line" in the main script but when I try to place it in a function I get problems.
With the current setup I get syntax error bu I have earlier obtained both segmentation error and stack type error (bad stack access: expecting(double);really(unknown)).

All help would be appreciated!
Robert

ted
Site Admin
Posts: 5592
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: copy and use object reference (SectionRef) in function

Post by ted » Wed Jan 08, 2014 12:03 am

rlindroos wrote:I want to make a function that calculates the somatic distance of a section similar to this thread:

http://www.neuron.yale.edu/phpbb/viewto ... =15&t=2892
If all you need is distance from the soma, there is no need for SectionRef or all the elaborations discussed in that thread. Just set a reference point for distance measurements (decide whether it is to be the 0 or 1 end of soma, or maybe soma's midpoint), then use

Code: Select all

forall for (x,0) {
  rangevar(x) = somefunction(distance(x))
}
to iterate over each internal node of each section and assign the desired value to your range variable of interest. If you only want to vary a parameter in a subset of sections, first create a SectionList, append the sections of interest to the SectionList, then

Code: Select all

forall seclistname for (x,0) {
  etc.
If you're unsure how to proceed, make a toy model cell with the CellBuilder, set up parameterized variation of some range variable parameter over a subset of sections (see the CellBuilder tutorial on NEURON's Documentation page), then export that CellBuilder to a hoc file and steal the code that sets up the subset and iterates over the subset to adjust the range variable.

rlindroos
Posts: 17
Joined: Thu Jan 02, 2014 2:23 pm

Re: copy and use object reference (SectionRef) in function

Post by rlindroos » Wed Jan 08, 2014 5:16 am

If all you need is distance from the soma, there is no need for SectionRef or all the elaborations discussed in that thread. Just set a reference point for distance measurements (decide whether it is to be the 0 or 1 end of soma, or maybe soma's midpoint), then use

forall for (x,0) {
rangevar(x) = somefunction(distance(x))
}
This is a smooth way to assign value to range variables, thanks for the insight! However I want to be able to compare the NEURON model currently under construction with one made using GENESIS and that will be hard since I don't understand the result of the distance() function. See earlier thread:

viewtopic.php?f=15&t=2994

For that reason and for a deeper understanding of NEURON I would still want to be able to build functions such as the one mentioned above - if it is possible?
If you only want to vary a parameter in a subset of sections, first create a SectionList, append the sections of interest to the SectionList, then ...
This is also interesting. Is there an automatic way to append all parents of an arbitrary section, from the section to the soma into a SectionList?

ted
Site Admin
Posts: 5592
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: copy and use object reference (SectionRef) in function

Post by ted » Wed Jan 08, 2014 2:52 pm

I don't understand the result of the distance() function. See earlier thread:
After you work through my reply to that, you probably now understand distance(). If not please continue discussion of distance() in that thread.
For that reason and for a deeper understanding of NEURON I would still want to be able to build functions such as the one mentioned above
I don't see why this is a problem. You want something that tells the distance of point xfoo in section foo from a reference point xbah in some other section bah. distance() does that.

Code: Select all

bah distance(0, xbah) // bah(xbah) is the origin for distance measurements
foo print distance(xfoo) // distance of foo(xfoo) from bah(xbah)
Is there an automatic way to append all parents of an arbitrary section, from the section to the soma into a SectionList?
Not built into NEURON, but with SectionRef's parent() method and a bit of recursion you could implement a recursive algorithm that produces such a SectionList.

Post Reply