Пример #1
0
    def calculate_gga(self, e_g, n_sg, dedn_sg, sigma_xg, dedsigma_xg):
        GGA.calculate_gga(self, e_g, n_sg, dedn_sg, sigma_xg, dedsigma_xg)

        eLDAc_g = self.gd.empty()
        vLDAc_sg = self.gd.zeros(1)

        if self.vdwcoef == 0.0:
            return

        if len(n_sg) == 1:
            self.LDAc.calculate(eLDAc_g, n_sg, vLDAc_sg)
            e = self.get_non_local_energy(n_sg[0], sigma_xg[0], eLDAc_g, vLDAc_sg[0], dedn_sg[0], dedsigma_xg[0])
        else:
            n_sg = n_sg.sum(0)
            n_sg.shape = (1,) + n_sg.shape
            self.LDAc.calculate(eLDAc_g, n_sg, vLDAc_sg)
            v_g = np.zeros_like(e_g)
            deda2nl_g = np.zeros_like(e_g)
            a2_g = sigma_xg[0] + 2 * sigma_xg[1] + sigma_xg[2]
            e = self.get_non_local_energy(n_sg[0], a2_g, eLDAc_g, vLDAc_sg[0], v_g, deda2nl_g)
            dedsigma_xg[0] += self.vdwcoef * deda2nl_g
            dedsigma_xg[1] += self.vdwcoef * 2 * deda2nl_g
            dedsigma_xg[2] += self.vdwcoef * deda2nl_g
            dedn_sg += self.vdwcoef * v_g

        if self.gd.comm.rank == 0:
            e_g[0, 0, 0] += self.vdwcoef * e / self.gd.dv
Пример #2
0
    def calculate_gga(self, e_g, n_sg, dedn_sg, sigma_xg, dedsigma_xg):
        GGA.calculate_gga(self, e_g, n_sg, dedn_sg, sigma_xg, dedsigma_xg)

        eLDAc_g = self.gd.empty()
        vLDAc_sg = self.gd.zeros(1)

        if self.vdwcoef == 0.0:
            return

        if len(n_sg) == 1:
            self.LDAc.calculate(eLDAc_g, n_sg, vLDAc_sg)
            e = self.get_non_local_energy(n_sg[0], sigma_xg[0], eLDAc_g,
                                          vLDAc_sg[0], dedn_sg[0],
                                          dedsigma_xg[0])
        else:
            n_sg = n_sg.sum(0)
            n_sg.shape = (1, ) + n_sg.shape
            self.LDAc.calculate(eLDAc_g, n_sg, vLDAc_sg)
            v_g = np.zeros_like(e_g)
            deda2nl_g = np.zeros_like(e_g)
            a2_g = sigma_xg[0] + 2 * sigma_xg[1] + sigma_xg[2]
            e = self.get_non_local_energy(n_sg[0], a2_g, eLDAc_g, vLDAc_sg[0],
                                          v_g, deda2nl_g)
            dedsigma_xg[0] += self.vdwcoef * deda2nl_g
            dedsigma_xg[1] += self.vdwcoef * 2 * deda2nl_g
            dedsigma_xg[2] += self.vdwcoef * deda2nl_g
            dedn_sg += self.vdwcoef * v_g

        if self.gd.comm.rank == 0:
            e_g[0, 0, 0] += self.vdwcoef * e / self.gd.dv
Пример #3
0
def test_selfconsistent():
    from gpaw import GPAW
    from ase.build import molecule
    from gpaw.xc.gga import GGA

    system = molecule('H2O')
    system.center(vacuum=3.)

    def test(xc):
        calc = GPAW(
            mode='lcao',
            xc=xc,
            setups='sg15',
            txt='gpaw.%s.txt' % str(xc)  # .kernel.name
        )
        system.set_calculator(calc)
        return system.get_potential_energy()

    libxc_results = {}

    for name in ['GGA_X_PBE_R+LDA_C_PW', 'GGA_X_RPW86+LDA_C_PW']:
        xc = GGA(LibXC(name))
        e = test(xc)
        libxc_results[name] = e

    cx_gga_results = {}
    cx_gga_results['rpw86'] = test(GGA(CXGGAKernel(just_kidding=True)))
    cx_gga_results['lv_rpw86'] = test(GGA(CXGGAKernel(just_kidding=False)))

    vdw_results = {}
    vdw_coef0_results = {}

    for vdw in [vdw_df(), vdw_df2(), vdw_df_cx()]:
        vdw.vdwcoef = 0.0
        vdw_coef0_results[vdw.__class__.__name__] = test(vdw)
        vdw.vdwcoef = 1.0  # Leave nicest text file by running real calc last
        vdw_results[vdw.__class__.__name__] = test(vdw)

    from gpaw.mpi import world
    # These tests basically verify that the LDA/GGA parts of vdwdf
    # work correctly.
    if world.rank == 0:
        print('Now comparing...')
        err1 = cx_gga_results['rpw86'] - libxc_results['GGA_X_RPW86+LDA_C_PW']
        print('Our rpw86 must be identical to that of libxc. Err=%e' % err1)
        print('RPW86 interpolated with Langreth-Vosko stuff differs by %f' %
              (cx_gga_results['lv_rpw86'] - cx_gga_results['rpw86']))
        print('Each vdwdf with vdwcoef zero must yield same result as gga'
              'kernel')
        err_df1 = vdw_coef0_results['VDWDF'] - libxc_results['GGA_X_PBE_R+'
                                                             'LDA_C_PW']
        print('  df1 err=%e' % err_df1)
        err_df2 = vdw_coef0_results['VDWDF2'] - libxc_results['GGA_X_RPW86+'
                                                              'LDA_C_PW']
        print('  df2 err=%e' % err_df2)
        err_cx = vdw_coef0_results['VDWDFCX'] - cx_gga_results['lv_rpw86']
        print('   cx err=%e' % err_cx)
Пример #4
0
    def __init__(self, kernel, nn=1):
        """Meta GGA functional.

        nn: int
            Number of neighbor grid points to use for FD stencil for
            wave function gradient.
        """
        self.nn = nn
        GGA.__init__(self, kernel)
Пример #5
0
 def __init__(self, atoms, parameters, qna_setup_name='PBE', alpha=2.0,
              override_atoms=None, stencil=2):
     # override_atoms is only used to test the partial derivatives
     # of xc-functional
     kernel = QNAKernel(self)
     GGA.__init__(self, kernel, stencil=stencil)
     self.atoms = atoms
     self.parameters = parameters
     self.qna_setup_name = qna_setup_name
     self.alpha = alpha
     self.override_atoms = override_atoms
     self.orbital_dependent = False
Пример #6
0
def vdw_df2(**kwargs):
    kwargs1 = dict(name='vdW-DF2',
                   setup_name='PBE',
                   semilocal_xc=GGA(LibXC('GGA_X_RPW86+LDA_C_PW'),
                                    stencil=kwargs.pop('stencil', 2)))
    kwargs1.update(kwargs)
    return VDWXC(**kwargs1)
Пример #7
0
def vdw_C09(**kwargs):
    kwargs1 = dict(name='vdW-C09',
                   libvdwxc_name='vdW-DF',
                   setup_name='PBE',
                   semilocal_xc=GGA(LibXC('GGA_X_C09X+LDA_C_PW'),
                                    stencil=kwargs.pop('stencil', 2)))
    kwargs1.update(kwargs)
    return VDWXC(**kwargs1)
Пример #8
0
def XC(kernel, parameters=None):
    """Create XCFunctional object.

    kernel: XCKernel object or str
        Kernel object or name of functional.
    parameters: ndarray
        Parameters for BEE functional.

    Recognized names are: LDA, PW91, PBE, revPBE, RPBE, BLYP, HCTH407,
    TPSS, M06L, revTPSS, vdW-DF, vdW-DF2, EXX, PBE0, B3LYP, BEE,
    GLLBSC.  One can also use equivalent libxc names, for example
    GGA_X_PBE+GGA_C_PBE is equivalent to PBE, and LDA_X to the LDA exchange.
    In this way one has access to all the functionals defined in libxc.
    See gpaw.xc.libxc_functionals.py for the complete list.  """

    if isinstance(kernel, str):
        name = kernel
        if name in ['vdW-DF', 'vdW-DF2']:
            from gpaw.xc.vdw import FFTVDWFunctional
            return FFTVDWFunctional(name)
        elif name in ['EXX', 'PBE0', 'B3LYP']:
            from gpaw.xc.hybrid import HybridXC
            return HybridXC(name)
        elif name == 'BEE1':
            from gpaw.xc.bee import BEE1
            kernel = BEE1(parameters)
        elif name.startswith('GLLB'):
            from gpaw.xc.gllb.nonlocalfunctionalfactory import \
                 NonLocalFunctionalFactory
            xc = NonLocalFunctionalFactory().get_functional_by_name(name)
            xc.print_functional()
            return xc
        elif name == 'LB94':
            from gpaw.xc.lb94 import LB94
            kernel = LB94()
        elif name.startswith('ODD_'):
            from ODD import ODDFunctional
            return ODDFunctional(name[4:])
        elif name.endswith('PZ-SIC'):
            try:
                from ODD import PerdewZungerSIC as SIC
                return SIC(xc=name[:-7])
            except:
                from gpaw.xc.sic import SIC
                return SIC(xc=name[:-7])
        elif name.startswith('old'):
            from gpaw.xc.kernel import XCKernel
            kernel = XCKernel(name[3:])
        else:
            kernel = LibXC(kernel)
    if kernel.type == 'LDA':
        return LDA(kernel)
    elif kernel.type == 'GGA':
        return GGA(kernel)
    else:
        return MGGA(kernel)
Пример #9
0
    def set_grid_descriptor(self, gd):
        GGA.set_grid_descriptor(self, gd)
        self.dedmu_g = gd.zeros()
        self.dedbeta_g = gd.zeros()
        # Create gaussian LFC
        l_lim = 1.0e-30
        rcut = 12
        points = 200
        r_i = np.linspace(0, rcut, points + 1)
        rcgauss = 1.2
        g_g = (2 / rcgauss**3 / np.pi *
               np.exp(-((r_i / rcgauss)**2)**self.alpha))

        # Values too close to zero can cause numerical problems especially with
        # forces (some parts of the mu and beta field can become negative)
        g_g[np.where(g_g < l_lim)] = l_lim
        spline = Spline(l=0, rmax=rcut, f_g=g_g)
        spline_j = [[spline]] * len(self.atoms)
        self.Pa = LFC(gd, spline_j)
Пример #10
0
def vdw_beef(**kwargs):
    # Kernel parameters stolen from vdw.py
    from gpaw.xc.bee import BEEVDWKernel
    kernel = BEEVDWKernel('BEE2', None, 0.600166476948828631066,
                          0.399833523051171368934)
    kwargs1 = dict(name='vdW-BEEF',
                   libvdwxc_name='vdW-DF2',
                   setup_name='PBE',
                   semilocal_xc=GGA(kernel, stencil=kwargs.pop('stencil', 2)))
    kwargs1.update(kwargs)
    return VDWXC(**kwargs1)
Пример #11
0
def vdw_beef(*args, **kwargs):
    # Kernel parameters stolen from vdw.py
    from gpaw.xc.bee import BEEVDWKernel
    kernel = BEEVDWKernel('BEE2', None, 0.600166476948828631066,
                          0.399833523051171368934)
    return VDWXC(semilocal_xc=GGA(kernel),
                 name='vdW-BEEF',
                 setup_name='PBE',
                 libvdwxc_name='vdW-DF2',
                 *args,
                 **kwargs)
Пример #12
0
def vdw_df_cx(**kwargs):
    # cx semilocal exchange is in libxc 2.2.2 or newer (or maybe from older)
    kernel = kwargs.get('kernel')
    if kernel is None:
        kernel = LibXC('GGA_X_LV_RPW86+LDA_C_PW')

    kwargs1 = dict(
        name='vdW-DF-cx',
        setup_name='PBE',
        # PBEsol is most correct but not distributed by default.
        semilocal_xc=GGA(kernel, stencil=kwargs.pop('stencil', 2)))
    kwargs1.update(kwargs)
    return VDWXC(**kwargs1)
Пример #13
0
def vdw_df_cx(*args, **kwargs):
    try:
        # Exists in libxc 2.2.2 or newer (or maybe from older)
        kernel = LibXC('GGA_X_LV_RPW86+LDA_C_PW')
    except NameError:
        kernel = CXGGAKernel()

    # Hidden debug feature
    if kwargs.get('gga_backend') == 'purepython':
        kernel = CXGGAKernel()
        kwargs.pop('gga_backend')
    assert 'gga_backend' not in kwargs

    return VDWXC(semilocal_xc=GGA(kernel), name='vdW-DF-CX', *args, **kwargs)
Пример #14
0
    def calculate_paw_correction(self, setup, D_sp, dEdD_sp=None,
                                 addcoredensity=True, a=None):
        assert not hasattr(self, 'D_sp')
        self.D_sp = D_sp
        self.n = 0
        self.ae = True
        self.c = setup.xc_correction
        self.dEdD_sp = dEdD_sp

        if self.c.tau_npg is None:
            self.c.tau_npg, self.c.taut_npg = self.initialize_kinetic(self.c)

        E = GGA.calculate_paw_correction(self, setup, D_sp, dEdD_sp,
                                         addcoredensity, a)
        del self.D_sp, self.n, self.ae, self.c, self.dEdD_sp
        return E
Пример #15
0
    def calculate_paw_correction(self,
                                 setup,
                                 D_sp,
                                 dEdD_sp=None,
                                 addcoredensity=True,
                                 a=None):
        assert not hasattr(self, 'D_sp')
        self.D_sp = D_sp
        self.n = 0
        self.ae = True
        self.c = setup.xc_correction
        self.dEdD_sp = dEdD_sp

        if self.c.tau_npg is None:
            self.c.tau_npg, self.c.taut_npg = self.initialize_kinetic(self.c)

        E = GGA.calculate_paw_correction(self, setup, D_sp, dEdD_sp,
                                         addcoredensity, a)
        del self.D_sp, self.n, self.ae, self.c, self.dEdD_sp
        return E
Пример #16
0
 def calculate_gga(self, *args):
     GGA.calculate_gga(self, *args)
     RealSpaceVDWFunctional.calculate_gga(self, *args)
Пример #17
0
def vdw_C09(*args, **kwargs):
    return VDWXC(semilocal_xc=GGA(LibXC('GGA_X_C09X+LDA_C_PW')),
                 name='vdW-C09',
                 libvdwxc_name='vdW-DF',
                 *args,
                 **kwargs)
Пример #18
0
def vdw_optB88(*args, **kwargs):
    return VDWXC(semilocal_xc=GGA(LibXC('GGA_X_OPTB88_VDW+LDA_C_PW')),
                 name='optB88',
                 libvdwxc_name='vdW-DF',
                 *args,
                 **kwargs)
Пример #19
0
 def __init__(self, name, kernel, **kwargs):
     RealSpaceVDWFunctional.__init__(self, **kwargs)
     GGA.__init__(self, kernel)
     self.name = name
Пример #20
0
    def __init__(
        self,
        name,
        world=None,
        q0cut=5.0,
        phi0=0.5,
        ds=1.0,
        Dmax=20.0,
        nD=201,
        ndelta=21,
        soft_correction=False,
        kernel=None,
        Zab=None,
        vdwcoef=1.0,
        verbose=False,
        energy_only=False,
    ):
        """vdW-DF.

        parameters:

        name: str
            Name of functional.
        world: MPI communicator
            Communicator to parallelize over.  Defaults to gpaw.mpi.world.
        q0cut: float
            Maximum value for q0.
        phi0: float
            Smooth value for phi(0,0).
        ds: float
            Cutoff for smooth kernel.
        Dmax: float
            Maximum value for D.
        nD: int
            Number of values for D in kernel-table.
        ndelta: int
            Number of values for delta in kernel-table.
        soft_correction: bool
            Correct for soft kernel.
        kernel:
            Which kernel to use.
        Zab:
            parameter in nonlocal kernel.
        vdwcoef: float
            Scaling of vdW energy.
        verbose: bool
            Print useful information.
        """

        if world is None:
            self.world = mpi.world
        else:
            self.world = world

        self.q0cut = q0cut
        self.phi0 = phi0
        self.ds = ds

        self.delta_i = np.linspace(0, 1.0, ndelta)
        self.D_j = np.linspace(0, Dmax, nD)

        self.verbose = verbose

        self.read_table()

        self.soft_correction = soft_correction
        if soft_correction:
            dD = self.D_j[1]
            self.C_soft = np.dot(self.D_j ** 2, self.phi_ij[0]) * 4 * pi * dD

        self.gd = None
        self.energy_only = energy_only
        self.timer = nulltimer

        if name == "vdW-DF":
            assert kernel is None and Zab is None
            kernel = LibXC("GGA_X_PBE_R+LDA_C_PW")
            Zab = -0.8491
        elif name == "vdW-DF2":
            assert kernel is None and Zab is None
            kernel = LibXC("GGA_X_RPW86+LDA_C_PW")
            Zab = -1.887
        elif name == "optPBE-vdW":
            assert kernel is None and Zab is None
            kernel = LibXC("GGA_X_OPTPBE_VDW+LDA_C_PW")
            Zab = -0.8491
        elif name == "optB88-vdW":
            assert kernel is None and Zab is None
            kernel = LibXC("GGA_X_OPTB88_VDW+LDA_C_PW")
            Zab = -0.8491
        elif name == "C09-vdW":
            assert kernel is None and Zab is None
            kernel = LibXC("GGA_X_C09X+LDA_C_PW")
            Zab = -0.8491
        else:
            assert kernel is not None and Zab is not None

        self.Zab = Zab
        GGA.__init__(self, kernel)
        self.vdwcoef = vdwcoef
        self.name = name
        self.LDAc = LibXC("LDA_C_PW")
Пример #21
0
 def set_grid_descriptor(self, gd):
     GGA.set_grid_descriptor(self, gd)
     RealSpaceVDWFunctional.set_grid_descriptor(self, gd)
Пример #22
0
 def set_grid_descriptor(self, gd):
     GGA.set_grid_descriptor(self, gd)
Пример #23
0
def XC(kernel, parameters=None, atoms=None, collinear=True):
    """Create XCFunctional object.

    kernel: XCKernel object, dict or str
        Kernel object or name of functional.
    parameters: ndarray
        Parameters for BEE functional.

    Recognized names are: LDA, PW91, PBE, revPBE, RPBE, BLYP, HCTH407,
    TPSS, M06-L, revTPSS, vdW-DF, vdW-DF2, EXX, PBE0, B3LYP, BEE,
    GLLBSC.  One can also use equivalent libxc names, for example
    GGA_X_PBE+GGA_C_PBE is equivalent to PBE, and LDA_X to the LDA exchange.
    In this way one has access to all the functionals defined in libxc.
    See xc_funcs.h for the complete list.  """

    if isinstance(kernel, basestring):
        kernel = xc_string_to_dict(kernel)

    kwargs = {}
    if isinstance(kernel, dict):
        kwargs = kernel.copy()
        name = kwargs.pop('name')
        backend = kwargs.pop('backend', None)

        if backend == 'libvdwxc' or name == 'vdW-DF-cx':
            # Must handle libvdwxc before old vdw implementation to override
            # behaviour for 'name'.  Also, cx is not implemented by the old
            # vdW module, so that always refers to libvdwxc.
            from gpaw.xc.libvdwxc import get_libvdwxc_functional
            return get_libvdwxc_functional(name=name, **kwargs)
        elif backend:
            error_msg = "A special backend for the XC functional was given, "\
                "but not understood. Please check if there's a typo."
            raise ValueError(error_msg)

        if name in ['vdW-DF', 'vdW-DF2', 'optPBE-vdW', 'optB88-vdW',
                    'C09-vdW', 'mBEEF-vdW', 'BEEF-vdW']:
            from gpaw.xc.vdw import VDWFunctional
            return VDWFunctional(name, **kwargs)
        elif name in ['EXX', 'PBE0', 'B3LYP',
                      'CAMY-BLYP', 'CAMY-B3LYP', 'LCY-BLYP', 'LCY-PBE']:
            from gpaw.xc.hybrid import HybridXC
            return HybridXC(name, **kwargs)
        elif name.startswith('LCY-') or name.startswith('CAMY-'):
            parts = name.split('(')
            from gpaw.xc.hybrid import HybridXC
            return HybridXC(parts[0], omega=float(parts[1][:-1]))
        elif name in ['HSE03', 'HSE06']:
            from gpaw.xc.exx import EXX
            return EXX(name, **kwargs)
        elif name == 'BEE1':
            from gpaw.xc.bee import BEE1
            kernel = BEE1(parameters)
        elif name == 'BEE2':
            from gpaw.xc.bee import BEE2
            kernel = BEE2(parameters)
        elif name.startswith('GLLB'):
            from gpaw.xc.gllb.nonlocalfunctionalfactory import \
                NonLocalFunctionalFactory
            # Pass kwargs somewhere?
            xc = NonLocalFunctionalFactory().get_functional_by_name(name)
            xc.print_functional()
            return xc
        elif name == 'LB94':
            from gpaw.xc.lb94 import LB94
            kernel = LB94()
        elif name == 'TB09':
            from gpaw.xc.tb09 import TB09
            return TB09(**kwargs)
        elif name.endswith('PZ-SIC'):
            from gpaw.xc.sic import SIC
            return SIC(xc=name[:-7], **kwargs)
        elif name in ['TPSS', 'M06-L', 'M06L', 'revTPSS']:
            if name == 'M06L':
                name = 'M06-L'
                warnings.warn('Please use M06-L instead of M06L')
            from gpaw.xc.kernel import XCKernel
            kernel = XCKernel(name)
        elif name.startswith('old'):
            from gpaw.xc.kernel import XCKernel
            kernel = XCKernel(name[3:])
        elif name == 'PPLDA':
            from gpaw.xc.lda import PurePythonLDAKernel
            kernel = PurePythonLDAKernel()
        elif name in ['pyPBE', 'pyPBEsol', 'pyRPBE', 'pyzvPBEsol']:
            from gpaw.xc.gga import PurePythonGGAKernel
            kernel = PurePythonGGAKernel(name)
        elif name == '2D-MGGA':
            from gpaw.xc.mgga import PurePython2DMGGAKernel
            kernel = PurePython2DMGGAKernel(name, parameters)
        elif name[0].isdigit():
            from gpaw.xc.parametrizedxc import ParametrizedKernel
            kernel = ParametrizedKernel(name)
        elif name == 'null':
            from gpaw.xc.kernel import XCNull
            kernel = XCNull()
        elif name == 'QNA':
            from gpaw.xc.qna import QNA
            return QNA(atoms, kernel['parameters'], kernel['setup_name'],
                       alpha=kernel['alpha'], stencil=kwargs.get('stencil', 2))
        else:
            kernel = LibXC(name)

    if kernel.type == 'LDA':
        if not collinear:
            kernel = NonCollinearLDAKernel(kernel)
        xc = LDA(kernel, **kwargs)
        return xc

    elif kernel.type == 'GGA':
        return GGA(kernel, **kwargs)
    else:
        return MGGA(kernel, **kwargs)
Пример #24
0
 def set_grid_descriptor(self, gd):
     GGA.set_grid_descriptor(self, gd)
     FFTVDWFunctional.set_grid_descriptor(self, gd)
Пример #25
0
 def __init__(self, kernel):
     """Meta GGA functional."""
     GGA.__init__(self, kernel)
Пример #26
0
 def __init__(self, name, kernel, **kwargs):
     RealSpaceVDWFunctional.__init__(self, **kwargs)
     GGA.__init__(self, kernel)
     self.name = name
Пример #27
0
 def set_grid_descriptor(self, gd):
     GGA.set_grid_descriptor(self, gd)
     FFTVDWFunctional.set_grid_descriptor(self, gd)
Пример #28
0
 def set_grid_descriptor(self, gd):
     GGA.set_grid_descriptor(self, gd)
     RealSpaceVDWFunctional.set_grid_descriptor(self, gd)
Пример #29
0
 def __init__(self, kernel):
     """Meta GGA functional."""
     GGA.__init__(self, kernel)
Пример #30
0
 def calculate_paw_correction(self, setup, D_sp, dEdD_sp=None,
                              addcoredensity=True, a=None):
     self.current_atom = a
     return GGA.calculate_paw_correction(self, setup, D_sp, dEdD_sp,
                                         addcoredensity, a)
Пример #31
0
def XC(kernel, parameters=None):
    """Create XCFunctional object.

    kernel: XCKernel object or str
        Kernel object or name of functional.
    parameters: ndarray
        Parameters for BEE functional.

    Recognized names are: LDA, PW91, PBE, revPBE, RPBE, BLYP, HCTH407,
    TPSS, M06-L, revTPSS, vdW-DF, vdW-DF2, EXX, PBE0, B3LYP, BEE,
    GLLBSC.  One can also use equivalent libxc names, for example
    GGA_X_PBE+GGA_C_PBE is equivalent to PBE, and LDA_X to the LDA exchange.
    In this way one has access to all the functionals defined in libxc.
    See xc_funcs.h for the complete list.  """

    if isinstance(kernel, basestring):
        name = kernel
        if name in [
                'vdW-DF', 'vdW-DF2', 'optPBE-vdW', 'optB88-vdW', 'C09-vdW',
                'mBEEF-vdW', 'BEEF-vdW'
        ]:
            from gpaw.xc.vdw import VDWFunctional
            return VDWFunctional(name)
        elif name in ['EXX', 'PBE0', 'B3LYP']:
            from gpaw.xc.hybrid import HybridXC
            return HybridXC(name)
        elif name in ['HSE03', 'HSE06']:
            from gpaw.xc.exx import EXX
            return EXX(name)
        elif name == 'BEE1':
            from gpaw.xc.bee import BEE1
            kernel = BEE1(parameters)
        elif name == 'BEE2':
            from gpaw.xc.bee import BEE2
            kernel = BEE2(parameters)
        elif name.startswith('GLLB'):
            from gpaw.xc.gllb.nonlocalfunctionalfactory import \
                NonLocalFunctionalFactory
            xc = NonLocalFunctionalFactory().get_functional_by_name(name)
            xc.print_functional()
            return xc
        elif name == 'LB94':
            from gpaw.xc.lb94 import LB94
            kernel = LB94()
        elif name == 'TB09':
            from gpaw.xc.tb09 import TB09
            return TB09()
        elif name.startswith('ODD_'):
            from ODD import ODDFunctional
            return ODDFunctional(name[4:])
        elif name.endswith('PZ-SIC'):
            try:
                from ODD import PerdewZungerSIC as SIC
                return SIC(xc=name[:-7])
            except:
                from gpaw.xc.sic import SIC
                return SIC(xc=name[:-7])
        elif name in ['TPSS', 'M06-L', 'M06L', 'revTPSS']:
            if name == 'M06L':
                name = 'M06-L'
                warnings.warn('Please use M06-L instead of M06L')
            from gpaw.xc.kernel import XCKernel
            kernel = XCKernel(name)
        elif name.startswith('old'):
            from gpaw.xc.kernel import XCKernel
            kernel = XCKernel(name[3:])
        elif name == 'PPLDA':
            from gpaw.xc.lda import PurePythonLDAKernel
            kernel = PurePythonLDAKernel()
        elif name in ['pyPBE', 'pyPBEsol', 'pyRPBE', 'pyzvPBEsol']:
            from gpaw.xc.gga import PurePythonGGAKernel
            kernel = PurePythonGGAKernel(name)
        elif name == '2D-MGGA':
            from gpaw.xc.mgga import PurePython2DMGGAKernel
            kernel = PurePython2DMGGAKernel(name, parameters)
        elif name[0].isdigit():
            from gpaw.xc.parametrizedxc import ParametrizedKernel
            kernel = ParametrizedKernel(name)
        else:
            kernel = LibXC(kernel)
    if kernel.type == 'LDA':
        return LDA(kernel)
    elif kernel.type == 'GGA':
        return GGA(kernel)
    else:
        return MGGA(kernel)
Пример #32
0
    def __init__(self,
                 name,
                 world=None,
                 q0cut=5.0,
                 phi0=0.5,
                 ds=1.0,
                 Dmax=20.0,
                 nD=201,
                 ndelta=21,
                 soft_correction=False,
                 kernel=None,
                 Zab=None,
                 vdwcoef=1.0,
                 verbose=False,
                 energy_only=False):
        """vdW-DF.

        parameters:

        name: str
            Name of functional.
        world: MPI communicator
            Communicator to parallelize over.  Defaults to gpaw.mpi.world.
        q0cut: float
            Maximum value for q0.
        phi0: float
            Smooth value for phi(0,0).
        ds: float
            Cutoff for smooth kernel.
        Dmax: float
            Maximum value for D.
        nD: int
            Number of values for D in kernel-table.
        ndelta: int
            Number of values for delta in kernel-table.
        soft_correction: bool
            Correct for soft kernel.
        kernel:
            Which kernel to use.
        Zab:
            parameter in nonlocal kernel.
        vdwcoef: float
            Scaling of vdW energy.
        verbose: bool
            Print useful information.
        """

        if world is None:
            self.world = mpi.world
        else:
            self.world = world

        self.q0cut = q0cut
        self.phi0 = phi0
        self.ds = ds

        self.delta_i = np.linspace(0, 1.0, ndelta)
        self.D_j = np.linspace(0, Dmax, nD)

        self.verbose = verbose

        self.read_table()

        self.soft_correction = soft_correction
        if soft_correction:
            dD = self.D_j[1]
            self.C_soft = np.dot(self.D_j**2, self.phi_ij[0]) * 4 * pi * dD

        self.gd = None
        self.energy_only = energy_only
        self.timer = nulltimer

        if name == 'vdW-DF':
            assert kernel is None and Zab is None
            kernel = LibXC('GGA_X_PBE_R+LDA_C_PW')
            Zab = -0.8491
        elif name == 'vdW-DF2':
            assert kernel is None and Zab is None
            kernel = LibXC('GGA_X_PW86+LDA_C_PW')
            Zab = -1.887

        self.Zab = Zab
        GGA.__init__(self, kernel)
        self.vdwcoef = vdwcoef
        self.name = name
        self.LDAc = LibXC('LDA_C_PW')
Пример #33
0
 def set_grid_descriptor(self, gd):
     GGA.set_grid_descriptor(self, gd)
Пример #34
0
def vdw_df2(*args, **kwargs):
    return VDWXC(semilocal_xc=GGA(LibXC('GGA_X_RPW86+LDA_C_PW')),
                 name='vdW-DF2',
                 *args,
                 **kwargs)
Пример #35
0
def vdw_df(*args, **kwargs):
    return VDWXC(semilocal_xc=GGA(LibXC('GGA_X_PBE_R+LDA_C_PW')),
                 name='vdW-DF',
                 *args,
                 **kwargs)
Пример #36
0
 def calculate_gga(self, *args):
     GGA.calculate_gga(self, *args)
     FFTVDWFunctional.calculate_gga(self, *args)