## Patch to geometry.py

Extending NEURON to handle reaction-diffusion problems.

Moderators: hines, wwlytton, ramcdougal

davidsterratt
Posts: 28
Joined: Tue Jan 17, 2006 11:36 am

### Patch to geometry.py

While I've been working on integrating the SpatialKappa rule-based simulator into NEURON (see work in progress at https://github.com/davidcsterratt/KappaNEURON), I've discovered what I think is a bug in share/lib/python/neuron/rxd/geometry.py . The patch below makes all functions in this file treat the sec argument in the same way:

Code: Select all

``````--- a/share/lib/python/neuron/rxd/geometry.py	Wed Sep 10 08:40:55 2014 +0200
+++ b/share/lib/python/neuron/rxd/geometry.py	Tue Sep 23 16:12:12 2014 +0100
@@ -20,10 +20,12 @@

def _volumes1d(sec):
-    arc3d = [h.arc3d(i, sec=sec._sec)
-             for i in xrange(int(h.n3d(sec=sec._sec)))]
-    diam3d = [h.diam3d(i, sec=sec._sec)
-              for i in xrange(int(h.n3d(sec=sec._sec)))]
+    if not isinstance(sec, nrn.Section):
+        sec = sec._sec
+    arc3d = [h.arc3d(i, sec=sec)
+             for i in xrange(int(h.n3d(sec=sec)))]
+    diam3d = [h.diam3d(i, sec=sec)
+              for i in xrange(int(h.n3d(sec=sec)))]
vols = numpy.zeros(sec.nseg)
dx = sec.L / sec.nseg
for iseg in xrange(sec.nseg):
@@ -89,10 +91,12 @@
_perimeter1d = _make_perimeter_function(numpy.pi)

def _neighbor_areas1d(sec):
-    arc3d = [h.arc3d(i, sec=sec._sec)
-             for i in xrange(int(h.n3d(sec=sec._sec)))]
-    diam3d = [h.diam3d(i, sec=sec._sec)
-              for i in xrange(int(h.n3d(sec=sec._sec)))]
+    if not isinstance(sec, nrn.Section):
+        sec = sec._sec
+    arc3d = [h.arc3d(i, sec=sec)
+             for i in xrange(int(h.n3d(sec=sec)))]
+    diam3d = [h.diam3d(i, sec=sec)
+              for i in xrange(int(h.n3d(sec=sec)))]
area_pos = numpy.linspace(0, sec.L, sec.nseg + 1)
diams = numpy.interp(area_pos, arc3d, diam3d)
return numpy.pi * 0.25 * diams ** 2
@@ -262,10 +266,12 @@
return 'Shell(lo=%r, hi=%r)' % (self._lo, self._hi)

def neighbor_areas1d(self, sec):
-        arc3d = [h.arc3d(i, sec=sec._sec)
-                 for i in xrange(int(h.n3d(sec=sec._sec)))]
-        diam3d = [h.diam3d(i, sec=sec._sec)
-                  for i in xrange(int(h.n3d(sec=sec._sec)))]
+        if not isinstance(sec, nrn.Section):
+            sec = sec._sec
+        arc3d = [h.arc3d(i, sec=sec)
+                 for i in xrange(int(h.n3d(sec=sec)))]
+        diam3d = [h.diam3d(i, sec=sec)
+                  for i in xrange(int(h.n3d(sec=sec)))]
area_pos = numpy.linspace(0, sec.L, sec.nseg + 1)
diams = numpy.interp(area_pos, arc3d, diam3d)
if self._type == _lo_hi_shell:
@@ -275,10 +281,12 @@
def is_area(self): return False

def volumes1d(self, sec):
-        arc3d = [h.arc3d(i, sec=sec._sec)
-                 for i in xrange(int(h.n3d(sec=sec._sec)))]
-        diam3d = [h.diam3d(i, sec=sec._sec)
-                  for i in xrange(int(h.n3d(sec=sec._sec)))]
+        if not isinstance(sec, nrn.Section):
+            sec = sec._sec
+        arc3d = [h.arc3d(i, sec=sec)
+                 for i in xrange(int(h.n3d(sec=sec)))]
+        diam3d = [h.diam3d(i, sec=sec)
+                  for i in xrange(int(h.n3d(sec=sec)))]
vols = numpy.zeros(sec.nseg)
dx = sec.L / sec.nseg
for iseg in xrange(sec.nseg):
``````
ramcdougal
Posts: 214
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

### Re: Patch to geometry.py

Thanks. That change makes the API more consistent.

I've added it to my development version of the code.
davidsterratt
Posts: 28
Joined: Tue Jan 17, 2006 11:36 am

### Re: Patch to geometry.py

Glad you like the change and thanks for putting it in your development version.

I've tried pulling the NEURON code, but there seem to be no changes coming through, so I was wondering when the change might make the main NEURON repo? If not in the next few days, I'll need to supply potential testers of my package with the patch to NEURON.
ramcdougal
Posts: 214
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

### Re: Patch to geometry.py

The main repository now includes your patch. Thanks again.