I am just learning about NEURON so please bear with me.
I am looking for a way to keep references to segments and made the following observation,
which might be helpful to other Python programmers, as NEURON behaves different from
usual Python modules:
Code: Select all
soma = Section()
segments = soma.allseg()
As I am very stubborn, I then tried
Code: Select all
segments = [seg for seg in soma.allseg()]
to the same segment. This is probably because of the hoc concept of <currently accessed object>.
This time I tought I could trick Python + NEURON so typed:
Code: Select all
segments = soma.allseg
but this failed, revealing that allseg returns a reference to the section itself, which is in turn iterable,
but not subscriptable. I think it would be useful to be able to access the segments at will without having
to calculate the x value for it, so I came up with this final statement:
Code: Select all
from copy import copy
segments = [copy(seg) for seg in soma.allseg()]
Here is a sample code which will segfault on Python 2.6.5 and NEURON 7.1
Code: Select all
from neuron import *
from nrn import *
from copy import copy
soma = Section()
segments = [copy(seg) for seg in soma.allseg()]
vectors = []
for seg in segments:
vector = h.Vector()
vector.record(seg._ref_v)
vectors.append(vector)
the Pythonic feel of the bindings.
Regards
Bryan