def test_gibbs_energy(self):
        warnings.simplefilter('ignore', ResourceWarning)

        kegg_id_to_coeff = {'C00002' : -1, 'C00001' : -1,
                            'C00008' :  1, 'C00009' :  1} # ATP + H2O = ADP + Pi
        kegg_id_to_conc  = {'C00002' : 1e-3,
                            'C00009' :  1e-4}
        reaction = Reaction(kegg_id_to_coeff)

        cc = ComponentContribution(pH=7.0, ionic_strength=0.1)
        dG0_prime, dG0_uncertainty = cc.dG0_prime(reaction)
        
        self.assertAlmostEqual(dG0_prime, -26.4, 1)
        self.assertAlmostEqual(dG0_uncertainty, 0.6, 1)
        
        dG_prime, _ = cc.dG_prime(reaction, kegg_id_to_conc)
        self.assertAlmostEqual(dG_prime, -32.1, 1)

        dGm_prime, _ = cc.dGm_prime(reaction)
        self.assertAlmostEqual(dGm_prime, -43.5, 1)
Exemple #2
0
def predict_dG(model, pH=7, ionic_strength=0.1, fn=None):
    eq_api = ComponentContribution(pH=7.0, ionic_strength=0.1)
    lst = []
    for r in model.reactions:
        kegg_string = build_kegg_string(r)
        if kegg_string:
            try:
                rxn = Reaction.parse_formula(kegg_string)
            except KeyError:
                print("eQuilibrator could not predict dG for {0}".format(r.id))
                continue
            # eq_api.dG0_prime(rxn)
            try:
                dgm = eq_api.dGm_prime(rxn)
                dg0 = eq_api.dG0_prime(rxn)
            except:
                print("eQuilibrator could not predict dG for {0}".format(r.id))
            else:
                if dgm[-1] > dGMm_STD_THRESHOLD:
                    print(
                        "eQuilibrator could not predict dG for {0} with a reasonable uncertainty"
                        .format(r.id))
                    continue
                print(r.id, dgm)
                lst.append([
                    r.id, r.name, r.annotation["kegg.reaction"],
                    parse_reversibility(r), *dg0, *dgm
                ])
    # Store as df
    df = pd.DataFrame(lst)
    df.columns = [
        "Rxn", "Rxn Name", "Rxn KEGG ID", "Reversibility in model",
        "dG0_prime", "dG0_prime_std", "dGm_prime", "dGm_prime_std"
    ]
    if not fn:
        fn = "eQuilibrator_reversibility.csv"
    df.to_csv(fn, index=False, sep=",")
    print("Found the dG for {0} of {1} reactions".format(
        len(lst), len(model.reactions)))
    return lst