Exemple #1
0
    def testBasic(self):
        reaction_energies = {'R1': 1, 'R2': -10, 'R3': 395.120}

        thermo_data = thermodynamic_data.ReactionBasedThermoData(
            reaction_energies)
        for id, r_energy in reaction_energies.iteritems():
            self.assertEquals(r_energy, thermo_data.GetDGrTagZero_ForID(id))

        self.assertTrue(np.isnan(thermo_data.GetDGrTagZero_ForID('FAKE_ID')))

        # Fetch compounds that have data.
        reaction_ids = reaction_energies.keys()
        expected_energies = [reaction_energies[k] for k in reaction_ids]
        actual_energies = thermo_data.GetDGrTagZero_ForIDs(reaction_ids)
        self.assertEqual(expected_energies, list(actual_energies))

        # Fetch mixture of compounds, one that has no data.
        reaction_ids.append('FAKE_ID')
        actual_energies = list(thermo_data.GetDGrTagZero_ForIDs(reaction_ids))

        self.assertEqual(expected_energies, actual_energies[:-1])
        self.assertTrue(np.isnan(actual_energies[-1]))

        # Check that you can't get compound energies by ID.
        self.assertRaises(NotImplementedError, thermo_data.GetDGfTagZero_ForID,
                          'FAKE_ID')

        # Check that we can get thermo data from the model.
        model = FakeStoichModel()
        reaction_ids = model.GetReactionIDs()
        expected_energies = thermo_data.GetDGrTagZero_ForIDs(reaction_ids)
        actual_energies = thermo_data.GetDGrTagZero_ForModel(model)
        self.assertEqual(list(expected_energies), list(actual_energies))
Exemple #2
0
    def testInfeasibleDummyProblem(self):
        stoich_model = FakeStoichModel()
        thermo = FakeInfeasibleThermoData()
        kdata = kinetic_data.UniformKineticData()

        opt = protein_optimizer.ProteinOptimizer(stoich_model, thermo, kdata)
        res = opt.FindOptimum()
        self.assertEqual(optimized_pathway.OptimizationStatus.INFEASIBLE,
                         res.status.status)
Exemple #3
0
    def testDummyProblemWideBounds(self):
        stoich_model = FakeStoichModel()
        thermo = FakeThermoData()
        b = self.WideBounds()

        iter = feasible_concentrations_iterator.FeasibleConcentrationsIterator(
            stoich_model, thermo, b)
        for concs in iter:
            self.assertTrue(iter.Feasible(concs))
Exemple #4
0
    def testDummyProblem(self):
        stoich_model = FakeStoichModel()
        thermo = FakeThermoData()
        kdata = kinetic_data.UniformKineticData()

        opt = protein_optimizer.ProteinOptimizer(stoich_model, thermo, kdata)
        res = opt.FindOptimum()
        self.assertEqual(optimized_pathway.OptimizationStatus.SUCCESSFUL,
                         res.status.status)

        result = res.opt_val
        self.assertAlmostEqual(0.048032, result, 3)
Exemple #5
0
    def testDummyProblem(self):
        stoich_model = FakeStoichModel()
        thermo = FakeThermoData()

        opt = mtdf_optimizer.MTDFOptimizer(stoich_model, thermo)
        res = opt.FindMTDF()

        transformed_dgr = res.dGr_tag
        expected_mtdf = -np.min(transformed_dgr)
        mtdf = res.opt_val

        self.assertAlmostEqual(6.90989, mtdf, 3)
        self.assertAlmostEqual(expected_mtdf, mtdf, 3)
Exemple #6
0
    def testBasic(self):
        stoich_model = FakeStoichModel()
        thermo = FakeThermoData()

        dG0_r_prime = thermo.GetDGrTagZero_ForModel(stoich_model)
        S = stoich_model.GetStoichiometricMatrix()
        Ncompounds, _ = S.shape
        injector = DummyInjector()

        minus_dg = protein_optimizer.MinusDG(S, dG0_r_prime, injector)

        # 1M concentrations should have no effect.
        x = np.ones(Ncompounds)
        transformed = minus_dg(x)
        expected_minus_dg = -np.matrix(dG0_r_prime)
        self.assertTrue((transformed == expected_minus_dg).all())

        # Biological concentrations should effect the dGrs.
        x = np.ones(Ncompounds) * 1e-3
        transformed = minus_dg(x)
        expected_minus_dg = -np.matrix(dG0_r_prime +
                                       protein_optimizer.RT * x * S)
        self.assertTrue((transformed == expected_minus_dg).all())
Exemple #7
0
    def testDummyProblemDifferentBounds(self):
        stoich_model = FakeStoichModel()
        thermo = FakeThermoData()

        b = self.MyBounds()
        opt = mtdf_optimizer.MTDFOptimizer(stoich_model, thermo)
        res = opt.FindMTDF(concentration_bounds=b)

        transformed_dgr = res.dGr_tag
        expected_mtdf = -np.min(transformed_dgr)
        mtdf = res.opt_val

        self.assertAlmostEqual(13.117132, mtdf, 3)
        self.assertAlmostEqual(expected_mtdf, mtdf, 3)
Exemple #8
0
    def testBasic(self):
        formation_energies = {'C1': 1, 'C2': -10, 'C3': 395.120}

        thermo_data = thermodynamic_data.FormationBasedThermoData(
            formation_energies)
        for id, formation in formation_energies.iteritems():
            self.assertEquals(formation, thermo_data.GetDGfTagZero_ForID(id))

        self.assertTrue(np.isnan(thermo_data.GetDGfTagZero_ForID('FAKE_ID')))

        # Fetch compounds that have data.
        compound_ids = formation_energies.keys()
        expected_formation = np.array(
            [formation_energies[k] for k in compound_ids])
        actual_formation = thermo_data.GetDGfTagZero_ForIDs(compound_ids)
        self.assertTrue((expected_formation == actual_formation).all())

        # Fetch mixture of compounds, one that has no data.
        compound_ids.append('FAKE_ID')
        actual_formation = thermo_data.GetDGfTagZero_ForIDs(compound_ids)
        self.assertTrue((expected_formation == actual_formation[0, :-1]).all())
        self.assertTrue(np.isnan(actual_formation[0, -1]))

        # Check that you can't get reaction energies by ID.
        self.assertRaises(NotImplementedError, thermo_data.GetDGrTagZero_ForID,
                          'FAKE_ID')

        # Check that we can get thermo data from the model.
        model = FakeStoichModel()
        S = model.GetStoichiometricMatrix()
        formation_energies = thermo_data.GetDGfTagZero_ForModel(model)
        expected_reaction_energies = np.dot(formation_energies, S)
        reaction_energies = thermo_data.GetDGrTagZero_ForModel(model)

        self.assertTrue(
            (expected_reaction_energies == reaction_energies).all())