finitialize() not working?

The basics of how to develop, test, and use models.
Post Reply
mgiugliano
Posts: 9
Joined: Fri Aug 18, 2006 12:08 pm
Location: Trieste, Italy
Contact:

finitialize() not working?

Post 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()
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: finitialize() not working?

Post 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.
mgiugliano
Posts: 9
Joined: Fri Aug 18, 2006 12:08 pm
Location: Trieste, Italy
Contact:

Re: finitialize() not working?

Post by mgiugliano »

Thank you for your precious answer.
Post Reply