problem instantiating a hoc template from python

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

Moderator: hines

Post Reply
alexandrapierri
Posts: 69
Joined: Wed Jun 17, 2015 5:31 pm

problem instantiating a hoc template from python

Post by alexandrapierri »

Hello

I have a file called pyrcellfile.hoc, which contains a hoc template that defines a cell class called PYR.
I want to use a Python script to load and instantiate my hoc file.

My python script, myscript.py, looks like his:

from neuron import h
h.load_file("pyrcellfile.hoc")
newpyr = h.PYR()

When I run it, I get the error:

Code: Select all

[b]NEURON: init not enough arguments
 near line 0
 ^
        PYR[0].init()[/b]
Any intuition with what might be causing this error would help a lot!

This is my init() proc in the pyrcellfile.hoc file:

Code: Select all

proc init() {
        gid = $1
        randi = $2

        // morphology
        connect_sections()     
        size_sections()         
        define_shape()          
        append_sections()       
        set_nseg()                      
        get_root()                      

        mechinit()                      
        insert_mechs()         
        set_chanparams()      
 
        pre_list = new List()
        define_synapses($3)     
}
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: problem instantiating a hoc template from python

Post by ted »

Looks like the template's proc init expects three arguments. The first would be a cell-instance-specific gid, the second looks like a parameter that is ultimately used to associate each cell with its own particular pseudorandom sequence, and the third has something to do with setting up synaptic mechanisms that are attached to the cell. What values should you supply? Read the paper that is associated with the model and whatever comments you might find in the source code.
alexandrapierri
Posts: 69
Joined: Wed Jun 17, 2015 5:31 pm

Re: problem instantiating a hoc template from python

Post by alexandrapierri »

thank you!

As a follow-up, I am using a script of yours Ted, to interpolate over the swc points in a hoc file.
The "def interplocs" below expects two arguments, I realize the sec refers to the section and locs to the pt3 points.
How do I call this definition from a separate python script though? Specifically, I am not sure what to insert for the locs argument.

soma_interp = nt.interplocs(pvbcsoma,locs) (what should locs be replaced with here?)

Code: Select all

def interplocs(sec, locs):
    """Computes xyz coords of locations in a section whose topology & geometry are defined by pt3d data.
    Based on code by Ted Carnevale.
    """
    nn = sec.n3d()

    xx = h.Vector(nn)
    yy = h.Vector(nn)
    zz = h.Vector(nn)
    ll = h.Vector(nn)
   
    for ii in range(0, nn):
        xx.x[ii] = sec.x3d(ii)
        yy.x[ii] = sec.y3d(ii)
        zz.x[ii] = sec.z3d(ii)
        ll.x[ii] = sec.arc3d(ii)

    ## normalize length
    ll.div(ll.x[nn - 1])

    xx = xx.to_python()
    yy = yy.to_python()
    zz = zz.to_python()
    ll = ll.to_python()

    pch_x = interpolate.pchip(ll, xx)
    pch_y = interpolate.pchip(ll, yy)
    pch_z = interpolate.pchip(ll, zz)

    res = np.asarray([(pch_x(loc), pch_y(loc), pch_z(loc)) for loc in locs], dtype=np.float32)
    return res
My pt3 points in my hoc file look like this:

Code: Select all

proc size_sections() {
        soma[0] {pt3dclear()
                pt3dadd(0, 0, 0, 10) // distance from (0,0,0) = 0
                pt3dadd(0, 10, 0, 10) // distance from (0,0,0) = 10
                pt3dadd(0, 20, 0, 10) // distance from (0,0,0) = 20
        }
        dend[0] {pt3dclear()
                pt3dadd(0, 20, 0, 4) // distance from (0,0,0) = 20
                pt3dadd(19.4709, 66.053, 0, 4) // distance from (0,0,0) = 68.8631
                pt3dadd(38.9418, 112.106, 0, 4) // distance from (0,0,0) = 118.677
Thank you!
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: problem instantiating a hoc template from python

Post by ted »

I am using a script of yours
Actually, no, you're not. The comment says
Based on code by Ted Carnevale
but that doesn't mean the code is a replication in python of anything that I wrote. One key difference is that this python code uses piecewise one-dimensional cubic interpolation to calculate the estimated locations of segment centers. The code that I wrote in hoc treats the x3d, y3d, and z3d data as the ordinates of piecewise linear functions of arc length, and uses simple linear interpolation to return coordinates that actually lie on the section's centroid. For a section whose centroid deviates from a straight line, cubic interpolation will return coordinates that seldom, if ever, lie on the centroid. Both methods are only approximate, but it is unclear whether one is superior to the other for dealing with neurites from real cells--and the "point source approximation" itself is an approximation.
How do I call this definition from a separate python script though? Specifically, I am not sure what to insert for the locs argument.
Surely this python code was part of a larger program or set of files that includes a working example of how to call the function. That's where your first and best clue lies. My guess is that locs is supposed to be a list or numpy array of range values that correspond to segment centers, but you should verify that for yourself. If my guess is correct, you can construct such a list by

Code: Select all

segx = []
for seg in sec:
  segx.append(seg.x)
Post Reply