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 the FORCE_EVAL section of cp2k
10 : !> \par History
11 : !> 06.2004 created [fawzi]
12 : !> \author fawzi
13 : ! **************************************************************************************************
14 : MODULE input_cp2k_force_eval
15 : USE cp_output_handling, ONLY: add_last_numeric,&
16 : cp_print_key_section_create,&
17 : debug_print_level,&
18 : high_print_level,&
19 : low_print_level,&
20 : medium_print_level
21 : USE cp_units, ONLY: cp_unit_to_cp2k
22 : USE generic_function_input, ONLY: create_function_section
23 : USE input_constants, ONLY: &
24 : do_eip, do_embed, do_fist, do_ipi, do_mixed, do_nnp, do_qmmm, do_qs, do_sirius, &
25 : do_stress_analytical, do_stress_diagonal_anal, do_stress_diagonal_numer, do_stress_none, &
26 : do_stress_numerical, numerical
27 : USE input_cp2k_dft, ONLY: create_bsse_section,&
28 : create_dft_section
29 : USE input_cp2k_eip, ONLY: create_eip_section
30 : USE input_cp2k_embed, ONLY: create_embed_section
31 : USE input_cp2k_mixed, ONLY: create_mix_section
32 : USE input_cp2k_mm, ONLY: create_mm_section
33 : USE input_cp2k_nnp, ONLY: create_nnp_section
34 : USE input_cp2k_properties_dft, ONLY: create_properties_section
35 : USE input_cp2k_pwdft, ONLY: create_pwdft_section
36 : USE input_cp2k_qmmm, ONLY: create_qmmm_section
37 : USE input_cp2k_subsys, ONLY: create_subsys_section
38 : USE input_keyword_types, ONLY: keyword_create,&
39 : keyword_release,&
40 : keyword_type
41 : USE input_section_types, ONLY: section_add_keyword,&
42 : section_add_subsection,&
43 : section_create,&
44 : section_release,&
45 : section_type
46 : USE input_val_types, ONLY: integer_t
47 : USE kinds, ONLY: dp
48 : USE string_utilities, ONLY: s2a
49 : #include "./base/base_uses.f90"
50 :
51 : IMPLICIT NONE
52 : PRIVATE
53 :
54 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
55 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_force_eval'
56 :
57 : PUBLIC :: create_force_eval_section
58 :
59 : CONTAINS
60 :
61 : ! **************************************************************************************************
62 : !> \brief creates the force_eval section
63 : !> \param section the section to be created
64 : !> \author fawzi
65 : ! **************************************************************************************************
66 1462 : SUBROUTINE create_force_eval_section(section)
67 : TYPE(section_type), POINTER :: section
68 :
69 : TYPE(keyword_type), POINTER :: keyword
70 : TYPE(section_type), POINTER :: subsection
71 :
72 1462 : CPASSERT(.NOT. ASSOCIATED(section))
73 : CALL section_create(section, __LOCATION__, name="force_eval", &
74 : description="parameters needed to calculate energy and forces and"// &
75 : " describe the system you want to analyze.", &
76 1462 : n_keywords=1, n_subsections=10, repeats=.TRUE.)
77 :
78 1462 : NULLIFY (subsection)
79 1462 : NULLIFY (keyword)
80 : CALL keyword_create(keyword, __LOCATION__, name="METHOD", &
81 : description="Selects the method used by this FORCE_EVAL section to compute energies, "// &
82 : "forces, and related properties.", &
83 : usage="METHOD <STRING>", &
84 : enum_c_vals=s2a("QS", &
85 : "SIRIUS", &
86 : "FIST", &
87 : "QMMM", &
88 : "EIP", &
89 : "QUICKSTEP", &
90 : "NNP", &
91 : "MIXED", &
92 : "EMBED", &
93 : "IPI"), &
94 : enum_desc=s2a("Alias for QUICKSTEP", &
95 : "PW DFT using the SIRIUS library", &
96 : "Molecular Mechanics", &
97 : "Hybrid quantum classical", &
98 : "Empirical Interatomic Potential", &
99 : "Electronic structure methods in the Quickstep module, including GPW and GAPW DFT.", &
100 : "Neural Network Potentials", &
101 : "Use a combination of two of the above", &
102 : "Perform an embedded calculation", &
103 : "Receive forces from an i-PI client"), &
104 : enum_i_vals=[do_qs, do_sirius, do_fist, do_qmmm, do_eip, do_qs, do_nnp, do_mixed, do_embed, do_ipi], &
105 1462 : default_i_val=do_qs)
106 1462 : CALL section_add_keyword(section, keyword)
107 1462 : CALL keyword_release(keyword)
108 :
109 : CALL keyword_create(keyword, __LOCATION__, name="STRESS_TENSOR", &
110 : description="Controls the calculation of the stress tensor. The combinations defined below"// &
111 : " are not implemented for all methods.", &
112 : usage="stress_tensor (NONE|ANALYTICAL|NUMERICAL|DIAGONAL_ANA|DIAGONAL_NUM)", &
113 : default_i_val=do_stress_none, &
114 : enum_c_vals=s2a("NONE", "ANALYTICAL", "NUMERICAL", "DIAGONAL_ANALYTICAL", "DIAGONAL_NUMERICAL"), &
115 : enum_i_vals=[do_stress_none, do_stress_analytical, do_stress_numerical, &
116 : do_stress_diagonal_anal, do_stress_diagonal_numer], &
117 : enum_desc=s2a("Do not compute stress tensor", &
118 : "Compute the stress tensor analytically (if available).", &
119 : "Compute the stress tensor numerically.", &
120 : "Compute the diagonal part only of the stress tensor analytically (if available).", &
121 1462 : "Compute the diagonal part only of the stress tensor numerically"))
122 :
123 1462 : CALL section_add_keyword(section, keyword)
124 1462 : CALL keyword_release(keyword)
125 :
126 : ! Create FORCE_EVAL/EXTERNAL_POTENTIAL section, corresponding to add_external_potential in
127 : ! external_potential_methods.F and applicable to any force method. A private subroutine
128 : ! create_ext_pot_section was previously used for this purpose, which has been dropped to
129 : ! avoid confusion with the similarly named one in input_cp2k_external.F for
130 : ! FORCE_EVAL/DFT/EXTERNAL_POTENTIAL and applicable to Quickstep DFT only.
131 : CALL create_function_section(subsection, "EXTERNAL_POTENTIAL", "FUNCTION", &
132 : description="Section controlling the presence of an external "// &
133 : "potential dependent on the atomic positions (X,Y,Z). Not to "// &
134 : "be confused with the Quickstep DFT-specific settings under "// &
135 : "FORCE_EVAL/DFT/EXTERNAL_POTENTIAL.", &
136 5848 : repeats=.TRUE., do_deriv=.TRUE., input_variables=["X", "Y", "Z"])
137 : CALL keyword_create(keyword, __LOCATION__, name="ATOMS_LIST", &
138 : description="Specifies the atoms on which the external potential will act", &
139 : usage="ATOMS_LIST {INT} {INT} ..", repeats=.TRUE., &
140 1462 : n_var=-1, type_of_var=integer_t)
141 1462 : CALL section_add_keyword(subsection, keyword)
142 1462 : CALL keyword_release(keyword)
143 1462 : CALL section_add_subsection(section, subsection)
144 1462 : CALL section_release(subsection)
145 :
146 1462 : CALL create_rescale_force_section(subsection)
147 1462 : CALL section_add_subsection(section, subsection)
148 1462 : CALL section_release(subsection)
149 :
150 1462 : CALL create_mix_section(subsection)
151 1462 : CALL section_add_subsection(section, subsection)
152 1462 : CALL section_release(subsection)
153 :
154 1462 : CALL create_embed_section(subsection)
155 1462 : CALL section_add_subsection(section, subsection)
156 1462 : CALL section_release(subsection)
157 :
158 1462 : CALL create_dft_section(subsection)
159 1462 : CALL section_add_subsection(section, subsection)
160 1462 : CALL section_release(subsection)
161 :
162 1462 : CALL create_pwdft_section(subsection)
163 1462 : CALL section_add_subsection(section, subsection)
164 1462 : CALL section_release(subsection)
165 :
166 1462 : CALL create_mm_section(subsection)
167 1462 : CALL section_add_subsection(section, subsection)
168 1462 : CALL section_release(subsection)
169 :
170 1462 : CALL create_nnp_section(subsection)
171 1462 : CALL section_add_subsection(section, subsection)
172 1462 : CALL section_release(subsection)
173 :
174 1462 : CALL create_qmmm_section(subsection)
175 1462 : CALL section_add_subsection(section, subsection)
176 1462 : CALL section_release(subsection)
177 :
178 1462 : CALL create_eip_section(subsection)
179 1462 : CALL section_add_subsection(section, subsection)
180 1462 : CALL section_release(subsection)
181 :
182 1462 : CALL create_bsse_section(subsection)
183 1462 : CALL section_add_subsection(section, subsection)
184 1462 : CALL section_release(subsection)
185 :
186 1462 : CALL create_subsys_section(subsection)
187 1462 : CALL section_add_subsection(section, subsection)
188 1462 : CALL section_release(subsection)
189 :
190 1462 : CALL create_properties_section(subsection)
191 1462 : CALL section_add_subsection(section, subsection)
192 1462 : CALL section_release(subsection)
193 :
194 1462 : CALL create_f_env_print_section(subsection)
195 1462 : CALL section_add_subsection(section, subsection)
196 1462 : CALL section_release(subsection)
197 :
198 1462 : END SUBROUTINE create_force_eval_section
199 :
200 : ! **************************************************************************************************
201 : !> \brief Creates the section controlling the rescaling of forces
202 : !> \param section the section to create
203 : !> \author teo
204 : ! **************************************************************************************************
205 1462 : SUBROUTINE create_rescale_force_section(section)
206 : TYPE(section_type), POINTER :: section
207 :
208 : TYPE(keyword_type), POINTER :: keyword
209 :
210 1462 : CPASSERT(.NOT. ASSOCIATED(section))
211 : CALL section_create(section, __LOCATION__, name="RESCALE_FORCES", &
212 : description="Section controlling the rescaling of forces. Useful when"// &
213 : " starting from quite bad geometries with unphysically large forces.", &
214 1462 : n_keywords=1, n_subsections=0, repeats=.FALSE.)
215 1462 : NULLIFY (keyword)
216 :
217 : CALL keyword_create(keyword, __LOCATION__, name="MAX_FORCE", &
218 : description="Specify the Maximum Values of the force. If the force"// &
219 : " of one atom exceed this value it's rescaled to the MAX_FORCE"// &
220 : " value.", &
221 : default_r_val=cp_unit_to_cp2k(value=50.0_dp, &
222 : unit_str="kcalmol*angstrom^-1"), &
223 1462 : unit_str="hartree*bohr^-1")
224 1462 : CALL section_add_keyword(section, keyword)
225 1462 : CALL keyword_release(keyword)
226 :
227 1462 : END SUBROUTINE create_rescale_force_section
228 :
229 : ! **************************************************************************************************
230 : !> \brief ...
231 : !> \param section ...
232 : !> \author fawzi
233 : ! **************************************************************************************************
234 1462 : SUBROUTINE create_f_env_print_section(section)
235 : TYPE(section_type), POINTER :: section
236 :
237 : TYPE(keyword_type), POINTER :: keyword
238 : TYPE(section_type), POINTER :: print_key
239 :
240 1462 : NULLIFY (keyword)
241 1462 : NULLIFY (print_key)
242 :
243 1462 : CPASSERT(.NOT. ASSOCIATED(section))
244 :
245 : CALL section_create(section, __LOCATION__, &
246 : name="PRINT", &
247 : description="Properties that you want to output and that are common to all methods", &
248 1462 : n_keywords=0, n_subsections=10, repeats=.FALSE.)
249 :
250 : CALL cp_print_key_section_create(print_key, __LOCATION__, &
251 : name="PROGRAM_RUN_INFO", &
252 : description="Controls the printing of basic information generated by FORCE_EVAL", &
253 1462 : print_level=low_print_level, add_last=add_last_numeric, filename="__STD_OUT__")
254 : CALL keyword_create(keyword, __LOCATION__, &
255 : name="ENERGY_UNIT", &
256 : description="Specifies the physical unit used for the printing of the total energy. "// &
257 : "Note that the meaningfulness of the unit is not checked.", &
258 : usage="ENERGY_UNIT eV", &
259 : default_c_val="hartree", &
260 1462 : repeats=.FALSE.)
261 1462 : CALL section_add_keyword(print_key, keyword)
262 1462 : CALL keyword_release(keyword)
263 1462 : CALL section_add_subsection(section, print_key)
264 1462 : CALL section_release(print_key)
265 :
266 : CALL cp_print_key_section_create(print_key, __LOCATION__, &
267 : name="FORCES", &
268 : description="Controls the printing of the forces after each force evaluation", &
269 1462 : print_level=high_print_level, filename="__STD_OUT__")
270 : CALL keyword_create(keyword, __LOCATION__, &
271 : name="NDIGITS", &
272 : description="Specifies the number of digits used "// &
273 : "for the printing of the forces", &
274 : usage="NDIGITS 6", &
275 : default_i_val=8, &
276 1462 : repeats=.FALSE.)
277 1462 : CALL section_add_keyword(print_key, keyword)
278 1462 : CALL keyword_release(keyword)
279 : CALL keyword_create(keyword, __LOCATION__, &
280 : name="FORCE_UNIT", &
281 : variants=["UNIT"], & ! add old keyword name for backward compatibility
282 : description="Specifies the physical unit used for the printing of the forces. "// &
283 : "Note that the meaningfulness of the unit is not checked.", &
284 : usage="FORCE_UNIT eV/angstrom", &
285 : default_c_val="hartree/bohr", &
286 2924 : repeats=.FALSE.)
287 1462 : CALL section_add_keyword(print_key, keyword)
288 1462 : CALL keyword_release(keyword)
289 1462 : CALL section_add_subsection(section, print_key)
290 1462 : CALL section_release(print_key)
291 :
292 : CALL cp_print_key_section_create(print_key, __LOCATION__, &
293 : name="GRID_INFORMATION", &
294 : description="Controls the printing of information regarding the PW and RS grid structures.", &
295 1462 : print_level=medium_print_level, filename="__STD_OUT__")
296 1462 : CALL section_add_subsection(section, print_key)
297 1462 : CALL section_release(print_key)
298 :
299 : CALL cp_print_key_section_create(print_key, __LOCATION__, &
300 : name="TOTAL_NUMBERS", &
301 : description="Controls the printing of the total number of atoms, kinds, ...", &
302 1462 : print_level=low_print_level, filename="__STD_OUT__")
303 1462 : CALL section_add_subsection(section, print_key)
304 1462 : CALL section_release(print_key)
305 :
306 : CALL cp_print_key_section_create(print_key, __LOCATION__, &
307 : name="DISTRIBUTION", &
308 : description="Controls the printing of the distribution of molecules, atoms, ...", &
309 1462 : print_level=high_print_level, filename="__STD_OUT__")
310 1462 : CALL section_add_subsection(section, print_key)
311 1462 : CALL section_release(print_key)
312 :
313 : CALL cp_print_key_section_create(print_key, __LOCATION__, &
314 : name="DISTRIBUTION2D", &
315 : description="Controls the printing of the distribution of matrix blocks, ...", &
316 1462 : print_level=high_print_level, filename="__STD_OUT__")
317 1462 : CALL section_add_subsection(section, print_key)
318 1462 : CALL section_release(print_key)
319 :
320 : CALL cp_print_key_section_create(print_key, __LOCATION__, &
321 : name="DISTRIBUTION1D", &
322 : description="Each node prints out its distribution info ...", &
323 1462 : print_level=high_print_level, filename="__STD_OUT__")
324 1462 : CALL section_add_subsection(section, print_key)
325 1462 : CALL section_release(print_key)
326 :
327 : CALL cp_print_key_section_create(print_key, __LOCATION__, &
328 : name="STRESS_TENSOR", &
329 : description="Controls the printing of the stress tensor", &
330 1462 : print_level=high_print_level, filename="__STD_OUT__")
331 : CALL keyword_create(keyword, __LOCATION__, &
332 : name="COMPONENTS", &
333 : description="Print all GPW/GAPW components contributing to the stress tensor", &
334 : usage="COMPONENTS", &
335 : default_l_val=.FALSE., &
336 1462 : lone_keyword_l_val=.TRUE.)
337 1462 : CALL section_add_keyword(print_key, keyword)
338 1462 : CALL keyword_release(keyword)
339 : CALL keyword_create(keyword, __LOCATION__, &
340 : name="STRESS_UNIT", &
341 : description="Specifies the physical unit used for the printing of the stress tensor. "// &
342 : "Note that the meaningfulness of the unit is not checked.", &
343 : usage="STRESS_UNIT kbar", &
344 : default_c_val="bar", &
345 1462 : repeats=.FALSE.)
346 1462 : CALL section_add_keyword(print_key, keyword)
347 1462 : CALL keyword_release(keyword)
348 1462 : CALL section_add_subsection(section, print_key)
349 1462 : CALL section_release(print_key)
350 :
351 : CALL cp_print_key_section_create(print_key, __LOCATION__, &
352 : name="GRRM", &
353 : description="Controls the printing of the GRRM interface file", &
354 1462 : print_level=debug_print_level + 1, filename="CP2K_GRRM")
355 1462 : CALL section_add_subsection(section, print_key)
356 1462 : CALL section_release(print_key)
357 :
358 : CALL cp_print_key_section_create(print_key, __LOCATION__, &
359 : name="SCINE", &
360 : description="Controls the printing of the SCINE interface file", &
361 1462 : print_level=debug_print_level + 1, filename="")
362 1462 : CALL section_add_subsection(section, print_key)
363 1462 : CALL section_release(print_key)
364 :
365 1462 : END SUBROUTINE create_f_env_print_section
366 :
367 : END MODULE input_cp2k_force_eval
|