Using events to implement parameter changes during a run

A collection of noteworthy items selected by our moderators from discussions about making and using models with NEURON.

Moderators: ted, wwlytton, tom_morse

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

Using events to implement parameter changes during a run

Post by ted »

It is often useful to have something happen at a specific time in the course of a simulation, for example, changing a model parameter. There are several ways to do this, but the two most flexible approaches take advantage of NEURON's event delivery system. For example, one could use the NetCon class's .record() method (see http://www.neuron.yale.edu/neuron/stati ... tml#record, especially the part about .record("stmt")).

The other event-driven approach uses an FInitializeHandler and cvode.event() (be sure to read about these in the Programmer's Reference!). Specifically, during initialization, an FInitializeHandler launches an event that will arrive at the time you want the parameter change to happen. For example, suppose your model has a soma section with the hh mechanism, and you want the sodium channel density gnabar_hh in the soma to drop to 1/2 of its initial value at t = 50 ms (as if you dumped a very fast-acting Na channel blocker onto the soma at that time). Put the following code in a file called changeparam.hoc, and make sure that your main program executes
load_file("changeparam.hoc")
right after your model setup code is complete but before you launch a simulation with run().

Code: Select all

control_gnabar_hh = soma.gnabar_hh // save this value for future use
objref fih
fih = new FInitializeHandler("set_up_param_change()")

// this is called during initialization
proc set_up_param_change() {
  soma.gnabar_hh = control_gnabar_hh // ensure that soma.gnabar_hh starts at its control value
  // we changed a parameter, so the adaptive integrator must be reset if we are using it
  if (cvode.active()) {
    cvode.re_init()
  } else {
    fcurrent()
  }
  // also we must reinitialize vector recording
  frecord_init()
  // and of course we must launch the event that will change soma.gnabar_hh at t = 50 ms
  cvode.event(50, "change_gnabar_hh()")
}

// this is the proc that is executed at t == 50 ms in order to change soma.gnabar_hh
proc change_gnabar_hh() {
  soma gnabar_hh = soma.gnabar_hh/2
  // we changed a parameter, so the adaptive integrator must be reset if we are using it
  if (cvode.active()) {
    cvode.re_init()
  } else {
    fcurrent()
  }
}
Post Reply