(git:3f0d10b)
Loading...
Searching...
No Matches
input_cp2k_nnp.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 Creates the NNP section of the input
10!> \author Christoph Schran (christoph.schran@rub.de)
11!> \author Dhruv Sharma (ds2173@cam.ac.uk)
12!> \date 2020-10-10
13! **************************************************************************************************
15
16 USE bibliography, ONLY: behler2007,&
22 USE cp_units, ONLY: cp_unit_to_cp2k
36 USE input_val_types, ONLY: char_t,&
37 integer_t,&
38 real_t
39 USE kinds, ONLY: dp
40 USE string_utilities, ONLY: s2a
41#include "./base/base_uses.f90"
42
43 IMPLICIT NONE
44 PRIVATE
45
46 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .false.
47 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_nnp'
48
49 PUBLIC :: create_nnp_section
50
51CONTAINS
52
53! **************************************************************************************************
54!> \brief Create the input section for NNP
55!> \param section the section to create
56!> \date 2020-10-10
57!> \author Christoph Schran (christoph.schran@rub.de)
58! **************************************************************************************************
59 SUBROUTINE create_nnp_section(section)
60 TYPE(section_type), POINTER :: section
61
62 TYPE(keyword_type), POINTER :: keyword
63 TYPE(section_type), POINTER :: subsection, subsubsection
64
65 cpassert(.NOT. ASSOCIATED(section))
66 CALL section_create(section, __location__, name="NNP", &
67 description="This section contains all information to run a "// &
68 "Neural Network Potential (NNP) calculation.", &
69 n_keywords=5, n_subsections=3, repeats=.false., &
71
72 NULLIFY (subsection, subsubsection, keyword)
73
74 CALL keyword_create(keyword, __location__, name="NNP_INPUT_FILE_NAME", &
75 description="File containing the input information for "// &
76 "the setup of the NNP (n2p2/RuNNer format).", &
77 repeats=.false., default_lc_val="input.nn")
78 CALL section_add_keyword(section, keyword)
79 CALL keyword_release(keyword)
80 CALL keyword_create(keyword, __location__, name="SCALE_FILE_NAME", &
81 description="File containing the scaling information for "// &
82 "the symmetry functions of the NNP.", &
83 repeats=.false., default_lc_val="scaling.data")
84 CALL section_add_keyword(section, keyword)
85 CALL keyword_release(keyword)
86
87 CALL keyword_create(keyword, __location__, name="RAD_SPLINE_N", &
88 description="Number of knots per radial group in "// &
89 "the cubic-Hermite spline tables that tabulate "// &
90 "the radial symmetry-function product "// &
91 "y(r) = exp(-eta*(r-rs)^2) * fcut(r). "// &
92 "The value error scales as O(1/n^4) and the "// &
93 "force (derivative) error as O(1/n^3); the "// &
94 "default keeps both inside the NNP regression "// &
95 "tolerance for a radial cutoff of ~12 bohr "// &
96 "(value ~1e-14, force ~1e-10). Larger cutoffs or "// &
97 "stricter tolerances may need a larger n, with "// &
98 "the force term the binding constraint. Memory "// &
99 "cost scales linearly in n per group.", &
100 repeats=.false., &
101 n_var=1, &
102 type_of_var=integer_t, &
103 default_i_val=8192, &
104 usage="RAD_SPLINE_N 8192")
105 CALL section_add_keyword(section, keyword)
106 CALL keyword_release(keyword)
107
108 CALL keyword_create(keyword, __location__, name="VERLET_SKIN", &
109 description="Verlet skin distance for the NNP descriptor "// &
110 "neighbour cell-list. The neighbour-list cutoff is "// &
111 "(symmetry-function cutoff + skin); the cell-list "// &
112 "chain is rebuilt only when an atom drifts more "// &
113 "than skin/2 from its rebuild-time position, "// &
114 "analogous to the LAMMPS 'neighbor <skin> bin' "// &
115 "command. Larger skin reduces the rebuild rate "// &
116 "but enlarges the per-atom neighbour list. "// &
117 "A negative value (default) selects the "// &
118 "automatic heuristic MIN(0.5 bohr, 0.1*cutoff). "// &
119 "Useful upper bound is half the smallest "// &
120 "perpendicular cell width.", &
121 repeats=.false., &
122 n_var=1, &
123 type_of_var=real_t, &
124 default_r_val=-1.0_dp, &
125 unit_str="bohr", &
126 usage="VERLET_SKIN [bohr] 0.5")
127 CALL section_add_keyword(section, keyword)
128 CALL keyword_release(keyword)
129
130 CALL keyword_create(keyword, __location__, name="USE_GPU", &
131 description="Choose between the CPU and GPU code paths for "// &
132 "the NNP energy and force evaluation. The GPU path "// &
133 "requires a build with CUDA or HIP support; it "// &
134 "reproduces the CPU results within the "// &
135 "regression-test tolerances. Analytic stress (e.g. "// &
136 "NPT) is accumulated on the device by the "// &
137 "force-scatter kernels; only energy-only "// &
138 "evaluations always use the CPU path.", &
139 usage="USE_GPU AUTO", &
140 repeats=.false., &
141 enum_c_vals=s2a("AUTO", "ON", "OFF"), &
143 enum_desc=s2a("Probe for a GPU at initialization and use it when "// &
144 "the build supports one, every rank sees a device, "// &
145 "the model fits the compiled-in device-table "// &
146 "capacities, and the system is large enough for the "// &
147 "transfer and launch overhead to pay off (currently "// &
148 "a thousand atoms per rank); otherwise fall back to "// &
149 "the CPU.", &
150 "Force the GPU code path; abort if the build has "// &
151 "no GPU support or no device is available.", &
152 "Force the CPU code path."), &
153 default_i_val=nnp_use_gpu_auto)
154 CALL section_add_keyword(section, keyword)
155 CALL keyword_release(keyword)
156
157 CALL keyword_create(keyword, __location__, name="GPU_PRECISION", &
158 description="Floating-point precision of the GPU code path. "// &
159 "Only meaningful when the GPU path is active.", &
160 usage="GPU_PRECISION DOUBLE", &
161 repeats=.false., &
162 enum_c_vals=s2a("DOUBLE", "MIXED"), &
164 enum_desc=s2a("All-FP64 path; reproduces the CPU trajectory "// &
165 "within the regression-test tolerances.", &
166 "FP32 angular symmetry-function math with FP64 "// &
167 "radial functions, network evaluation and every "// &
168 "accumulator that sums over neighbours. Faster on "// &
169 "GPUs whose single-precision throughput exceeds "// &
170 "their double-precision throughput, at the cost of "// &
171 "a perturbation of energies and forces that is "// &
172 "model dependent (a relative 4.5e-11 on the "// &
173 "step-zero energy of the shipped regression-test "// &
174 "model, whose tests bound it at 1e-6; measure it "// &
175 "for your own)."), &
176 default_i_val=nnp_gpu_prec_double)
177 CALL section_add_keyword(section, keyword)
178 CALL keyword_release(keyword)
179
180 CALL keyword_create(keyword, __location__, name="VALIDATE", &
181 description="When enabled and the GPU code path is active, the CPU "// &
182 "reference implementation is run in shadow mode on every force "// &
183 "evaluation and its energies, forces and stress are compared with "// &
184 "those from the GPU path. If the two results differ by too much "// &
185 "then the calculation is aborted. Under USE_GPU AUTO the "// &
186 "system-size heuristic is skipped, so the GPU path engages "// &
187 "whenever the build and the machine support it. Has no effect "// &
188 "when the evaluation runs on the CPU, so the same input can be "// &
189 "used on every architecture.", &
190 usage="VALIDATE", &
191 default_l_val=.false., &
192 lone_keyword_l_val=.true.)
193 CALL section_add_keyword(section, keyword)
194 CALL keyword_release(keyword)
195
196 ! BIAS subsection
197 CALL section_create(subsection, __location__, name="BIAS", &
198 description="Section to bias the committee disagreement (sigma) by "// &
199 "E = 0.5 * K_B * (sigma - SIGMA_0)**2, if sigma > SIGMA_0.", &
200 n_keywords=2, n_subsections=0, repeats=.false., &
201 citations=[schran2020b])
202 CALL keyword_create(keyword, __location__, name="K_B", &
203 description="Harmonic spring constant of the bias potential [1/hartree].", &
204 repeats=.false., &
205 n_var=1, &
206 type_of_var=real_t, &
207 default_r_val=cp_unit_to_cp2k(value=0.1_dp, unit_str="hartree^-1"), &
208 unit_str="hartree^-1", &
209 usage="K_B [hartree^-1] 0.1")
210 CALL section_add_keyword(subsection, keyword)
211 CALL keyword_release(keyword)
212 CALL keyword_create(keyword, __location__, name="SIGMA_0", &
213 description="Shift of the harmonic bias potential.", &
214 repeats=.false., &
215 n_var=1, &
216 type_of_var=real_t, &
217 default_r_val=cp_unit_to_cp2k(value=0.1_dp, unit_str="hartree"), &
218 unit_str="hartree", &
219 usage="SIGMA_0 [hartree] 0.1")
220 CALL section_add_keyword(subsection, keyword)
221 CALL keyword_release(keyword)
222 CALL keyword_create(keyword, __location__, name="ALIGN_NNP_ENERGIES", &
223 description="Remove PES shifts within the committee by "// &
224 "subtracting energy for each committee member. Provide "// &
225 "one number per C-NNP member.", &
226 repeats=.false., &
227 n_var=-1, &
228 type_of_var=real_t, &
229 usage="ALIGN_NNP_ENERGIES <REAL> <REAL> ... <REAL>")
230 CALL section_add_keyword(subsection, keyword)
231 CALL keyword_release(keyword)
232 ! print bias subsubsection:
233 CALL create_nnp_bias_print_section(subsubsection)
234 CALL section_add_subsection(subsection, subsubsection)
235 CALL section_release(subsubsection)
236
237 CALL section_add_subsection(section, subsection)
238 CALL section_release(subsection)
239 ! end BIAS subsection
240
241 CALL section_create(subsection, __location__, name="MODEL", &
242 description="Section for a single NNP model. "// &
243 "If this section is repeated, a committee model (C-NNP) "// &
244 "is used where the NNP members share the same symmetry functions.", &
245 n_keywords=1, n_subsections=0, repeats=.true.)
246 CALL keyword_create(keyword, __location__, name="WEIGHTS", &
247 description="File containing the weights for the "// &
248 "artificial neural networks of the NNP. "// &
249 "The specified name is extended by .XXX.data", &
250 repeats=.false., default_lc_val="weights")
251 CALL section_add_keyword(subsection, keyword)
252 CALL keyword_release(keyword)
253 CALL section_add_subsection(section, subsection)
254 CALL section_release(subsection)
255
256 CALL create_nnp_print_section(subsection)
257 CALL section_add_subsection(section, subsection)
258 CALL section_release(subsection)
259
260 END SUBROUTINE create_nnp_section
261
262! **************************************************************************************************
263!> \brief Creates the print section for the nnp subsection
264!> \param section the section to create
265!> \date 2020-10-10
266!> \author Christoph Schran (christoph.schran@rub.de)
267! **************************************************************************************************
268 SUBROUTINE create_nnp_print_section(section)
269 TYPE(section_type), POINTER :: section
270
271 TYPE(keyword_type), POINTER :: keyword
272 TYPE(section_type), POINTER :: print_key
273
274 cpassert(.NOT. ASSOCIATED(section))
275 CALL section_create(section, __location__, name="PRINT", &
276 description="Section of possible print options in NNP code.", &
277 n_keywords=0, n_subsections=5, repeats=.false.)
278
279 NULLIFY (print_key, keyword)
280
281 CALL cp_print_key_section_create(print_key, __location__, "ENERGIES", &
282 description="Controls the printing of the NNP energies.", &
283 print_level=medium_print_level, common_iter_levels=1)
284 CALL section_add_subsection(section, print_key)
285 CALL section_release(print_key)
286
287 CALL cp_print_key_section_create(print_key, __location__, "FORCES", &
288 description="Controls the printing of the NNP forces.", &
289 print_level=medium_print_level, common_iter_levels=1)
290 CALL section_add_subsection(section, print_key)
291 CALL section_release(print_key)
292
293 CALL cp_print_key_section_create(print_key, __location__, "FORCES_SIGMA", &
294 description="Controls the printing of the STD per atom of the NNP forces.", &
295 print_level=medium_print_level, common_iter_levels=1)
296 CALL section_add_subsection(section, print_key)
297 CALL section_release(print_key)
298
299 CALL cp_print_key_section_create(print_key, __location__, "EXTRAPOLATION", &
300 description="If activated, output structures with extrapolation "// &
301 "warning in xyz-format", &
302 print_level=medium_print_level, common_iter_levels=1)
303 CALL section_add_subsection(section, print_key)
304 CALL section_release(print_key)
305
306 CALL cp_print_key_section_create(print_key, __location__, "SUM_FORCE", &
307 description="If activated, output summed force over specified atoms. "// &
308 "Used in Green-Kubo relation for friction at liquid-solid interfaces.", &
309 print_level=medium_print_level, common_iter_levels=1)
310
311 CALL keyword_create(keyword, __location__, name="ATOM_LIST", &
312 description="List of atoms over which to calculate summed force", &
313 usage="ATOM_LISTS {O} {H} .. {X}", repeats=.false., &
314 n_var=-1, type_of_var=char_t)
315 CALL section_add_keyword(print_key, keyword)
316 CALL keyword_release(keyword)
317
318 CALL section_add_subsection(section, print_key)
319 CALL section_release(print_key)
320
321 END SUBROUTINE create_nnp_print_section
322
323! **************************************************************************************************
324!> \brief Creates the print section for the nnp bias subsubsection
325!> \param section the section to create
326!> \date 2020-10-10
327!> \author Christoph Schran (christoph.schran@rub.de)
328! **************************************************************************************************
329 SUBROUTINE create_nnp_bias_print_section(section)
330 TYPE(section_type), POINTER :: section
331
332 TYPE(section_type), POINTER :: print_key
333
334 cpassert(.NOT. ASSOCIATED(section))
335 CALL section_create(section, __location__, name="PRINT", &
336 description="Section of possible print options in NNP code.", &
337 n_keywords=0, n_subsections=3, repeats=.false.)
338
339 NULLIFY (print_key)
340
341 CALL cp_print_key_section_create(print_key, __location__, "BIAS_ENERGY", &
342 description="Controls the printing of the BIAS energy.", &
343 print_level=medium_print_level, common_iter_levels=1)
344 CALL section_add_subsection(section, print_key)
345 CALL section_release(print_key)
346
347 CALL cp_print_key_section_create(print_key, __location__, "BIAS_FORCES", &
348 description="Controls the printing of the BIAS forces.", &
349 print_level=medium_print_level, common_iter_levels=1)
350 CALL section_add_subsection(section, print_key)
351 CALL section_release(print_key)
352
353 END SUBROUTINE create_nnp_bias_print_section
354
355END MODULE input_cp2k_nnp
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public schran2020b
integer, save, public schran2020a
integer, save, public behler2011
integer, save, public behler2007
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
subroutine, public cp_print_key_section_create(print_key_section, location, name, description, print_level, each_iter_names, each_iter_values, add_last, filename, common_iter_levels, citations, unit_str, do_backup)
creates a print_key section
integer, parameter, public medium_print_level
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:1282
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public nnp_gpu_prec_mixed
integer, parameter, public nnp_use_gpu_off
integer, parameter, public nnp_use_gpu_on
integer, parameter, public nnp_use_gpu_auto
integer, parameter, public nnp_gpu_prec_double
Creates the NNP section of the input.
subroutine, public create_nnp_section(section)
Create the input section for NNP.
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
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