def test_read_write_0(): xyz = 10 * np.random.randn(100, 11, 3) lengths = np.ones(shape=(100, 3)) angles = np.empty(shape=(100, 3)) angles.fill(45) with LAMMPSTrajectoryFile(temp, mode='w') as f: f.write(xyz, lengths, angles) with LAMMPSTrajectoryFile(temp) as f: xyz2, new_lengths, new_angles = f.read() eq(lengths, new_lengths) eq(angles, new_angles) eq(xyz, xyz2, decimal=3)
def test_multiread(): reference = md.load(get_fn('frame0.lammpstrj'), top=get_fn('native.pdb')) with LAMMPSTrajectoryFile(get_fn('frame0.lammpstrj')) 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)
def test_seek(): reference = md.load(get_fn('frame0.lammpstrj'), top=get_fn('native.pdb')) with LAMMPSTrajectoryFile(get_fn('frame0.lammpstrj')) 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)
def test_read_0(): with LAMMPSTrajectoryFile(get_fn('frame0.lammpstrj')) as f: xyz, _, _ = f.read() with LAMMPSTrajectoryFile(get_fn('frame0.lammpstrj')) as f: xyz3, _, _ = f.read(stride=3) eq(xyz[::3], xyz3)