(git:3f0d10b)
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-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 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 ! The helium-solute coupling has no device force path, so this environment
94 ! stays on the CPU and never claims the per-process GPU state.
95 CALL nnp_init_model(nnp, "HELIUM NNP", gpu_capable=.false.)
96
97 periodicity = 0
98 IF (helium%periodic) periodicity = 1
99 NULLIFY (he_cell)
100 CALL cell_create(he_cell, hmat=helium%cell_m, &
101 periodic=periodicity, tag="HELIUM NNP")
102 CALL nnp_env_set(nnp, cell=he_cell)
103 CALL cell_release(he_cell)
104
105 ! Set up arrays for calculation:
106 ALLOCATE (nnp%ele_ind(nnp%num_atoms))
107 ALLOCATE (nnp%nuc_atoms(nnp%num_atoms))
108 ALLOCATE (nnp%coord(3, nnp%num_atoms))
109 ALLOCATE (nnp%nnp_forces(3, nnp%num_atoms))
110 ALLOCATE (nnp%atoms(nnp%num_atoms))
111 ALLOCATE (nnp%sort(nnp%num_atoms - 1))
112
113 !fill arrays, assume that order will not change during simulation
114 ig = 1
115 is = 1
116 DO i = 1, nnp%n_ele
117 IF (nnp%ele(i) == 'He') THEN
118 nnp%atoms(ig) = 'He'
119 CALL get_ptable_info(nnp%atoms(ig) (1:2), number=nnp%nuc_atoms(ig))
120 nnp%ele_ind(ig) = i
121 ig = ig + 1
122 END IF
123 DO j = 1, helium%solute_atoms
124 IF (nnp%ele(i) == helium%solute_element(j)) THEN
125 nnp%atoms(ig) = nnp%ele(i)
126 CALL get_ptable_info(nnp%atoms(ig) (1:2), number=nnp%nuc_atoms(ig))
127 nnp%ele_ind(ig) = i
128 nnp%sort(is) = j
129 ig = ig + 1
130 is = is + 1
131 END IF
132 END DO
133 END DO
134
135 ALLOCATE (helium%nnp_sr_cut(nnp%n_ele))
136 helium%nnp_sr_cut = 0.0_dp
137
138 sr_cutoff_section => section_vals_get_subs_vals(nnp%nnp_input, "SR_CUTOFF")
139 CALL section_vals_get(sr_cutoff_section, n_repetition=is)
140 DO i = 1, is
141 CALL section_vals_val_get(sr_cutoff_section, "ELEMENT", c_val=elem, i_rep_section=i)
142 found = .false.
143 DO ig = 1, nnp%n_ele
144 IF (trim(nnp%ele(ig)) == trim(elem)) THEN
145 found = .true.
146 CALL section_vals_val_get(sr_cutoff_section, "RADIUS", r_val=helium%nnp_sr_cut(ig), &
147 i_rep_section=i)
148 END IF
149 END DO
150 IF (.NOT. found) THEN
151 msg_str = "SR_CUTOFF for element "//trim(elem)//" defined but not found in NNP"
152 cpwarn(msg_str)
153 END IF
154 END DO
155 helium%nnp_sr_cut(:) = helium%nnp_sr_cut(:)**2
156
157 RETURN
158
159 END SUBROUTINE helium_init_nnp
160
161! **************************************************************************************************
162!> \brief Print properties according to the requests in input file
163!> \param nnp ...
164!> \param print_section ...
165!> \param ind_he ...
166!> \date 2023-07-31
167!> \author Laura Duran
168! **************************************************************************************************
169 SUBROUTINE helium_nnp_print(nnp, print_section, ind_he)
170 TYPE(nnp_type), INTENT(INOUT) :: nnp
171 TYPE(section_vals_type), INTENT(IN), POINTER :: print_section
172 INTEGER, INTENT(IN) :: ind_he
173
174 INTEGER :: unit_nr
175 LOGICAL :: file_is_new
176 TYPE(cp_logger_type), POINTER :: logger
177 TYPE(section_vals_type), POINTER :: print_key
178
179 NULLIFY (logger, print_key)
180 logger => cp_get_default_logger()
181
182 print_key => section_vals_get_subs_vals(print_section, "ENERGIES")
183 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
184 unit_nr = cp_print_key_unit_nr(logger, print_key, extension=".data", &
185 middle_name="helium-nnp-energies", is_new_file=file_is_new)
186 IF (unit_nr > 0) CALL helium_nnp_print_energies(nnp, unit_nr, file_is_new)
187 CALL cp_print_key_finished_output(unit_nr, logger, print_key)
188 END IF
189
190 print_key => section_vals_get_subs_vals(print_section, "FORCES_SIGMA")
191 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
192 unit_nr = cp_print_key_unit_nr(logger, print_key, extension=".data", &
193 middle_name="helium-nnp-forces-std", is_new_file=file_is_new)
194 IF (unit_nr > 0) CALL helium_nnp_print_force_sigma(nnp, unit_nr, file_is_new)
195 CALL cp_print_key_finished_output(unit_nr, logger, print_key)
196 END IF
197
198 CALL logger%para_env%sum(nnp%output_expol)
199 IF (nnp%output_expol) THEN
200 print_key => section_vals_get_subs_vals(print_section, "EXTRAPOLATION")
201 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
202 unit_nr = cp_print_key_unit_nr(logger, print_key, extension=".xyz", &
203 middle_name="-NNP-He-extrapolation")
204 IF (unit_nr > 0) CALL helium_nnp_print_expol(nnp, unit_nr, ind_he)
205 CALL cp_print_key_finished_output(unit_nr, logger, print_key)
206 END IF
207 END IF
208
209 END SUBROUTINE helium_nnp_print
210
211! **************************************************************************************************
212!> \brief Print NNP energies and standard deviation sigma
213!> \param nnp ...
214!> \param unit_nr ...
215!> \param file_is_new ...
216!> \date 2023-07-31
217!> \author Laura Duran
218! **************************************************************************************************
219 SUBROUTINE helium_nnp_print_energies(nnp, unit_nr, file_is_new)
220 TYPE(nnp_type), INTENT(INOUT) :: nnp
221 INTEGER, INTENT(IN) :: unit_nr
222 LOGICAL, INTENT(IN) :: file_is_new
223
224 CHARACTER(len=default_path_length) :: fmt_string
225 INTEGER :: i
226 REAL(kind=dp) :: std
227
228 IF (file_is_new) THEN
229 WRITE (unit_nr, "(A1,1X,A20)", advance='no') "#", "NNP Average [a.u.],"
230 WRITE (unit_nr, "(A20)", advance='no') "NNP sigma [a.u.]"
231 DO i = 1, nnp%n_committee
232 WRITE (unit_nr, "(A17,I3)", advance='no') "NNP", i
233 END DO
234 WRITE (unit_nr, "(A)") ""
235 END IF
236
237 fmt_string = "(2X,2(F20.9))"
238 WRITE (fmt_string, "(A,I3,A)") "(2X", nnp%n_committee + 2, "(F20.9))"
239 std = sum((sum(nnp%atomic_energy, 1) - nnp%nnp_potential_energy)**2)
240 std = std/real(nnp%n_committee, dp)
241 std = sqrt(std)
242 WRITE (unit_nr, fmt_string) nnp%nnp_potential_energy, std, sum(nnp%atomic_energy, 1)
243
244 END SUBROUTINE helium_nnp_print_energies
245
246! **************************************************************************************************
247!> \brief Print standard deviation sigma of NNP forces
248!> \param nnp ...
249!> \param unit_nr ...
250!> \param file_is_new ...
251!> \date 2023-07-31
252!> \author Laura Duran
253! **************************************************************************************************
254 SUBROUTINE helium_nnp_print_force_sigma(nnp, unit_nr, file_is_new)
255 TYPE(nnp_type), INTENT(INOUT) :: nnp
256 INTEGER, INTENT(IN) :: unit_nr
257 LOGICAL, INTENT(IN) :: file_is_new
258
259 INTEGER :: i, ig, j
260 REAL(kind=dp), DIMENSION(3) :: var
261
262 IF (unit_nr > 0) THEN
263 IF (file_is_new) THEN
264 WRITE (unit_nr, "(A,1X,A)") "# NNP sigma of forces [a.u.] x, y, z coordinates"
265 END IF
266
267 ig = 1
268 DO i = 1, nnp%num_atoms
269 IF (nnp%ele(i) == 'He') THEN
270 var = 0.0_dp
271 DO j = 1, nnp%n_committee
272 var = var + (nnp%committee_forces(:, i, j) - nnp%nnp_forces(:, i))**2
273 END DO
274 WRITE (unit_nr, "(A4,1X,3E20.10)") nnp%ele(i), var
275 END IF
276 ig = ig + 1
277 END DO
278 END IF
279
280 END SUBROUTINE helium_nnp_print_force_sigma
281
282! **************************************************************************************************
283!> \brief Print structures with extrapolation warning
284!> \param nnp ...
285!> \param unit_nr ...
286!> \param ind_he ...
287!> \date 2023-10-11
288!> \author Harald Forbert (harald.forbert@rub.de)
289! **************************************************************************************************
290 SUBROUTINE helium_nnp_print_expol(nnp, unit_nr, ind_he)
291 TYPE(nnp_type), INTENT(INOUT) :: nnp
292 INTEGER, INTENT(IN) :: unit_nr, ind_he
293
294 CHARACTER(len=default_path_length) :: fmt_string
295 INTEGER :: i
296 REAL(kind=dp) :: mass, unit_conv
297 REAL(kind=dp), DIMENSION(3) :: com
298 TYPE(cell_type), POINTER :: cell
299
300 NULLIFY (cell)
301 CALL nnp_env_get(nnp_env=nnp, cell=cell)
302
303 nnp%expol = nnp%expol + 1
304 WRITE (unit_nr, *) nnp%num_atoms
305 WRITE (unit_nr, "(A,1X,I6)") "HELIUM-NNP extrapolation point N =", nnp%expol
306
307 ! move to COM of solute and wrap the box
308 ! coord not needed afterwards, therefore manipulation ok
309 com = 0.0_dp
310 mass = 0.0_dp
311 DO i = 1, nnp%num_atoms
312 IF (i == ind_he) cycle
313 CALL get_ptable_info(nnp%atoms(i) (1:2), amass=unit_conv)
314 com(:) = com(:) + nnp%coord(:, i)*unit_conv
315 mass = mass + unit_conv
316 END DO
317 com(:) = com(:)/mass
318
319 DO i = 1, nnp%num_atoms
320 nnp%coord(:, i) = nnp%coord(:, i) - com(:)
321 nnp%coord(:, i) = pbc(nnp%coord(:, i), cell)
322 END DO
323
324 unit_conv = cp_unit_from_cp2k(1.0_dp, trim("angstrom"))
325 fmt_string = "(A4,1X,3F20.10)"
326 DO i = 1, nnp%num_atoms
327 WRITE (unit_nr, fmt_string) &
328 nnp%atoms(i), &
329 nnp%coord(1, i)*unit_conv, &
330 nnp%coord(2, i)*unit_conv, &
331 nnp%coord(3, i)*unit_conv
332 END DO
333
334 END SUBROUTINE helium_nnp_print_expol
335
336END 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:704
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...
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...
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, file_access)
...
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:1311
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:170
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, gpu_capable)
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:60
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.