Skip to content

Commit

Permalink
Merge pull request #571 from marrink-lab/issue570
Browse files Browse the repository at this point in the history
Log a helpful message when an element is not present in the ATOM_MASS dict
  • Loading branch information
pckroon authored Jan 31, 2024
2 parents 11ae07c + d7ce38f commit cb8a9f6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
5 changes: 0 additions & 5 deletions .coveragerc

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ requires = [
"setuptools >= 30.3.0",
"pbr",
]

[tool.pytest.ini_options]
addopts = "--import-mode=importlib"
testpaths = ["vermouth/tests"]
python_files = "test_*.py"

[tool.coverage.run]
branch = true
omit = ["vermouth/tests/*", "vermouth/redistributed/*", '*/bin/pytest']
source_pkgs = ["vermouth"]
13 changes: 10 additions & 3 deletions vermouth/processors/attach_mass.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
"""
Expand All @@ -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):
Expand Down

0 comments on commit cb8a9f6

Please sign in to comment.