It's looking good. Here are some suggestions.
1. The call to finitialize does nothing useful and can be eliminated. run() executes finitialize before it does anything else.
2. The first call to run() can be commented out--it isn't doing anything useful.
If I change the simulation parameters (e.g sodium conductance or soma size, ), the graph doesn’t change as if the vector had not been updated by a new run
Instead of calling run and calculating the derivatives at the top level of the interpreter, wrap that up in a procedure that automates the sequence
execute a simulation
calculate derivative(s)
plot results
I'm going to assume that you're capturing the time course of v and i_cap to a pair of Vectors called vvec and icvec, e.g. by doing this
Code: Select all
objref vvec, icvec
vvec = new Vector()
soma vvec.record(&v(0.5))
icvec = new Vector()
soma icvec.record(&i_cap(0.5))
in the "instrumentation" section of your program (that's after the model's anatomical and biophysical properties have been specified, and before run() is called).
It is convenient to call the procedure that automates simulation followed by data analysis and display something like myrun. myrun() is very simple
Code: Select all
proc myrun() {
run()
postprocess() // analyze and display results
}
It makes sense to put proc myrun() right after the instrumentation part of your program, and maybe precede it with the comment
because that's what it does--it controls the sequence of events that happen during and after a simulation.
The role of proc postprocess() is to calculate the derivative of i_cap and then plot it vs. i_cap. Here's what I'd do--
Code: Select all
objref d2, g2 // d2 will contain derivative of i_cap, g2 will plot that vs. i_cap
d2 = new Vector()
objref nil
proc postprocess() {
d2.deriv(icvec, dt) // note use of dt, so you can use any dt>0
// 0.025 ms produces a rather crude phase plane plot
// instead of making dt smaller, make steps_per_ms larger
// and dt will automatically be made smaller
// 200 works nicely (dt will be 0.005 ms)
if (g2==nil) g2 = new Graph(0) // prevent discarding of previously "kept" traces
d2.plot(g2, icvec)
g2.size(-0.5,0.5,-15,15)
g2.view(-0.5, -15, 1, 30, 648, 296, 300.48, 200.32)
g2.exec_menu("View = plot") // just to make sure it's all visible
g2.label(0.05, 0.9, "x-axis: i_cap(0.5)", 2, 1, 0, 0, 1)
g2.label(0.05, 0.75, "y-axis: D_t(i_cap(0.5))", 2, 1, 0, 0, 1)
// maybe use g2.exec_menu("View = plot") to autoscale the graph
// g2.exec_menu("View = plot")
// to autoscale g2's axes
}
You can put this code right after the definition of proc myrun().
Now if you change parameters, just execute
myrun()
and g2 will automatically be updated.
You might be interested in plotting i_cap vs. v in the course of a simulation.
To do that, insert this at the end of your instrumentation code, i.e. just before the start of the simulation flow control code
Code: Select all
// plot i_cap vs. v during a simulation
objref icvsv
icvsv = new Graph(0)
icvsv.size(-100,20,-0.5,0.5)
icvsv.view(-100, -0.5, 120, 1, 648, 34, 300.48, 200.32)
graphList[3].append(icvsv) // to update it during a run
icvsv.xexpr("v(0.5)", 0)
icvsv.label(0.05, 0.9, "x-axis: v(0.5)", 2, 1, 0, 0, 1)
icvsv.addvar("soma.i_cap( 0.5 )", 2, 1, 0.05, 0.85, 2)
If you want this graph to rescale automatically, include the statement
icvsv.exec_menu("View = plot")
as the last thing that proc postprocess() does.