Finding netcon-s from python

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

Moderator: hines

Post Reply
uri.cohen
Posts: 24
Joined: Wed Jul 20, 2011 9:14 am

Finding netcon-s from python

Post by uri.cohen » Tue Mar 20, 2012 5:43 am

I have a hoc file which setups some simulation and I load it and run it from python.
I would like to record event times in a simulation from python. My problem is that the NetCon objects are setup in the hoc file, and I need to find them from python in order to record from them.

Are those objects somehow accessible from python? I found I can access a segment's point processes (synaptic inputs) through the seg.point_processes() method, but it does not contains the NetCon which feed them.

Alternatively, is there a way to record the input times from synapses? I have the usual (I think) exp2syn.mod synapses.
Thanks!

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

Re: Finding netcon-s from python

Post by ted » Tue Mar 20, 2012 10:09 am

uri.cohen wrote:I have a hoc file which setups some simulation and I load it and run it from python.
I would like to record event times in a simulation from python. My problem is that the NetCon objects are setup in the hoc file, and I need to find them from python in order to record from them.
Does your hoc program set up a List to which all NetCons are appended? Lists are the most convenient way to manage collections of objects, whether you are using hoc or Python.
Are those objects somehow accessible from python?
All hoc variables and objects are accessible from Python and vice versa. Have you read the Programmer's Reference entries on Python?
is there a way to record the input times from synapses?
The NetCon class's record() method is used to record source event times to a Vector. Read about it in the documentation of the NetCon class.

uri.cohen
Posts: 24
Joined: Wed Jul 20, 2011 9:14 am

Re: Finding netcon-s from python

Post by uri.cohen » Tue Mar 20, 2012 10:16 am

Does your hoc program set up a List to which all NetCons are appended?
Yes.
All hoc variables and objects are accessible from Python and vice versa.
This is exactly the part I could not find how to do.
The NetCon class's record() method is used to record source event times to a Vector.
Ok, so this is what I want to do.

To narrow down my question after your clarifications from above, how do I access from python the collection of NetCon-s which I have assigned from hoc?
Thanks!

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

Re: Finding netcon-s from python

Post by ted » Tue Mar 20, 2012 11:59 pm

You'll want to read the documentation of Python_accessing_Hoc
http://www.neuron.yale.edu/neuron/stati ... essing_Hoc
and in particular about HocObject
http://www.neuron.yale.edu/neuron/stati ... #HocObject
I'm not a big "NEURON + Python" maven, but from this it looks to me like
import neuron
h = neuron.hoc.HocObject()
should let you access a hoc List called nclist like this:
h.nclist.count()
should return the number of elements in nclist
and
h.nclist.o(i)
should allow you to access the i+1th element in nclist.

I'd try all this on a toy program if I were you, maybe something like this:

Code: Select all

create soma
access soma
objref nclist, nil
nclist = new List()
for i=0,3 nclist.append(new NetCon(&v(0.5), nil))
Make sure that NEURON can execute this toy program without complaint. It creates a List called nclist that contains 4 NetCons. Verify that they exist by executing these commands at the oc> prompt:

Code: Select all

nclist.count()
for i=0,nclist.count()-1 print nclist.o(i) // should print NetCon[0] . . . NetCon[3]
Then exit NEURON, and restart NEURON with Python as its interpreter, then get it to execute the toy program file, and finally check out accessing nclist from Python.

uri.cohen
Posts: 24
Joined: Wed Jul 20, 2011 9:14 am

Re: Finding netcon-s from python

Post by uri.cohen » Wed Mar 21, 2012 5:33 am

Thank you, this is what I needed and I missed it in the documentation.

Your example works for List objects ("new List()") but not for arrays, defined in hoc as:

Code: Select all

objref netconExc[EXCTOTALSYNAPSES]
In case someone will look at this post, for such objects the access is done using:

Code: Select all

import neuron
print len(neuron.h.netconExc) # prints length
for nc in neuron.h.netconExc:
  print nc.hname() # prints NetCon[id]
Thanks again.

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

Re: Finding netcon-s from python

Post by ted » Wed Mar 21, 2012 9:26 pm

Too bad you have to work with code that uses "arrays" of objrefs. Lists are far better for managing collections of objects.

Post Reply