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)
if setup_paths[0] != '.': setup_paths.insert(0, '.') for atom in ['Be']: gen(atom, xcname='PBE', scalarrel=True, exx=True, yukawa_gamma=0.83, gpernode=149) h = 0.35 be = Cluster(Atoms('Be', positions=[[0, 0, 0]])) be.minimal_box(3.0, h=h) c = {'energy': 0.05, 'eigenstates': 0.05, 'density': 0.05} IP = 8.79 xc = HybridXC('LCY-PBE', omega=0.83) fname = 'Be_rsf.gpw' calc = GPAW(txt='Be.txt', xc=xc, convergence=c, eigensolver=RMMDIIS(), h=h, occupations=FermiDirac(width=0.0), spinpol=False) be.set_calculator(calc) # energy = na2.get_potential_energy() # calc.set(xc=xc) energy_083 = be.get_potential_energy() (eps_homo, eps_lumo) = calc.get_homo_lumo() equal(eps_homo, -IP, 0.15) xc2 = 'LCY-PBE' energy_075 = calc.get_xc_difference(HybridXC(xc2)) equal(energy_083 - energy_075, 21.13, 0.2, 'wrong energy difference') calc.write(fname)
'PBE': (5.424066548470926, -3.84092, -0.96192), 'PBE0': (-790.919942, -4.92321, -1.62948), 'EXX': (-785.5837828306236, -7.16802337336, -2.72602997017) } def xc(name): return dict(name=name, stencil=1) from gpaw.xc import XC from gpaw.xc.hybrid import HybridXC current = {} # Current revision for xc in [ XC(xc('PBE')), HybridXC('PBE0', stencil=1, finegrid=True), HybridXC('EXX', stencil=1, finegrid=True), XC(xc('PBE')) ]: # , 'oldPBE', 'LDA']: # Generate setup #g = Generator('Be', setup, scalarrel=True, nofiles=True, txt=None) #g.run(exx=True, **parameters['Be']) # switch to new xc functional calc.set(xc=xc) E = be2.get_potential_energy() if xc.name != 'PBE': E += calc.get_reference_energy() bands = calc.get_eigenvalues()[:2] # not 3 as unocc. eig are random!? XXX res = (E, ) + tuple(bands) print(xc.name, res)
E = {} niter = {} for fg in fgl: if fg: tstr = 'Exx on fine grid' else: tstr = 'Exx on coarse grid' timer.start(tstr) calc = GPAW(h=0.3, xc='PBE', nbands=4, convergence={'eigenstates': 1e-4}, charge=-1) loa.set_calculator(calc) E[fg] = loa.get_potential_energy() calc.set(xc=HybridXC('PBE0', finegrid=fg)) E[fg] = loa.get_potential_energy() niter[fg] = calc.get_number_of_iterations() timer.stop(tstr) timer.write(sys.stdout) print 'Total energy on the fine grid =', E[True] print 'Total energy on the coarse grid =', E[False] equal(E[True], E[False], 0.01) energy_tolerance = 0.0003 equal(E[False], 6.97818, energy_tolerance) assert 15 <= niter[False] <= 24, niter[False] equal(E[True], 6.97153, energy_tolerance) assert 15 <= niter[True] <= 24, niter[True]
be2.set_calculator(calc) ref_1871 = { # Values from revision 1871. Not true reference values # xc Energy eigenvalue 0 eigenvalue 1 'PBE': (5.427450, -3.84092, -0.96192), 'PBE0': (-790.919942, -4.92321, -1.62948), 'EXX': (-785.580737092, -7.16802337336, -2.72602997017) } from gpaw.xc import XC from gpaw.xc.hybrid import HybridXC current = {} # Current revision for xc in [ XC('PBE'), HybridXC('PBE0', finegrid=True), HybridXC('EXX', finegrid=True), XC('PBE') ]: # , 'oldPBE', 'LDA']: # Generate setup #g = Generator('Be', setup, scalarrel=True, nofiles=True, txt=None) #g.run(exx=True, **parameters['Be']) # switch to new xc functional calc.set(xc=xc) E = be2.get_potential_energy() if xc.name != 'PBE': E += calc.get_reference_energy() bands = calc.get_eigenvalues()[:2] # not 3 as unocc. eig are random!? XXX res = (E, ) + tuple(bands) print(xc.name, res)
timer = Timer() loa = Atoms('Be2', [(0, 0, 0), (2.45, 0, 0)], cell=[5.9, 4.8, 5.0]) loa.center() txt = None xc = 'PBE0' nbands = 4 unocc = True load = False # usual calculation fname = 'Be2.gpw' if not load: xco = HybridXC(xc) cocc = GPAW(h=0.3, eigensolver='rmm-diis', xc=xco, nbands=nbands, convergence={'eigenstates': 1e-4}, txt=txt) cocc.calculate(loa) else: cocc = GPAW(fname) cocc.converge_wave_functions() fo_n = 1. * cocc.get_occupation_numbers() eo_n = 1. * cocc.get_eigenvalues() if unocc: # apply Fock opeartor also to unoccupied orbitals
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)
calc = GPAW(gpts=(32, 32, 32), nbands=1, xc=xc('PBE'), txt='H.txt', eigensolver=Davidson(12), mixer=Mixer(0.5, 5), parallel=dict(kpt=1), convergence=dict(eigenstates=3.3e-8)) atom.set_calculator(calc) e1 = atom.get_potential_energy() niter1 = calc.get_number_of_iterations() print('start') de1t = calc.get_xc_difference(xc('TPSS')) de1m = calc.get_xc_difference(xc('M06-L')) de1x = calc.get_xc_difference(HybridXC('EXX', stencil=1, finegrid=True)) de1xb = calc.get_xc_difference(HybridXC('EXX', stencil=1, finegrid=False)) print('stop') # Hydrogen molecule: d = 0.74 # Experimental bond length molecule = Atoms([Atom('H', (c - d / 2, c, c)), Atom('H', (c + d / 2, c, c))], cell=(a, a, a), pbc=False) calc.set(txt='H2.txt') molecule.set_calculator(calc) e2 = molecule.get_potential_energy() niter2 = calc.get_number_of_iterations() de2t = calc.get_xc_difference(xc('TPSS'))
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)
h = 0.3 # No energies - simpley convergence test, esp. for 3d TM # for atom in ['F', 'Cl', 'Br', 'Cu', 'Ag']: for atom in ['Ti']: gen(atom, xcname='PBE', scalarrel=False, exx=True) work_atom = Cluster(Atoms(atom, [(0, 0, 0)])) work_atom.minimal_box(4, h=h) work_atom.translate([0.01, 0.02, 0.03]) work_atom.set_initial_magnetic_moments([2.0]) calculator = GPAW(convergence={ 'energy': 0.01, 'eigenstates': 3, 'density': 3 }, eigensolver=RMMDIIS(), poissonsolver=PoissonSolver(use_charge_center=True), occupations=FermiDirac(width=0.0, fixmagmom=True), h=h, maxiter=35) # Up to 24 are needed by now calculator.set(xc=HybridXC('PBE0')) calculator.set(txt=atom + '-PBE0.txt') work_atom.set_calculator(calculator) try: work_atom.get_potential_energy() except KohnShamConvergenceError: pass assert calculator.scf.converged, 'Calculation not converged'