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 function that builds the hartree fock exchange section of the input
10 : !> \par History
11 : !> 09.2007 created
12 : !> \author Manuel Guidon
13 : ! **************************************************************************************************
14 : MODULE input_cp2k_hfx
15 : USE bibliography, ONLY: Guidon2008, &
16 : Guidon2009, &
17 : Lin2016ACE
18 : USE cp_output_handling, ONLY: add_last_numeric, &
19 : cp_print_key_section_create, &
20 : high_print_level, &
21 : medium_print_level
22 : USE input_constants, ONLY: &
23 : do_potential_coulomb, do_potential_gaussian, do_potential_id, do_potential_long, &
24 : do_potential_mix_cl, do_potential_mix_cl_trunc, do_potential_mix_lg, do_potential_short, &
25 : do_potential_truncated, ehrenfest, gaussian, hfx_ri_do_2c_cholesky, hfx_ri_do_2c_diag, &
26 : hfx_ri_do_2c_iter
27 : USE input_keyword_types, ONLY: keyword_create, &
28 : keyword_release, &
29 : keyword_type
30 : USE input_section_types, ONLY: section_add_keyword, &
31 : section_add_subsection, &
32 : section_create, &
33 : section_release, &
34 : section_type
35 : USE input_val_types, ONLY: real_t
36 : USE kinds, ONLY: dp
37 : USE string_utilities, ONLY: s2a
38 : #include "./base/base_uses.f90"
39 :
40 : IMPLICIT NONE
41 : PRIVATE
42 :
43 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .FALSE.
44 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_hfx'
45 : INTEGER, PARAMETER, PUBLIC :: ri_mo = 1, ri_pmat = 2
46 :
47 : PUBLIC :: create_hfx_section
48 :
49 : CONTAINS
50 :
51 : ! **************************************************************************************************
52 : !> \brief creates the input section for the hf part
53 : !> \param section the section to create
54 : !> \author Manuel Guidon
55 : ! **************************************************************************************************
56 246720 : SUBROUTINE create_hfx_section(section)
57 : TYPE(section_type), POINTER :: section
58 :
59 : TYPE(keyword_type), POINTER :: keyword
60 : TYPE(section_type), POINTER :: print_key, subsection
61 :
62 246720 : CPASSERT(.NOT. ASSOCIATED(section))
63 : CALL section_create(section, __LOCATION__, name="HF", &
64 : description="Controls Hartree-Fock exchange for hybrid DFT, Hartree-Fock, "// &
65 : "and related post-Hartree-Fock workflows.", &
66 : n_keywords=5, n_subsections=2, repeats=.TRUE., &
67 740160 : citations=[Guidon2008, Guidon2009])
68 :
69 246720 : NULLIFY (keyword, print_key, subsection)
70 :
71 : CALL keyword_create(keyword, __LOCATION__, name="FRACTION", &
72 : description="Fraction of Hartree-Fock exchange to add to the total energy. "// &
73 : "1.0 implies standard Hartree-Fock if used with XC_FUNCTIONAL NONE. "// &
74 : "NOTE: In a mixed potential calculation this should be set to 1.0, otherwise "// &
75 : "all parts are multiplied with this factor. ", &
76 246720 : usage="FRACTION 1.0", default_r_val=1.0_dp)
77 246720 : CALL section_add_keyword(section, keyword)
78 246720 : CALL keyword_release(keyword)
79 :
80 : CALL keyword_create(keyword, __LOCATION__, name="TREAT_LSD_IN_CORE", &
81 : description="Determines how spin densities are taken into account. "// &
82 : "If true, the beta spin density is included via a second in core call. "// &
83 : "If false, alpha and beta spins are done in one shot ", &
84 246720 : usage="TREAT_LSD_IN_CORE TRUE", default_l_val=.FALSE.)
85 246720 : CALL section_add_keyword(section, keyword)
86 246720 : CALL keyword_release(keyword)
87 :
88 : CALL keyword_create(keyword, __LOCATION__, name="PW_HFX", &
89 : description="Compute the Hartree-Fock energy also in the plane wave basis. "// &
90 : "The value is ignored, and intended for debugging only.", &
91 246720 : usage="PW_HFX FALSE", default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
92 246720 : CALL section_add_keyword(section, keyword)
93 246720 : CALL keyword_release(keyword)
94 :
95 : CALL keyword_create(keyword, __LOCATION__, name="PW_HFX_BLOCKSIZE", &
96 : description="Improve the performance of pw_hfx at the cost of some additional memory "// &
97 : "by storing the realspace representation of PW_HFX_BLOCKSIZE states.", &
98 246720 : usage="PW_HFX_BLOCKSIZE 20", default_i_val=20)
99 246720 : CALL section_add_keyword(section, keyword)
100 246720 : CALL keyword_release(keyword)
101 :
102 246720 : NULLIFY (print_key)
103 : CALL cp_print_key_section_create(print_key, __LOCATION__, "HF_INFO", &
104 : description="Controls the printing basic info about hf method", &
105 246720 : print_level=medium_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
106 246720 : CALL section_add_subsection(section, print_key)
107 246720 : CALL section_release(print_key)
108 :
109 246720 : CALL create_hf_pbc_section(subsection)
110 246720 : CALL section_add_subsection(section, subsection)
111 246720 : CALL section_release(subsection)
112 :
113 246720 : CALL create_hf_screening_section(subsection)
114 246720 : CALL section_add_subsection(section, subsection)
115 246720 : CALL section_release(subsection)
116 :
117 246720 : CALL create_hf_potential_section(subsection)
118 246720 : CALL section_add_subsection(section, subsection)
119 246720 : CALL section_release(subsection)
120 :
121 246720 : CALL create_hf_load_balance_section(subsection)
122 246720 : CALL section_add_subsection(section, subsection)
123 246720 : CALL section_release(subsection)
124 :
125 246720 : CALL create_hf_memory_section(subsection)
126 246720 : CALL section_add_subsection(section, subsection)
127 246720 : CALL section_release(subsection)
128 :
129 246720 : CALL create_hf_ri_section(subsection)
130 246720 : CALL section_add_subsection(section, subsection)
131 246720 : CALL section_release(subsection)
132 :
133 246720 : CALL create_hf_ace_section(subsection)
134 246720 : CALL section_add_subsection(section, subsection)
135 246720 : CALL section_release(subsection)
136 :
137 246720 : END SUBROUTINE create_hfx_section
138 :
139 : ! **************************************************************************************************
140 : !> \brief !****f* input_cp2k_dft/create_hf_load_balance_section [1.0] *
141 : !>
142 : !> creates the input section for the hf potential part
143 : !> \param section the section to create
144 : !> \author Manuel Guidon
145 : ! **************************************************************************************************
146 246720 : SUBROUTINE create_hf_load_balance_section(section)
147 : TYPE(section_type), POINTER :: section
148 :
149 : TYPE(keyword_type), POINTER :: keyword
150 : TYPE(section_type), POINTER :: print_key
151 :
152 246720 : CPASSERT(.NOT. ASSOCIATED(section))
153 : CALL section_create(section, __LOCATION__, name="LOAD_BALANCE", &
154 : description="Parameters influencing the load balancing of the HF", &
155 : n_keywords=1, n_subsections=0, repeats=.FALSE., &
156 493440 : citations=[guidon2008])
157 :
158 246720 : NULLIFY (keyword)
159 : CALL keyword_create( &
160 : keyword, __LOCATION__, &
161 : name="NBINS", &
162 : description="Number of bins per process used to group atom quartets.", &
163 : usage="NBINS 32", &
164 246720 : default_i_val=64)
165 246720 : CALL section_add_keyword(section, keyword)
166 246720 : CALL keyword_release(keyword)
167 :
168 : CALL keyword_create( &
169 : keyword, __LOCATION__, &
170 : name="BLOCK_SIZE", &
171 : description="Determines the blocking used for the atomic quartet loops. "// &
172 : "A proper choice can speedup the calculation. The default (-1) is automatic.", &
173 : usage="BLOCK_SIZE 4", &
174 246720 : default_i_val=-1)
175 246720 : CALL section_add_keyword(section, keyword)
176 246720 : CALL keyword_release(keyword)
177 :
178 246720 : NULLIFY (keyword)
179 : CALL keyword_create( &
180 : keyword, __LOCATION__, &
181 : name="RANDOMIZE", &
182 : description="This flag controls the randomization of the bin assignment to processes. "// &
183 : "For highly ordered input structures with a bad load balance, setting "// &
184 : "this flag to TRUE might improve.", &
185 : usage="RANDOMIZE TRUE", &
186 246720 : default_l_val=.FALSE.)
187 246720 : CALL section_add_keyword(section, keyword)
188 246720 : CALL keyword_release(keyword)
189 :
190 246720 : NULLIFY (print_key)
191 : CALL cp_print_key_section_create(print_key, __LOCATION__, "PRINT", &
192 : description="Controls the printing of info about load balance", &
193 246720 : print_level=medium_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
194 246720 : CALL section_add_subsection(section, print_key)
195 :
196 246720 : CALL keyword_release(keyword)
197 : CALL keyword_create(keyword, __LOCATION__, &
198 : name="LOAD_BALANCE_INFO", &
199 : description="Activates the printing of load balance information ", &
200 : default_l_val=.FALSE., &
201 246720 : lone_keyword_l_val=.TRUE.)
202 246720 : CALL section_add_keyword(print_key, keyword)
203 246720 : CALL keyword_release(keyword)
204 246720 : CALL section_release(print_key)
205 :
206 246720 : END SUBROUTINE create_hf_load_balance_section
207 :
208 : ! **************************************************************************************************
209 : !> \brief !****f* input_cp2k_dft/create_hf_potential_section [1.0] *
210 : !>
211 : !> creates the input section for the hf potential part
212 : !> \param section the section to create
213 : !> \author Manuel Guidon
214 : ! **************************************************************************************************
215 246720 : SUBROUTINE create_hf_potential_section(section)
216 : TYPE(section_type), POINTER :: section
217 :
218 : TYPE(keyword_type), POINTER :: keyword
219 :
220 246720 : CPASSERT(.NOT. ASSOCIATED(section))
221 : CALL section_create(section, __LOCATION__, name="INTERACTION_POTENTIAL", &
222 : description="Defines the Coulomb, range-separated, mixed, or truncated interaction "// &
223 : "operator used for Hartree-Fock exchange.", &
224 : n_keywords=1, n_subsections=0, repeats=.FALSE., &
225 740160 : citations=[guidon2008, guidon2009])
226 :
227 246720 : NULLIFY (keyword)
228 : CALL keyword_create( &
229 : keyword, __LOCATION__, &
230 : name="POTENTIAL_TYPE", &
231 : description="Selects the interaction potential used for Hartree-Fock exchange. "// &
232 : "Periodic hybrid calculations commonly use a short-range, truncated, or mixed potential.", &
233 : usage="POTENTIAL_TYPE SHORTRANGE", &
234 : enum_c_vals=s2a("COULOMB", "SHORTRANGE", "LONGRANGE", "MIX_CL", "GAUSSIAN", &
235 : "MIX_LG", "IDENTITY", "TRUNCATED", "MIX_CL_TRUNC"), &
236 : enum_i_vals=[do_potential_coulomb, do_potential_short, do_potential_long, &
237 : do_potential_mix_cl, do_potential_gaussian, do_potential_mix_lg, &
238 : do_potential_id, do_potential_truncated, do_potential_mix_cl_trunc], &
239 : enum_desc=s2a("Coulomb potential: $\frac{1}{r}$", &
240 : "Shortrange potential: $\frac{\mathrm{erfc}(\omega \cdot r)}{r}$", &
241 : "Longrange potential: $\frac{\mathrm{erf}(\omega \cdot r)}{r}$", &
242 : "Mix coulomb and longrange potential: $\frac{1}{r} + \frac{\mathrm{erf}(\omega \cdot r)}{r}$", &
243 : "Damped Gaussian potential: $\exp{(-\omega^2 \cdot r^2)}$", &
244 : "Mix Gaussian and longrange potential: "// &
245 : "$\frac{\mathrm{erf}(\omega \cdot r)}{r} + \exp{(-\omega^2 \cdot r^2)}$", &
246 : "Overlap", &
247 : "Truncated coulomb potential: if (r < R_c) 1/r else 0", &
248 : "Truncated Mix coulomb and longrange potential, assumes/requires that the erf has fully decayed at R_c"), &
249 246720 : default_i_val=do_potential_coulomb)
250 246720 : CALL section_add_keyword(section, keyword)
251 246720 : CALL keyword_release(keyword)
252 :
253 246720 : NULLIFY (keyword)
254 : CALL keyword_create( &
255 : keyword, __LOCATION__, &
256 : name="OMEGA", &
257 : description="Parameter $\omega$ for short/longrange interaction", &
258 : usage="OMEGA 0.5", &
259 246720 : default_r_val=0.0_dp)
260 246720 : CALL section_add_keyword(section, keyword)
261 246720 : CALL keyword_release(keyword)
262 :
263 : CALL keyword_create(keyword, __LOCATION__, name="SCALE_COULOMB", &
264 : description="Scales Hartree-Fock contribution arising from a coulomb potential. "// &
265 : "Only valid when doing a mixed potential calculation", &
266 246720 : usage="SCALE_COULOMB 1.0", default_r_val=1.0_dp)
267 246720 : CALL section_add_keyword(section, keyword)
268 246720 : CALL keyword_release(keyword)
269 :
270 : CALL keyword_create(keyword, __LOCATION__, name="SCALE_LONGRANGE", &
271 : description="Scales Hartree-Fock contribution arising from a longrange potential. "// &
272 : "Only valid when doing a mixed potential calculation", &
273 246720 : usage="SCALE_LONGRANGE 1.0", default_r_val=1.0_dp)
274 246720 : CALL section_add_keyword(section, keyword)
275 246720 : CALL keyword_release(keyword)
276 :
277 : CALL keyword_create(keyword, __LOCATION__, name="SCALE_GAUSSIAN", &
278 : description="Scales Hartree-Fock contribution arising from a gaussian potential. "// &
279 : "Only valid when doing a mixed potential calculation", &
280 246720 : usage="SCALE_GAUSSIAN 1.0", default_r_val=1.0_dp)
281 246720 : CALL section_add_keyword(section, keyword)
282 246720 : CALL keyword_release(keyword)
283 :
284 : CALL keyword_create(keyword, __LOCATION__, name="CUTOFF_RADIUS", &
285 : description="Cutoff radius for the truncated $\frac{1}{r}$ potential or the short-range "// &
286 : "$\frac{\mathrm{erfc}(\omega \cdot r)}{r}$ potential. For truncated Coulomb in a "// &
287 : "periodic cell, choose a radius compatible with the cell dimensions. The default value "// &
288 : "for short-range potentials when this keyword is omitted is solved from "// &
289 : "$\frac{\mathrm{erfc}(\omega \cdot r)}{r} = \epsilon_{\mathrm{schwarz}}$ "// &
290 : "by Newton-Raphson method, with $\epsilon_{\mathrm{schwarz}}$ set by SCREENING/EPS_SCHWARZ", &
291 : usage="CUTOFF_RADIUS 10.0", type_of_var=real_t, & ! default_r_val=10.0_dp,&
292 246720 : unit_str="angstrom")
293 246720 : CALL section_add_keyword(section, keyword)
294 246720 : CALL keyword_release(keyword)
295 :
296 : CALL keyword_create( &
297 : keyword, __LOCATION__, &
298 : name="T_C_G_DATA", &
299 : description="Location of the file t_c_g.dat that contains the data for the "// &
300 : "evaluation of the truncated gamma function ", &
301 : usage="T_C_G_DATA /data/t_c_g.dat", &
302 246720 : default_c_val="t_c_g.dat")
303 246720 : CALL section_add_keyword(section, keyword)
304 246720 : CALL keyword_release(keyword)
305 :
306 246720 : END SUBROUTINE create_hf_potential_section
307 :
308 : !****f* input_cp2k_dft/create_hf_screening_section [1.0] *
309 :
310 : ! **************************************************************************************************
311 : !> \brief creates the input section for the hf screening part
312 : !> \param section the section to create
313 : !> \author Manuel Guidon
314 : ! **************************************************************************************************
315 246720 : SUBROUTINE create_hf_screening_section(section)
316 : TYPE(section_type), POINTER :: section
317 :
318 : TYPE(keyword_type), POINTER :: keyword
319 :
320 246720 : CPASSERT(.NOT. ASSOCIATED(section))
321 : CALL section_create(section, __LOCATION__, name="SCREENING", &
322 : description="Controls screening thresholds for Hartree-Fock exchange integrals.", &
323 : n_keywords=1, n_subsections=0, repeats=.FALSE., &
324 740160 : citations=[guidon2008, guidon2009])
325 :
326 246720 : NULLIFY (keyword)
327 : CALL keyword_create( &
328 : keyword, __LOCATION__, &
329 : name="EPS_SCHWARZ", &
330 : description="Schwarz inequality threshold for screening near-field electronic repulsion integrals. "// &
331 : "Tighter values reduce screening error but increase cost.", &
332 : usage="EPS_SCHWARZ 1.0E-6", &
333 246720 : default_r_val=1.0E-10_dp)
334 246720 : CALL section_add_keyword(section, keyword)
335 246720 : CALL keyword_release(keyword)
336 :
337 246720 : NULLIFY (keyword)
338 : CALL keyword_create( &
339 : keyword, __LOCATION__, &
340 : name="EPS_SCHWARZ_FORCES", &
341 : description="Schwarz threshold used for force-related electronic repulsion integrals. "// &
342 : "This is approximately the force accuracy and should normally be similar to EPS_SCF. "// &
343 : "Default value is 100*EPS_SCHWARZ.", &
344 : usage="EPS_SCHWARZ_FORCES 1.0E-5", &
345 246720 : default_r_val=1.0E-6_dp)
346 246720 : CALL section_add_keyword(section, keyword)
347 246720 : CALL keyword_release(keyword)
348 :
349 246720 : NULLIFY (keyword)
350 : CALL keyword_create( &
351 : keyword, __LOCATION__, &
352 : name="SCREEN_P_FORCES", &
353 : description="Screens the electronic repulsion integrals for the forces "// &
354 : "using the density matrix. Will be disabled for the "// &
355 : "response part of forces in MP2/RPA/TDDFT. "// &
356 : "This results in a significant speedup for large systems, "// &
357 : "but might require a somewhat tigher EPS_SCHWARZ_FORCES.", &
358 : usage="SCREEN_P_FORCES TRUE", &
359 246720 : default_l_val=.TRUE.)
360 246720 : CALL section_add_keyword(section, keyword)
361 246720 : CALL keyword_release(keyword)
362 :
363 246720 : NULLIFY (keyword)
364 : CALL keyword_create(keyword, __LOCATION__, name="SCREEN_ON_INITIAL_P", &
365 : description="Screen on an initial density matrix. For the first MD step"// &
366 : " this matrix must be provided by a Restart File.", &
367 246720 : usage="SCREEN_ON_INITIAL_P TRUE", default_l_val=.FALSE.)
368 246720 : CALL section_add_keyword(section, keyword)
369 246720 : CALL keyword_release(keyword)
370 :
371 246720 : NULLIFY (keyword)
372 : CALL keyword_create(keyword, __LOCATION__, name="P_SCREEN_CORRECTION_FACTOR", &
373 : description="Recalculates integrals on the fly if the actual density matrix is"// &
374 : " larger by a given factor than the initial one. If the factor is set"// &
375 : " to 0.0_dp, this feature is disabled.", &
376 246720 : usage="P_SCREEN_CORRECTION_FACTOR 0.0_dp", default_r_val=0.0_dp)
377 246720 : CALL section_add_keyword(section, keyword)
378 246720 : CALL keyword_release(keyword)
379 :
380 246720 : END SUBROUTINE create_hf_screening_section
381 :
382 : ! **************************************************************************************************
383 : !> \brief creates the input section for the hf-pbc part
384 : !> \param section the section to create
385 : !> \author Manuel Guidon
386 : ! **************************************************************************************************
387 246720 : SUBROUTINE create_hf_pbc_section(section)
388 : TYPE(section_type), POINTER :: section
389 :
390 : TYPE(keyword_type), POINTER :: keyword
391 :
392 246720 : CPASSERT(.NOT. ASSOCIATED(section))
393 : CALL section_create(section, __LOCATION__, name="PERIODIC", &
394 : description="Sets up periodic boundary condition parameters if requested ", &
395 : n_keywords=1, n_subsections=0, repeats=.FALSE., &
396 740160 : citations=[guidon2008, guidon2009])
397 246720 : NULLIFY (keyword)
398 : CALL keyword_create( &
399 : keyword, __LOCATION__, &
400 : name="NUMBER_OF_SHELLS", &
401 : description="Number of shells taken into account for periodicity. "// &
402 : "By default, cp2k tries to automatically evaluate this number. "// &
403 : "This algorithm might be to conservative, resulting in some overhead. "// &
404 : "You can try to adjust this number in order to make a calculation cheaper. ", &
405 : usage="NUMBER_OF_SHELLS 2", &
406 246720 : default_i_val=-1)
407 246720 : CALL section_add_keyword(section, keyword)
408 246720 : CALL keyword_release(keyword)
409 :
410 246720 : END SUBROUTINE create_hf_pbc_section
411 :
412 : ! **************************************************************************************************
413 : !> \brief creates the input section for the hf-memory part
414 : !> \param section the section to create
415 : !> \author Manuel Guidon
416 : ! **************************************************************************************************
417 246720 : SUBROUTINE create_hf_memory_section(section)
418 : TYPE(section_type), POINTER :: section
419 :
420 : TYPE(keyword_type), POINTER :: keyword
421 :
422 246720 : CPASSERT(.NOT. ASSOCIATED(section))
423 : CALL section_create(section, __LOCATION__, name="MEMORY", &
424 : description="Sets up memory parameters for the storage of the ERI's if requested ", &
425 : n_keywords=1, n_subsections=0, repeats=.FALSE., &
426 493440 : citations=[guidon2008])
427 246720 : NULLIFY (keyword)
428 : CALL keyword_create( &
429 : keyword, __LOCATION__, &
430 : name="EPS_STORAGE_SCALING", &
431 : variants=["EPS_STORAGE"], &
432 : description="Scaling factor to scale eps_schwarz. Storage threshold for compression "// &
433 : "will be EPS_SCHWARZ*EPS_STORAGE_SCALING.", &
434 : usage="EPS_STORAGE 1.0E-2", &
435 493440 : default_r_val=1.0E0_dp)
436 246720 : CALL section_add_keyword(section, keyword)
437 246720 : CALL keyword_release(keyword)
438 :
439 : CALL keyword_create( &
440 : keyword, __LOCATION__, &
441 : name="MAX_MEMORY", &
442 : description="Defines the maximum amount of memory [MiB] to be consumed by the full HFX module. "// &
443 : "All temporary buffers and helper arrays are subtracted from this number. "// &
444 : "What remains will be used for storage of integrals. NOTE: This number "// &
445 : "is assumed to represent the memory available to one MPI process. "// &
446 : "When running a threaded version, cp2k automatically takes care of "// &
447 : "distributing the memory among all the threads within a process.", &
448 : usage="MAX_MEMORY 256", &
449 246720 : default_i_val=512)
450 246720 : CALL section_add_keyword(section, keyword)
451 246720 : CALL keyword_release(keyword)
452 :
453 : CALL keyword_create( &
454 : keyword, __LOCATION__, &
455 : name="STORAGE_LOCATION", &
456 : description="Loaction where ERI's are stored if MAX_DISK_SPACE /=0 "// &
457 : "Expects a path to a directory. ", &
458 : usage="STORAGE_LOCATION /data/scratch", &
459 246720 : default_c_val=".")
460 246720 : CALL section_add_keyword(section, keyword)
461 246720 : CALL keyword_release(keyword)
462 :
463 : CALL keyword_create( &
464 : keyword, __LOCATION__, &
465 : name="MAX_DISK_SPACE", &
466 : description="Defines the maximum amount of disk space [MiB] used to store precomputed "// &
467 : "compressed four-center integrals. If 0, nothing is stored to disk", &
468 : usage="MAX_DISK_SPACE 256", &
469 246720 : default_i_val=0)
470 246720 : CALL section_add_keyword(section, keyword)
471 246720 : CALL keyword_release(keyword)
472 :
473 : CALL keyword_create(keyword, __LOCATION__, name="TREAT_FORCES_IN_CORE", &
474 : description="Determines whether the derivative ERI's should be stored to RAM or not. "// &
475 : "Only meaningful when performing Ehrenfest MD. "// &
476 : "Memory usage is defined via MAX_MEMORY, i.e. the memory is shared wit the energy ERI's.", &
477 246720 : usage="TREAT_FORCES_IN_CORE TRUE", default_l_val=.FALSE.)
478 246720 : CALL section_add_keyword(section, keyword)
479 246720 : CALL keyword_release(keyword)
480 :
481 246720 : END SUBROUTINE create_hf_memory_section
482 :
483 : ! **************************************************************************************************
484 : !> \brief ...
485 : !> \param section ...
486 : ! **************************************************************************************************
487 246720 : SUBROUTINE create_hf_ri_section(section)
488 : TYPE(section_type), POINTER :: section
489 :
490 : TYPE(keyword_type), POINTER :: keyword
491 : TYPE(section_type), POINTER :: print_key, subsection
492 :
493 246720 : NULLIFY (keyword, print_key, subsection)
494 :
495 246720 : CPASSERT(.NOT. ASSOCIATED(section))
496 : CALL section_create(section, __LOCATION__, name="RI", &
497 : description="Parameters for RI methods in HFX, including RI-HFXk with "// &
498 : "k-point sampling. All keywords relevant to RI-HFXk have an "// &
499 246720 : "alias starting with KP_")
500 :
501 : CALL keyword_create(keyword, __LOCATION__, name="_SECTION_PARAMETERS_", &
502 : description="controls the activation of RI", &
503 : usage="&RI T", &
504 : default_l_val=.FALSE., &
505 246720 : lone_keyword_l_val=.TRUE.)
506 246720 : CALL section_add_keyword(section, keyword)
507 246720 : CALL keyword_release(keyword)
508 :
509 : CALL keyword_create(keyword, __LOCATION__, name="EPS_FILTER", &
510 : description="Filter threshold for DBT tensor contraction.", &
511 : variants=["KP_EPS_FILTER"], &
512 493440 : default_r_val=1.0E-09_dp)
513 246720 : CALL section_add_keyword(section, keyword)
514 246720 : CALL keyword_release(keyword)
515 :
516 : CALL keyword_create(keyword, __LOCATION__, name="EPS_FILTER_2C", &
517 : description="Filter threshold for 2c integrals. Default should be kept.", &
518 246720 : default_r_val=1.0E-12_dp)
519 246720 : CALL section_add_keyword(section, keyword)
520 246720 : CALL keyword_release(keyword)
521 :
522 : CALL keyword_create(keyword, __LOCATION__, &
523 : name="EPS_STORAGE_SCALING", &
524 : description="Scaling factor to scale EPS_FILTER for storage of 3-center integrals. Storage threshold "// &
525 : "will be EPS_FILTER*EPS_STORAGE_SCALING.", &
526 246720 : default_r_val=0.01_dp)
527 246720 : CALL section_add_keyword(section, keyword)
528 246720 : CALL keyword_release(keyword)
529 :
530 : CALL keyword_create(keyword, __LOCATION__, name="EPS_FILTER_MO", &
531 : description="Filter threshold for contraction of 3-center integrals with MOs. "// &
532 : "Default should be kept.", &
533 246720 : default_r_val=1.0E-12_dp)
534 246720 : CALL section_add_keyword(section, keyword)
535 246720 : CALL keyword_release(keyword)
536 :
537 : CALL keyword_create(keyword, __LOCATION__, name="OMEGA", &
538 : description="The range parameter for the short range operator (in 1/a0). "// &
539 : "Default is OMEGA from INTERACTION_POTENTIAL. ", &
540 : variants=["KP_OMEGA"], &
541 : default_r_val=0.0_dp, &
542 493440 : repeats=.FALSE.)
543 246720 : CALL section_add_keyword(section, keyword)
544 246720 : CALL keyword_release(keyword)
545 :
546 : CALL keyword_create(keyword, __LOCATION__, name="CUTOFF_RADIUS", &
547 : description="The cutoff radius (in Angstroms) for the truncated Coulomb operator. "// &
548 : "Default is CUTOFF_RADIUS from INTERACTION_POTENTIAL. ", &
549 : variants=["KP_CUTOFF_RADIUS"], &
550 : default_r_val=0.0_dp, &
551 : repeats=.FALSE., &
552 493440 : unit_str="angstrom")
553 246720 : CALL section_add_keyword(section, keyword)
554 246720 : CALL keyword_release(keyword)
555 :
556 : CALL keyword_create(keyword, __LOCATION__, name="SCALE_COULOMB", &
557 : description="Scales Hartree-Fock contribution arising from a coulomb potential. "// &
558 : "Only valid when doing a mixed potential calculation. "// &
559 : "Default is SCALE_COULOMB from INTERACTION_POTENTIAL", &
560 246720 : usage="SCALE_COULOMB 1.0", default_r_val=1.0_dp)
561 246720 : CALL section_add_keyword(section, keyword)
562 246720 : CALL keyword_release(keyword)
563 :
564 : CALL keyword_create(keyword, __LOCATION__, name="SCALE_LONGRANGE", &
565 : description="Scales Hartree-Fock contribution arising from a longrange potential. "// &
566 : "Only valid when doing a mixed potential calculation. "// &
567 : "Default if SCALE_LONGRANGE from INTERACTION_POTENTIAL", &
568 246720 : usage="SCALE_LONGRANGE 1.0", default_r_val=1.0_dp)
569 246720 : CALL section_add_keyword(section, keyword)
570 246720 : CALL keyword_release(keyword)
571 :
572 : CALL keyword_create(keyword, __LOCATION__, name="KP_NGROUPS", &
573 : description="The number of MPI subgroup that work in parallel during the SCF. "// &
574 : "The default value is 1. Using N subgroups should speed up the "// &
575 : "calculation by a factor ~N, at the cost of N times more memory usage.", &
576 : variants=["NGROUPS"], &
577 : usage="KP_NGROUPS {int}", &
578 : repeats=.FALSE., &
579 493440 : default_i_val=1)
580 246720 : CALL section_add_keyword(section, keyword)
581 246720 : CALL keyword_release(keyword)
582 :
583 : CALL keyword_create(keyword, __LOCATION__, name="KP_USE_DELTA_P", &
584 : description="This kweyword controls whether the KS matrix at each SCF cycle "// &
585 : "is built by adding the contribution of the denisty difference (wrt to previous step) "// &
586 : "to the KS matrix of the previous step. As the SCF converges, the density fluctuations "// &
587 : "get smaller and sparsity increases, leading to faster SCF steps. Not always "// &
588 : "numerically stable => turn off if SCF struggles to converge.", &
589 : variants=s2a("USE_DELTA_P", "KP_USE_P_DIFF", "USE_P_DIFF"), &
590 : usage="KP_USE_DELTA_P {logical}", &
591 : repeats=.FALSE., &
592 246720 : default_l_val=.TRUE.)
593 246720 : CALL section_add_keyword(section, keyword)
594 246720 : CALL keyword_release(keyword)
595 :
596 : CALL keyword_create(keyword, __LOCATION__, name="KP_STACK_SIZE", &
597 : description="When doing contraction over periodic cells of the type: "// &
598 : "T_mu^a,nu^b,P^c = (mu^a nu^b | Q^d) * (Q^d | P^c), with "// &
599 : "a,b,c,d labeling cells, there are in principle Ncells "// &
600 : "contractions taking place. Because a smaller number of "// &
601 : "contractions involving larger tensors is more efficient, "// &
602 : "the tensors can be stacked along the d direction. STCK_SIZE "// &
603 : "controls the size of this stack. Larger stacks are more efficient, "// &
604 : "but required more memory.", &
605 : variants=["STACK_SIZE"], &
606 : usage="KP_STACK_SIZE {int}", &
607 : repeats=.FALSE., &
608 493440 : default_i_val=16)
609 246720 : CALL section_add_keyword(section, keyword)
610 246720 : CALL keyword_release(keyword)
611 :
612 : CALL keyword_create(keyword, __LOCATION__, name="KP_RI_BUMP_FACTOR", &
613 : variants=s2a("RI_BUMP", "BUMP", "BUMP_FACTOR"), &
614 : description="In KP-RI-HFX, the extended RI basis set has a bump radius. "// &
615 : "All basis elements within that radius contribute with full weight. "// &
616 : "All basis elements beyond that radius have decaying weight, from "// &
617 : "1 at the bump radius, to zero at the RI extension radius. The "// &
618 : "bump radius is calculated as a fraction of the RI extension radius: "// &
619 : "bump radius = KP_RI_NUMP_FACTOR * RI extension radius", &
620 : default_r_val=0.85_dp, &
621 246720 : repeats=.FALSE.)
622 246720 : CALL section_add_keyword(section, keyword)
623 246720 : CALL keyword_release(keyword)
624 :
625 : CALL keyword_create(keyword, __LOCATION__, name="RI_METRIC", &
626 : description="The type of RI operator. "// &
627 : "Default is POTENTIAL_TYPE from INTERACTION_POTENTIAL. "// &
628 : "The standard "// &
629 : "Coulomb operator cannot be used in periodic systems.", &
630 : usage="RI_METRIC {string}", &
631 : repeats=.FALSE., &
632 : variants=["KP_RI_METRIC"], &
633 : default_i_val=0, &
634 : enum_c_vals=s2a("HFX", "COULOMB", "IDENTITY", "TRUNCATED", "SHORTRANGE"), &
635 : enum_desc=s2a("Same as HFX operator", &
636 : "Standard Coulomb operator: 1/r", &
637 : "Overlap", &
638 : "Truncated Coulomb operator: 1/r if (r<R_c), 0 otherwise ", &
639 : "Short range: erfc(omega*r)/r"), &
640 : enum_i_vals=[0, do_potential_coulomb, do_potential_id, do_potential_truncated, &
641 493440 : do_potential_short])
642 246720 : CALL section_add_keyword(section, keyword)
643 246720 : CALL keyword_release(keyword)
644 :
645 : CALL keyword_create(keyword, __LOCATION__, name="2C_MATRIX_FUNCTIONS", &
646 : description="Methods for matrix inverse and matrix square root.", &
647 : default_i_val=hfx_ri_do_2c_cholesky, &
648 : enum_c_vals=s2a("DIAG", "CHOLESKY", "ITER"), &
649 : enum_desc=s2a("Diagonalization with eigenvalue quenching: stable", &
650 : "Cholesky: not stable in case of ill-conditioned RI basis", &
651 : "Iterative algorithms: linear scaling "// &
652 : "Hotelling's method for inverse and Newton-Schulz iteration for matrix square root"), &
653 246720 : enum_i_vals=[hfx_ri_do_2c_diag, hfx_ri_do_2c_cholesky, hfx_ri_do_2c_iter])
654 246720 : CALL section_add_keyword(section, keyword)
655 246720 : CALL keyword_release(keyword)
656 :
657 : CALL keyword_create(keyword, __LOCATION__, name="EPS_EIGVAL", &
658 : description="Throw away linear combinations of RI basis functions with a small eigenvalue, "// &
659 : "this is applied only if 2C_MATRIX_FUNCTIONS DIAG", &
660 246720 : default_r_val=1.0e-7_dp)
661 246720 : CALL section_add_keyword(section, keyword)
662 246720 : CALL keyword_release(keyword)
663 :
664 : CALL keyword_create(keyword, __LOCATION__, name="CHECK_2C_MATRIX", &
665 : description="Report accuracy for the inverse/sqrt of the 2-center integral matrix.", &
666 246720 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
667 246720 : CALL section_add_keyword(section, keyword)
668 246720 : CALL keyword_release(keyword)
669 :
670 : CALL keyword_create( &
671 : keyword, __LOCATION__, &
672 : name="CALC_COND_NUM", &
673 : variants=["CALC_CONDITION_NUMBER"], &
674 : description="Calculate the condition number of integral matrices.", &
675 : usage="CALC_COND_NUM", &
676 : default_l_val=.FALSE., &
677 493440 : lone_keyword_l_val=.TRUE.)
678 246720 : CALL section_add_keyword(section, keyword)
679 246720 : CALL keyword_release(keyword)
680 :
681 : CALL keyword_create(keyword, __LOCATION__, name="SQRT_ORDER", &
682 : description="Order of the iteration method for the calculation of "// &
683 : "the sqrt of 2-center integral matrix.", &
684 246720 : default_i_val=3)
685 246720 : CALL section_add_keyword(section, keyword)
686 246720 : CALL keyword_release(keyword)
687 :
688 : CALL keyword_create(keyword, __LOCATION__, name="EPS_LANCZOS", &
689 : description="Threshold used for lanczos estimates.", &
690 246720 : default_r_val=1.0E-3_dp)
691 246720 : CALL section_add_keyword(section, keyword)
692 246720 : CALL keyword_release(keyword)
693 :
694 : CALL keyword_create(keyword, __LOCATION__, name="EPS_PGF_ORB", &
695 : description="Sets precision of the integral tensors.", &
696 : variants=["KP_EPS_PGF_ORB"], &
697 493440 : default_r_val=1.0E-5_dp)
698 246720 : CALL section_add_keyword(section, keyword)
699 246720 : CALL keyword_release(keyword)
700 :
701 : CALL keyword_create(keyword, __LOCATION__, name="MAX_ITER_LANCZOS", &
702 : description="Maximum number of lanczos iterations.", &
703 246720 : usage="MAX_ITER_LANCZOS ", default_i_val=500)
704 246720 : CALL section_add_keyword(section, keyword)
705 246720 : CALL keyword_release(keyword)
706 :
707 : CALL keyword_create(keyword, __LOCATION__, name="RI_FLAVOR", &
708 : description="Flavor of RI: how to contract 3-center integrals", &
709 : enum_c_vals=s2a("MO", "RHO"), &
710 : enum_desc=s2a("with MO coefficients", "with density matrix"), &
711 : enum_i_vals=[ri_mo, ri_pmat], &
712 246720 : default_i_val=ri_pmat)
713 246720 : CALL section_add_keyword(section, keyword)
714 246720 : CALL keyword_release(keyword)
715 :
716 : CALL keyword_create(keyword, __LOCATION__, name="MIN_BLOCK_SIZE", &
717 : description="Minimum tensor block size.", &
718 246720 : default_i_val=4)
719 246720 : CALL section_add_keyword(section, keyword)
720 246720 : CALL keyword_release(keyword)
721 :
722 : CALL keyword_create(keyword, __LOCATION__, name="MAX_BLOCK_SIZE_MO", &
723 : description="Maximum tensor block size for MOs.", &
724 246720 : default_i_val=64)
725 246720 : CALL section_add_keyword(section, keyword)
726 246720 : CALL keyword_release(keyword)
727 :
728 : CALL keyword_create(keyword, __LOCATION__, name="MEMORY_CUT", &
729 : description="Memory reduction factor. This keyword controls the batching of tensor "// &
730 : "contractions into smaller, more manageable chunks. The details vary "// &
731 : "depending on the RI_FLAVOR.", &
732 246720 : default_i_val=3)
733 246720 : CALL section_add_keyword(section, keyword)
734 246720 : CALL keyword_release(keyword)
735 :
736 : CALL keyword_create(keyword, __LOCATION__, name="FLAVOR_SWITCH_MEMORY_CUT", &
737 : description="Memory reduction factor to be applied upon RI_FLAVOR switching "// &
738 : "from MO to RHO. The RHO flavor typically requires more memory, "// &
739 : "and depending on the ressources available, a higher MEMORY_CUT.", &
740 246720 : default_i_val=3)
741 246720 : CALL section_add_keyword(section, keyword)
742 246720 : CALL keyword_release(keyword)
743 :
744 : CALL section_create(subsection, __LOCATION__, name="PRINT", &
745 : description="Section of possible print options in the RI-HFX code.", &
746 246720 : n_keywords=0, n_subsections=1, repeats=.FALSE.)
747 :
748 : CALL keyword_create(keyword, __LOCATION__, name="KP_RI_PROGRESS_BAR", &
749 : variants=s2a("PROGRESS_BAR", "PROGRESS", "KP_PROGRESS", "KP_PROGRESS_BAR"), &
750 : description="Whether a progress bar for individual SCF steps should be printed. "// &
751 : "In RI-HFXk, an expensive triple loop runs over periodic images and "// &
752 : "atomic pairs. This printing option tracks the progress of this loop "// &
753 : "in real time. Note that some work also takes place before the loop "// &
754 : "starts, and the time spent doing it depends on the value of "// &
755 : "KP_STACK_SIZE (larger = faster, but more memory used).", &
756 246720 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
757 246720 : CALL section_add_keyword(subsection, keyword)
758 246720 : CALL keyword_release(keyword)
759 :
760 : !TODO: add a incentive to restart from GGA calculation? Test that it improves things
761 : CALL keyword_create(keyword, __LOCATION__, name="KP_RI_MEMORY_ESTIMATE", &
762 : variants=s2a("MEMORY_ESTIMATE"), &
763 : description="Calculate and print a rough upper bound estimate of the memory "// &
764 : "required to run a RI-HFXk ENERGY calculation. Note that a fair "// &
765 : "amount of computing must take place before this estimate can be "// &
766 : "produced. If the calculation runs out of memory beforehand, "// &
767 : "use more resources, or change the value of memory related keywords "// &
768 : "(e.g. KP_NGROUPS, interaction potential parameters, KP_STACK_SIZE). "// &
769 : "The estimate is more accurate when restarting from a (GGA) wavefunction. "// &
770 : "Calculations involving forces will require more memory than this estimate.", &
771 246720 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
772 246720 : CALL section_add_keyword(subsection, keyword)
773 246720 : CALL keyword_release(keyword)
774 :
775 : CALL cp_print_key_section_create(print_key, __LOCATION__, "RI_INFO", &
776 : description="Controls the printing of DBCSR tensor log in RI HFX.", &
777 246720 : print_level=high_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
778 246720 : CALL section_add_subsection(subsection, print_key)
779 246720 : CALL section_release(print_key)
780 :
781 : CALL cp_print_key_section_create(print_key, __LOCATION__, "RI_DENSITY_COEFFS", &
782 : description="Controls the printing of the projection of the elecontric "// &
783 : "density on the RI_HFX basis. n(r) = sum_s c_s*phi_RI_s(r), "// &
784 : "where c_s = sum_pqr P_pq (pq|r) (r|s)^-1 and | is the RI_METRIC", &
785 : print_level=high_print_level, filename="RI_DENSITY_COEFFS", &
786 246720 : common_iter_levels=3)
787 :
788 : CALL keyword_create(keyword, __LOCATION__, name="MULTIPLY_BY_RI_2C_INTEGRALS", &
789 : variants=s2a("MULT_BY_RI", "MULT_BY_S", "MULT_BY_RI_INTS"), &
790 : description="Whether the RI density coefficients to be printed should "// &
791 : "be pre-multiplied by the RI_METRIC 2c-integrals: (r|s)*C_s. "// &
792 : "Not compatible with the SKIP_RI_METRIC keyword.", &
793 246720 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
794 246720 : CALL section_add_keyword(print_key, keyword)
795 246720 : CALL keyword_release(keyword)
796 :
797 : CALL keyword_create(keyword, __LOCATION__, name="SKIP_RI_METRIC", &
798 : variants=s2a("SKIP_INVERSE", "SKIP_2C_INTS", "SKIP_2C_INTEGRALS"), &
799 : description="Skip the calculation, inversion, and contraction of the 2-center RI "// &
800 : "metric integrals. The printed coefficients are only the contraction of the "// &
801 : "density matrix with the 3-center integrals, i.e. c_r = sum_pq P_pq (pq|r) "// &
802 : "Allows for memory savings when printing the RI density coefficients.", &
803 246720 : default_l_val=.FALSE., lone_keyword_l_val=.TRUE.)
804 246720 : CALL section_add_keyword(print_key, keyword)
805 246720 : CALL keyword_release(keyword)
806 :
807 : CALL keyword_create(keyword, __LOCATION__, name="FILE_FORMAT", &
808 : description="Format of file containing density fitting coefficients: "// &
809 : "BASIC(default)-original format; EXTENDED-format with basis set info.", &
810 246720 : default_c_val="BASIC")
811 246720 : CALL section_add_keyword(print_key, keyword)
812 246720 : CALL keyword_release(keyword)
813 :
814 246720 : CALL section_add_subsection(subsection, print_key)
815 246720 : CALL section_release(print_key)
816 :
817 : CALL cp_print_key_section_create(print_key, __LOCATION__, "RI_METRIC_2C_INTS", &
818 : description="Controls the printing of RI 2-center integrals for the "// &
819 : "HFX potential.", &
820 : print_level=high_print_level, filename="RI_2C_INTS", &
821 246720 : common_iter_levels=3)
822 246720 : CALL section_add_subsection(subsection, print_key)
823 246720 : CALL section_release(print_key)
824 :
825 246720 : CALL section_add_subsection(section, subsection)
826 246720 : CALL section_release(subsection)
827 :
828 246720 : END SUBROUTINE create_hf_ri_section
829 :
830 : ! ACE Keyword section
831 :
832 246720 : SUBROUTINE create_hf_ace_section(section)
833 : TYPE(section_type), POINTER :: section
834 :
835 : TYPE(keyword_type), POINTER :: keyword
836 :
837 246720 : CPASSERT(.NOT. ASSOCIATED(section))
838 : CALL section_create(section, __LOCATION__, &
839 : name="ACE", &
840 : description="Parameters for the Adaptively Compressed Exchange (ACE) "// &
841 : "operator. ACE replaces the full exchange matrix with a "// &
842 : "low-rank projector K_ACE = -W*W^T after an initial "// &
843 : "full HFX build, reducing cost of subsequent SCF steps. "// &
844 : "NOTE: ACE requires diagonalization-based SCF. "// &
845 : "It is incompatible with orbital transformation (OT) methods "// &
846 : "because OT does not construct MO coefficients.", &
847 : n_keywords=2, &
848 : n_subsections=0, &
849 : repeats=.FALSE., &
850 493440 : citations=[Lin2016ACE])
851 :
852 246720 : NULLIFY (keyword)
853 :
854 : ! --- ACTIVE ---
855 : CALL keyword_create(keyword, __LOCATION__, &
856 : name="ACTIVE", &
857 : description="Enable the ACE approximation for HFX. "// &
858 : "When .TRUE., the exchange matrix is replaced by "// &
859 : "the ACE projector after the first full build.", &
860 : usage="ACTIVE .TRUE.", &
861 : default_l_val=.FALSE., &
862 246720 : lone_keyword_l_val=.TRUE.)
863 246720 : CALL section_add_keyword(section, keyword)
864 246720 : CALL keyword_release(keyword)
865 :
866 : ! --- REBUILD_FREQUENCY ---
867 : CALL keyword_create(keyword, __LOCATION__, &
868 : name="REBUILD_FREQUENCY", &
869 : description="Rebuild the ACE projectors W every N SCF steps. "// &
870 : "N=1 means rebuild every step (identical to full HFX, "// &
871 : "use for testing only). N=10-20 is typical for production. "// &
872 : "Projectors are always rebuilt when the structure changes.", &
873 : usage="REBUILD_FREQUENCY 20", &
874 246720 : default_i_val=20)
875 246720 : CALL section_add_keyword(section, keyword)
876 246720 : CALL keyword_release(keyword)
877 :
878 246720 : END SUBROUTINE create_hf_ace_section
879 :
880 : END MODULE input_cp2k_hfx
|