Пример #1
0
    def __init__(self, parameter_values=None):
        Model.__init__(self, name="chapter2")
        self.volume = 1

        # Parameters
        self.add_parameter(Parameter(name="birth_A", expression="1"))
        self.add_parameter(Parameter(name="birth_B", expression="0.1"))
        self.add_parameter(Parameter(name="death_B", expression="0.05"))

        # Variables
        self.add_species(Species(name="A", initial_value=100, mode="discrete"))
        self.add_species(Species(name="B", initial_value=0, mode="discrete"))

        # Reactions
        self.add_reaction(
            Reaction(name="birthA",
                     reactants={},
                     products={'A': 1},
                     rate=self.listOfParameters["birth_A"]))
        self.add_reaction(
            Reaction(name="birthB",
                     reactants={'B': 1},
                     products={},
                     rate=self.listOfParameters["death_B"]))
        self.add_reaction(
            Reaction(name="birthC",
                     reactants={'A': 1},
                     products={'B': 1},
                     rate=self.listOfParameters["birth_B"]))

        # Timespan
        self.timespan(np.arange(0, 100, 1.0))
Пример #2
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=0.6))

        ## 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))
Пример #3
0
    def build_specie(self, args, is_ode):
        '''
        Build a GillesPy2 species.

        Atrributes
        ----------
        args : dict
            A json representation of a species.
        '''
        name = args['name'].strip()
        value = args['value']
        if not is_ode:
            mode = args['mode']
        else:
            mode = 'continuous'
        switch_tol = args['switchTol']
        if args['isSwitchTol']:
            switch_min = 0
        else:
            switch_min = args['switchMin']

        return Species(name=name,
                       initial_value=value,
                       mode=mode,
                       switch_tol=switch_tol,
                       switch_min=switch_min)
Пример #4
0
 def test__create_mass_action__species_obj_reactant(self):
     """ Test Reaction._create_mass_action when reactants is keyed by species object. """
     test_species = Species(name="A", initial_value=1)
     self.valid_ma_reaction.reactants = {test_species: 1}
     self.valid_ma_reaction._create_mass_action()
     self.assertEqual(self.valid_ma_reaction.propensity_function, "(k1*A)")
     self.assertEqual(self.valid_ma_reaction.ode_propensity_function,
                      "(k1*A)")
Пример #5
0
 def test_constructor__products_keyed_by_species_obj(self):
     """ Test the Reaction constructor with products keyed by species objs. """
     test_species = Species(name="B", initial_value=0)
     reaction = Reaction(name="test_reaction",
                         reactants={"A": 1},
                         products={test_species: 1},
                         rate="k2")
     self.assertEqual(reaction.products, {"B": 1})
Пример #6
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)")
Пример #7
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})")
Пример #8
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)
Пример #9
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)