(git:495eafe)
Loading...
Searching...
No Matches
nnp_environment.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 Methods dealing with Neural Network potentials
10!> \author Christoph Schran (christoph.schran@rub.de)
11!> \date 2020-10-10
12! **************************************************************************************************
14
16 USE bibliography, ONLY: behler2007,&
20 cite_reference
21 USE cell_types, ONLY: cell_type
40 USE kinds, ONLY: default_path_length,&
41 dp
50 USE nnp_environment_types, ONLY: &
54 USE nnp_model, ONLY: nnp_write_arc
60#include "./base/base_uses.f90"
61
62 IMPLICIT NONE
63
64 PRIVATE
65
66 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .true.
67 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'nnp_environment'
68
69 PUBLIC :: nnp_init
70 PUBLIC :: nnp_init_model
71
72CONTAINS
73
74! **************************************************************************************************
75!> \brief Read and initialize all the information for neural network potentials
76!> \param nnp_env ...
77!> \param root_section ...
78!> \param para_env ...
79!> \param force_env_section ...
80!> \param subsys_section ...
81!> \param use_motion_section ...
82!> \date 2020-10-10
83!> \author Christoph Schran (christoph.schran@rub.de)
84! **************************************************************************************************
85 SUBROUTINE nnp_init(nnp_env, root_section, para_env, force_env_section, subsys_section, &
86 use_motion_section)
87 TYPE(nnp_type), INTENT(INOUT), POINTER :: nnp_env
88 TYPE(section_vals_type), INTENT(IN), POINTER :: root_section
89 TYPE(mp_para_env_type), INTENT(IN), POINTER :: para_env
90 TYPE(section_vals_type), INTENT(INOUT), POINTER :: force_env_section, subsys_section
91 LOGICAL, INTENT(IN) :: use_motion_section
92
93 CHARACTER(len=*), PARAMETER :: routinen = 'nnp_init'
94
95 INTEGER :: handle
96 LOGICAL :: explicit
97 TYPE(cp_subsys_type), POINTER :: subsys
98 TYPE(section_vals_type), POINTER :: nnp_section
99
100 CALL timeset(routinen, handle)
101 CALL cite_reference(behler2007)
102 CALL cite_reference(behler2011)
103 CALL cite_reference(schran2020a)
104 CALL cite_reference(schran2020b)
105
106 cpassert(ASSOCIATED(nnp_env))
107
108 NULLIFY (nnp_section, subsys)
109
110 IF (.NOT. ASSOCIATED(subsys_section)) THEN
111 subsys_section => section_vals_get_subs_vals(force_env_section, "SUBSYS")
112 END IF
113 nnp_section => section_vals_get_subs_vals(force_env_section, "NNP")
114 CALL section_vals_get(nnp_section, explicit=explicit)
115 IF (.NOT. explicit) THEN
116 cpwarn("NNP section not explicitly stated. Using default file names.")
117 END IF
118
119 CALL nnp_env_set(nnp_env=nnp_env, nnp_input=nnp_section, &
120 force_env_input=force_env_section)
121
122 CALL cp_subsys_create(subsys, para_env, root_section, &
123 force_env_section=force_env_section, subsys_section=subsys_section, &
124 use_motion_section=use_motion_section)
125
126 CALL nnp_init_subsys(nnp_env=nnp_env, subsys=subsys, &
127 subsys_section=subsys_section)
128
129 CALL timestop(handle)
130
131 END SUBROUTINE nnp_init
132
133! **************************************************************************************************
134!> \brief Read and initialize all the information for neural network potentials
135!> \param nnp_env ...
136!> \param subsys ...
137!> \param subsys_section ...
138!> \date 2020-10-10
139!> \author Christoph Schran (christoph.schran@rub.de)
140! **************************************************************************************************
141 SUBROUTINE nnp_init_subsys(nnp_env, subsys, subsys_section)
142 TYPE(nnp_type), INTENT(INOUT), POINTER :: nnp_env
143 TYPE(cp_subsys_type), INTENT(IN), POINTER :: subsys
144 TYPE(section_vals_type), INTENT(IN), POINTER :: subsys_section
145
146 CHARACTER(len=*), PARAMETER :: routinen = 'nnp_init_subsys'
147
148 INTEGER :: handle, natom
149 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
150 TYPE(cell_type), POINTER :: my_cell, my_cell_ref
151 TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
152 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
153 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
154 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
155
156 CALL timeset(routinen, handle)
157
158 NULLIFY (atomic_kind_set, molecule_kind_set, my_cell, my_cell_ref, &
159 particle_set, molecule_set, local_molecules, local_particles)
160
161 particle_set => subsys%particles%els
162 atomic_kind_set => subsys%atomic_kinds%els
163 molecule_kind_set => subsys%molecule_kinds%els
164 molecule_set => subsys%molecules%els
165 my_cell => subsys%cell
166 my_cell_ref => subsys%cell_ref
167
168 !Print the molecule kind set
169 CALL write_molecule_kind_set(molecule_kind_set, subsys_section)
170
171 !Set up cell
172 CALL nnp_env_set(nnp_env=nnp_env, subsys=subsys, &
173 cell=my_cell, cell_ref=my_cell_ref, &
174 use_ref_cell=subsys%use_ref_cell)
175
176 !Print the atomic coordinates
177 CALL write_fist_particle_coordinates(particle_set, subsys_section)
178 CALL write_particle_distances(particle_set, cell=my_cell, &
179 subsys_section=subsys_section)
180 CALL write_structure_data(particle_set, cell=my_cell, &
181 input_section=subsys_section)
182
183 !Distribute molecules and atoms using the new data structures
184 CALL distribute_molecules_1d(atomic_kind_set=atomic_kind_set, &
185 particle_set=particle_set, &
186 local_particles=local_particles, &
187 molecule_kind_set=molecule_kind_set, &
188 molecule_set=molecule_set, &
189 local_molecules=local_molecules, &
190 force_env_section=nnp_env%force_env_input)
191
192 natom = SIZE(particle_set)
193
194 ALLOCATE (nnp_env%nnp_forces(3, natom))
195
196 nnp_env%nnp_forces(:, :) = 0.0_dp
197
198 nnp_env%nnp_potential_energy = 0.0_dp
199
200 ! Set up arrays for calculation:
201 nnp_env%num_atoms = natom
202 ALLOCATE (nnp_env%ele_ind(natom))
203 ALLOCATE (nnp_env%nuc_atoms(natom))
204 ALLOCATE (nnp_env%coord(3, natom))
205 ALLOCATE (nnp_env%atoms(natom))
206 ALLOCATE (nnp_env%sort(natom))
207 ALLOCATE (nnp_env%sort_inv(natom))
208
209 CALL nnp_env_set(nnp_env=nnp_env, &
210 local_molecules=local_molecules, &
211 local_particles=local_particles)
212
213 CALL distribution_1d_release(local_particles)
214 CALL distribution_1d_release(local_molecules)
215
216 CALL nnp_init_model(nnp_env=nnp_env, printtag="NNP")
217
218 CALL timestop(handle)
219
220 END SUBROUTINE nnp_init_subsys
221
222! **************************************************************************************************
223!> \brief Initialize the Neural Network Potential
224!> \param nnp_env ...
225!> \param printtag ...
226!> \date 2020-10-10
227!> \author Christoph Schran (christoph.schran@rub.de)
228! **************************************************************************************************
229 SUBROUTINE nnp_init_model(nnp_env, printtag)
230 TYPE(nnp_type), INTENT(INOUT), POINTER :: nnp_env
231 CHARACTER(LEN=*), INTENT(IN) :: printtag
232
233 CHARACTER(len=*), PARAMETER :: routinen = 'nnp_init_model'
234 INTEGER, PARAMETER :: def_str_len = 256, &
236
237 CHARACTER(len=1), ALLOCATABLE, DIMENSION(:) :: cactfnct
238 CHARACTER(len=2) :: ele
239 CHARACTER(len=def_str_len) :: dummy, line
240 CHARACTER(len=default_path_length) :: base_name, file_name
241 INTEGER :: handle, i, i_com, io, iweight, j, k, l, &
242 n_weight, nele, nuc_ele, symfnct_type, &
243 unit_nr
244 LOGICAL :: at_end, atom_e_found, explicit, first, &
245 found
246 REAL(kind=dp) :: energy
247 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: weights
248 REAL(kind=dp), DIMENSION(7) :: test_array
249 REAL(kind=dp), DIMENSION(:), POINTER :: work
250 TYPE(cp_logger_type), POINTER :: logger
251 TYPE(cp_parser_type) :: parser
252 TYPE(section_vals_type), POINTER :: bias_section, model_section
253
254 CALL timeset(routinen, handle)
255
256 NULLIFY (logger)
257
258 logger => cp_get_default_logger()
259
260 IF (logger%para_env%is_source()) THEN
261 unit_nr = cp_logger_get_default_unit_nr(logger)
262 WRITE (unit_nr, *) ""
263 WRITE (unit_nr, *) trim(printtag)//"| Neural Network Potential Force Environment"
264 END IF
265
266 model_section => section_vals_get_subs_vals(nnp_env%nnp_input, "MODEL")
267 CALL section_vals_get(model_section, n_repetition=nnp_env%n_committee)
268 ALLOCATE (nnp_env%atomic_energy(nnp_env%num_atoms, nnp_env%n_committee))
269 ALLOCATE (nnp_env%committee_energy(nnp_env%n_committee))
270 ALLOCATE (nnp_env%myforce(3, nnp_env%num_atoms, nnp_env%n_committee))
271 ALLOCATE (nnp_env%committee_forces(3, nnp_env%num_atoms, nnp_env%n_committee))
272 ALLOCATE (nnp_env%committee_stress(3, 3, nnp_env%n_committee))
273
274 CALL section_vals_val_get(nnp_env%nnp_input, "NNP_INPUT_FILE_NAME", c_val=file_name)
275 CALL parser_create(parser, file_name, para_env=logger%para_env)
276
277 ! read number of elements and cut_type and check for scale and center
278 nnp_env%scale_acsf = .false.
279 nnp_env%scale_sigma_acsf = .false.
280 ! Defaults for scale min and max:
281 nnp_env%scmin = 0.0_dp
282 nnp_env%scmax = 1.0_dp
283 nnp_env%center_acsf = .false.
284 nnp_env%normnodes = .false.
285 nnp_env%n_hlayer = 0
286
287 IF (logger%para_env%is_source()) THEN
288 unit_nr = cp_logger_get_default_unit_nr(logger)
289 WRITE (unit_nr, *) trim(printtag)//"| Reading NNP input from file: ", trim(file_name)
290 END IF
291
292 CALL parser_search_string(parser, "number_of_elements", .true., found, line, &
293 search_from_begin_of_file=.true.)
294 IF (found) THEN
295 READ (line, *) dummy, nnp_env%n_ele
296 ELSE
297 CALL cp_abort(__location__, trim(printtag)// &
298 "| number of elements missing in NNP_INPUT_FILE")
299 END IF
300
301 CALL parser_search_string(parser, "scale_symmetry_functions_sigma", .true., found, &
302 search_from_begin_of_file=.true.)
303 nnp_env%scale_sigma_acsf = found
304
305 CALL parser_search_string(parser, "scale_symmetry_functions", .true., found, &
306 search_from_begin_of_file=.true.)
307 nnp_env%scale_acsf = found
308
309 ! Test if there are two keywords of this:
310 CALL parser_search_string(parser, "scale_symmetry_functions", .true., found)
311 IF (found .AND. nnp_env%scale_sigma_acsf) THEN
312 cpwarn('Two scaling keywords in the input, we will ignore sigma scaling in this case')
313 nnp_env%scale_sigma_acsf = .false.
314 ELSE IF (.NOT. found .AND. nnp_env%scale_sigma_acsf) THEN
315 nnp_env%scale_acsf = .false.
316 END IF
317
318 CALL parser_search_string(parser, "scale_min_short_atomic", .true., found, line, &
319 search_from_begin_of_file=.true.)
320 IF (found) READ (line, *) dummy, nnp_env%scmin
321
322 CALL parser_search_string(parser, "scale_max_short_atomic", .true., found, line, &
323 search_from_begin_of_file=.true.)
324 IF (found) READ (line, *) dummy, nnp_env%scmax
325
326 CALL parser_search_string(parser, "center_symmetry_functions", .true., found, &
327 search_from_begin_of_file=.true.)
328 nnp_env%center_acsf = found
329 ! n2p2 overwrites sigma scaling, if centering is requested:
330 IF (nnp_env%scale_sigma_acsf .AND. nnp_env%center_acsf) THEN
331 nnp_env%scale_sigma_acsf = .false.
332 END IF
333 ! Print warning if centering and scaling is requested:
334 IF (nnp_env%center_acsf .AND. nnp_env%scale_acsf) THEN
335 IF ((abs(nnp_env%scmin) > epsilon(0.0_dp)*1.0e+4_dp) .OR. (abs(nnp_env%scmax - 1.0_dp) > epsilon(0.0_dp)*1.0e+4_dp)) THEN
336 CALL cp_warn(__location__, &
337 "Centering and scaling of symmetry functions requested while scale_min_short_atomic != 0 and/or "// &
338 "scale_max_short_atomic != 1. Make sure that scaling and centering of symmetry functions in CP2K "// &
339 "is consistent with your training code. "// &
340 "In CP2K: G* = (G - ave(G)) / (max(G) - min(G)) * (Smax - Smin) + Smin")
341 END IF
342 END IF
343
344 CALL parser_search_string(parser, "normalize_nodes", .true., found, &
345 search_from_begin_of_file=.true.)
346 nnp_env%normnodes = found
347
348 CALL parser_search_string(parser, "cutoff_type", .true., found, line, &
349 search_from_begin_of_file=.true.)
350 IF (found) THEN
351 READ (line, *) dummy, nnp_env%cut_type
352 ELSE
353 CALL cp_abort(__location__, trim(printtag)// &
354 "| no cutoff type specified in NNP_INPUT_FILE")
355 END IF
356
357 CALL parser_search_string(parser, "global_hidden_layers_short", .true., found, line, &
358 search_from_begin_of_file=.true.)
359 IF (found) THEN
360 READ (line, *) dummy, nnp_env%n_hlayer
361 ELSE
362 CALL cp_abort(__location__, trim(printtag)// &
363 "| number of hidden layers missing in NNP_INPUT_FILE")
364 END IF
365 nnp_env%n_layer = nnp_env%n_hlayer + 2
366
367 nele = nnp_env%n_ele
368 ALLOCATE (nnp_env%rad(nele))
369 ALLOCATE (nnp_env%ang(nele))
370 ALLOCATE (nnp_env%n_rad(nele))
371 ALLOCATE (nnp_env%n_ang(nele))
372 ALLOCATE (nnp_env%actfnct(nnp_env%n_hlayer + 1))
373 ALLOCATE (cactfnct(nnp_env%n_hlayer + 1))
374 ALLOCATE (nnp_env%ele(nele))
375 ALLOCATE (nnp_env%nuc_ele(nele))
376 ALLOCATE (nnp_env%arc(nele))
377 DO i = 1, nele
378 ALLOCATE (nnp_env%arc(i)%layer(nnp_env%n_layer))
379 ALLOCATE (nnp_env%arc(i)%n_nodes(nnp_env%n_layer))
380 END DO
381 ALLOCATE (nnp_env%n_hnodes(nnp_env%n_hlayer))
382 ALLOCATE (nnp_env%atom_energies(nele))
383 nnp_env%atom_energies = 0.0_dp
384
385 ! read elements, broadcast and sort
386 CALL parser_reset(parser)
387 DO
388 CALL parser_search_string(parser, "elements", .true., found, line)
389 IF (found) THEN
390 READ (line, *) dummy
391 IF (trim(adjustl(dummy)) == "elements") THEN
392 READ (line, *) dummy, nnp_env%ele(:)
393 CALL nnp_sort_ele(nnp_env%ele, nnp_env%nuc_ele)
394 EXIT
395 END IF
396 ELSE
397 CALL cp_abort(__location__, trim(printtag)// &
398 "| elements not specified in NNP_INPUT_FILE")
399 END IF
400 END DO
401
402 CALL parser_search_string(parser, "remove_atom_energies", .true., atom_e_found, &
403 search_from_begin_of_file=.true.)
404
405 IF (atom_e_found) THEN
406 CALL parser_reset(parser)
407 i = 0
408 DO
409 CALL parser_search_string(parser, "atom_energy", .true., found, line)
410 IF (found) THEN
411 READ (line, *) dummy, ele, energy
412 DO j = 1, nele
413 IF (nnp_env%ele(j) == trim(ele)) THEN
414 i = i + 1
415 nnp_env%atom_energies(j) = energy
416 END IF
417 END DO
418 IF (i == nele) EXIT
419 ELSE
420 CALL cp_abort(__location__, trim(printtag)// &
421 "| atom energies are not specified")
422 END IF
423 END DO
424 END IF
425
426 CALL parser_search_string(parser, "global_nodes_short", .true., found, line, &
427 search_from_begin_of_file=.true.)
428 IF (found) THEN
429 READ (line, *) dummy, nnp_env%n_hnodes(:)
430 ELSE
431 CALL cp_abort(__location__, trim(printtag)// &
432 "NNP| global_nodes_short not specified in NNP_INPUT_FILE")
433 END IF
434
435 CALL parser_search_string(parser, "global_activation_short", .true., found, line, &
436 search_from_begin_of_file=.true.)
437 IF (found) THEN
438 READ (line, *) dummy, cactfnct(:)
439 ELSE
440 CALL cp_abort(__location__, trim(printtag)// &
441 "| global_activation_short not specified in NNP_INPUT_FILE")
442 END IF
443
444 DO i = 1, nnp_env%n_hlayer + 1
445 SELECT CASE (cactfnct(i))
446 CASE ("t")
447 nnp_env%actfnct(i) = nnp_actfnct_tanh
448 CASE ("g")
449 nnp_env%actfnct(i) = nnp_actfnct_gaus
450 CASE ("l")
451 nnp_env%actfnct(i) = nnp_actfnct_lin
452 CASE ("c")
453 nnp_env%actfnct(i) = nnp_actfnct_cos
454 CASE ("s")
455 nnp_env%actfnct(i) = nnp_actfnct_sig
456 CASE ("S")
457 nnp_env%actfnct(i) = nnp_actfnct_invsig
458 CASE ("e")
459 nnp_env%actfnct(i) = nnp_actfnct_exp
460 CASE ("p")
461 nnp_env%actfnct(i) = nnp_actfnct_softplus
462 CASE ("h")
463 nnp_env%actfnct(i) = nnp_actfnct_quad
464 CASE DEFAULT
465 CALL cp_abort(__location__, trim(printtag)// &
466 "| Activation function unkown")
467 END SELECT
468 END DO
469
470 ! determine n_rad and n_ang
471 DO i = 1, nele
472 nnp_env%n_rad(i) = 0
473 nnp_env%n_ang(i) = 0
474 END DO
475
476 ! count symfunctions
477 CALL parser_reset(parser)
478 first = .true.
479 DO
480 CALL parser_search_string(parser, "symfunction_short", .true., found, line)
481 IF (found) THEN
482 READ (line, *) dummy, ele, symfnct_type
483 DO i = 1, nele
484 IF (trim(ele) == nnp_env%ele(i)) THEN
485 IF (symfnct_type == 2) THEN
486 nnp_env%n_rad(i) = nnp_env%n_rad(i) + 1
487 ELSE IF (symfnct_type == 3) THEN
488 nnp_env%n_ang(i) = nnp_env%n_ang(i) + 1
489 ELSE
490 CALL cp_abort(__location__, trim(printtag)// &
491 "| Symmetry function type not supported")
492 END IF
493 END IF
494 END DO
495 first = .false.
496 ELSE
497 IF (first) CALL cp_abort(__location__, trim(printtag)// &
498 "| no symfunction_short specified in NNP_INPUT_FILE")
499 ! no additional symfnct found
500 EXIT
501 END IF
502 END DO
503
504 DO i = 1, nele
505 ALLOCATE (nnp_env%rad(i)%y(nnp_env%n_rad(i)))
506 ALLOCATE (nnp_env%rad(i)%funccut(nnp_env%n_rad(i)))
507 ALLOCATE (nnp_env%rad(i)%eta(nnp_env%n_rad(i)))
508 ALLOCATE (nnp_env%rad(i)%rs(nnp_env%n_rad(i)))
509 ALLOCATE (nnp_env%rad(i)%loc_min(nnp_env%n_rad(i)))
510 ALLOCATE (nnp_env%rad(i)%loc_max(nnp_env%n_rad(i)))
511 ALLOCATE (nnp_env%rad(i)%loc_av(nnp_env%n_rad(i)))
512 ALLOCATE (nnp_env%rad(i)%sigma(nnp_env%n_rad(i)))
513 ALLOCATE (nnp_env%rad(i)%ele(nnp_env%n_rad(i)))
514 ALLOCATE (nnp_env%rad(i)%nuc_ele(nnp_env%n_rad(i)))
515 nnp_env%rad(i)%funccut = 0.0_dp
516 nnp_env%rad(i)%eta = 0.0_dp
517 nnp_env%rad(i)%rs = 0.0_dp
518 nnp_env%rad(i)%ele = 'X'
519 nnp_env%rad(i)%nuc_ele = 0
520
521 ALLOCATE (nnp_env%ang(i)%y(nnp_env%n_ang(i)))
522 ALLOCATE (nnp_env%ang(i)%funccut(nnp_env%n_ang(i)))
523 ALLOCATE (nnp_env%ang(i)%eta(nnp_env%n_ang(i)))
524 ALLOCATE (nnp_env%ang(i)%zeta(nnp_env%n_ang(i)))
525 ALLOCATE (nnp_env%ang(i)%prefzeta(nnp_env%n_ang(i)))
526 ALLOCATE (nnp_env%ang(i)%lam(nnp_env%n_ang(i)))
527 ALLOCATE (nnp_env%ang(i)%loc_min(nnp_env%n_ang(i)))
528 ALLOCATE (nnp_env%ang(i)%loc_max(nnp_env%n_ang(i)))
529 ALLOCATE (nnp_env%ang(i)%loc_av(nnp_env%n_ang(i)))
530 ALLOCATE (nnp_env%ang(i)%sigma(nnp_env%n_ang(i)))
531 ALLOCATE (nnp_env%ang(i)%ele1(nnp_env%n_ang(i)))
532 ALLOCATE (nnp_env%ang(i)%ele2(nnp_env%n_ang(i)))
533 ALLOCATE (nnp_env%ang(i)%nuc_ele1(nnp_env%n_ang(i)))
534 ALLOCATE (nnp_env%ang(i)%nuc_ele2(nnp_env%n_ang(i)))
535 nnp_env%ang(i)%funccut = 0.0_dp
536 nnp_env%ang(i)%eta = 0.0_dp
537 nnp_env%ang(i)%zeta = 0.0_dp
538 nnp_env%ang(i)%prefzeta = 1.0_dp
539 nnp_env%ang(i)%lam = 0.0_dp
540 nnp_env%ang(i)%ele1 = 'X'
541 nnp_env%ang(i)%ele2 = 'X'
542 nnp_env%ang(i)%nuc_ele1 = 0
543 nnp_env%ang(i)%nuc_ele2 = 0
544
545 ! set number of nodes
546 nnp_env%arc(i)%n_nodes(1) = nnp_env%n_rad(i) + nnp_env%n_ang(i)
547 nnp_env%arc(i)%n_nodes(2:nnp_env%n_layer - 1) = nnp_env%n_hnodes
548 nnp_env%arc(i)%n_nodes(nnp_env%n_layer) = 1
549 DO j = 1, nnp_env%n_layer
550 ALLOCATE (nnp_env%arc(i)%layer(j)%node(nnp_env%arc(i)%n_nodes(j)))
551 ALLOCATE (nnp_env%arc(i)%layer(j)%node_grad(nnp_env%arc(i)%n_nodes(j)))
552 ALLOCATE (nnp_env%arc(i)%layer(j)%tmp_der(nnp_env%arc(i)%n_nodes(1), nnp_env%arc(i)%n_nodes(j)))
553 END DO
554 END DO
555
556 ! read, bcast and sort symfnct parameters
557 DO i = 1, nele
558 nnp_env%n_rad(i) = 0
559 nnp_env%n_ang(i) = 0
560 END DO
561 CALL parser_reset(parser)
562 first = .true.
563 nnp_env%max_cut = 0.0_dp
564 DO
565 CALL parser_search_string(parser, "symfunction_short", .true., found, line)
566 IF (found) THEN
567 READ (line, *) dummy, ele, symfnct_type
568 DO i = 1, nele
569 IF (trim(ele) == nnp_env%ele(i)) THEN
570 IF (symfnct_type == 2) THEN
571 nnp_env%n_rad(i) = nnp_env%n_rad(i) + 1
572 READ (line, *) dummy, ele, symfnct_type, &
573 nnp_env%rad(i)%ele(nnp_env%n_rad(i)), &
574 nnp_env%rad(i)%eta(nnp_env%n_rad(i)), &
575 nnp_env%rad(i)%rs(nnp_env%n_rad(i)), &
576 nnp_env%rad(i)%funccut(nnp_env%n_rad(i))
577 IF (nnp_env%max_cut < nnp_env%rad(i)%funccut(nnp_env%n_rad(i))) THEN
578 nnp_env%max_cut = nnp_env%rad(i)%funccut(nnp_env%n_rad(i))
579 END IF
580 ELSE IF (symfnct_type == 3) THEN
581 nnp_env%n_ang(i) = nnp_env%n_ang(i) + 1
582 READ (line, *) dummy, ele, symfnct_type, &
583 nnp_env%ang(i)%ele1(nnp_env%n_ang(i)), &
584 nnp_env%ang(i)%ele2(nnp_env%n_ang(i)), &
585 nnp_env%ang(i)%eta(nnp_env%n_ang(i)), &
586 nnp_env%ang(i)%lam(nnp_env%n_ang(i)), &
587 nnp_env%ang(i)%zeta(nnp_env%n_ang(i)), &
588 nnp_env%ang(i)%funccut(nnp_env%n_ang(i))
589 nnp_env%ang(i)%prefzeta(nnp_env%n_ang(i)) = &
590 2.0_dp**(1.0_dp - nnp_env%ang(i)%zeta(nnp_env%n_ang(i)))
591 IF (nnp_env%max_cut < nnp_env%ang(i)%funccut(nnp_env%n_ang(i))) THEN
592 nnp_env%max_cut = nnp_env%ang(i)%funccut(nnp_env%n_ang(i))
593 END IF
594 ELSE
595 CALL cp_abort(__location__, trim(printtag)// &
596 "| Symmetry function type not supported")
597 END IF
598 END IF
599 END DO
600 first = .false.
601 ELSE
602 IF (first) CALL cp_abort(__location__, trim(printtag)// &
603 "| no symfunction_short specified in NNP_INPUT_FILE")
604 ! no additional symfnct found
605 EXIT
606 END IF
607 END DO
608
609 DO i = 1, nele
610 DO j = 1, nnp_env%n_rad(i)
611 CALL get_ptable_info(nnp_env%rad(i)%ele(j), number=nnp_env%rad(i)%nuc_ele(j))
612 END DO
613 DO j = 1, nnp_env%n_ang(i)
614 CALL get_ptable_info(nnp_env%ang(i)%ele1(j), number=nnp_env%ang(i)%nuc_ele1(j))
615 CALL get_ptable_info(nnp_env%ang(i)%ele2(j), number=nnp_env%ang(i)%nuc_ele2(j))
616 ! sort ele1 and ele2
617 IF (nnp_env%ang(i)%nuc_ele1(j) > nnp_env%ang(i)%nuc_ele2(j)) THEN
618 ele = nnp_env%ang(i)%ele1(j)
619 nnp_env%ang(i)%ele1(j) = nnp_env%ang(i)%ele2(j)
620 nnp_env%ang(i)%ele2(j) = ele
621 nuc_ele = nnp_env%ang(i)%nuc_ele1(j)
622 nnp_env%ang(i)%nuc_ele1(j) = nnp_env%ang(i)%nuc_ele2(j)
623 nnp_env%ang(i)%nuc_ele2(j) = nuc_ele
624 END IF
625 END DO
626 END DO
627 ! Done with input.nn file
628 CALL parser_release(parser)
629
630 ! sort symmetry functions and output information
631 CALL nnp_sort_acsf(nnp_env)
632 CALL nnp_write_acsf(nnp_env, logger%para_env, printtag)
633 CALL nnp_write_arc(nnp_env, logger%para_env, printtag)
634
635 ! read scaling information from file
636 IF (nnp_env%scale_acsf .OR. nnp_env%center_acsf .OR. nnp_env%scale_sigma_acsf) THEN
637 IF (logger%para_env%is_source()) THEN
638 WRITE (unit_nr, *) trim(printtag)//"| Reading scaling information from file: ", trim(file_name)
639 END IF
640 CALL section_vals_val_get(nnp_env%nnp_input, "SCALE_FILE_NAME", &
641 c_val=file_name)
642 CALL parser_create(parser, file_name, para_env=logger%para_env)
643
644 ! Get number of elements in scaling file
645 CALL parser_read_line(parser, 1)
646 k = 0
647 DO WHILE (k < 7)
648 READ (parser%input_line, *, iostat=io) test_array(1:k)
649 IF (io == -1) EXIT
650 k = k + 1
651 END DO
652 k = k - 1
653
654 IF (k == 5 .AND. nnp_env%scale_sigma_acsf) THEN
655 cpabort("Sigma scaling requested, but scaling.data does not contain sigma.")
656 END IF
657
658 CALL parser_reset(parser)
659 DO i = 1, nnp_env%n_ele
660 DO j = 1, nnp_env%n_rad(i)
661 CALL parser_read_line(parser, 1)
662 IF (nnp_env%scale_sigma_acsf) THEN
663 READ (parser%input_line, *) dummy, dummy, &
664 nnp_env%rad(i)%loc_min(j), &
665 nnp_env%rad(i)%loc_max(j), &
666 nnp_env%rad(i)%loc_av(j), &
667 nnp_env%rad(i)%sigma(j)
668 ELSE
669 READ (parser%input_line, *) dummy, dummy, &
670 nnp_env%rad(i)%loc_min(j), &
671 nnp_env%rad(i)%loc_max(j), &
672 nnp_env%rad(i)%loc_av(j)
673 END IF
674 END DO
675 DO j = 1, nnp_env%n_ang(i)
676 CALL parser_read_line(parser, 1)
677 IF (nnp_env%scale_sigma_acsf) THEN
678 READ (parser%input_line, *) dummy, dummy, &
679 nnp_env%ang(i)%loc_min(j), &
680 nnp_env%ang(i)%loc_max(j), &
681 nnp_env%ang(i)%loc_av(j), &
682 nnp_env%ang(i)%sigma(j)
683 ELSE
684 READ (parser%input_line, *) dummy, dummy, &
685 nnp_env%ang(i)%loc_min(j), &
686 nnp_env%ang(i)%loc_max(j), &
687 nnp_env%ang(i)%loc_av(j)
688 END IF
689 END DO
690 END DO
691 CALL parser_release(parser)
692 END IF
693
694 CALL nnp_init_acsf_groups(nnp_env)
695
696 ! read weights from file
697 DO i = 1, nnp_env%n_ele
698 DO j = 2, nnp_env%n_layer
699 ALLOCATE (nnp_env%arc(i)%layer(j)%weights(nnp_env%arc(i)%n_nodes(j - 1), &
700 nnp_env%arc(i)%n_nodes(j), nnp_env%n_committee))
701 ALLOCATE (nnp_env%arc(i)%layer(j)%bweights(nnp_env%arc(i)%n_nodes(j), nnp_env%n_committee))
702 END DO
703 END DO
704 DO i_com = 1, nnp_env%n_committee
705 CALL section_vals_val_get(model_section, "WEIGHTS", c_val=base_name, i_rep_section=i_com)
706 IF (logger%para_env%is_source()) THEN
707 WRITE (unit_nr, *) trim(printtag)//"| Initializing weights for model: ", i_com
708 END IF
709 DO i = 1, nnp_env%n_ele
710 WRITE (file_name, '(A,I0.3,A)') trim(base_name)//".", nnp_env%nuc_ele(i), ".data"
711 IF (logger%para_env%is_source()) THEN
712 WRITE (unit_nr, *) trim(printtag)//"| Reading weights from file: ", trim(file_name)
713 END IF
714 CALL parser_create(parser, file_name, para_env=logger%para_env)
715 n_weight = 0
716 DO WHILE (.true.)
717 CALL parser_read_line(parser, 1, at_end)
718 IF (at_end) EXIT
719 n_weight = n_weight + 1
720 END DO
721
722 ALLOCATE (weights(n_weight))
723
724 CALL parser_reset(parser)
725 DO j = 1, n_weight
726 CALL parser_read_line(parser, 1)
727 READ (parser%input_line, *) weights(j)
728 END DO
729 CALL parser_release(parser)
730
731 ! sort weights into corresponding arrays
732 iweight = 0
733 DO j = 2, nnp_env%n_layer
734 DO k = 1, nnp_env%arc(i)%n_nodes(j - 1)
735 DO l = 1, nnp_env%arc(i)%n_nodes(j)
736 iweight = iweight + 1
737 nnp_env%arc(i)%layer(j)%weights(k, l, i_com) = weights(iweight)
738 END DO
739 END DO
740
741 DO k = 1, nnp_env%arc(i)%n_nodes(j)
742 iweight = iweight + 1
743 nnp_env%arc(i)%layer(j)%bweights(k, i_com) = weights(iweight)
744 END DO
745 END DO
746
747 DEALLOCATE (weights)
748 END DO
749 END DO
750
751 !Initialize extrapolation counter
752 nnp_env%expol = 0
753
754 ! Bias the standard deviation of committee disagreement
755 NULLIFY (bias_section)
756 explicit = .false.
757 !HELIUM NNP does atm not allow for bias (not even defined)
758 bias_section => section_vals_get_subs_vals(nnp_env%nnp_input, "BIAS", can_return_null=.true.)
759 IF (ASSOCIATED(bias_section)) CALL section_vals_get(bias_section, explicit=explicit)
760 nnp_env%bias = .false.
761 IF (explicit) THEN
762 IF (nnp_env%n_committee > 1) THEN
763 IF (logger%para_env%is_source()) THEN
764 WRITE (unit_nr, *) "NNP| Biasing of committee disagreement enabled"
765 END IF
766 nnp_env%bias = .true.
767 ALLOCATE (nnp_env%bias_forces(3, nnp_env%num_atoms))
768 ALLOCATE (nnp_env%bias_e_avrg(nnp_env%n_committee))
769 CALL section_vals_val_get(bias_section, "SIGMA_0", r_val=nnp_env%bias_sigma0)
770 CALL section_vals_val_get(bias_section, "K_B", r_val=nnp_env%bias_kb)
771 nnp_env%bias_e_avrg(:) = 0.0_dp
772 CALL section_vals_val_get(bias_section, "ALIGN_NNP_ENERGIES", explicit=explicit)
773 nnp_env%bias_align = explicit
774 IF (explicit) THEN
775 NULLIFY (work)
776 CALL section_vals_val_get(bias_section, "ALIGN_NNP_ENERGIES", r_vals=work)
777 IF (SIZE(work) /= nnp_env%n_committee) THEN
778 cpabort("ALIGN_NNP_ENERGIES size mismatch wrt committee size.")
779 END IF
780 nnp_env%bias_e_avrg(:) = work
781 IF (logger%para_env%is_source()) THEN
782 WRITE (unit_nr, *) trim(printtag)//"| Biasing is aligned by shifting the energy prediction of the C-NNP members"
783 END IF
784 END IF
785 ELSE
786 cpwarn("NNP committee size is 1, BIAS section is ignored.")
787 END IF
788 END IF
789
790 IF (logger%para_env%is_source()) THEN
791 WRITE (unit_nr, *) trim(printtag)//"| NNP force environment initialized"
792 END IF
793
794 CALL timestop(handle)
795
796 END SUBROUTINE nnp_init_model
797
798END MODULE nnp_environment
Define the atomic kind types and their sub types.
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
Handles all functions related to the CELL.
Definition cell_types.F:15
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Utility routines to read data from files. Kept as close as possible to the old parser because.
subroutine, public parser_read_line(parser, nline, at_end)
Read the next line from a logical unit "unit" (I/O node only). Skip (nline-1) lines and skip also all...
subroutine, public parser_search_string(parser, string, ignore_case, found, line, begin_line, search_from_begin_of_file)
Search a string pattern in a file defined by its logical unit number "unit". A case sensitive search ...
Utility routines to read data from files. Kept as close as possible to the old parser because.
subroutine, public parser_reset(parser)
Resets the parser: rewinding the unit and re-initializing all parser structures.
subroutine, public parser_release(parser)
releases the parser
subroutine, public parser_create(parser, file_name, unit_nr, para_env, end_section_label, separator_chars, comment_char, continuation_char, quote_char, section_char, parse_white_lines, initial_variables, apply_preprocessing)
Start a parser run. Initial variables allow to @SET stuff before opening the file.
Initialize a small environment for a particular calculation.
subroutine, public cp_subsys_create(subsys, para_env, root_section, force_env_section, subsys_section, use_motion_section, qmmm, qmmm_env, exclusions, elkind)
Creates allocates and fills subsys from given input.
types that represent a subsys, i.e. a part of the system
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
subroutine, public distribution_1d_release(distribution_1d)
releases the given distribution_1d
Distribution methods for atoms, particles, or molecules.
subroutine, public distribute_molecules_1d(atomic_kind_set, particle_set, local_particles, molecule_kind_set, molecule_set, local_molecules, force_env_section, prev_molecule_kind_set, prev_local_molecules)
Distribute molecules and particles.
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_path_length
Definition kinds.F:58
Interface to the message passing library MPI.
Define the molecule kind structure types and the corresponding functionality.
subroutine, public write_molecule_kind_set(molecule_kind_set, subsys_section)
Write a moleculeatomic kind set data set to the output unit.
Define the data structure for the molecule information.
Functionality for atom centered symmetry functions for neural network potentials.
Definition nnp_acsf.F:14
subroutine, public nnp_write_acsf(nnp, para_env, printtag)
Write symmetry function information.
Definition nnp_acsf.F:1197
subroutine, public nnp_init_acsf_groups(nnp)
Initialize symmetry function groups.
Definition nnp_acsf.F:1055
subroutine, public nnp_sort_acsf(nnp)
Sort symmetry functions according to different criteria.
Definition nnp_acsf.F:796
subroutine, public nnp_sort_ele(ele, nuc_ele)
Sort element array according to atomic number.
Definition nnp_acsf.F:756
Data types for neural network potentials.
integer, parameter, public nnp_actfnct_lin
subroutine, public nnp_env_set(nnp_env, nnp_forces, subsys, atomic_kind_set, particle_set, local_particles, molecule_kind_set, molecule_set, local_molecules, nnp_input, force_env_input, cell, cell_ref, use_ref_cell, nnp_potential_energy)
Sets various attributes of the nnp environment.
integer, parameter, public nnp_actfnct_cos
integer, parameter, public nnp_actfnct_invsig
integer, parameter, public nnp_actfnct_sig
integer, parameter, public nnp_actfnct_exp
integer, parameter, public nnp_actfnct_softplus
integer, parameter, public nnp_actfnct_quad
integer, parameter, public nnp_actfnct_gaus
integer, parameter, public nnp_actfnct_tanh
Methods dealing with Neural Network potentials.
subroutine, public nnp_init_model(nnp_env, printtag)
Initialize the Neural Network Potential.
subroutine, public nnp_init(nnp_env, root_section, para_env, force_env_section, subsys_section, use_motion_section)
Read and initialize all the information for neural network potentials.
Methods dealing with core routines for artificial neural networks.
Definition nnp_model.F:13
subroutine, public nnp_write_arc(nnp, para_env, printtag)
Write neural network architecture information.
Definition nnp_model.F:47
Define methods related to particle_type.
subroutine, public write_fist_particle_coordinates(particle_set, subsys_section, charges)
Write the atomic coordinates to the output unit.
subroutine, public write_structure_data(particle_set, cell, input_section)
Write structure data requested by a separate structure data input section to the output unit....
subroutine, public write_particle_distances(particle_set, cell, subsys_section)
Write the matrix of the particle distances to the output unit.
Define the data structure for the particle information.
Periodic Table related data definitions.
subroutine, public get_ptable_info(symbol, number, amass, ielement, covalent_radius, metallic_radius, vdw_radius, found)
Pass information about the kind given the element symbol.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represents a system: atoms, molecules, their pos,vel,...
structure to store local (to a processor) ordered lists of integers.
stores all the informations relevant to an mpi environment
Main data type collecting all relevant data for neural network potentials.