def combine(fname, text_out): modules = {} for row in csv.DictReader(open(fname, 'r')): options = modules.setdefault(row['Module'], {}) enzymes = options.setdefault(row['Option'], []) reaction = Reaction.FromFormula(row['Formula']) reaction.Balance(balance_water=False, exception_if_unknown=False) enzymes.append((row['Enzyme'], row['Formula'], float(row['Flux']))) l_mod = [] for module, options in sorted(modules.iteritems()): l_opt = [] for option, enzymes in sorted(options.iteritems()): l_opt.append(("%s%s" % (module, option), enzymes)) l_mod.append(l_opt) for combination in itertools.product(*l_mod): entry = '_'.join([mod for mod, enzymes in combination]) text_out.write('ENTRY %s\n' % entry) text_out.write('THERMO merged\n') firstrow = True for mod, enzymes in combination: for enzyme, formula, flux in enzymes: if firstrow: text_out.write('REACTION %-6s %s (x%g)\n' % (enzyme, formula, flux)) firstrow = False else: text_out.write(' %-6s %s (x%g)\n' % (enzyme, formula, flux)) text_out.write('///\n')
def GetForamtionEnergies(self, thermo): self.db.CreateTable(self.GIBBS_ENERGY_TABLE_NAME, "equation TEXT, dG0 REAL, dGc REAL", drop_if_exists=True) self.db.CreateIndex('gibbs_equation_idx', self.GIBBS_ENERGY_TABLE_NAME, 'equation', unique=True, drop_if_exists=True) all_equations = set() for row in self.db.Execute("SELECT distinct(equation) FROM %s" % (self.EQUATION_TABLE_NAME)): all_equations.add(str(row[0])) from pygibbs.kegg import Kegg kegg = Kegg.getInstance() all_kegg_cids = set(kegg.get_all_cids()) for equation in all_equations: try: rxn = Reaction.FromFormula(equation) if not rxn.get_cids().issubset(all_kegg_cids): raise KeggNonCompoundException rxn.Balance(balance_water=True, exception_if_unknown=True) dG0 = thermo.GetTransfromedKeggReactionEnergies([rxn], conc=1)[0, 0] dGc = thermo.GetTransfromedKeggReactionEnergies([rxn], conc=1e-3)[0, 0] self.db.Insert(self.GIBBS_ENERGY_TABLE_NAME, [equation, dG0, dGc]) except (KeggParseException, KeggNonCompoundException, KeggReactionNotBalancedException): self.db.Insert(self.GIBBS_ENERGY_TABLE_NAME, [equation, None, None]) self.db.Commit()
def GetC1Thermodynamics( html_writer, reaction_fname='../data/thermodynamics/c1_reaction_thermodynamics.csv' ): html_writer.write("<h1>C1 thermodynamics</h1>\n") dict_list = [] db_public = SqliteDatabase('../data/public_data.sqlite') alberty = PsuedoisomerTableThermodynamics.FromDatabase(\ db_public, 'alberty_pseudoisomers', name='alberty') alberty.AddPseudoisomer(101, nH=23, z=0, nMg=0, dG0=0) reacthermo = ReactionThermodynamics(alberty, 'C1') reacthermo.pH = 7 reacthermo.I = 0.1 reacthermo.T = 298.15 reacthermo.pMg = 14 c1_reactions = [] for row in csv.DictReader(open(reaction_fname, 'r')): r = Reaction.FromFormula(row['formula']) r.Balance(balance_water=False) r.SetNames(row['enzyme']) dG0_r_prime = float(row['dG0_r_prime']) pH, I, pMg, T = [float(row[k]) for k in ['pH', 'I', 'pMg', 'T']] reacthermo.AddReaction(r, dG0_r_prime, pH=pH, I=I, pMg=pMg, T=T) c1_reactions.append(r) row['formula'] = r.to_hypertext(show_cids=False) dict_list.append(row) html_writer.write_table( dict_list, headers=['acronym', 'enzyme', 'formula', 'dG0_r_prime']) reacthermo._Recalculate() return reacthermo
def runBeta2Alpha(thermo, reactionList): pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/Beta2Alpha.html'), thermo=thermo, max_solutions=None, max_reactions=15, maximal_dG=0.0, thermodynamic_method=OptimizationMethods.GLOBAL, update_file=None) add_cofactor_reactions(pl) add_redox_reactions(pl) for r in reactionList: pl.add_reaction(Reaction.FromFormula(r, "Auto generate #%s" % hash(r))) r = Reaction.FromFormula("C00099 => C01401") pl.find_path("Beta2Alpha", r)
def example_formate(thermo, product_cid=22, co2_conc=1e-5): co2_hydration = Reaction.FromFormula("C00011 + C00001 => C00288") co2_hydration_dG0_prime = float(thermo.GetTransfromedKeggReactionEnergies([co2_hydration])) carbonate_conc = co2_conc * np.exp(-co2_hydration_dG0_prime / (R*default_T)) thermo.bounds[11] = (co2_conc, co2_conc) thermo.bounds[288] = (carbonate_conc, carbonate_conc) pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/pathologic.html'), thermo=thermo, max_solutions=None, max_reactions=20, maximal_dG=0.0, thermodynamic_method=OptimizationMethods.GLOBAL, update_file=None) add_cofactor_reactions(pl, free_ATP_hydrolysis=True) add_redox_reactions(pl, NAD_only=False) pl.delete_reaction(134) # formate:NADP+ oxidoreductase pl.delete_reaction(519) # Formate:NAD+ oxidoreductase pl.delete_reaction(24) # Rubisco pl.delete_reaction(581) # L-serine:NAD+ oxidoreductase (deaminating) pl.delete_reaction(220) # L-serine ammonia-lyase pl.delete_reaction(13) # glyoxylate carboxy-lyase (dimerizing; tartronate-semialdehyde-forming) pl.delete_reaction(585) # L-Serine:pyruvate aminotransferase pl.delete_reaction(1440) # D-Xylulose-5-phosphate:formaldehyde glycolaldehydetransferase pl.delete_reaction(5338) # 3-hexulose-6-phosphate synthase pl.add_reaction(Reaction.FromFormula("C06265 => C00011", name="CO2 uptake")) pl.add_reaction(Reaction.FromFormula("C06265 => C00288", name="carbonate uptake")) pl.add_reaction(Reaction.FromFormula("C06265 => C00058", name="formate uptake")) r = Reaction.FromFormula("5 C06265 + C00058 => C%05d" % product_cid) # at least one formate to product #r.Balance() kegg = Kegg.getInstance() pl.find_path("formate to %s" % kegg.cid2name(product_cid), r)
def runPathologic(thermo, reactionList): pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/mog_finder.html'), thermo=thermo, max_solutions=None, max_reactions=15, maximal_dG=-3.0, thermodynamic_method=OptimizationMethods.GLOBAL, update_file=None) add_cofactor_reactions(pl) add_redox_reactions(pl) for r in reactionList: pl.add_reaction(Reaction.FromFormula(r, "Auto generate #%s" % hash(r))) pl.delete_reaction(134) pl.delete_reaction(344) pl.delete_reaction(575) pl.delete_reaction(212) #pl.add_reaction(Reaction.FromFormula('C00149 + C00006 <=> C00036 + C00005 + C00080', # 'malate + NADP+ = oxaloacetate + NADPH',343)) #pl.add_reaction(Reaction.FromFormula('C00222 + C00010 + C00006 <=> C00083 + C00005', # 'malonate-semialdehyde + CoA + NADP+ = malonyl-CoA + NADPH',740)) r = Reaction.FromFormula("2 C00288 => C00048") pl.find_path("MOG_finder", r)
def example_reductive(thermo): pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/pathologic.html'), thermo=thermo, max_solutions=None, max_reactions=15, maximal_dG=0.0, thermodynamic_method=OptimizationMethods.GLOBAL, update_file=None) add_cofactor_reactions(pl) add_redox_reactions(pl) r = Reaction.FromFormula("3 C00011 => C00022") #r.Balance() pl.find_path("reductive", r)
def example_oxidative(thermo): pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/pathologic.html'), thermo=thermo, max_solutions=None, max_reactions=10, maximal_dG=0, thermodynamic_method=OptimizationMethods.MAX_TOTAL, update_file=None) add_cofactor_reactions(pl) add_redox_reactions(pl, NAD_only=False) r = Reaction.FromFormula("C00022 => 3 C00011") #r.Balance() pl.find_path("oxidative", r)
def example_lower_glycolysis(thermo): pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/pathologic.html'), thermo=thermo, max_solutions=None, max_reactions=8, maximal_dG=0.0, thermodynamic_method=OptimizationMethods.GLOBAL, update_file=None) add_cofactor_reactions(pl) add_redox_reactions(pl) #r = Reaction.FromFormula("C00003 + C00118 + C00001 => C00022 + C00004 + C00009") r = Reaction.FromFormula("C00118 => C00022") #r.Balance() pl.find_path("GAP => PYR", r)
def example_rpi_bypass(thermo): pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/pathologic.html'), thermo=thermo, max_solutions=None, max_reactions=10, maximal_dG=0.0, thermodynamic_method=OptimizationMethods.GLOBAL, update_file=None) add_cofactor_reactions(pl) #add_redox_reactions(pl) pl.delete_reaction(1056) # ribose-phosphate isomerase pl.delete_reaction(1081) # ribose isomerase r = Reaction.FromFormula("C00117 => C01182") #r.Balance() pl.find_path("rpi_bypass", r)
def example_three_acetate(thermo): pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/pathologic.html'), thermo=thermo, max_solutions=None, max_reactions=20, maximal_dG=0.0, thermodynamic_method=OptimizationMethods.GLOBAL, update_file=None) add_cofactor_reactions(pl) #add_redox_reactions(pl) pl.delete_reaction(761) # F6P + Pi = E4P + acetyl-P pl.delete_reaction(1621) # X5P + Pi = GA3P + acetyl-P r = Reaction.FromFormula("C00031 => 3 C00033") #r.Balance() pl.find_path("three_acetate", r)
def example_glycolysis(thermo): pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/pathologic.html'), thermo=thermo, max_solutions=None, max_reactions=15, maximal_dG=0.0, thermodynamic_method=OptimizationMethods.GLOBAL, update_file=None) add_cofactor_reactions(pl, free_ATP_hydrolysis=False) ban_toxic_compounds(pl) #add_carbon_counts(pl) #r = Reaction.FromFormula("C00031 => 6 C06265") r = Reaction.FromFormula("C00031 + 3 C00008 => 2 C00186 + 3 C00002") #r.Balance() pl.find_path("GLC => 2 LAC, 3 ATP, No methylglyoxal", r)
def example_glucose_to_ethanol_and_formate(thermo): pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/pathologic.html'), thermo=thermo, max_solutions=None, max_reactions=15, maximal_dG=0.0, thermodynamic_method=OptimizationMethods.GLOBAL, update_file=None) #add_cofactor_reactions(pl) #add_XTP_reactions(pl, '=>') #add_redox_reactions(pl) #pl.delete_reaction(761) # F6P + Pi = E4P + acetyl-P #pl.delete_reaction(1621) # X5P + Pi = GA3P + acetyl-P r = Reaction.FromFormula("2 C00031 + 3 C00001 => 6 C00058 + 3 C00469") r.Balance() pl.find_path("glucose_to_ethanol_and_formate", r)
def example_more_than_two_pyruvate(thermo): pl = Pathologic(db=SqliteDatabase('../res/gibbs.sqlite', 'r'), public_db=SqliteDatabase('../data/public_data.sqlite'), html_writer=HtmlWriter('../res/pathologic.html'), thermo=thermo, max_solutions=None, max_reactions=20, maximal_dG=0.0, thermodynamic_method=OptimizationMethods.GLOBAL, update_file=None) #add_cofactor_reactions(pl) #add_XTP_reactions(pl, '=>') #add_redox_reactions(pl) #pl.delete_reaction(761) # F6P + Pi = E4P + acetyl-P #pl.delete_reaction(1621) # X5P + Pi = GA3P + acetyl-P r = Reaction.FromFormula("3 C00031 + 3 C00011 + C00003 => 7 C00022 + 3 C00001 + C00004") r.Balance() pl.find_path("more_than_two_pyr", r)
def FromCsv(csv_fname, formation_thermo): data = [] for row in csv.DictReader(open(csv_fname, 'r')): r = Reaction.FromFormula(row['formula']) r.Balance(balance_water=False) r.SetNames(row['enzyme']) dG0_r_prime = float(row['dG0_r_prime']) pH = float(row['pH']) I = float(row['I']) pMg = float(row.get('pMg', '10')) T = float(row['T']) data.append((r, dG0_r_prime, pH, I, pMg, T)) reacthermo = ReactionThermodynamics(formation_thermo) reacthermo.SetConditions(pH=pH, I=I, pMg=pMg, T=T) for r, dG0, pH, I, pMg, T in data: reacthermo.AddReaction(r, dG0, pH=pH, I=I, pMg=pMg, T=T) reacthermo._Recalculate() return reacthermo
def GetStoichiometries(self): self.db.CreateTable(self.STOICHIOMETRY_TABLE_NAME, "equation TEXT, compound TEXT, coefficient REAL", drop_if_exists=True) self.db.CreateIndex('stoichiometry_equation_idx', self.STOICHIOMETRY_TABLE_NAME, 'equation', unique=False, drop_if_exists=True) self.db.CreateIndex('stoichiometry_compound_idx', self.STOICHIOMETRY_TABLE_NAME, 'compound', unique=False, drop_if_exists=True) all_kegg_reactions = [] all_equations = [] for row in self.db.Execute("SELECT distinct(equation) FROM %s" % (self.EQUATION_TABLE_NAME)): try: r = Reaction.FromFormula(str(row[0])) all_equations.append(str(row[0])) all_kegg_reactions.append(r) except (KeggParseException, KeggNonCompoundException): pass for i, equation in enumerate(all_equations): for compound, coefficient in all_kegg_reactions[i].iteritems(): self.db.Insert(self.STOICHIOMETRY_TABLE_NAME, [equation, "cpd:C%05d" % compound, coefficient]) self.db.Commit()
def add_carbon_counts(pl): """Add reactions counting carbons in various plausible fermentation products. """ reactions = [ #Reaction.FromFormula("C00246 => 4 C06265", name="Butyrate makeup"), #Reaction.FromFormula("C02632 => 4 C06265", name="Isobutyrate makeup"), Reaction.FromFormula("C00042 => 4 C06265", name="Succinate makeup"), #Reaction.FromFormula("C00022 => 3 C06265", name="Pyruvate makeup"), #Reaction.FromFormula("C00163 => 3 C06265", name="Propionate makeup"), #Reaction.FromFormula("C01013 => 3 C06265", name="3-hydroxypropionate makeup"), Reaction.FromFormula("C00186 => 3 C06265", name="Lactate makeup"), Reaction.FromFormula("C00033 => 2 C06265", name="Acetate makeup"), Reaction.FromFormula("C00469 => 2 C06265", name="Ethanol makeup"), Reaction.FromFormula("C00058 => 1 C06265", name="Formate makeup"), Reaction.FromFormula("C00011 => 1 C06265", name="CO2 makeup"), ] for rxn in reactions: pl.add_reaction(rxn) """
row['formula'] = r.to_hypertext(show_cids=False) dict_list.append(row) html_writer.write_table( dict_list, headers=['acronym', 'enzyme', 'formula', 'dG0_r_prime']) reacthermo._Recalculate() return reacthermo if __name__ == "__main__": html_writer = HtmlWriter('../res/c1_thermodynamics.html') reacthermo = GetC1Thermodynamics(html_writer) html_writer.close() formulas = [ "C02051 + C00004 => C02972 + C00003", "C00143 + C00037 + C00001 => C00101 + C00065", "C00288 + 2 C00138 + C00862 => 2 C00001 + 2 C00139 + C01001", "C00101 + C00003 => C00415 + C00004" ] reactions = [] for f in formulas: r = Reaction.FromFormula(f) r.Balance() reactions.append(r) print reacthermo.GetTransfromedKeggReactionEnergies(reactions)
def add_redox_reactions(pl, NAD_only=False): # all electron transfer reactions pl.add_cofactor_reaction(Reaction.FromFormula("C00003 <=> C00004", name='NAD redox')) pl.add_cofactor_reaction(Reaction.FromFormula("C00006 <=> C00005", name='NADP redox')) if not NAD_only: pl.add_cofactor_reaction(Reaction.FromFormula("C00016 <=> C01352", name='FAD redox')) pl.add_cofactor_reaction(Reaction.FromFormula("C00138 <=> C00139", name='ferredoxin redox')) pl.add_cofactor_reaction(Reaction.FromFormula("C00030 <=> C00028", name='acceptor/donor redox')) pl.add_cofactor_reaction(Reaction.FromFormula("C00125 <=> C00126", name='ferricytochrome c redox')) pl.add_cofactor_reaction(Reaction.FromFormula("C00996 <=> C00999", name='ferricytochrome b5 redox')) pl.add_cofactor_reaction(Reaction.FromFormula("C01070 <=> C01071", name='ferricytochrome c-553 redox')) pl.add_cofactor_reaction(Reaction.FromFormula("C05906 <=> C01617", name='leucocyanidin redox')) pl.add_cofactor_reaction(Reaction.FromFormula("C00343 <=> C00342", name='thioredoxin disulfide redox')) pl.add_cofactor_reaction(Reaction.FromFormula("C03648 <=> C00974", name='cis-3,4-Leucopelargonidin redox')) pl.add_cofactor_reaction(Reaction.FromFormula("C05684 <=> C01528", name='selenide redox')) else: pl.ban_compound(16) # FAD(ox) pl.ban_compound(1352) # FAD(red) pl.ban_compound(138) # ferredoxin (ox) pl.ban_compound(139) # ferredoxin (red) pl.ban_compound(30) # acceptor pl.ban_compound(28) # donor pl.ban_compound(125) # ferricytochrome c (ox) pl.ban_compound(126) # ferricytochrome c (red) pl.ban_compound(996) # ferricytochrome b5 (ox) pl.ban_compound(999) # ferricytochrome b5 (red) pl.ban_compound(1070) # ferricytochrome c-553 (ox) pl.ban_compound(1071) # ferricytochrome c-553 (red) pl.ban_compound(5906) # leucocyanidin (ox) pl.ban_compound(1617) # leucocyanidin (red) pl.ban_compound(343) # thioredoxin disulfide (ox) pl.ban_compound(342) # thioredoxin disulfide (red) pl.ban_compound(3648) # cis-3,4-Leucopelargonidin (ox) pl.ban_compound(974) # cis-3,4-Leucopelargonidin (red) pl.ban_compound(5684) # selenide (ox) pl.ban_compound(1528) # selenide (red)
def add_XTP_reactions(pl, direction='<=>'): """ Adds phosphorylated nucleotide reactions, which ignore thermodynamics and phosphate balance constraints. The direction arguments can be set to allow them only in one direction. For example, a useful scenario would be to force a pathway not to consume ATP without constraining it for zero ATP production. """ pl.add_cofactor_reaction(Reaction.FromFormula("C00002 %s C00008" % direction, name='ATP to ADP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00002 %s C00020" % direction, name='ATP to AMP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00008 %s C00020" % direction, name='ADP to AMP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00131 %s C00206" % direction, name='dATP to dADP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00131 %s C00360" % direction, name='dATP to dAMP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00206 %s C00360" % direction, name='dADP to dAMP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00081 %s C00104" % direction, name='ITP to IDP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00081 %s C00130" % direction, name='ITP to IMP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00104 %s C00130" % direction, name='IDP to IMP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00044 %s C00035" % direction, name='GTP to GDP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00044 %s C00144" % direction, name='GTP to GMP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00035 %s C00144" % direction, name='GDP to GMP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00063 %s C00112" % direction, name='CTP to CDP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00063 %s C00055" % direction, name='CTP to CMP')) pl.add_cofactor_reaction(Reaction.FromFormula("C00112 %s C00055" % direction, name='CDP to CMP'))
def add_cofactor_reactions(pl): pl.add_cofactor_reaction(Reaction.FromFormula("C00001 <=> null", name='Free H2O')) pl.add_cofactor_reaction(Reaction.FromFormula("C00009 <=> null", name='Free Pi')) pl.add_cofactor_reaction(Reaction.FromFormula("C00013 <=> null", name='Free PPi'))
ugc.init() if args.test: r_list = [] # r_list += [Reaction.FromFormula("C00002 + C00001 = C00008 + C00009")] # r_list += [Reaction.FromFormula("C00036 + C00024 = C00022 + C00083")] # r_list += [Reaction.FromFormula("C00036 + C00100 = C00022 + C00683")] # r_list += [Reaction.FromFormula("C01013 + C00010 + C00002 = C05668 + C00020 + C00013")] # r_list += [Reaction.FromFormula("C00091 + C00005 = C00232 + C00010 + C00006")] # r_list += [Reaction.FromFormula("C00002 + C00493 = C00008 + C03175")] # r_list += [Reaction.FromFormula("C00243 + C00125 = C05403 + C00126")] # r_list += [Reaction.FromFormula("2 C00206 = C00360 + C00131")] # r_list += [Reaction.FromFormula("C04171 + C00003 = C00196 + C00080 + C00004")] # r_list += [Reaction.FromFormula("C00036 + C00044 = C00011 + C00035 + C00074")] r_list += [ Reaction.FromFormula( "C00001 + C00022 + C17569 = C00011 + C00033 + C00390") ] kegg = Kegg.getInstance() S, cids = kegg.reaction_list_to_S(r_list) dG0_prime = ugc.GetTransfromedReactionEnergies(S, cids, pH=7.0, I=0.15) ln_conc = np.matrix(np.ones((1, S.shape[0]))) * np.log(0.001) if 1 in cids: ln_conc[0, cids.index(1)] = 0 # H2O should have a concentration of 1 RT = R * default_T dGc_prime = dG0_prime + RT * ln_conc * S for i in xrange(len(r_list)): r_list[i].Balance()
plt.legend(['value in iAF1260', 'UGCM estimation']) plt.savefig(FIG_FNAME + "_fig3.svg", fmt='.svg') db = SqliteDatabase('../res/gibbs.sqlite', 'w') ugc = UnifiedGroupContribution(db) ugc.LoadGroups(True) ugc.LoadObservations(True) ugc.LoadGroupVectors(True) ugc.LoadData(True) ugc.init() r_list = [] #r_list += [Reaction.FromFormula("C00036 + C00044 = C00011 + C00035 + C00074")] #r_list += [Reaction.FromFormula("C00003 + C00037 + C00101 = C00004 + C00011 + C00014 + C00080 + C00143")] # glycine synthase r_list += [ Reaction.FromFormula( "C00001 + C00002 + C00064 + C04376 => C00008 + C00009 + C00025 + C04640" ) ] #r_list += [Reaction.FromFormula("C00001 + 2 C00002 + C00064 + C00288 <=> 2 C00008 + C00009 + C00025 + C00169")] kegg = Kegg.getInstance() S, cids = kegg.reaction_list_to_S(r_list) logging.getLogger('').setLevel(logging.DEBUG) dG0_prime = ugc.GetTransfromedReactionEnergies(S, cids, pH=pH, I=I, pMg=pMg, T=T)
def analyze(prefix, thermo): kegg_file = ParsedKeggFile.FromKeggFile('../data/thermodynamics/%s.txt' % prefix) html_writer = HtmlWriter('../res/%s.html' % prefix) co2_hydration = Reaction.FromFormula("C00011 + C00001 => C00288") #pH_vec = np.arange(5, 9.001, 0.5) #pH_vec = np.array([6, 7, 8]) pH_vec = np.array( [6, 7, 8]) # this needs to be fixed so that the txt file will set the pH #co2_conc_vec = np.array([1e-5, 1e-3]) co2_conc_vec = np.array([1e-5]) data_mat = [] override_bounds = {} for pH in pH_vec.flat: co2_hydration_dG0_prime = float( thermo.GetTransfromedKeggReactionEnergies([co2_hydration], pH=pH)) for co2_conc in co2_conc_vec.flat: carbonate_conc = co2_conc * np.exp(-co2_hydration_dG0_prime / (R * default_T)) #print "[CO2] = %g, [carbonate] = %g, pH = %.1f, I = %.2fM" % (co2_conc, carbonate_conc, pH, I) override_bounds[11] = (co2_conc, co2_conc) override_bounds[288] = (carbonate_conc, carbonate_conc) section_prefix = 'pH_%g_CO2_%g' % (pH, co2_conc * 1000) section_title = 'pH = %g, [CO2] = %g mM' % (pH, co2_conc * 1000) html_writer.write('<h1 id="%s_title">%s</h1>\n' % (section_prefix, section_title)) html_writer.write_ul([ '<a href="#%s_tables">Individual result tables</a>' % section_prefix, '<a href="#%s_summary">Summary table</a>' % section_prefix, '<a href="#%s_figure">Summary figure</a>' % section_prefix ]) data, labels = pareto(kegg_file, html_writer, thermo, pH=pH, section_prefix=section_prefix, balance_water=True, override_bounds=override_bounds) data_mat.append(data) data_mat = np.array(data_mat) if data_mat.shape[0] == 1: pareto_fig = plt.figure(figsize=(6, 6), dpi=90) plt.plot(data_mat[0, :, 0], data_mat[0, :, 1], '.', figure=pareto_fig) for i in xrange(data_mat.shape[1]): if data[i, 1] < 0: color = 'grey' else: color = 'black' plt.text(data_mat[0, i, 0], data_mat[0, i, 1], labels[i], ha='left', va='bottom', fontsize=8, color=color, figure=pareto_fig) plt.title(section_title, figure=pareto_fig) else: pareto_fig = plt.figure(figsize=(10, 10), dpi=90) for i in xrange(data_mat.shape[1]): plt.plot(data_mat[:, i, 0], data_mat[:, i, 1], '-', figure=pareto_fig) plt.text(data_mat[0, i, 0], data_mat[0, i, 1], '%g' % pH_vec[0], ha='center', fontsize=6, color='black', figure=pareto_fig) plt.text(data_mat[-1, i, 0], data_mat[-1, i, 1], '%g' % pH_vec[-1], ha='center', fontsize=6, color='black', figure=pareto_fig) plt.legend(labels, loc='upper right') plt.title('Pareto', figure=pareto_fig) plt.xlabel('Optimal Energetic Efficiency [kJ/mol]', figure=pareto_fig) plt.ylabel('Optimized Distributed Bottleneck [kJ/mol]', figure=pareto_fig) html_writer.write('<h2 id="%s_figure">Summary figure</h1>\n' % section_prefix) # plot the Pareto figure showing all values (including infeasible) html_writer.embed_matplotlib_figure(pareto_fig, name=prefix + '_0') # set axes to hide infeasible pathways and focus on feasible ones pareto_fig.axes[0].set_xlim(None, 0) pareto_fig.axes[0].set_ylim(0, None) html_writer.embed_matplotlib_figure(pareto_fig, name=prefix + '_1') html_writer.close()