Commit 581b3295 authored by Elad Noor's avatar Elad Noor

Merge branch 'web' into 'develop'

Web

See merge request !7
parents 53b63b29 8cfff060
Pipeline #49862615 passed with stages
in 30 minutes and 30 seconds
......@@ -13,14 +13,14 @@ test36:
script:
- tox -e isort
- tox -e flake8
- tox -e safety
- tox -e py36 -- --cov-report xml --cov-report term
- tox -e py36
- tox -e codecov
test37:
image: python:3.7
stage: test
image: python:3.7
script:
- tox -e py37 -- --cov-report xml --cov-report term
- tox -e py37
pypi:
stage: deploy
......
......@@ -33,8 +33,8 @@ install_requires =
pyparsing>=2.2.0
sbtab>=0.9.49
matplotlib>=3.0.0
equilibrator-cache>=0.1.9
component-contribution>=0.1.6
equilibrator-cache>=0.2.0
component-contribution>=0.2.0
python_requires = >=3.6
tests_require =
tox
......@@ -72,6 +72,7 @@ filterwarnings =
ignore::DeprecationWarning:libsbml
[isort]
skip = __init__.py
line_length = 80
indent = 4
multi_line_output = 4
......
......@@ -30,7 +30,7 @@ del get_versions
import numpy as np
from equilibrator_cache import Compound, ureg, Q_, R
from equilibrator_cache import Compound
from equilibrator_cache import CompoundCache
from equilibrator_cache.thermodynamic_constants import (
FARADAY, POSSIBLE_REACTION_ARROWS, Q_, R, default_I, default_pH,
......@@ -39,10 +39,10 @@ from equilibrator_cache.thermodynamic_constants import (
ccache = CompoundCache()
default_pMg = Q_("14.0")
default_phase = 'aqueous'
default_conc_lb = Q_("1e-6 M")
default_conc_ub = Q_("1e-2 M")
default_e_potential = Q_("0 V")
def strip_units(v: np.array) -> np.array:
return np.array(list(map(float, v.flat))).reshape(v.shape)
......
......@@ -232,7 +232,7 @@ class Pathway(object):
:return: the reaction IDs
"""
return map(lambda rxn: rxn.reaction_id, self.reactions)
return map(lambda rxn: rxn.rid, self.reactions)
@property
def reaction_formulas(self) -> Iterable[str]:
......@@ -356,9 +356,7 @@ class Pathway(object):
rxn = PhasedReaction.parse_formula(row.ReactionFormula,
row.ID,
name_to_compound.get)
if not rxn.is_balanced(fix_protons=True,
fix_water=True,
raise_exception=False):
if not rxn.is_balanced(ignore_atoms=("H")):
warnings.warn(f"Reaction {rxn.rid} is not balanced")
reactions.append(rxn)
if row.ID in reaction_ids:
......
This diff is collapsed.
This diff is collapsed.
"""unit test for balance with oxidation function."""
# The MIT License (MIT)
#
# Copyright (c) 2013 Weizmann Institute of Science
# Copyright (c) 2018 Institute for Molecular Systems Biology,
# ETH Zurich
# Copyright (c) 2018 Novo Nordisk Foundation Center for Biosustainability,
# Technical University of Denmark
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import pytest
from equilibrator_api import Q_, ComponentContribution, Reaction, ccache
from . import approx_unit
@pytest.fixture(scope="module")
def comp_contribution() -> ComponentContribution:
"""Create a ComponentContribution object."""
return ComponentContribution(p_h=Q_("7"), ionic_strength=Q_("0.25M"))
@pytest.mark.parametrize(
"compound_id, exp_standard_dg_prime",
[
("kegg:C00031", Q_("-2929.5 kJ/mol")),
("kegg:C00033", Q_("-872.6 kJ/mol")),
("kegg:C00064", Q_("-2040.3 kJ/mol")),
])
def test_oxidation(compound_id, exp_standard_dg_prime, comp_contribution):
"""Test how reactions are balanced by oxidation."""
compound = ccache.get_compound(compound_id)
r1 = Reaction.get_oxidation_reaction(compound)
approx_unit(comp_contribution.dg_prime(r1)[0],
exp_standard_dg_prime,
abs=0.1)
r2 = Reaction.parse_formula(f"{compound_id} = ").balance_by_oxidation()
approx_unit(comp_contribution.dg_prime(r2)[0],
exp_standard_dg_prime,
abs=0.1)
......@@ -32,7 +32,7 @@ import numpy
import pytest
from equilibrator_api import Q_, ComponentContribution, Reaction, ccache
from equilibrator_api.phased_reaction import GAS_PHASE
from equilibrator_api.phased_compound import GAS_PHASE_NAME
from . import approx_unit
......@@ -50,15 +50,34 @@ def atp_hydrolysis() -> Reaction:
return Reaction.parse_formula(formula)
@pytest.fixture(scope="module")
def missing_h2o() -> Reaction:
"""Create a ATP hydrolysis reaction."""
formula = "KEGG:C00002 = KEGG:C00008 + KEGG:C00009"
return Reaction.parse_formula(formula)
@pytest.fixture(scope="module")
def fermentation_gas() -> Reaction:
"""Create a reaction object of glucose => 2 ethanol + 2 CO2(g)."""
formula = "KEGG:C00031 = 2 KEGG:C00469 + 2 KEGG:C00011"
rxn = Reaction.parse_formula(formula)
rxn.change_phase(ccache.get_compound("KEGG:C00011"), GAS_PHASE)
rxn.set_phase(ccache.get_compound("KEGG:C00011"), GAS_PHASE_NAME)
return rxn
def test_water_balancing(comp_contribution, missing_h2o):
"""Test if the reaction can be balanced using H2O."""
assert not missing_h2o.is_balanced()
assert missing_h2o.is_balanced(ignore_atoms=("H", "O", "e-"))
balanced_rxn = missing_h2o.balance_with_compound(
ccache.get_compound('KEGG:C00001'),
ignore_atoms=("H")
)
assert balanced_rxn is not None
def test_atp_hydrolysis_physiological_dg(comp_contribution, atp_hydrolysis):
"""Test the dG adjustments for physiological conditions (with H2O)."""
warnings.simplefilter('ignore', ResourceWarning)
......@@ -66,12 +85,11 @@ def test_atp_hydrolysis_physiological_dg(comp_contribution, atp_hydrolysis):
assert float(atp_hydrolysis.physiological_dg_correction()) == \
pytest.approx(numpy.log(1e-3), rel=1e-3)
compound_to_conc = {ccache.get_compound('KEGG:C00001'): None,
ccache.get_compound('KEGG:C00002'): Q_("1uM"),
ccache.get_compound('KEGG:C00008'): Q_("1uM"),
ccache.get_compound('KEGG:C00009'): Q_("1uM")}
atp_hydrolysis.set_abundance(ccache.get_compound('KEGG:C00002'), Q_("1uM"))
atp_hydrolysis.set_abundance(ccache.get_compound('KEGG:C00008'), Q_("1uM"))
atp_hydrolysis.set_abundance(ccache.get_compound('KEGG:C00009'), Q_("1uM"))
assert float(atp_hydrolysis.dg_correction(compound_to_conc)) == \
assert float(atp_hydrolysis.dg_correction()) == \
pytest.approx(numpy.log(1e-6), rel=1e-3)
......@@ -86,10 +104,9 @@ def test_atp_hydrolysis_dg(comp_contribution, atp_hydrolysis):
"""Test the CC predictions for ATP hydrolysis."""
warnings.simplefilter('ignore', ResourceWarning)
compound_to_conc = {ccache.get_compound('KEGG:C00001'): None,
ccache.get_compound('KEGG:C00002'): Q_("1mM"),
ccache.get_compound('KEGG:C00008'): Q_("10mM"),
ccache.get_compound('KEGG:C00009'): Q_("10mM")}
atp_hydrolysis.set_abundance(ccache.get_compound('KEGG:C00002'), Q_("1mM"))
atp_hydrolysis.set_abundance(ccache.get_compound('KEGG:C00008'), Q_("10mM"))
atp_hydrolysis.set_abundance(ccache.get_compound('KEGG:C00009'), Q_("10mM"))
standard_dg_prime, dg_uncertainty = comp_contribution.standard_dg_prime(
atp_hydrolysis)
......@@ -97,7 +114,7 @@ def test_atp_hydrolysis_dg(comp_contribution, atp_hydrolysis):
approx_unit(standard_dg_prime, Q_("-25.8 kJ/mol"), abs=0.1)
approx_unit(dg_uncertainty, Q_("0.3 kJ/mol"), abs=0.1)
dg_prime, _ = comp_contribution.dg_prime(atp_hydrolysis, compound_to_conc)
dg_prime, _ = comp_contribution.dg_prime(atp_hydrolysis)
approx_unit(dg_prime, Q_("-31.5 kJ/mol"), abs=0.1)
physiological_dg_prime, _ = comp_contribution.physiological_dg_prime(
......@@ -131,6 +148,7 @@ def test_reduction_potential(comp_contribution):
reaction = Reaction.parse_formula(formula)
assert reaction.check_half_reaction_balancing() == 2
assert reaction.is_balanced(ignore_atoms=("H", "e-"))
standard_e_prime, e_uncertainty = comp_contribution.standard_e_prime(
reaction)
......
"""unit test for balance with oxidation function."""
# The MIT License (MIT)
#
# Copyright (c) 2013 Weizmann Institute of Science
# Copyright (c) 2018 Institute for Molecular Systems Biology,
# ETH Zurich
# Copyright (c) 2018 Novo Nordisk Foundation Center for Biosustainability,
# Technical University of Denmark
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import pytest
from equilibrator_api import Q_, Reaction, ccache
@pytest.fixture(scope="module")
def atp_hydrolysis() -> Reaction:
"""Create a ATP hydrolysis reaction."""
formula = "KEGG:C00002 + KEGG:C00001 = KEGG:C00008 + KEGG:C00009"
return Reaction.parse_formula(formula)
def test_serialize(atp_hydrolysis):
"""Test the serialize function of PhasedRection."""
atp_compound = ccache.get_compound("KEGG:C00002")
atp_hydrolysis.set_abundance(atp_compound, Q_("10 mM"))
ser = atp_hydrolysis.serialize()
assert ser[0]["mnx_id"] == "MNXM3" # ATP
assert ser[0]["phase"] == "aqueous"
assert ser[0]["coefficient"] == -1
assert len(ser[0]["microspecies"]) == 7
assert ser[1]["mnx_id"] == "MNXM2" # H2O
assert ser[1]["phase"] == "liquid"
assert len(ser[1]["microspecies"]) == 1
assert ser[2]["mnx_id"] == "MNXM7" # ADP
assert len(ser[2]["microspecies"]) == 7
[tox]
envlist = flake8, isort, safety, py{36,37}
envlist = flake8, isort, safety, py{36,37}, codecov
[testenv]
setenv =
......@@ -8,8 +8,9 @@ deps =
pytest
pytest-cov
pytest-raises
coverage
commands =
pytest --cov={envsitepackagesdir}/equilibrator_api {posargs}
pytest --cov=./
[testenv:flake8]
skip_install = True
......@@ -31,3 +32,11 @@ deps=
safety
commands=
safety check
[testenv:codecov]
passenv=
GITLAB_CI CI_BUILD_REF_NAME CI_BUILD_ID CI_BUILD_REPO CI_BUILD_REF CODECOV_TOKEN
deps=
codecov>=1.4.0
commands=
codecov
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