FInitializeHandler example in Python

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

Moderator: hines

Post Reply
Posts: 74
Joined: Tue Mar 14, 2006 6:10 pm
Location: New Haven, CT

FInitializeHandler example in Python

Post by mctavish »

I rewrote the FInitializerHandler example from the hoc reference for python. I had gotten hung up on trying to pass the function as a string to FInitializerHandler(). Turns out you pass the reference....

Code: Select all

from neuron import h as nrn


def fi0():
    global a
    print "fi0() called after v set but before INITIAL blocks"
    print "  a.v=%g a.m_hh=%g\n" %(a.v, a.m_hh)
    a.v = 10

def fi1():
    print "fi1() called after INITIAL blocks but before BREAKPOINT blocks"
    print "     or variable step initialization."
    print "     Good place to change any states."
    print "  a.v=%g a.m_hh=%g\n" %(a.v, a.m_hh)
    print "  b.v=%g b.m_hh=%g\n" %(b.v, b.m_hh)
    b.v = 10

def fi2():
    print "fi2() called after everything initialized. Just before return"
    print "     from finitialize."
    print "     Good place to record or plot initial values"
    print "  a.v=%g a.m_hh=%g\n" %(a.v, a.m_hh)
    print "  b.v=%g b.m_hh=%g\n" %(b.v, b.m_hh)

class Test:
    def __init__(self):
        self.fih = nrn.FInitializeHandler(1, self.p)
    def p(self):
        print "inside %s.p()\n" %self

fih = []
fih.append(nrn.FInitializeHandler(0, fi0))
fih.append(nrn.FInitializeHandler(1, fi1))
fih.append(nrn.FInitializeHandler(2, fi2))

a = nrn.Section(name='a')
b = nrn.Section(name='b')

for sec in nrn.allsec():

for sec in nrn.allsec():
test = Test()

Site Admin
Posts: 5795
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine

Re: FInitializeHandler example in Python

Post by ted »

Thanks, Tom, I'm going to have to try this.
Post Reply