Commit 48680f5e authored by eladnoor's avatar eladnoor

yet more small changes regarding pint

parent 0d04168f
......@@ -39,22 +39,21 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='Calculate potentials for a number of reactions.')
parser.add_argument(
'infile', type=argparse.FileType(),
parser.add_argument('infile', type=argparse.FileType(),
help='path to input file containing reactions')
parser.add_argument(
'--plaintext', action='store_true',
help='indicate that reactions are given in plain text (not KEGG IDs)')
parser.add_argument(
'outfile', type=argparse.FileType('w'),
parser.add_argument('outfile', type=argparse.FileType('w'),
help='path to output file')
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',
default="0.1 M")
default="0.25M")
parser.add_argument('--t', type=str,
help='ionic strength',
default="298.15 K")
parser.add_argument('--ph', type=float, help='pH level', default=7.0)
default="298.15K")
logging.getLogger().setLevel(logging.WARNING)
args = parser.parse_args()
......@@ -77,6 +76,7 @@ if __name__ == '__main__':
sys.stderr.write('pH = %s\n' % p_h)
sys.stderr.write('I = %s\n' % ionic_strength)
sys.stderr.write('T = %s\n' % temperature)
sys.stderr.flush()
infile_lines = list(filter(None, map(str.strip, args.infile.readlines())))
......
......@@ -9,16 +9,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"from equilibrator_api import ComponentContribution, Reaction, ccache, ureg"
"from equilibrator_api import ComponentContribution, Reaction, ccache, Q_"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 6,
"metadata": {},
"outputs": [
{
......@@ -26,13 +26,13 @@
"output_type": "stream",
"text": [
"MNXM2 + MNXM3 = MNXM7 + MNXM9\n",
"ΔG'° = -26369.829368611856 joule / mole ± 308.0507323351917 joule / mole\n",
"ΔG'm = -43484.666903332894 joule / mole ± 308.0507323351917 joule / mole\n",
"Concentrations:\n",
"ΔG'° = -25.770698956711307 kilojoule / mole ± 0.6090984397505056 kilojoule / mole\n",
"ΔG'm = -42.88553649143234 kilojoule / mole ± 0.6090984397505056 kilojoule / mole\n",
"Reactant concentrations:\n",
"MNXM3 : 1.0 millimolar\n",
"MNXM9 : 0.1 millimolar\n",
"MNXM7 : 3.0 millimolar\n",
"ΔG' = -46467.661828610144 joule / mole ± 308.0507323351917 joule / mole\n"
"ΔG' = -45.86853141670959 kilojoule / mole ± 0.6090984397505056 kilojoule / mole\n"
]
}
],
......@@ -40,25 +40,25 @@
"kegg_id_to_coeff = {'C00002' : -1, 'C00001' : -1,\n",
" 'C00008' : 1, 'C00009' : 1} # ATP + H2O = ADP + Pi\n",
"reaction = Reaction.parse_formula(\"KEGG:C00002 + KEGG:C00001 = KEGG:C00008 + KEGG:C00009\")\n",
"cc = ComponentContribution(p_h=7.0, ionic_strength=ureg(\"0.1 M\"))\n",
"cc = ComponentContribution(p_h=Q_(7.0), ionic_strength=Q_(\"0.25M\"), temperature=Q_(\"298.15K\"))\n",
"\n",
"print(reaction)\n",
"dG0_prime, uncertainty = cc.standard_dg_prime(reaction)\n",
"print(f\"ΔG'° = {dG0_prime} ± {uncertainty}\")\n",
"print(f\"ΔG'° = {dG0_prime} ± {1.96*uncertainty}\")\n",
"\n",
"dGm_prime, uncertainty = cc.physiological_dg_prime(reaction)\n",
"print(f\"ΔG'm = {dGm_prime} ± {uncertainty}\")\n",
"print(f\"ΔG'm = {dGm_prime} ± {1.96*uncertainty}\")\n",
"\n",
"concentrations = [('KEGG:C00002', ureg(\"1.0 mM\")),\n",
" ('KEGG:C00009', ureg(\"0.1 mM\")),\n",
" ('KEGG:C00008', ureg(\"3.0 mM\"))]\n",
"concentrations = [('KEGG:C00002', Q_(\"1.0 mM\")),\n",
" ('KEGG:C00009', Q_(\"0.1 mM\")),\n",
" ('KEGG:C00008', Q_(\"3.0 mM\"))]\n",
"compound_to_conc = {ccache.get_compound(x[0]): x[1] for x in concentrations}\n",
"\n",
"print('Concentrations:')\n",
"print('Reactant concentrations:')\n",
"for compound, conc in compound_to_conc.items():\n",
" print(f\"{compound} : {conc}\")\n",
"dG_prime, uncertainty = cc.dg_prime(reaction, compound_to_conc)\n",
"print(f\"ΔG' = {dG_prime} ± {uncertainty}\")\n"
"print(f\"ΔG' = {dG_prime} ± {1.96*uncertainty}\")\n"
]
},
{
......@@ -70,23 +70,23 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"from equilibrator_api import Reaction, Pathway, Bounds, ComponentContribution, R, ureg"
"from equilibrator_api import Reaction, Pathway, Bounds, ComponentContribution, R, Q_"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MDF = 11.58 kJ/mol\n"
"MDF = 12.200665544421918 RT\n"
]
},
{
......@@ -129,7 +129,7 @@
" <tr>\n",
" <th>1</th>\n",
" <td>MNXM5</td>\n",
" <td>0.010000000000000014 molar</td>\n",
" <td>0.009999999999999995 molar</td>\n",
" <td>5.000000e-01</td>\n",
" <td>1 micromolar</td>\n",
" <td>10 millimolar</td>\n",
......@@ -137,7 +137,7 @@
" <tr>\n",
" <th>2</th>\n",
" <td>MNXM6</td>\n",
" <td>1.0000000000000004e-06 molar</td>\n",
" <td>9.99999999999997e-07 molar</td>\n",
" <td>-5.000000e-01</td>\n",
" <td>1 micromolar</td>\n",
" <td>10 millimolar</td>\n",
......@@ -145,7 +145,7 @@
" <tr>\n",
" <th>3</th>\n",
" <td>MNXM13</td>\n",
" <td>0.0008044483885525074 molar</td>\n",
" <td>0.0006938829409187895 molar</td>\n",
" <td>-5.551115e-17</td>\n",
" <td>1 micromolar</td>\n",
" <td>10 millimolar</td>\n",
......@@ -161,7 +161,7 @@
" <tr>\n",
" <th>5</th>\n",
" <td>MNXM160</td>\n",
" <td>0.010000000000000004 molar</td>\n",
" <td>0.009999999999999995 molar</td>\n",
" <td>5.000000e-01</td>\n",
" <td>1 micromolar</td>\n",
" <td>10 millimolar</td>\n",
......@@ -169,7 +169,7 @@
" <tr>\n",
" <th>6</th>\n",
" <td>MNXM325</td>\n",
" <td>1.0000000000000004e-06 molar</td>\n",
" <td>1.0000000000000023e-06 molar</td>\n",
" <td>-5.000000e-01</td>\n",
" <td>1 micromolar</td>\n",
" <td>10 millimolar</td>\n",
......@@ -177,7 +177,7 @@
" <tr>\n",
" <th>7</th>\n",
" <td>MNXM429</td>\n",
" <td>0.0022874077755825365 molar</td>\n",
" <td>0.002549891200999209 molar</td>\n",
" <td>0.000000e+00</td>\n",
" <td>1 micromolar</td>\n",
" <td>10 millimolar</td>\n",
......@@ -189,13 +189,13 @@
"text/plain": [
" compound concentration shadow_price lower_bound \\\n",
"0 MNXM2 0.010000000000000004 molar 5.000000e-01 1 micromolar \n",
"1 MNXM5 0.010000000000000014 molar 5.000000e-01 1 micromolar \n",
"2 MNXM6 1.0000000000000004e-06 molar -5.000000e-01 1 micromolar \n",
"3 MNXM13 0.0008044483885525074 molar -5.551115e-17 1 micromolar \n",
"1 MNXM5 0.009999999999999995 molar 5.000000e-01 1 micromolar \n",
"2 MNXM6 9.99999999999997e-07 molar -5.000000e-01 1 micromolar \n",
"3 MNXM13 0.0006938829409187895 molar -5.551115e-17 1 micromolar \n",
"4 MNXM145 1.0000000000000004e-06 molar -5.551115e-17 1 micromolar \n",
"5 MNXM160 0.010000000000000004 molar 5.000000e-01 1 micromolar \n",
"6 MNXM325 1.0000000000000004e-06 molar -5.000000e-01 1 micromolar \n",
"7 MNXM429 0.0022874077755825365 molar 0.000000e+00 1 micromolar \n",
"5 MNXM160 0.009999999999999995 molar 5.000000e-01 1 micromolar \n",
"6 MNXM325 1.0000000000000023e-06 molar -5.000000e-01 1 micromolar \n",
"7 MNXM429 0.002549891200999209 molar 0.000000e+00 1 micromolar \n",
"\n",
" upper_bound \n",
"0 10 millimolar \n",
......@@ -208,25 +208,27 @@
"7 10 millimolar "
]
},
"execution_count": 13,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cc = ComponentContribution(p_h=7.0, ionic_strength=ureg(\"0.1 M\"))\n",
"p_h = Q_(\"7.0\")\n",
"temperature = Q_(\"298.15K\")\n",
"ionic_strength = Q_(\"0.25M\")\n",
"cc = ComponentContribution(p_h=p_h, ionic_strength=ionic_strength, temperature=temperature)\n",
"reactions = ['KEGG:C00092 + KEGG:C00006 <=> KEGG:C01236 + KEGG:C00005',\n",
" 'KEGG:C01236 + KEGG:C00001 <=> KEGG:C00345',\n",
" 'KEGG:C00345 + KEGG:C00006 <=> KEGG:C00199 + KEGG:C00011 + KEGG:C00005']\n",
"reactions = list(map(Reaction.parse_formula, reactions))\n",
"fluxes = [1.0, 1.0, 1.0]\n",
"T = ureg(\"298.15 K\")\n",
"standard_dg_primes = [float(cc.standard_dg_prime(r)[0]/(R*T)) for r in reactions]\n",
"bounds = Bounds(default_lb=ureg(\"1 uM\"), default_ub=ureg(\"10 mM\"))\n",
"standard_dg_primes = [float(cc.standard_dg_prime(r)[0]/(R*temperature)) for r in reactions]\n",
"bounds = Bounds(default_lb=Q_(\"1 uM\"), default_ub=Q_(\"10 mM\"))\n",
"pp = Pathway(reactions, fluxes, standard_dg_primes, bounds=bounds)\n",
"\n",
"mdf_data = pp.calc_mdf()\n",
"print('MDF = %.2f kJ/mol' % mdf_data.mdf)\n",
"print('MDF = %s RT' % mdf_data.mdf)\n",
"mdf_data.compound_df"
]
},
......
......@@ -33,7 +33,7 @@ import argparse
import logging
import sys
from equilibrator_api import ComponentContribution, Reaction, ureg
from equilibrator_api import ComponentContribution, Reaction, Q_
def MakeParser():
......@@ -42,10 +42,15 @@ def MakeParser():
'the following calculates dGr0 for ATP hydrolysis '
'at pH 6: equlibrator_cmd.py --ph 6 "KEGG:C00002 + '
'KEGG:C00001 = KEGG:C00008 + KEGG:C00009"'))
parser.add_argument('--ph', type=float, help='pH level', default=7.0)
parser.add_argument('--i', type=float,
help='ionic strength in M',
default=0.1)
parser.add_argument('--ph', type=str,
help='pH level',
default="7.0")
parser.add_argument('--i', type=str,
help='ionic strength',
default="0.25M")
parser.add_argument('--t', type=str,
help='ionic strength',
default="298.15K")
parser.add_argument('reaction', type=str, help='reaction in KEGG notation')
return parser
......@@ -56,12 +61,24 @@ args = parser.parse_args()
logging.getLogger().setLevel(logging.WARNING)
p_h = args.ph
ionic_strength = args.i * ureg.molar
p_h = Q_(args.ph)
assert p_h.check(None)
sys.stderr.write('pH = %.1f\n' % p_h)
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('pH = %s\n' % p_h)
sys.stderr.write('I = %s\n' % ionic_strength)
sys.stderr.write('Reaction: %s\n' % args.reaction)
sys.stderr.write('T = %s\n' % temperature)
sys.stderr.flush()
# parse the reaction
......@@ -78,20 +95,17 @@ if n_e is None:
logging.error('reaction is not chemically balanced')
sys.exit(-1)
elif n_e == 0:
dG0_prime, dG0_uncertainty = equilibrator.standard_dg_prime(reaction)
sys.stdout.write(u'\u0394G\'\u00B0 = %s \u00B1 %s\n' %
(dG0_prime, dG0_uncertainty))
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(u'ln(Reversibility Index) = %.1f\n' % ln_RI)
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')
E0_prime_mV, E0_uncertainty = equilibrator.standard_e_prime(reaction)
sys.stdout.write(
u'E\'\u00B0 = %s \u00B1 %s\n' %
(E0_prime_mV, E0_uncertainty))
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'
......
......@@ -50,12 +50,13 @@ if __name__ == '__main__':
pp = Pathway.from_sbtab(args.infile)
output_pdf = PdfPages(args.outfile)
mdf_res = pp.calc_mdf()
output_pdf.savefig(mdf_res.compound_plot)
output_pdf.savefig(mdf_res.reaction_plot)
output_pdf.close()
with PdfPages(args.outfile) as pdf:
pdf.savefig(mdf_res.compound_plot)
pdf.savefig(mdf_res.reaction_plot)
net_rxn = pp.net_reaction()
rxn_df = mdf_res.reaction_df
cpd_df = mdf_res.compound_df
......@@ -34,8 +34,8 @@ install_requires =
sbtab>=0.9.49
matplotlib>=3.0.0
requests
equilibrator-cache>=0.1.5
component-contribution>=0.1.1
equilibrator-cache>=0.1.6
component-contribution>=0.1.2
python_requires = >=3.6
tests_require =
tox
......
......@@ -64,6 +64,34 @@ class BaseBounds(object):
"""
raise NotImplementedError
def GetLowerBounds(
self,
compounds: Iterable[Compound]
) -> Iterable[float]:
"""Get the bounds for a set of keys in order
Args:
keys: an iterable of keys
Returns:
An iterable of the lower bounds
"""
return map(self.GetLowerBound, compounds)
def GetUpperBounds(
self,
compounds: Iterable[Compound]
) -> Iterable[float]:
"""Get the bounds for a set of keys in order
Args:
keys: an iterable of keys
Returns:
An iterable of the upper bounds
"""
return map(self.GetUpperBound, compounds)
def GetBoundTuple(self, compound: Compound):
"""Get both upper and lower bounds for this key
Args:
......@@ -110,6 +138,39 @@ class BaseBounds(object):
b2log = lambda b: log(b / standard_concentration)
return map(b2log, lbs), map(b2log, ubs)
def GetLnLowerBounds(
self,
compounds: Iterable[Compound]
) -> Iterable[float]:
"""Get the bounds for a set of keys in order
Args:
keys: an iterable of keys
Returns:
An iterable of the log-scaled lower bounds
"""
lbs = self.GetLowerBounds(compounds)
b2log = lambda b: log(b / standard_concentration)
return map(b2log, lbs)
def GetLnUpperBounds(
self,
compounds: Iterable[Compound]
) -> Iterable[float]:
"""Get the bounds for a set of keys in order
Args:
keys: an iterable of keys
Returns:
An iterable of the log-scaled upper bounds
"""
ubs = self.GetUpperBounds(compounds)
b2log = lambda b: log(b / standard_concentration)
return map(b2log, ubs)
@ureg.check(None, None, '[concentration]', '[concentration]')
def SetBounds(self, compound: Compound, lb: float, ub: float):
"""Set bounds for a specific key
......
......@@ -34,7 +34,8 @@ from equilibrator_cache.reaction import (
create_stoichiometric_matrix_from_reactions)
from sbtab import SBtab
from . import Compound, ccache, ureg
from . import Compound, ccache
from .settings import ureg, Q_, R, default_T
from .bounds import Bounds
from .component_contribution import ComponentContribution
from .phased_reaction import PhasedReaction
......@@ -63,11 +64,12 @@ class Pathway(object):
Designed for checking input prior to converting to a stoichiometric model.
"""
@ureg.check(None, None, None, "[energy]/[substance]", "[energy]/[substance]", None)
def __init__(self,
reactions: List[PhasedReaction],
fluxes: Iterable[float],
standard_dg_primes: Iterable[float],
dg_uncertainties: np.array = None,
fluxes: np.array,
standard_dg_primes: np.array,
dg_uncertainties: np.array,
bounds: Bounds = None
) -> object:
"""Initialize.
......@@ -83,19 +85,18 @@ class Pathway(object):
self.reactions = reactions
Nr = len(reactions)
self.fluxes = np.array(list(fluxes))
self.standard_dg_primes = np.array(list(standard_dg_primes))
self.fluxes = fluxes
self.standard_dg_primes = standard_dg_primes
assert self.fluxes.shape == (Nr, )
assert self.standard_dg_primes.shape == (Nr,)
if dg_uncertainties is None:
self.dg_uncertainties = np.zeros((len(reactions), len(reactions)))
else:
assert dg_uncertainties.shape == (Nr, Nr)
self.dg_uncertainties = dg_uncertainties
assert dg_uncertainties.shape == (Nr, Nr)
self.dg_uncertainties = dg_uncertainties
phys_corr = np.array(
[float(r.physiological_dg_correction()) for r in reactions])
[float(r.physiological_dg_correction()) for r in reactions]) * R \
* default_T
self.physiological_dg_prime = self.standard_dg_primes + phys_corr
if bounds is None:
......@@ -116,8 +117,8 @@ class Pathway(object):
S_T = self.S.T.values
S_inv = np.linalg.pinv(S_T)
null_proj = np.eye(self.S.shape[1]) - S_T @ S_inv
projected = null_proj * self.standard_dg_primes.T
if (projected > 1e-8).any():
projected = null_proj @ self.standard_dg_primes.T
if (projected > Q_("1e-8 kJ/mol")).any():
raise ViolatesFirstLaw(
'Supplied reaction dG values are inconsistent '
'with the stoichiometric matrix.')
......@@ -139,8 +140,26 @@ class Pathway(object):
return self._bounds.GetBounds(self.S.index)
@property
def ln_bounds(self) -> Tuple[Iterable[float], Iterable[float]]:
return self._bounds.GetLnBounds(self.S.index)
def ln_conc_lb(self) -> np.array:
return np.array(list(map(float,
self._bounds.GetLnLowerBounds(self.S.index))))
@property
def ln_conc_ub(self) -> np.array:
return np.array(list(map(float,
self._bounds.GetLnUpperBounds(self.S.index))))
@property
def standard_dg_prime_over_rt(self) -> np.array:
dg_over_rt = self.standard_dg_primes / (R * default_T)
return np.array(list(map(float, dg_over_rt.flat))).reshape(
dg_over_rt.shape)
@property
def dg_uncertainty_prime_over_rt(self) -> np.array:
u_over_rt = self.dg_uncertainties / (R * default_T)
return np.array(list(map(float, u_over_rt.flat))).reshape(
u_over_rt.shape)
@classmethod
def from_csv_file(cls,
......@@ -197,7 +216,8 @@ class Pathway(object):
return map(str, self.reactions)
def net_reaction(self) -> PhasedReaction:
net_rxn_stoich = self.S @ self.fluxes.T
v = np.array(list(map(float, self.fluxes)))
net_rxn_stoich = self.S @ v
net_rxn_stoich = net_rxn_stoich[net_rxn_stoich != 0]
sparse = net_rxn_stoich.to_dict()
return PhasedReaction(sparse)
......@@ -225,7 +245,7 @@ class Pathway(object):
% table_id)
dfs.append(sbtab.to_data_frame())
bounds_df, reaction_df, flux_df, keqs_df = dfs
bounds_df, reaction_df, flux_df, param_df = dfs
# TODO support also other identifiers (i.e. parse the column name and
# use the last string as the registry name)
......@@ -255,21 +275,23 @@ class Pathway(object):
reactions.append(rxn)
reaction_ids = reaction_df['ID']
fluxes = flux_df[flux_df['QuantityType'] == 'flux']
reaction_fluxes = dict(zip(fluxes['Reaction'], fluxes['Value']))
fluxes_ordered = [float(reaction_fluxes[rid]) for rid in reaction_ids]
# grab rows containing keqs.
keqs = keqs_df[keqs_df['QuantityType'] == 'equilibrium constant']
reaction_keqs = dict(zip(keqs['Reaction'], keqs['Value']))
flux_df = flux_df[flux_df['QuantityType'] == 'flux'
].set_index('Reaction')['Value'].apply(float)
v = np.array(flux_df.loc[reaction_ids].tolist()) * Q_("dimensionless")
# grab rows containing keqs and calculate the standard Gibbs
# reaction energies from the equilibrium constants, in units of RT
keq_df = param_df[param_df['QuantityType'] == 'equilibrium constant'
].set_index('Reaction')['Value'].apply(float)
keq = np.array(keq_df.loc[reaction_ids].tolist()) * Q_("dimensionless")
standard_dg_primes = -np.log(keq) * R * default_T
# calculate the standard Gibbs reaction energies from the equilibrium
# constants, in units of RT
standard_dg_primes = [-np.log(float(reaction_keqs[rid]))
for rid in reaction_ids]
dg_uncertainties = np.zeros((len(reactions), len(reactions))) * Q_("kJ/mol")
pp = Pathway(reactions, fluxes_ordered, standard_dg_primes,
bounds=bounds)
pp = Pathway(reactions, v, standard_dg_primes,
dg_uncertainties, bounds=bounds)
# override the compound names with the ones in the SBtab
pp.set_compound_names(compound_to_name.get)
......
......@@ -27,10 +27,10 @@
from equilibrator_cache.thermodynamic_constants import (
FARADAY, POSSIBLE_REACTION_ARROWS, Q_, R, Rlog10, default_I, default_pH,
default_T, physiological_concentration, standard_concentration)
default_T, physiological_concentration, standard_concentration, ureg)
default_pMg = Q_("14.0")
default_phase = 'aqueous'
default_conc_lb = Q_("1e-6 M")
default_conc_ub = Q_("1e-2 M")
default_conc_ub = Q_("1e-2 M")
\ No newline at end of file
This diff is collapsed.
......@@ -6,3 +6,10 @@ Created on Thu Aug 10 17:28:18 2017
@author: noore
"""
import pytest
def approx_unit(obs: float, exp: float, rel=None, abs=None):
assert obs.check(exp.units)
obs = float(obs / exp.units)
exp = float(exp / exp.units)
assert obs == pytest.approx(exp, rel=rel, abs=abs)
......@@ -31,13 +31,12 @@ import warnings
import pytest
from equilibrator_api import Pathway, Reaction
from equilibrator_api import Pathway, Reaction, Q_
from . import approx_unit
TEST_DIR = os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe())))
def test_mdf():
warnings.simplefilter('ignore', ResourceWarning)
......@@ -52,7 +51,7 @@ def test_mdf():
"2 KEGG:C00002 + 2 KEGG:C00001 + 2 KEGG:C00469 + 2 KEGG:C00011")
assert net_rxn == reference_net_rxn
assert pp_mdf_data.mdf == pytest.approx(0.682, rel=1e-2)
approx_unit(pp_mdf_data.mdf, Q_("1.69 kJ/mol"), abs=0.1)
shadow_prices = pp_mdf_data.reaction_df.set_index(
'reaction_id').shadow_price
......
......@@ -30,12 +30,7 @@ import warnings
import pytest
from equilibrator_api import Q_, ComponentContribution, Reaction, ccache
def assert_with_unit(obs_dg: float, exp_dg: float, abs: float = 1e-1,
unit: str = "kJ/mol"):
assert obs_dg.check(unit)
assert float(obs_dg / Q_(unit)) == pytest.approx(float(exp_dg), abs=abs)
from . import approx_unit
@pytest.fixture(scope="module")
......@@ -56,15 +51,15 @@ def test_gibbs_energy_atp_hydrolysis(comp_contribution):
standard_dg_prime, dg_uncertainty = comp_contribution.standard_dg_prime(
reaction)
assert_with_unit(standard_dg_prime, -26.4)
assert_with_unit(dg_uncertainty, 0.3)
approx_unit(standard_dg_prime, Q_("-26.4 kJ/mol"), abs=0.1)
approx_unit(dg_uncertainty, Q_("0.3 kJ/mol"), abs=0.1)
dg_prime, _ = comp_contribution.dg_prime(reaction, compound_to_conc)
assert_with_unit(dg_prime, -32.1)
approx_unit(dg_prime, Q_("-32.1 kJ/mol"), abs=0.1)
physiological_dg_prime, _ = comp_contribution.physiological_dg_prime(
reaction)
assert_with_unit(physiological_dg_prime, -43.5)
approx_unit(physiological_dg_prime, Q_("-43.5 kJ/mol"), abs=0.1)
def test_gibbs_energy_pyruvate_decarboxylase(comp_contribution):
......@@ -77,8 +72,8 @@ def test_gibbs_energy_pyruvate_decarboxylase(comp_contribution):
standard_dg_prime, dg_uncertainty = comp_contribution.standard_dg_prime(
reaction)
assert_with_unit(standard_dg_prime, -18.4)
assert_with_unit(dg_uncertainty, 3.3)
approx_unit(standard_dg_prime, Q_("-18.4 kJ/mol"), abs=0.1)
approx_unit(dg_uncertainty, Q_("3.3 kJ/mol"), abs=0.1)
def test_reduction_potential(comp_contribution):
......@@ -91,8 +86,8 @@ def test_reduction_potential(comp_contribution):
standard_e_prime, e_uncertainty = comp_contribution.standard_e_prime(
reaction)
assert_with_unit(standard_e_prime, -175.0, unit="mV")
assert_with_unit(e_uncertainty, 3.3, unit="mV")
approx_unit(standard_e_prime, Q_("-175.0 mV"), abs=1.0)
approx_unit(e_uncertainty, Q_("3.3 mV"), abs=1.0)
def test_unresolved_reactions(comp_contribution):
......
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