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()
}
}