append sections to sectionlist

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

Moderator: hines

Post Reply
ioannisv

append sections to sectionlist

Post by ioannisv »

Hi

I have the following code and it crashes if I have a big number in _axonnodes(around 80)
I have read the forum that there is a stack size limit.
I didn't really figure out though if we can change the stack size or if there is another way of append in the SectionLists
Since I am using h.pop_section() shouldn't the stack size not be a problem?

Code: Select all

from neuron import h


#----------Defining variables in python environment	
_D = 20										# Fiber diameter [um]
_d = 0.7*_D									# Axon diameter at node [um]
_w = 2.5									# Nodal gap [um]
_rhol = 100									# Axoplasmic resistivity [ohm*cm]
_rhoe = 300									# External medium resistivity [ohm*cm]
_cm = 2										# Membrane capacity [uF/(cm*cm)]
_gm = 0.0304								# Membrane conductivity [S/(cm*cm)]
_Li = 100*_D								# Internodal distance [um]
_dEl = 2000									# Radial distance to longitudinally centered electrode [um]
_axonnodes = 100#int(math.floor(_lAx/_Li)-1)		# Number of unmyelinated axon nodes  				
_axoninter = _axonnodes+1	# Number of myelinated axon inter-nodes

#-----------Defining variables in hoc environment
h('_D = 20')								# Fiber diameter [um]
h('_d = 0.7*_D')							# Axon diameter at node [um]
h('_w = 2.5')								# Nodal gap [um]
h('_rhol = 100')							# Axoplasmic resistivity [ohm*cm]
h('_rhoe = 300')							# External medium resistivity [ohm*cm]
h('_cm = 2')								# Membrane capacity [uF/(cm*cm)]
h('_gm = 0.0304')							# Membrane conductivity [S/(cm*cm)]
h('_Li = 100*_D')							# Internodal distance [um]
h('_dEl = 2000')							# Radial distance to longitudinally centered electrode [um]
h('_lAx = 10*_dEl')							# Total length of modeled axon [um]		
h('_axoninter = _axonnodes+1')				# Number of myelinated axon inter-nodes


h('create node[_axonnodes]')
h('create internode[_axoninter]')
h('access node[0]')
h.nrn_load_dll("C:/Users/Ioannis/Desktop/SENN - nrn7.3/nrnmech.dll")

SubsetAll = h.SectionList()
SubsetNodes = h.SectionList()
SubsetInternodes = h.SectionList()

def celldef():
  topol()
  subsets()
  geom()
  biophys()
  geom_nseg()

def  topol():
	print "topol"
	for i in range(_axonnodes):
		h.node[i].connect(h.internode[i],1,0)
		h.internode[i+1].connect(h.node[i],1,0)
	basic_shape()

def subsets():
	print "subsets"
	for i in range(_axonnodes):
		print i
		SubsetAll.append(h.node[i].push())
		h.pop_section()
		SubsetAll.append(h.internode[i].push())
		h.pop_section()
	SubsetAll.append(h.internode[_axoninter-1].push())
	h.pop_section()
	
	for i in range(_axonnodes):
		SubsetNodes.append(h.node[i].push())
		h.pop_section()
	
	for i in range(_axoninter):
		SubsetInternodes.append(h.internode[i].push())
		h.pop_section()
		
def basic_shape():
	x = -0.5*(_axoninter*_Li - _w)
	y = _dEl
	z = 0
	for i in range(_axonnodes):
		h.internode[i].push()
		h.pt3dclear()
		h.pt3dadd(x, y, z, _d)
		x = x + _Li - _w
		h.pt3dadd(x, y, z, _d)
		h.pop_section()
		h.node[i].push()
		h.pt3dclear()
		h.pt3dadd(x, y, z, _d)
		x = x + _w
		h.pt3dadd(x, y, z, _d)
		h.pop_section()
	h.internode[_axonnodes].push()
	h.pt3dclear()
	h.pt3dadd(x, y, z, _d)
	x = x + _Li - _w
	h.pt3dadd(x, y, z, _d)
	h.pop_section
	
def biophys():
	for sec in SubsetAll:
		sec.insert('extracellular')
		sec.push()
		h('xraxial[0] = 1e+09')
		h('xraxial[1] = 1e+09')
		h('xg = 1e+09')
		h('xc = 0')
		h('e_extracellular = 0')
		h.pop_section

		
	for sec in SubsetNodes:
		sec.cm = _cm
		sec.Ra = _rhol
		sec.insert('fh')
		sec.push()
		h('nai = 13.74')
		h('nao = 114.5')
		h('ki = 120')
		h('ko = 2.5')
		h('celsius = 22.01')
		h.pop_section
		
	for sec in SubsetInternodes:
		sec.cm = 0
		sec.Ra = _rhol

def geom_nseg():
	for sec in SubsetAll:
		sec.nseg = 1
	
		
def geom():
	1


h('access node[0]')
celldef()
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: append sections to sectionlist

Post by ted »

The first error message I see is

Code: Select all

/usr/local/nrn/i686/bin/nrniv: undefined variable _axonnodes
 near line 0
 _axoninter = _axonnodes+1
                          ^
which is generated in response to the statement

Code: Select all

h('_axoninter = _axonnodes+1')
probably because _axonnodes was defined in Python, not in hoc.
ioannisv

Re: append sections to sectionlist

Post by ioannisv »

yes you are right
I accidentaly deleted a line just above that
there should be a line just above the line you posted

Code: Select all

h('_axonnodes = 80')
h('_axoninter = _axonnodes+1')
However the stack overflow is still present
ted
Site Admin
Posts: 6300
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: append sections to sectionlist

Post by ted »

You're too close to the code to see the causes of the problem.

First, there are several points at which you push a section onto the stack when it isn't necessary.

Code: Select all

for sec in SubsetAll:
  . . . statements . . .
iterates over all the sections in SubsetAll. On the first pass through this loop, the first section in SubsetAll becomes the currently accessed section. On the second pass, the second section in SubsetsAll is the currently accessed section. etc. There's no need for the sec.push() in this bit of code:

Code: Select all

for sec in SubsetAll:
  sec.insert('extracellular')
  sec.push()
  . . . other statements . . .
If you want to verify this, just insert a couple of
print h.secname()
statements in the loop and see for yourself. Eliminate the unneeded sec.push() statements, and your code will be almost fixed.
Since I am using h.pop_section()
Sometimes you do, and sometimes you don't. h.pop_section() pops a section from the stack, h.pop_section does not. When you fix this problem, remember that you only need to pop_section() if you have already executed sec.push()--there is no need to do pop_section() at the end of a

Code: Select all

forsec in SomeSubset:
  . . . code . . .
if the ". . . code . . ." inside the loop doesn't contain a sec.push() statement. And I can't think of a reason to do sec.push() inside a forsec loop, because that merely pushes the currently accessed section onto the stack _again_, and why would that be useful?
Post Reply