コード例 #1
0
ファイル: test_dx.py プロジェクト: lstorchi/GridDataFormats
def test_write_dx(tmpdir, nptype, dxtype, outfile, counts=100, ndim=3):
    # conversion from numpy array to DX file

    h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10)
    g = Grid(h, edges)

    # hack the grid to be a different dtype
    g.grid = g.grid.astype(nptype)

    assert_equal(g.grid.sum(), counts)

    with tmpdir.as_cwd():
        g.export(outfile)
        g2 = Grid(outfile)

        # check that dxtype was written
        dx = gridData.OpenDX.field(0)
        dx.read(outfile)
        data = dx.components['data']
        out_dxtype = data.type

    assert_almost_equal(g.grid,
                        g2.grid,
                        err_msg="written grid does not match original")
    assert_almost_equal(g.delta,
                        g2.delta,
                        decimal=6,
                        err_msg="deltas of written grid do not match original")

    assert_equal(out_dxtype, dxtype)
コード例 #2
0
ファイル: test_dx.py プロジェクト: MDAnalysis/GridDataFormats
def test_write_dx(tmpdir, nptype, dxtype, counts=100, ndim=3):
    # conversion from numpy array to DX file

    h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10)
    g = Grid(h, edges)

    # hack the grid to be a different dtype
    g.grid = g.grid.astype(nptype)

    assert_equal(g.grid.sum(), counts)

    with tmpdir.as_cwd():
        outfile = "grid.dx"
        g.export(outfile)
        g2 = Grid(outfile)

        # check that dxtype was written
        dx = gridData.OpenDX.field(0)
        dx.read(outfile)
        data = dx.components['data']
        out_dxtype = data.type

    assert_almost_equal(g.grid, g2.grid,
                        err_msg="written grid does not match original")
    assert_almost_equal(
        g.delta, g2.delta,
        decimal=6,
        err_msg="deltas of written grid do not match original")

    assert_equal(out_dxtype, dxtype)
コード例 #3
0
def _test_write_dx(counts=100, ndim=3, nptype="float32", dxtype="float"):
    h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10)
    g = Grid(h, edges)

    # hack the grid to be a different dtype
    g.grid = g.grid.astype(nptype)

    assert_equal(g.grid.sum(), counts)

    with tempdir.in_tempdir():
        outfile = "grid.dx"
        g.export(outfile)
        g2 = Grid(outfile)

        # check that dxtype was written
        dx = gridData.OpenDX.field(0)
        dx.read(outfile)
        data = dx.components['data']
        out_dxtype = data.type

    assert_almost_equal(g.grid, g2.grid,
                        err_msg="written grid does not match original")
    assert_almost_equal(
        g.delta, g2.delta,
        decimal=6,
        err_msg="deltas of written grid do not match original")

    assert_equal(out_dxtype, dxtype)
コード例 #4
0
def mask_generator(maskfile, referencefile=None, distance=5):
    if os.path.splitext(maskfile)[1] == ".pdb":
        mask = GridUtil.gen_distance_grid(referencefile, maskfile)
    else:
        mask = Grid(maskfile)

    mask.grid = mask.grid < distance
    return mask
コード例 #5
0
ファイル: test_dx.py プロジェクト: lstorchi/GridDataFormats
def test_write_dx_ValueError(tmpdir, nptype, outfile, counts=100, ndim=3):
    h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10)
    g = Grid(h, edges)

    # hack the grid to be a different dtype
    g.grid = g.grid.astype(nptype)

    with pytest.raises(ValueError):
        with tmpdir.as_cwd():
            g.export(outfile)
コード例 #6
0
ファイル: test_dx.py プロジェクト: MDAnalysis/GridDataFormats
def test_write_dx_ValueError(tmpdir, nptype, counts=100, ndim=3):
    h, edges = np.histogramdd(np.random.random((counts, ndim)), bins=10)
    g = Grid(h, edges)

    # hack the grid to be a different dtype
    g.grid = g.grid.astype(nptype)

    with pytest.raises(ValueError):
        with tmpdir.as_cwd():
            outfile = "grid.dx"
            g.export(outfile)