Find all point processes

The basics of how to develop, test, and use models.
Post Reply
landoskape
Posts: 6
Joined: Sat Oct 17, 2020 3:08 pm

Find all point processes

Post 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!
ted
Site Admin
Posts: 5893
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Find all point processes

Post 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 = []
landoskape
Posts: 6
Joined: Sat Oct 17, 2020 3:08 pm

Re: Find all point processes

Post by landoskape »

I love this. I actually started doing something like this, but I'm going to name my list doomed now. Thanks
ted
Site Admin
Posts: 5893
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Find all point processes

Post 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
landoskape
Posts: 6
Joined: Sat Oct 17, 2020 3:08 pm

Re: Find all point processes

Post 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.
ted
Site Admin
Posts: 5893
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Find all point processes

Post 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.
Post Reply