Exemplo n.º 1
0
def python_main():
    logger = logging.getLogger('')
    logger.setLevel(logging.INFO)
    from python.component_contribution import ComponentContribution
    from python.kegg_model import KeggModel
    from python.thermodynamic_constants import default_RT

    cc = ComponentContribution.init()
    reaction_strings = open(REACTION_FNAME, 'r').readlines()
    model = KeggModel.from_formulas(reaction_strings)

    model.add_thermo(cc)
    dG0_prime, dG0_std = model.get_transformed_dG0(7.0, 0.2, 298.15)
    
    cid2c_range = {cid : (1e-6, 1e-2) for cid in model.cids}
    cid2c_range['C00001'] = (1.0, 1.0) # water must be always set to 1 (equivalent to 55M)
    
    ln_conc = np.log(np.matrix([cid2c_range[cid] for cid in model.cids]))
    ln_conc_min = ln_conc[:, 0]
    ln_conc_max = ln_conc[:, 1]
    
    S_minus, S_plus = model.get_unidirectional_S()
    
    dG_prime_min = dG0_prime + default_RT * (S_minus.T * ln_conc_max + S_plus.T * ln_conc_min)
    dG_prime_max = dG0_prime + default_RT * (S_minus.T * ln_conc_min + S_plus.T * ln_conc_max)
    
    for i, r in enumerate(reaction_strings):
        print '-'*50
        print r.strip()
        print "dG'0      = %8.1f +- %5.1f" % (dG0_prime[i, 0], dG0_std[i, i] * 1.96)
        print "dG' range = %8.1f  - %8.1f" % (dG_prime_min[i, 0], dG_prime_max[i, 0])
        if dG_prime_min[i, 0] < 0 and dG_prime_max[i, 0] > 0:
            print "REVERSIBLE!"
        else:
            print "IRREVERSIBLE!"
def python_main():
    logger = logging.getLogger('')
    logger.setLevel(logging.INFO)
    from python.component_contribution import ComponentContribution
    from python.kegg_model import KeggModel

    cc = ComponentContribution.init()
    reaction_strings = open(REACTION_FNAME, 'r').readlines()
    model = KeggModel.from_formulas(reaction_strings)
    model.add_thermo(cc)

    dG0_prime, dG0_std = model.get_transformed_dG0(7.0, 0.2, 298.15)

    print "For a linear problem, define two vector variables 'x' and 'y', each of length Nr (i.e. " + \
          "the same length as the list of reactions). Then add these following " + \
          "constraints: \n" + \
          "-1 <= y <= 1\n" + \
          "x = dG0_prime + 3 * dG0_std * y\n" + \
          "Then use 'x' as the value of the standard Gibbs energy for all reactions."
    print "The results are writteng to: " + OUTPUT_FNAME

    savemat(OUTPUT_FNAME, {
        'dG0_prime': dG0_prime,
        'dG0_std': dG0_std
    },
            oned_as='row')
Exemplo n.º 3
0
def python_main():
    logger = logging.getLogger("")
    logger.setLevel(logging.INFO)
    from python.component_contribution import ComponentContribution
    from python.kegg_model import KeggModel

    cc = ComponentContribution.init()
    reaction_strings = open(REACTION_FNAME, "r").readlines()
    model = KeggModel.from_formulas(reaction_strings)
    model.add_thermo(cc)

    dG0_prime, dG0_std = model.get_transformed_dG0(7.0, 0.2, 298.15)

    print "For a linear problem, define two vector variables 'x' and 'y', each of length Nr (i.e. " + "the same length as the list of reactions). Then add these following " + "constraints: \n" + "-1 <= y <= 1\n" + "x = dG0_prime + 3 * dG0_std * y\n" + "Then use 'x' as the value of the standard Gibbs energy for all reactions."
    print "The results are writteng to: " + OUTPUT_FNAME

    savemat(OUTPUT_FNAME, {"dG0_prime": dG0_prime, "dG0_std": dG0_std}, oned_as="row")
def python_main():
    logger = logging.getLogger('')
    logger.setLevel(logging.INFO)
    from python.component_contribution import ComponentContribution
    from python.kegg_model import KeggModel
    from python.thermodynamic_constants import default_RT

    cc = ComponentContribution.init()
    reaction_strings = open(REACTION_FNAME, 'r').readlines()
    model = KeggModel.from_formulas(reaction_strings)

    model.add_thermo(cc)
    dG0_prime, dG0_std = model.get_transformed_dG0(7.0, 0.2, 298.15)

    cid2c_range = {cid: (1e-6, 1e-2) for cid in model.cids}
    cid2c_range['C00001'] = (
        1.0, 1.0)  # water must be always set to 1 (equivalent to 55M)

    ln_conc = np.log(np.matrix([cid2c_range[cid] for cid in model.cids]))
    ln_conc_min = ln_conc[:, 0]
    ln_conc_max = ln_conc[:, 1]

    S_minus, S_plus = model.get_unidirectional_S()

    dG_prime_min = dG0_prime + default_RT * (S_minus.T * ln_conc_max +
                                             S_plus.T * ln_conc_min)
    dG_prime_max = dG0_prime + default_RT * (S_minus.T * ln_conc_min +
                                             S_plus.T * ln_conc_max)

    for i, r in enumerate(reaction_strings):
        print '-' * 50
        print r.strip()
        print "dG'0      = %8.1f +- %5.1f" % (dG0_prime[i, 0],
                                              dG0_std[i, i] * 1.96)
        print "dG' range = %8.1f  - %8.1f" % (dG_prime_min[i, 0],
                                              dG_prime_max[i, 0])
        if dG_prime_min[i, 0] < 0 and dG_prime_max[i, 0] > 0:
            print "REVERSIBLE!"
        else:
            print "IRREVERSIBLE!"
if not os.path.exists(REPORT_CACHE_FNAME):
    fp = open(REPORT_CACHE_FNAME, 'w')
    cc = ComponentContribution()
    cc.train()
    csv_out = csv.writer(fp)
    csv_out.writerow(['cid', 'dG0_f'])
    for compound_id in cc.ccache.get_all_compound_ids():
        dG0_f = cc.get_major_ms_dG0_f(compound_id)
        csv_out.writerow([compound_id, '%8.2f' % dG0_f])
        cid2dG0[compound_id] = dG0_f
else:
    for row in csv.DictReader(open(REPORT_CACHE_FNAME, 'r')):
        cid2dG0[row['cid']] = float(row['dG0_f'])

REACTION_FNAME = 'tests/report_gc_reactions.txt'
reaction_strings = open(REACTION_FNAME, 'r').readlines()
model = KeggModel.from_formulas(reaction_strings)    

# compare the dG0_r of the model to the one we get if multiplying
# the model stoichiometric matrix by the formation energies
model_dG0_f = np.matrix([cid2dG0[cid] for cid in model.cids]).T
model_dG0_r = model.S.T * model_dG0_f

cc2 = ComponentContribution()
model.add_thermo(cc2)
plt.plot(model.dG0, model_dG0_r, '.')
plt.show()

#dG0_prime, dG0_std = model.get_transformed_dG0(pH=7.5, I=0.2, T=298.15)

Exemplo n.º 6
0
cid2dG0 = {}
if not os.path.exists(REPORT_CACHE_FNAME):
    fp = open(REPORT_CACHE_FNAME, 'w')
    cc = ComponentContribution()
    cc.train()
    csv_out = csv.writer(fp)
    csv_out.writerow(['cid', 'dG0_f'])
    for compound_id in cc.ccache.get_all_compound_ids():
        dG0_f = cc.get_major_ms_dG0_f(compound_id)
        csv_out.writerow([compound_id, '%8.2f' % dG0_f])
        cid2dG0[compound_id] = dG0_f
else:
    for row in csv.DictReader(open(REPORT_CACHE_FNAME, 'r')):
        cid2dG0[row['cid']] = float(row['dG0_f'])

REACTION_FNAME = 'tests/report_gc_reactions.txt'
reaction_strings = open(REACTION_FNAME, 'r').readlines()
model = KeggModel.from_formulas(reaction_strings)

# compare the dG0_r of the model to the one we get if multiplying
# the model stoichiometric matrix by the formation energies
model_dG0_f = np.matrix([cid2dG0[cid] for cid in model.cids]).T
model_dG0_r = model.S.T * model_dG0_f

cc2 = ComponentContribution()
model.add_thermo(cc2)
plt.plot(model.dG0, model_dG0_r, '.')
plt.show()

#dG0_prime, dG0_std = model.get_transformed_dG0(pH=7.5, I=0.2, T=298.15)