Debian Codegraph @

doc/tutorialsexercises/energetics/rpa_tut/c2cu.py

raw
1 from pathlib import Path
2
3 from ase import Atoms
4 from ase.build import fcc111
5 from gpaw import GPAW, PW, FermiDirac, MixerSum, Davidson
6 from gpaw.hybrids.energy import non_self_consistent_energy as nsc_energy
7 from gpaw.mpi import world
8 from gpaw.xc.rpa import RPACorrelation
9
10 # Lattice parametes of Cu:
11 d = 2.56
12 a = 2**0.5 * d
13 slab = fcc111('Cu', a=a, size=(1, 1, 4), vacuum=10.0)
14 slab.pbc = True
15
16 # Add graphite (we adjust height later):
17 slab += Atoms('C2',
18 scaled_positions=[[0, 0, 0],
19 [1 / 3, 1 / 3, 0]],
20 cell=slab.cell)
21
22
23 def calculate(xc: str, d: float) -> float:
24 slab.positions[4:6, 2] = slab.positions[3, 2] + d
25 tag = f'{d:.3f}'
26 if xc == 'RPA':
27 xc0 = 'PBE'
28 else:
29 xc0 = xc
30 slab.calc = GPAW(xc=xc0,
31 mode=PW(800),
32 basis='dzp',
33 eigensolver=Davidson(niter=4),
34 nbands='200%',
35 kpts={'size': (12, 12, 1), 'gamma': True},
36 occupations=FermiDirac(width=0.05),
37 convergence={'density': 1e-5},
38 parallel={'domain': 1},
39 mixer=MixerSum(0.05, 5, 50),
40 txt=f'{xc0}-{tag}.txt')
41 e = slab.get_potential_energy()
42
43 if xc == 'RPA':
44 e_hf = nsc_energy(slab.calc, 'EXX').sum()
45
46 slab.calc.diagonalize_full_hamiltonian()
47 slab.calc.write(f'{xc0}-{tag}.gpw', mode='all')
48
49 rpa = RPACorrelation(f'{xc0}-{tag}.gpw',
50 ecut=[200],
51 txt=f'RPAc-{tag}.txt',
52 skip_gamma=True,
53 frequency_scale=2.5)
54 e_rpac = rpa.calculate()[0]
55 e = e_hf + e_rpac
56
57 if world.rank == 0:
58 Path(f'{xc0}-{tag}.gpw').unlink()
59 with open(f'RPA-{tag}.result', 'w') as fd:
60 print(d, e, e_hf, e_rpac, file=fd)
61
62 return e
63
64
65 if __name__ == '__main__':
66 import sys
67 xc = sys.argv[1]
68 for arg in sys.argv[2:]:
69 d = float(arg)
70 calculate(xc, d)