substitute stadard init() precedure from Python

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
rth
Posts: 41
Joined: Thu Jun 21, 2012 4:47 pm

substitute stadard init() precedure from Python

Post 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
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: substitute stadard init() precedure from Python

Post 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()
rth
Posts: 41
Joined: Thu Jun 21, 2012 4:47 pm

Re: substitute stadard init() precedure from Python

Post by rth »

Wonderful! Thanks!
Post Reply