Skip to content

Commit

Permalink
Nodelist support different regions (#2780)
Browse files Browse the repository at this point in the history
resolve #1280
  • Loading branch information
rgourdine committed May 8, 2024
1 parent cb09926 commit 2b040b7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions share/lib/python/neuron/rxd/node.py
Expand Up @@ -141,6 +141,16 @@ def satisfies(self, condition):
return self.region == condition
raise RxDException("selector %r not supported for this node type" % condition)

def _safe_satisfies(self, condition):
"""Tests if a Node satisfies a given condition.
Works the same as node.satisfies but replaces RxDException with False
"""
try:
return self.satisfies(condition)
except RxDException:
return False

@property
def _ref_concentration(self):
"""Returns a NEURON reference to the Node's concentration
Expand Down
2 changes: 1 addition & 1 deletion share/lib/python/neuron/rxd/nodelist.py
Expand Up @@ -17,7 +17,7 @@ def __init__(self, items):

def __call__(self, restriction):
"""returns a sub-NodeList consisting of nodes satisfying restriction"""
return NodeList([i for i in self if i.satisfies(restriction)])
return NodeList([i for i in self if i._safe_satisfies(restriction)])

def __getitem__(self, key):
if isinstance(key, slice):
Expand Down
10 changes: 10 additions & 0 deletions test/rxd/test_nodelist.py
Expand Up @@ -88,3 +88,13 @@ def test_only_nodes(neuron_instance):
assert len(nl) == 2
except TypeError:
raise Exception("should not get here")


def test_different_regions(neuron_nosave_instance):
h, rxd, _ = neuron_nosave_instance
sec = h.Section(name="sec")
cyt = rxd.Region(h.allsec())
ecs = rxd.Extracellular(-10, -10, -10, 10, 10, 10, dx=10)
k = rxd.Species([ecs, cyt], name="k", charge=1)
nd = k.nodes(sec)
assert abs(nd.x[0] - 0.5) < 1e-12

0 comments on commit 2b040b7

Please sign in to comment.