Page 1 of 1

substitute stadard init() precedure from Python

Posted: Wed Feb 25, 2015 5:10 pm
by rth
Hi,

I need a bit help with NEURON+Python.
In hoc file, I can easily write new init procedure and it will be called from the run() function. But how can I substitute standard init() if I use Python?

I've tried something like this:

Code: Select all

def myinit():
	h.finitialize()
	h.fcurrent()
	h.frecord_init()
h.init = myinit
h.run()
but it returns error:

Code: Select all

Traceback (most recent call last):
  File "network.py", line 583, in <module>
    h.init = duminit
TypeError: not assignable
>>>
 
Do we have any way to reset init procedure from Python?

Thanks,
Ruben

Re: substitute stadard init() precedure from Python

Posted: Wed Feb 25, 2015 8:18 pm
by ramcdougal
Often one doesn't need to change init but rather wants to do additional things (e.g. assign state variables) during the initialization. If that's your situation, use an h.FInitializeHandler. It has options to specify when exactly things are done, but in the simplest use case, you just pass it a function name to run during initialize. e.g.

Code: Select all

from neuron import h, gui

def do_this_on_init():
    print 'hello from inside init'

fih = h.FInitializeHandler(do_this_on_init)

h.run()
If you really do need to replace init, you can have a one-line HOC procedure that calls your Python function. (There's no meaningful performance issue here since initialization only happens once.) e.g.

Code: Select all

from neuron import h, gui

def do_this_on_init():
    print 'hello from inside init'

h('proc init() {nrnpython("do_this_on_init()")}')

h.run()

Re: substitute stadard init() precedure from Python

Posted: Thu Feb 26, 2015 10:57 am
by rth
Wonderful! Thanks!