Calling python function from hoc statement

Moderator: wwlytton

Post Reply
Krishna Chaitanya
Posts: 70
Joined: Wed Jan 18, 2012 12:25 am
Location: University of Pavia

Calling python function from hoc statement

Post by Krishna Chaitanya »


I am trying to call python function in a class using hoc statements to redefine init block. It was pretty easy using hoc programming, but to do the same, in python, I used this approach.

I have a MPI based network and in the prun block, I define

Code: Select all

 def prun(self):
                if self.rank==0:
                        print 'In the function SIMULATING CELLS...\n'
                #h('proc init() {nrnpython("prepruninitialize()")}') - this didn't work either
                h('''objref po
                po=new PythonObject()
                proc init(){
                        if (cvode_active()){
 def prepruninitialize(self):
                if self.rank==0:
                        print 'Setting up initial conditions...\n'
                for ii in range(len(self.grcells)):
                        self.grcells[ii].setv()    # setting up initial voltage.
Whenever I execute this program, it says that "prepruninitialize is not defined". I was able to execute this successfully when I run as individual blocks on nrniv shell but not with MPI based network code.

What am I doing wrong here? Can you kindly let me know?

Thank you.
Site Admin
Posts: 5935
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: Calling python function from hoc statement

Post by ted »

I think I'd try a type 1 FInitializeHandler for this. And instead of using h(''' hoc strings ''') I'd call everything from Python using h, e.g.
. . . test h.cvode_active() and take appropriate steps from Python . . .

Then your custom prun would omit the h(''' . . . ''')

Check out the example ... izeHandler
Post Reply