예제 #1
0
def get_potential_energy(in_file='input.traj'):
    """Performs a ASE get_potential_energy() call with the ase-espresso calculator
    with the keywords defined inside the atoms object information.

    This can be a singlepoint calculation or a full relaxation depending
    on the keywords.

    Parameters
    ----------
    in_file : str
        Name of the input file to load from the local directory.
    """
    atoms = read(in_file)

    # Planewave basis set requires periodic boundary conditions
    atoms.set_pbc([1, 1, 1])

    # Assign kpoints to be split across nodes
    if get_nnodes() > 1:
        if not np.prod(atoms.info['kpts']) == 1:
            atoms.info['parflags'] = '-npool {}'.format(get_nnodes())

    # Setting up the calculator
    calc = espresso(**atoms.info)
    atoms.set_calculator(calc)

    # Perform the calculation and write trajectory from log.
    atoms.get_potential_energy()
    images = log_to_atoms(out_file='output.traj')

    # Save the calculator to the local disk for later use.
    try:
        calc.save_flev_output()
    except (RuntimeError):
        calc.save_output()

    if images[-1].info.get('beefensemble'):
        beef = BEEFEnsemble(calc).get_ensemble_energies()
        images[-1].info['beef_std'] = beef.std()
        write('output.traj', images)

    return atoms_to_encode(images)
예제 #2
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)
예제 #3
0
#Data is stored in a dictionary with key: input sys.argv string "s" indicating ion-species. value : tuple of one value and one array,
#indicating Gsol and dGsol.
output = {}

#Perform solvent-only (gas phase) calculation
solvent.set_cell(cell)
solvent.center()  #set box size
calc = GPAW(xc=xc, gpts=h2gpts(h, solvent.get_cell(), idiv=16))
solvent.calc = calc
solvent.get_potential_energy()  #converge WFs with PBE

calc.set(xc=beef)
solvent.calc = calc
E_sv = solvent.get_potential_energy()  #BEEF best fit energy
ense = BEEFEnsemble(calc)
dE_sv = ense.get_ensemble_energies(
)  #N=2000 non-self-consist calculation to generate uncertainty spread

#Perform solvent-only (solvated phase) calculation
scalc = SolvationGPAW(xc=xc,
                      gpts=h2gpts(h, solvent.get_cell(), idiv=16),
                      cavity=EffectivePotentialCavity(
                          effective_potential=Power12Potential(
                              atomic_radii, u0),
                          temperature=T,
                          surface_calculator=GradientSurface()),
                      dielectric=LinearDielectric(epsinf=epsinf),
                      interactions=[SurfaceInteraction(surface_tension=gamma)])
solvent.calc = scalc
solvent.get_potential_energy()
예제 #4
0
for xc, E0, dE0 in [('mBEEF', 4.86, 0.16), ('BEEF-vdW', 5.13, 0.20),
                    ('mBEEF-vdW', 4.74, 0.36)]:
    print(xc)
    if not newlibxc and xc[0] == 'm':
        print('Skipped')
        continue

    # H2 molecule:
    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())
예제 #5
0
kp2 = [1 for i in range(3)]
for i in range(3):
    kp2[i] = int(np.ceil(20 / np.linalg.norm(atoms.cell[i, :])))

vdW = 'BEEF-vdW'

calc = GPAW(xc=vdW,
            mode=PW(700, dedecut='estimate'),
            kpts={
                'size': kp2,
                'gamma': True
            },
            occupations=FermiDirac(width=0.05))

atoms.set_calculator(calc)
name = atoms.get_chemical_formula(mode='hill')

atoms.calc.set(txt=name + '_final.txt')
atoms.calc.attach(atoms.calc.write, 5, name + '_final.gpw')
uf = ExpCellFilter(atoms, constant_volume=True)
relax = BFGS(uf)
traj = Trajectory(name + '_final.traj', 'w', atoms)
relax.attach(traj)
relax.run(fmax=0.03)
atoms.calc.write(name + '_final.gpw')
#Writing ensemble energies to file
if atoms.calc.get_xc_functional() == 'BEEF-vdW':
    ens = BEEFEnsemble(atoms.calc)
    ens_material = ens.get_ensemble_energies()
    np.savetxt(str(name) + '_Ensemble_Energies.txt', ens_material)
예제 #6
0
from jasp import *
from ase.dft.bee import BEEFEnsemble
with jasp('molecules/H-beef') as calc:
    BE1 = BEEFEnsemble(calc.get_atoms()).get_ensemble_energies()
with jasp('molecules/H2-beef') as calc:
    BE2 = BEEFEnsemble(calc.get_atoms()).get_ensemble_energies()
print((2 * BE1 - BE2).mean())
print((2 * BE1 - BE2).std())
예제 #7
0
    if xc == 'mBEEF-vdW':
        # 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):
예제 #8
0
for xc, E0, dE0 in [("mBEEF", 4.86, 0.16), ("BEEF-vdW", 5.13, 0.20), ("mBEEF-vdW", 4.74, 0.36)]:
    print(xc)
    if not newlibxc and xc[0] == "m":
        print("Skipped")
        continue

    # H2 molecule:
    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())