Page 1 of 1

finitialize() not working?

Posted: Sat Feb 08, 2020 10:10 am
by mgiugliano
I am preparing a simple PYTHON-NEURON tutorial and found I am unable to use finitialize() properly.
In the minimal code, below, the initial condition set by finitialize(-100) is ignored and the simulated voltage trace starts at -65mV. Why?

Can anybody help me, understanding where is my mistake? Thank you!

Code: Select all

from neuron import h
from matplotlib import pyplot

h.load_file('stdrun.hoc')

soma = h.Section(name='soma') 

soma.insert('pas')

v_vec = h.Vector()             
v_vec.record(soma(0.5)._ref_v) 

h.finitialize(-100)
h.tstop = 50.0
h.run()  

pyplot.plot(v_vec)
pyplot.show()

Re: finitialize() not working?

Posted: Sat Feb 08, 2020 11:58 am
by ted
Much of NEURON's standard run system is implemented in
nrn/share/nrn/lib/hoc/stdrun.hoc

h.run() executes the code in a procedure called run() that is defined in stdrun.hoc.
Here is the chain of (most of the) procedures that are executed when you call h.run(). All of these are defined in stdrun.hoc:

Code: Select all

run()
  stdinit()
    setdt()
    init()
      finitialize(v_init)
  continuerun(tstop)
So if you
h.finitialize(somevalue)
and then call
h.run()
you're executing finitialize() twice--first with the value you want, then with the value that is specified by the hoc parameter v_init. And then the simulation starts.

The fix? Change

Code: Select all

h.finitialize(-100)
h.tstop = 50.0
h.run()
to

Code: Select all

h.v_init = -100
h.tstop = 50.0
h.run()
You'll see a lot of Python code that does this instead:

Code: Select all

h.finitialize(initialpotentialvalue)
h.continuerun(tstopvalue)
This works, but it requires typing long words, and somehow the longer the word that I have to type, the more likely I am to mess it up. Also, it bypasses parts of NEURON's standard run system that can be important if you want to use NEURON's built-in graphics, e.g. for model debugging or just to get quick and not-so-dirty plots of interesting variables. You're using matplotlib, so this consideration may not apply to you.

Re: finitialize() not working?

Posted: Sun Feb 09, 2020 5:07 am
by mgiugliano
Thank you for your precious answer.