From a3029661acfdc0e805a33b44f6c991dea0dea1d0 Mon Sep 17 00:00:00 2001 From: Peter Kroon Date: Mon, 29 Jan 2024 14:11:24 +0100 Subject: [PATCH 1/4] Log a helpful message when an element is not present in the ATOM_MASS dict, and then use a relatively high mass since it's probably a metal --- vermouth/processors/attach_mass.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/vermouth/processors/attach_mass.py b/vermouth/processors/attach_mass.py index 538117d33..bd2d5adae 100644 --- a/vermouth/processors/attach_mass.py +++ b/vermouth/processors/attach_mass.py @@ -18,10 +18,13 @@ from .processor import Processor +from ..log_helpers import StyleAdapter, get_logger -# TODO: make the masses part of the forcefield -ATOM_MASSES = {'H': 1, 'C': 12, 'N': 14, 'O': 16, 'S': 32, 'P': 31, 'M': 0} +LOGGER = StyleAdapter(get_logger(__name__)) +# TODO: make the masses part of the forcefield +ATOM_MASSES = {'H': 1, 'C': 12, 'N': 14, 'O': 16, 'S': 32, 'P': 31} +DEFAULT_MASS = 30 def attach_mass(molecule, attribute='mass'): """ @@ -36,7 +39,11 @@ def attach_mass(molecule, attribute='mass'): The attribute the mass is assigned to. """ for node in molecule.nodes.values(): - node[attribute] = ATOM_MASSES[node['element']] + element = node['element'] + if element not in ATOM_MASSES: + LOGGER.info("Cannot find a mass for element {}. We assume it's some" + " metal, and will set its mass to {} amu.", element, DEFAULT_MASS) + node[attribute] = ATOM_MASSES.get(node['element'], DEFAULT_MASS) class AttachMass(Processor): From 755132e89ec834da08bf6653dddfcbab227cea50 Mon Sep 17 00:00:00 2001 From: Peter Kroon Date: Mon, 29 Jan 2024 15:20:30 +0100 Subject: [PATCH 2/4] Fix test failure. Hopefully --- pyproject.toml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 44bfde4dc..bb27dfc11 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,3 +4,8 @@ requires = [ "setuptools >= 30.3.0", "pbr", ] + +[tool.pytest.ini_options] +addopts = "--import-mode=importlib" +testpaths = ["vermouth/tests"] +python_files = "test_*.py" From 806a0d138122872f1d248598b8481715853dc44c Mon Sep 17 00:00:00 2001 From: Peter Kroon Date: Mon, 29 Jan 2024 16:02:05 +0100 Subject: [PATCH 3/4] Move .coveragerc to pyproject.toml --- .coveragerc | 5 ----- pyproject.toml | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) delete mode 100644 .coveragerc diff --git a/.coveragerc b/.coveragerc deleted file mode 100644 index e88fbffab..000000000 --- a/.coveragerc +++ /dev/null @@ -1,5 +0,0 @@ -[run] -branch = True -omit = - vermouth/tests/* - vermouth/redistributed/* diff --git a/pyproject.toml b/pyproject.toml index bb27dfc11..22331bbfa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,3 +9,8 @@ requires = [ addopts = "--import-mode=importlib" testpaths = ["vermouth/tests"] python_files = "test_*.py" + +[tool.coverage.run] +branch = true +omit = ["vermouth/tests/*", "vermouth/redistributed/*"] + From d7ce38fc1009b494a0d685cc9cdd13f90da5d117 Mon Sep 17 00:00:00 2001 From: Peter Kroon Date: Mon, 29 Jan 2024 16:14:15 +0100 Subject: [PATCH 4/4] Fight with more CI tests --- .github/workflows/deploy.yml | 2 +- .github/workflows/run_tests.yml | 6 +++++- pyproject.toml | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0d6d5e995..6dea77172 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -52,7 +52,7 @@ jobs: - name: Run pytest with codecoverage run: | - coverage run --source=vermouth $(which pytest) -vv vermouth --hypothesis-show-statistics + coverage run $(which pytest) -vv --hypothesis-show-statistics coverage report --omit='*/bin/pytest' - if: ${{ matrix.WITH_CODECOV }} diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 1ebf193c2..72e8c9db4 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -53,7 +53,11 @@ jobs: pip install -r requirements-tests.txt - name: Run pytest with codecoverage - run: pytest vermouth --cov=vermouth --cov-report=xml --hypothesis-show-statistics + run: | + coverage run $(which pytest) -vv --hypothesis-show-statistics + coverage report + coverage xml + - if: ${{ matrix.WITH_CODECOV }} name: Upload coverage codecov uses: codecov/codecov-action@v3 diff --git a/pyproject.toml b/pyproject.toml index 22331bbfa..b2a592a45 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,5 +12,5 @@ python_files = "test_*.py" [tool.coverage.run] branch = true -omit = ["vermouth/tests/*", "vermouth/redistributed/*"] - +omit = ["vermouth/tests/*", "vermouth/redistributed/*", '*/bin/pytest'] +source_pkgs = ["vermouth"]