Skip to content
Permalink
Browse files

Fix multi-bonds in _as_graph

  • Loading branch information...
alubbock committed Apr 11, 2019
1 parent cb22e2a commit 6b04d3ba57131a727ade7128e1e0ff30b06a1ee9
Showing with 23 additions and 2 deletions.
  1. +5 −1 pysb/core.py
  2. +3 −0 pysb/generator/kappa.py
  3. +15 −1 pysb/tests/test_core.py
@@ -481,6 +481,7 @@ class MonomerPattern(object):
* *tuple of (str, int)* : state with specified bond
* *tuple of (str, WILD)* : state with wildcard bond
* *tuple of (str, ANY)* : state with any bond
* MultiSite : duplicate sites
If a site is not listed in site_conditions then the pattern will match any
state for that site, i.e. \"don't write, don't care\".
@@ -806,7 +807,7 @@ def _handle_site_instance(state_or_bond):
elif is_state_bond_tuple(state_or_bond):
state = state_or_bond[0]
bond_num = state_or_bond[1]
elif isinstance(state_or_bond, int):
elif isinstance(state_or_bond, (int, list)):
bond_num = state_or_bond
elif state_or_bond is not ANY and state_or_bond is not None:
raise ValueError('Unrecognized state: {}'.format(
@@ -827,6 +828,9 @@ def _handle_site_instance(state_or_bond):
bond_edges[NO_BOND].append(mon_site_id)
elif isinstance(bond_num, int):
bond_edges[bond_num].append(mon_site_id)
elif isinstance(bond_num, list):
for bond in bond_num:
bond_edges[bond].append(mon_site_id)

for mp in self.monomer_patterns:
mon_node_id = next(node_count)
@@ -196,6 +196,9 @@ def format_site_condition(self, site, state, mon_name):
# If there is a bond number
elif isinstance(state, int):
state_code = '[%s]' % state
# Multi-bond (list of bonds)
elif isinstance(state, list):
raise KappaException("Kappa generator does not support multi-bonds")
# If there is a MultiBond, raise an Exception (not supported by Kappa)
elif isinstance(state, pysb.MultiSite):
raise KappaException("Kappa generator does not support MultiSites.")
@@ -379,6 +379,17 @@ def test_rulepattern_match_none_against_state():
A(phospho=None) + A(phospho=None) >> A(phospho=1) % A(phospho=1)


@with_model
def test_multi_bonds():
Monomer('A', ['a'])
a_pat = A(a=[1, 2])

# Check _as_graph() works for multi-bonds
a_pat._as_graph()

assert a_pat.is_concrete()


@with_model
def test_duplicate_sites():
Monomer('A', ['a', 'a'])
@@ -403,4 +414,7 @@ def test_duplicate_sites():
assert_raises(ValueError, B, b=['u', 'p'])

# Syntax error (can't nest MultiSite)
assert_raises(ValueError, MultiSite, MultiSite(1, 2), 'p')
assert_raises(ValueError, MultiSite, MultiSite(1, 2), 'p')

# Duplicate sites with multi-bond
A(a=MultiSite([1, 2], [1, 2]))

0 comments on commit 6b04d3b

Please sign in to comment.
You can’t perform that action at this time.