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!
Finding netcon-s from python
Moderator: hines
-
- Site Admin
- Posts: 6289
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Finding netcon-s from python
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.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.
All hoc variables and objects are accessible from Python and vice versa. Have you read the Programmer's Reference entries on Python?Are those objects somehow accessible from python?
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.is there a way to record the input times from synapses?
Re: Finding netcon-s from python
Yes.Does your hoc program set up a List to which all NetCons are appended?
This is exactly the part I could not find how to do.All hoc variables and objects are accessible from Python and vice versa.
Ok, so this is what I want to do.The NetCon class's record() method is used to record source event times to a Vector.
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!
-
- Site Admin
- Posts: 6289
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Finding netcon-s from python
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: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:
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.
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))
Code: Select all
nclist.count()
for i=0,nclist.count()-1 print nclist.o(i) // should print NetCon[0] . . . NetCon[3]
Re: Finding netcon-s from python
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:
In case someone will look at this post, for such objects the access is done using:
Thanks again.
Your example works for List objects ("new List()") but not for arrays, defined in hoc as:
Code: Select all
objref netconExc[EXCTOTALSYNAPSES]
Code: Select all
import neuron
print len(neuron.h.netconExc) # prints length
for nc in neuron.h.netconExc:
print nc.hname() # prints NetCon[id]
-
- Site Admin
- Posts: 6289
- Joined: Wed May 18, 2005 4:50 pm
- Location: Yale University School of Medicine
- Contact:
Re: Finding netcon-s from python
Too bad you have to work with code that uses "arrays" of objrefs. Lists are far better for managing collections of objects.