Page 1 of 1

Find all point processes

Posted: Mon Mar 08, 2021 4:37 pm
by landoskape
Hi.

It would be convenient for me to have a single function that removes all point processes from a cell. (Context: doing experiments where I inject current in different locations and measure the response across the whole cell). I know, I know, I should just keep track of all my point processes and set them to None, but I think a catch-all function should be possible.

Example:

Code: Select all

# Setup some IClamp
stim1 = h.IClamp()

# Then: I want a function like this:
def removeAllPointProcesses():
	for sec in h.allsec():
		# find if sec has a point process -- possible with sec.psection()
		if sec.psection() has a point process
			return variable name of point process

# In this case, if I call:
allPP = soma.psection()["point_processes"]

#It will return:
display(allPP) -->
{'IClamp': {IClamp[0]}}

# But I don't know how to use that information to find the variable 'stim1'

So basically, I'd like to be able to return "stim1" from anywhere... or simply remove it...

Is this possible? Thanks!

Re: Find all point processes

Posted: Tue Mar 09, 2021 3:15 pm
by ted
Why not hose the whole model and rebuild it from scratch? Seriously. That's the only bulletproof way to avoid undesired persistence of object instances (an instance persists until its reference count is 0). You might say, "oh, but undesired persistence will never happen because I will never create more than one reference to any object that I might later want to destroy."

To which the reply is: If you're going to be that disciplined, you might as well exert some discipline in the first place. Every time you create an object that you will later want to destroy, immediately append it to a "list of the doomed" instead of associating it with a top level name. Then when it comes time to destroy everything in the doomed list, just discard the list, and presto! all doomed object instances vanish. Example (assumes the existence of sections called soma and dend):

Code: Select all

doomed = []
doomed.append(h.IClamp(soma(0.5)))
doomed.append(h.IClamp(dend(0.1)))
doomed # should print [IClamp[0], IClamp[1]], if no other IClamps previously existed
# time to destroy them
doomed = []

Re: Find all point processes

Posted: Thu Mar 11, 2021 11:43 am
by landoskape
I love this. I actually started doing something like this, but I'm going to name my list doomed now. Thanks

Re: Find all point processes

Posted: Thu Mar 11, 2021 1:10 pm
by ted
It's always good to use meaningful names so a program automatically documents itself.

One more hint: you can verify the existence or nonexistence of objects by using h.allobjects("classname") to discover the names of all instances of the named class (as well as the reference count for each object instance). Toy example:

Code: Select all

>>> from neuron import h
>>> soma = h.Section(name="soma")
>>> stim = h.IClamp(soma(0.5))
>>> h.allobjects("IClamp")
IClamp[0] with 1 refs
0.0

Re: Find all point processes

Posted: Fri Mar 12, 2021 3:23 pm
by landoskape
That is super useful. Thanks for your help. And also: general thanks for being so present with this forum over the years. I'm sure it's made a huge difference in the use of Neuron in the community.

Re: Find all point processes

Posted: Sat Mar 13, 2021 12:14 pm
by ted
Thanks, but I'm just standing on the shoulders of giants. More credit goes to those who are responsible for the hard work of software development (not to mention getting support for such development). The list at http://neuron.yale.edu/neuron/credits lags behind the growth of the development team.