예제 #1
0
 def setUp(self):
     self.tmpdir = tempfile.mkdtemp('test_random_access')
     self.dim = 5
     self.data = [
         np.random.random((100, self.dim)).astype(np.float32),
         np.random.random((20, self.dim)).astype(np.float32),
         np.random.random((20, self.dim)).astype(np.float32)
     ]
     self.stride = np.asarray([[0, 1], [0, 3], [0, 3], [0, 5], [0, 6],
                               [0, 7], [2, 1], [2, 1]])
     self.stride2 = np.asarray([[2, 0]])
     self.topfile = pkg_resources.resource_filename(__name__,
                                                    'data/test.pdb')
     trajfile1, xyz1, n_frames1 = create_traj(self.topfile,
                                              dir=self.tmpdir,
                                              format=".binpos",
                                              length=100)
     trajfile2, xyz2, n_frames2 = create_traj(self.topfile,
                                              dir=self.tmpdir,
                                              format=".binpos",
                                              length=20)
     trajfile3, xyz3, n_frames3 = create_traj(self.topfile,
                                              dir=self.tmpdir,
                                              format=".binpos",
                                              length=20)
     self.data_feature_reader = [trajfile1, trajfile2, trajfile3]
예제 #2
0
    def test_fragmented_xtc(self):
        from pyemma.coordinates.tests.test_featurereader import create_traj

        top_file = pkg_resources.resource_filename(__name__, 'data/test.pdb')
        trajfiles = []
        for _ in range(3):
            f, _, _ = create_traj(top_file)
            trajfiles.append(f)
        try:
            # three trajectories: one consisting of all three, one consisting of the first,
            # one consisting of the first and the last
            source = coor.source(
                [trajfiles, [trajfiles[0]], [trajfiles[0], trajfiles[2]]],
                top=top_file)
            source.chunksize = 1000

            out = source.get_output(stride=1)
            trajs = [
                mdtraj.load(trajfiles[i], top=top_file).xyz.reshape(-1, 9)
                for i in range(0, 3)
            ]

            np.testing.assert_equal(out[0], np.vstack(trajs))
            np.testing.assert_equal(out[1], trajs[0])
            np.testing.assert_equal(out[2], np.vstack((trajs[0], trajs[2])))
        finally:
            for t in trajfiles:
                try:
                    os.unlink(t)
                except EnvironmentError:
                    pass
예제 #3
0
    def test_feature_reader_random_access(self):
        from pyemma.coordinates.tests.test_featurereader import create_traj

        topfile = pkg_resources.resource_filename(__name__, 'data/test.pdb')
        trajfiles = []
        for _ in range(3):
            f, _, _ = create_traj(topfile)
            trajfiles.append(f)
        try:
            source = coor.source(trajfiles, top=topfile)
            source.chunksize = 2

            out = source.get_output(stride=self.stride)
            keys = np.unique(self.stride[:, 0])
            for i, coords in enumerate(out):
                if i in keys:
                    traj = mdtraj.load(trajfiles[i], top=topfile)
                    np.testing.assert_equal(
                        coords, traj.xyz[np.array(
                            self.stride[self.stride[:, 0] == i][:,
                                                                1])].reshape(
                                                                    -1, 9))
        finally:
            for t in trajfiles:
                try:
                    os.unlink(t)
                except EnvironmentError:
                    pass
예제 #4
0
 def test_fragmented_reader(self):
     top_file = pkg_resources.resource_filename(__name__, 'data/test.pdb')
     trajfiles = []
     nframes = []
     with TemporaryDirectory() as wd:
         for _ in range(3):
             f, _, l = create_traj(top_file, dir=wd)
             trajfiles.append(f)
             nframes.append(l)
         # three trajectories: one consisting of all three, one consisting of the first,
         # one consisting of the first and the last
         reader = api.source(
             [trajfiles, [trajfiles[0]], [trajfiles[0], trajfiles[2]]], top=top_file)
         np.testing.assert_equal(reader.trajectory_lengths(),
                                 [sum(nframes), nframes[0], nframes[0] + nframes[2]])