Confusion regarding get_loc and h.cas

Managing anatomically complex model cells with the CellBuilder. Importing morphometric data with NEURON's Import3D tool or Robert Cannon's CVAPP. Where to find detailed morphometric data.
Post Reply
sbrich
Posts: 23
Joined: Tue May 08, 2018 2:08 pm

Confusion regarding get_loc and h.cas

Post by sbrich » Thu Mar 07, 2019 3:03 pm

I have an anatomically detailed neuron model and I'm starting to attach some synapses to it in an automated fashion. To check to ensure things are operating as expected, I'm trying to check where each of my various synapses are being placed, for which I'm using the get_loc command (i.e. my synapses are called synapse[j], so I call synapse[j].get_loc). Obviously this only returns the position on the segment, and not the segment itself, where the point process (I'm using an Exp2Syn) is located. All of the various documentation says to call h.cas() to return the segment information... but whenever I call h.cas(), cas(), or any possible manipulation I can think of, I always get a very broad syntax error.

It's my understanding from the documentation that calling get_loc "pushes" the current section to be the currently accessed section. However, when I even use something like psection() or secname() immediately following my use of get_loc it gives me the default accessed section that is my soma, NOT where the point process is currently located.

In short, I've explored all avenues I can envision to sidestep the problem of h.cas() not working to output this information from the command line (as opposed to having to go into PointProcessManager every time) to no avail. This seems like a very straightforward task, so I'm assuming that I am fundamentally misunderstanding the way the cas() command works... and I've searched through the forums and the documentation without luck. Any help that can be provided to help me make use of the cas() command to figure out the section that my point process is located in would be greatly appreciated!

sbrich
Posts: 23
Joined: Tue May 08, 2018 2:08 pm

Re: Confusion regarding get_loc and h.cas

Post by sbrich » Mon Mar 11, 2019 10:35 am

My apologies for the "double post", but was curious to see if anyone could help me with this issue. Thanks!

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

Re: Confusion regarding get_loc and h.cas

Post by ted » Mon Mar 11, 2019 3:16 pm

It's only a double post if you put essentially the same post in two different threads.

You're confusing sections, segments, range, and currently accessed section, not to mention Python and hoc syntax. Before carrying this discussion further, we need to settle on whether it will focus on Python or hoc syntax--which do you prefer?

sbrich
Posts: 23
Joined: Tue May 08, 2018 2:08 pm

Re: Confusion regarding get_loc and h.cas

Post by sbrich » Mon Mar 11, 2019 3:30 pm

Thanks Ted... I figured I was confused on something low-level, but didn't realize how confused, haha.

To answer your question, I'm only using hoc syntax (I don't know Python... learning it has long been on my ever growing to-do list!). I believe I remember seeing that the h.cas was Python based, but considering I couldn't find a "hoc alternative" I figured it might work in both syntaxes. Obviously I was wrong there! Thanks in advance for your help clearing this up.

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

Re: Confusion regarding get_loc and h.cas

Post by ted » Mon Mar 11, 2019 6:58 pm

Forget about h.cas. You're using hoc, not Python.

Before you create any synaptic mechanism, you should first create a List.
objref synlist
synlist = new List()

Every time you create a new instance of a synaptic mechanism and attach it to your model cell, you should also append that particular instance to synlist.

After all synaptic mechanisms have been created, you can then iterate through synlist and print out the name of each synaptic mechansm, the section to which it was attached, and the location on that section at which it was attached.

Code: Select all

// usage:
// reportpps(foo)
// where foo is an objref that points to a List of point processes
// prints out the name of the point process itself
// (useful only as a reminder of the point process's class),
// the name of the section to which it is attached, 
// and its location along that section
proc reportpps() { local i, x
  for i = 0, $o1.count()-1 {
    x = $o1.o(i).get_loc()
    print $o1.o(i), " is attached to ", secname(), " at ", x
    pop_section()
  }
}
Comment 20190312: when I first posted this message, I accidentally omitted the statement
synlist = new List()
Of course, the first attempt to append anything to synlist would have generated an error message.

sbrich
Posts: 23
Joined: Tue May 08, 2018 2:08 pm

Re: Confusion regarding get_loc and h.cas

Post by sbrich » Tue Mar 12, 2019 10:36 am

Thanks Ted. One last question here. I think I'm doing something similar to what you're suggesting in my code already: namely, since I'm creating a large number of synapses, I use a single object to store them all in. Namely:

Code: Select all

numsyn=1000 // Number of synapses I'm creating in this run
...

objref spikesource[numsyn], synapse[numsyn], connection[numsyn] // Creates a location for the source, 
//synapse, and connection for each of the numsyn synapses
...

// After a bunch of code/loops to determine where on the cell I want to attach the synapse, I then say

synapse[numattachedsyn] = new Exp2Syn(loc) // where numattachedsyn is the current synapse number,
//i.e. what I'm looping over with numsyn as it's max, and loc is the location on the current segment
So, my question is this: is the object "synapse" I currently have to store my synapses the same thing as the "List" you're referring to? It doesn't seem like you are initializing the object "synlist" in a fashion specific to a List object (or in a way significantly different than how I initiated "synapse"). If there is a key difference here, how should I "append [each synaptic mechanism] to synlist" as you suggested? I'm also slightly confused by the "x = $o1.o(i).get_loc()" in your code, because this was a mechanism I had tried to get the segment location with no luck (although maybe this is where the difference in using a List is coming into play!).

My apologies for all the questions, I just want to make sure I'm not just regurgitating your code, but I'm truly understanding what's going on here, particularly any potential differences between a "List" object and the object I'm currently using as I generate my synapses.

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

Re: Confusion regarding get_loc and h.cas

Post by ted » Tue Mar 12, 2019 11:31 am

First, I should mention that when I entered the post dated Mon Mar 11, 2019 5:58 pm, I omitted the statment
synlist = new List()
I have now revised that post.
sbrich wrote:
Tue Mar 12, 2019 10:36 am
Thanks Ted. One last question here. I think I'm doing something similar to what you're suggesting in my code already: namely, since I'm creating a large number of synapses, I use a single object to store them all in.
First, no you're not. objref foo[N]
where N is a whole number
creates N objrefs with names foo[j] where j lies in the range [0,N-1].

Second, by doing that, you are embedding magic numbers in your code. This is not a good idea because it complicates development, debugging, and reuse of your code. Lists are a much better way to manage collections of objects, because they allow you to write robust code that works regardless of how many objects exist. For examples of the use of lists, you might find it interesting to read this paper
Translating network models to parallel hardware in NEURON, Hines, M. L., and Carnevale N. T. , Journal of neuroscience methods, Volume 169, p.425–455, (2008) http://www.neuron.yale.edu/neuron/stati ... nm2008.pdf
and its source code which is available from ModelDB. For now, focus on the serial implementations of the two networks.
how should I "append [each synaptic mechanism] to synlist"
Read the Programmer's Reference documentation of the List class, especially the append() method.
I'm also slightly confused by the "x = $o1.o(i).get_loc()" in your code
See if the documentation of the List class's o() or object() method helps. Many readers of this thread might want to review hoc syntax https://www.neuron.yale.edu/neuron/stat ... hoc-syntax, and especially the part about arguments https://www.neuron.yale.edu/neuron/stat ... #arguments
My apologies for all the questions, I just want to make sure I'm not just regurgitating your code, but I'm truly understanding what's going on here
No need to apologize. The Forum wouldn't exist if its subscribers/readers already knew everything; nor would the Programmer's Reference, for that matter.

sbrich
Posts: 23
Joined: Tue May 08, 2018 2:08 pm

Re: Confusion regarding get_loc and h.cas

Post by sbrich » Tue Mar 12, 2019 12:41 pm

OK, I think this is starting to make more sense now. I'll go back into my code and redo things with lists as opposed to the N objrefs I was using previously, and then see if I'm able to recover the section info.

Here's what I'm still confused about: even if using N objrefs as I was previously doing isn't a "best-practice", per se, it is most certainly still working... so why isn't the "get_loc()" command working as desired, i.e. allowing me to output the section along with the location? Is this something that can ONLY be done when the synapses are in a List? I would've thought that inputting

Code: Select all

x=synapse[i].get_loc()
would still work, but doing this still gives always returns my "default" segment when I call secname().

Thanks again!

sbrich
Posts: 23
Joined: Tue May 08, 2018 2:08 pm

Re: Confusion regarding get_loc and h.cas

Post by sbrich » Tue Mar 12, 2019 1:11 pm

Hi Ted,

Happy to report that using Lists and the function you provided solved my problem... for the most part. I'm still curious about one, minor issue (more for my own edification and improving my overall understanding of NEURON than anything else).

As it stands, now that everything is a list, when I call reportpps(foo) everything works as expected. However, if I try to call the individual parts of that function from the command line, i.e.

Code: Select all

x=synapse.o(1).get_loc()
secname()
I still get the default "soma" returned as opposed to the actual location of the synapse. This is what was happening to me with my original usage of the get_loc() function when I wasn't using lists. So was my problem less to do with Lists/No Lists and more to do with how I was utilizing the get_loc() function? Does using it within a proc do something differently than running the individual commands from the command line?

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

Re: Confusion regarding get_loc and h.cas

Post by ted » Tue Mar 12, 2019 1:18 pm

Your example didn't provide enough code context for me to say anything about why it didn't work. Don't bother doing that now. Lists are the way to go. Where's the value in figuring out how to properly do something in a way that is at best strongly deprecated, if not frankly wrong.

This discussion involves some tacit assumptions that remain to be verified.
1. that the model setup code is working properly (attaching synaptic mechanisms to sections of your algorithmic choice)
2. that proc reportpps() will work properly. I think it will, but in discussing the use of a List to store references to point processes, I initially didn't bother to declare synlist = new List(), so how likely does it seem that the more complex proc reportpps() doesn't contain some trivial bug?

sbrich
Posts: 23
Joined: Tue May 08, 2018 2:08 pm

Re: Confusion regarding get_loc and h.cas

Post by sbrich » Tue Mar 12, 2019 1:25 pm

I think we're talking about different things here... let me try and rephrase.

I agree with your comment regarding Lists, and am forgetting entirely about everything I wrote pre-Lists. Now everything I'm using is in List form.

My synapses are located correctly based on every check I've been able to perform, primarily just going into the PointProcessManager and directly visualizing them on my morphology. Now, your reportpps() code is CONFIRMING this and giving me the correct locations of all of my synapses.

However, I can envision a scenario in which I'd like to check on the location of a particular synapse, say synapse.o(1), after running a simulation, and ideally I'd like to do this from the command line. Thus, I would've imagined that running the following two lines of code,

Code: Select all

x=synapse.o(1).get_loc()
secname()
from the command line would accomplish this, since that's what is allowing me to correctly output the segment where the synapse is located when run in the reportpps() proc. However, that is not the case, as calling secname() always returns the default location of my soma.

So my question boils down to essentially this: why do those two lines of code work correctly from within the reportpps() proc, but not when run sequentially in the command line?

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

Re: Confusion regarding get_loc and h.cas

Post by ted » Fri Mar 15, 2019 11:35 am

From the Programmer's Reference for hoc https://www.neuron.yale.edu/neuron/stat ... nt.get_loc

Syntax:
{ x = pnt.get_loc() stmt pop_section()}
Description:
get_loc() pushes the section containing the POINT_PROCESS instance, pnt, onto the section stack (makes it the currently accessed section), and returns the position (ranging from 0 to 1) of the POINT_PROCESS instance. The section stack should be popped when the section is no longer needed. Note that the braces are necessary if the statement is typed at the top level since the section stack is automatically popped when waiting for user input. (emphasis added; see comment below about the term "top level")

Example: Consider the following model specification

Code: Select all

create soma, dend
access soma
connect dend(0), soma(1)
objref syn
dend syn = new ExpSyn(0.5)
After executing this code, here is a sequence of commands entered at the oc> prompt and NEURON's resulting output:

Code: Select all

oc>syn
	ExpSyn[0] 
oc>syn.get_loc()
	0.5 
oc>secname()
soma
oc>{ x=syn.get_loc() print secname(), " ", x } 
dend 0.5 
Comment about "if the statement is typed at the top level"
All hoc statements are at the top level EXCEPT for those that are contained in paired curly braces { } and/or wrapped in a template.

Post Reply