Skip to content

Commit

Permalink
fixed automated_dihedral_tests that were order sensitive
Browse files Browse the repository at this point in the history
- use set comparisons
- removed skipif for python < 3.8 and replaced with comment referencing
  issue #239
  • Loading branch information
orbeckst committed Jun 30, 2023
1 parent dcc631d commit e6a0a9f
Showing 1 changed file with 18 additions and 41 deletions.
59 changes: 18 additions & 41 deletions mdpow/tests/test_automated_dihedral_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,41 +128,30 @@ def test_build_universe(self, SM25_tmp_dir):
solute_names = solute.atoms.names
assert solute_names.all() == self.universe_solute_atom_names.all()

# the following 'reason' affects every downstream function that relies
# on the atom indices returned for dihedral atom group selections
# issue raised (#239) to identify and resolve exact package/version responsible
@pytest.mark.skipif(sys.version_info < (3, 8), reason='pytest=7.2.0, build=py37h89c1867_0, '
'returns incorrect atom_indices for dihedral atom group selections')
# Use set comparison because ordering of indices appears to change
# between RDKIT versions; issue raised (#239) to identify and
# resolve exact package/version responsible
def test_dihedral_indices(self, atom_indices):
atom_group_indices = atom_indices[0]
assert atom_group_indices == self.check_atom_group_indices
assert set(atom_group_indices) == set(self.check_atom_group_indices)

# the following 'reason' affects every downstream function that relies
# on the atom indices returned for dihedral atom group selections
# issue raised (#239) to identify and resolve exact package/version responsible
@pytest.mark.skipif(sys.version_info < (3, 8), reason='pytest=7.2.0, build=py37h89c1867_0, '
'returns incorrect atom_indices for dihedral atom group selections')
# Possible ordering issue (#239)
def test_SMARTS(self, atom_indices):
atom_group_indices_alt = atom_indices[1]
assert atom_group_indices_alt == self.check_atom_group_indices_alt

# the following 'reason' affects every downstream function that relies
# on the atom indices returned for dihedral atom group selections
# issue raised (#239) to identify and resolve exact package/version responsible
@pytest.mark.skipif(sys.version_info < (3, 8), reason='pytest=7.2.0, build=py37h89c1867_0, '
'returns incorrect atom_indices for dihedral atom group selections')
# Use set comparison because ordering of indices appears to change
# between RDKIT versions; issue raised (#239) to identify and
# resolve exact package/version responsible
def test_dihedral_groups(self, SM25_tmp_dir):
groups = dihedrals.dihedral_groups(dirname=SM25_tmp_dir, resname=self.resname)
i = 0
while i < len(groups):
assert groups[i].all() == self.check_groups[i].all()
i+=1

# the following 'reason' affects every downstream function that relies
# on the atom indices returned for dihedral atom group selections
# issue raised (#239) to identify and resolve exact package/version responsible
@pytest.mark.skipif(sys.version_info < (3, 8), reason='pytest=7.2.0, build=py37h89c1867_0, '
'returns incorrect atom_indices for dihedral atom group selections')

values = [g.all() for g in groups]
reference = [g.all() for g in self.check_groups]

assert set(values) == set(reference)

# Possible ordering issue (#239)
def test_dihedral_groups_ensemble(self, dihedral_data):

df = dihedral_data[0]
Expand Down Expand Up @@ -192,11 +181,7 @@ def test_save_df_info(self, dihedral_data, SM25_tmp_dir, caplog):
dihedrals.save_df(df=dihedral_data[0], df_save_dir=SM25_tmp_dir, molname='SM25')
assert f'Results DataFrame saved as {SM25_tmp_dir}/SM25/SM25_full_df.csv.bz2' in caplog.text, 'Save location not logged or returned'

# the following 'reason' affects every downstream function that relies
# on the atom indices returned for dihedral atom group selections
# issue raised (#239) to identify and resolve exact package/version responsible
@pytest.mark.skipif(sys.version_info < (3, 8), reason='pytest=7.2.0, build=py37h89c1867_0, '
'returns incorrect atom_indices for dihedral atom group selections')
# Possible ordering issue (#239)
def test_periodic_angle(self, dihedral_data):

df_aug = dihedral_data[1]
Expand All @@ -209,22 +194,14 @@ def test_periodic_angle(self, dihedral_data):
aug_dh2_mean == pytest.approx(self.ADG_C13141520_mean)
aug_dh2_var == pytest.approx(self.ADG_C13141520_var)

# the following 'reason' affects every downstream function that relies
# on the atom indices returned for dihedral atom group selections
# issue raised (#239) to identify and resolve exact package/version responsible
@pytest.mark.skipif(sys.version_info < (3, 8), reason='pytest=7.2.0, build=py37h89c1867_0, '
'returns incorrect atom_indices for dihedral atom group selections')
# Possible ordering issue (#239)
def test_save_fig(self, SM25_tmp_dir):
dihedrals.automated_dihedral_analysis(dirname=SM25_tmp_dir, figdir=SM25_tmp_dir,
resname=self.resname, molname='SM25',
solvents=('water',))
assert (SM25_tmp_dir / 'SM25' / 'SM25_C10-C5-S4-O11_violins.pdf').exists(), 'PDF file not generated'

# the following 'reason' affects every downstream function that relies
# on the atom indices returned for dihedral atom group selections
# issue raised (#239) to identify and resolve exact package/version responsible
@pytest.mark.skipif(sys.version_info < (3, 8), reason='pytest=7.2.0, build=py37h89c1867_0, '
'returns incorrect atom_indices for dihedral atom group selections')
# Possible ordering issue (#239)
def test_save_fig_info(self, SM25_tmp_dir, caplog):
caplog.clear()
caplog.set_level(logging.INFO, logger='mdpow.workflows.dihedrals')
Expand Down

0 comments on commit e6a0a9f

Please sign in to comment.