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

Updated rxd reactions to allow pure backward reactions. #3273

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion share/lib/python/neuron/rxd/generalizedReaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def get_scheme_rate1_rate2_regions_custom_dynamics_mass_action(args, kwargs):
rate1 = args[1]
rate2 = args[2]
else:
scheme = args[0] > args[1]
scheme = args[0].__gt__(args[1])
# don't use '>' to avoid Python prioritizing subclass methods
rate1 = args[2]
rate2 = None
elif len(args) == 2:
Expand Down
21 changes: 6 additions & 15 deletions share/lib/python/neuron/rxd/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,18 @@ def _do_init(self):
def _update_rates(self):
lhs = self._scheme._lhs._items
rhs = self._scheme._rhs._items
if self._dir == "<":
# TODO: remove this limitation (probably means doing with rate_b what done with rate_f and making sure _sources and _dests are correct
raise RxDException(
"pure reverse reaction currently not supported; reformulate as a forward reaction"
)

rate_f = rxdmath._ensure_arithmeticed(self._original_rate_f)
rate_b = rxdmath._ensure_arithmeticed(self._original_rate_b)

if not self._custom_dynamics:
for k, v in zip(list(lhs.keys()), list(lhs.values())):
if v == 1:
rate_f *= k
else:
rate_f *= k**v
if self._dir == "<>":
if ">" in self._dir:
for k, v in lhs.items():
rate_f *= k if v == 1 else k**v
if "<" in self._dir:
for k, v in rhs.items():
if v == 1:
rate_b *= k
else:
rate_b *= k**v
rate_b *= k if v == 1 else k**v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this change? If this is just a cleanup, can we move this and any other cleanups into a second, later PR? The idea being to keep it clear what changes exist to address the backward reaction issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need this change. I removed some of the unnecessary formatting changes to generalizedReaction.py.


rate = rate_f - rate_b
self._rate_arithmeticed = rate

Expand Down
19 changes: 19 additions & 0 deletions test/rxd/test_state_reaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from .testutils import compare_data, tol


def test_state_reaction(neuron_instance):
"""Test a simple rxd.Reaction involving a rxd.State"""
h, rxd, data, save_path = neuron_instance
sec = h.Section(name="sec")
cyt = rxd.Region([sec], name="cyt", nrn_region="i")
ca = rxd.Species(cyt, name="ca", charge=2, initial=0.001)
cabuf = rxd.State(cyt, name="cabuf", initial=0)
# buffering = rxd.Reaction(ca, cabuf, 0.02)
# generated the test data with a forward reaction
buffering = rxd.Reaction(cabuf < ca, 0.02)
h.finitialize(-65)
h.continuerun(10)
if not save_path:
max_err = compare_data(data)
assert max_err < tol
2 changes: 1 addition & 1 deletion test/rxd/testdata
Loading