Skip to content

Commit

Permalink
Merge pull request #870 from StochSS/fix_869
Browse files Browse the repository at this point in the history
Fixing homo-dimer bimolecular propensity function
  • Loading branch information
seanebum authored Oct 5, 2022
2 parents cb08a9d + 6ffd93c commit 71cd8d1
Show file tree
Hide file tree
Showing 3 changed files with 251 additions and 3 deletions.
248 changes: 248 additions & 0 deletions examples/Advanced_Features/Bimolecular_reactions.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gillespy2/core/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _create_mass_action(self):
reactant = reactant.name
# Case 1: 2X -> Y
if stoichiometry == 2:
propensity_function = f"0.5 * {propensity_function} * {reactant} * ({reactant} - 1) / vol"
propensity_function = f"{propensity_function} * {reactant} * ({reactant} - 1) / vol"
ode_propensity_function += f" * {reactant} * {reactant}"
else:
# Case 3: X1, X2 -> Y;
Expand Down
4 changes: 2 additions & 2 deletions test/unit_tests/test_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def test__create_mass_action__2X_to_Y(self):
self.valid_ma_reaction.reactants = {"X": 2}
self.valid_ma_reaction.products = {"Y": 1}
self.valid_ma_reaction._create_mass_action()
self.assertEqual(self.valid_ma_reaction.propensity_function, "((((0.5*k1)*X)*(X-1))/vol)")
self.assertEqual(self.valid_ma_reaction.propensity_function, "(((k1*X)*(X-1))/vol)")
self.assertEqual(self.valid_ma_reaction.ode_propensity_function, "((k1*X)*X)")

def test__create_mass_action__species_obj_reactant(self):
Expand Down Expand Up @@ -536,7 +536,7 @@ def test_add_reactant__massaction_reaction_stoich_0_to_2(self):
self.valid_ma_reaction.add_reactant("X", 2)
self.assertIn("X", self.valid_ma_reaction.reactants)
self.assertEqual(self.valid_ma_reaction.reactants["X"], 2)
self.assertEqual(self.valid_ma_reaction.propensity_function, "((((0.5*k1)*X)*(X-1))/vol)")
self.assertEqual(self.valid_ma_reaction.propensity_function, "(((k1*X)*(X-1))/vol)")
self.assertEqual(self.valid_ma_reaction.ode_propensity_function, "((k1*X)*X)")

def test_add_reactant__invalid_species(self):
Expand Down

0 comments on commit 71cd8d1

Please sign in to comment.