Exemple #1
0
def generate_basis_functions(ppdata):
    class SimpleBasis(Basis):
        def __init__(self, symbol, l_j):
            Basis.__init__(self, symbol, 'simple', readxml=False)
            self.generatordata = 'simple'
            self.d = 0.02
            self.ng = 160
            rgd = self.get_grid_descriptor()
            bf_j = self.bf_j
            rcgauss = rgd.r_g[-1] / 3.0
            gauss_g = np.exp(-(rgd.r_g / rcgauss)**2.0)
            for l in l_j:
                phit_g = rgd.r_g**l * gauss_g
                norm = (rgd.integrate(phit_g**2) / (4 * np.pi))**0.5
                phit_g /= norm
                bf = BasisFunction(l, rgd.r_g[-1], phit_g, 'gaussian')
                bf_j.append(bf)
    #l_orb_j = [state.l for state in self.data['states']]
    b1 = SimpleBasis(ppdata.symbol, ppdata.l_orb_j)
    apaw = AtomPAW(ppdata.symbol, [ppdata.f_ln], h=0.05, rcut=9.0,
                   basis={ppdata.symbol: b1},
                   setups={ppdata.symbol : ppdata},
                   lmax=0, txt=None)
    basis = apaw.extract_basis_functions()
    return basis
def generate_basis_functions(ppdata):
    class SimpleBasis(Basis):
        def __init__(self, symbol, l_j):
            Basis.__init__(self, symbol, 'simple', readxml=False)
            self.generatordata = 'simple'
            self.d = 0.02
            self.ng = 160
            rgd = self.get_grid_descriptor()
            bf_j = self.bf_j
            rcgauss = rgd.r_g[-1] / 3.0
            gauss_g = np.exp(-(rgd.r_g / rcgauss)**2.0)
            for l in l_j:
                phit_g = rgd.r_g**l * gauss_g
                norm = (rgd.integrate(phit_g**2) / (4 * np.pi))**0.5
                phit_g /= norm
                bf = BasisFunction(l, rgd.r_g[-1], phit_g, 'gaussian')
                bf_j.append(bf)
    #l_orb_j = [state.l for state in self.data['states']]
    b1 = SimpleBasis(ppdata.symbol, ppdata.l_orb_j)
    apaw = AtomPAW(ppdata.symbol, [ppdata.f_ln], h=0.05, rcut=9.0,
                   basis={ppdata.symbol: b1},
                   setups={ppdata.symbol: ppdata},
                   lmax=0, txt=None)
    basis = apaw.extract_basis_functions()
    return basis
Exemple #3
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 #4
0
 def create_basis_functions(self):
     class SimpleBasis(Basis):
         def __init__(self, symbol, l_j):
             Basis.__init__(self, symbol, 'simple', readxml=False)
             self.generatordata = 'simple'
             self.d = 0.02
             self.ng = 160
             rgd = self.get_grid_descriptor()
             bf_j = self.bf_j
             rcgauss = rgd.rcut / 3.0
             gauss_g = np.exp(-(rgd.r_g / rcgauss)**2.0)
             for l in l_j:
                 phit_g = rgd.r_g**l * gauss_g
                 norm = np.dot((rgd.r_g * phit_g)**2, rgd.dr_g)**.5
                 phit_g /= norm
                 bf = BasisFunction(l, rgd.rcut, phit_g, 'gaussian')
                 bf_j.append(bf)
     b1 = SimpleBasis(self.symbol, range(max(self.l_j) + 1))
     apaw = AtomPAW(self.symbol, [self.f_ln], h=0.05, rcut=9.0,
                    basis={self.symbol: b1},
                    setups={self.symbol : self},
                    lmax=0, txt=None)
     basis = apaw.extract_basis_functions()
     return basis
Exemple #5
0
import numpy as np
x = np.linspace(0.0, 5.0, 1000)
dr = x[1] - x[0]

psi = pp.phit_j[0].map(x)
p = pp.pt_j[0].map(x)

from gpaw.atom.atompaw import AtomPAW

if 0:
    f = 1.0  #1e-12
    c = AtomPAW(
        'H',
        [[[2.0], [4.0]]],
        #charge=1 - f,
        h=0.04,
        #setups='paw',
        #setups='hgh',
        setups={'H': s})

    import pylab as pl
    pl.plot(c.wfs.gd.r_g, c.hamiltonian.vt_sg[0])
    pl.show()
    raise SystemExit

#print 'test v201 Au.pz-d-hgh.UPF'
#s = UPFSetupData('Au.pz-d-hgh.UPF')
#print 'v201 ok'

#print 'test horrible version O.pz-mt.UPF'
#s = UPFSetupData('O.pz-mt.UPF')
Exemple #6
0

# Load pseudopotential from Python module as string, then
# write the string to a file, then load the file.
def upf(upf_module, fname):
    with open(fname, 'w') as fd:
        fd.write(upf_module.ps_txt)
    return UPFSetupData(fname)


if world.rank == 0:  # This test is not really parallel
    kwargs = dict(txt=None)
    for setup in ['paw', 'hgh', upf(H_hgh, 'H.pz-hgh.UPF')]:
        calc = AtomPAW('H', [[[1]]],
                       rcut=12.0,
                       h=0.05,
                       setups={'H': setup},
                       **kwargs)
        tol = 5e-4 if setup in ['paw', 'hgh'
                                ] else 1e-3  # horrible UPF right now
        check('H %s' % setup, calc, [-0.233471], tol)

    for setup in ['paw', 'hgh', upf(O_hgh, 'O.pz-hgh.UPF')]:
        calc = AtomPAW('O', [[[2], [4]]],
                       rcut=10.0,
                       h=0.035,
                       setups={'O': setup},
                       **kwargs)
        tol = 1e-3 if setup in ['paw', 'hgh'
                                ] else 5e-3  # horrible UPF right now
        check('O %s' % setup, calc, [-0.871362, -0.338381], tol)
Exemple #7
0
def atompaw(setup, f_ln, rcut, **kwargs):
    return AtomPAW(setup.symbol, [f_ln],
                   rcut=rcut,
                   setups={setup.symbol: setup},
                   **kwargs)
Exemple #8
0
def upfplot(setup, show=True, calculate=False):
    # A version of this, perhaps nicer, is in pseudopotential.py.
    # Maybe it is not worth keeping this version
    if isinstance(setup, dict):
        setup = UPFSetupData(setup)

    pp = setup.data
    r0 = pp['r'].copy()
    r0[0] = 1e-8

    def rtrunc(array, rdividepower=0):
        r = r0[:len(array)]
        arr = divrl(array, rdividepower, r)
        return r, arr

    import pylab as pl
    fig = pl.figure()
    fig.canvas.set_window_title('%s - UPF setup for %s' %
                                (pp['fname'], setup.symbol))

    vax = fig.add_subplot(221)
    pax = fig.add_subplot(222)
    rhoax = fig.add_subplot(223)
    wfsax = fig.add_subplot(224)

    r, v = rtrunc(pp['vlocal'])

    vax.plot(r, v, label='vloc')

    vscreened, rhocomp = screen_potential(r, v, setup.Nv)
    icut = len(rhocomp)
    vcomp = v.copy()
    vcomp[:icut] -= vscreened
    vax.axvline(r[icut], ls=':', color='k')

    vax.plot(r, vcomp, label='vcomp')
    vax.plot(r[:icut], vscreened, label='vscr')
    vax.axis(xmin=0.0, xmax=6.0)
    rhoax.plot(r[:icut], rhocomp[:icut], label='rhocomp')

    for j, proj in enumerate(pp['projectors']):
        r, p = rtrunc(proj.values, 0)
        pax.plot(r, p, label='p%d [l=%d]' % (j + 1, proj.l))

    for j, st in enumerate(pp['states']):
        r, psi = rtrunc(st.values, 1)
        wfsax.plot(r, r * psi, label='wf%d %s' % (j, st.label))

    r, rho = rtrunc(pp['rhoatom'], 2)
    wfsax.plot(r, r * rho, label='rho')

    if calculate:
        calc = AtomPAW(
            setup.symbol,
            [setup.f_ln],
            # xc='PBE', # XXX does not support GGAs :( :( :(
            setups={setup.symbol: setup},
            h=0.08,
            rcut=10.0)
        r_g = calc.wfs.gd.r_g
        basis = calc.extract_basis_functions()
        wfsax.plot(r_g,
                   r_g * calc.density.nt_sg[0] * 4.0 * np.pi,
                   ls='--',
                   label='rho [calc]',
                   color='r')

        splines = basis.tosplines()
        for spline, bf in zip(splines, basis.bf_j):
            wfsax.plot(r_g, r_g * spline.map(r_g), label=bf.type)

    vax.legend(loc='best')
    rhoax.legend(loc='best')
    pax.legend(loc='best')
    wfsax.legend(loc='best')

    for ax in [vax, rhoax, pax, wfsax]:
        ax.set_xlabel('r [Bohr]')
        ax.axhline(0.0, ls=':', color='black')

    vax.set_ylabel('potential')
    pax.set_ylabel('projectors')
    wfsax.set_ylabel(r'$r \psi(r), r n(r)$')
    rhoax.set_ylabel('Comp charges')

    fig.subplots_adjust(wspace=0.3)

    if show:
        pl.show()