示例#1
0
def written_xtc(tmpdir, xtc):
    fname = str(tmpdir.join("foo.xtc"))
    with XTCFile(fname, 'w') as f:
        for frame in xtc:
            f.write(*frame)
    with XTCFile(fname) as f:
        yield f
示例#2
0
def test_write_different_x_xtc():
    with XTCFile(XTC_multi_frame) as f_in, XTCFile('foo.xtc', 'w') as f_out:
        assert_equal(f_out.n_atoms, 0)
        frame = f_in.read()
        f_out.write(frame.x, frame.box, frame.step, frame.time, frame.prec)
        x = np.ones((f_in.n_atoms - 1, 3))
        f_out.write(x, frame.box, frame.step, frame.time, frame.prec)
示例#3
0
def test_write_different_prec():
    mf_xtc = XTCFile(XTC_multi_frame)
    with XTCFile('foo.xtc', 'w') as f_out:
        assert_equal(f_out.n_atoms, 0)
        frame = mf_xtc.read()
        f_out.write(frame.x, frame.box, frame.step, frame.time, frame.prec)
        f_out.write(frame.x, frame.box, frame.step, frame.time, 10000.0)
def test_write_different_prec():
    mf_xtc = XTCFile(XTC_multi_frame)
    with XTCFile('foo.xtc', 'w') as f_out:
        assert_equal(f_out.n_atoms, 0)
        frame = mf_xtc.read()
        f_out.write(frame.x, frame.box, frame.step,
                    frame.time, frame.prec)
        f_out.write(frame.x, frame.box, frame.step,
                    frame.time, 10000.0)
示例#5
0
def test_write_prec(tmpdir, xtc):
    outname = str(tmpdir.join('foo.xtc'))
    with XTCFile(outname, 'w') as f_out:
        assert f_out.n_atoms == 0
        frame = xtc.read()
        f_out.write(frame.x, frame.box, frame.step, frame.time, 100.0)
    xtc = XTCFile(outname)
    assert len(xtc) == 1
    frame = xtc.read()
    assert frame.prec == 100.0
def test_xtc():
    f = XTCFile(XTC_single_frame)
    assert_equal(f.n_atoms, 10)
    xyz, box, step, time, prec = f.read()
    # xtc only saves with 3 decimal places precision
    assert_array_almost_equal(xyz.flat, np.arange(30), decimal=3)
    assert_array_almost_equal(box, np.eye(3) * 20, decimal=3)
    assert_equal(step, 0)
    assert_equal(time, 10.0)
    assert_equal(prec, 1000.0)
示例#7
0
def test_xtc():
    f = XTCFile(XTC_single_frame)
    assert_equal(f.n_atoms, 10)
    xyz, box, step, time, prec = f.read()
    # xtc only saves with 3 decimal places precision
    assert_array_almost_equal(xyz.flat, np.arange(30), decimal=3)
    assert_array_almost_equal(box, np.eye(3) * 20, decimal=3)
    assert_equal(step, 0)
    assert_equal(time, 10.0)
    assert_equal(prec, 1000.0)
示例#8
0
def test_write_prec(tmpdir, xtc):
    outname = str(tmpdir.join('foo.xtc'))
    with XTCFile(outname, 'w') as f_out:
        assert f_out.n_atoms == 0
        frame = xtc.read()
        f_out.write(frame.x, frame.box, frame.step, frame.time, 100.0)
    xtc = XTCFile(outname)
    assert len(xtc) == 1
    frame = xtc.read()
    assert frame.prec == 100.0
示例#9
0
def test_write_different_prec(tmpdir, xtc):
    outname = str(tmpdir.join('foo.xtc'))
    with XTCFile(outname, 'w') as f_out:
        assert f_out.n_atoms == 0
        frame = xtc.read()
        f_out.write(frame.x, frame.box, frame.step, frame.time, frame.prec)
        with pytest.raises(IOError):
            f_out.write(frame.x, frame.box, frame.step, frame.time, 10000.0)
示例#10
0
def test_write_xtc():
    with XTCFile(XTC_multi_frame) as f_in, XTCFile('foo.xtc', 'w') as f_out:
        assert_equal(f_out.n_atoms, 0)
        for frame in f_in:
            f_out.write(*frame)

    with XTCFile('foo.xtc') as f:
        assert_equal(len(f), 10)
        ones = np.ones(30).reshape(10, 3)
        box_compare = np.eye(3) * 20
        for i, frame in enumerate(f):
            xyz, box, step, time, prec = frame
            assert_array_almost_equal(xyz, ones * i, decimal=3)
            assert_array_almost_equal(box, box_compare, decimal=3)
            assert_equal(step, i)
            assert_equal(time, i * 0.5)
            assert_equal(prec, 1000.0)
示例#11
0
def test_different_box_xtc(tmpdir, xtc):
    """test if we can write different box-sizes for different frames.
    """
    orig_box = None
    fname = str(tmpdir.join('foo.xtc'))
    with XTCFile(fname, 'w') as f_out:
        assert f_out.n_atoms == 0
        frame = xtc.read()
        f_out.write(frame.x, frame.box, frame.step, frame.time, frame.prec)
        orig_box = frame.box.copy()
        box = frame.box.copy() + 1
        f_out.write(frame.x, box, frame.step, frame.time, frame.prec)

    with XTCFile(fname) as xtc:
        assert len(xtc) == 2
        frame_1 = xtc.read()
        frame_2 = xtc.read()
        assert_array_almost_equal(frame_1.box, orig_box)
        assert_array_almost_equal(frame_1.box + 1, frame_2.box)
示例#12
0
def test_write_xtc_array_like(tmpdir, array_like, xtc):
    fname = str(tmpdir.join("foo.xtc"))
    with XTCFile(fname, 'w') as f:
        for frame in xtc:
            x = array_like(frame.x)
            box = array_like(frame.box)
            f.write(xyz=x,
                    box=box,
                    step=frame.step,
                    time=frame.time,
                    precision=frame.prec)
示例#13
0
def test_write_xtc_dtype(tmpdir, dtype, xtc):
    fname = str(tmpdir.join("foo.xtc"))
    with XTCFile(fname, 'w') as f:
        for frame in xtc:
            x = frame.x.astype(dtype)
            box = frame.box.astype(dtype)
            f.write(xyz=x,
                    box=box,
                    step=frame.step,
                    time=frame.time,
                    precision=frame.prec)
示例#14
0
def test_different_box_xtc():
    """test if we can write different box-sizes for different frames.
    """
    fname = 'foo.xtc'
    orig_box = None
    with XTCFile(XTC_multi_frame) as f_in, XTCFile(fname, 'w') as f_out:
        assert_equal(f_out.n_atoms, 0)
        frame = f_in.read()
        f_out.write(frame.x, frame.box, frame.step, frame.time, frame.prec)
        orig_box = frame.box.copy()
        box = frame.box.copy() + 1
        f_out.write(frame.x, box, frame.step, frame.time, frame.prec)

    with XTCFile(fname) as xtc:
        assert_equal(len(xtc), 2)
        frame_1 = xtc.read()
        frame_2 = xtc.read()

        assert_array_almost_equal(frame_1.box, orig_box)
        assert_array_almost_equal(frame_1.box + 1, frame_2.box)
示例#15
0
def test_read_multi_frame_xtc():
    with XTCFile(XTC_multi_frame) as f:
        f.seek(5)
        assert_equal(f.tell(), 5)
        assert_equal(len(f), 10)
        assert_equal(f.tell(), 5)
        f.seek(0)
        assert_equal(f.tell(), 0)
        ones = np.ones(30).reshape(10, 3)
        box_compare = np.eye(3) * 20
        for i, frame in enumerate(f):
            xyz, box, step, time, prec = frame
            assert_array_almost_equal(xyz, ones * i, decimal=3)
            assert_array_almost_equal(box, box_compare, decimal=3)
            assert_equal(step, i)
            assert_equal(time, i * 0.5)
            assert_equal(prec, 1000.0)
示例#16
0
def xtc():
    with XTCFile(XTC_multi_frame) as f:
        yield f