silencing netstim during simulation.

When Python is the interpreter, what is a good
design for the interface to the basic NEURON

Moderator: hines

Post Reply
Posts: 25
Joined: Wed Jun 17, 2015 5:31 pm

silencing netstim during simulation.

Post by alexandrapierri »


Following other posts on the forum, I want to silence my netstim at a certain time (400ms) during my simulation. To do this I set, or I've also tried to do netcon.weight=0 according to viewtopic.php?p=17875#p17875. I have a very novice syntax question here. The following if statement gives a syntax error, what is wrong with it?

Code: Select all

        proc connect_cell() {$nc = new NetCon(ns, $o1)}
                            if (runtime=400){
Thanks for any input.
Site Admin
Posts: 5918
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: silencing netstim during simulation.

Post by ted »

The following if statement gives a syntax error, what is wrong with it?
The clue does not lie in the code excerpt that you provided. What was the complete error message?

But whatever is wrong with the if statement's syntax, the code excerpt contains several other errors.

1. The variable name $ns doesn't follow hoc's rules for positional arguments. If the statement
$nc = new NetCon(ns, $o1)
doesn't generate an error message when the interpreter first parses it, it will definitely produce an error when connect_cell() is called.

2. The conditional test
if (runtime=400)
will execute the conditional code as soon as the interpreter encounters it (in this case setting nc.weight to 0) because
is an assignment statement, not a test of whether runtime equals 400.

3. If you fix problem 2 by changing the conditional test to
if (runtime==400)
you may find that the conditional code is never executed. Why? If the value of runtime is calculated by adding up numbers that have nonzero fractional parts (i.e. numbers that are not exact integers), roundoff error may cause failure of the "numerical identity test"

Why not just use NetCon to send an event with negative weight at time t == 400 to the NetStim that you want to silence? Example: suppose the NetStim you want to silence is called ns. Then

objref nil, ncstumm
ncstumm = new NetCon(nil, ns)
ncstumm.weight = -1

will create a NetCon that you can use to shut off ns. How do you get ncstumm to deliver an event to ns at t==400 ms, and make this happen every time you launch a new simulation? Use an FInitializeHandler.

objref fih
fih = new FInitializeHandler("ncstumm.event(400)")

There you go. Put those 5 statements into your program, after model setup is complete but before you call finitialize() or run(). No need to check the value of t (or "runtime") at every fadvance(), and no worry about roundoff error. Be sure to read the Programmer's Reference documentation of the NetCon class's event() method and the FInitializeHandler.
Posts: 25
Joined: Wed Jun 17, 2015 5:31 pm

Re: silencing netstim during simulation.

Post by alexandrapierri »

thanks for this most didactic response.
My apologies for what may seem like excessive pedantry, but in writing these entries I realize that they will also be read by others who may not have the same background or local resources as the person who asked the question in the first place.
I recently bought the book too which complements the Programmer's Reference really well, as it takes you through the logic of things.
Thank you for the complement.
Do I need to define what "nil" represents? Right now it is only mentioned in the objref list. It is a conceptual "entity" that connects to my NetStim.
nil is just an objref that has not yet been associated with an instance of a class. Technically speaking it is "NULLObject"; you will find nil and NULLObject mentioned in the documentation of the NetCon class, where it is used as the target of a NetCon for purposes such as recording spike times from a network's "output cells" (which would otherwise not be monitored by any NetCons), or stopping a simulation when a state variable in a segment (e.g. membrane potential or an ionic concentration) reaches a threshold.

But not mentioned in the documentation of NetCon is the use of NULLObject as a NetCon's source in situations where you need to generate a single network event at a particular time. The parsimonious way to do that is to use the NetCon class's event method. Of course one could the same thing by using a NetStim to generate the event, but that would involve a bit more code and would use more memory since you'd still need a NetCon to deliver the event to whatever target you had in mind.
2. Is is necessary that I place the new NetCon (ncstumm) in a separate process to that of my ns? What about fih? Can it be in the same process as ncstumm or should it be placed in a separate process?
The principal advantage of using multiple processes is achieving load balance on parallel hardware. NetCons, FInitializeHandlers, and NetStims pose negligible computational burdens compared to biophysical model cells, so there's no particular advantage to placing them in separate processes.
Post Reply