Commit e43b13fc authored by eladnoor's avatar eladnoor

removing pint warnings

parent 0da1bfbf
Pipeline #47233916 (#120) passed with stage
in 17 minutes and 46 seconds
......@@ -24,7 +24,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from ._version import get_versions
__version__ = get_versions()['version']
del get_versions
......@@ -36,3 +35,4 @@ from equilibrator_api.pathway import Pathway
from equilibrator_api.phased_reaction import PhasedReaction as Reaction
from equilibrator_api.component_contribution import ComponentContribution
from equilibrator_api.thermo_models import PathwayThermoModel
......@@ -75,12 +75,13 @@ class ComponentContribution(object):
U as the covariance of a Gaussian used for sampling
(where dG0_cc is the mean of that Gaussian).
"""
rxn_aquoues, dg_prime_nonaq = zip(
rxn_aquoues, dg_prime_nonaq = zip(*
[reaction.split_aqueous_phase(
p_h=self.p_h,
ionic_strength=self.ionic_strength,
temperature=self.temperature)
for reaction in reactions])
dg_prime_nonaq = np.array(dg_prime_nonaq)
standard_dg_prime, dg_sigma = self.predictor.standard_dg_prime_multi(
rxn_aquoues,
......@@ -88,7 +89,7 @@ class ComponentContribution(object):
ionic_strength=self.ionic_strength,
temperature=self.temperature
)
return standard_dg_prime + dg_prime_nonaq, dg_sigma
return standard_dg_prime + dg_prime_nonaq * self.RT, dg_sigma
def standard_dg_prime(
self,
......@@ -114,7 +115,7 @@ class ComponentContribution(object):
temperature=self.temperature
)
return standard_dg_prime + dg_prime_nonaq, dg_sigma
return standard_dg_prime + dg_prime_nonaq * self.RT, dg_sigma
def dg_prime(
self,
......
......@@ -27,6 +27,7 @@
import csv
import logging
import warnings
from io import IOBase
from typing import Callable, Iterable, List, TextIO, Tuple
......@@ -40,7 +41,8 @@ from . import Compound
from .bounds import Bounds
from .component_contribution import ComponentContribution
from .phased_reaction import PhasedReaction
from .settings import Q_, R, default_I, default_pH, default_pMg, default_T, ureg
from .settings import (
Q_, R, default_I, default_pH, default_pMg, default_T, strip_units)
from .thermo_models import PathwayThermoModel
......@@ -101,6 +103,7 @@ class Pathway(object):
self.fluxes = fluxes
assert self.fluxes.shape == (Nr, )
self.comp_contrib = None
if standard_dg_primes is None:
assert dg_sigma is None, ("If standard_dg_primes are not "
"provided, dg_sigme must also be None")
......@@ -136,20 +139,40 @@ class Pathway(object):
def set_aqueous_params(
self,
p_h: float = default_pH,
p_mg: float = default_pMg,
ionic_strength: float = default_I,
temperature: float = default_T
p_h: float = None,
p_mg: float = None,
ionic_strength: float = None,
temperature: float = None
) -> None:
comp_contribution = ComponentContribution(
p_h=p_h, p_mg=p_mg, ionic_strength=ionic_strength,
temperature=temperature)
if self.comp_contrib is None:
p_h = p_h or default_pH
p_mg = p_mg or default_pMg
ionic_strength = ionic_strength or default_I
temperature = temperature or default_T
self.comp_contrib = ComponentContribution(
p_h=p_h, p_mg=p_mg, ionic_strength=ionic_strength,
temperature=temperature
)
else:
if p_h is not None:
self.comp_contrib.p_h = p_h
if p_mg is not None:
self.comp_contrib.p_mg = p_mg
if ionic_strength is not None:
self.comp_contrib.ionic_strength = ionic_strength
if temperature is not None:
self.comp_contrib.temperature = temperature
RT = R * self.comp_contrib.temperature
standard_dg_primes, dg_uncertainties = \
comp_contribution.standard_dg_prime_multi(self.reactions)
self.comp_contrib.standard_dg_prime_multi(self.reactions)
self.standard_dg_primes = strip_units(standard_dg_primes / RT)
self.standard_dg_primes = standard_dg_primes / (R * temperature)
self.dg_sigma = fractional_matrix_power(
dg_uncertainties / (R * temperature) ** 2, 0.5)
dg_uncertainties /= RT ** 2
dg_uncertainties = strip_units(dg_uncertainties)
self.dg_sigma = fractional_matrix_power(dg_uncertainties, 0.5)
def set_compound_names(
self,
......@@ -294,7 +317,7 @@ class Pathway(object):
if not rxn.is_balanced(fix_protons=True,
fix_water=True,
raise_exception=False):
logging.warning(f"Reaction {rxn.rid} is not balanced")
warnings.warn(f"Reaction {rxn.rid} is not balanced")
reactions.append(rxn)
if row.ID in reaction_ids:
raise KeyError(f"Reaction IDs must be unique, but you have "
......@@ -311,9 +334,12 @@ class Pathway(object):
keq_df = param_df[param_df['QuantityType'] == 'equilibrium constant']
keq_df.set_index('Reaction', inplace=True)
if not set(reaction_ids).issubset(keq_df.index):
logging.warning("Not all reactions have Keq values in the "
"Parameter table. Therefore, we use "
"Component-Contribution to calculate all of them.")
# TODO: change the SBtab format to make it explicit when to use
# the given equilibrium constants, and when to use
# component-contribution.
warnings.warn("Not all reactions have Keq values in the "
"Parameter table. Therefore, we use "
"Component-Contribution to calculate all of them.")
# TODO: read the aqueous conditions directly from the SBtab file
p_h = default_pH
p_mg = default_pMg
......
......@@ -24,7 +24,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import numpy as np
from equilibrator_cache.thermodynamic_constants import (
FARADAY, POSSIBLE_REACTION_ARROWS, Q_, R, default_I, default_pH, default_T,
physiological_concentration, standard_concentration, ureg)
......@@ -34,3 +34,6 @@ default_pMg = Q_("14.0")
default_phase = 'aqueous'
default_conc_lb = Q_("1e-6 M")
default_conc_ub = Q_("1e-2 M")
def strip_units(v: np.array) -> np.array:
return np.array(list(map(float, v.flat))).reshape(v.shape)
......@@ -37,6 +37,8 @@ from equilibrator_api import Q_, Pathway, Reaction
from . import approx_unit
warnings.simplefilter('error', UserWarning)
@pytest.fixture(scope="module")
def toy_pathway() -> Pathway:
test_dir = os.path.dirname(
......
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