Exemplo n.º 1
0
 def test_constructor__reactants_keyed_by_species_obj(self):
     """ Test the Reaction constructor with reactants keyed by species objs. """
     test_species = Species(name="A", initial_value=0)
     reaction = Reaction(name="test_reaction",
                         reactants={test_species: 1},
                         products={"B": 1},
                         rate="k2")
     self.assertEqual(reaction.reactants, {"A": 1})
Exemplo n.º 2
0
 def test_add_reactant__customized_reaction_species_object(self):
     """ Test Reaction.add_reactant when reaction is customized and species is GillesPy2.Species. """
     test_species = Species(name="X", initial_value=1)
     self.valid_cp_reaction.add_reactant(test_species, 1)
     self.assertIn(test_species.name, self.valid_cp_reaction.reactants)
     self.assertEqual(self.valid_cp_reaction.reactants[test_species.name],
                      1)
     self.assertEqual(self.valid_cp_reaction.propensity_function, "(k1*A)")
     self.assertEqual(self.valid_cp_reaction.ode_propensity_function,
                      "(k1*A)")
Exemplo n.º 3
0
 def test_add_reactant__massaction_reaction_species_object(self):
     """ Test Reaction.add_reactant when reaction is mass-action and species is GillesPy2.Species. """
     test_species = Species(name="X", initial_value=1)
     self.valid_ma_reaction.add_reactant(test_species, 1)
     self.assertIn(test_species.name, self.valid_ma_reaction.reactants)
     self.assertEqual(self.valid_ma_reaction.reactants[test_species.name],
                      1)
     self.assertEqual(self.valid_ma_reaction.propensity_function,
                      f"(((k1*A)*{test_species.name})/vol)")
     self.assertEqual(self.valid_ma_reaction.ode_propensity_function,
                      f"((k1*A)*{test_species.name})")
Exemplo n.º 4
0
    def __init__(self, parameter_values=None):
        Model.__init__(self, name="lotka_volterra")
        self.volume = 1

        # Parameters
        self.add_parameter(Parameter(name="k1", expression=1.0))
        self.add_parameter(Parameter(name="k2", expression=0.005))
        self.add_parameter(Parameter(name="k3", expression=1.0))

        # Species
        self.add_species(Species(name='prey', initial_value = 100, mode = 'discrete'))
        self.add_species(Species(name='predator', initial_value = 100, mode = 'discrete'))
        
        # Reactions
        self.add_reaction(Reaction(name="r1", reactants = {'prey' : 1}, products = {'prey' : 2}, rate = self.listOfParameters['k1']))
        self.add_reaction(Reaction(name="r2", reactants = {'predator' : 1, 'prey' : 1}, products = {'predator' : 2}, rate = self.listOfParameters['k2']))
        self.add_reaction(Reaction(name="r3", reactants = {'predator' : 1}, products = {}, rate = self.listOfParameters['k3']))

        # Timespan
        self.timespan(np.linspace(0, 50, 51))
Exemplo n.º 5
0
 def test_model_add__species(self):
     from gillespy2 import Species
     s3 = Species(name="s3", initial_value=29)
     self.model.add(s3)
     self.assertIn("s3", self.model.listOfSpecies)
Exemplo n.º 6
0
 def test_add_product__species_object(self):
     """ Test Reaction.add_product when species is GillesPy2.Species. """
     test_species = Species(name="X", initial_value=1)
     self.valid_ma_reaction.add_product(test_species, 1)
     self.assertIn(test_species.name, self.valid_ma_reaction.products)
     self.assertEqual(self.valid_ma_reaction.products[test_species.name], 1)