예제 #1
0
def check_del_atom(value):
    atoms, exp = value[0:2]
    proc, alg = value[-1]

    scat = ElasticScatter(exp_dict=exp, verbose=True)
    scat.set_processor(proc, alg)

    assert scat._check_wrap_atoms_state(atoms) == False
    # Test a set of different sized ensembles
    ans1 = scat.get_fq(atoms)
    assert scat._check_wrap_atoms_state(atoms) == True
    # Check that Scatter gave back something
    assert ans1 is not None
    assert np.any(ans1)

    atoms2 = dc(atoms)
    del atoms2[np.random.choice(len(atoms2))]
    assert scat._check_wrap_atoms_state(atoms2) == False
    ans2 = scat.get_fq(atoms2)
    assert scat._check_wrap_atoms_state(atoms2) == True
    # Check that Scatter gave back something
    assert ans2 is not None
    assert np.any(ans2)

    assert not np.allclose(ans1, ans2)
    # make certain we did not give back the same pointer
    assert ans1 is not ans2
    # Check that all the values are not zero
    del atoms, exp, proc, alg, scat, ans1
    return
예제 #2
0
def check_scatter_fq(value):
    """
    Check two processor, algorithm pairs against each other for 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_fq(atoms)

    # run algorithm 2
    scat.set_processor(proc2, alg2)
    ans2 = scat.get_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
예제 #3
0
def check_del_atom(value):
    atoms, exp = value[0:2]
    proc, alg = value[-1]

    scat = ElasticScatter(exp_dict=exp, verbose=True)
    scat.set_processor(proc, alg)

    assert scat._check_wrap_atoms_state(atoms) == False
    # Test a set of different sized ensembles
    ans1 = scat.get_fq(atoms)
    assert scat._check_wrap_atoms_state(atoms) == True
    # Check that Scatter gave back something
    assert ans1 is not None
    assert np.any(ans1)

    atoms2 = dc(atoms)
    del atoms2[np.random.choice(len(atoms2))]
    assert scat._check_wrap_atoms_state(atoms2) == False
    ans2 = scat.get_fq(atoms2)
    assert scat._check_wrap_atoms_state(atoms2) == True
    # Check that Scatter gave back something
    assert ans2 is not None
    assert np.any(ans2)

    assert not np.allclose(ans1, ans2)
    # make certain we did not give back the same pointer
    assert ans1 is not ans2
    # Check that all the values are not zero
    del atoms, exp, proc, alg, scat, ans1
    return
예제 #4
0
def finite_difference_grad(atoms, exp_dict):
    s = ElasticScatter(exp_dict, verbose=True)
    start_fq = s.get_fq(atoms)
    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
예제 #5
0
def check_scatter_fq(value):
    """
    Smoke test for FQ

    Parameters
    ----------
    value: list or tuple
        The values to use in the tests
    """
    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_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
예제 #6
0
def test_consistency():
    outs = [[] for i in range(len(test_atoms))]
    s = ElasticScatter()
    for i, atoms in enumerate(test_data):
        fq = s.get_fq(atoms)
        outs[i % len(test_atoms)].append(fq)
    for j in range(len(test_atoms)):
        for a, b in permutations(outs[j], 2):
            stats_check(a, b, rtol=2e-7, atol=1e-7)
예제 #7
0
def test_consistency():
    outs = [[] for i in range(len(test_atoms))]
    s = ElasticScatter()
    for i, atoms in enumerate(test_data):
        fq = s.get_fq(atoms)
        outs[i % len(test_atoms)].append(fq)
    for j in range(len(test_atoms)):
        for a, b in permutations(outs[j], 2):
            stats_check(a, b, rtol=2e-7, atol=1e-7)
예제 #8
0
def check_scatter_consistancy(value):
    atoms, exp = value[0:2]
    proc, alg = value[-1]

    scat = ElasticScatter(exp_dict=exp, verbose=True)
    scat.set_processor(proc, alg)
    ans = scat.get_pdf(atoms)
    ans1 = scat.get_fq(atoms)
    print(len(ans1))
    print(scat.get_scatter_vector().shape)
    ans2 = scat.get_sq(atoms)
    print(len(ans2))
    ans3 = scat.get_iq(atoms)
예제 #9
0
def check_dynamics(value):
    """
    Test classical dynamics simulation, symplectic dynamics are look the same
    forward as reversed

    Parameters
    ----------
    value: list or tuple
        The values to use in the tests
    """
    ideal_atoms, _ = value[0]
    ideal_atoms.set_velocities(np.zeros((len(ideal_atoms), 3)))
    if isinstance(value[1], str):
        s = ElasticScatter(verbose=True)
        target_data = None
        exp_func = None
        exp_grad = None
        if value[1] == 'PDF':
            target_data = s.get_pdf(ideal_atoms)
            exp_func = s.get_pdf
            exp_grad = s.get_grad_pdf

        elif value[1] == 'FQ':
            target_data = s.get_fq(ideal_atoms)
            exp_func = s.get_fq
            exp_grad = s.get_grad_fq
        calc = Calc1D(target_data=target_data,
                      exp_function=exp_func, exp_grad_function=exp_grad,
                      potential='rw', conv=30)
    else:
        calc = value[1]
    ideal_atoms.positions *= 1.02

    ideal_atoms.set_calculator(calc)
    start_pe = ideal_atoms.get_potential_energy()
    e = value[2]
    traj = classical_dynamics(ideal_atoms, e, 5)

    pe_list = []
    for atoms in traj:
        pe_list.append(atoms.get_potential_energy())
    min_pe = np.min(pe_list)
    print(min_pe, start_pe, len(traj))
    print(pe_list)
    if start_pe != 0.0:
        assert min_pe < start_pe
예제 #10
0
def check_n_forces(value):
    """
    Test numerical vs analytical forces

    Parameters
    ----------
    value: list or tuple
        The values to use in the tests
    """
    rtol = 1e-6
    atol = 6e-5
    ideal_atoms = value[0]
    ideal_atoms.set_velocities(np.zeros((len(ideal_atoms), 3)))
    if isinstance(value[1], str):
        s = ElasticScatter(verbose=True)
        target_data = None
        exp_func = None
        exp_grad = None
        if value[1] == 'PDF':
            target_data = s.get_pdf(ideal_atoms)
            exp_func = s.get_pdf
            exp_grad = s.get_grad_pdf

        elif value[1] == 'FQ':
            target_data = s.get_fq(ideal_atoms)
            exp_func = s.get_fq
            exp_grad = s.get_grad_fq
        calc = Calc1D(target_data=target_data,
                      exp_function=exp_func, exp_grad_function=exp_grad,
                      potential='rw', conv=1)
    else:
        calc = value[1]
    ideal_atoms.positions *= 1.02

    ideal_atoms.set_calculator(calc)
    ans1 = ideal_atoms.get_forces()
    ans2 = calc.calculate_numerical_forces(ideal_atoms, d=5e-5)
    stats_check(ans2, ans1,
                rtol=rtol,
                atol=atol
                )
예제 #11
0
def check_n_forces(value):
    """
    Test numerical vs analytical forces

    Parameters
    ----------
    value: list or tuple
        The values to use in the tests
    """
    rtol = 1e-6
    atol = 6e-5
    ideal_atoms = value[0]
    ideal_atoms.set_velocities(np.zeros((len(ideal_atoms), 3)))
    if isinstance(value[1], str):
        s = ElasticScatter(verbose=True)
        target_data = None
        exp_func = None
        exp_grad = None
        if value[1] == 'PDF':
            target_data = s.get_pdf(ideal_atoms)
            exp_func = s.get_pdf
            exp_grad = s.get_grad_pdf

        elif value[1] == 'FQ':
            target_data = s.get_fq(ideal_atoms)
            exp_func = s.get_fq
            exp_grad = s.get_grad_fq
        calc = Calc1D(target_data=target_data,
                      exp_function=exp_func,
                      exp_grad_function=exp_grad,
                      potential='rw',
                      conv=1)
    else:
        calc = value[1]
    ideal_atoms.positions *= 1.02

    ideal_atoms.set_calculator(calc)
    ans1 = ideal_atoms.get_forces()
    ans2 = calc.calculate_numerical_forces(ideal_atoms, d=5e-5)
    stats_check(ans2, ans1, rtol=rtol, atol=atol)
예제 #12
0
def test_fq_against_srfit():
    # unpack the atoms and experiment
    atoms = local_test_atoms
    exp = None

    # get the pyIID F(Q)
    s = ElasticScatter(exp)
    # s.set_processor('CPU', 'nxn')

    # get the SrFit F(Q)
    stru = convert_atoms_to_stru(atoms)
    srfit_calc = DebyePDFCalculator()
    srfit_calc.qmin = s.exp['qmin']
    srfit_calc.qmax = s.exp['qmax']
    srfit_calc.qstep = s.exp['qbin']
    srfit_calc(stru)
    stats_check(s.get_scatter_vector(), srfit_calc.qgrid)
    ans1 = s.get_fq(atoms)
    ans2 = srfit_calc.fq
    stats_check(ans1, ans2, rtol=1e-4, atol=5e-6)
    del srfit_calc
    stats_check(ans1, ans2, rtol=1e-4, atol=5e-6)