Esempio n. 1
0
def test_bee(xc, testdir):
    """Check BEEF ensemble code."""
    size = 7  # size of ensemble

    # From a calculator:
    calc = BEECalculator(xc)
    ens = BEEFEnsemble(calc)
    energies = ens.get_ensemble_energies(size)
    assert energies.shape == (size, )

    # From a file:
    ens.write(f'{xc}.bee')
    e, de, contribs, seed, xc = readbee(f'{xc}.bee', all=True)
    assert e + de == pytest.approx(energies, abs=1e-12)
    e2000 = ensemble(e, contribs, xc)
    assert e2000.shape == (2000, )

    # From data:
    ens = BEEFEnsemble(e=e, contribs=contribs, xc=xc, verbose=False)
    energies2 = ens.get_ensemble_energies(size)
    assert energies2 == pytest.approx(energies, abs=1e-12)
Esempio n. 2
0
    h2 = Atoms('H2', [[0, 0, 0], [0, 0, d]])
    h2.center(vacuum=2)
    h2.calc = GPAW(txt='H2-' + xc + '.txt', convergence=c)
    h2.get_potential_energy()
    h2.calc.set(xc=xc)
    h2.get_potential_energy()
    h2.get_forces()
    ens = BEEFEnsemble(h2.calc)
    e_h2 = ens.get_ensemble_energies()

    # H atom:
    h = Atoms('H', cell=h2.cell, magmoms=[1])
    h.center()
    h.calc = GPAW(txt='H-' + xc + '.txt', convergence=c)
    h.get_potential_energy()
    h.calc.set(xc=xc)
    h.get_potential_energy()
    ens = BEEFEnsemble(h.calc)
    e_h = ens.get_ensemble_energies()

    # binding energy
    ae = 2 * e_h - e_h2
    print(ae.mean(), ae.std())
    equal(ae.mean(), E0, 0.015)
    equal(ae.std(), dE0, 0.015)

ens.write('H')
world.barrier()
energies = readbee('H')
equal(abs(energies - e_h).max(), 0, 1e-12)
Esempio n. 3
0
        # Does not work with libxc-4
        continue

    E = []
    V = []
    for a in np.linspace(5.4, 5.5, 3):
        si = bulk('Si', a=a)
        si.calc = GPAW(txt='Si-' + xc + '.txt',
                       mixer=Mixer(0.8, 7, 50.0),
                       xc=xc,
                       kpts=[2, 2, 2],
                       mode=PW(200))
        E.append(si.get_potential_energy())
        ens = BEEFEnsemble(si.calc, verbose=False)
        ens.get_ensemble_energies(200)
        ens.write('Si-{}-{:.3f}'.format(xc, a))
        V.append(si.get_volume())

    p = np.polyfit(V, E, 2)
    v0 = np.roots(np.polyder(p))[0]
    a = (v0 * 4)**(1 / 3)

    a0, da0 = results[xc]

    assert abs(a - a0) < 0.001, (xc, a, a0)

    if world.rank == 0:
        E = []
        for a in np.linspace(5.4, 5.5, 3):
            e = readbee('Si-{}-{:.3f}'.format(xc, a))
            E.append(e)
Esempio n. 4
0
    h2 = Atoms("H2", [[0, 0, 0], [0, 0, d]])
    h2.center(vacuum=2)
    h2.calc = GPAW(txt="H2-" + xc + ".txt", convergence=c)
    h2.get_potential_energy()
    h2.calc.set(xc=xc)
    h2.get_potential_energy()
    h2.get_forces()
    ens = BEEFEnsemble(h2.calc)
    e_h2 = ens.get_ensemble_energies()

    # H atom:
    h = Atoms("H", cell=h2.cell, magmoms=[1])
    h.center()
    h.calc = GPAW(txt="H-" + xc + ".txt", convergence=c)
    h.get_potential_energy()
    h.calc.set(xc=xc)
    h.get_potential_energy()
    ens = BEEFEnsemble(h.calc)
    e_h = ens.get_ensemble_energies()

    # binding energy
    ae = 2 * e_h - e_h2
    print(ae.mean(), ae.std())
    equal(ae.mean(), E0, 0.015)
    equal(ae.std(), dE0, 0.015)

ens.write("H")
world.barrier()
energies = readbee("H")
equal(abs(energies - e_h).max(), 0, 1e-12)