コード例 #1
0
def test_massaction_from_parameters():
    mak = MassAction(k_forward=ParameterEntry("k", .1))
    assert mak.k_forward == .1

    mak = MassAction(k_forward=ParameterEntry("k", .1),
                     k_reverse=ParameterEntry("k", .01))
    assert mak.k_reverse == .01
コード例 #2
0
def test_massaction_forward_rate():

    with pytest.raises(ValueError, match=r"Propensity parameters must be Parameters or floats with positive values.*"):
        MassAction(k_forward=0)

    with pytest.raises(ValueError, match=r"Propensity parameters must be Parameters or floats with positive values.*"):
        MassAction(k_forward=-1)
コード例 #3
0
def test_massaction_reserve_rate():
    with pytest.raises(TypeError, match=r"missing 1 required positional argument: 'k_forward'"):
        MassAction(k_reverse=0.1)

    with pytest.raises(ValueError, match=r"Propensity parameters must be Parameters or floats with positive values.*"):
        MassAction(k_forward=1, k_reverse=0)

    with pytest.raises(ValueError, match=r"Propensity parameters must be Parameters or floats with positive values.*"):
        MassAction(k_forward=1, k_reverse=-1)
コード例 #4
0
def test_reaction_equality():
    """test for the_equality operator"""
    sp1 = Species(name='test_species_a')
    sp2 = Species(name='test_species_b')
    rxn1 = Reaction(inputs=[sp1, sp2], outputs=[sp2, sp2], propensity_type=MassAction(k_forward=1))
    rxn2 = Reaction(inputs=[sp2, sp1], outputs=[sp2, sp2], propensity_type=MassAction(k_forward=1))
    rxn3 = Reaction(inputs=[sp2, sp1], outputs=[sp2, sp2], propensity_type=MassAction(k_forward=10))
    rxn4 = Reaction(inputs=[sp2, sp1], outputs=[sp2], propensity_type=MassAction(k_forward=1))
    assert rxn1 == rxn2
    assert rxn1 != rxn3
    assert rxn1 != rxn4
コード例 #5
0
def test_species_merging():
    sp1 = Species(name='test_species_a')
    chem_complexes = [WeightedSpecies(species=sp1, stoichiometry=2),
                      WeightedSpecies(species=sp1, stoichiometry=1)]
    rxn = Reaction(inputs=chem_complexes, outputs=[], propensity_type=MassAction(k_forward=1))
    # same species with different stoichiometry gets merged into one species
    assert len(rxn.inputs) == 1

    sp1 = Species(name='test_species_a')
    chem_complexes = [WeightedSpecies(species=sp1, stoichiometry=2),
                      WeightedSpecies(species=sp1, stoichiometry=1)]
    rxn = Reaction(inputs=[], outputs=chem_complexes, propensity_type=MassAction(k_forward=1))

    # same species with different stoichiometry gets merged into one species
    assert len(rxn.outputs) == 1
コード例 #6
0
def test_reaction_list_flattening():
    sp1 = Species(name='test_species_a')
    sp2 = Species(name='test_species_b')
    k_f = 1
    mak = MassAction(k_forward=k_f)
    rxn1 = Reaction(inputs=[sp1, [sp1, sp2]], outputs=[[sp2, sp2], sp1], propensity_type=mak)
    rxn2 = Reaction(inputs=[sp1, sp1, sp2], outputs=[sp1, sp2, sp2], propensity_type=mak)
    assert rxn1 == rxn2
コード例 #7
0
def test_propensity_dict_massaction():
    k1 = ParameterEntry(parameter_value='1', parameter_name='k1')
    k2 = ParameterEntry(parameter_value='2', parameter_name='k2')

    #Should store the ParameterEntry in this case
    P1 = MassAction(k_forward=k1, k_reverse=k2)
    assert P1.propensity_dict["parameters"]["k_forward"] == k1
    assert P1.propensity_dict["parameters"]["k_reverse"] == k2

    #assert getters work (should return values instead of ParameterEntries)
    assert P1.k_forward == k1.value
    assert P1.k_reverse == k2.value

    #Should store a numerical value in this case
    P2 = MassAction(k_forward=k1.value, k_reverse=k2.value)
    assert P2.propensity_dict["parameters"]["k_forward"] == k1.value
    assert P2.propensity_dict["parameters"]["k_reverse"] == k2.value

    #assert getters work
    assert P2.k_forward == k1.value
    assert P2.k_reverse == k2.value
コード例 #8
0
    def test_reaction_initialization(self):
        # warns if both input and output species are empty
        mak = MassAction(k_forward=0.1)
        with self.assertWarns(Warning):
            Reaction(inputs=[], outputs=[], propensity_type=mak)

        # test for invalid propensity type
        with self.assertRaises(ValueError):
            Reaction(inputs=[], outputs=[], propensity_type=Species)

        # input must be a valid species object
        with self.assertRaises(TypeError):
            Reaction(inputs=['a'], outputs=[], propensity_type=mak)
        # output must be a valid species object
        with self.assertRaises(TypeError):
            Reaction(inputs=[], outputs=['b'], propensity_type=mak)

        rxn = Reaction.from_massaction(inputs=[], outputs=[], k_forward=0.1, k_reverse=1)
        # test whether the reaction is registered as reversible
        self.assertTrue(rxn.is_reversible)
        # test whether the reaction is registered as massaction
        self.assertTrue(isinstance(rxn.propensity_type, MassAction))

        # test WeightedSpecies inputs
        sp1 = Species(name='test_species_a')
        sp2 = Species(name='test_species_b')
        chem_com_sp1 = WeightedSpecies(species=sp1, stoichiometry=2)
        chem_com_sp2 = WeightedSpecies(species=sp2, stoichiometry=1)
        Reaction(inputs=[chem_com_sp1], outputs=[chem_com_sp2], propensity_type=MassAction(k_forward=1))

        # test different input and output lists
        Reaction(inputs=[chem_com_sp1], outputs=[sp2], propensity_type=MassAction(k_forward=1))

        # mixing WeightedSpecies and Species is not allowed
        with self.assertRaises(TypeError):
            Reaction(inputs=[chem_com_sp1, sp2], outputs=[sp1], propensity_type=MassAction(k_forward=1))
コード例 #9
0
def test_massaction_is_reverable():
    mak = MassAction(k_forward=1, k_reverse=0.1)
    assert mak.is_reversible