コード例 #1
0
ファイル: test_derivatives.py プロジェクト: shivupa/pyqmc
def test_func3d():
    """
    Ensure that the 3-dimensional functions correctly compute their gradient and laplacian
    """
    from pyqmc.func3d import (
        PadeFunction,
        PolyPadeFunction,
        GaussianFunction,
        ExpCuspFunction,
        test_func3d_gradient,
        test_func3d_laplacian,
    )

    test_functions = {
        "Pade": PadeFunction(0.2),
        "PolyPade": PolyPadeFunction(2.0, 1.5),
        "ExpCusp": ExpCuspFunction(2.0, 1.5),
        "Gaussian": GaussianFunction(0.4),
    }
    delta = 1e-6
    epsilon = 1e-5

    for name, func in test_functions.items():
        assert test_func3d_gradient(func, delta=delta)[0] < epsilon
        assert test_func3d_laplacian(func, delta=delta)[0] < epsilon
コード例 #2
0
def test_func3d():
    """
    Ensure that the 3-dimensional functions correctly compute their gradient and laplacian
    """
    from pyqmc.func3d import (
        PadeFunction,
        PolyPadeFunction,
        GaussianFunction,
        CutoffCuspFunction,
        test_func3d_gradient,
        test_func3d_laplacian,
        test_func3d_gradient_laplacian,
        test_func3d_pgradient,
    )

    test_functions = {
        "Pade": PadeFunction(0.2),
        "PolyPade": PolyPadeFunction(2.0, 1.5),
        "CutoffCusp": CutoffCuspFunction(2.0, 1.5),
        "Gaussian": GaussianFunction(0.4),
    }
    delta = 1e-6
    epsilon = 1e-5

    for name, func in test_functions.items():
        grad = test_func3d_gradient(func, delta=delta)[0]
        lap = test_func3d_laplacian(func, delta=delta)[0]
        andg, andl = test_func3d_gradient_laplacian(func)
        pgrad = test_func3d_pgradient(func, delta=1e-9)[0]
        print(name, grad, lap, "both:", andg, andl)
        print(name, pgrad)
        assert grad < epsilon
        assert lap < epsilon
        assert andg < epsilon
        assert andl < epsilon
        for k, v in pgrad.items():
            assert v < epsilon, (name, k, v)

    #Check CutoffCusp does not diverge at r/rcut = 1
    rcut = 1.5
    f = CutoffCuspFunction(2.0, rcut)
    gamma = 2.0
    rc = 1.5
    basis = CutoffCuspFunction(gamma, rc)
    rvec = np.array([0, 0, rc])[np.newaxis, :]
    r = np.linalg.norm(rvec)[np.newaxis]

    v = basis.value(rvec, r)
    g = basis.gradient(rvec, r)
    l = basis.laplacian(rvec, r)
    g_both, l_both = basis.gradient_laplacian(rvec, r)

    assert abs(v).sum() == 0
    assert abs(g).sum() == 0
    assert abs(l).sum() == 0
    assert abs(g_both).sum() == 0
    assert abs(l_both).sum() == 0
コード例 #3
0
ファイル: test_derivatives.py プロジェクト: krongch2/pyqmc
def test_func3d():
    """
    Ensure that the 3-dimensional functions correctly compute their gradient and laplacian
    """
    from pyqmc.func3d import PadeFunction, GaussianFunction, test_func3d_gradient, test_func3d_laplacian
    test_functions = {
        'Pade': PadeFunction(0.2),
        'Gaussian': GaussianFunction(0.4)
    }
    delta = 1e-6
    epsilon = 1e-5

    for name, func in test_functions.items():
        assert test_func3d_gradient(func, delta=delta)[0] < epsilon
        assert test_func3d_laplacian(func, delta=delta)[0] < epsilon
コード例 #4
0
def test_func3d(func, delta=1e-6, epsilon=1e-5):
    """
    Ensure that the 3-dimensional functions correctly compute their gradient and laplacian
    """
    delta = 1e-6
    epsilon = 1e-5

    grad = func3d.test_func3d_gradient(func, delta=delta)
    lap = func3d.test_func3d_laplacian(func, delta=delta)
    gl = func3d.test_func3d_gradient_laplacian(func)
    gv = func3d.test_func3d_gradient_value(func)
    pgrad = func3d.test_func3d_pgradient(func, delta=1e-9)
    # print(name, grad, lap, "both:", gl["grad"], gl["lap"])
    # print(name, pgrad)
    assert grad < epsilon
    assert lap < epsilon
    assert gl["grad"] < epsilon
    assert gl["lap"] < epsilon
    assert gv["grad"] < epsilon
    assert gv["val"] < epsilon
    for k, v in pgrad.items():
        assert v < epsilon, (func, k, v)