def test_gibbs_energy(self): kegg_id_to_coeff = { 'C00002': -1, 'C00001': -1, 'C00008': 1, 'C00009': 1 } # ATP + H2O = ADP + Pi 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)
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)
def reaction_gibbs(equation, dfG_dict=None, pH=7.0, eq_api=None): """Calculate standard Gibbs reaction energy.""" # Remove compartment tags from compound IDs equation = re.sub("_\[[a-z]{3}\]", "", equation) equation = re.sub("_[a-z]{1}", "", equation) if dfG_dict: s = parse_equation(equation) if None in [dfG_dict[c[1]] for c in s[0] + s[1]]: # Cannot calculate drG when dfG is missing return None else: p = sum([c[0] * Decimal(str(dfG_dict[c[1]])) for c in s[1]]) r = sum([c[0] * Decimal(str(dfG_dict[c[1]])) for c in s[0]]) return float(p - r) else: # Use Equilibrator API if not eq_api: eq_api = ComponentContribution(pH=pH, ionic_strength=0.1) rxn = Reaction.parse_formula(equation) return round(eq_api.dG0_prime(rxn)[0], 1)
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
for formula in data.ReactionFormula: rxn = Reaction.parse_formula(formula) name = str(data.ID[i]) KEGGID = str(data.KEGGIDs[i]) reactionStr = name#+'_'+KEGGID parameterID = 'kEQ_'+name print(name) #Check if reaction is atomically balanced if not rxn.check_full_reaction_balancing(): print('%s is not balanced' % name) #raw_input("Press the <ENTER> key to continue...") print(' ') i = i+1 #Get standard Gibbs free energy for the rxn dG0_prime, dG0_uncertainty = eq_api.dG0_prime(rxn) if name == 'RIP1': dG0_prime = -38.46 #Edda Klipp's work if name == 'RIP1': dG0_prime = -38.46 #Edda Klipp's work KEQ = exp(-dG0_prime/(R*Temp)) print("dG0' = %.1f uncertainty: %.1f kJ/mol" % (dG0_prime, dG0_uncertainty)) print ("Keq = %1f" % (KEQ)) #Get reversibility index ln_RI = rxn.reversibility_index() print('ln(Reversibility Index) = %.1f\n' % ln_RI) output = output+type+'\t'+reactionStr+'\t'+compound+'\t'+str(KEQ)+'\t'+unit+'\t'+ KEGGID+'\t'+compoundID+'\t'+parameterID+'\n' #Write output: os.chdir(ECM_path+'/dataFiles') fid = open('kEqTable.txt','w')
# parse the reaction try: reaction = Reaction.parse_formula(args.reaction) except ValueError as e: logging.error(str(e)) sys.exit(-1) equilibrator = ComponentContribution(pH=args.ph, ionic_strength=args.i) n_e = reaction.check_half_reaction_balancing() if n_e is None: logging.error('reaction is not chemically balanced') sys.exit(-1) elif n_e == 0: dG0_prime, dG0_uncertainty = equilibrator.dG0_prime(reaction) sys.stdout.write(u'\u0394G\'\u00B0 = %.1f \u00B1 %.1f kJ/mol\n' % (dG0_prime, dG0_uncertainty)) ln_RI = equilibrator.reversibility_index(reaction) sys.stdout.write(u'ln(Reversibility Index) = %.1f\n' % ln_RI) else: # treat as a half-reaction logging.warning('This reaction isn\'t balanced, but can still be treated' ' as a half-reaction') E0_prime_mV, E0_uncertainty = equilibrator.E0_prime(reaction) sys.stdout.write(u'E\'\u00B0 = %.1f \u00B1 %.1f mV\n' % (E0_prime_mV, E0_uncertainty)) sys.stdout.flush() sys.stderr.write(r'* the range represents the 95% confidence interval'