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 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 : ! **************************************************************************************************
14 : MODULE input_cp2k_nnp
15 :
16 : USE bibliography, ONLY: Behler2007,&
17 : Behler2011,&
18 : Schran2020a,&
19 : Schran2020b
20 : USE cp_output_handling, ONLY: cp_print_key_section_create,&
21 : medium_print_level
22 : USE cp_units, ONLY: cp_unit_to_cp2k
23 : USE input_keyword_types, ONLY: keyword_create,&
24 : keyword_release,&
25 : keyword_type
26 : USE input_section_types, ONLY: section_add_keyword,&
27 : section_add_subsection,&
28 : section_create,&
29 : section_release,&
30 : section_type
31 : USE input_val_types, ONLY: char_t,&
32 : integer_t,&
33 : real_t
34 : USE kinds, ONLY: dp
35 : #include "./base/base_uses.f90"
36 :
37 : IMPLICIT NONE
38 : PRIVATE
39 :
40 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .FALSE.
41 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_nnp'
42 :
43 : PUBLIC :: create_nnp_section
44 :
45 : CONTAINS
46 :
47 : ! **************************************************************************************************
48 : !> \brief Create the input section for NNP
49 : !> \param section the section to create
50 : !> \date 2020-10-10
51 : !> \author Christoph Schran (christoph.schran@rub.de)
52 : ! **************************************************************************************************
53 10624 : SUBROUTINE create_nnp_section(section)
54 : TYPE(section_type), POINTER :: section
55 :
56 : TYPE(keyword_type), POINTER :: keyword
57 : TYPE(section_type), POINTER :: subsection, subsubsection
58 :
59 10624 : CPASSERT(.NOT. ASSOCIATED(section))
60 : CALL section_create(section, __LOCATION__, name="NNP", &
61 : description="This section contains all information to run a "// &
62 : "Neural Network Potential (NNP) calculation.", &
63 : n_keywords=5, n_subsections=3, repeats=.FALSE., &
64 53120 : citations=[Behler2007, Behler2011, Schran2020a, Schran2020b])
65 :
66 10624 : NULLIFY (subsection, subsubsection, keyword)
67 :
68 : CALL keyword_create(keyword, __LOCATION__, name="NNP_INPUT_FILE_NAME", &
69 : description="File containing the input information for "// &
70 : "the setup of the NNP (n2p2/RuNNer format).", &
71 10624 : repeats=.FALSE., default_lc_val="input.nn")
72 10624 : CALL section_add_keyword(section, keyword)
73 10624 : CALL keyword_release(keyword)
74 : CALL keyword_create(keyword, __LOCATION__, name="SCALE_FILE_NAME", &
75 : description="File containing the scaling information for "// &
76 : "the symmetry functions of the NNP.", &
77 10624 : repeats=.FALSE., default_lc_val="scaling.data")
78 10624 : CALL section_add_keyword(section, keyword)
79 10624 : CALL keyword_release(keyword)
80 :
81 : CALL keyword_create(keyword, __LOCATION__, name="RAD_SPLINE_N", &
82 : description="Number of knots per radial group in "// &
83 : "the cubic-Hermite spline tables that tabulate "// &
84 : "the radial symmetry-function product "// &
85 : "y(r) = exp(-eta*(r-rs)^2) * fcut(r). "// &
86 : "The value error scales as O(1/n^4) and the "// &
87 : "force (derivative) error as O(1/n^3); the "// &
88 : "default keeps both inside the NNP regression "// &
89 : "tolerance for a radial cutoff of ~12 bohr "// &
90 : "(value ~1e-14, force ~1e-10). Larger cutoffs or "// &
91 : "stricter tolerances may need a larger n, with "// &
92 : "the force term the binding constraint. Memory "// &
93 : "cost scales linearly in n per group.", &
94 : repeats=.FALSE., &
95 : n_var=1, &
96 : type_of_var=integer_t, &
97 : default_i_val=8192, &
98 10624 : usage="RAD_SPLINE_N 8192")
99 10624 : CALL section_add_keyword(section, keyword)
100 10624 : CALL keyword_release(keyword)
101 :
102 : CALL keyword_create(keyword, __LOCATION__, name="VERLET_SKIN", &
103 : description="Verlet skin distance for the NNP descriptor "// &
104 : "neighbour cell-list. The neighbour-list cutoff is "// &
105 : "(symmetry-function cutoff + skin); the cell-list "// &
106 : "chain is rebuilt only when an atom drifts more "// &
107 : "than skin/2 from its rebuild-time position, "// &
108 : "analogous to the LAMMPS 'neighbor <skin> bin' "// &
109 : "command. Larger skin reduces the rebuild rate "// &
110 : "but enlarges the per-atom neighbour list. "// &
111 : "A negative value (default) selects the "// &
112 : "automatic heuristic MIN(0.5 bohr, 0.1*cutoff). "// &
113 : "Useful upper bound is half the smallest "// &
114 : "perpendicular cell width.", &
115 : repeats=.FALSE., &
116 : n_var=1, &
117 : type_of_var=real_t, &
118 : default_r_val=-1.0_dp, &
119 : unit_str="bohr", &
120 10624 : usage="VERLET_SKIN [bohr] 0.5")
121 10624 : CALL section_add_keyword(section, keyword)
122 10624 : CALL keyword_release(keyword)
123 :
124 : ! BIAS subsection
125 : CALL section_create(subsection, __LOCATION__, name="BIAS", &
126 : description="Section to bias the committee disagreement (sigma) by "// &
127 : "E = 0.5 * K_B * (sigma - SIGMA_0)**2, if sigma > SIGMA_0.", &
128 : n_keywords=2, n_subsections=0, repeats=.FALSE., &
129 21248 : citations=[Schran2020b])
130 : CALL keyword_create(keyword, __LOCATION__, name="K_B", &
131 : description="Harmonic spring constant of the bias potential [1/hartree].", &
132 : repeats=.FALSE., &
133 : n_var=1, &
134 : type_of_var=real_t, &
135 : default_r_val=cp_unit_to_cp2k(value=0.1_dp, unit_str="hartree^-1"), &
136 : unit_str="hartree^-1", &
137 10624 : usage="K_B [hartree^-1] 0.1")
138 10624 : CALL section_add_keyword(subsection, keyword)
139 10624 : CALL keyword_release(keyword)
140 : CALL keyword_create(keyword, __LOCATION__, name="SIGMA_0", &
141 : description="Shift of the harmonic bias potential.", &
142 : repeats=.FALSE., &
143 : n_var=1, &
144 : type_of_var=real_t, &
145 : default_r_val=cp_unit_to_cp2k(value=0.1_dp, unit_str="hartree"), &
146 : unit_str="hartree", &
147 10624 : usage="SIGMA_0 [hartree] 0.1")
148 10624 : CALL section_add_keyword(subsection, keyword)
149 10624 : CALL keyword_release(keyword)
150 : CALL keyword_create(keyword, __LOCATION__, name="ALIGN_NNP_ENERGIES", &
151 : description="Remove PES shifts within the committee by "// &
152 : "subtracting energy for each committee member. Provide "// &
153 : "one number per C-NNP member.", &
154 : repeats=.FALSE., &
155 : n_var=-1, &
156 : type_of_var=real_t, &
157 10624 : usage="ALIGN_NNP_ENERGIES <REAL> <REAL> ... <REAL>")
158 10624 : CALL section_add_keyword(subsection, keyword)
159 10624 : CALL keyword_release(keyword)
160 : ! print bias subsubsection:
161 10624 : CALL create_nnp_bias_print_section(subsubsection)
162 10624 : CALL section_add_subsection(subsection, subsubsection)
163 10624 : CALL section_release(subsubsection)
164 :
165 10624 : CALL section_add_subsection(section, subsection)
166 10624 : CALL section_release(subsection)
167 : ! end BIAS subsection
168 :
169 : CALL section_create(subsection, __LOCATION__, name="MODEL", &
170 : description="Section for a single NNP model. "// &
171 : "If this section is repeated, a committee model (C-NNP) "// &
172 : "is used where the NNP members share the same symmetry functions.", &
173 10624 : n_keywords=1, n_subsections=0, repeats=.TRUE.)
174 : CALL keyword_create(keyword, __LOCATION__, name="WEIGHTS", &
175 : description="File containing the weights for the "// &
176 : "artificial neural networks of the NNP. "// &
177 : "The specified name is extended by .XXX.data", &
178 10624 : repeats=.FALSE., default_lc_val="weights")
179 10624 : CALL section_add_keyword(subsection, keyword)
180 10624 : CALL keyword_release(keyword)
181 10624 : CALL section_add_subsection(section, subsection)
182 10624 : CALL section_release(subsection)
183 :
184 10624 : CALL create_nnp_print_section(subsection)
185 10624 : CALL section_add_subsection(section, subsection)
186 10624 : CALL section_release(subsection)
187 :
188 10624 : END SUBROUTINE create_nnp_section
189 :
190 : ! **************************************************************************************************
191 : !> \brief Creates the print section for the nnp subsection
192 : !> \param section the section to create
193 : !> \date 2020-10-10
194 : !> \author Christoph Schran (christoph.schran@rub.de)
195 : ! **************************************************************************************************
196 10624 : SUBROUTINE create_nnp_print_section(section)
197 : TYPE(section_type), POINTER :: section
198 :
199 : TYPE(keyword_type), POINTER :: keyword
200 : TYPE(section_type), POINTER :: print_key
201 :
202 10624 : CPASSERT(.NOT. ASSOCIATED(section))
203 : CALL section_create(section, __LOCATION__, name="PRINT", &
204 : description="Section of possible print options in NNP code.", &
205 10624 : n_keywords=0, n_subsections=5, repeats=.FALSE.)
206 :
207 10624 : NULLIFY (print_key, keyword)
208 :
209 : CALL cp_print_key_section_create(print_key, __LOCATION__, "ENERGIES", &
210 : description="Controls the printing of the NNP energies.", &
211 10624 : print_level=medium_print_level, common_iter_levels=1)
212 10624 : CALL section_add_subsection(section, print_key)
213 10624 : CALL section_release(print_key)
214 :
215 : CALL cp_print_key_section_create(print_key, __LOCATION__, "FORCES", &
216 : description="Controls the printing of the NNP forces.", &
217 10624 : print_level=medium_print_level, common_iter_levels=1)
218 10624 : CALL section_add_subsection(section, print_key)
219 10624 : CALL section_release(print_key)
220 :
221 : CALL cp_print_key_section_create(print_key, __LOCATION__, "FORCES_SIGMA", &
222 : description="Controls the printing of the STD per atom of the NNP forces.", &
223 10624 : print_level=medium_print_level, common_iter_levels=1)
224 10624 : CALL section_add_subsection(section, print_key)
225 10624 : CALL section_release(print_key)
226 :
227 : CALL cp_print_key_section_create(print_key, __LOCATION__, "EXTRAPOLATION", &
228 : description="If activated, output structures with extrapolation "// &
229 : "warning in xyz-format", &
230 10624 : print_level=medium_print_level, common_iter_levels=1)
231 10624 : CALL section_add_subsection(section, print_key)
232 10624 : CALL section_release(print_key)
233 :
234 : CALL cp_print_key_section_create(print_key, __LOCATION__, "SUM_FORCE", &
235 : description="If activated, output summed force over specified atoms. "// &
236 : "Used in Green-Kubo relation for friction at liquid-solid interfaces.", &
237 10624 : print_level=medium_print_level, common_iter_levels=1)
238 :
239 : CALL keyword_create(keyword, __LOCATION__, name="ATOM_LIST", &
240 : description="List of atoms over which to calculate summed force", &
241 : usage="ATOM_LISTS {O} {H} .. {X}", repeats=.FALSE., &
242 10624 : n_var=-1, type_of_var=char_t)
243 10624 : CALL section_add_keyword(print_key, keyword)
244 10624 : CALL keyword_release(keyword)
245 :
246 10624 : CALL section_add_subsection(section, print_key)
247 10624 : CALL section_release(print_key)
248 :
249 10624 : END SUBROUTINE create_nnp_print_section
250 :
251 : ! **************************************************************************************************
252 : !> \brief Creates the print section for the nnp bias subsubsection
253 : !> \param section the section to create
254 : !> \date 2020-10-10
255 : !> \author Christoph Schran (christoph.schran@rub.de)
256 : ! **************************************************************************************************
257 10624 : SUBROUTINE create_nnp_bias_print_section(section)
258 : TYPE(section_type), POINTER :: section
259 :
260 : TYPE(section_type), POINTER :: print_key
261 :
262 10624 : CPASSERT(.NOT. ASSOCIATED(section))
263 : CALL section_create(section, __LOCATION__, name="PRINT", &
264 : description="Section of possible print options in NNP code.", &
265 10624 : n_keywords=0, n_subsections=3, repeats=.FALSE.)
266 :
267 10624 : NULLIFY (print_key)
268 :
269 : CALL cp_print_key_section_create(print_key, __LOCATION__, "BIAS_ENERGY", &
270 : description="Controls the printing of the BIAS energy.", &
271 10624 : print_level=medium_print_level, common_iter_levels=1)
272 10624 : CALL section_add_subsection(section, print_key)
273 10624 : CALL section_release(print_key)
274 :
275 : CALL cp_print_key_section_create(print_key, __LOCATION__, "BIAS_FORCES", &
276 : description="Controls the printing of the BIAS forces.", &
277 10624 : print_level=medium_print_level, common_iter_levels=1)
278 10624 : CALL section_add_subsection(section, print_key)
279 10624 : CALL section_release(print_key)
280 :
281 10624 : END SUBROUTINE create_nnp_bias_print_section
282 :
283 : END MODULE input_cp2k_nnp
|