Beispiel #1
0
def test_iterload_comprehensive(tmpdir):
    trajin, tn = fn("tz2.ortho.nc"), fn("tz2.ortho.parm7")

    # frame_slice
    t0 = pt.iterload(trajin, tn, frame_slice=(0, -1, 0))
    aa_eq(traj_tz2_ortho.xyz, t0.xyz)

    t0 = pt.iterload(trajin, tn, frame_slice=(0, -1, 2))
    aa_eq(traj_tz2_ortho.xyz[::2], t0.xyz)

    # stride
    t0 = pt.iterload(trajin, tn, stride=2)
    aa_eq(traj_tz2_ortho.xyz[::2], t0.xyz)

    # stride, ignore frame_slice
    t0 = pt.iterload(trajin, tn, stride=2, frame_slice=(0, -1, 3))
    aa_eq(traj_tz2_ortho.xyz[::2], t0.xyz)

    # stride, load two files
    t0 = pt.iterload([trajin, trajin], tn, stride=2)
    xyz_2 = np.vstack((traj_tz2_ortho.xyz[::2], traj_tz2_ortho.xyz[::2]))
    aa_eq(xyz_2, t0.xyz)

    # stride, load two files, ignore frame_slice
    t0 = pt.iterload([trajin, trajin],
                     tn,
                     stride=2,
                     frame_slice=[(0, -1, 5), (0, -1, 2)])
    xyz_2 = np.vstack((traj_tz2_ortho.xyz[::2], traj_tz2_ortho.xyz[::2]))
    aa_eq(xyz_2, t0.xyz)

    # stride, 4 trajs
    filenames, tn = get_remd_fn('remd_ala2')
    t0 = pt.iterload(filenames, tn, stride=3)
    # add frame_slice
    t1 = pt.iterload(filenames, tn, frame_slice=[
        (0, -1, 3),
    ] * 4)
    xyz_expected = np.vstack(
        [pt.iterload(fname, tn)[::3].xyz for fname in filenames])
    aa_eq(xyz_expected, t0.xyz)
    aa_eq(xyz_expected, t1.xyz)

    # stride, 4 trajs, ignore frame_slice
    filenames, tn = get_remd_fn('remd_ala2')
    t0 = pt.iterload(filenames, tn, stride=3, frame_slice=(0 - 1, 4))
    xyz_expected = np.vstack(
        [pt.iterload(fname, tn)[::3].xyz for fname in filenames])
    aa_eq(xyz_expected, t0.xyz)

    # filename with space
    with tmpdir.as_cwd():
        traj = pt.datafiles.load_tz2()
        fname = "abc\ xyz.nc"
        traj.save(fname)
        traj2 = pt.iterload(fname, traj.top)
        assert traj2.n_frames == traj.n_frames
Beispiel #2
0
    def test_iterload_comprehensive(self):
        fn, tn = ("data/tz2.ortho.nc", "data/tz2.ortho.parm7")

        # frame_slice
        t0 = pt.iterload(fn, tn, frame_slice=(0, -1, 0))
        aa_eq(self.traj_tz2_ortho.xyz, t0.xyz)

        t0 = pt.iterload(fn, tn, frame_slice=(0, -1, 2))
        aa_eq(self.traj_tz2_ortho.xyz[::2], t0.xyz)

        # stride
        t0 = pt.iterload(fn, tn, stride=2)
        aa_eq(self.traj_tz2_ortho.xyz[::2], t0.xyz)

        # stride, ignore frame_slice
        t0 = pt.iterload(fn, tn, stride=2, frame_slice=(0, -1, 3))
        aa_eq(self.traj_tz2_ortho.xyz[::2], t0.xyz)

        # stride, load two files
        t0 = pt.iterload([fn, fn], tn, stride=2)
        xyz_2 = np.vstack(
            (self.traj_tz2_ortho.xyz[::2], self.traj_tz2_ortho.xyz[::2]))
        aa_eq(xyz_2, t0.xyz)

        # stride, load two files, ignore frame_slice
        t0 = pt.iterload([fn, fn],
                         tn,
                         stride=2,
                         frame_slice=[(0, -1, 5), (0, -1, 2)])
        xyz_2 = np.vstack(
            (self.traj_tz2_ortho.xyz[::2], self.traj_tz2_ortho.xyz[::2]))
        aa_eq(xyz_2, t0.xyz)

        # stride, 4 trajs
        filenames, tn = get_remd_fn('remd_ala2')
        t0 = pt.iterload(filenames, tn, stride=3)
        # add frame_slice
        t1 = pt.iterload(filenames, tn, frame_slice=[
            (0, -1, 3),
        ] * 4)
        xyz_expected = np.vstack(
            [pt.iterload(fn, tn)[::3].xyz for fn in filenames])
        aa_eq(xyz_expected, t0.xyz)
        aa_eq(xyz_expected, t1.xyz)

        # stride, 4 trajs, ignore frame_slice
        filenames, tn = get_remd_fn('remd_ala2')
        t0 = pt.iterload(filenames, tn, stride=3, frame_slice=(0 - 1, 4))
        xyz_expected = np.vstack(
            [pt.iterload(fn, tn)[::3].xyz for fn in filenames])
        aa_eq(xyz_expected, t0.xyz)