Ejemplo n.º 1
0
def check_scatter_grad_fq(value):
    """
    Check two processor, algorithm pairs against each other for gradient FQ
    calculation
    :param value:
    :return:
    """
    # set everything up
    atoms, exp = value[:2]
    scat = ElasticScatter(exp_dict=exp, verbose=True)
    proc1, alg1 = value[-1][0]
    proc2, alg2 = value[-1][1]

    # run algorithm 1
    scat.set_processor(proc1, alg1)
    ans1 = scat.get_grad_fq(atoms)

    # run algorithm 2
    scat.set_processor(proc2, alg2)
    ans2 = scat.get_grad_fq(atoms)

    # test
    if not stats_check(ans1, ans2, rtol, atol):
        print(value)
    assert_allclose(ans1, ans2, rtol=rtol, atol=atol)
    # make certain we did not give back the same pointer
    assert ans1 is not ans2
Ejemplo n.º 2
0
def check_scatter_grad_fq(value):
    """
    Smoke test for grad FQ
    :param value:
    :return:
    """
    atoms, exp = value[0:2]
    proc, alg = value[-1]

    scat = ElasticScatter(exp_dict=exp, verbose=True)
    scat.set_processor(proc, alg)
    # Test a set of different sized ensembles
    
    ans = scat.get_grad_fq(atoms)
    # Check that Scatter gave back something
    assert ans is not None
    # Check that all the values are not zero
    assert np.any(ans)
    del atoms, exp, proc, alg, scat, ans
    return
Ejemplo n.º 3
0
    finite_difference_grad_fq = np.zeros((len(atoms), 3, len(start_fq)))
    for i in range(len(atoms)):
        for w in range(3):
            atoms2 = dc(atoms)
            atoms2[i].position[w] += dq
            fq2 = s.get_fq(atoms2)
            finite_difference_grad_fq[i, w, :] = (fq2 - start_fq) / dq
    return finite_difference_grad_fq


if __name__ == '__main__':
    rt = 1e-5
    at = 2e-2
    import matplotlib.pyplot as plt

    # atoms = setup_atomic_square()[0]
    # atoms.adps = ADP(atoms, adps=np.random.random((len(atoms), 3)))
    atoms = Atoms('Au2', [[0, 0, 0], [3, 0, 0]])
    exp = None
    s = ElasticScatter(exp)
    # s.set_processor('CPU', 'nxn')
    a = finite_difference_grad(atoms, exp)
    b = s.get_grad_fq(atoms)
    print(a[0, 0] / b[0, 0])
    plt.plot(a[0, 0, :], label='fd')
    plt.plot(b[0, 0, :], label='analytical')
    plt.legend(loc='best')
    plt.show()
    # stats_check(a, b, rt, at)
    # assert_allclose(a, b, rtol=rt, atol=at)