Skip to content

Commit

Permalink
Fix parmed imports, adds warning tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IAlibay committed May 9, 2021
1 parent 249bc74 commit 5b25b49
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion package/MDAnalysis/coordinates/ParmEd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#
import warnings
from ..converters.ParmEd import ParmEdConverter, ParmEdReader
from ..converters.ParmEd import (ParmEdConverter, ParmEdReader,
get_indices_from_subset, MDA2PMD,)


warnings.warn(
"This module is deprecated as of MDAnalysis version 2.0.0. "
Expand Down
2 changes: 1 addition & 1 deletion package/MDAnalysis/topology/ParmEdParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#
import warnings
from ..converters.ParmEdParser import ParmEdParser
from ..converters.ParmEdParser import ParmEdParser, squash_identical

warnings.warn(
"This module is deprecated as of MDAnalysis version 2.0.0."
Expand Down
18 changes: 16 additions & 2 deletions testsuite/MDAnalysisTests/converters/test_parmed.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def test_coordinates(self):
assert_almost_equal(up, rp, decimal=3)



class BaseTestParmEdReader(_SingleFrameReader):
def setUp(self):
self.universe = mda.Universe(pmd.load_file(self.ref_filename))
Expand Down Expand Up @@ -95,6 +94,7 @@ def test_uses_ParmEdReader(self):

assert isinstance(self.universe.trajectory, ParmEdReader), "failed to choose ParmEdReader"


def _parmed_param_eq(a, b):
a_idx = [a.atom1.idx, a.atom2.idx]
b_idx = [b.atom1.idx, b.atom2.idx]
Expand All @@ -110,6 +110,7 @@ def _parmed_param_eq(a, b):
atoms = a_idx == b_idx or a_idx == b_idx[::-1]
return atoms and a.type == b.type


class BaseTestParmEdConverter:

equal_atom_attrs = ('name', 'altloc')
Expand Down Expand Up @@ -176,7 +177,6 @@ def test_equivalent_ureybradley_values(self, universe, output):
ix = (param.atom1.idx, param.atom2.idx)
assert ix in vals or ix[::-1] in vals


def test_equivalent_atoms(self, ref, output):
for r, o in zip(ref.atoms, output.atoms):
for attr in self.equal_atom_attrs:
Expand Down Expand Up @@ -235,6 +235,7 @@ def universe(self):
u = mda.Universe(self.ref_filename)
return mda.Merge(u.atoms[self.start_i:self.end_i:self.skip_i])


class BaseTestParmEdConverterFromParmed(BaseTestParmEdConverter):

equal_atom_attrs = ('name', 'number', 'altloc')
Expand All @@ -250,12 +251,15 @@ def test_equivalent_connectivity_counts(self, ref, output):
o = getattr(output, attr)
assert len(r) == len(o)


class TestParmEdConverterPRM(BaseTestParmEdConverter):
ref_filename = PRM


class TestParmEdConverterParmedPRM(BaseTestParmEdConverterFromParmed):
ref_filename = PRM_UreyBradley


# class TestParmEdConverterPDBSubset(BaseTestParmEdConverterSubset):
# ref_filename = PDB
# start_i = 101
Expand All @@ -264,12 +268,15 @@ class TestParmEdConverterParmedPRM(BaseTestParmEdConverterFromParmed):

# TODO: Add Subset test for PRMs when mda.Merge accepts Universes without positions


class TestParmEdConverterParmedPSF(BaseTestParmEdConverterFromParmed):
ref_filename = PSF_cmap


class TestParmEdConverterPSF(BaseTestParmEdConverter):
ref_filename = PSF_NAMD


class TestParmEdConverterGROSubset(BaseTestParmEdConverterSubset):
ref_filename = GRO
start_i = 5
Expand All @@ -287,8 +294,15 @@ class TestParmEdConverterPDB(BaseTestParmEdConverter):
def test_equivalent_coordinates(self, ref, output):
assert_almost_equal(ref.coordinates, output.coordinates, decimal=3)


def test_incorrect_object_passed_typeerror():
err = "No atoms found in obj argument"
with pytest.raises(TypeError, match=err):
c = ParmEdConverter()
c.convert("we still don't support emojis :(")


def test_old_import_warning():
wmsg = "Please import the ParmEd classes from MDAnalysis.converters"
with pytest.warns(DeprecationWarning, match=wmsg):
from MDAnalysis.coordinates.ParmEd import ParmEdConverter
6 changes: 6 additions & 0 deletions testsuite/MDAnalysisTests/converters/test_parmed_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,9 @@ def test_dihedral_types(self, universe):
)):
assert dih.type[i].type.phi_k == phi_k
assert dih.type[i].type.per == per


def test_old_import_warning():
wmsg = "Please import the ParmEd classes from MDAnalysis.converters"
with pytest.warns(DeprecationWarning, match=wmsg):
from MDAnalysis.topology.ParmEdParser import squash_identical

0 comments on commit 5b25b49

Please sign in to comment.