diff --git a/package/CHANGELOG b/package/CHANGELOG index ef0a8c5a631..d262424c8c5 100644 --- a/package/CHANGELOG +++ b/package/CHANGELOG @@ -27,6 +27,8 @@ Changes * Maximum pinned versions in setup.py removed for python 3.6+ (PR #3139) Deprecations + * 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) diff --git a/package/MDAnalysis/core/universe.py b/package/MDAnalysis/core/universe.py index 2ae4343247b..4f1f39cf0f2 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: @@ -850,6 +858,16 @@ 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): + 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) diff --git a/testsuite/MDAnalysisTests/core/test_universe.py b/testsuite/MDAnalysisTests/core/test_universe.py index 7eb5c091a57..3dd7f5cc1f6 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")