Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief builds the input structure for optimize_basis
10 : !> \par History
11 : !> 03.2012 created [Florian Schiffmann]
12 : !> \author Florian Schiffmann
13 : ! **************************************************************************************************
14 : MODULE input_optimize_basis
15 :
16 : USE cp_units, ONLY: cp_unit_to_cp2k
17 : USE input_constants, ONLY: do_opt_all, &
18 : do_opt_coeff, &
19 : do_opt_exps, &
20 : do_opt_none
21 : USE input_keyword_types, ONLY: keyword_create, &
22 : keyword_release, &
23 : keyword_type
24 : USE input_section_types, ONLY: section_add_keyword, &
25 : section_add_subsection, &
26 : section_create, &
27 : section_release, &
28 : section_type
29 : USE input_val_types, ONLY: char_t, &
30 : integer_t, &
31 : real_t
32 : USE kinds, ONLY: dp
33 : USE string_utilities, ONLY: s2a
34 : #include "./base/base_uses.f90"
35 :
36 : IMPLICIT NONE
37 : PRIVATE
38 :
39 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_optimize_basis'
40 : PUBLIC :: create_optimize_basis_section
41 :
42 : CONTAINS
43 :
44 : ! **************************************************************************************************
45 : !> \brief creates the optimize_basis section
46 : !> \param section ...
47 : !> \author Florian Schiffmann
48 : ! **************************************************************************************************
49 10850 : SUBROUTINE create_optimize_basis_section(section)
50 : TYPE(section_type), POINTER :: section
51 :
52 : TYPE(keyword_type), POINTER :: keyword
53 : TYPE(section_type), POINTER :: subsection
54 :
55 10850 : CPASSERT(.NOT. ASSOCIATED(section))
56 : CALL section_create(section, __LOCATION__, name="OPTIMIZE_BASIS", &
57 : description="describes a basis optimization job, in which an ADMM like approach is used to"// &
58 : " find the best exponents and/or coefficients to match a given training set.", &
59 10850 : repeats=.FALSE.)
60 10850 : NULLIFY (keyword, subsection)
61 :
62 : CALL keyword_create(keyword, __LOCATION__, name="BASIS_TEMPLATE_FILE", &
63 : description="Name of the basis set file, containing the structure of the new basis set", &
64 : usage="BASIS_TEMPLATE_FILE <FILENAME>", &
65 : type_of_var=char_t, repeats=.FALSE., &
66 10850 : default_c_val="BASIS_SET", n_var=-1)
67 10850 : CALL section_add_keyword(section, keyword)
68 10850 : CALL keyword_release(keyword)
69 :
70 : CALL keyword_create(keyword, __LOCATION__, name="BASIS_WORK_FILE", &
71 : description="Name of the basis set file which is created to be read as initial guess", &
72 : usage="BASIS_WORK_FILE <FILENAME>", &
73 : type_of_var=char_t, repeats=.FALSE., &
74 10850 : default_c_val="BASIS_WORK_FILE", n_var=-1)
75 10850 : CALL section_add_keyword(section, keyword)
76 10850 : CALL keyword_release(keyword)
77 :
78 : CALL keyword_create(keyword, __LOCATION__, name="BASIS_OUTPUT_FILE", &
79 : description="Name of the basis set file containing the optimized basis", &
80 : usage="BASIS_OUTPUT_FILE <FILENAME>", &
81 : type_of_var=char_t, repeats=.FALSE., &
82 10850 : default_c_val="BASIS_OUTPUT_FILE", n_var=-1)
83 10850 : CALL section_add_keyword(section, keyword)
84 10850 : CALL keyword_release(keyword)
85 :
86 : CALL keyword_create(keyword, __LOCATION__, name="WRITE_FREQUENCY", &
87 : description="Frequency at which the intermediate results should be written", &
88 : usage="WRITE_FREQUENCY 1000", &
89 10850 : default_i_val=5000)
90 10850 : CALL section_add_keyword(section, keyword)
91 10850 : CALL keyword_release(keyword)
92 :
93 : CALL keyword_create(keyword, __LOCATION__, name="USE_CONDITION_NUMBER", &
94 : description="Determines whether condition number should be part of optimization or not", &
95 : usage="USE_CONDITION_NUMBER", &
96 10850 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
97 10850 : CALL section_add_keyword(section, keyword)
98 10850 : CALL keyword_release(keyword)
99 :
100 : CALL keyword_create( &
101 : keyword, __LOCATION__, name="BASIS_COMBINATIONS", &
102 : description="If multiple atomic kinds are fitted at the same time, this keyword "// &
103 : "allows to specify which basis sets should be used together in optimization (underived set ID=0). "// &
104 : "If skipped all combinations are used. The order is taken as the kinds and sets are specified in the input", &
105 : repeats=.TRUE., &
106 10850 : usage="BASIS_COMBINATIONS SET_ID(KIND1) SET_ID(KIND2) ... ", type_of_var=integer_t, n_var=-1)
107 10850 : CALL section_add_keyword(section, keyword)
108 10850 : CALL keyword_release(keyword)
109 :
110 : CALL keyword_create( &
111 : keyword, __LOCATION__, name="RESIDUUM_WEIGHT", &
112 : description="This keyword allows to give different weight factors to the "// &
113 : "residuum of the different basis combinations. "// &
114 : "The first entry corresponds to the original basis sets. Every further value is assigned to the combinations "// &
115 : "in the order given for BASIS_COMBINATIONS.", &
116 : repeats=.TRUE., &
117 10850 : usage="RESIDUUM_WEIGHT REAL ", default_r_val=1.0_dp)
118 10850 : CALL section_add_keyword(section, keyword)
119 10850 : CALL keyword_release(keyword)
120 :
121 : CALL keyword_create( &
122 : keyword, __LOCATION__, name="CONDITION_WEIGHT", &
123 : description="This keyword allows to give different weight factors to the "// &
124 : "condition number of different basis combinations (LOG(cond) is used). "// &
125 : "The first entry corresponds to the original basis sets. Every further value is assigned to the combinations "// &
126 : "in the order given for BASIS_COMBINATIONS.", &
127 : repeats=.TRUE., &
128 10850 : usage="CONDITION_WEIGHT REAL ", default_r_val=1.0_dp)
129 10850 : CALL section_add_keyword(section, keyword)
130 10850 : CALL keyword_release(keyword)
131 :
132 : CALL keyword_create(keyword, __LOCATION__, name="GROUP_PARTITION", &
133 : description="Allows the specification of the group mpi group sizes in parallel "// &
134 : "runs. If less Groups than tasks are speciefied, consecutive calculations "// &
135 : "Will be assigned to one group (derived basis sets and then training sets) "// &
136 : "If keyword is skipped, equal group sizes will be generated trying to fit all calculations.", &
137 : repeats=.TRUE., &
138 10850 : usage="GROUP_PARTITION INT INT ... ", type_of_var=integer_t, n_var=-1)
139 10850 : CALL section_add_keyword(section, keyword)
140 10850 : CALL keyword_release(keyword)
141 :
142 10850 : CALL create_fit_kinds_section(subsection)
143 10850 : CALL section_add_subsection(section, subsection)
144 10850 : CALL section_release(subsection)
145 :
146 10850 : CALL create_frontier_orbitals_section(subsection)
147 10850 : CALL section_add_subsection(section, subsection)
148 10850 : CALL section_release(subsection)
149 :
150 10850 : CALL create_frontier_orbital_screening_section(subsection)
151 10850 : CALL section_add_subsection(section, subsection)
152 10850 : CALL section_release(subsection)
153 :
154 10850 : CALL create_training_section(subsection)
155 10850 : CALL section_add_subsection(section, subsection)
156 10850 : CALL section_release(subsection)
157 :
158 10850 : CALL create_powell_section(subsection)
159 10850 : CALL section_add_subsection(section, subsection)
160 10850 : CALL section_release(subsection)
161 :
162 10850 : END SUBROUTINE create_optimize_basis_section
163 :
164 : ! **************************************************************************************************
165 : !> \brief Creates the optional frontier-orbital objective section.
166 : !> \param section ...
167 : ! **************************************************************************************************
168 10850 : SUBROUTINE create_frontier_orbitals_section(section)
169 : TYPE(section_type), POINTER :: section
170 :
171 : CHARACTER(len=2), PARAMETER :: paragraph_break = NEW_LINE("A")//NEW_LINE("A")
172 : TYPE(keyword_type), POINTER :: keyword
173 :
174 10850 : NULLIFY (keyword)
175 10850 : CPASSERT(.NOT. ASSOCIATED(section))
176 : CALL section_create( &
177 : section, __LOCATION__, name="FRONTIER_ORBITALS", &
178 : description="Optimizes a compact basis set to reproduce the occupied and low-energy virtual "// &
179 : "Kohn-Sham states obtained from a very large reference basis set. For each training system, "// &
180 : "a quantum-mechanical DFT reference calculation using this basis must be provided through "// &
181 : "TRAINING_FILES, including a converged reference wavefunction. The Kohn-Sham Hamiltonian from "// &
182 : "the reference calculation is frozen and "// &
183 : "projected into every trial compact basis. Consequently, all candidate orbital subspaces and "// &
184 : "energies, including the HOMO-LUMO gap, are evaluated relative to the reference Hamiltonian. "// &
185 : "When optimizing the compact basis against the large reference basis, the following loss "// &
186 : "function is minimized:"//paragraph_break// &
187 : "$$\mathcal{L}=\alpha_{\mathrm{occ}}\mathcal{L}_{\mathrm{occ}}+ "// &
188 : "\alpha_{\mathrm{vir}}\mathcal{L}_{\mathrm{vir}}+ "// &
189 : "\alpha_{\mathrm{empty}}\mathcal{L}_{\mathrm{empty}}+ "// &
190 : "\alpha_{\mathrm{gap}}\mathcal{L}_{\mathrm{gap}}+ "// &
191 : "\alpha_{\mathrm{coeff}}\mathcal{L}_{\mathrm{coeff}}+ "// &
192 : "\alpha_\kappa\mathcal{L}_\kappa.$$"//paragraph_break// &
193 : "Below, all loss functions $\mathcal{L}$ are defined. $R$ and $C$ label reference and "// &
194 : "candidate quantities, $i$ and $j$ label occupied orbitals, and $a$ and $b$ label virtual "// &
195 : "orbitals. Their overlaps are $M_{ij}=\langle\psi_i^R\vert\psi_j^C\rangle$ and "// &
196 : "$M_{ab}=\langle\psi_a^R\vert\psi_b^C\rangle$, respectively. "// &
197 : "$N_{\mathrm{occ}}$ is the number of occupied spatial orbitals. "// &
198 : "The occupied-subspace loss is"//paragraph_break// &
199 : "$$\mathcal{L}_{\mathrm{occ}}=1-\frac{1}{N_{\mathrm{occ}}} "// &
200 : "\sum_{i,j\in\mathrm{occ}}\lvert M_{ij}\rvert^2.$$"//paragraph_break// &
201 : "It penalizes a poor representation of the reference occupied orbitals by the occupied "// &
202 : "orbitals of the compact candidate basis. "// &
203 : "Low-energy virtual orbitals are selected smoothly using"//paragraph_break// &
204 : "$$w_a^X=\left[1+\exp\left( "// &
205 : "\frac{\epsilon_a^X-\epsilon_{\mathrm{LUMO}}^X-E_{\mathrm{cut}}}{\Delta E} "// &
206 : "\right)\right]^{-1},\qquad X\in\{R,C\}.$$"//paragraph_break// &
207 : "Define $N_X=\sum_{a\in\mathrm{vir}}(w_a^X)^2$. The virtual-subspace loss can be written "// &
208 : "directly as the normalized squared distance between the two energy-weighted virtual-space "// &
209 : "operators:"// &
210 : paragraph_break// &
211 : "$$\begin{aligned} "// &
212 : "\mathcal{L}_{\mathrm{vir}}&=\frac{1}{2N_R}\left\| "// &
213 : "\sum_{a\in\mathrm{vir}}w_a^R\lvert\psi_a^R\rangle\langle\psi_a^R\rvert- "// &
214 : "\sum_{b\in\mathrm{vir}}w_b^C\lvert\psi_b^C\rangle\langle\psi_b^C\rvert "// &
215 : "\right\|_F^2\\ "// &
216 : "&=\frac{N_R+N_C-2\sum_{a,b\in\mathrm{vir}} "// &
217 : "w_a^R w_b^C\lvert M_{ab}\rvert^2}{2N_R}. "// &
218 : "\end{aligned}$$"//paragraph_break// &
219 : "The first operator represents the reference low-energy virtual space and the second represents "// &
220 : "the candidate low-energy virtual space. Here, $\lVert\cdot\rVert_F^2$ is the squared Frobenius "// &
221 : "norm, which measures their squared matrix distance. Thus, $\mathcal{L}_{\mathrm{vir}}$ penalizes "// &
222 : "differences between the low-energy virtual orbitals of the compact candidate basis and the "// &
223 : "reference space; it is zero when these spaces coincide. The compact candidate basis can contain "// &
224 : "empty orbitals outside the "// &
225 : "selected low-energy interval. To test whether the reference low-energy virtual orbitals can be "// &
226 : "represented in the entire candidate empty space, the empty-subspace loss is"//paragraph_break// &
227 : "$$\mathcal{L}_{\mathrm{empty}}=1- "// &
228 : "\frac{\sum_{a,b\in\mathrm{vir}}(w_a^R)^2\lvert M_{ab}\rvert^2}{N_R}. "// &
229 : "$$"//paragraph_break// &
230 : "It penalizes reference low-energy virtual orbitals that cannot be represented by any empty "// &
231 : "orbital of the compact candidate basis. "// &
232 : "With $E_{\mathrm{gap}}^X=\epsilon_{\mathrm{LUMO}}^X-\epsilon_{\mathrm{HOMO}}^X$, "// &
233 : "the gap loss is"//paragraph_break// &
234 : "$$\mathcal{L}_{\mathrm{gap}}=\left( "// &
235 : "\frac{E_{\mathrm{gap}}^C-E_{\mathrm{gap}}^R}{E_{\mathrm{scale}}} "// &
236 : "\right)^2.$$"//paragraph_break// &
237 : "It penalizes deviations of the candidate HOMO-LUMO gap from the reference gap."// &
238 : paragraph_break// &
239 : "During the optimization, the electron density and the corresponding Kohn-Sham Hamiltonian "// &
240 : "are held fixed at the values obtained with the large reference basis set. Therefore, the "// &
241 : "candidate gap reported in the optimization output is the fixed-density gap of the reference "// &
242 : "Hamiltonian projected into the compact candidate basis. A separate self-consistent Kohn-Sham "// &
243 : "DFT calculation with the optimized compact basis can produce a different electron density and, "// &
244 : "consequently, a different HOMO-LUMO gap."//paragraph_break// &
245 : "For the "// &
246 : "optimized and initial contraction coefficients of the compact basis set, $c$ and $c_0$, "// &
247 : "the coefficient loss is"//paragraph_break// &
248 : "$$\mathcal{L}_{\mathrm{coeff}}= "// &
249 : "\frac{\sum_p(c_p-c_{0,p})^2}{\sum_p c_{0,p}^2}.$$"//paragraph_break// &
250 : "It penalizes large deviations from the coefficients of the initially supplied compact "// &
251 : "basis set. Finally, the conditioning loss is"//paragraph_break// &
252 : "$$\mathcal{L}_\kappa=\log_{10}\kappa(S_C),\qquad "// &
253 : "\kappa(S_C)=\frac{\lambda_{\max}(S_C)}{\lambda_{\min}(S_C)}.$$"//paragraph_break// &
254 : "It penalizes an ill-conditioned candidate overlap matrix. The weights "// &
255 : "$\alpha_{\mathrm{occ}}$, $\alpha_{\mathrm{vir}}$, $\alpha_{\mathrm{empty}}$, "// &
256 : "$\alpha_{\mathrm{gap}}$, and $\alpha_{\mathrm{coeff}}$ are set below; "// &
257 : "CONDITION_WEIGHT supplies $\alpha_\kappa$."//paragraph_break// &
258 : "The loss weights $\alpha_{\mathrm{occ}}$, $\alpha_{\mathrm{vir}}$, "// &
259 : "$\alpha_{\mathrm{empty}}$, $\alpha_{\mathrm{gap}}$, "// &
260 : "$\alpha_{\mathrm{coeff}}$, and $\alpha_\kappa$ can have a strong and "// &
261 : "system-dependent effect on the accuracy of the optimized basis set. In particular, the user "// &
262 : "has to test the new basis set in a self-consistent DFT calculation, which also uses the "// &
263 : "self-consistent electron density computed with the optimized basis set (during the "// &
264 : "optimization, the electron density is kept fixed at the density obtained with the large "// &
265 : "reference basis set). Several combinations of loss weights should be tested, and the optimal "// &
266 : "basis should be selected based on validation with a self-consistent DFT calculation using the "// &
267 : "new basis set (for example, by focusing on the resulting DFT gap, GW gap, or GW-BSE excitation "// &
268 : "energy). Useful candidate parameter combinations include:"//paragraph_break// &
269 : "1. OCCUPIED_WEIGHT 1, VIRTUAL_WEIGHT 1, EMPTY_OVERLAP_WEIGHT 1, GAP_WEIGHT 10, "// &
270 : "GAP_ENERGY_SCALE [eV] 1, CONDITION_WEIGHT 0.1, COEFFICIENT_WEIGHT 0.001"//NEW_LINE("A")// &
271 : "2. OCCUPIED_WEIGHT 10, VIRTUAL_WEIGHT 10, EMPTY_OVERLAP_WEIGHT 10, GAP_WEIGHT 10, "// &
272 : "GAP_ENERGY_SCALE [eV] 1, CONDITION_WEIGHT 0.001, COEFFICIENT_WEIGHT 0.001"//NEW_LINE("A")// &
273 : "3. OCCUPIED_WEIGHT 30, VIRTUAL_WEIGHT 30, EMPTY_OVERLAP_WEIGHT 30, GAP_WEIGHT 10, "// &
274 : "GAP_ENERGY_SCALE [eV] 1, CONDITION_WEIGHT 0.001, COEFFICIENT_WEIGHT 0.001"//NEW_LINE("A")// &
275 : "4. OCCUPIED_WEIGHT 10, VIRTUAL_WEIGHT 30, EMPTY_OVERLAP_WEIGHT 30, GAP_WEIGHT 10, "// &
276 : "GAP_ENERGY_SCALE [eV] 1, CONDITION_WEIGHT 0.001, COEFFICIENT_WEIGHT 0.01", &
277 10850 : repeats=.FALSE.)
278 :
279 : CALL keyword_create( &
280 : keyword, __LOCATION__, name="OCCUPIED_WEIGHT", &
281 : description="Prefactor $\alpha_{\mathrm{occ}}$ multiplying the occupied-subspace loss "// &
282 : "$\mathcal{L}_{\mathrm{occ}}$.", &
283 10850 : usage="OCCUPIED_WEIGHT 1.0", type_of_var=real_t, default_r_val=1.0_dp)
284 10850 : CALL section_add_keyword(section, keyword)
285 10850 : CALL keyword_release(keyword)
286 :
287 : CALL keyword_create( &
288 : keyword, __LOCATION__, name="VIRTUAL_WEIGHT", &
289 : description="Prefactor $\alpha_{\mathrm{vir}}$ multiplying the virtual-subspace loss "// &
290 : "$\mathcal{L}_{\mathrm{vir}}$.", &
291 10850 : usage="VIRTUAL_WEIGHT 1.0", type_of_var=real_t, default_r_val=1.0_dp)
292 10850 : CALL section_add_keyword(section, keyword)
293 10850 : CALL keyword_release(keyword)
294 :
295 : CALL keyword_create( &
296 : keyword, __LOCATION__, name="EMPTY_OVERLAP_WEIGHT", &
297 : description="Prefactor $\alpha_{\mathrm{empty}}$ multiplying "// &
298 : "$\mathcal{L}_{\mathrm{empty}}$, the loss of reference low-energy virtual-state "// &
299 : "completeness in the candidate virtual subspace.", &
300 10850 : usage="EMPTY_OVERLAP_WEIGHT 1.0", type_of_var=real_t, default_r_val=1.0_dp)
301 10850 : CALL section_add_keyword(section, keyword)
302 10850 : CALL keyword_release(keyword)
303 :
304 : CALL keyword_create( &
305 : keyword, __LOCATION__, name="GAP_WEIGHT", &
306 : description="Prefactor $\alpha_{\mathrm{gap}}$ multiplying the normalized HOMO-LUMO gap loss "// &
307 : "$\mathcal{L}_{\mathrm{gap}}$. Because $\mathcal{L}_{\mathrm{gap}}$ is proportional to "// &
308 : "$1/E_{\mathrm{scale}}^2$, reducing GAP_ENERGY_SCALE by a factor "// &
309 : "of 100 requires reducing GAP_WEIGHT by a factor of 10000 to retain the same balance.", &
310 10850 : usage="GAP_WEIGHT 1.0E-3", type_of_var=real_t, default_r_val=1.0E-3_dp)
311 10850 : CALL section_add_keyword(section, keyword)
312 10850 : CALL keyword_release(keyword)
313 :
314 : CALL keyword_create( &
315 : keyword, __LOCATION__, name="COEFFICIENT_WEIGHT", &
316 : description="Prefactor $\alpha_{\mathrm{coeff}}$ multiplying the normalized squared change "// &
317 : "$\mathcal{L}_{\mathrm{coeff}}$ of the optimized contraction coefficients from their "// &
318 : "initial values.", &
319 10850 : usage="COEFFICIENT_WEIGHT 1.0E-3", type_of_var=real_t, default_r_val=1.0E-3_dp)
320 10850 : CALL section_add_keyword(section, keyword)
321 10850 : CALL keyword_release(keyword)
322 :
323 : CALL keyword_create( &
324 : keyword, __LOCATION__, name="GAP_ENERGY_SCALE", &
325 : description="$E_{\mathrm{scale}}$ in the gap loss. A gap error of this magnitude gives "// &
326 : "$\mathcal{L}_{\mathrm{gap}}=1$. The default is 0.01 eV.", &
327 : usage="GAP_ENERGY_SCALE [eV] 0.01", type_of_var=real_t, unit_str="eV", &
328 10850 : default_r_val=cp_unit_to_cp2k(value=0.01_dp, unit_str="eV"))
329 10850 : CALL section_add_keyword(section, keyword)
330 10850 : CALL keyword_release(keyword)
331 :
332 : CALL keyword_create( &
333 : keyword, __LOCATION__, name="VIRTUAL_ENERGY_CUTOFF", &
334 : description="$E_{\mathrm{cut}}$, the virtual-orbital energy window measured "// &
335 : "from the corresponding LUMO. The default is 3 eV.", &
336 : usage="VIRTUAL_ENERGY_CUTOFF [eV] 3.0", type_of_var=real_t, unit_str="eV", &
337 10850 : default_r_val=cp_unit_to_cp2k(value=3.0_dp, unit_str="eV"))
338 10850 : CALL section_add_keyword(section, keyword)
339 10850 : CALL keyword_release(keyword)
340 :
341 : CALL keyword_create( &
342 : keyword, __LOCATION__, name="VIRTUAL_ENERGY_SMOOTHING", &
343 : description="$\Delta E$, the smoothing width at the outer boundary of the "// &
344 : "virtual-orbital energy window. It must be positive; the default is 0.2 eV.", &
345 : usage="VIRTUAL_ENERGY_SMOOTHING [eV] 0.2", type_of_var=real_t, unit_str="eV", &
346 10850 : default_r_val=cp_unit_to_cp2k(value=0.2_dp, unit_str="eV"))
347 10850 : CALL section_add_keyword(section, keyword)
348 10850 : CALL keyword_release(keyword)
349 :
350 10850 : END SUBROUTINE create_frontier_orbitals_section
351 :
352 : ! **************************************************************************************************
353 : !> \brief Creates the optional serial frontier-orbital screening section.
354 : !> \param section ...
355 : ! **************************************************************************************************
356 10850 : SUBROUTINE create_frontier_orbital_screening_section(section)
357 : TYPE(section_type), POINTER :: section
358 :
359 : TYPE(keyword_type), POINTER :: keyword
360 :
361 10850 : NULLIFY (keyword)
362 10850 : CPASSERT(.NOT. ASSOCIATED(section))
363 : CALL section_create( &
364 : section, __LOCATION__, name="FRONTIER_ORBITAL_SCREENING", &
365 : description="Optimize a basis set to match frontier orbitals of a reference basis "// &
366 : "(frontier orbitals: orbitals close to the HOMO and close to the LUMO). This section uses the "// &
367 : "optimization described in OPTIMIZE_BASIS%FRONTIER_ORBITALS, where the complete optimization "// &
368 : "theory is given. The optimization contains several parameters, in particular the prefactors "// &
369 : "of its different loss functions, and the resulting optimized basis set can depend strongly "// &
370 : "on these prefactors. This section runs up to five pre-tabulated sets of optimization "// &
371 : "parameters. All optimized basis sets are reported together with their self-consistent "// &
372 : "HOMO-LUMO gaps and total energies. The optimization uses the fixed electron density obtained "// &
373 : "with a large reference basis, and CP2K also converges an SCF calculation with every optimized "// &
374 : "basis set and reports the resulting HOMO-LUMO gap and total energy. No training calculation "// &
375 : "or previous DFT calculation needs to be read. All DFT calculations are performed automatically "// &
376 : "inside CP2K when this section is activated, using the DFT input parameters supplied in the "// &
377 : "FORCE_EVAL section of the input file. All optimized basis sets are written to "// &
378 : "BASIS_OUTPUT_FILE with suffixes such as _1 and _2.", &
379 10850 : repeats=.FALSE.)
380 :
381 : CALL keyword_create(keyword, __LOCATION__, name="NUMBER_OF_OPTIMIZATIONS", &
382 : description="Number of pre-tabulated sets of optimization parameters.", &
383 : usage="NUMBER_OF_OPTIMIZATIONS 5", &
384 10850 : default_i_val=5)
385 10850 : CALL section_add_keyword(section, keyword)
386 10850 : CALL keyword_release(keyword)
387 :
388 10850 : END SUBROUTINE create_frontier_orbital_screening_section
389 :
390 : ! **************************************************************************************************
391 : !> \brief ...
392 : !> \param section ...
393 : ! **************************************************************************************************
394 10850 : SUBROUTINE create_fit_kinds_section(section)
395 : TYPE(section_type), POINTER :: section
396 :
397 : TYPE(keyword_type), POINTER :: keyword
398 : TYPE(section_type), POINTER :: subsection
399 :
400 10850 : NULLIFY (keyword, subsection)
401 10850 : CPASSERT(.NOT. ASSOCIATED(section))
402 : CALL section_create(section, __LOCATION__, name="FIT_KIND", &
403 : description="specicifies the atomic kinds to be fitted and the basis"// &
404 : " sets associated with the kind.", &
405 10850 : repeats=.TRUE.)
406 :
407 : CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
408 : description="The name of the kind described in this section.", &
409 10850 : usage="H", default_c_val="DEFAULT")
410 10850 : CALL section_add_keyword(section, keyword)
411 10850 : CALL keyword_release(keyword)
412 :
413 : CALL keyword_create(keyword, __LOCATION__, name="BASIS_SET", &
414 : description="The name of the basis set for the kind. Has to be specified in BASIS_TEMPLATE_FILE.", &
415 10850 : usage="BASIS_SET H", default_c_val="DEFAULT")
416 10850 : CALL section_add_keyword(section, keyword)
417 10850 : CALL keyword_release(keyword)
418 :
419 : CALL keyword_create(keyword, __LOCATION__, name="INITIAL_DEGREES_OF_FREEDOM", &
420 : description="Specifies the initial degrees of freedom in the basis optimization. "// &
421 : "This can be used to make further specifications easier", &
422 : usage="INITIAL_DEGREES_OF_FREEDOM ALL", &
423 : enum_c_vals=s2a("ALL", "NONE", "COEFFICIENTS", "EXPONENTS"), &
424 : enum_desc=s2a("Set all parameters in the basis to be variable.", &
425 : "Set all parameters in the basis to be fixed.", &
426 : "Set all coefficients in the basis set to be variable.", &
427 : "Set all exponents in the basis to be variable."), &
428 : enum_i_vals=[do_opt_all, do_opt_none, do_opt_coeff, do_opt_exps], &
429 10850 : default_i_val=do_opt_coeff)
430 10850 : CALL section_add_keyword(section, keyword)
431 10850 : CALL keyword_release(keyword)
432 :
433 : CALL keyword_create(keyword, __LOCATION__, name="SWITCH_COEFF_STATE", &
434 : description="Allows to switch the state of a given coefficient from current state "// &
435 : "(varibale/fixed)) to the opposite state. The three integers indicate "// &
436 : "the set number, the angular momentum i'th contraction and i'th coefficient", repeats=.TRUE., &
437 10850 : usage="SWITCH_COEFF_STATE SET L CONTRACTION IPGF", type_of_var=integer_t, n_var=4)
438 10850 : CALL section_add_keyword(section, keyword)
439 10850 : CALL keyword_release(keyword)
440 :
441 : CALL keyword_create(keyword, __LOCATION__, name="SWITCH_CONTRACTION_STATE", &
442 : description="Allows to switch the state of a given contraction from current state "// &
443 : "(varibale/fixed)) to the opposite state. The three integers indicate "// &
444 : "the set number, the angular momentum and i'th contraction ", repeats=.TRUE., &
445 10850 : usage="SWITCH_CONTRACTION_STATE SET L CONTRACTION ", type_of_var=integer_t, n_var=3)
446 10850 : CALL section_add_keyword(section, keyword)
447 10850 : CALL keyword_release(keyword)
448 :
449 : CALL keyword_create(keyword, __LOCATION__, name="SWITCH_EXP_STATE", &
450 : description="Allows to switch the state of a given exponent from current state "// &
451 : "(varibale/fixed)) to the opposite state. The two integers indicate "// &
452 : "the set number and i'th exponent", repeats=.TRUE., &
453 10850 : usage="SWITCH_EXP_STATE SET IEXP", type_of_var=integer_t, n_var=2)
454 10850 : CALL section_add_keyword(section, keyword)
455 10850 : CALL keyword_release(keyword)
456 :
457 : CALL keyword_create(keyword, __LOCATION__, name="SWITCH_SET_STATE", &
458 : description="Allows to switch the states of in a set from current state "// &
459 : "(varibale/fixed)) to the opposite state. The two integers indicate "// &
460 : "the affected part (0=ALL,1=EXPS,2=COEFF) and i'th set", repeats=.TRUE., &
461 10850 : usage="SWITCH_SET_STATE SET IEXP", type_of_var=integer_t, n_var=2)
462 10850 : CALL section_add_keyword(section, keyword)
463 10850 : CALL keyword_release(keyword)
464 :
465 10850 : CALL create_constrain_exp_section(subsection)
466 10850 : CALL section_add_subsection(section, subsection)
467 10850 : CALL section_release(subsection)
468 :
469 10850 : CALL create_derived_sets_section(subsection)
470 10850 : CALL section_add_subsection(section, subsection)
471 10850 : CALL section_release(subsection)
472 :
473 10850 : END SUBROUTINE create_fit_kinds_section
474 :
475 : ! **************************************************************************************************
476 : !> \brief ...
477 : !> \param section ...
478 : ! **************************************************************************************************
479 10850 : SUBROUTINE create_derived_sets_section(section)
480 : TYPE(section_type), POINTER :: section
481 :
482 : TYPE(keyword_type), POINTER :: keyword
483 :
484 10850 : NULLIFY (keyword)
485 10850 : CPASSERT(.NOT. ASSOCIATED(section))
486 : CALL section_create(section, __LOCATION__, name="DERIVED_BASIS_SETS", &
487 : description="This section can be used to create subsets of a basis"// &
488 : " which will be fitted at the same time. This is especially useful if connected"// &
489 : " bsis sets e.g. TZVP, DZVP, SZV should be fitted.", &
490 10850 : repeats=.TRUE.)
491 :
492 : CALL keyword_create(keyword, __LOCATION__, name="BASIS_SET_NAME", &
493 : description="Defines the name of the derived basis set, which will be "// &
494 : "automatically generated otherwise.", &
495 : usage="BASIS_SET_NAME {word}", &
496 : type_of_var=char_t, &
497 : repeats=.FALSE., &
498 10850 : default_c_val="")
499 10850 : CALL section_add_keyword(section, keyword)
500 10850 : CALL keyword_release(keyword)
501 :
502 : CALL keyword_create(keyword, __LOCATION__, name="REFERENCE_SET", &
503 : description="Specifies the reference basis ID which is used as template to create the new set. "// &
504 : "The original basis has ID 0. All following sets are counted in order as specified in the Input."// &
505 : " The descriptors always assume the structure of the input basis set.", &
506 10850 : repeats=.FALSE., usage="REFERENCE_SET INTEGER", default_i_val=0)
507 10850 : CALL section_add_keyword(section, keyword)
508 10850 : CALL keyword_release(keyword)
509 :
510 : CALL keyword_create(keyword, __LOCATION__, name="REMOVE_CONTRACTION", &
511 : description="Can be used to remove a contraction from the reference basis set. "// &
512 : "The contraction is speciefied by set number, angular momentum and number of contraction."// &
513 : " The descriptors always assume the structure of the input basis set.", &
514 10850 : repeats=.TRUE., usage="REMOVE_CONTRACTION SET L ICONTRACTION", type_of_var=integer_t, n_var=3)
515 10850 : CALL section_add_keyword(section, keyword)
516 10850 : CALL keyword_release(keyword)
517 :
518 : CALL keyword_create(keyword, __LOCATION__, name="REMOVE_SET", &
519 : description="Can be used to remove a set from the reference basis set. ", &
520 10850 : repeats=.TRUE., usage="REMOVE_SET SET", type_of_var=integer_t, n_var=1)
521 10850 : CALL section_add_keyword(section, keyword)
522 10850 : CALL keyword_release(keyword)
523 :
524 10850 : END SUBROUTINE create_derived_sets_section
525 :
526 : ! **************************************************************************************************
527 : !> \brief ...
528 : !> \param section ...
529 : ! **************************************************************************************************
530 10850 : SUBROUTINE create_constrain_exp_section(section)
531 : TYPE(section_type), POINTER :: section
532 :
533 : TYPE(keyword_type), POINTER :: keyword
534 :
535 10850 : NULLIFY (keyword)
536 10850 : CPASSERT(.NOT. ASSOCIATED(section))
537 : CALL section_create(section, __LOCATION__, name="CONSTRAIN_EXPONENTS", &
538 : description="specicifies constraints for the exponents to be fitted."// &
539 : " Only a single constraint can be applied to an exponent", &
540 10850 : repeats=.TRUE.)
541 :
542 : CALL keyword_create(keyword, __LOCATION__, name="USE_EXP", &
543 : description="Defines the exponent to be constraint. The two integers indicate "// &
544 : "the set number and i'th exponent. The value -1 can be used to mark all sets/exponents in a set.", &
545 10850 : repeats=.FALSE., usage="USE_EXP SET IEXP", type_of_var=integer_t, n_var=2)
546 10850 : CALL section_add_keyword(section, keyword)
547 10850 : CALL keyword_release(keyword)
548 :
549 : CALL keyword_create(keyword, __LOCATION__, name="BOUNDARIES", &
550 : description="Defines the boundaries to which the optimization is restricted."// &
551 : " First value is the lower bound, second value is the upper bound.", &
552 10850 : repeats=.FALSE., usage="BOUNDARIES LOWER UPPER", type_of_var=real_t, n_var=2)
553 10850 : CALL section_add_keyword(section, keyword)
554 10850 : CALL keyword_release(keyword)
555 :
556 : CALL keyword_create(keyword, __LOCATION__, name="MAX_VAR_FRACTION", &
557 : description="Defines the maximum fractionr by which the exponent is allowed to vary."// &
558 : " e.g. 0.5 allows the exp to vary by 0.5*exp in both directions.", &
559 10850 : repeats=.FALSE., usage="MAX_VAR_FRACTION REAL", type_of_var=real_t, n_var=1)
560 10850 : CALL section_add_keyword(section, keyword)
561 10850 : CALL keyword_release(keyword)
562 :
563 10850 : END SUBROUTINE create_constrain_exp_section
564 :
565 : ! **************************************************************************************************
566 : !> \brief ...
567 : !> \param section ...
568 : ! **************************************************************************************************
569 10850 : SUBROUTINE create_training_section(section)
570 : TYPE(section_type), POINTER :: section
571 :
572 : TYPE(keyword_type), POINTER :: keyword
573 :
574 10850 : NULLIFY (keyword)
575 10850 : CPASSERT(.NOT. ASSOCIATED(section))
576 : CALL section_create(section, __LOCATION__, name="TRAINING_FILES", &
577 : description="specicifies the location in which the files necessary for"// &
578 : " fitting procedure are located. Each Training set needs a repetition of this section.", &
579 10850 : repeats=.TRUE.)
580 :
581 : CALL keyword_create(keyword, __LOCATION__, name="DIRECTORY", &
582 : description="the directory in which the files are placed", &
583 : usage="DIRECTORY /my/path", &
584 10850 : default_lc_val=".")
585 10850 : CALL section_add_keyword(section, keyword)
586 10850 : CALL keyword_release(keyword)
587 :
588 : CALL keyword_create(keyword, __LOCATION__, name="INPUT_FILE_NAME", &
589 : description="the filename of the input file used to run the original calculation", &
590 : usage="INPUT_FILE_NAME my_input.inp", &
591 10850 : default_lc_val="input.inp")
592 10850 : CALL section_add_keyword(section, keyword)
593 10850 : CALL keyword_release(keyword)
594 :
595 10850 : END SUBROUTINE create_training_section
596 :
597 : ! **************************************************************************************************
598 : !> \brief ...
599 : !> \param section ...
600 : ! **************************************************************************************************
601 10850 : SUBROUTINE create_powell_section(section)
602 : TYPE(section_type), POINTER :: section
603 :
604 : TYPE(keyword_type), POINTER :: keyword
605 :
606 10850 : NULLIFY (keyword)
607 10850 : CPASSERT(.NOT. ASSOCIATED(section))
608 : CALL section_create(section, __LOCATION__, name="OPTIMIZATION", &
609 : description="sets the parameters for optimizition, output frequency and restarts", &
610 10850 : repeats=.FALSE.)
611 :
612 : CALL keyword_create(keyword, __LOCATION__, name="ACCURACY", &
613 : description="Final accuracy requested in optimization (RHOEND)", &
614 : usage="ACCURACY 0.00001", &
615 10850 : default_r_val=1.e-5_dp)
616 10850 : CALL section_add_keyword(section, keyword)
617 10850 : CALL keyword_release(keyword)
618 :
619 : CALL keyword_create(keyword, __LOCATION__, name="STEP_SIZE", &
620 : description="Initial step size for search algorithm (RHOBEG)", &
621 : usage="STEP_SIZE 0.005", &
622 10850 : default_r_val=0.1_dp)
623 10850 : CALL section_add_keyword(section, keyword)
624 10850 : CALL keyword_release(keyword)
625 :
626 : CALL keyword_create(keyword, __LOCATION__, name="MAX_FUN", &
627 : description="Maximum number of function evaluations", &
628 : usage="MAX_FUN 1000", &
629 10850 : default_i_val=5000)
630 10850 : CALL section_add_keyword(section, keyword)
631 10850 : CALL keyword_release(keyword)
632 :
633 10850 : END SUBROUTINE create_powell_section
634 :
635 : END MODULE input_optimize_basis
|