Commit e4bb6092 authored by Elad Noor's avatar Elad Noor

isort & flake8

parent 34cd517e
Pipeline #49961152 passed with stages
in 20 minutes and 35 seconds
......@@ -34,31 +34,10 @@ import numpy as np
import pandas as pd
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Calculate potentials for a number of reactions.')
parser.add_argument('infile', type=argparse.FileType('r'),
help='path to input file containing reactions (TXT format)')
parser.add_argument('outfile', type=argparse.FileType('w'),
help='path to output file (CSV format)')
parser.add_argument('--plaintext', action='store_true',
help="indicate that reactions are given in plain text"
" (not accessions)")
parser.add_argument('--ph', type=str,
help='pH level',
default="7.0")
parser.add_argument('--i', type=str,
help='ionic strength (in molar, default 0.25 M)',
default="0.25M")
parser.add_argument('--t', type=str,
help='temperature (in kalvin, default 298.15 K)',
default="298.15K")
logging.getLogger().setLevel(logging.WARNING)
args = parser.parse_args()
from equilibrator_api import Q_, ComponentContribution, Reaction, ureg
def main(args):
"""Run main script, calculates the reaction Gibbs energy change."""
from equilibrator_api import (
Q_, ComponentContribution, Reaction, ureg) # isort:skip
ureg.default_format = ".2f"
p_h = Q_(args.ph)
......@@ -110,7 +89,29 @@ if __name__ == '__main__':
result_df.loc[non_balanced, "ln(Reversibility index)"] = np.nan
result_df.loc[non_balanced, "comment"] = ("reaction is not chemically "
"balanced")
result_df.to_csv(args.outfile)
args.outfile.flush()
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Calculate potentials for a number of reactions.')
parser.add_argument('infile', type=argparse.FileType('r'),
help='path to file containing reactions (TXT format)')
parser.add_argument('outfile', type=argparse.FileType('w'),
help='path to result file (CSV format)')
parser.add_argument('--plaintext', action='store_true',
help="indicate that reactions are given in plain text"
" (not accessions)")
parser.add_argument('--ph', type=str,
help='pH level',
default="7.0")
parser.add_argument('--i', type=str,
help='ionic strength (in molar, default 0.25 M)',
default="0.25M")
parser.add_argument('--t', type=str,
help='temperature (in kalvin, default 298.15 K)',
default="298.15K")
logging.getLogger().setLevel(logging.WARNING)
args = parser.parse_args()
......@@ -51,71 +51,79 @@ def MakeParser():
parser.add_argument('--t', type=str,
help='temperature (in kalvin, default 298.15 K)',
default="298.15K")
parser.add_argument('reaction', type=str, help='chemical formula using accessions')
parser.add_argument('reaction', type=str,
help='chemical formula using accessions')
return parser
###############################################################################
parser = MakeParser()
args = parser.parse_args()
logging.getLogger().setLevel(logging.WARNING)
from equilibrator_api import Q_, ComponentContribution, Reaction, ureg
ureg.default_format = ".2f"
p_h = Q_(args.ph)
assert p_h.check(None)
ionic_strength = Q_(args.i)
if ionic_strength.check(None):
ionic_strength *= Q_("M")
else:
assert ionic_strength.check("[concentration]")
temperature = Q_(args.t)
if temperature.check(None):
temperature *= Q_("K")
else:
assert temperature.check("[temperature]")
sys.stderr.write(f"pH = {p_h}\n")
sys.stderr.write(f"I = {ionic_strength:.2g}\n")
sys.stderr.write(f"T = {temperature}\n")
sys.stderr.flush()
# parse the reaction
try:
reaction = Reaction.parse_formula(args.reaction)
except ValueError as e:
logging.error(str(e))
sys.exit(-1)
equilibrator = ComponentContribution(p_h=p_h, ionic_strength=ionic_strength)
n_e = reaction.check_half_reaction_balancing()
if n_e is None:
sys.stderr.write(f"This reaction is not chemically balanced:\n")
atom_bag = reaction._get_reaction_atom_bag()
for atom, count in atom_bag.items():
if count < 0:
sys.stderr.write(f"* {abs(count):g} extra '{atom}'s on the left-hand side\n")
else:
sys.stderr.write(f"* {abs(count):g} extra '{atom}'s on the right-hand side\n")
sys.exit(-1)
elif n_e == 0:
standard_dg_prime, dg_uncertainty = equilibrator.standard_dg_prime(reaction)
sys.stdout.write(f"ΔG'° = {standard_dg_prime} ± {1.96*dg_uncertainty} *\n")
ln_RI = equilibrator.ln_reversibility_index(reaction)
sys.stdout.write(f"ln(Reversibility Index) = {ln_RI}\n")
else: # treat as a half-reaction
logging.warning('This reaction isn\'t balanced, but can still be treated'
' as a half-reaction')
standard_e_prime, e_uncertainty = equilibrator.standard_e_prime(reaction)
sys.stdout.write(f"E'° = {standard_e_prime} ± {e_uncertainty}\n")
sys.stdout.flush()
sys.stderr.write(r'* the range represents the 95% confidence interval'
' due to Component Contribution estimation uncertainty\n')
def main(args):
"""Run main script, calculates the reaction Gibbs energy change."""
logging.getLogger().setLevel(logging.WARNING)
from equilibrator_api import (
Q_, ComponentContribution, Reaction, ureg) # isort:skip
ureg.default_format = ".2f"
p_h = Q_(args.ph)
assert p_h.check(None)
ionic_strength = Q_(args.i)
if ionic_strength.check(None):
ionic_strength *= Q_("M")
else:
assert ionic_strength.check("[concentration]")
temperature = Q_(args.t)
if temperature.check(None):
temperature *= Q_("K")
else:
assert temperature.check("[temperature]")
sys.stderr.write(f"pH = {p_h}\n")
sys.stderr.write(f"I = {ionic_strength:.2g}\n")
sys.stderr.write(f"T = {temperature}\n")
sys.stderr.flush()
# parse the reaction
try:
reaction = Reaction.parse_formula(args.reaction)
except ValueError as e:
logging.error(str(e))
sys.exit(-1)
equilibrator = ComponentContribution(p_h=p_h,
ionic_strength=ionic_strength)
n_e = reaction.check_half_reaction_balancing()
if n_e is None:
sys.stderr.write(f"This reaction is not chemically balanced:\n")
atom_bag = reaction._get_reaction_atom_bag()
for atom, count in atom_bag.items():
side = "left" if count < 0 else "right"
sys.stderr.write(
f"* {abs(count):g} extra '{atom}'s on the {side}-hand side\n")
sys.exit(-1)
elif n_e == 0:
standard_dg_prime, dg_uncertainty = \
equilibrator.standard_dg_prime(reaction)
sys.stdout.write(
f"ΔG'° = {standard_dg_prime} ± {1.96*dg_uncertainty} *\n")
ln_RI = equilibrator.ln_reversibility_index(reaction)
sys.stdout.write(f"ln(Reversibility Index) = {ln_RI}\n")
else: # treat as a half-reaction
logging.warning('This reaction isn\'t balanced, but can still be '
' left as a half-reaction')
standard_e_prime, e_uncertainty = \
equilibrator.standard_e_prime(reaction)
sys.stdout.write(f"E'° = {standard_e_prime} ± {e_uncertainty}\n")
sys.stdout.flush()
sys.stderr.write(r'* the range represents the 95% confidence interval'
' due to Component Contribution estimation uncertainty\n')
if __name__ == "__main__":
parser = MakeParser()
args = parser.parse_args()
main(args)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment