section, segment, mechanism, rangevariable.
Code: Select all
[hines@NeuronDev nrnpy]$ cat demo.py
from section import *
soma = Section()
print soma
soma.insert(hh)
for seg in soma :
print seg
for m in seg :
print m
for rv in m :
print rv
soma.nseg = 5
soma.insert(hh)
for seg in soma :
seg.diam = 2 + 3*seg.x
seg.hh.gnabar = seg.diam * 2
for x in [.1, .5, .9] :
print x, soma(x).x, soma(x).diam, soma(x).hh.gnabar
Code: Select all
[hines@NeuronDev nrnpy]$ python demo.py
hello
create Section
<section.Section instance at 0xb7cc8c6c>
<section.Segment instance at 0xb7cc8eac>
<section.hh instance at 0xb7cc8f0c>
('gnabar', 0.12)
('gkbar', 0.035999999999999997)
0.1 0.1 2.3 4.6
0.5 0.5 3.5 7.0
0.9 0.9 4.7 9.4
[hines@NeuronDev nrnpy]$
Code: Select all
[hines@NeuronDev nrnpy]$ cat section.py
class Section :
def __init__(self) :
self.change_nseg(1)
self.L = 100
print "create Section"
def __iter__(self) :
for x in self.segments :
yield x
def __call__(self, x) :
i = int(x*self.nseg - .5)
return self.segments[i]
def __setattr__(self, attr, value) :
if attr == 'nseg' :
self.change_nseg(value)
else :
self.__dict__[attr] = value
def change_nseg(self, value) :
s = []
self.__dict__['segments'] = s
self.__dict__['nseg'] = value
for i in range(value) :
x = (i+.5)/value
s.append(Segment(x))
def insert(self, mechtype) :
for s in self.segments :
s.insert(mechtype)
class Segment :
def __init__(self, pos) :
self.x = pos
self.v = -65.
self.diam = 10.
self.c = 1.
self.mechs = {}
def __iter__(self) :
for x in self.mechs :
yield self.mechs[x]
def insert(self, mechtype) :
m = mechtype()
self.mechs[m.name] = m
def __getattr__(self, attr) :
if attr in self.mechs :
return self.mechs[attr]
else :
raise AttributeError, attr
class Mechanism :
def __init__(self) :
self.rvs = {}
def __iter__(self) :
for x in self.rvs :
yield (x, self.rvs[x])
class hh(Mechanism) :
name = 'hh'
def __init__(self) :
self.rvs = {'gnabar':0.12, 'gkbar':0.036}
def __setattr__(self, attr, value) :
if (attr == 'rvs') :
self.__dict__[attr] = value
elif attr in self.__dict__['rvs'] :
self.__dict__['rvs'][attr] = value
else :
raise AttributeError, attr + ' not allowed'
def __getattr__(self, attr) :
if attr in self.rvs :
return self.rvs[attr]
else :
raise AttributeError, attr
print "hello"
[hines@NeuronDev nrnpy]$