Coverage for gpaw/test/big/dcdft/pbe_aims.py: 0%
76 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
1import os
2import sys
3import time
5import numpy as np
7import ase.db
8from ase.utils import opencew
9from ase.calculators.calculator import kpts2mp
10from ase.io import Trajectory
11from ase.calculators.aims import Aims
12from ase.test.tasks.dcdft import DeltaCodesDFTCollection as Collection
14collection = Collection()
16if len(sys.argv) == 1:
17 names = collection.names
18else:
19 names = [sys.argv[1]]
21c = ase.db.connect('dcdft_aims.db')
23# select the basis set
24basis = 'light'
25# basis = 'tight'
26# basis = 'really_tight'
27# basis = 'tier2'
29kptdensity = 16.0 # this is converged
30kptdensity = 6.0 # just for testing
31width = 0.01
33basis_threshold = 0.00001
34relativistic = 'none'
35relativistic = 1.e-12
36relativistic = 'scalar'
38sc_accuracy_rho = 1.e-4
39sc_accuracy_eev = 5.e-3
41if relativistic == 'none':
42 linspace = (0.92, 1.08, 7) # eos numpy's linspace
43else:
44 linspace = (0.98, 1.02, 5) # eos numpy's linspace
45linspacestr = ''.join([str(t) + 'x' for t in linspace])[:-1]
47code = 'aims' + '-' + basis + '_e' + linspacestr
48code = code + '_k' + str(kptdensity) + '_w' + str(width)
49code = code + '_t' + str(basis_threshold) + '_r' + str(relativistic)
51collection = Collection()
53for name in names:
54 # save all steps in one traj file in addition to the database
55 # we should only used the database c.reserve, but here
56 # traj file is used as another lock ...
57 fd = opencew(name + '_' + code + '.traj')
58 if fd is None:
59 continue
60 traj = Trajectory(name + '_' + code + '.traj', 'w')
61 atoms = collection[name]
62 cell = atoms.get_cell()
63 kpts = tuple(kpts2mp(atoms, kptdensity, even=True))
64 kwargs = {}
65 if relativistic == 'scalar':
66 kwargs.update({'relativistic': ['atomic_zora', relativistic]})
67 elif relativistic == 'none':
68 kwargs.update({'relativistic': 'none'})
69 else: # e.g. 1.0e-12
70 kwargs.update({'relativistic': ['zora', 'scalar', relativistic]})
71 if atoms.get_initial_magnetic_moments().any(): # spin-polarization
72 magmom = atoms.get_initial_magnetic_moments().sum() / len(atoms)
73 kwargs.update({'spin': 'collinear'})
74 # convergence problems for tier2
75 charge_mix_param = 0.01
76 basis_threshold = 0.00001
77 if basis in ['tier2']:
78 if name in ['Cr', 'Fe'] and relativistic == 'none':
79 basis_threshold = 0.00005
80 sc_accuracy_rho = 2.5e-3
81 sc_accuracy_eev = 5.e-3
82 if name in ['Mn']:
83 charge_mix_param = 0.01
84 basis_threshold = 0.00005
85 sc_accuracy_rho = 2.5e-3
86 sc_accuracy_eev = 5.e-3
87 if relativistic == 'none':
88 sc_accuracy_rho = 3.0e-3
89 # loop over EOS linspace
90 for n, x in enumerate(np.linspace(linspace[0], linspace[1], linspace[2])):
91 id = c.reserve(name=name, basis=basis, linspacestr=linspacestr,
92 kptdensity=kptdensity, width=width,
93 basis_threshold=basis_threshold,
94 relativistic=relativistic,
95 x=x)
96 if id is None:
97 continue
98 # perform EOS step
99 atoms.set_cell(cell * x, scale_atoms=True)
100 # set calculator
101 atoms.calc = Aims(
102 label=name + '_' + code + '_' + str(n),
103 species_dir=os.path.join(os.environ['AIMS_SPECIES_DIR'], basis),
104 xc='PBE',
105 kpts=kpts,
106 KS_method='elpa',
107 sc_accuracy_rho=sc_accuracy_rho,
108 sc_accuracy_eev=sc_accuracy_eev,
109 occupation_type=['gaussian', width],
110 override_relativity=True,
111 override_illconditioning=True,
112 basis_threshold=basis_threshold,
113 charge_mix_param=charge_mix_param,
114 sc_iter_limit=9000)
115 atoms.calc.set(**kwargs) # remaining calc keywords
116 t = time.time()
117 atoms.get_potential_energy()
118 c.write(atoms,
119 name=name, basis=basis, linspacestr=linspacestr,
120 kptdensity=kptdensity, width=width,
121 basis_threshold=basis_threshold,
122 relativistic=relativistic,
123 x=x,
124 time=time.time() - t)
125 traj.write(atoms)
126 del c[id]