Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 18 additions & 0 deletions package/MDAnalysis/core/universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

Expand Down
13 changes: 13 additions & 0 deletions testsuite/MDAnalysisTests/core/test_universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
GRO, TRR,
two_water_gro, two_water_gro_nonames,
TRZ, TRZ_psf,
PDB, MMTF,
)

import MDAnalysis as mda
Expand Down Expand Up @@ -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")