Beispiel #1
0
def upfplot(setup, show=True):
    # 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()
    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, psi, label='wf%d %s' % (j, st.label))

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

    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('WF / density')
    rhoax.set_ylabel('Comp charges')

    #fig.canvas.set_window_title(fname) remember fname in setup
    fig.subplots_adjust(wspace=0.3)

    if show:
        pl.show()
Beispiel #2
0
    def __init__(self, data):
        # data can be string (filename)
        # or dict (that's what we are looking for).
        # Maybe just a symbol would also be fine if we know the
        # filename to look for.
        if isinstance(data, basestring):
            data = parse_upf(data)
        
        assert isinstance(data, dict)
        self.data = data # more or less "raw" data from the file

        self.name = 'upf'

        header = data['header']
        
        keys = header.keys()
        keys.sort()

        self.symbol = header['element']
        self.Z = atomic_numbers[self.symbol]
        self.Nv = header['z_valence']
        self.Nc = self.Z - self.Nv
        self.Delta0 = -self.Nv / np.sqrt(4.0 * np.pi) # like hgh
        self.rcut_j = [data['r'][len(proj.values) -1]
                       for proj in data['projectors']]

        beta = 0.1 # XXX nice parameters?
        N = 4 * 450 # XXX
        # This is "stolen" from hgh.  Figure out something reasonable
        #rgd = AERadialGridDescriptor(beta / N, 1.0 / N, N,
        #                             default_spline_points=100)
        
        from gpaw.atom.radialgd import EquidistantRadialGridDescriptor
        rgd = EquidistantRadialGridDescriptor(0.02)
        self.rgd = rgd
        
        # Whyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy???
        # What abominable part of the code requires the states
        # to be ordered like this?
        self.jargs = self.get_jargs()

        projectors = [data['projectors'][jarg] for jarg in self.jargs]
        if projectors:
            self.l_j = [proj.l for proj in projectors]
            self.pt_jg = []
            for proj in projectors:
                val = proj.values.copy()
                val /= 2.
                val[1:] /= data['r'][1:len(val)]
                val[0] = val[1]

                r0 = np.linspace(0., 10., 1000)
                
                pt_g = self._interp(val) #* np.sqrt(4.0 * np.pi)
                sqrnorm = (pt_g**2 * self.rgd.dr_g).sum()
                self.pt_jg.append(pt_g)
        
        else:
            self.l_j = [0]
            gcut = self.rgd.r2g(1.0)
            self.pt_jg = [np.zeros(gcut)] # XXX yet another "null" function

        self.rcgauss = 0.0 # XXX .... what is this used for?
        self.ni = sum([2 * l + 1 for l in self.l_j])

        self.filename = None # remember filename?
        self.fingerprint = None # XXX hexdigest the file?
        self.HubU = None # XXX
        self.lq = None # XXX

        #if data['states']:
        #    states_lmax = max([state.l for state in data['states']])
        #else:
        #    states_lmax = 1 # XXXX

        if data['states']:
            states_lmax = max([state.l for state in data['states']])
            f_ln = [[] for _ in range(1 + states_lmax)]
            electroncount = 0.0
            for state in data['states']:
                # Where should the electrons be in the inner list??
                # This is probably wrong and will lead to bad initialization
                f_ln[state.l].append(state.occupation)
                electroncount += state.occupation
                # The Cl.pz-hgh.UPF from quantum espresso has only 6
                # but should have 7 electrons.  Oh well....
            err = abs(electroncount - self.Nv)
            self.f_j = [state.occupation for state in data['states']]
            self.n_j = [state.n for state in data['states']]
            self.l_orb_j = [state.l for state in data['states']]
            self.f_ln = f_ln
        else:
            self.n_j, self.l_orb_j, self.f_j, self.f_ln = \
                figure_out_valence_states(self)

        vlocal_unscreened = data['vlocal']
        vbar_g, ghat_g = screen_potential(data['r'], vlocal_unscreened,
                                          self.Nv)
        
        self.vbar_g = self._interp(vbar_g) * np.sqrt(4.0 * np.pi)
        self.ghat_lg = [4.0 * np.pi / self.Nv * self._interp(ghat_g)]
Beispiel #3
0
    def __init__(self, data):
        # data can be string (filename)
        # or dict (that's what we are looking for).
        # Maybe just a symbol would also be fine if we know the
        # filename to look for.
        if isinstance(data, basestring):
            data = parse_upf(data)

        assert isinstance(data, dict)
        self.data = data  # more or less "raw" data from the file

        self.name = 'upf'

        header = data['header']

        keys = header.keys()
        keys.sort()

        self.symbol = header['element']
        self.Z = atomic_numbers[self.symbol]
        self.Nv = header['z_valence']
        self.Nc = self.Z - self.Nv
        self.Delta0 = -self.Nv / np.sqrt(4.0 * np.pi)  # like hgh
        self.rcut_j = [
            data['r'][len(proj.values) - 1] for proj in data['projectors']
        ]

        #beta = 0.1 # XXX nice parameters?
        #N = 4 * 450 # XXX
        # This is "stolen" from hgh.  Figure out something reasonable
        #rgd = AERadialGridDescriptor(beta / N, 1.0 / N, N,
        #                             default_spline_points=100)

        from gpaw.atom.radialgd import EquidistantRadialGridDescriptor
        rgd = EquidistantRadialGridDescriptor(0.02)
        self.rgd = rgd

        # Whyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy???
        # What abominable part of the code requires the states
        # to be ordered like this?
        self.jargs = self.get_jargs()

        projectors = [data['projectors'][jarg] for jarg in self.jargs]
        if projectors:
            self.l_j = [proj.l for proj in projectors]
            self.pt_jg = []
            for proj in projectors:
                val = proj.values.copy()
                val /= 2.
                val[1:] /= data['r'][1:len(val)]
                val[0] = val[1]
                pt_g = self._interp(val)  #* np.sqrt(4.0 * np.pi)
                #sqrnorm = (pt_g**2 * self.rgd.dr_g).sum()
                self.pt_jg.append(pt_g)

        else:
            self.l_j = [0]
            gcut = self.rgd.r2g(1.0)
            self.pt_jg = [np.zeros(gcut)]  # XXX yet another "null" function

        self.rcgauss = 0.0  # XXX .... what is this used for?
        self.ni = sum([2 * l + 1 for l in self.l_j])

        self.filename = None  # remember filename?
        self.fingerprint = None  # XXX hexdigest the file?
        self.HubU = None  # XXX
        self.lq = None  # XXX

        #if data['states']:
        #    states_lmax = max([state.l for state in data['states']])
        #else:
        #    states_lmax = 1 # XXXX

        if data['states']:
            states_lmax = max([state.l for state in data['states']])
            f_ln = [[] for _ in range(1 + states_lmax)]
            electroncount = 0.0
            for state in data['states']:
                # Where should the electrons be in the inner list??
                # This is probably wrong and will lead to bad initialization
                f_ln[state.l].append(state.occupation)
                electroncount += state.occupation
                # The Cl.pz-hgh.UPF from quantum espresso has only 6
                # but should have 7 electrons.  Oh well....
            #err = abs(electroncount - self.Nv)
            self.f_j = [state.occupation for state in data['states']]
            self.n_j = [state.n for state in data['states']]
            self.l_orb_j = [state.l for state in data['states']]
            self.f_ln = f_ln
        else:
            self.n_j, self.l_orb_j, self.f_j, self.f_ln = \
                figure_out_valence_states(self)

        vlocal_unscreened = data['vlocal']

        # The UPF representation of HGH setups should be equal to that
        # used with setups='hgh'.  But the UPF files do not contain
        # info on the localization of the compensation charges!  That
        # means the screen_potential code will choose the shape of the
        # compensation charges, resulting in some numerical differences.
        #
        # One could hack that it looks up some radii to compare e.g. H2O.
        # The results of the below comments still have some numerical error.
        # But it's not huge.
        #a = None
        #if self.symbol == 'H':
        #    a = 0.2
        #elif self.symbol == 'O':
        #    a = .247621

        vbar_g, ghat_g = screen_potential(data['r'], vlocal_unscreened,
                                          self.Nv)  #, a=a)

        self.vbar_g = self._interp(vbar_g) * np.sqrt(4.0 * np.pi)
        self.ghat_lg = [4.0 * np.pi / self.Nv * self._interp(ghat_g)]
Beispiel #4
0
def upfplot(setup, show=True):
    # 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, psi, label='wf%d %s' % (j, st.label))

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

    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('WF / density')
    rhoax.set_ylabel('Comp charges')

    fig.subplots_adjust(wspace=0.3)

    if show:
        pl.show()
Beispiel #5
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()