Coverage for gpaw/test/big/dcdft/pbe_abinit_paw.py: 0%
58 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
1import os
2import sys
3import time
5import numpy as np
7import ase.db
8from ase.units import Rydberg
9from ase.utils import opencew
10from ase.calculators.calculator import kpts2mp
11from ase.io import Trajectory
12from ase.calculators.abinit import Abinit
13from ase.test.tasks.dcdft import DeltaCodesDFTCollection as Collection
15collection = Collection()
17if len(sys.argv) == 1:
18 names = collection.names
19else:
20 names = [sys.argv[1]]
22c = ase.db.connect('dcdft_abinit_paw.db')
24ecut = 100
25pawecutdg = 300
27kptdensity = 16.0 # this is converged
28kptdensity = 6.0 # just for testing
29width = 0.01
30ecutsm = 0.0
31fband = 1.5
32tolsym = 1.e-12
34linspace = (0.98, 1.02, 5) # eos numpy's linspace
35linspacestr = ''.join([str(t) + 'x' for t in linspace])[:-1]
37code = 'abinit' + '-' + '_c' + str(ecut) + str(pawecutdg) + '_e' + linspacestr
38code = (code + '_k' + str(kptdensity) + '_w' + str(width) + '_s' +
39 str(ecutsm) + '_t' + str(tolsym))
41for name in names:
42 # save all steps in one traj file in addition to the database
43 # we should only used the database c.reserve, but here
44 # traj file is used as another lock ...
45 fd = opencew(name + '_' + code + '.traj')
46 if fd is None:
47 continue
48 traj = Trajectory(name + '_' + code + '.traj', 'w')
49 atoms = collection[name]
50 if name == 'Mn': # fails to find the right magnetic state
51 atoms.set_initial_magnetic_moments([10., 20., -10., -20.])
52 if name == 'Co': # fails to find the right magnetic state
53 atoms.set_initial_magnetic_moments([10., 10.])
54 if name == 'Ni': # fails to find the right magnetic state
55 atoms.set_initial_magnetic_moments([10., 10., 10., 10.])
56 cell = atoms.get_cell()
57 kpts = tuple(kpts2mp(atoms, kptdensity, even=True))
58 kwargs = {}
59 # loop over EOS linspace
60 for n, x in enumerate(np.linspace(linspace[0], linspace[1], linspace[2])):
61 id = c.reserve(name=name, ecut=ecut, pawecutdg=pawecutdg,
62 linspacestr=linspacestr,
63 kptdensity=kptdensity, width=width, ecutsm=ecutsm,
64 fband=fband, tolsym=tolsym,
65 x=x)
66 if id is None:
67 continue
68 # perform EOS step
69 atoms.set_cell(cell * x, scale_atoms=True)
70 # set calculator
71 atoms.calc = Abinit(
72 pps='paw', # uses highest valence
73 label=name + '_' + code + '_' + str(n),
74 xc='PBE',
75 kpts=kpts,
76 ecut=ecut * Rydberg,
77 pawecutdg=pawecutdg * Rydberg,
78 occopt=3,
79 tsmear=width,
80 ecutsm=ecutsm,
81 toldfe=1.0e-6,
82 nstep=900,
83 pawovlp=-1, # bypass overlap check
84 fband=fband,
85 # https://forum.abinit.org/viewtopic.php?f=8&t=35
86 chksymbreak=0,
87 tolsym=tolsym,
88 prtwf=0,
89 prtden=0,
90 )
91 atoms.calc.set(**kwargs) # remaining calc keywords
92 t = time.time()
93 atoms.get_potential_energy()
94 c.write(atoms,
95 name=name, ecut=ecut, pawecutdg=pawecutdg,
96 linspacestr=linspacestr,
97 kptdensity=kptdensity, width=width, ecutsm=ecutsm,
98 fband=fband, tolsym=tolsym,
99 x=x,
100 time=time.time() - t)
101 traj.write(atoms)
102 wfk = name + '_' + code + '_' + str(n) + 'o_WFK'
103 if os.path.exists(wfk):
104 os.remove(wfk)
105 del c[id]