From 50224da8c917e15b410483225bb1285792ed422b Mon Sep 17 00:00:00 2001 From: Lily Wang Date: Sun, 14 Mar 2021 12:56:48 -0700 Subject: [PATCH 1/4] added deprecation warning for anyone trying to add_TopAttr bfactors or tempfactors --- package/CHANGELOG | 2 ++ package/MDAnalysis/core/universe.py | 8 ++++++++ testsuite/MDAnalysisTests/core/test_universe.py | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/package/CHANGELOG b/package/CHANGELOG index ef0a8c5a631..1920c07ff0a 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -29,6 +29,8 @@ Changes Deprecations * hbonds.WaterBridgeAnalysis will be removed in 2.0.0 and replaced with hydrogenbonds.WaterBridgeAnalysis (#3111) + * Deprecated tempfactors and bfactors being separate + TopologyAttrs, with a warning (PR #3161) 01/17/21 richardjgowers, IAlibay, orbeckst, tylerjereddy, jbarnoud, yuxuanzhuang, lilyminium, VOD555, p-j-smith, bieniekmateusz, diff --git a/package/MDAnalysis/core/universe.py b/package/MDAnalysis/core/universe.py index 2ae4343247b..457bd669b20 100644 --- a/package/MDAnalysis/core/universe.py +++ b/package/MDAnalysis/core/universe.py @@ -850,6 +850,14 @@ def add_TopologyAttr(self, topologyattr, values=None): n_residues=self._topology.n_residues, n_segments=self._topology.n_segments, values=values) + alias_pairs = [("bfactors", "tempfactors"), ("tempfactors", "bfactors")] + for a, b in alias_pairs: + if topologyattr.attrname == a and hasattr(self._topology, b): + warnings.warn(f"You are adding {a} to a Universe that " + f"has {b}. From MDAnalysis version 2.0, {a} " + f"and {b} will no longer be separate " + "TopologyAttrs. Instead, they will be aliases " + "of the same attribute.", DeprecationWarning) self._topology.add_TopologyAttr(topologyattr) self._process_attr(topologyattr) diff --git a/testsuite/MDAnalysisTests/core/test_universe.py b/testsuite/MDAnalysisTests/core/test_universe.py index 7eb5c091a57..d10370b61ef 100644 --- a/testsuite/MDAnalysisTests/core/test_universe.py +++ b/testsuite/MDAnalysisTests/core/test_universe.py @@ -51,6 +51,7 @@ GRO, TRR, two_water_gro, two_water_gro_nonames, TRZ, TRZ_psf, + PDB, MMTF, ) import MDAnalysis as mda @@ -1136,3 +1137,15 @@ def test_empty_creation_raises_error(self): def test_as_Universe_deprecation(): with pytest.deprecated_call(): _ = mda.core.universe.as_Universe(PSF, DCD) + + +def test_deprecate_b_tempfactors(): + u = mda.Universe(PDB) + with pytest.warns(DeprecationWarning, match="alias"): + u.add_TopologyAttr("bfactors") + + +def test_deprecate_temp_bfactors(): + u = mda.Universe(MMTF) + with pytest.warns(DeprecationWarning, match="alias"): + u.add_TopologyAttr("tempfactors") \ No newline at end of file From 82fa8db640288cfbe986f8f1a43a3ccc743d2f81 Mon Sep 17 00:00:00 2001 From: Lily Wang Date: Sun, 14 Mar 2021 13:03:38 -0700 Subject: [PATCH 2/4] pep8 --- package/MDAnalysis/core/universe.py | 5 +++-- testsuite/MDAnalysisTests/core/test_universe.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package/MDAnalysis/core/universe.py b/package/MDAnalysis/core/universe.py index 457bd669b20..8eaf561c9b2 100644 --- a/package/MDAnalysis/core/universe.py +++ b/package/MDAnalysis/core/universe.py @@ -850,9 +850,10 @@ def add_TopologyAttr(self, topologyattr, values=None): n_residues=self._topology.n_residues, n_segments=self._topology.n_segments, values=values) - alias_pairs = [("bfactors", "tempfactors"), ("tempfactors", "bfactors")] + alias_pairs = [("bfactors", "tempfactors"), + ("tempfactors", "bfactors")] for a, b in alias_pairs: - if topologyattr.attrname == a and hasattr(self._topology, b): + if topologyattr.attrname == a and hasattr(self._topology, b): warnings.warn(f"You are adding {a} to a Universe that " f"has {b}. From MDAnalysis version 2.0, {a} " f"and {b} will no longer be separate " diff --git a/testsuite/MDAnalysisTests/core/test_universe.py b/testsuite/MDAnalysisTests/core/test_universe.py index d10370b61ef..3dd7f5cc1f6 100644 --- a/testsuite/MDAnalysisTests/core/test_universe.py +++ b/testsuite/MDAnalysisTests/core/test_universe.py @@ -1148,4 +1148,4 @@ def test_deprecate_b_tempfactors(): def test_deprecate_temp_bfactors(): u = mda.Universe(MMTF) with pytest.warns(DeprecationWarning, match="alias"): - u.add_TopologyAttr("tempfactors") \ No newline at end of file + u.add_TopologyAttr("tempfactors") From ea60da0007775e754da39c71ad7ef33c5cc8ff91 Mon Sep 17 00:00:00 2001 From: Lily Wang Date: Sun, 14 Mar 2021 13:22:20 -0700 Subject: [PATCH 3/4] added versionchanged --- package/CHANGELOG | 4 ++-- package/MDAnalysis/core/universe.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/package/CHANGELOG b/package/CHANGELOG index 1920c07ff0a..d262424c8c5 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -27,10 +27,10 @@ Changes * Maximum pinned versions in setup.py removed for python 3.6+ (PR #3139) Deprecations - * hbonds.WaterBridgeAnalysis will be removed in 2.0.0 and - replaced with hydrogenbonds.WaterBridgeAnalysis (#3111) * Deprecated tempfactors and bfactors being separate TopologyAttrs, with a warning (PR #3161) + * hbonds.WaterBridgeAnalysis will be removed in 2.0.0 and + replaced with hydrogenbonds.WaterBridgeAnalysis (#3111) 01/17/21 richardjgowers, IAlibay, orbeckst, tylerjereddy, jbarnoud, yuxuanzhuang, lilyminium, VOD555, p-j-smith, bieniekmateusz, diff --git a/package/MDAnalysis/core/universe.py b/package/MDAnalysis/core/universe.py index 8eaf561c9b2..98ba96589c7 100644 --- a/package/MDAnalysis/core/universe.py +++ b/package/MDAnalysis/core/universe.py @@ -830,6 +830,14 @@ def add_TopologyAttr(self, topologyattr, values=None): Can now also add TopologyAttrs with a string of the name of the attribute to add (eg 'charges'), can also supply initial values using values keyword. + + .. versionchanged:: 1.1.0 + Now warns when adding bfactors to a Universe with + existing tempfactors, or adding tempfactors to a + Universe with existing bfactors. + In version 2.0, MDAnalysis will stop treating + tempfactors and bfactors as separate attributes. Instead, + they will be aliases of the same attribute. """ if isinstance(topologyattr, six.string_types): try: From 737cdcddf8c8f0889dd934b729e304a5b9037cd9 Mon Sep 17 00:00:00 2001 From: Lily Wang Date: Sun, 14 Mar 2021 14:06:29 -0700 Subject: [PATCH 4/4] rm f strings --- package/MDAnalysis/core/universe.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/package/MDAnalysis/core/universe.py b/package/MDAnalysis/core/universe.py index 98ba96589c7..4f1f39cf0f2 100644 --- a/package/MDAnalysis/core/universe.py +++ b/package/MDAnalysis/core/universe.py @@ -862,11 +862,12 @@ def add_TopologyAttr(self, topologyattr, values=None): ("tempfactors", "bfactors")] for a, b in alias_pairs: if topologyattr.attrname == a and hasattr(self._topology, b): - warnings.warn(f"You are adding {a} to a Universe that " - f"has {b}. From MDAnalysis version 2.0, {a} " - f"and {b} will no longer be separate " - "TopologyAttrs. Instead, they will be aliases " - "of the same attribute.", DeprecationWarning) + err = ("You are adding {a} to a Universe that " + "has {b}. From MDAnalysis version 2.0, {a} " + "and {b} will no longer be separate " + "TopologyAttrs. Instead, they will be aliases " + "of the same attribute.").format(a=a, b=b) + warnings.warn(err, DeprecationWarning) self._topology.add_TopologyAttr(topologyattr) self._process_attr(topologyattr)