From 6f53c4f3682f6f3e1d1cd6882afb97346c65a495 Mon Sep 17 00:00:00 2001 From: Max Linke Date: Tue, 8 Nov 2016 16:59:17 +0100 Subject: [PATCH] enable cross version compatibility for MDAnalysis --- src/mdsynthesis/limbs.py | 7 ++++++- src/mdsynthesis/tests/test_treants.py | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/mdsynthesis/limbs.py b/src/mdsynthesis/limbs.py index 9dc5bf4..078a83e 100644 --- a/src/mdsynthesis/limbs.py +++ b/src/mdsynthesis/limbs.py @@ -215,7 +215,12 @@ def _apply_resnums(self): resnums = None if resnums: - self._treant._universe.residues.resnums = resnums + # Compatibility for MDAnalysis pre 0.16.0 + try: + self._treant._universe.residues.resnums = resnums + except AttributeError: + self._treant._universe.residues.set_resnum(resnums) + @deprecate(message="resnum storage is deprecated") def _set_resnums(self, resnums): diff --git a/src/mdsynthesis/tests/test_treants.py b/src/mdsynthesis/tests/test_treants.py index a57ecf9..12b0c57 100644 --- a/src/mdsynthesis/tests/test_treants.py +++ b/src/mdsynthesis/tests/test_treants.py @@ -135,7 +135,11 @@ def test_set_resnums(self, treant): protein = treant.universe.select_atoms('protein') resids = protein.residues.resids - protein.residues.resnums = resids + 3 + # Compatibility for MDAnalysis pre 0.16.0 + try: + protein.residues.resnums = resids + 3 + except AttributeError: + protein.residues.set_resnum(resids + 3) treant.universedef._set_resnums(treant.universe.residues.resnums) @@ -144,8 +148,11 @@ def test_set_resnums(self, treant): protein = treant.universe.select_atoms('protein') assert (resids + 3 == protein.residues.resnums).all() - # test resetting of resnums - protein.residues.resnums = resids + 6 + # Compatibility for MDAnalysis pre 0.16.0 + try: + protein.residues.resnums = resids + 6 + except AttributeError: + protein.residues.set_resnum(resids + 6) assert (protein.residues.resnums == resids + 6).all() treant.universedef._set_resnums(treant.universe.residues.resnums)