(git:5e7fe52)
Loading...
Searching...
No Matches
input_optimize_basis.F
Go to the documentation of this file.
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! **************************************************************************************************
15
16 USE cp_units, ONLY: cp_unit_to_cp2k
17 USE input_constants, ONLY: do_opt_all, &
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'
41
42CONTAINS
43
44! **************************************************************************************************
45!> \brief creates the optimize_basis section
46!> \param section ...
47!> \author Florian Schiffmann
48! **************************************************************************************************
50 TYPE(section_type), POINTER :: section
51
52 TYPE(keyword_type), POINTER :: keyword
53 TYPE(section_type), POINTER :: subsection
54
55 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 repeats=.false.)
60 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 default_c_val="BASIS_SET", n_var=-1)
67 CALL section_add_keyword(section, keyword)
68 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 default_c_val="BASIS_WORK_FILE", n_var=-1)
75 CALL section_add_keyword(section, keyword)
76 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 default_c_val="BASIS_OUTPUT_FILE", n_var=-1)
83 CALL section_add_keyword(section, keyword)
84 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 default_i_val=5000)
90 CALL section_add_keyword(section, keyword)
91 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 default_l_val=.false., lone_keyword_l_val=.true.)
97 CALL section_add_keyword(section, keyword)
98 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 usage="BASIS_COMBINATIONS SET_ID(KIND1) SET_ID(KIND2) ... ", type_of_var=integer_t, n_var=-1)
107 CALL section_add_keyword(section, keyword)
108 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 usage="RESIDUUM_WEIGHT REAL ", default_r_val=1.0_dp)
118 CALL section_add_keyword(section, keyword)
119 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 usage="CONDITION_WEIGHT REAL ", default_r_val=1.0_dp)
129 CALL section_add_keyword(section, keyword)
130 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 usage="GROUP_PARTITION INT INT ... ", type_of_var=integer_t, n_var=-1)
139 CALL section_add_keyword(section, keyword)
140 CALL keyword_release(keyword)
141
142 CALL create_fit_kinds_section(subsection)
143 CALL section_add_subsection(section, subsection)
144 CALL section_release(subsection)
145
146 CALL create_frontier_orbitals_section(subsection)
147 CALL section_add_subsection(section, subsection)
148 CALL section_release(subsection)
149
150 CALL create_frontier_orbital_screening_section(subsection)
151 CALL section_add_subsection(section, subsection)
152 CALL section_release(subsection)
153
154 CALL create_training_section(subsection)
155 CALL section_add_subsection(section, subsection)
156 CALL section_release(subsection)
157
158 CALL create_powell_section(subsection)
159 CALL section_add_subsection(section, subsection)
160 CALL section_release(subsection)
161
162 END SUBROUTINE create_optimize_basis_section
163
164! **************************************************************************************************
165!> \brief Creates the optional frontier-orbital objective section.
166!> \param section ...
167! **************************************************************************************************
168 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 NULLIFY (keyword)
175 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 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 usage="OCCUPIED_WEIGHT 1.0", type_of_var=real_t, default_r_val=1.0_dp)
284 CALL section_add_keyword(section, keyword)
285 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 usage="VIRTUAL_WEIGHT 1.0", type_of_var=real_t, default_r_val=1.0_dp)
292 CALL section_add_keyword(section, keyword)
293 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 usage="EMPTY_OVERLAP_WEIGHT 1.0", type_of_var=real_t, default_r_val=1.0_dp)
301 CALL section_add_keyword(section, keyword)
302 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 usage="GAP_WEIGHT 1.0E-3", type_of_var=real_t, default_r_val=1.0e-3_dp)
311 CALL section_add_keyword(section, keyword)
312 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 usage="COEFFICIENT_WEIGHT 1.0E-3", type_of_var=real_t, default_r_val=1.0e-3_dp)
320 CALL section_add_keyword(section, keyword)
321 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 default_r_val=cp_unit_to_cp2k(value=0.01_dp, unit_str="eV"))
329 CALL section_add_keyword(section, keyword)
330 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 default_r_val=cp_unit_to_cp2k(value=3.0_dp, unit_str="eV"))
338 CALL section_add_keyword(section, keyword)
339 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 default_r_val=cp_unit_to_cp2k(value=0.2_dp, unit_str="eV"))
347 CALL section_add_keyword(section, keyword)
348 CALL keyword_release(keyword)
349
350 END SUBROUTINE create_frontier_orbitals_section
351
352! **************************************************************************************************
353!> \brief Creates the optional serial frontier-orbital screening section.
354!> \param section ...
355! **************************************************************************************************
356 SUBROUTINE create_frontier_orbital_screening_section(section)
357 TYPE(section_type), POINTER :: section
358
359 TYPE(keyword_type), POINTER :: keyword
360
361 NULLIFY (keyword)
362 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 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 default_i_val=5)
385 CALL section_add_keyword(section, keyword)
386 CALL keyword_release(keyword)
387
388 END SUBROUTINE create_frontier_orbital_screening_section
389
390! **************************************************************************************************
391!> \brief ...
392!> \param section ...
393! **************************************************************************************************
394 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 NULLIFY (keyword, subsection)
401 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 repeats=.true.)
406
407 CALL keyword_create(keyword, __location__, name="_SECTION_PARAMETERS_", &
408 description="The name of the kind described in this section.", &
409 usage="H", default_c_val="DEFAULT")
410 CALL section_add_keyword(section, keyword)
411 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 usage="BASIS_SET H", default_c_val="DEFAULT")
416 CALL section_add_keyword(section, keyword)
417 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."), &
429 default_i_val=do_opt_coeff)
430 CALL section_add_keyword(section, keyword)
431 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 usage="SWITCH_COEFF_STATE SET L CONTRACTION IPGF", type_of_var=integer_t, n_var=4)
438 CALL section_add_keyword(section, keyword)
439 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 usage="SWITCH_CONTRACTION_STATE SET L CONTRACTION ", type_of_var=integer_t, n_var=3)
446 CALL section_add_keyword(section, keyword)
447 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 usage="SWITCH_EXP_STATE SET IEXP", type_of_var=integer_t, n_var=2)
454 CALL section_add_keyword(section, keyword)
455 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 usage="SWITCH_SET_STATE SET IEXP", type_of_var=integer_t, n_var=2)
462 CALL section_add_keyword(section, keyword)
463 CALL keyword_release(keyword)
464
465 CALL create_constrain_exp_section(subsection)
466 CALL section_add_subsection(section, subsection)
467 CALL section_release(subsection)
468
469 CALL create_derived_sets_section(subsection)
470 CALL section_add_subsection(section, subsection)
471 CALL section_release(subsection)
472
473 END SUBROUTINE create_fit_kinds_section
474
475! **************************************************************************************************
476!> \brief ...
477!> \param section ...
478! **************************************************************************************************
479 SUBROUTINE create_derived_sets_section(section)
480 TYPE(section_type), POINTER :: section
481
482 TYPE(keyword_type), POINTER :: keyword
483
484 NULLIFY (keyword)
485 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 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 default_c_val="")
499 CALL section_add_keyword(section, keyword)
500 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 repeats=.false., usage="REFERENCE_SET INTEGER", default_i_val=0)
507 CALL section_add_keyword(section, keyword)
508 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 repeats=.true., usage="REMOVE_CONTRACTION SET L ICONTRACTION", type_of_var=integer_t, n_var=3)
515 CALL section_add_keyword(section, keyword)
516 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 repeats=.true., usage="REMOVE_SET SET", type_of_var=integer_t, n_var=1)
521 CALL section_add_keyword(section, keyword)
522 CALL keyword_release(keyword)
523
524 END SUBROUTINE create_derived_sets_section
525
526! **************************************************************************************************
527!> \brief ...
528!> \param section ...
529! **************************************************************************************************
530 SUBROUTINE create_constrain_exp_section(section)
531 TYPE(section_type), POINTER :: section
532
533 TYPE(keyword_type), POINTER :: keyword
534
535 NULLIFY (keyword)
536 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 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 repeats=.false., usage="USE_EXP SET IEXP", type_of_var=integer_t, n_var=2)
546 CALL section_add_keyword(section, keyword)
547 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 repeats=.false., usage="BOUNDARIES LOWER UPPER", type_of_var=real_t, n_var=2)
553 CALL section_add_keyword(section, keyword)
554 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 repeats=.false., usage="MAX_VAR_FRACTION REAL", type_of_var=real_t, n_var=1)
560 CALL section_add_keyword(section, keyword)
561 CALL keyword_release(keyword)
562
563 END SUBROUTINE create_constrain_exp_section
564
565! **************************************************************************************************
566!> \brief ...
567!> \param section ...
568! **************************************************************************************************
569 SUBROUTINE create_training_section(section)
570 TYPE(section_type), POINTER :: section
571
572 TYPE(keyword_type), POINTER :: keyword
573
574 NULLIFY (keyword)
575 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 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 default_lc_val=".")
585 CALL section_add_keyword(section, keyword)
586 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 default_lc_val="input.inp")
592 CALL section_add_keyword(section, keyword)
593 CALL keyword_release(keyword)
594
595 END SUBROUTINE create_training_section
596
597! **************************************************************************************************
598!> \brief ...
599!> \param section ...
600! **************************************************************************************************
601 SUBROUTINE create_powell_section(section)
602 TYPE(section_type), POINTER :: section
603
604 TYPE(keyword_type), POINTER :: keyword
605
606 NULLIFY (keyword)
607 cpassert(.NOT. ASSOCIATED(section))
608 CALL section_create(section, __location__, name="OPTIMIZATION", &
609 description="sets the parameters for optimizition, output frequency and restarts", &
610 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 default_r_val=1.e-5_dp)
616 CALL section_add_keyword(section, keyword)
617 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 default_r_val=0.1_dp)
623 CALL section_add_keyword(section, keyword)
624 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 default_i_val=5000)
630 CALL section_add_keyword(section, keyword)
631 CALL keyword_release(keyword)
632
633 END SUBROUTINE create_powell_section
634
635END MODULE input_optimize_basis
unit conversion facility
Definition cp_units.F:30
real(kind=dp) function, public cp_unit_to_cp2k(value, unit_str, defaults, power)
converts to the internal cp2k units to the given unit
Definition cp_units.F:1222
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_opt_coeff
integer, parameter, public do_opt_all
integer, parameter, public do_opt_exps
integer, parameter, public do_opt_none
represents keywords in an input
subroutine, public keyword_release(keyword)
releases the given keyword (see doc/ReferenceCounting.html)
subroutine, public keyword_create(keyword, location, name, description, usage, type_of_var, n_var, repeats, variants, default_val, default_l_val, default_r_val, default_lc_val, default_c_val, default_i_val, default_l_vals, default_r_vals, default_c_vals, default_i_vals, lone_keyword_val, lone_keyword_l_val, lone_keyword_r_val, lone_keyword_c_val, lone_keyword_i_val, lone_keyword_l_vals, lone_keyword_r_vals, lone_keyword_c_vals, lone_keyword_i_vals, enum_c_vals, enum_i_vals, enum, enum_strict, enum_desc, unit_str, citations, deprecation_notice, removed)
creates a keyword object
builds the input structure for optimize_basis
subroutine, public create_optimize_basis_section(section)
creates the optimize_basis section
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_create(section, location, name, description, n_keywords, n_subsections, repeats, citations, deprecation_notice)
creates a list of keywords
subroutine, public section_add_keyword(section, keyword)
adds a keyword to the given section
subroutine, public section_add_subsection(section, subsection)
adds a subsection to the given section
recursive subroutine, public section_release(section)
releases the given keyword list (see doc/ReferenceCounting.html)
a wrapper for basic fortran types.
integer, parameter, public real_t
integer, parameter, public char_t
integer, parameter, public integer_t
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Utilities for string manipulations.
represent a keyword in the input
represent a section of the input file