Skip to content

Commit

Permalink
Add deprecation warning for ITPParser (#4744)
Browse files Browse the repository at this point in the history
* add deprecation warning for ITPParser
* add test for no deprecation warning in itp without valid elements

---------

Co-authored-by: Irfan Alibay <IAlibay@users.noreply.github.com>
Co-authored-by: Rocco Meli <r.meli@bluemail.ch>
  • Loading branch information
3 people authored Oct 24, 2024
1 parent 101008b commit d2729f7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ Changes
numpy.testing.assert_allclose #4438)

Deprecations
* Element guessing in the ITPParser is deprecated and will be removed in version 3.0
(Issue #4698)
* Unknown masses are set to 0.0 for current version, this will be depracated
in version 3.0.0 and replaced by :class:`Masses`' no_value_label attribute(np.nan)
(PR #3753)
Expand Down
10 changes: 9 additions & 1 deletion package/MDAnalysis/topology/ITPParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,15 @@ def parse(self, include_dir='/usr/local/gromacs/share/gromacs/top/',
if all(e.capitalize() in SYMB2Z for e in self.elements):
attrs.append(Elements(np.array(self.elements,
dtype=object), guessed=True))

warnings.warn(
"The elements attribute has been populated by guessing "
"elements from atom types. This behaviour has been "
"temporarily added to the ITPParser as we transition "
"to the new guessing API. "
"This behavior will be removed in release 3.0. "
"Please see issue #4698 for more information. ",
DeprecationWarning
)
else:
warnings.warn("Element information is missing, elements attribute "
"will not be populated. If needed these can be "
Expand Down
17 changes: 17 additions & 0 deletions testsuite/MDAnalysisTests/topology/test_itp.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,3 +490,20 @@ def test_missing_elements_no_attribute():
u = mda.Universe(ITP_atomtypes)
with pytest.raises(AttributeError):
_ = u.atoms.elements


def test_elements_deprecation_warning():
"""Test deprecation warning is present"""
with pytest.warns(DeprecationWarning, match="removed in release 3.0"):
mda.Universe(ITP_nomass)


def test_elements_nodeprecation_warning():
"""Test deprecation warning is not present if elements isn't guessed"""
with pytest.warns(UserWarning) as record:
mda.Universe(ITP_atomtypes)
assert len(record) == 2

warned = [warn.message.args[0] for warn in record]
assert "Element information is missing" in warned[0]
assert "No coordinate reader found" in warned[1]

0 comments on commit d2729f7

Please sign in to comment.