(git:1f285aa)
nnp_environment.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 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 
15  USE atomic_kind_types, ONLY: atomic_kind_type
16  USE bibliography, ONLY: behler2007,&
17  behler2011,&
18  schran2020a,&
19  schran2020b,&
20  cite_reference
21  USE cell_methods, ONLY: read_cell,&
23  USE cell_types, ONLY: cell_release,&
24  cell_type,&
25  get_cell
28  cp_logger_type
31  USE cp_parser_types, ONLY: cp_parser_type,&
36  USE cp_subsys_types, ONLY: cp_subsys_set,&
37  cp_subsys_type
39  distribution_1d_type
43  section_vals_type,&
45  USE kinds, ONLY: default_path_length,&
46  dp
47  USE message_passing, ONLY: mp_para_env_type
48  USE molecule_kind_types, ONLY: molecule_kind_type,&
50  USE molecule_types, ONLY: molecule_type
51  USE nnp_acsf, ONLY: nnp_init_acsf_groups,&
53  nnp_sort_ele,&
55  USE nnp_environment_types, ONLY: &
58  nnp_type
59  USE nnp_model, ONLY: nnp_write_arc
63  USE particle_types, ONLY: particle_type
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 
77 CONTAINS
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, &
252  default_path_length = 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 
351  CALL parser_search_string(parser, "normalize_nodes", .true., found, &
352  search_from_begin_of_file=.true.)
353  nnp_env%normnodes = found
354 
355  CALL parser_search_string(parser, "cutoff_type", .true., found, line, &
356  search_from_begin_of_file=.true.)
357  IF (found) THEN
358  READ (line, *) dummy, nnp_env%cut_type
359  ELSE
360  CALL cp_abort(__location__, trim(printtag)// &
361  "| no cutoff type specified in NNP_INPUT_FILE")
362  END IF
363 
364  CALL parser_search_string(parser, "global_hidden_layers_short", .true., found, line, &
365  search_from_begin_of_file=.true.)
366  IF (found) THEN
367  READ (line, *) dummy, nnp_env%n_hlayer
368  ELSE
369  CALL cp_abort(__location__, trim(printtag)// &
370  "| number of hidden layers missing in NNP_INPUT_FILE")
371  END IF
372  nnp_env%n_layer = nnp_env%n_hlayer + 2
373 
374  nele = nnp_env%n_ele
375  ALLOCATE (nnp_env%rad(nele))
376  ALLOCATE (nnp_env%ang(nele))
377  ALLOCATE (nnp_env%n_rad(nele))
378  ALLOCATE (nnp_env%n_ang(nele))
379  ALLOCATE (nnp_env%actfnct(nnp_env%n_hlayer + 1))
380  ALLOCATE (cactfnct(nnp_env%n_hlayer + 1))
381  ALLOCATE (nnp_env%ele(nele))
382  ALLOCATE (nnp_env%nuc_ele(nele))
383  ALLOCATE (nnp_env%arc(nele))
384  DO i = 1, nele
385  ALLOCATE (nnp_env%arc(i)%layer(nnp_env%n_layer))
386  ALLOCATE (nnp_env%arc(i)%n_nodes(nnp_env%n_layer))
387  END DO
388  ALLOCATE (nnp_env%n_hnodes(nnp_env%n_hlayer))
389  ALLOCATE (nnp_env%atom_energies(nele))
390  nnp_env%atom_energies = 0.0_dp
391 
392  ! read elements, broadcast and sort
393  CALL parser_reset(parser)
394  DO
395  CALL parser_search_string(parser, "elements", .true., found, line)
396  IF (found) THEN
397  READ (line, *) dummy
398  IF (trim(adjustl(dummy)) == "elements") THEN
399  READ (line, *) dummy, nnp_env%ele(:)
400  CALL nnp_sort_ele(nnp_env%ele, nnp_env%nuc_ele)
401  EXIT
402  END IF
403  ELSE
404  CALL cp_abort(__location__, trim(printtag)// &
405  "| elements not specified in NNP_INPUT_FILE")
406  END IF
407  END DO
408 
409  CALL parser_search_string(parser, "remove_atom_energies", .true., atom_e_found, &
410  search_from_begin_of_file=.true.)
411 
412  IF (atom_e_found) THEN
413  CALL parser_reset(parser)
414  i = 0
415  DO
416  CALL parser_search_string(parser, "atom_energy", .true., found, line)
417  IF (found) THEN
418  READ (line, *) dummy, ele, energy
419  DO j = 1, nele
420  IF (nnp_env%ele(j) == trim(ele)) THEN
421  i = i + 1
422  nnp_env%atom_energies(j) = energy
423  END IF
424  END DO
425  IF (i == nele) EXIT
426  ELSE
427  CALL cp_abort(__location__, trim(printtag)// &
428  "| atom energies are not specified")
429  END IF
430  END DO
431  END IF
432 
433  CALL parser_search_string(parser, "global_nodes_short", .true., found, line, &
434  search_from_begin_of_file=.true.)
435  IF (found) THEN
436  READ (line, *) dummy, nnp_env%n_hnodes(:)
437  ELSE
438  CALL cp_abort(__location__, trim(printtag)// &
439  "NNP| global_nodes_short not specified in NNP_INPUT_FILE")
440  END IF
441 
442  CALL parser_search_string(parser, "global_activation_short", .true., found, line, &
443  search_from_begin_of_file=.true.)
444  IF (found) THEN
445  READ (line, *) dummy, cactfnct(:)
446  ELSE
447  CALL cp_abort(__location__, trim(printtag)// &
448  "| global_activation_short not specified in NNP_INPUT_FILE")
449  END IF
450 
451  DO i = 1, nnp_env%n_hlayer + 1
452  SELECT CASE (cactfnct(i))
453  CASE ("t")
454  nnp_env%actfnct(i) = nnp_actfnct_tanh
455  CASE ("g")
456  nnp_env%actfnct(i) = nnp_actfnct_gaus
457  CASE ("l")
458  nnp_env%actfnct(i) = nnp_actfnct_lin
459  CASE ("c")
460  nnp_env%actfnct(i) = nnp_actfnct_cos
461  CASE ("s")
462  nnp_env%actfnct(i) = nnp_actfnct_sig
463  CASE ("S")
464  nnp_env%actfnct(i) = nnp_actfnct_invsig
465  CASE ("e")
466  nnp_env%actfnct(i) = nnp_actfnct_exp
467  CASE ("p")
468  nnp_env%actfnct(i) = nnp_actfnct_softplus
469  CASE ("h")
470  nnp_env%actfnct(i) = nnp_actfnct_quad
471  CASE DEFAULT
472  CALL cp_abort(__location__, trim(printtag)// &
473  "| Activation function unkown")
474  END SELECT
475  END DO
476 
477  ! determine n_rad and n_ang
478  DO i = 1, nele
479  nnp_env%n_rad(i) = 0
480  nnp_env%n_ang(i) = 0
481  END DO
482 
483  ! count symfunctions
484  CALL parser_reset(parser)
485  first = .true.
486  DO
487  CALL parser_search_string(parser, "symfunction_short", .true., found, line)
488  IF (found) THEN
489  READ (line, *) dummy, ele, symfnct_type
490  DO i = 1, nele
491  IF (trim(ele) .EQ. nnp_env%ele(i)) THEN
492  IF (symfnct_type .EQ. 2) THEN
493  nnp_env%n_rad(i) = nnp_env%n_rad(i) + 1
494  ELSE IF (symfnct_type .EQ. 3) THEN
495  nnp_env%n_ang(i) = nnp_env%n_ang(i) + 1
496  ELSE
497  CALL cp_abort(__location__, trim(printtag)// &
498  "| Symmetry function type not supported")
499  END IF
500  END IF
501  END DO
502  first = .false.
503  ELSE
504  IF (first) CALL cp_abort(__location__, trim(printtag)// &
505  "| no symfunction_short specified in NNP_INPUT_FILE")
506  ! no additional symfnct found
507  EXIT
508  END IF
509  END DO
510 
511  DO i = 1, nele
512  ALLOCATE (nnp_env%rad(i)%y(nnp_env%n_rad(i)))
513  ALLOCATE (nnp_env%rad(i)%funccut(nnp_env%n_rad(i)))
514  ALLOCATE (nnp_env%rad(i)%eta(nnp_env%n_rad(i)))
515  ALLOCATE (nnp_env%rad(i)%rs(nnp_env%n_rad(i)))
516  ALLOCATE (nnp_env%rad(i)%loc_min(nnp_env%n_rad(i)))
517  ALLOCATE (nnp_env%rad(i)%loc_max(nnp_env%n_rad(i)))
518  ALLOCATE (nnp_env%rad(i)%loc_av(nnp_env%n_rad(i)))
519  ALLOCATE (nnp_env%rad(i)%sigma(nnp_env%n_rad(i)))
520  ALLOCATE (nnp_env%rad(i)%ele(nnp_env%n_rad(i)))
521  ALLOCATE (nnp_env%rad(i)%nuc_ele(nnp_env%n_rad(i)))
522  nnp_env%rad(i)%funccut = 0.0_dp
523  nnp_env%rad(i)%eta = 0.0_dp
524  nnp_env%rad(i)%rs = 0.0_dp
525  nnp_env%rad(i)%ele = 'X'
526  nnp_env%rad(i)%nuc_ele = 0
527 
528  ALLOCATE (nnp_env%ang(i)%y(nnp_env%n_ang(i)))
529  ALLOCATE (nnp_env%ang(i)%funccut(nnp_env%n_ang(i)))
530  ALLOCATE (nnp_env%ang(i)%eta(nnp_env%n_ang(i)))
531  ALLOCATE (nnp_env%ang(i)%zeta(nnp_env%n_ang(i)))
532  ALLOCATE (nnp_env%ang(i)%prefzeta(nnp_env%n_ang(i)))
533  ALLOCATE (nnp_env%ang(i)%lam(nnp_env%n_ang(i)))
534  ALLOCATE (nnp_env%ang(i)%loc_min(nnp_env%n_ang(i)))
535  ALLOCATE (nnp_env%ang(i)%loc_max(nnp_env%n_ang(i)))
536  ALLOCATE (nnp_env%ang(i)%loc_av(nnp_env%n_ang(i)))
537  ALLOCATE (nnp_env%ang(i)%sigma(nnp_env%n_ang(i)))
538  ALLOCATE (nnp_env%ang(i)%ele1(nnp_env%n_ang(i)))
539  ALLOCATE (nnp_env%ang(i)%ele2(nnp_env%n_ang(i)))
540  ALLOCATE (nnp_env%ang(i)%nuc_ele1(nnp_env%n_ang(i)))
541  ALLOCATE (nnp_env%ang(i)%nuc_ele2(nnp_env%n_ang(i)))
542  nnp_env%ang(i)%funccut = 0.0_dp
543  nnp_env%ang(i)%eta = 0.0_dp
544  nnp_env%ang(i)%zeta = 0.0_dp
545  nnp_env%ang(i)%prefzeta = 1.0_dp
546  nnp_env%ang(i)%lam = 0.0_dp
547  nnp_env%ang(i)%ele1 = 'X'
548  nnp_env%ang(i)%ele2 = 'X'
549  nnp_env%ang(i)%nuc_ele1 = 0
550  nnp_env%ang(i)%nuc_ele2 = 0
551 
552  ! set number of nodes
553  nnp_env%arc(i)%n_nodes(1) = nnp_env%n_rad(i) + nnp_env%n_ang(i)
554  nnp_env%arc(i)%n_nodes(2:nnp_env%n_layer - 1) = nnp_env%n_hnodes
555  nnp_env%arc(i)%n_nodes(nnp_env%n_layer) = 1
556  DO j = 1, nnp_env%n_layer
557  ALLOCATE (nnp_env%arc(i)%layer(j)%node(nnp_env%arc(i)%n_nodes(j)))
558  ALLOCATE (nnp_env%arc(i)%layer(j)%node_grad(nnp_env%arc(i)%n_nodes(j)))
559  ALLOCATE (nnp_env%arc(i)%layer(j)%tmp_der(nnp_env%arc(i)%n_nodes(1), nnp_env%arc(i)%n_nodes(j)))
560  END DO
561  END DO
562 
563  ! read, bcast and sort symfnct parameters
564  DO i = 1, nele
565  nnp_env%n_rad(i) = 0
566  nnp_env%n_ang(i) = 0
567  END DO
568  CALL parser_reset(parser)
569  first = .true.
570  nnp_env%max_cut = 0.0_dp
571  DO
572  CALL parser_search_string(parser, "symfunction_short", .true., found, line)
573  IF (found) THEN
574  READ (line, *) dummy, ele, symfnct_type
575  DO i = 1, nele
576  IF (trim(ele) .EQ. nnp_env%ele(i)) THEN
577  IF (symfnct_type .EQ. 2) THEN
578  nnp_env%n_rad(i) = nnp_env%n_rad(i) + 1
579  READ (line, *) dummy, ele, symfnct_type, &
580  nnp_env%rad(i)%ele(nnp_env%n_rad(i)), &
581  nnp_env%rad(i)%eta(nnp_env%n_rad(i)), &
582  nnp_env%rad(i)%rs(nnp_env%n_rad(i)), &
583  nnp_env%rad(i)%funccut(nnp_env%n_rad(i))
584  IF (nnp_env%max_cut < nnp_env%rad(i)%funccut(nnp_env%n_rad(i))) THEN
585  nnp_env%max_cut = nnp_env%rad(i)%funccut(nnp_env%n_rad(i))
586  END IF
587  ELSE IF (symfnct_type .EQ. 3) THEN
588  nnp_env%n_ang(i) = nnp_env%n_ang(i) + 1
589  READ (line, *) dummy, ele, symfnct_type, &
590  nnp_env%ang(i)%ele1(nnp_env%n_ang(i)), &
591  nnp_env%ang(i)%ele2(nnp_env%n_ang(i)), &
592  nnp_env%ang(i)%eta(nnp_env%n_ang(i)), &
593  nnp_env%ang(i)%lam(nnp_env%n_ang(i)), &
594  nnp_env%ang(i)%zeta(nnp_env%n_ang(i)), &
595  nnp_env%ang(i)%funccut(nnp_env%n_ang(i))
596  nnp_env%ang(i)%prefzeta(nnp_env%n_ang(i)) = &
597  2.0_dp**(1.0_dp - nnp_env%ang(i)%zeta(nnp_env%n_ang(i)))
598  IF (nnp_env%max_cut < nnp_env%ang(i)%funccut(nnp_env%n_ang(i))) THEN
599  nnp_env%max_cut = nnp_env%ang(i)%funccut(nnp_env%n_ang(i))
600  END IF
601  ELSE
602  CALL cp_abort(__location__, trim(printtag)// &
603  "| Symmetry function type not supported")
604  END IF
605  END IF
606  END DO
607  first = .false.
608  ELSE
609  IF (first) CALL cp_abort(__location__, trim(printtag)// &
610  "| no symfunction_short specified in NNP_INPUT_FILE")
611  ! no additional symfnct found
612  EXIT
613  END IF
614  END DO
615 
616  DO i = 1, nele
617  DO j = 1, nnp_env%n_rad(i)
618  CALL get_ptable_info(nnp_env%rad(i)%ele(j), number=nnp_env%rad(i)%nuc_ele(j))
619  END DO
620  DO j = 1, nnp_env%n_ang(i)
621  CALL get_ptable_info(nnp_env%ang(i)%ele1(j), number=nnp_env%ang(i)%nuc_ele1(j))
622  CALL get_ptable_info(nnp_env%ang(i)%ele2(j), number=nnp_env%ang(i)%nuc_ele2(j))
623  ! sort ele1 and ele2
624  IF (nnp_env%ang(i)%nuc_ele1(j) .GT. nnp_env%ang(i)%nuc_ele2(j)) THEN
625  ele = nnp_env%ang(i)%ele1(j)
626  nnp_env%ang(i)%ele1(j) = nnp_env%ang(i)%ele2(j)
627  nnp_env%ang(i)%ele2(j) = ele
628  nuc_ele = nnp_env%ang(i)%nuc_ele1(j)
629  nnp_env%ang(i)%nuc_ele1(j) = nnp_env%ang(i)%nuc_ele2(j)
630  nnp_env%ang(i)%nuc_ele2(j) = nuc_ele
631  END IF
632  END DO
633  END DO
634  ! Done with input.nn file
635  CALL parser_release(parser)
636 
637  ! sort symmetry functions and output information
638  CALL nnp_sort_acsf(nnp_env)
639  CALL nnp_write_acsf(nnp_env, logger%para_env, printtag)
640  CALL nnp_write_arc(nnp_env, logger%para_env, printtag)
641 
642  ! read scaling information from file
643  IF (nnp_env%scale_acsf .OR. nnp_env%center_acsf .OR. nnp_env%scale_sigma_acsf) THEN
644  IF (logger%para_env%is_source()) THEN
645  WRITE (unit_nr, *) trim(printtag)//"| Reading scaling information from file: ", trim(file_name)
646  END IF
647  CALL section_vals_val_get(nnp_env%nnp_input, "SCALE_FILE_NAME", &
648  c_val=file_name)
649  CALL parser_create(parser, file_name, para_env=logger%para_env)
650 
651  ! Get number of elements in scaling file
652  CALL parser_read_line(parser, 1)
653  k = 0
654  DO WHILE (k < 7)
655  READ (parser%input_line, *, iostat=io) test_array(1:k)
656  IF (io == -1) EXIT
657  k = k + 1
658  END DO
659  k = k - 1
660 
661  IF (k == 5 .AND. nnp_env%scale_sigma_acsf) THEN
662  cpabort("Sigma scaling requested, but scaling.data does not contain sigma.")
663  END IF
664 
665  CALL parser_reset(parser)
666  DO i = 1, nnp_env%n_ele
667  DO j = 1, nnp_env%n_rad(i)
668  CALL parser_read_line(parser, 1)
669  IF (nnp_env%scale_sigma_acsf) THEN
670  READ (parser%input_line, *) dummy, dummy, &
671  nnp_env%rad(i)%loc_min(j), &
672  nnp_env%rad(i)%loc_max(j), &
673  nnp_env%rad(i)%loc_av(j), &
674  nnp_env%rad(i)%sigma(j)
675  ELSE
676  READ (parser%input_line, *) dummy, dummy, &
677  nnp_env%rad(i)%loc_min(j), &
678  nnp_env%rad(i)%loc_max(j), &
679  nnp_env%rad(i)%loc_av(j)
680  END IF
681  END DO
682  DO j = 1, nnp_env%n_ang(i)
683  CALL parser_read_line(parser, 1)
684  IF (nnp_env%scale_sigma_acsf) THEN
685  READ (parser%input_line, *) dummy, dummy, &
686  nnp_env%ang(i)%loc_min(j), &
687  nnp_env%ang(i)%loc_max(j), &
688  nnp_env%ang(i)%loc_av(j), &
689  nnp_env%ang(i)%sigma(j)
690  ELSE
691  READ (parser%input_line, *) dummy, dummy, &
692  nnp_env%ang(i)%loc_min(j), &
693  nnp_env%ang(i)%loc_max(j), &
694  nnp_env%ang(i)%loc_av(j)
695  END IF
696  END DO
697  END DO
698  CALL parser_release(parser)
699  END IF
700 
701  CALL nnp_init_acsf_groups(nnp_env)
702 
703  ! read weights from file
704  DO i = 1, nnp_env%n_ele
705  DO j = 2, nnp_env%n_layer
706  ALLOCATE (nnp_env%arc(i)%layer(j)%weights(nnp_env%arc(i)%n_nodes(j - 1), &
707  nnp_env%arc(i)%n_nodes(j), nnp_env%n_committee))
708  ALLOCATE (nnp_env%arc(i)%layer(j)%bweights(nnp_env%arc(i)%n_nodes(j), nnp_env%n_committee))
709  END DO
710  END DO
711  DO i_com = 1, nnp_env%n_committee
712  CALL section_vals_val_get(model_section, "WEIGHTS", c_val=base_name, i_rep_section=i_com)
713  IF (logger%para_env%is_source()) THEN
714  WRITE (unit_nr, *) trim(printtag)//"| Initializing weights for model: ", i_com
715  END IF
716  DO i = 1, nnp_env%n_ele
717  WRITE (file_name, '(A,I0.3,A)') trim(base_name)//".", nnp_env%nuc_ele(i), ".data"
718  IF (logger%para_env%is_source()) THEN
719  WRITE (unit_nr, *) trim(printtag)//"| Reading weights from file: ", trim(file_name)
720  END IF
721  CALL parser_create(parser, file_name, para_env=logger%para_env)
722  n_weight = 0
723  DO WHILE (.true.)
724  CALL parser_read_line(parser, 1, at_end)
725  IF (at_end) EXIT
726  n_weight = n_weight + 1
727  END DO
728 
729  ALLOCATE (weights(n_weight))
730 
731  CALL parser_reset(parser)
732  DO j = 1, n_weight
733  CALL parser_read_line(parser, 1)
734  READ (parser%input_line, *) weights(j)
735  END DO
736  CALL parser_release(parser)
737 
738  ! sort weights into corresponding arrays
739  iweight = 0
740  DO j = 2, nnp_env%n_layer
741  DO k = 1, nnp_env%arc(i)%n_nodes(j - 1)
742  DO l = 1, nnp_env%arc(i)%n_nodes(j)
743  iweight = iweight + 1
744  nnp_env%arc(i)%layer(j)%weights(k, l, i_com) = weights(iweight)
745  END DO
746  END DO
747 
748  DO k = 1, nnp_env%arc(i)%n_nodes(j)
749  iweight = iweight + 1
750  nnp_env%arc(i)%layer(j)%bweights(k, i_com) = weights(iweight)
751  END DO
752  END DO
753 
754  DEALLOCATE (weights)
755  END DO
756  END DO
757 
758  !Initialize extrapolation counter
759  nnp_env%expol = 0
760 
761  ! Bias the standard deviation of committee disagreement
762  NULLIFY (bias_section)
763  explicit = .false.
764  !HELIUM NNP does atm not allow for bias (not even defined)
765  bias_section => section_vals_get_subs_vals(nnp_env%nnp_input, "BIAS", can_return_null=.true.)
766  IF (ASSOCIATED(bias_section)) CALL section_vals_get(bias_section, explicit=explicit)
767  nnp_env%bias = .false.
768  IF (explicit) THEN
769  IF (nnp_env%n_committee > 1) THEN
770  IF (logger%para_env%is_source()) THEN
771  WRITE (unit_nr, *) "NNP| Biasing of committee disagreement enabled"
772  END IF
773  nnp_env%bias = .true.
774  ALLOCATE (nnp_env%bias_forces(3, nnp_env%num_atoms))
775  ALLOCATE (nnp_env%bias_e_avrg(nnp_env%n_committee))
776  CALL section_vals_val_get(bias_section, "SIGMA_0", r_val=nnp_env%bias_sigma0)
777  CALL section_vals_val_get(bias_section, "K_B", r_val=nnp_env%bias_kb)
778  nnp_env%bias_e_avrg(:) = 0.0_dp
779  CALL section_vals_val_get(bias_section, "ALIGN_NNP_ENERGIES", explicit=explicit)
780  nnp_env%bias_align = explicit
781  IF (explicit) THEN
782  NULLIFY (work)
783  CALL section_vals_val_get(bias_section, "ALIGN_NNP_ENERGIES", r_vals=work)
784  IF (SIZE(work) .NE. nnp_env%n_committee) THEN
785  cpabort("ALIGN_NNP_ENERGIES size mismatch wrt committee size.")
786  END IF
787  nnp_env%bias_e_avrg(:) = work
788  IF (logger%para_env%is_source()) THEN
789  WRITE (unit_nr, *) trim(printtag)//"| Biasing is aligned by shifting the energy prediction of the C-NNP members"
790  END IF
791  END IF
792  ELSE
793  cpwarn("NNP committee size is 1, BIAS section is ignored.")
794  END IF
795  END IF
796 
797  IF (logger%para_env%is_source()) THEN
798  WRITE (unit_nr, *) trim(printtag)//"| NNP force environment initialized"
799  END IF
800 
801  CALL timestop(handle)
802 
803  END SUBROUTINE nnp_init_model
804 
805 END 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...
Definition: bibliography.F:28
integer, save, public schran2020b
Definition: bibliography.F:43
integer, save, public schran2020a
Definition: bibliography.F:43
integer, save, public behler2011
Definition: bibliography.F:43
integer, save, public behler2007
Definition: bibliography.F:43
Handles all functions related to the CELL.
Definition: cell_methods.F:15
recursive subroutine, public read_cell(cell, cell_ref, use_ref_cell, cell_section, check_for_ref, para_env)
...
Definition: cell_methods.F:272
subroutine, public write_cell(cell, subsys_section, tag)
Write the cell parameters to the output unit.
Definition: cell_methods.F:731
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.