(git:374b731)
Loading...
Searching...
No Matches
helium_nnp.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 interaction potential
10!> \author Laura Duran
11!> \date 2023-02-17
12! **************************************************************************************************
14
15 USE bibliography, ONLY: behler2007,&
19 cite_reference
20 USE cell_methods, ONLY: cell_create
21 USE cell_types, ONLY: cell_release,&
22 cell_type,&
23 pbc
26 USE cp_output_handling, ONLY: cp_p_file,&
36 USE kinds, ONLY: default_path_length,&
38 dp
44 USE physcon, ONLY: angstrom
45#include "../base/base_uses.f90"
46
47 IMPLICIT NONE
48
49 PRIVATE
50
51 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .true.
52 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'helium_nnp'
53
54 PUBLIC :: helium_init_nnp, &
56
57CONTAINS
58
59! ***************************************************************************
60!> \brief Read and initialize all the information for neural network potentials
61!> \param helium ...
62!> \param nnp ...
63!> \param input ...
64!> \date 2023-02-21
65!> \author lduran
66! **************************************************************************************************
67 SUBROUTINE helium_init_nnp(helium, nnp, input)
68 TYPE(helium_solvent_type), INTENT(INOUT) :: helium
69 TYPE(nnp_type), POINTER :: nnp
70 TYPE(section_vals_type), POINTER :: input
71
72 CHARACTER(len=default_path_length) :: msg_str
73 CHARACTER(len=default_string_length) :: elem
74 INTEGER :: i, ig, is, j
75 INTEGER, DIMENSION(3) :: periodicity
76 LOGICAL :: found
77 TYPE(cell_type), POINTER :: he_cell
78 TYPE(cp_logger_type), POINTER :: logger
79 TYPE(section_vals_type), POINTER :: sr_cutoff_section
80
81 CALL cite_reference(behler2007)
82 CALL cite_reference(behler2011)
83 CALL cite_reference(schran2020a)
84 CALL cite_reference(schran2020b)
85
86 NULLIFY (logger)
87 logger => cp_get_default_logger()
88
89 CALL nnp_env_set(nnp_env=nnp, nnp_input=input)
90
91 nnp%num_atoms = helium%solute_atoms + 1
92
93 CALL nnp_init_model(nnp, "HELIUM NNP")
94
95 periodicity = 0
96 IF (helium%periodic) periodicity = 1
97 NULLIFY (he_cell)
98 CALL cell_create(he_cell, hmat=helium%cell_m, &
99 periodic=periodicity, tag="HELIUM NNP")
100 CALL nnp_env_set(nnp, cell=he_cell)
101 CALL cell_release(he_cell)
102
103 ! Set up arrays for calculation:
104 ALLOCATE (nnp%ele_ind(nnp%num_atoms))
105 ALLOCATE (nnp%nuc_atoms(nnp%num_atoms))
106 ALLOCATE (nnp%coord(3, nnp%num_atoms))
107 ALLOCATE (nnp%nnp_forces(3, nnp%num_atoms))
108 ALLOCATE (nnp%atoms(nnp%num_atoms))
109 ALLOCATE (nnp%sort(nnp%num_atoms - 1))
110
111 !fill arrays, assume that order will not change during simulation
112 ig = 1
113 is = 1
114 DO i = 1, nnp%n_ele
115 IF (nnp%ele(i) == 'He') THEN
116 nnp%atoms(ig) = 'He'
117 CALL get_ptable_info(nnp%atoms(ig), number=nnp%nuc_atoms(ig))
118 nnp%ele_ind(ig) = i
119 ig = ig + 1
120 END IF
121 DO j = 1, helium%solute_atoms
122 IF (nnp%ele(i) == helium%solute_element(j)) THEN
123 nnp%atoms(ig) = nnp%ele(i)
124 CALL get_ptable_info(nnp%atoms(ig), number=nnp%nuc_atoms(ig))
125 nnp%ele_ind(ig) = i
126 nnp%sort(is) = j
127 ig = ig + 1
128 is = is + 1
129 END IF
130 END DO
131 END DO
132
133 ALLOCATE (helium%nnp_sr_cut(nnp%n_ele))
134 helium%nnp_sr_cut = 0.0_dp
135
136 sr_cutoff_section => section_vals_get_subs_vals(nnp%nnp_input, "SR_CUTOFF")
137 CALL section_vals_get(sr_cutoff_section, n_repetition=is)
138 DO i = 1, is
139 CALL section_vals_val_get(sr_cutoff_section, "ELEMENT", c_val=elem, i_rep_section=i)
140 found = .false.
141 DO ig = 1, nnp%n_ele
142 IF (trim(nnp%ele(ig)) == trim(elem)) THEN
143 found = .true.
144 CALL section_vals_val_get(sr_cutoff_section, "RADIUS", r_val=helium%nnp_sr_cut(ig), &
145 i_rep_section=i)
146 END IF
147 END DO
148 IF (.NOT. found) THEN
149 msg_str = "SR_CUTOFF for element "//trim(elem)//" defined but not found in NNP"
150 cpwarn(msg_str)
151 END IF
152 END DO
153 helium%nnp_sr_cut(:) = helium%nnp_sr_cut(:)**2
154
155 RETURN
156
157 END SUBROUTINE helium_init_nnp
158
159! **************************************************************************************************
160!> \brief Print properties according to the requests in input file
161!> \param nnp ...
162!> \param print_section ...
163!> \param ind_he ...
164!> \date 2023-07-31
165!> \author Laura Duran
166! **************************************************************************************************
167 SUBROUTINE helium_nnp_print(nnp, print_section, ind_he)
168 TYPE(nnp_type), INTENT(INOUT) :: nnp
169 TYPE(section_vals_type), INTENT(IN), POINTER :: print_section
170 INTEGER, INTENT(IN) :: ind_he
171
172 INTEGER :: unit_nr
173 LOGICAL :: file_is_new
174 TYPE(cp_logger_type), POINTER :: logger
175 TYPE(section_vals_type), POINTER :: print_key
176
177 NULLIFY (logger, print_key)
178 logger => cp_get_default_logger()
179
180 print_key => section_vals_get_subs_vals(print_section, "ENERGIES")
181 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
182 unit_nr = cp_print_key_unit_nr(logger, print_key, extension=".data", &
183 middle_name="helium-nnp-energies", is_new_file=file_is_new)
184 IF (unit_nr > 0) CALL helium_nnp_print_energies(nnp, unit_nr, file_is_new)
185 CALL cp_print_key_finished_output(unit_nr, logger, print_key)
186 END IF
187
188 print_key => section_vals_get_subs_vals(print_section, "FORCES_SIGMA")
189 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
190 unit_nr = cp_print_key_unit_nr(logger, print_key, extension=".data", &
191 middle_name="helium-nnp-forces-std", is_new_file=file_is_new)
192 IF (unit_nr > 0) CALL helium_nnp_print_force_sigma(nnp, unit_nr, file_is_new)
193 CALL cp_print_key_finished_output(unit_nr, logger, print_key)
194 END IF
195
196 CALL logger%para_env%sum(nnp%output_expol)
197 IF (nnp%output_expol) THEN
198 print_key => section_vals_get_subs_vals(print_section, "EXTRAPOLATION")
199 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
200 unit_nr = cp_print_key_unit_nr(logger, print_key, extension=".xyz", &
201 middle_name="-NNP-He-extrapolation")
202 IF (unit_nr > 0) CALL helium_nnp_print_expol(nnp, unit_nr, ind_he)
203 CALL cp_print_key_finished_output(unit_nr, logger, print_key)
204 END IF
205 END IF
206
207 END SUBROUTINE helium_nnp_print
208
209! **************************************************************************************************
210!> \brief Print NNP energies and standard deviation sigma
211!> \param nnp ...
212!> \param unit_nr ...
213!> \param file_is_new ...
214!> \date 2023-07-31
215!> \author Laura Duran
216! **************************************************************************************************
217 SUBROUTINE helium_nnp_print_energies(nnp, unit_nr, file_is_new)
218 TYPE(nnp_type), INTENT(INOUT) :: nnp
219 INTEGER, INTENT(IN) :: unit_nr
220 LOGICAL, INTENT(IN) :: file_is_new
221
222 CHARACTER(len=default_path_length) :: fmt_string
223 INTEGER :: i
224 REAL(kind=dp) :: std
225
226 IF (file_is_new) THEN
227 WRITE (unit_nr, "(A1,1X,A20)", advance='no') "#", "NNP Average [a.u.],"
228 WRITE (unit_nr, "(A20)", advance='no') "NNP sigma [a.u.]"
229 DO i = 1, nnp%n_committee
230 WRITE (unit_nr, "(A17,I3)", advance='no') "NNP", i
231 END DO
232 WRITE (unit_nr, "(A)") ""
233 END IF
234
235 fmt_string = "(2X,2(F20.9))"
236 WRITE (fmt_string, "(A,I3,A)") "(2X", nnp%n_committee + 2, "(F20.9))"
237 std = sum((sum(nnp%atomic_energy, 1) - nnp%nnp_potential_energy)**2)
238 std = std/real(nnp%n_committee, dp)
239 std = sqrt(std)
240 WRITE (unit_nr, fmt_string) nnp%nnp_potential_energy, std, sum(nnp%atomic_energy, 1)
241
242 END SUBROUTINE helium_nnp_print_energies
243
244! **************************************************************************************************
245!> \brief Print standard deviation sigma of NNP forces
246!> \param nnp ...
247!> \param unit_nr ...
248!> \param file_is_new ...
249!> \date 2023-07-31
250!> \author Laura Duran
251! **************************************************************************************************
252 SUBROUTINE helium_nnp_print_force_sigma(nnp, unit_nr, file_is_new)
253 TYPE(nnp_type), INTENT(INOUT) :: nnp
254 INTEGER, INTENT(IN) :: unit_nr
255 LOGICAL, INTENT(IN) :: file_is_new
256
257 INTEGER :: i, ig, j
258 REAL(kind=dp), DIMENSION(3) :: var
259
260 IF (unit_nr > 0) THEN
261 IF (file_is_new) THEN
262 WRITE (unit_nr, "(A,1X,A)") "# NNP sigma of forces [a.u.] x, y, z coordinates"
263 END IF
264
265 ig = 1
266 DO i = 1, nnp%num_atoms
267 IF (nnp%ele(i) == 'He') THEN
268 var = 0.0_dp
269 DO j = 1, nnp%n_committee
270 var = var + (nnp%committee_forces(:, i, j) - nnp%nnp_forces(:, i))**2
271 END DO
272 WRITE (unit_nr, "(A4,1X,3E20.10)") nnp%ele(i), var
273 END IF
274 ig = ig + 1
275 END DO
276 END IF
277
278 END SUBROUTINE helium_nnp_print_force_sigma
279
280! **************************************************************************************************
281!> \brief Print structures with extrapolation warning
282!> \param nnp ...
283!> \param unit_nr ...
284!> \param ind_he ...
285!> \date 2023-10-11
286!> \author Harald Forbert (harald.forbert@rub.de)
287! **************************************************************************************************
288 SUBROUTINE helium_nnp_print_expol(nnp, unit_nr, ind_he)
289 TYPE(nnp_type), INTENT(INOUT) :: nnp
290 INTEGER, INTENT(IN) :: unit_nr, ind_he
291
292 CHARACTER(len=default_path_length) :: fmt_string
293 INTEGER :: i
294 REAL(kind=dp) :: mass, unit_conv
295 REAL(kind=dp), DIMENSION(3) :: com
296 TYPE(cell_type), POINTER :: cell
297
298 NULLIFY (cell)
299 CALL nnp_env_get(nnp_env=nnp, cell=cell)
300
301 nnp%expol = nnp%expol + 1
302 WRITE (unit_nr, *) nnp%num_atoms
303 WRITE (unit_nr, "(A,1X,I6)") "HELIUM-NNP extrapolation point N =", nnp%expol
304
305 ! move to COM of solute and wrap the box
306 ! coord not needed afterwards, therefore manipulation ok
307 com = 0.0_dp
308 mass = 0.0_dp
309 DO i = 1, nnp%num_atoms
310 IF (i == ind_he) cycle
311 CALL get_ptable_info(nnp%atoms(i), amass=unit_conv)
312 com(:) = com(:) + nnp%coord(:, i)*unit_conv
313 mass = mass + unit_conv
314 END DO
315 com(:) = com(:)/mass
316
317 DO i = 1, nnp%num_atoms
318 nnp%coord(:, i) = nnp%coord(:, i) - com(:)
319 nnp%coord(:, i) = pbc(nnp%coord(:, i), cell)
320 END DO
321
322 unit_conv = cp_unit_from_cp2k(1.0_dp, trim("angstrom"))
323 fmt_string = "(A4,1X,3F20.10)"
324 DO i = 1, nnp%num_atoms
325 WRITE (unit_nr, fmt_string) &
326 nnp%atoms(i), &
327 nnp%coord(1, i)*unit_conv, &
328 nnp%coord(2, i)*unit_conv, &
329 nnp%coord(3, i)*unit_conv
330 END DO
331
332 END SUBROUTINE helium_nnp_print_expol
333
334END MODULE helium_nnp
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public schran2020b
integer, save, public schran2020a
integer, save, public behler2011
integer, save, public behler2007
Handles all functions related to the CELL.
subroutine, public cell_create(cell, hmat, periodic, tag)
allocates and initializes a cell
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
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
unit conversion facility
Definition cp_units.F:30
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
Definition cp_units.F:1179
Methods dealing with Neural Network interaction potential.
Definition helium_nnp.F:13
subroutine, public helium_nnp_print(nnp, print_section, ind_he)
Print properties according to the requests in input file.
Definition helium_nnp.F:168
subroutine, public helium_init_nnp(helium, nnp, input)
Read and initialize all the information for neural network potentials.
Definition helium_nnp.F:68
Data types representing superfluid helium.
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_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Data types for neural network potentials.
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.
subroutine, public nnp_env_get(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, virial)
Returns various attributes of the nnp environment.
Methods dealing with Neural Network potentials.
subroutine, public nnp_init_model(nnp_env, printtag)
Initialize the Neural Network Potential.
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.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public angstrom
Definition physcon.F:144
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...
data structure for solvent helium
Main data type collecting all relevant data for neural network potentials.