示例#1
0
def test_write_1():
    xyz = np.array(np.random.randn(500, 10, 3), dtype=np.float32)
    with BINPOSTrajectoryFile(temp, 'w') as f:
        f.write(xyz)

    xyz2 = BINPOSTrajectoryFile(temp).read()
    eq(xyz, xyz2)
示例#2
0
def test_seek():
    reference = BINPOSTrajectoryFile(get_fn('frame0.binpos')).read()
    with BINPOSTrajectoryFile(get_fn('frame0.binpos')) as f:
        xyz = f.read(1)[0]
        eq(xyz, reference[0])
        eq(f.tell(), 1)

        xyz = f.read(1)[0]
        eq(xyz, reference[1])
        eq(f.tell(), 2)

        f.seek(0)
        eq(f.tell(), 0)
        xyz = f.read(1)[0]
        eq(f.tell(), 1)
        eq(xyz, reference[0])

        f.seek(5)
        eq(f.read(1)[0], reference[5])
        eq(f.tell(), 6)

        f.seek(-5, 1)
        eq(f.tell(), 1)
        xyz = f.read(1)[0]
        eq(xyz, reference[1])

        f.seek(0, 2)
        eq(f.tell(), len(reference))
示例#3
0
def test_write_1(tmpdir):
    xyz = np.array(np.random.randn(500, 10, 3), dtype=np.float32)
    fn = '{}/x.binpos'.format(tmpdir)
    with BINPOSTrajectoryFile(fn, 'w') as f:
        f.write(xyz)

    xyz2 = BINPOSTrajectoryFile(fn).read()
    assert eq(xyz, xyz2)
示例#4
0
def test_read_atom_indices_slice(get_fn):
    "Read a binpos with atom_indices as a slice"
    fn_binpos = get_fn('frame0.binpos')
    with BINPOSTrajectoryFile(fn_binpos) as f:
        xyz = f.read(atom_indices=slice(0, 10, None))
    xyz2 = io.loadh(get_fn('frame0.binpos.h5'), 'xyz')
    assert eq(xyz, xyz2[:, 0:10, :])
示例#5
0
def test_read_atom_indices(get_fn):
    "Read a binpos with atom_indices as a list"
    fn_binpos = get_fn('frame0.binpos')
    with BINPOSTrajectoryFile(fn_binpos) as f:
        xyz = f.read(atom_indices=[0, 1, 2])
    xyz2 = io.loadh(get_fn('frame0.binpos.h5'), 'xyz')
    assert eq(xyz, xyz2[:, [0, 1, 2], :])
示例#6
0
def test_read_stride_2(get_fn):
    # Read a binpos with stride=3 when n_frames is supplied (different code path)
    fn_binpos = get_fn('frame0.binpos')
    with BINPOSTrajectoryFile(fn_binpos) as f:
        xyz = f.read(n_frames=1000, stride=3)
    xyz2 = io.loadh(get_fn('frame0.binpos.h5'), 'xyz')
    assert eq(xyz, xyz2[::3])
示例#7
0
def test_read_stride(get_fn):
    # Read a binpos with stride=3
    fn_binpos = get_fn('frame0.binpos')
    with BINPOSTrajectoryFile(fn_binpos) as f:
        xyz = f.read(stride=3)
    xyz2 = io.loadh(get_fn('frame0.binpos.h5'), 'xyz')
    assert eq(xyz, xyz2[::3])
示例#8
0
def test_read_1():
    with BINPOSTrajectoryFile(fn_binpos, chunk_size_multiplier=0.5) as f:
        xyz = f.read()
    with DCDTrajectoryFile(fn_dcd) as f:
        xyz2 = f.read()[0]
    xyz3 = io.loadh(get_fn('frame0.binpos.h5'), 'xyz')

    yield lambda: eq(xyz[1:], xyz2)
    yield lambda: eq(xyz, xyz3)
示例#9
0
def test_tell():
    with BINPOSTrajectoryFile(get_fn('frame0.binpos')) as f:
        eq(f.tell(), 0)

        f.read(101)
        eq(f.tell(), 101)

        f.read(3)
        eq(f.tell(), 104)
示例#10
0
def test_read_2(get_fn):
    fn_binpos = get_fn('frame0.binpos')
    fn_dcd = get_fn('frame0.dcd')
    with BINPOSTrajectoryFile(fn_binpos, chunk_size_multiplier=10) as f:
        xyz = f.read()
    with DCDTrajectoryFile(fn_dcd) as f:
        xyz2 = f.read()[0]
    xyz3 = io.loadh(get_fn('frame0.binpos.h5'), 'xyz')

    assert eq(xyz[1:], xyz2)
    assert eq(xyz, xyz3)
示例#11
0
def test_read_stride():
    "Read a binpos with stride=3"
    with BINPOSTrajectoryFile(fn_binpos) as f:
        xyz = f.read(stride=3)
    xyz2 = io.loadh(get_fn('frame0.binpos.h5'), 'xyz')
    yield lambda: eq(xyz, xyz2[::3])