class TestHOLE(TestCase): filename = PDB_HOLE @dec.skipif(executable_not_found("hole"), msg="Test skipped because HOLE not found") def setUp(self): # keep tempdir around for the whole lifetime of the class self.tempdir = tempdir.TempDir() with in_dir(self.tempdir.name): H = HOLE(self.filename, raseed=31415) H.run() H.collect() self.H = H def tearDown(self): del self.H del self.tempdir @attr('slow') @dec.skipif(executable_not_found("hole"), msg="Test skipped because HOLE not found") def test_HOLE(self): profiles = self.H.profiles.values() assert_equal(len(profiles), 1, err_msg="HOLE.profile should contain exactly 1 profile") p = profiles[0] assert_equal(len(p), 425, err_msg="wrong number of points in HOLE profile") assert_almost_equal(p.rxncoord.mean(), -1.41225, err_msg="wrong mean HOLE rxncoord") assert_almost_equal(p.radius.min(), 1.19707, err_msg="wrong min HOLE radius") @attr('slow') @dec.skipif(executable_not_found("hole"), msg="Test skipped because HOLE not found") def test_vmd_surface(self): with in_dir(self.tempdir.name): filename = self.H.create_vmd_surface(filename="hole.vmd") assert_equal(len(open(filename).readlines()), 6504, err_msg="HOLE VMD surface file is incomplete")
class TestAlignmentProcessing(object): seq = FASTA def test_fasta2select_aligned(self): """test align.fasta2select() on aligned FASTA (Issue 112)""" sel = align.fasta2select(self.seq, is_aligned=True) # length of the output strings, not residues or anything real... assert len( sel['reference']) == 30623, "selection string has unexpected length" assert len( sel['mobile']) == 30623, "selection string has unexpected length" @pytest.mark.skipif(executable_not_found("clustalw2"), reason="Test skipped because clustalw2 executable not found") def test_fasta2select_ClustalW(self, tmpdir): """MDAnalysis.analysis.align: test fasta2select() with ClustalW (Issue 113)""" alnfile = str(tmpdir.join('alignmentprocessing.aln')) treefile = str(tmpdir.join('alignmentprocessing.dnd')) sel = align.fasta2select(self.seq, is_aligned=False, alnfilename=alnfile, treefilename=treefile) # numbers computed from alignment with clustalw 2.1 on Mac OS X # [orbeckst] length of the output strings, not residues or anything # real... assert len( sel['reference']) == 23080, "selection string has unexpected length" assert len( sel['mobile']) == 23090, "selection string has unexpected length"
def setUpClass(cls): cls.universe = MDAnalysis.Universe(cls.filename) if not executable_not_found("hole"): with tempdir.in_tempdir(): H = HOLEtraj(cls.universe, start=cls.start, stop=cls.stop, raseed=31415) H.run() cls.H = H else: cls.H = None cls.frames = [ts.frame for ts in cls.universe.trajectory[cls.start:cls.stop]]
class TestAlignmentProcessing(TestCase): def setUp(self): self.seq = FASTA fd, self.alnfile = tempfile.mkstemp(suffix=".aln") os.close(fd) fd, self.treefile = tempfile.mkstemp(suffix=".dnd") os.close(fd) def tearDown(self): for f in self.alnfile, self.treefile: try: os.unlink(f) except OSError: pass @attr('issue') def test_fasta2select_aligned(self): """test align.fasta2select() on aligned FASTA (Issue 112)""" from MDAnalysis.analysis.align import fasta2select sel = fasta2select(self.seq, is_aligned=True) # length of the output strings, not residues or anything real... assert_equal(len(sel['reference']), 30623, err_msg="selection string has unexpected length") assert_equal(len(sel['mobile']), 30623, err_msg="selection string has unexpected length") @attr('issue') @dec.skipif(executable_not_found("clustalw2"), msg="Test skipped because clustalw2 executable not found") def test_fasta2select_ClustalW(self): """MDAnalysis.analysis.align: test fasta2select() with calling ClustalW (Issue 113)""" # note: will not be run if clustalw is not installed from MDAnalysis.analysis.align import fasta2select sel = fasta2select(self.seq, is_aligned=False, alnfilename=self.alnfile, treefilename=self.treefile) # numbers computed from alignment with clustalw 2.1 on Mac OS X [orbeckst] # length of the output strings, not residues or anything real... assert_equal(len(sel['reference']), 23080, err_msg="selection string has unexpected length") assert_equal(len(sel['mobile']), 23090, err_msg="selection string has unexpected length")
def setUpClass(cls): cls.universe = MDAnalysis.Universe(cls.filename) if not executable_not_found("hole"): with tempdir.in_tempdir(): H = HOLEtraj(cls.universe, start=cls.start, stop=cls.stop, raseed=31415) H.run() cls.H = H else: cls.H = None cls.frames = [ ts.frame for ts in cls.universe.trajectory[cls.start:cls.stop] ]
class TestAlignmentProcessing(TestCase): def setUp(self): self.seq = FASTA self.tempdir = tempdir.TempDir() self.alnfile = path.join(self.tempdir.name, 'alignmentprocessing.aln') self.treefile = path.join(self.tempdir.name, 'alignmentprocessing.dnd') def tearDown(self): del self.tempdir @attr('issue') def test_fasta2select_aligned(self): """test align.fasta2select() on aligned FASTA (Issue 112)""" from MDAnalysis.analysis.align import fasta2select sel = fasta2select(self.seq, is_aligned=True) # length of the output strings, not residues or anything real... assert_equal(len(sel['reference']), 30623, err_msg="selection string has unexpected length") assert_equal(len(sel['mobile']), 30623, err_msg="selection string has unexpected length") @attr('issue') @dec.skipif(executable_not_found("clustalw2"), msg="Test skipped because clustalw2 executable not found") def test_fasta2select_ClustalW(self): """MDAnalysis.analysis.align: test fasta2select() with calling ClustalW (Issue 113)""" # note: will not be run if clustalw is not installed from MDAnalysis.analysis.align import fasta2select sel = fasta2select(self.seq, is_aligned=False, alnfilename=self.alnfile, treefilename=self.treefile) # numbers computed from alignment with clustalw 2.1 on Mac OS X # [orbeckst] length of the output strings, not residues or anything # real... assert_equal(len(sel['reference']), 23080, err_msg="selection string has unexpected length") assert_equal(len(sel['mobile']), 23090, err_msg="selection string has unexpected length")
u.atoms.write(path) fixed = check_and_fix_long_filename(path) assert os.path.islink(fixed) assert fixed.endswith(short_name) def test_symlink_file(self, tmpdir): long_name = 'a' * 10 + self.filename with tmpdir.as_cwd(): fixed = check_and_fix_long_filename(long_name) assert os.path.islink(fixed) assert not fixed.endswith(long_name) @pytest.mark.skipif(executable_not_found("hole"), reason="Test skipped because HOLE not found") class TestHole(object): filename = PDB_HOLE random_seed = 31415 profile_length = 425 rxn_coord_mean = -1.41225 radius_min = 1.19707 def test_correct_input(self, tmpdir): with tmpdir.as_cwd(): hole2.hole(self.filename, random_seed=self.random_seed, infile='hole.inp') infile = str(tmpdir.join('hole.inp'))
class TestHoleModule(TestCase): @dec.skipif( rlimits_missing, msg="Test skipped because platform does not allow setting rlimits") def setUp(self): self.universe = MDAnalysis.Universe(MULTIPDB_HOLE) try: # on Unix we can manipulate our limits: http://docs.python.org/2/library/resource.html import resource self.soft_max_open_files, self.hard_max_open_files = resource.getrlimit( resource.RLIMIT_NOFILE) except ImportError: pass @attr('slow') @attr('issue') @dec.skipif( rlimits_missing, msg="Test skipped because platform does not allow setting rlimits") @dec.skipif(executable_not_found("hole"), msg="Test skipped because HOLE not found") def test_hole_module_fd_closure(self): """test open file descriptors are closed (MDAnalysisTests.analysis.test_hole.TestHoleModule): Issue 129""" # If Issue 129 isn't resolved, this function will produce an OSError on # the system, and cause many other tests to fail as well. # # Successful test takes ~10 s, failure ~2 s. # Hasten failure by setting "ulimit -n 64" (can't go too low because of open modules etc...) import resource # ----- temporary hack ----- # on Mac OS X (on Travis) we run out of open file descriptors # before even starting this test (see # https://github.com/MDAnalysis/mdanalysis/pull/901#issuecomment-231938093); # if this issue is solved by #363 then revert the following # hack: # import platform if platform.platform() == "Darwin": max_open_files = 512 else: max_open_files = 64 # # -------------------------- resource.setrlimit(resource.RLIMIT_NOFILE, (max_open_files, self.hard_max_open_files)) with tempdir.in_tempdir(): try: H = HOLEtraj(self.universe, cvect=[0, 1, 0], sample=20.0) finally: self._restore_rlimits() # pretty unlikely that the code will get through 2 rounds if the MDA # issue 129 isn't fixed, although this depends on the file descriptor # open limit for the machine in question try: for i in range(2): # will typically get an OSError for too many files being open after # about 2 seconds if issue 129 isn't resolved H.run() except OSError as err: if err.errno == errno.EMFILE: raise AssertionError( "HOLEtraj does not close file descriptors (Issue 129)") raise finally: # make sure to restore open file limit !! self._restore_rlimits() def _restore_rlimits(self): try: import resource resource.setrlimit( resource.RLIMIT_NOFILE, (self.soft_max_open_files, self.hard_max_open_files)) except ImportError: pass def tearDown(self): self._restore_rlimits() del self.universe
class TestHOLEtraj(TestCase): filename = MULTIPDB_HOLE start = 5 stop = 7 # HOLE is so slow so we only run it once and keep it in # the class; note that you may not change universe.trajectory # (eg iteration) because this is not safe in parallel @classmethod def setUpClass(cls): cls.universe = MDAnalysis.Universe(cls.filename) if not executable_not_found("hole"): with tempdir.in_tempdir(): H = HOLEtraj(cls.universe, start=cls.start, stop=cls.stop, raseed=31415) H.run() cls.H = H else: cls.H = None cls.frames = [ ts.frame for ts in cls.universe.trajectory[cls.start:cls.stop] ] @classmethod def tearDownClass(cls): del cls.H del cls.universe # This is VERY slow on 11 frames so we just take 2 @attr('slow') @dec.skipif(executable_not_found("hole"), msg="Test skipped because HOLE not found") def test_HOLEtraj(self): assert_array_equal( sorted(self.H.profiles.keys()), self.frames, err_msg="H.profiles.keys() should contain the frame numbers") data = np.transpose([(len(p), p.rxncoord.mean(), p.radius.min()) for p in self.H.profiles.values()]) assert_array_equal(data[0], [401, 399], err_msg="incorrect profile lengths") assert_array_almost_equal(data[1], [1.98767, 0.0878], err_msg="wrong mean HOLE rxncoord") assert_array_almost_equal(data[2], [1.19819, 1.29628], err_msg="wrong minimum radius") @attr('slow') @dec.skipif(executable_not_found("hole"), msg="Test skipped because HOLE not found") def test_min_radius(self): assert_array_almost_equal(self.H.min_radius(), np.array([[5., 1.19819], [6., 1.29628]]), err_msg="min_radius() array not correct") @attr('slow') @dec.skipif(executable_not_found("hole"), msg="Test skipped because HOLE not found") def test_plot(self): ax = self.H.plot(label=True) assert_(isinstance(ax, matplotlib.axes.Axes), msg="H.plot() did not produce an Axes instance") @attr('slow') @dec.skipif(executable_not_found("hole"), msg="Test skipped because HOLE not found") def test_plot3D(self): ax = self.H.plot3D() assert_(isinstance(ax, mpl_toolkits.mplot3d.Axes3D), msg="H.plot3D() did not produce an Axes3D instance") @attr('slow') @dec.skipif(executable_not_found("hole"), msg="Test skipped because HOLE not found") def test_plot3D_rmax(self): ax = self.H.plot3D(rmax=2.5) assert_(isinstance(ax, mpl_toolkits.mplot3d.Axes3D), msg="H.plot3D(rmax=float) did not produce an Axes3D instance")
from MDAnalysisTests import executable_not_found def rlimits_missing(): # return True if resources module not accesible (ie setting of rlimits) try: # on Unix we can manipulate our limits: http://docs.python.org/2/library/resource.html import resource soft_max_open_files, hard_max_open_files = resource.getrlimit(resource.RLIMIT_NOFILE) except ImportError: return True return False @pytest.mark.skipif(executable_not_found("hole"), reason="Test skipped because HOLE not found") class TestHOLE(object): @staticmethod @pytest.fixture() def H(tmpdir): # keep tempdir around for the whole lifetime of the class with tmpdir.as_cwd(): filename = PDB_HOLE H = HOLE(filename, raseed=31415) H.run() H.collect() return H def test_HOLE(self, H): profiles_values = list(H.profiles.values()) assert len(profiles_values) == 1, "HOLE.profile should contain exactly 1 profile"
class TestHoleModule(TestCase): def setUp(self): self.universe = MDAnalysis.Universe(PDB_HOLE, XTC_HOLE) try: # on Unix we can manipulate our limits: http://docs.python.org/2/library/resource.html import resource self.soft_max_open_files, self.hard_max_open_files = resource.getrlimit( resource.RLIMIT_NOFILE) except ImportError: pass @attr('slow') @attr('issue') @dec.skipif( rlimits_missing, msg="Test skipped because platform does not allow setting rlimits") @dec.skipif(executable_not_found("hole"), msg="Test skipped because HOLE not found") def test_hole_module_fd_closure(self): """MDAnalysis.analysis.hole: Issue 129: ensure low level file descriptors to PDB files used by Hole program are properly closed""" # If Issue 129 isn't resolved, this function will produce an OSError on # the system, and cause many other tests to fail as well. # # Successful test takes ~10 s, failure ~2 s. try: # Hasten failure by setting "ulimit -n 64" (can't go too low because of open modules etc...) import resource resource.setrlimit(resource.RLIMIT_NOFILE, (64, self.hard_max_open_files)) except ImportError: raise NotImplementedError( "Test cannot be run without the resource module.") with tempdir.in_tempdir(): try: # will need to have the 'hole' command available in the path H = HOLEtraj(self.universe, cvect=[0, 1, 0], sample=20.0) except OSError as err: if err.errno == errno.ENOENT: raise OSError(errno.ENOENT, "HOLE binary not found") raise finally: self._restore_rlimits() # pretty unlikely that the code will get through 2 rounds if the MDA # issue 129 isn't fixed, although this depends on the file descriptor # open limit for the machine in question try: for i in xrange(2): # will typically get an OSError for too many files being open after # about 2 seconds if issue 129 isn't resolved H.run() except OSError as err: if err.errno == errno.EMFILE: raise AssertionError( "HOLEtraj does not close file descriptors (Issue 129)") elif err.errno == errno.ENOENT: raise OSError(errno.ENOENT, "HOLE binary not found") raise finally: # make sure to restore open file limit !! self._restore_rlimits() def _restore_rlimits(self): try: import resource resource.setrlimit( resource.RLIMIT_NOFILE, (self.soft_max_open_files, self.hard_max_open_files)) except ImportError: pass def tearDown(self): self._restore_rlimits() del self.universe