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

Duplicate sites support #410

Merged
merged 10 commits into from May 10, 2019

Fix multi-bonds in _as_graph

  • Loading branch information...
alubbock committed Apr 11, 2019
commit 6b04d3ba57131a727ade7128e1e0ff30b06a1ee9
@@ -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]))
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.