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