Exemple #1
0
def ip(symbol, fd, setup):
    xc = 'LDA'
    aea = AllElectronAtom(symbol, log=fd)
    aea.initialize()
    aea.run()
    aea.refine()
    aea.scalar_relativistic = True
    aea.refine()
    energy = aea.ekin + aea.eH + aea.eZ + aea.exc
    eigs = []
    for l, channel in enumerate(aea.channels):
        n = l + 1
        for e, f in zip(channel.e_n, channel.f_n):
            if f == 0:
                break
            eigs.append((e, n, l))
            n += 1
    e0, n0, l0 = max(eigs)
    aea = AllElectronAtom(symbol, log=fd)
    aea.add(n0, l0, -1)
    aea.initialize()
    aea.run()
    aea.refine()
    aea.scalar_relativistic = True
    aea.refine()
    IP = aea.ekin + aea.eH + aea.eZ + aea.exc - energy
    IP *= Ha

    s = create_setup(symbol, type=setup, xc=xc)
    f_ln = defaultdict(list)
    for l, f in zip(s.l_j, s.f_j):
        if f:
            f_ln[l].append(f)

    f_sln = [[f_ln[l] for l in range(1 + max(f_ln))]]
    calc = AtomPAW(symbol, f_sln, xc=xc, txt=fd, setups=setup)
    energy = calc.results['energy']
    # eps_n = calc.wfs.kpt_u[0].eps_n

    f_sln[0][l0][-1] -= 1
    calc = AtomPAW(symbol, f_sln, xc=xc, charge=1, txt=fd, setups=setup)
    IP2 = calc.results['energy'] - energy
    return IP, IP2
Exemple #2
0
    'GGA_X_B88+GGA_C_LYP': 2.28183010548,
    'GGA_X_FT97_A+GGA_C_LYP': 2.26846048873,
    }

libxc_set = [
    'LDA_X', 'LDA_X+LDA_C_PW', 'LDA_X+LDA_C_VWN', 'LDA_X+LDA_C_PZ',
    'GGA_X_PBE+GGA_C_PBE', 'GGA_X_PBE_R+GGA_C_PBE',
    'GGA_X_B88+GGA_C_P86', 'GGA_X_B88+GGA_C_LYP',
    'GGA_X_FT97_A+GGA_C_LYP'
    ]

x = 0.000001
for xcname in libxc_set:
    ra.seed(8)
    xc = XC(xcname)
    s = create_setup('N', xc)
    ni = s.ni
    nii = ni * (ni + 1) // 2
    D_p = 0.1 * ra.random(nii) + 0.4
    H_p = np.zeros(nii)

    E1 = s.xc_correction.calculate(xc, D_p.reshape(1, -1), H_p.reshape(1, -1))
    dD_p = x * ra.random(nii)
    D_p += dD_p
    dE = np.dot(H_p, dD_p) / x
    E2 = s.xc_correction.calculate(xc, D_p.reshape(1, -1))
    print xcname, dE, (E2 - E1) / x
    equal(dE, (E2 - E1) / x, 0.003)

    E2s = s.xc_correction.calculate(xc,
        np.array([0.5 * D_p, 0.5 * D_p]), np.array([H_p, H_p]))
Exemple #3
0
    'GGA_X_B88+GGA_C_P86': 2.30508027546,
    'GGA_X_B88+GGA_C_LYP': 2.28183010548,
    'GGA_X_FT97_A+GGA_C_LYP': 2.26846048873,
    }

libxc_set = [
    'LDA_X', 'LDA_X+LDA_C_PW', 'LDA_X+LDA_C_VWN', 'LDA_X+LDA_C_PZ',
    'GGA_X_PBE+GGA_C_PBE', 'GGA_X_PBE_R+GGA_C_PBE', 'GGA_X_B88+GGA_C_P86',
    'GGA_X_B88+GGA_C_LYP', 'GGA_X_FT97_A+GGA_C_LYP'
]

x = 0.000001
for xcname in libxc_set:
    ra.seed(8)
    xc = XC(xcname)
    s = create_setup('N', xc)
    ni = s.ni
    nii = ni * (ni + 1) // 2
    D_p = 0.1 * ra.random(nii) + 0.4
    H_p = np.zeros(nii)

    E1 = s.xc_correction.calculate(xc, D_p.reshape(1, -1), H_p.reshape(1, -1))
    dD_p = x * ra.random(nii)
    D_p += dD_p
    dE = np.dot(H_p, dD_p) / x
    E2 = s.xc_correction.calculate(xc, D_p.reshape(1, -1))
    print xcname, dE, (E2 - E1) / x
    equal(dE, (E2 - E1) / x, 0.003)

    E2s = s.xc_correction.calculate(xc, np.array([0.5 * D_p, 0.5 * D_p]),
                                    np.array([H_p, H_p]))
Exemple #4
0
    import argparse
    import matplotlib.pyplot as plt
    from gpaw.setup import create_setup

    parser = argparse.ArgumentParser(
        description='Calculate approximation to the energy variation with '
        'plane-wave cutoff energy.  The approximation is to use the kinetic '
        'energy from a PAW atom, which can be calculated efficiently on '
        'a radial grid.')
    parser.add_argument('-d', '--derivative', type=float, metavar='ECUT',
                        help='Calculate derivative of energy correction with '
                        'respect to plane-wave cutoff energy.')
    parser.add_argument('name', help='Name of PAW dataset.')
    args = parser.parse_args()

    ds = create_setup(args.name)

    G, de, e0 = ekin(ds)
    dG = G[1]

    if args.derivative:
        dedecut = -dekindecut(G, de, args.derivative / Ha)
        print('de/decut({}, {} eV) = {:.6f}'
              .format(args.name, args.derivative, dedecut))
    else:
        de = (np.add.accumulate(de) - 0.5 * de[0] - 0.5 * de) * dG

        ecut = 0.5 * G**2 * Ha
        y = (de[-1] - de) * Ha
        plt.plot(ecut, y)
        plt.xlim(300, 1000)
Exemple #5
0
from math import sqrt, pi
import numpy as np
from gpaw.setup import create_setup
from gpaw.grid_descriptor import GridDescriptor
from gpaw.localized_functions import create_localized_functions
from gpaw.xc import XC

n = 60  #40 /8 * 10
a = 10.0
gd = GridDescriptor((n, n, n), (a, a, a))
c_LL = np.identity(9, float)
a_Lg = gd.zeros(9)
nspins = 2
xc = XC('LDA')
for soft in [False]:
    s = create_setup('Cu', xc, lmax=2)
    ghat_l = s.ghat_l
    ghat_Lg = create_localized_functions(ghat_l, gd, (0.54321, 0.5432, 0.543))
    a_Lg[:] = 0.0
    ghat_Lg.add(a_Lg, c_LL)
    for l in range(3):
        for m in range(2 * l + 1):
            L = l**2 + m
            a_g = a_Lg[L]
            Q0 = gd.integrate(a_g) / sqrt(4 * pi)
            Q1_m = -gd.calculate_dipole_moment(a_g) / sqrt(4 * pi / 3)
            print(Q0)
            if l == 0:
                Q0 -= 1.0
                Q1_m[:] = 0.0
            elif l == 1:
Exemple #6
0
from gpaw.setup import create_setup

for symbol, M, n in [('Pd', 1, 6),  # 4d -> 5s
                     ('Fe', 3, 5),
                     ('V', 3, 5),
                     ('Ti', 2, 5)]:
    s = create_setup(symbol)
    f_si = s.calculate_initial_occupation_numbers(magmom=M,
                                                  hund=False,
                                                  charge=0,
                                                  nspins=2)
    print(f_si)
    magmom = (f_si[0] - f_si[1]).sum()
    assert abs(magmom - M) < 1e-10
    N = ((f_si[0] - f_si[1]) != 0).sum()
    assert n == N, 'Wrong # of values have changed'
Exemple #7
0
import numpy as np
import numpy.random as ra
from gpaw.setup import create_setup
from gpaw.xc import XC

x = 0.000001
ra.seed(8)
xc = XC('LDA')
s = create_setup('H', xc)
ni = s.ni
nii = ni * (ni + 1) // 2
D_p = 0.1 * ra.random((1, nii)) + 0.2
H_p = np.zeros(nii)


def f(x):
    return x


J_pp = s.xc_correction.four_phi_integrals(D_p, f)

# Check integrals using two_phi_integrals function and finite differences:
pass
Exemple #8
0
import numpy as np
import numpy.random as ra
from gpaw.setup import create_setup
from gpaw.xc import XC
from gpaw.test import equal


x = 0.000001
ra.seed(8)
for xc in ["LDA", "PBE"]:
    print xc
    xc = XC(xc)
    s = create_setup("N", xc)
    ni = s.ni
    nii = ni * (ni + 1) // 2
    D_p = 0.1 * ra.random(nii) + 0.2
    H_p = np.zeros(nii)

    E = xc.calculate_paw_correction(s, D_p.reshape(1, -1), H_p.reshape(1, -1))
    dD_p = x * ra.random(nii)
    dE = np.dot(H_p, dD_p) / x
    D_p += dD_p
    Ep = xc.calculate_paw_correction(s, D_p.reshape(1, -1))
    D_p -= 2 * dD_p
    Em = xc.calculate_paw_correction(s, D_p.reshape(1, -1))
    print dE, dE - 0.5 * (Ep - Em) / x
    equal(dE, 0.5 * (Ep - Em) / x, 1e-6)

    Ems = xc.calculate_paw_correction(s, np.array([0.5 * D_p, 0.5 * D_p]))
    print Em - Ems
    equal(Em, Ems, 1.0e-12)
Exemple #9
0
from math import sqrt, pi
import numpy as np
from gpaw.setup import create_setup
from gpaw.grid_descriptor import GridDescriptor
from gpaw.localized_functions import create_localized_functions
from gpaw.xc import XC

n = 60#40 /8 * 10
a = 10.0
gd = GridDescriptor((n, n, n), (a, a, a))
c_LL = np.identity(9, float)
a_Lg = gd.zeros(9)
nspins = 2
xc = XC('LDA')
for soft in [False]:
    s = create_setup('Cu', xc, lmax=2)
    ghat_l = s.ghat_l
    ghat_Lg = create_localized_functions(ghat_l, gd, (0.54321, 0.5432, 0.543))
    a_Lg[:] = 0.0
    ghat_Lg.add(a_Lg, c_LL)
    for l in range(3):
        for m in range(2 * l + 1):
            L = l**2 + m
            a_g = a_Lg[L]
            Q0 = gd.integrate(a_g) / sqrt(4 * pi)
            Q1_m = -gd.calculate_dipole_moment(a_g) / sqrt(4 * pi / 3)
            print Q0
            if l == 0:
                Q0 -= 1.0
                Q1_m[:] = 0.0
            elif l == 1:
Exemple #10
0
import numpy as np
import numpy.random as ra
from gpaw.setup import create_setup
from gpaw.xc import XC


x = 0.000001
ra.seed(8)
xc = XC('LDA')
s = create_setup('H', xc)
ni = s.ni
nii = ni * (ni + 1) // 2
D_p = 0.1 * ra.random((1, nii)) + 0.2
H_p = np.zeros(nii)

def f(x):
    return x

J_pp = s.xc_correction.four_phi_integrals(D_p, f)

# Check integrals using two_phi_integrals function and finite differences:
pass