Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nodelist support different regions #2780

Merged
merged 18 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions share/lib/python/neuron/rxd/node.py
Original file line number Diff line number Diff line change
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):
ramcdougal marked this conversation as resolved.
Show resolved Hide resolved
"""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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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