def gpawCalc(calc, restart=False, surf=False): """ Accepts a job (either Surface or Bulk) and returns a Calculator """ from gpaw import GPAW, PW, Davidson, Mixer, MixerSum, FermiDirac return GPAW( mode=PW(calc.pw) #eV , xc=calc.xc, kpts={ 'density': calc.kpt, 'gamma': True } if isinstance(calc.kpt, int) else calc.kpt, spinpol=calc.magmom > 0, convergence={'energy': calc.eConv} #eV/electron , mixer=((MixerSum(beta=calc.mixing, nmaxold=calc.nmix, weight=100)) if calc.magmom > 0 else (Mixer(beta=calc.mixing, nmaxold=calc.nmix, weight=100))), maxiter=calc.maxsteps, nbands=-1 * calc.nbands, occupations=FermiDirac(calc.sigma), setups='sg15', eigensolver=Davidson(5), poissonsolver= None # {'dipolelayer': 'xy'} if isinstance(self,SurfaceJob) else None , txt=str(calc) + '.txt', symmetry={'do_not_symmetrize_the_density': True} #ERROR IN LI bcc 111 surface )
def test(): vdw = VDWFunctional('vdW-DF', verbose=1) d = 3.9 x = d / sqrt(3) L = 3.0 + 2 * 4.0 dimer = Atoms('Ar2', [(0, 0, 0), (x, x, x)], cell=(L, L, L)) dimer.center() calc = GPAW(h=0.2, xc=dict(name='revPBE', stencil=1), mixer=Mixer(0.8, 7, 50.0), eigensolver=Davidson(5)) dimer.set_calculator(calc) e2 = dimer.get_potential_energy() calc.write('Ar2.gpw') e2vdw = calc.get_xc_difference(vdw) e2vdwb = GPAW('Ar2.gpw').get_xc_difference(vdw) print(e2vdwb - e2vdw) assert abs(e2vdwb - e2vdw) < 1e-9 del dimer[1] e = dimer.get_potential_energy() evdw = calc.get_xc_difference(vdw) E = 2 * e - e2 Evdw = E + 2 * evdw - e2vdw print(E, Evdw) assert abs(E - -0.0048) < 6e-3, abs(E) assert abs(Evdw - +0.0223) < 3e-2, abs(Evdw) print(e2, e) equal(e2, -0.001581923, energy_tolerance) equal(e, -0.003224226, energy_tolerance)
def gpawRestart(self): from gpaw import restart, PW, Davidson, Mixer, MixerSum, FermiDirac spinpol = any([x > 0 for x in self.magmomsinit()]) return restart( 'preCalc_inp.gpw', mode=PW(self.pw), xc=self.xc, kpts=self.kpt(), spinpol=spinpol, convergence={'energy': self.econv()} #eV/electron , mixer=( (MixerSum(beta=self.mixing(), nmaxold=self.nmix(), weight=100)) if spinpol else (Mixer(beta=self.mixing(), nmaxold=self.nmix(), weight=100))), maxiter=self.maxstep(), nbands=self.nbands(), occupations=FermiDirac(self.sigma()), setups=self.psp #(pspDict[calc.psp]).pthFunc[cluster] , eigensolver=Davidson(5), poissonsolver= None # {'dipolelayer': 'xy'} if isinstance(self,SurfaceJob) else None , txt='%d_%s.txt' % (self.pw, self.xc), symmetry={'do_not_symmetrize_the_density': True}) #ERROR IN LI bcc 111 surface
def pbeU(tag=None): U = 4.0 ecut = 800 kdens = 12 width = 0.01 atoms = read('Ru2Cl6-input.json') mm = get_mm(atoms, 'afm') atoms.set_initial_magnetic_moments(mm) xc = 'PBE' setups = get_U_setups(atoms, U) if tag is None: xcstr = 'Ru2Cl6' else: xcstr = 'Ru2Cl6' + tag calc = GPAW(txt='{}.txt'.format(xcstr), mode=PW(ecut), eigensolver=Davidson(2), setups=setups, kpts={ 'density': kdens, 'gamma': True }, xc=xc, parallel={'augment_grids': True}, occupations=FermiDirac(width=width), nbands='140%', convergence={'bands': -4}) atoms.calc = calc atoms.get_potential_energy() atoms.calc.write('{}.gpw'.format(xcstr))
def makeGPAWcalc(): from gpaw import GPAW, PW, Davidson, Mixer, MixerSum, FermiDirac, setup_paths if p['psp'] == 'oldpaw': setup_paths.insert( 0, '/scratch/users/ksb/gpaw/oldpaw/gpaw-setups-0.6.6300/') psp = 'paw' else: psp = p['psp'] return GPAW( mode=PW(p['pw']), xc=p['xc'], kpts=json.loads(p['kpts']), spinpol=p['spinpol'], convergence={'energy': p['econv']} #eV/electron , mixer=((MixerSum(beta=p['mixing'], nmaxold=p['nmix'], weight=100)) if p['spinpol'] else (Mixer(beta=p['mixing'], nmaxold=p['nmix'], weight=100))), maxiter=p['maxstep'], nbands=p['nbands'], occupations=FermiDirac(p['sigma']), setups=psp, eigensolver=Davidson(5), poissonsolver=None, txt='log', symmetry={'do_not_symmetrize_the_density': True})
def PBEcalc(self): from gpaw import GPAW, PW, Davidson, Mixer, MixerSum, FermiDirac return GPAW( mode=PW(self.pw()) #eV , xc='PBE', kpts=self.kpt(), spinpol=self.spinpol(), convergence={'energy': self.econv()} #eV/electron , mixer=( (MixerSum(beta=self.mixing(), nmaxold=self.nmix(), weight=100)) if self.spinpol() else (Mixer(beta=self.mixing(), nmaxold=self.nmix(), weight=100))), maxiter=self.maxstep(), nbands=self.nbands(), occupations=FermiDirac(self.sigma()), setups=self.psp(), eigensolver=Davidson(5), poissonsolver= None # {'dipolelayer': 'xy'} if isinstance(self,SurfaceJob) else None , txt='%d_%s.txt' % (self.pw(), self.xc()), symmetry={'do_not_symmetrize_the_density': True}) #ERROR IN LI bcc 111 surface
def gpawRestart(calc): from gpaw import restart, PW, Davidson, Mixer, MixerSum, FermiDirac return restart( 'preCalc_inp.gpw', mode=PW(calc.pw), xc=calc.xc, kpts={ 'density': calc.kpt, 'gamma': True } if isinstance(calc.kpt, int) else calc.kpt, spinpol=calc.magmom > 0, convergence={'energy': calc.eConv} #eV/electron , mixer=((MixerSum(beta=calc.mixing, nmaxold=calc.nmix, weight=100)) if calc.magmom > 0 else (Mixer(beta=calc.mixing, nmaxold=calc.nmix, weight=100))), maxiter=calc.maxsteps, nbands=-1 * calc.nbands, occupations=FermiDirac(calc.sigma), setups='sg15' #(pspDict[calc.psp]).pthFunc[cluster] , eigensolver=Davidson(5), poissonsolver= None # {'dipolelayer': 'xy'} if isinstance(self,SurfaceJob) else None , txt=str(calc) + '.txt', symmetry={'do_not_symmetrize_the_density': True} #ERROR IN LI bcc 111 surface )
def calculate(**kwargs1): kwargs = dict(mode=mode, basis='sz(dzp)', eigensolver=Davidson(4) if mode != 'lcao' else None, xc=vdw_df(), h=0.25, convergence=dict(energy=1e-6), mixer=Mixer(0.5, 5, 10.)) kwargs.update(kwargs1) calc = GPAW(**kwargs) system.set_calculator(calc) system.get_potential_energy() return calc
def makeGPAWcalc(p): from gpaw import GPAW, PW, Davidson, Mixer, MixerSum, FermiDirac return GPAW( mode=PW(p['pw']), xc=p['xc'], kpts=kpt, spinpol=spinpol, convergence={'energy': p['econv']} #eV/electron , mixer=((MixerSum(beta=p['mixing'], nmaxold=p['nmix'], weight=100)) if spinpol else (Mixer(beta=p['mixing'], nmaxold=p['nmix'], weight=100))), maxiter=p['maxstep'], nbands=p['nbands'], occupations=FermiDirac(p['sigma']), setups=p['psp'], eigensolver=Davidson(5), poissonsolver=None, txt='log', symmetry={'do_not_symmetrize_the_density': True})
def gpawCalc(self, xc, spinpol): from gpaw import GPAW, PW, Davidson, Mixer, MixerSum, FermiDirac return GPAW( mode=PW(self.pw) #eV , xc=xc, kpts=self.kpt, spinpol=spinpol, convergence={'energy': self.econv} #eV/electron , mixer=((MixerSum(beta=self.mixing, nmaxold=self.nmix, weight=100)) if spinpol else (Mixer(beta=self.mixing, nmaxold=self.nmix, weight=100))), maxiter=self.maxstep, nbands=-1 * self.nbands, occupations=FermiDirac(self.sigma), setups='sg15', eigensolver=Davidson(5), poissonsolver= None # {'dipolelayer': 'xy'} if isinstance(self,SurfaceJob) else None , txt='%d_%s.txt' % (self.pw, xc), symmetry={'do_not_symmetrize_the_density': True}) #ERROR IN LI bcc 111 surface
# first on 3D without restart. Then does restart and recalculates. atom = 'Ne' setup_paths.insert(0, '.') for xcname in ['GLLB', 'GLLBSC']: if world.rank == 0: g = Generator(atom, xcname=xcname, scalarrel=False, nofiles=True) g.run(**parameters[atom]) eps = g.e_j[-1] world.barrier() a = 10 Ne = Atoms([Atom(atom, (0, 0, 0))], cell=(a, a, a), pbc=False) Ne.center() calc = GPAW(eigensolver=Davidson(4), nbands=10, h=0.18, xc=xcname, basis='dzp', mixer=Mixer(0.6)) Ne.set_calculator(calc) e = Ne.get_potential_energy() response = calc.hamiltonian.xc.xcs['RESPONSE'] response.calculate_delta_xc() KS, dxc = response.calculate_delta_xc_perturbation() if xcname == 'GLLB': equal(KS + dxc, 24.89, 1.5e-1) else: equal(KS + dxc, 27.70, 6.0e-2) eps3d = calc.wfs.kpt_u[0].eps_n[3]
eps = 1e-12 atoms.positions[0, :] = eps atoms.get_potential_energy() atoms.positions[0, 2] -= 2 * eps atoms.get_potential_energy() print(calc.scf.niter) # We should be within the convergence criterion. # It runs a minimum of three iterations: assert calc.scf.niter == 3 kwargs = lambda: dict(xc='oldLDA', mixer=Mixer(0.7), kpts=[1, 1, 2]) test(GPAW(mode='lcao', basis='sz(dzp)', h=0.3)) test( GPAW(mode='pw', eigensolver=Davidson(3), experimental={'reuse_wfs_method': 'paw'}, **kwargs())) test( GPAW(mode='fd', h=0.3, experimental={'reuse_wfs_method': 'lcao'}, **kwargs())) # pw + lcao extrapolation is currently broken (PWLFC lacks integrate2): #test(GPAW(mode='pw', experimental={'reuse_wfs_method': 'lcao'}, **kwargs()))
from __future__ import print_function from ase.build import bulk from gpaw.atom.generator import Generator from gpaw import GPAW, Davidson, Mixer, PW from gpaw.xc.libvdwxc import vdw_mbeef from gpaw.test import gen setup = gen('Si', xcname='PBEsol') system = bulk('Si') calc = GPAW(mode=PW(200), xc=vdw_mbeef(), kpts=(2, 2, 2), nbands=4, convergence=dict(density=1e-6), mixer=Mixer(1.0), eigensolver=Davidson(4), setups={'Si': setup}) system.calc = calc e = system.get_potential_energy() ref = -60.50368932260335 err = abs(e - ref) print('e=%r ref=%r err=%r' % (e, ref, err)) assert err < 1e-6
def adsorb(db, height=1.2, nlayers=3, nkpts=7, ecut=400): """Adsorb nitrogen in hcp-site on Ru(0001) surface. Do calculations for N/Ru(0001), Ru(0001) and a nitrogen atom if they have not already been done. db: Database Database for collecting results. height: float Height of N-atom above top Ru-layer. nlayers: int Number of Ru-layers. nkpts: int Use a (nkpts * nkpts) Monkhorst-Pack grid that includes the Gamma point. ecut: float Cutoff energy for plane waves. Returns height. """ name = f'Ru{nlayers}-{nkpts}x{nkpts}-{ecut:.0f}' parameters = dict(mode=PW(ecut), eigensolver=Davidson(niter=2), poissonsolver={'dipolelayer': 'xy'}, kpts={'size': (nkpts, nkpts, 1), 'gamma': True}, xc='PBE') # N/Ru(0001): slab = hcp0001('Ru', a=a, c=c, size=(1, 1, nlayers)) z = slab.positions[:, 2].max() + height x, y = np.dot([2 / 3, 2 / 3], slab.cell[:2, :2]) slab.append('N') slab.positions[-1] = [x, y, z] slab.center(vacuum=vacuum, axis=2) # 2: z-axis # Fix first nlayer atoms: slab.constraints = FixAtoms(indices=list(range(nlayers))) id = db.reserve(name=f'N/{nlayers}Ru(0001)', nkpts=nkpts, ecut=ecut) if id is not None: # skip calculation if already done slab.calc = GPAW(txt='N' + name + '.txt', **parameters) optimizer = BFGSLineSearch(slab, logfile='N' + name + '.opt') optimizer.run(fmax=0.01) height = slab.positions[-1, 2] - slab.positions[:-1, 2].max() del db[id] db.write(slab, name=f'N/{nlayers}Ru(0001)', nkpts=nkpts, ecut=ecut, height=height) # Clean surface (single point calculation): id = db.reserve(name=f'{nlayers}Ru(0001)', nkpts=nkpts, ecut=ecut) if id is not None: del slab[-1] # remove nitrogen atom slab.calc = GPAW(txt=name + '.txt', **parameters) slab.get_forces() del db[id] db.write(slab, name=f'{nlayers}Ru(0001)', nkpts=nkpts, ecut=ecut) # Nitrogen atom: id = db.reserve(name='N-atom', ecut=ecut) if id is not None: # Create spin-polarized nitrogen atom: molecule = Atoms('N', magmoms=[3]) molecule.center(vacuum=4.0) # Remove parameters that make no sense for an isolated atom: del parameters['kpts'] del parameters['poissonsolver'] # Calculate energy: molecule.calc = GPAW(txt=name + '.txt', **parameters) molecule.get_potential_energy() del db[id] db.write(molecule, name='N-atom', ecut=ecut) return height
for formula in systems: temp = split_formula(formula) for atom in temp: if atom not in systems: systems.append(atom) energies = {} niters = {} # Calculate energies for formula in systems: loa = molecule(formula) loa.set_cell(cell) loa.center() calc = GPAW( h=0.3, eigensolver=Davidson(8), parallel=dict(kpt=1), mixer=Mixer(0.5, 5), nbands=-2, poissonsolver=PoissonSolver(relax='GS'), xc='oldPBE', #fixmom=True, txt=formula + '.txt') if len(loa) == 1: calc.set(hund=True) else: pos = loa.get_positions() pos[1, :] = pos[0, :] + [0.0, 0.0, exp_bonds_dE[formula][0]] loa.set_positions(pos) loa.center() loa.set_calculator(calc)
def getkwargs(): return dict(eigensolver=Davidson(4), mixer=Mixer(0.8, 5, 10.0), xc='oldPBE')
xc = 'GLLBSC' gen('C', xcname=xc) setup_paths.insert(0, '.') # Calculate ground state atoms = bulk('C', 'diamond', a=3.567) # We want sufficiently many grid points that the calculator # can use wfs.world for the finegd, to test that part of the code. calc = GPAW(h=0.2, kpts=(4, 4, 4), xc=xc, nbands=8, mixer=Mixer(0.5, 5, 10.0), parallel=dict(domain=min(world.size, 2), band=1), eigensolver=Davidson(niter=2)) atoms.set_calculator(calc) atoms.get_potential_energy() calc.write('Cgs.gpw') # Calculate accurate KS-band gap from band structure calc = GPAW('Cgs.gpw', kpts={ 'path': 'GX', 'npoints': 12 }, fixdensity=True, symmetry='off', nbands=8, convergence=dict(bands=6), eigensolver=Davidson(niter=4))
from gpaw import GPAW, PW, Davidson # Create tube of MoS2: atoms = mx2('MoS2', size=(3, 2, 1)) atoms.cell[1, 0] = 0 atoms = atoms.repeat((1, 10, 1)) p = atoms.positions p2 = p.copy() L = atoms.cell[1, 1] r0 = L / (2 * pi) angle = p[:, 1] / L * 2 * pi p2[:, 1] = (r0 + p[:, 2]) * np.cos(angle) p2[:, 2] = (r0 + p[:, 2]) * np.sin(angle) atoms.positions = p2 atoms.cell = [atoms.cell[0, 0], 0, 0] # setup calculator ecut = 800 kpoints = (4, 1, 1) atoms.center(vacuum=6, axis=[1, 2]) atoms.pbc = True tag = 'MoS2-benchmark' atoms.calc = GPAW(mode=PW(ecut), eigensolver=Davidson(2), xc='PBE', txt=tag + '.txt', kpts={'size': kpoints}, nbands='120%', parallel={'augment_grids': True}) forces = atoms.get_forces()
from ase import io atoms = io.read('POSCAR') from gpaw import GPAW, PW, FermiDirac, restart, Davidson, Mixer, MixerSum, MixerDif from ase.optimize import QuasiNewton from ase.parallel import paropen kpts = (13, 13, 13) atoms.calc = GPAW(setups='sg15', mode=PW(800), xc='PBE', eigensolver=Davidson(5), mixer=Mixer(0.1, 5, 100), kpts=kpts, occupations=FermiDirac(0.2), nbands=-16, txt='pbe.txt') atoms.get_potential_energy() atoms.calc.write('inp.gpw', mode='all') #This uses libxc for MBEEF, you can use for relaxations, etc... (might be #a little bit faster) #atoms,calc = restart('inp.gpw', setups='sg15', xc='MGGA_X_MBEEF+GGA_C_PBE_SOL', convergence={'energy': 5e-6}, txt='mbeef.txt') #But for xc energy contribution output (i.e. single-point calculations) #only the python version works: atoms, calc = restart('inp.gpw', setups='sg15', xc='mBEEF', convergence={'energy': 5e-6},
TiO2_basis = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5], [u, u, 0.0], [-u, -u, 0.0], [0.5 + u, 0.5 - u, 0.5], [0.5 - u, 0.5 + u, 0.5]]) bulk_crystal = Atoms(symbols=['Ti', 'Ti', 'O', 'O', 'O', 'O'], scaled_positions=TiO2_basis, cell=rutile_cell, pbc=(1, 1, 1)) data_s = [] for symmetry in ['off', {}]: bulk_calc = GPAW(mode=PW(pwcutoff), nbands=42, eigensolver=Davidson(1), kpts={'size': (k, k, k), 'gamma': True}, xc='PBE', occupations=FermiDirac(0.00001), parallel={'band': 1}, symmetry=symmetry) bulk_crystal.set_calculator(bulk_calc) e0_bulk_pbe = bulk_crystal.get_potential_energy() bulk_calc.write('bulk.gpw', mode='all') X = Chi0('bulk.gpw') chi_t = X.calculate([1. / 4, 0, 0])[1:] data_s.append(list(chi_t)) msg = 'Difference in Chi when turning off symmetries!'
import numpy as np from ase import Atoms from gpaw import GPAW, FermiDirac, Davidson from gpaw.test import equal calc = GPAW(nbands=1, eigensolver=Davidson(6), occupations=FermiDirac(0.0)) atoms = Atoms('He', pbc=True, calculator=calc) atoms.center(vacuum=3) e0 = atoms.get_potential_energy() niter0 = calc.get_number_of_iterations() try: calc.get_fermi_level() except ValueError: pass # It *should* raise an error else: raise RuntimeError('get_fermi_level should not be possible for width=0') calc.set(nbands=3, convergence={'bands': 2}) atoms.get_potential_energy() h**o, lumo = calc.get_homo_lumo() equal(h**o, -15.4473, 0.01) equal(lumo, -0.2566, 0.01) calc.write('test') assert np.all(GPAW('test', txt=None).get_homo_lumo() == (h**o, lumo)) ef = calc.get_fermi_level() equal(ef, -7.85196, 0.01) calc.set(occupations=FermiDirac(0.1))
def getkwargs(): return dict(eigensolver=Davidson(4), mixer=MixerSum(0.5, 5, 10.0))