Defining event times in the 'NetCon' object

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

Moderator: hines

Post Reply
lempkas
Posts: 4
Joined: Wed Oct 05, 2011 12:14 pm

Defining event times in the 'NetCon' object

Post by lempkas »

I am trying to deliver a train of synaptic inputs to a cell at specified times using the event property of the 'NetCon' function and the 'Exp2Syn' mechanism. I have been able to do this in HOC but I'm having problems doing this in Python.

An example of the typical structure of my HOC code is the following:

Code: Select all

//Define synaptic inputs
objref syn[1], nc[1]

create soma

soma {
    	insert hh

    	syn[0] = new Exp2Syn(.5)

    	nc[0] = new NetCon(&v(0.5), syn[0])
}

//Applying synaptic inputs
objref syntimes

syntimes=new Vector(3)

syntimes.x[0]=100
syntimes.x[1]=200
syntimes.x[2]=300

objref fih
fih = new FInitializeHandler("loadqueue()")
proc loadqueue() { local ii
  for ii=0,syntimes.size()-1 nc[0].event(syntimes.x[ii])
}
Now below is the general way I am trying to perform the same steps in Python:

Code: Select all

from neuron import h

soma=h.Section()

soma.insert('hh')

syn = h.Exp2Syn(0.5,sec=soma)

nc = h.NetCon(soma(0.5)._ref_v,syn)

syntimes=[100,200,300]

def loadqueue():
    for i in syntimes:
        nc.event(i)

fih=h.FInitializeHandler(1,loadqueue())
The call to 'FInitializeHandler' causes Python to crash. I know there are many possible reasons this is not working. Is the HOC syntax of 'nc.event(tdeliver)' the correct syntax for assigning the event times in Python? How and when is the correct time to call 'FInitializeHandler' in Python? This method of delivering synaptic inputs works fine in HOC but do you recommend a different method for doing this?

Thanks for the help!
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Defining event times in the 'NetCon' object

Post by ted »

Start by fixing the hoc code, which contains at least one latent bug that waits to bite you, and also applies an inefficient method for implementing synaptic activations at user-specified times.
The bug is here

Code: Select all

soma {
 . . .
    	syn[0] = new Exp2Syn(.5)
    	nc[0] = new NetCon(&v(0.5), syn[0])
which sets up an autapse with soma as the pre- and postsynaptic element. Unless you really want that, please re-read the Programmer's Reference documentation about the NetCon class, with particular attention to the different kinds of sources that may be used.
The inefficiency is here

Code: Select all

objref fih
fih = new FInitializeHandler("loadqueue()")
proc loadqueue() { local ii
  for ii=0,syntimes.size()-1 nc[0].event(syntimes.x[ii])
}
which loads all user-specified event times into the event queue at initialization. This doesn't scale well, because the compuational overhead involved in managing the event queue depends on the number of events that have not yet been delivered. By stuffing all events into the queue at the start of a simulation, you're adding a bit of extra runtime. Yes, I did post an example of this on the Forum some time ago, but it isn't good practice. I have learned better since then, and now must make amends. A far better way to proceed is to use an instance of the VecStim class. A VecStim is a kind of artificial spiking cell, but it's not a variant of "leaky integrate and fire." Instead, its spike times are defined by the contents of a Vector. Look in
nrn-x.x/share/examples/nrniv/netcon (UNIX/Linux/OS X)
or
nrnxx/share/examples/nrniv/netcon (MSWin)
for vecevent.hoc .mod, and .ses. vecevent.mod defines the VecStim class; the .ses and .hoc files are a program that demonstrates its operation. Notice that there is no need to use an FInitiailzeHandler to load anything into the event queue. Just

Code: Select all

objref vs
vs = new VecStim()
// now use a NetCon to attach vs to the target synaptic mechanism
 . . . you already know how . . .
 . . . don't forget to specify the NetCon's delay and weight . . .
// next comes code to set up your vector of event times
objref syntimes
syntimes = new Vector()
 . . . fill syntimes with desired event times . . .
vs.pp.play(syntimes)
and every time you run a simulation the synaptic mechanism will be "pinged" at the desired times.

Once all of this is working in hoc, you can try implementing it in Python.
Post Reply