Exemple #1
0
def test_read_write():
    xyz = np.around(10 * np.random.randn(100, 11, 3), decimals=3)
    with XYZTrajectoryFile(temp, mode='w') as f:
        f.write(xyz)
    with XYZTrajectoryFile(temp) as f:
        xyz2 = f.read()

    eq(xyz, xyz2)
Exemple #2
0
def test_multiread(get_fn):
    reference = md.load(get_fn('frame0.xyz'), top=get_fn('native.pdb'))
    with XYZTrajectoryFile(get_fn('frame0.xyz')) as f:
        xyz0 = f.read(n_frames=1)
        xyz1 = f.read(n_frames=1)

    eq(reference.xyz[0], xyz0[0] / 10)
    eq(reference.xyz[1], xyz1[0] / 10)
Exemple #3
0
def test_seek(get_fn):
    reference = md.load(get_fn('frame0.xyz'), top=get_fn('native.pdb'))

    with XYZTrajectoryFile(get_fn('frame0.xyz')) as f:
        f.seek(1)
        eq(1, f.tell())
        xyz1 = f.read(n_frames=1)
        eq(reference.xyz[1], xyz1[0] / 10)

        f.seek(10)
        eq(10, f.tell())
        xyz10 = f.read(n_frames=1)
        eq(reference.xyz[10], xyz10[0] / 10)
        eq(11, f.tell())

        f.seek(-8, 1)
        xyz3 = f.read(n_frames=1)
        eq(reference.xyz[3], xyz3[0] / 10)

        f.seek(4, 1)
        xyz8 = f.read(n_frames=1)
        eq(reference.xyz[8], xyz8[0] / 10)
Exemple #4
0
def test_read_0(get_fn):
    with XYZTrajectoryFile(get_fn('frame0.xyz')) as f:
        xyz = f.read()
    with XYZTrajectoryFile(get_fn('frame0.xyz')) as f:
        xyz3 = f.read(stride=3)
    eq(xyz[::3], xyz3)