Page 1 of 1

Accessing / SumUp I_CAP and I_MEMBRANE

Posted: Sat Apr 26, 2008 4:44 am
by AndiL
Hi.

Can i access variables stepwise (and sum them) when i dont have explicit access to the .mod files?

My problem is, that i want to sum up i_cap and i_membrane.
What i really need is, the integral of the two currents. (but the sum will do anyway)

So in one of my models i just added another variable (sum_xxx) and added the value in every BREAKPOINT.

But to those i dont have access to.

Looking forward for help.
thanks in advance.

cheers,
andi

Integrating hoc-level variables

Posted: Sun Apr 27, 2008 4:22 pm
by ted
If you don't need a running sum in the course of a simulation, just use the Vector class's
record() method (assert during model setup) to capture their time courses. Then
integrate after the end of the simulation. To automate this, declare a procedure that
calls run(), then a user-defined "postprocessing" procedure.

Example:

Code: Select all

// assumes simulation generated with fixed time steps
objref icvec
icvec = new Vector()
soma icvec.record(&i_cap(0.5))
icint = 0

// does trapezoidal integration of data sampled at fixed intervals
// expects 2 args: vector to be integrated, and data sampling interval
func trapint() {
  return $2*($o1.sum() - 0.5 * ( $o1.x[0] + $o1.x[$o1.size()-1] ))
}

postprocess() {
    icint = trapint(icvec, dt)
}

proc customrun() {
  run()
  postprocess()
}
Deal with i_membrane in exactly the same way.

This approach executes almost as fast as any NMODL-based approach, and it requires
absolutely no change to any mod files whatsoever.

Be sure to read about the Vector class's record(), sum(), ans size() methods in the
Programmer's Reference
http://www.neuron.yale.edu/neuron/stati ... tml#Vector
Also, to learn about proc trapint() and what to do if your simulations use cvode instead of
fixed dt, read this thread in The NEURON Forum
https://www.neuron.yale.edu/phpBB2/viewtopic.php?t=201