Skip to content

Commit

Permalink
Adding bounds attribute to reaction (#281)
Browse files Browse the repository at this point in the history
This PR adds a `bounds` attribute to `cobra.Reaction`, which allows
bounds to be checked and changed with a single line:

```
model.reactions.PGI.bounds = (0, 1000)
```

```
>>> model.reactions.PGI.bounds
(0, 1000)
```
  • Loading branch information
pstjohn authored and hredestig committed Sep 22, 2016
1 parent f00ec0a commit 9e2cd8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cobra/core/Reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,20 @@ def x(self):
raise Exception("model solution was not optimal")
raise e # Not sure what the exact problem was

@property
def bounds(self):
""" A more convienient bounds structure than seperate upper and lower
bounds """

return (self.lower_bound, self.upper_bound)

@bounds.setter
def bounds(self, value):
""" Set the bounds directly from a tuple """

self.lower_bound = value[0]
self.upper_bound = value[1]

@property
def reversibility(self):
"""Whether the reaction can proceed in both directions (reversible)
Expand Down
3 changes: 3 additions & 0 deletions cobra/test/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@ def test_build_from_string(self):
pgi = model.reactions.get_by_id("PGI")
pgi.reaction = "g6p_c --> f6p_c"
self.assertEqual(pgi.lower_bound, 0)
pgi.bounds = (0, 1000)
self.assertEqual(pgi.bounds, (0, 1000))
self.assertEqual(pgi.reversibility, False)
pgi.reaction = "g6p_c <== f6p_c"
self.assertEqual(pgi.upper_bound, 0)
self.assertEqual(pgi.reaction.strip(), "g6p_c <-- f6p_c")
Expand Down

0 comments on commit 9e2cd8b

Please sign in to comment.