示例#1
0
 def hole(self, universe, tmpdir):
     with tmpdir.as_cwd():
         h = hole2.HoleAnalysis(universe)
         h.run(start=self.start,
               stop=self.stop,
               random_seed=self.random_seed)
     return h
示例#2
0
    def test_output_level(self, tmpdir, universe):
        with tmpdir.as_cwd():
            with pytest.warns(UserWarning, match="needs to be < 3"):
                h = hole2.HoleAnalysis(universe, output_level=100)
                h.run(start=self.start,
                      stop=self.stop,
                      random_seed=self.random_seed)

            # no profiles
            assert len(h.profiles) == 0
示例#3
0
 def test_output_level(self, tmpdir, universe):
     with tmpdir.as_cwd():
         with pytest.warns(UserWarning) as rec:
             h = hole2.HoleAnalysis(universe, output_level=100)
             h.run(start=self.start,
                   stop=self.stop,
                   random_seed=self.random_seed)
         assert len(rec) == 1
         assert 'needs to be < 3' in rec[0].message.args[0]
         # no profiles
         assert len(h.profiles) == 0
示例#4
0
    def test_hole_module_fd_closure(self, universe, tmpdir):
        """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 tmpdir.as_cwd():
            try:
                H = hole2.HoleAnalysis(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 pytest.fail(
                        "hole2.HoleAnalysis does not close file descriptors (Issue 129)"
                    )
                raise
            finally:
                # make sure to restore open file limit !!
                self._restore_rlimits()
示例#5
0
    def test_output_level(self, tmpdir, universe):
        with tmpdir.as_cwd():
            with pytest.warns(UserWarning) as rec:
                h = hole2.HoleAnalysis(universe, output_level=100)
                h.run(start=self.start,
                      stop=self.stop,
                      random_seed=self.random_seed)
            assert len(rec) == 5

            assert any('needs to be < 3' in r.message.args[0] for r in rec)
            assert any('has no dt information' in r.message.args[0]
                       for r in rec)  # 2x
            assert any('Unit cell dimensions not found.' in r.message.args[0]
                       for r in rec)  # 2x

            # no profiles
            assert len(h.profiles) == 0
示例#6
0
    def test_cpoint_geometry(self, tmpdir, universe):
        protein = universe.select_atoms('protein')
        cogs = [protein.center_of_geometry() for ts in universe.trajectory]
        with tmpdir.as_cwd():
            h = hole2.HoleAnalysis(universe,
                                   select='protein',
                                   cpoint='center_of_geometry',
                                   write_input_files=True)
            h.run(start=self.start,
                  stop=self.stop,
                  random_seed=self.random_seed)

            infiles = sorted(glob.glob(str(tmpdir.join('hole*.inp'))))
            for file, cog in zip(infiles, cogs[self.start:self.stop]):
                with open(file, 'r') as f:
                    line = f.read().split('CPOINT')[1].split('\n')[0]
                arr = np.array(list(map(float, line.split())))
                assert_almost_equal(arr, cog)
示例#7
0
    def test_context_manager(self, universe, tmpdir):
        with tmpdir.as_cwd():
            with hole2.HoleAnalysis(universe) as h:
                h.run()
                h.run()  # run again for *.old files
                h.create_vmd_surface(filename='hole.vmd')

        sphpdbs = tmpdir.join('*.sph')
        assert len(glob.glob(str(sphpdbs))) == 0
        outfiles = tmpdir.join('*.out')
        assert len(glob.glob(str(outfiles))) == 0
        vdwradii = tmpdir.join('simple2.rad')
        assert len(glob.glob(str(vdwradii))) == 0
        pdbfiles = tmpdir.join('*.pdb')
        assert len(glob.glob(str(pdbfiles))) == 0
        oldfiles = tmpdir.join('*.old')
        assert len(glob.glob(str(oldfiles))) == 0
        vmd_file = tmpdir.join('hole.vmd')
        assert len(glob.glob(str(vmd_file))) == 1