Skip to content

Commit

Permalink
Use tempdir when testing align.AlignTraj (#2534)
Browse files Browse the repository at this point in the history
  • Loading branch information
RMeli authored Feb 16, 2020
1 parent aca26d2 commit ae4b516
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions testsuite/MDAnalysisTests/analysis/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,22 @@ def test_nomatch_residues_raise_empty(self, universe, reference_small,
with pytest.warns(SelectionWarning):
with pytest.raises(SelectionError):
groups = align.get_matching_atoms(ref, mobile, strict=strict)

def test_toggle_atom_mismatch_default_error(self, universe, reference):
selection = ('resname ALA and name CA', 'resname ALA and name O')
with pytest.raises(SelectionError):
rmsd = align.alignto(universe, reference, select=selection)

def test_toggle_atom_mismatch_kwarg_error(self, universe, reference):
selection = ('resname ALA and name CA', 'resname ALA and name O')
with pytest.raises(SelectionError):
rmsd = align.alignto(universe, reference, select=selection, match_atoms=True)

def test_toggle_atom_nomatch(self, universe, reference):
selection = ('resname ALA and name CA', 'resname ALA and name O')
rmsd = align.alignto(universe, reference, select=selection, match_atoms=False)
assert rmsd[0] > 0.01

def test_toggle_atom_nomatch_mismatch_atoms(self, universe, reference):
# mismatching number of atoms, but same number of residues
u = universe.select_atoms('resname ALA and name CA')
Expand All @@ -151,9 +151,6 @@ def test_toggle_atom_nomatch_mismatch_atoms(self, universe, reference):
with pytest.raises(SelectionError):
align.alignto(u, ref, select='all', match_atoms=False)





class TestAlign(object):
@staticmethod
Expand Down Expand Up @@ -226,14 +223,16 @@ def test_AlignTraj_outfile_default_exists(self, universe, reference, tmpdir):
fitted = mda.Universe(PSF, outfile)

# ensure default file exists
with mda.Writer(str(tmpdir.join('rmsfit_align_test.dcd')),
with mda.Writer(str(tmpdir.join("rmsfit_align_test.dcd")),
n_atoms=fitted.atoms.n_atoms) as w:
w.write(fitted.atoms)

align.AlignTraj(fitted, reference)
# we are careful now. The default does nothing
with pytest.raises(IOError):
align.AlignTraj(fitted, reference, force=False)
with tempdir.in_tempdir():
align.AlignTraj(fitted, reference)

# we are careful now. The default does nothing
with pytest.raises(IOError):
align.AlignTraj(fitted, reference, force=False)

def test_AlignTraj_step_works(self, universe, reference, tmpdir):
reference.trajectory[-1]
Expand Down Expand Up @@ -359,6 +358,7 @@ def test_alignto_partial_universe(self, universe, reference):
assert_array_almost_equal(segB_bound.positions, segB_free.positions,
decimal=3)


def _get_aligned_average_positions(ref_files, ref, select="all", **kwargs):
u = mda.Universe(*ref_files, in_memory=True)
prealigner = align.AlignTraj(u, ref, select=select, **kwargs).run()
Expand All @@ -370,7 +370,7 @@ def _get_aligned_average_positions(ref_files, ref, select="all", **kwargs):
class TestAverageStructure(object):

ref_files = (PSF, DCD)

@pytest.fixture
def universe(self):
return mda.Universe(*self.ref_files)
Expand All @@ -384,13 +384,13 @@ def test_average_structure(self, universe, reference):
avg = align.AverageStructure(universe, reference).run()
assert_almost_equal(avg.universe.atoms.positions, ref, decimal=4)
assert_almost_equal(avg.rmsd, rmsd)

def test_average_structure_mass_weighted(self, universe, reference):
ref, rmsd = _get_aligned_average_positions(self.ref_files, reference, weights='mass')
avg = align.AverageStructure(universe, reference, weights='mass').run()
assert_almost_equal(avg.universe.atoms.positions, ref, decimal=4)
assert_almost_equal(avg.rmsd, rmsd)

def test_average_structure_select(self, universe, reference):
select = 'protein and name CA and resid 3-5'
ref, rmsd = _get_aligned_average_positions(self.ref_files, reference, select=select)
Expand All @@ -403,7 +403,7 @@ def test_average_structure_no_ref(self, universe):
avg = align.AverageStructure(universe).run()
assert_almost_equal(avg.universe.atoms.positions, ref, decimal=4)
assert_almost_equal(avg.rmsd, rmsd)

def test_average_structure_no_msf(self, universe):
avg = align.AverageStructure(universe).run()
assert not hasattr(avg, 'msf')
Expand All @@ -412,7 +412,7 @@ def test_mismatch_atoms(self, universe):
u = mda.Merge(universe.atoms[:10])
with pytest.raises(SelectionError):
align.AverageStructure(universe, u)

def test_average_structure_ref_frame(self, universe):
ref_frame = 3
u = mda.Merge(universe.atoms)
Expand All @@ -434,7 +434,6 @@ def test_average_structure_in_memory(self, universe):
assert_almost_equal(avg.universe.atoms.positions, reference_coordinates, decimal=4)
assert avg.filename is None



class TestAlignmentProcessing(object):
seq = FASTA
Expand Down

0 comments on commit ae4b516

Please sign in to comment.