Line data Source code
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 Data types for neural network potentials
10 : !> \author Christoph Schran (christoph.schran@rub.de)
11 : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
12 : !> \date 2020-10-10
13 : ! **************************************************************************************************
14 : MODULE nnp_environment_types
15 : USE atomic_kind_list_types, ONLY: atomic_kind_list_create,&
16 : atomic_kind_list_release,&
17 : atomic_kind_list_type
18 : USE atomic_kind_types, ONLY: atomic_kind_type
19 : USE cell_types, ONLY: cell_release,&
20 : cell_retain,&
21 : cell_type
22 : USE cp_subsys_types, ONLY: cp_subsys_get,&
23 : cp_subsys_release,&
24 : cp_subsys_set,&
25 : cp_subsys_type
26 : USE distribution_1d_types, ONLY: distribution_1d_type
27 : USE input_section_types, ONLY: section_vals_type
28 : USE kinds, ONLY: default_string_length,&
29 : dp
30 : USE molecule_kind_list_types, ONLY: molecule_kind_list_create,&
31 : molecule_kind_list_release,&
32 : molecule_kind_list_type
33 : USE molecule_kind_types, ONLY: molecule_kind_type
34 : USE molecule_list_types, ONLY: molecule_list_create,&
35 : molecule_list_release,&
36 : molecule_list_type
37 : USE molecule_types, ONLY: molecule_type
38 : USE particle_list_types, ONLY: particle_list_create,&
39 : particle_list_release,&
40 : particle_list_type
41 : USE particle_types, ONLY: particle_type
42 : USE virial_types, ONLY: virial_type
43 : #include "./base/base_uses.f90"
44 :
45 : IMPLICIT NONE
46 :
47 : PRIVATE
48 :
49 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .FALSE.
50 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'nnp_environment_types'
51 :
52 : !> derived data types
53 : PUBLIC :: nnp_type
54 : PUBLIC :: nnp_arc_type
55 : PUBLIC :: nnp_neighbor_type
56 : PUBLIC :: nnp_neigh_grp_type
57 : PUBLIC :: nnp_symfgrp_type
58 : PUBLIC :: nnp_acsf_rad_type
59 : PUBLIC :: nnp_acsf_ang_type
60 : PUBLIC :: nnp_cell_list_cache_type
61 : PUBLIC :: nnp_neighbor_pair_map_type
62 : PUBLIC :: nnp_dGdr_grp_type
63 : PUBLIC :: nnp_neighbor_workspace_type
64 : PUBLIC :: nnp_neighbor_interface_state_type
65 :
66 : ! Public subroutines ***
67 : PUBLIC :: nnp_env_release, &
68 : nnp_env_set, &
69 : nnp_env_get, &
70 : nnp_cell_list_cache_release, &
71 : nnp_neighbor_interface_state_release
72 :
73 : INTEGER, PARAMETER, PUBLIC :: &
74 : nnp_cut_cos = 1, &
75 : nnp_cut_tanh = 2
76 :
77 : INTEGER, PARAMETER, PUBLIC :: &
78 : nnp_actfnct_tanh = 1, &
79 : nnp_actfnct_gaus = 2, &
80 : nnp_actfnct_lin = 3, &
81 : nnp_actfnct_cos = 4, &
82 : nnp_actfnct_sig = 5, &
83 : nnp_actfnct_invsig = 6, &
84 : nnp_actfnct_exp = 7, &
85 : nnp_actfnct_softplus = 8, &
86 : nnp_actfnct_quad = 9
87 :
88 : ! **************************************************************************************************
89 : !> \brief Main data type collecting all relevant data for neural network potentials
90 : !> \author Christoph Schran (christoph.schran@rub.de)
91 : !> \date 2020-10-10
92 : ! **************************************************************************************************
93 : TYPE nnp_type
94 : TYPE(nnp_acsf_rad_type), DIMENSION(:), POINTER :: rad => NULL() ! DIM(n_ele)
95 : TYPE(nnp_acsf_ang_type), DIMENSION(:), POINTER :: ang => NULL() ! DIM(n_ele)
96 : INTEGER, DIMENSION(:), ALLOCATABLE :: n_rad ! # radial symfnct for this element
97 : INTEGER, DIMENSION(:), ALLOCATABLE :: n_ang ! # angular symfnct for this element
98 : INTEGER :: n_ele = -1 ! # elements
99 : CHARACTER(len=2), ALLOCATABLE, DIMENSION(:) :: ele ! elements(n_ele)
100 : INTEGER, ALLOCATABLE, DIMENSION(:) :: nuc_ele ! elements(n_ele)
101 : LOGICAL :: scale_acsf = .FALSE.
102 : LOGICAL :: scale_sigma_acsf = .FALSE.
103 : LOGICAL :: center_acsf = .FALSE.
104 : LOGICAL :: normnodes = .FALSE.
105 : INTEGER :: n_radgrp = -1
106 : INTEGER :: n_anggrp = -1
107 : INTEGER :: cut_type = -1 ! cutofftype
108 : REAL(KIND=dp) :: eshortmin = -1.0_dp
109 : REAL(KIND=dp) :: eshortmax = -1.0_dp
110 : REAL(KIND=dp) :: scmax = -1.0_dp !scale
111 : REAL(KIND=dp) :: scmin = -1.0_dp !scale
112 : REAL(KIND=dp) :: max_cut = -1.0_dp !largest cutoff
113 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: atom_energies !DIM(n_ele)
114 : TYPE(nnp_arc_type), POINTER, DIMENSION(:) :: arc => NULL() ! DIM(n_ele)
115 : INTEGER :: n_committee = -1
116 : INTEGER :: n_hlayer = -1
117 : INTEGER :: n_layer = -1
118 : INTEGER :: rad_spline_n = 8192 ! knots/radial group (RAD_SPLINE_N)
119 : REAL(KIND=dp) :: verlet_skin = -1.0_dp ! cell-list skin, bohr (VERLET_SKIN; <0 = auto)
120 : INTEGER, ALLOCATABLE, DIMENSION(:) :: n_hnodes
121 : INTEGER, ALLOCATABLE, DIMENSION(:) :: actfnct
122 : INTEGER :: expol = -1 ! extrapolation counter
123 : LOGICAL :: output_expol = .FALSE. ! output extrapolation
124 : ! structures for calculation
125 : INTEGER :: num_atoms = -1
126 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: atomic_energy
127 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: committee_energy
128 : INTEGER, ALLOCATABLE, DIMENSION(:) :: ele_ind, nuc_atoms, sort, sort_inv
129 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: coord
130 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: myforce
131 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: committee_forces, committee_stress
132 : CHARACTER(len=default_string_length), &
133 : ALLOCATABLE, DIMENSION(:) :: atoms
134 : REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: nnp_forces
135 : REAL(KIND=dp) :: nnp_potential_energy = -1.0_dp
136 : TYPE(cp_subsys_type), POINTER :: subsys => NULL()
137 : TYPE(section_vals_type), POINTER :: nnp_input => NULL()
138 : TYPE(section_vals_type), POINTER :: force_env_input => NULL()
139 : TYPE(cell_type), POINTER :: cell => NULL()
140 : TYPE(cell_type), POINTER :: cell_ref => NULL()
141 : LOGICAL :: use_ref_cell = .FALSE.
142 : ! bias
143 : LOGICAL :: bias = .FALSE.
144 : LOGICAL :: bias_align = .FALSE.
145 : REAL(KIND=dp) :: bias_energy = -1.0_dp
146 : REAL(KIND=dp) :: bias_kb = -1.0_dp
147 : REAL(KIND=dp) :: bias_sigma0 = -1.0_dp
148 : REAL(KIND=dp) :: bias_sigma = -1.0_dp
149 : REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: bias_forces
150 : REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: bias_e_avrg
151 : ! Per-nnp persistent neighbour-finder state, owned by nnp_type so committee
152 : ! and MIX force_evals carry independent caches whose lifetime tracks
153 : ! nnp_env_release. Allocated by nnp_prepare_neighbor_cache, freed in
154 : ! nnp_env_release; operated on by nnp_cell_list and nnp_neighbor_interface.
155 : TYPE(nnp_cell_list_cache_type), ALLOCATABLE :: cell_list_cache
156 : TYPE(nnp_neighbor_interface_state_type), ALLOCATABLE :: neighbor_interface_state
157 : END TYPE nnp_type
158 :
159 : ! **************************************************************************************************
160 : !> \brief Symmetry functions group type
161 : !> \param n_symf - # of associated sym fncts
162 : !> \param symf - indices of associated sym fncts DIM(nsymf)
163 : !> \param ele - elements indices rad:DIM(2), ang:DIM(3)
164 : !> \param cutoff - associated cutoff value
165 : !> \author Christoph Schran (christoph.schran@rub.de)
166 : !> \date 2020-10-10
167 : ! **************************************************************************************************
168 : TYPE nnp_symfgrp_type
169 : INTEGER :: n_symf = -1
170 : INTEGER, DIMENSION(:), ALLOCATABLE :: symf
171 : INTEGER, DIMENSION(:), ALLOCATABLE :: ele_ind
172 : CHARACTER(LEN=2), DIMENSION(:), ALLOCATABLE :: ele
173 : REAL(KIND=dp) :: cutoff = -1.0_dp
174 : ! Packed per-member parameters: contiguous arrays sized n_symf so the inner
175 : ! SF loop streams memory instead of indexing ang(ind)%{eta,zeta,lam,prefzeta}
176 : ! through symf(sf). pack_izeta/pack_use_int_zeta skip NINT in the inner loop.
177 : REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: pack_eta
178 : REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: pack_zeta
179 : REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: pack_lam
180 : REAL(KIND=dp), DIMENSION(:), ALLOCATABLE :: pack_prefzeta
181 : INTEGER, DIMENSION(:), ALLOCATABLE :: pack_izeta
182 : LOGICAL, DIMENSION(:), ALLOCATABLE :: pack_use_int_zeta
183 : ! Group-shared Hermite cubic spline tables (radial groups only). All SFs in
184 : ! a group share grp%cutoff, hence one uniform grid (spline_n nodes, spacing
185 : ! spline_dx). y(r) and y'(r) are packed sf-first so nnp_calc_rad streams them
186 : ! after computing the interpolation parameters once per call.
187 : LOGICAL :: spline_built = .FALSE.
188 : INTEGER :: spline_n = 0
189 : REAL(KIND=dp) :: spline_dx = 1.0_dp
190 : REAL(KIND=dp) :: spline_dx_inv = 1.0_dp
191 : REAL(KIND=dp) :: spline_x_max = 0.0_dp
192 : REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: spline_y ! (n_symf, n_grid)
193 : REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE :: spline_dy ! (n_symf, n_grid)
194 : END TYPE nnp_symfgrp_type
195 :
196 : ! **************************************************************************************************
197 : !> \brief Set of radial symmetry function type
198 : !> \param y - acsf value - DIM(n_rad)
199 : !> \param funccut - distance cutoff bohr - DIM(n_rad)
200 : !> \param eta - eta parameter of radial sym fncts bohr^-2 - DIM(n_rad)
201 : !> \param rs - r shift parameter of radial sym fncts bohr - DIM(n_rad)
202 : !> \param loc_min - minimum of the sym fnct DIM(n_rad)
203 : !> \param loc_max - maximum of the sym fnct DIM(n_rad)
204 : !> \param loc_av - average of the sym fnct DIM(n_rad)
205 : !> \param sigma - SD of the sym fnc DIM(n_rad)
206 : !> \param ele - element associated to the sym fnct DIM(n_rad)
207 : !> \param nuc_ele - associated atomic number DIM(n_rad)
208 : !> \author Christoph Schran (christoph.schran@rub.de)
209 : !> \date 2020-10-10
210 : ! **************************************************************************************************
211 : TYPE nnp_acsf_rad_type
212 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: y
213 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: funccut
214 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: eta
215 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: rs
216 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_min
217 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_max
218 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_av
219 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: sigma
220 : CHARACTER(len=2), ALLOCATABLE, DIMENSION(:) :: ele
221 : INTEGER, ALLOCATABLE, DIMENSION(:) :: nuc_ele
222 : INTEGER :: n_symfgrp = -1
223 : TYPE(nnp_symfgrp_type), DIMENSION(:), ALLOCATABLE :: symfgrp
224 : END TYPE nnp_acsf_rad_type
225 :
226 : ! **************************************************************************************************
227 : !> \brief Set of angular symmetry function type
228 : !> \param y - acsf value - DIM(n_ang)
229 : !> \param funccut - distance cutoff bohr - DIM(n_ang)
230 : !> \param eta - eta param. of angular sym fncts bohr^-2 - DIM(n_ang)
231 : !> \param zeta - zeta param. of angular sym fncts DIM(n_ang)
232 : !> \param lam - lambda param. of angular sym fncts DIM(n_ang)
233 : !> \param loc_min - minimum of the sym fnct DIM(n_ang)
234 : !> \param loc_max - maximum of the sym fnct DIM(n_ang)
235 : !> \param loc_av - average of the sym fnct DIM(n_ang)
236 : !> \param sigma - SD of the sym fnc DIM(n_ang)
237 : !> \param ele1,ele2 - elements associated to the sym fnct DIM(n_ang)
238 : !> \param nuc_ele2, nuc_ele2 - associated atomic numbers DIM(n_ang)
239 : !> \author Christoph Schran (christoph.schran@rub.de)
240 : !> \date 2020-10-10
241 : ! **************************************************************************************************
242 : TYPE nnp_acsf_ang_type
243 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: y
244 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: funccut
245 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: eta
246 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: zeta
247 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: prefzeta
248 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: lam
249 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_min
250 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_max
251 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: loc_av
252 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: sigma
253 : CHARACTER(len=2), ALLOCATABLE, DIMENSION(:) :: ele1
254 : CHARACTER(len=2), ALLOCATABLE, DIMENSION(:) :: ele2
255 : INTEGER, ALLOCATABLE, DIMENSION(:) :: nuc_ele1
256 : INTEGER, ALLOCATABLE, DIMENSION(:) :: nuc_ele2
257 : INTEGER :: n_symfgrp = -1
258 : TYPE(nnp_symfgrp_type), DIMENSION(:), ALLOCATABLE :: symfgrp
259 : END TYPE nnp_acsf_ang_type
260 :
261 : ! **************************************************************************************************
262 : !> \brief Per-SF-group dense neighbour container. cap is the allocated slab size;
263 : !> the live count is nnp_neighbor_type%n_rad/n_ang1/n_ang2 for the matching
264 : !> group. ind(j) is the j-th neighbour's atom index; dist(1:3, j) is its
265 : !> displacement and dist(4, j) its norm. Sized lazily by nnp_neigh_grp_grow.
266 : ! **************************************************************************************************
267 : TYPE nnp_neigh_grp_type
268 : INTEGER :: cap = 0
269 : INTEGER, ALLOCATABLE, DIMENSION(:) :: ind ! (cap)
270 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: dist ! (4, cap)
271 : END TYPE nnp_neigh_grp_type
272 :
273 : ! **************************************************************************************************
274 : !> \brief Contains neighbors list of an atom (per-group dense layout).
275 : !> \param n_rad/n_ang1/n_ang2 - live neighbor counts per symfgrp
276 : !> \param rad/ang1/ang2 - per-group dense (ind, dist) containers
277 : !> \author Christoph Schran (christoph.schran@rub.de)
278 : !> \date 2020-10-10
279 : ! **************************************************************************************************
280 : TYPE nnp_neighbor_type
281 : INTEGER, DIMENSION(3) :: pbc_copies = -1
282 : INTEGER, DIMENSION(:), ALLOCATABLE :: n_rad
283 : INTEGER, DIMENSION(:), ALLOCATABLE :: n_ang1
284 : INTEGER, DIMENSION(:), ALLOCATABLE :: n_ang2
285 : TYPE(nnp_neigh_grp_type), ALLOCATABLE, DIMENSION(:) :: rad
286 : TYPE(nnp_neigh_grp_type), ALLOCATABLE, DIMENSION(:) :: ang1
287 : TYPE(nnp_neigh_grp_type), ALLOCATABLE, DIMENSION(:) :: ang2
288 : END TYPE nnp_neighbor_type
289 :
290 : ! **************************************************************************************************
291 : !> \brief Linked-cell + Verlet-skin cache for the NNP descriptor neighbour walk.
292 : !> Persisted across MD steps so the image pool, bin geometry, and
293 : !> reference positions survive between force evaluations and the
294 : !> head/next chain can be reused as long as no atom has drifted more
295 : !> than skin/2. Operated on by nnp_cell_list.F.
296 : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
297 : ! **************************************************************************************************
298 : TYPE nnp_cell_list_cache_type
299 : LOGICAL :: initialized = .FALSE.
300 : INTEGER :: num_atoms = -1
301 : INTEGER :: n_images = 0
302 : INTEGER :: n_cells = 1
303 : INTEGER, DIMENSION(3) :: exact_pbc_copies = 0
304 : INTEGER, DIMENSION(3) :: list_pbc_copies = 0
305 : INTEGER, DIMENSION(3) :: image_copies = 0
306 : INTEGER, DIMENSION(3) :: nbin = 1
307 : INTEGER, DIMENSION(3) :: bin_span = 0
308 : INTEGER, DIMENSION(3) :: perd = 0
309 : LOGICAL :: orthorhombic = .FALSE.
310 : REAL(KIND=dp) :: exact_cutoff = -1.0_dp
311 : REAL(KIND=dp) :: list_cutoff = -1.0_dp
312 : REAL(KIND=dp) :: verlet_skin = 0.0_dp
313 : REAL(KIND=dp), DIMENSION(3) :: lower = 0.0_dp
314 : REAL(KIND=dp), DIMENSION(3) :: upper = 0.0_dp
315 : REAL(KIND=dp), DIMENSION(3) :: bin_width = 1.0_dp
316 : REAL(KIND=dp), DIMENSION(3, 3) :: hmat = 0.0_dp
317 : REAL(KIND=dp), DIMENSION(3, 3) :: h_inv = 0.0_dp
318 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: coord_primary
319 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: coord_scaled
320 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: ref_coord_primary
321 : INTEGER, ALLOCATABLE, DIMENSION(:) :: image_atom
322 : INTEGER, ALLOCATABLE, DIMENSION(:) :: head
323 : INTEGER, ALLOCATABLE, DIMENSION(:) :: next
324 : INTEGER, ALLOCATABLE, DIMENSION(:, :) :: image_shift
325 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: image_translation
326 : END TYPE nnp_cell_list_cache_type
327 :
328 : ! **************************************************************************************************
329 : !> \brief Species-pair routing table. For one (central element, neighbour element)
330 : !> pair, lists which radial / angular symmetry-function groups need that
331 : !> neighbour and the worst-case relevant cutoff.
332 : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
333 : ! **************************************************************************************************
334 : TYPE nnp_neighbor_pair_map_type
335 : INTEGER :: n_rad = 0
336 : INTEGER :: n_ang1 = 0
337 : INTEGER :: n_ang2 = 0
338 : REAL(KIND=dp) :: max_relevant_cutoff = 0.0_dp
339 : INTEGER, ALLOCATABLE, DIMENSION(:) :: rad_groups
340 : INTEGER, ALLOCATABLE, DIMENSION(:) :: ang1_groups
341 : INTEGER, ALLOCATABLE, DIMENSION(:) :: ang2_groups
342 : END TYPE nnp_neighbor_pair_map_type
343 :
344 : ! **************************************************************************************************
345 : !> \brief Per-(element, SF-group) dG_k/dr buffer, sized to the group's n_symf (no
346 : !> max_*_symf padding) and the observed peak neighbour count for the group.
347 : !> Grown lazily (1.5x) so it settles at the true peak.
348 : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
349 : ! **************************************************************************************************
350 : TYPE nnp_dGdr_grp_type
351 : INTEGER :: cap = 0
352 : INTEGER :: n_symf = 0
353 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: data ! (3, n_symf, cap)
354 : END TYPE nnp_dGdr_grp_type
355 :
356 : ! **************************************************************************************************
357 : !> \brief Reusable per-element scratch / persistent caches for the ACSF
358 : !> descriptor and force assembly. See nnp_neighbor_interface for the
359 : !> routines that populate and grow these buffers.
360 : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
361 : ! **************************************************************************************************
362 : TYPE nnp_neighbor_workspace_type
363 : INTEGER :: max_rad_symf = 0
364 : INTEGER :: max_ang_symf = 0
365 : INTEGER :: n_input_nodes = 0
366 : ! High-water mark of the per-element angular-cache slab, tracked so the 1D
367 : ! cutoff caches settle at the true per-element peak.
368 : INTEGER :: cache_cap = 0
369 : ! There is a bug with some older compilers preventing requiring an explicit
370 : ! initialization of allocatable components (see mp2_types.F).
371 : #if defined(FTN_NO_DEFAULT_INIT)
372 : TYPE(nnp_neighbor_type) :: neighbor = nnp_neighbor_type( &
373 : pbc_copies=-1, n_rad=NULL(), &
374 : n_ang1=NULL(), n_ang2=NULL(), &
375 : rad=NULL(), ang1=NULL(), ang2=NULL())
376 : #else
377 : TYPE(nnp_neighbor_type) :: neighbor = nnp_neighbor_type()
378 : #endif
379 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: radial_sym
380 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: radial_force
381 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: angular_sym
382 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: angular_force
383 : ! Per-element persistent cutoff caches reused across this element's central
384 : ! atoms. Sized lazily by nnp_workspace_grow_caches to MAX(n_ang1)/MAX(n_ang2).
385 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: fc_cache1
386 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: dfc_cache1
387 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: fc_cache2
388 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: dfc_cache2
389 : ! Per-neighbour dG_k/dr storage, replacing the global
390 : ! dsymdxyz(3, n_input_nodes, num_atoms) slab. The per-group buffers are
391 : ! dense in (3, n_symf_for_group, n_neighbors_in_group), which shrinks the
392 : ! working set and keeps each group walk a contiguous stride.
393 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: self_dGdr
394 : TYPE(nnp_dGdr_grp_type), ALLOCATABLE, DIMENSION(:) :: dGdr_rad
395 : TYPE(nnp_dGdr_grp_type), ALLOCATABLE, DIMENSION(:) :: dGdr_ang_jj
396 : TYPE(nnp_dGdr_grp_type), ALLOCATABLE, DIMENSION(:) :: dGdr_ang_kk
397 : END TYPE nnp_neighbor_workspace_type
398 :
399 : ! **************************************************************************************************
400 : !> \brief Persistent neighbour-interface state. Owned by nnp_type so that the
401 : !> per-nnp pair-routing tables and per-element workspaces survive
402 : !> across MD steps without leaking between independent &NNP
403 : !> force_evals. Operated on by nnp_neighbor_interface.F.
404 : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
405 : ! **************************************************************************************************
406 : TYPE nnp_neighbor_interface_state_type
407 : LOGICAL :: initialized = .FALSE.
408 : INTEGER :: n_ele = 0
409 : INTEGER, ALLOCATABLE, DIMENSION(:) :: n_rad
410 : INTEGER, ALLOCATABLE, DIMENSION(:) :: n_ang
411 : INTEGER, ALLOCATABLE, DIMENSION(:) :: n_radgrp
412 : INTEGER, ALLOCATABLE, DIMENSION(:) :: n_anggrp
413 : TYPE(nnp_neighbor_pair_map_type), ALLOCATABLE, &
414 : DIMENSION(:, :) :: pair_map
415 : ! (element, thread): one workspace column per OpenMP thread
416 : TYPE(nnp_neighbor_workspace_type), ALLOCATABLE, &
417 : DIMENSION(:, :) :: workspace
418 : END TYPE nnp_neighbor_interface_state_type
419 :
420 : ! **************************************************************************************************
421 : !> \brief Data type for artificial neural networks
422 : !> \author Christoph Schran (christoph.schran@rub.de)
423 : !> \date 2020-10-10
424 : ! **************************************************************************************************
425 : TYPE nnp_arc_type
426 : TYPE(nnp_arc_layer_type), POINTER, DIMENSION(:) :: layer => NULL() ! DIM(n_layer)
427 : INTEGER, ALLOCATABLE, DIMENSION(:) :: n_nodes
428 : END TYPE nnp_arc_type
429 :
430 : ! **************************************************************************************************
431 : !> \brief Data type for individual layer
432 : !> \author Christoph Schran (christoph.schran@rub.de)
433 : !> \date 2020-10-10
434 : ! **************************************************************************************************
435 : TYPE nnp_arc_layer_type
436 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :, :) :: weights ! node weights
437 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: bweights ! bias weights
438 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: node ! DIM(n_nodes)
439 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: node_grad ! DIM(n_nodes)
440 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: tmp_der ! DIM(n_sym,n_nodes)
441 : END TYPE nnp_arc_layer_type
442 :
443 : CONTAINS
444 :
445 : ! **************************************************************************************************
446 : !> \brief Release data structure that holds all the information for neural
447 : !> network potentials
448 : !> \param nnp_env ...
449 : !> \date 2020-10-10
450 : !> \author Christoph Schran (christoph.schran@rub.de)
451 : ! **************************************************************************************************
452 17 : SUBROUTINE nnp_env_release(nnp_env)
453 : TYPE(nnp_type), INTENT(INOUT) :: nnp_env
454 :
455 : INTEGER :: i, j
456 :
457 17 : IF (ASSOCIATED(nnp_env%rad)) THEN
458 52 : DO i = 1, nnp_env%n_ele
459 106 : DO j = 1, nnp_env%rad(i)%n_symfgrp
460 71 : IF (ALLOCATED(nnp_env%rad(i)%symfgrp(j)%symf)) THEN
461 : DEALLOCATE (nnp_env%rad(i)%symfgrp(j)%symf, &
462 0 : nnp_env%rad(i)%symfgrp(j)%ele, &
463 71 : nnp_env%rad(i)%symfgrp(j)%ele_ind)
464 : END IF
465 71 : IF (ALLOCATED(nnp_env%rad(i)%symfgrp(j)%spline_y)) THEN
466 71 : DEALLOCATE (nnp_env%rad(i)%symfgrp(j)%spline_y)
467 : END IF
468 71 : IF (ALLOCATED(nnp_env%rad(i)%symfgrp(j)%spline_dy)) THEN
469 71 : DEALLOCATE (nnp_env%rad(i)%symfgrp(j)%spline_dy)
470 : END IF
471 106 : nnp_env%rad(i)%symfgrp(j)%spline_built = .FALSE.
472 : END DO
473 0 : DEALLOCATE (nnp_env%rad(i)%y, &
474 0 : nnp_env%rad(i)%funccut, &
475 0 : nnp_env%rad(i)%eta, &
476 0 : nnp_env%rad(i)%rs, &
477 0 : nnp_env%rad(i)%loc_min, &
478 0 : nnp_env%rad(i)%loc_max, &
479 0 : nnp_env%rad(i)%loc_av, &
480 0 : nnp_env%rad(i)%sigma, &
481 0 : nnp_env%rad(i)%ele, &
482 0 : nnp_env%rad(i)%nuc_ele, &
483 123 : nnp_env%rad(i)%symfgrp)
484 : END DO
485 17 : DEALLOCATE (nnp_env%rad)
486 : END IF
487 :
488 17 : IF (ASSOCIATED(nnp_env%ang)) THEN
489 52 : DO i = 1, nnp_env%n_ele
490 121 : DO j = 1, nnp_env%ang(i)%n_symfgrp
491 86 : IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%symf)) THEN
492 : DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%symf, &
493 0 : nnp_env%ang(i)%symfgrp(j)%ele, &
494 86 : nnp_env%ang(i)%symfgrp(j)%ele_ind)
495 : END IF
496 86 : IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_eta)) THEN
497 86 : DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_eta)
498 : END IF
499 86 : IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_zeta)) THEN
500 86 : DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_zeta)
501 : END IF
502 86 : IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_lam)) THEN
503 86 : DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_lam)
504 : END IF
505 86 : IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_prefzeta)) THEN
506 86 : DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_prefzeta)
507 : END IF
508 86 : IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_izeta)) THEN
509 86 : DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_izeta)
510 : END IF
511 121 : IF (ALLOCATED(nnp_env%ang(i)%symfgrp(j)%pack_use_int_zeta)) THEN
512 86 : DEALLOCATE (nnp_env%ang(i)%symfgrp(j)%pack_use_int_zeta)
513 : END IF
514 : END DO
515 0 : DEALLOCATE (nnp_env%ang(i)%y, &
516 0 : nnp_env%ang(i)%funccut, &
517 0 : nnp_env%ang(i)%eta, &
518 0 : nnp_env%ang(i)%zeta, &
519 0 : nnp_env%ang(i)%prefzeta, &
520 0 : nnp_env%ang(i)%lam, &
521 0 : nnp_env%ang(i)%loc_min, &
522 0 : nnp_env%ang(i)%loc_max, &
523 0 : nnp_env%ang(i)%loc_av, &
524 0 : nnp_env%ang(i)%sigma, &
525 0 : nnp_env%ang(i)%ele1, &
526 0 : nnp_env%ang(i)%ele2, &
527 0 : nnp_env%ang(i)%nuc_ele1, &
528 0 : nnp_env%ang(i)%nuc_ele2, &
529 138 : nnp_env%ang(i)%symfgrp)
530 : END DO
531 17 : DEALLOCATE (nnp_env%ang)
532 : END IF
533 :
534 17 : IF (ASSOCIATED(nnp_env%arc)) THEN
535 52 : DO i = 1, nnp_env%n_ele
536 52 : IF (ASSOCIATED(nnp_env%arc(i)%layer)) THEN
537 175 : DO j = 1, nnp_env%n_layer
538 140 : IF (ALLOCATED(nnp_env%arc(i)%layer(j)%node)) THEN
539 140 : DEALLOCATE (nnp_env%arc(i)%layer(j)%node)
540 : END IF
541 140 : IF (ALLOCATED(nnp_env%arc(i)%layer(j)%node_grad)) THEN
542 140 : DEALLOCATE (nnp_env%arc(i)%layer(j)%node_grad)
543 : END IF
544 140 : IF (ALLOCATED(nnp_env%arc(i)%layer(j)%weights)) THEN
545 105 : DEALLOCATE (nnp_env%arc(i)%layer(j)%weights)
546 : END IF
547 140 : IF (ALLOCATED(nnp_env%arc(i)%layer(j)%bweights)) THEN
548 105 : DEALLOCATE (nnp_env%arc(i)%layer(j)%bweights)
549 : END IF
550 175 : IF (ALLOCATED(nnp_env%arc(i)%layer(j)%tmp_der)) THEN
551 140 : DEALLOCATE (nnp_env%arc(i)%layer(j)%tmp_der)
552 : END IF
553 : END DO
554 0 : DEALLOCATE (nnp_env%arc(i)%layer, &
555 35 : nnp_env%arc(i)%n_nodes)
556 : END IF
557 : END DO
558 17 : DEALLOCATE (nnp_env%arc)
559 : END IF
560 :
561 17 : IF (ALLOCATED(nnp_env%ele)) DEALLOCATE (nnp_env%ele)
562 17 : IF (ALLOCATED(nnp_env%nuc_ele)) DEALLOCATE (nnp_env%nuc_ele)
563 17 : IF (ALLOCATED(nnp_env%n_hnodes)) DEALLOCATE (nnp_env%n_hnodes)
564 17 : IF (ALLOCATED(nnp_env%actfnct)) DEALLOCATE (nnp_env%actfnct)
565 17 : IF (ALLOCATED(nnp_env%nnp_forces)) DEALLOCATE (nnp_env%nnp_forces)
566 17 : IF (ALLOCATED(nnp_env%atomic_energy)) DEALLOCATE (nnp_env%atomic_energy)
567 17 : IF (ALLOCATED(nnp_env%committee_energy)) DEALLOCATE (nnp_env%committee_energy)
568 17 : IF (ALLOCATED(nnp_env%ele_ind)) DEALLOCATE (nnp_env%ele_ind)
569 17 : IF (ALLOCATED(nnp_env%nuc_atoms)) DEALLOCATE (nnp_env%nuc_atoms)
570 17 : IF (ALLOCATED(nnp_env%sort)) DEALLOCATE (nnp_env%sort)
571 17 : IF (ALLOCATED(nnp_env%sort_inv)) DEALLOCATE (nnp_env%sort_inv)
572 17 : IF (ALLOCATED(nnp_env%coord)) DEALLOCATE (nnp_env%coord)
573 17 : IF (ALLOCATED(nnp_env%myforce)) DEALLOCATE (nnp_env%myforce)
574 17 : IF (ALLOCATED(nnp_env%committee_forces)) DEALLOCATE (nnp_env%committee_forces)
575 17 : IF (ALLOCATED(nnp_env%committee_stress)) DEALLOCATE (nnp_env%committee_stress)
576 17 : IF (ALLOCATED(nnp_env%atoms)) DEALLOCATE (nnp_env%atoms)
577 :
578 17 : IF (ALLOCATED(nnp_env%cell_list_cache)) THEN
579 17 : CALL nnp_cell_list_cache_release(nnp_env%cell_list_cache)
580 17 : DEALLOCATE (nnp_env%cell_list_cache)
581 : END IF
582 17 : IF (ALLOCATED(nnp_env%neighbor_interface_state)) THEN
583 17 : CALL nnp_neighbor_interface_state_release(nnp_env%neighbor_interface_state)
584 17 : DEALLOCATE (nnp_env%neighbor_interface_state)
585 : END IF
586 :
587 17 : IF (ASSOCIATED(nnp_env%subsys)) THEN
588 16 : CALL cp_subsys_release(nnp_env%subsys)
589 : END IF
590 17 : IF (ASSOCIATED(nnp_env%cell)) THEN
591 17 : CALL cell_release(nnp_env%cell)
592 : END IF
593 17 : IF (ASSOCIATED(nnp_env%cell_ref)) THEN
594 16 : CALL cell_release(nnp_env%cell_ref)
595 : END IF
596 :
597 17 : END SUBROUTINE nnp_env_release
598 :
599 : ! **************************************************************************************************
600 : !> \brief Free the allocatable parts of a cell-list cache. Co-located with the
601 : !> type definition to avoid creating a USE-cycle through nnp_cell_list.
602 : !> \param cache cell-list cache whose allocatable image-pool and bin arrays are freed
603 : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
604 : ! **************************************************************************************************
605 17 : SUBROUTINE nnp_cell_list_cache_release(cache)
606 : TYPE(nnp_cell_list_cache_type), INTENT(INOUT) :: cache
607 :
608 17 : IF (ALLOCATED(cache%coord_primary)) DEALLOCATE (cache%coord_primary)
609 17 : IF (ALLOCATED(cache%coord_scaled)) DEALLOCATE (cache%coord_scaled)
610 17 : IF (ALLOCATED(cache%ref_coord_primary)) DEALLOCATE (cache%ref_coord_primary)
611 17 : IF (ALLOCATED(cache%image_atom)) DEALLOCATE (cache%image_atom)
612 17 : IF (ALLOCATED(cache%head)) DEALLOCATE (cache%head)
613 17 : IF (ALLOCATED(cache%next)) DEALLOCATE (cache%next)
614 17 : IF (ALLOCATED(cache%image_shift)) DEALLOCATE (cache%image_shift)
615 17 : IF (ALLOCATED(cache%image_translation)) DEALLOCATE (cache%image_translation)
616 17 : cache%initialized = .FALSE.
617 17 : cache%num_atoms = -1
618 17 : cache%n_images = 0
619 17 : END SUBROUTINE nnp_cell_list_cache_release
620 :
621 : ! **************************************************************************************************
622 : !> \brief Free the allocatable parts of a neighbour-interface state. Co-located
623 : !> with the type definition to avoid creating a USE-cycle through
624 : !> nnp_neighbor_interface.
625 : !> \param state neighbour-interface state whose pair maps and per-element workspaces are freed
626 : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
627 : ! **************************************************************************************************
628 34 : SUBROUTINE nnp_neighbor_interface_state_release(state)
629 : TYPE(nnp_neighbor_interface_state_type), &
630 : INTENT(INOUT) :: state
631 :
632 : INTEGER :: i, j
633 :
634 34 : IF (ALLOCATED(state%pair_map)) THEN
635 52 : DO i = 1, SIZE(state%pair_map, 1)
636 125 : DO j = 1, SIZE(state%pair_map, 2)
637 73 : IF (ALLOCATED(state%pair_map(i, j)%rad_groups)) DEALLOCATE (state%pair_map(i, j)%rad_groups)
638 73 : IF (ALLOCATED(state%pair_map(i, j)%ang1_groups)) DEALLOCATE (state%pair_map(i, j)%ang1_groups)
639 108 : IF (ALLOCATED(state%pair_map(i, j)%ang2_groups)) DEALLOCATE (state%pair_map(i, j)%ang2_groups)
640 : END DO
641 : END DO
642 90 : DEALLOCATE (state%pair_map)
643 : END IF
644 :
645 34 : IF (ALLOCATED(state%workspace)) THEN
646 34 : DO j = 1, SIZE(state%workspace, 2)
647 69 : DO i = 1, SIZE(state%workspace, 1)
648 52 : CALL nnp_workspace_release(state%workspace(i, j))
649 : END DO
650 : END DO
651 52 : DEALLOCATE (state%workspace)
652 : END IF
653 :
654 34 : IF (ALLOCATED(state%n_rad)) DEALLOCATE (state%n_rad)
655 34 : IF (ALLOCATED(state%n_ang)) DEALLOCATE (state%n_ang)
656 34 : IF (ALLOCATED(state%n_radgrp)) DEALLOCATE (state%n_radgrp)
657 34 : IF (ALLOCATED(state%n_anggrp)) DEALLOCATE (state%n_anggrp)
658 :
659 34 : state%initialized = .FALSE.
660 34 : state%n_ele = 0
661 34 : END SUBROUTINE nnp_neighbor_interface_state_release
662 :
663 : ! **************************************************************************************************
664 : !> \brief Free the allocatable parts of one per-element workspace.
665 : !> \param workspace per-element workspace whose scratch, cutoff caches and dGdr buffers are freed
666 : !> \author Dhruv Sharma (ds2173@cam.ac.uk)
667 : ! **************************************************************************************************
668 35 : SUBROUTINE nnp_workspace_release(workspace)
669 : TYPE(nnp_neighbor_workspace_type), INTENT(INOUT) :: workspace
670 :
671 : INTEGER :: s
672 :
673 35 : IF (ALLOCATED(workspace%neighbor%rad)) THEN
674 106 : DO s = 1, SIZE(workspace%neighbor%rad)
675 71 : IF (ALLOCATED(workspace%neighbor%rad(s)%ind)) DEALLOCATE (workspace%neighbor%rad(s)%ind)
676 106 : IF (ALLOCATED(workspace%neighbor%rad(s)%dist)) DEALLOCATE (workspace%neighbor%rad(s)%dist)
677 : END DO
678 106 : DEALLOCATE (workspace%neighbor%rad)
679 : END IF
680 35 : IF (ALLOCATED(workspace%neighbor%ang1)) THEN
681 121 : DO s = 1, SIZE(workspace%neighbor%ang1)
682 86 : IF (ALLOCATED(workspace%neighbor%ang1(s)%ind)) DEALLOCATE (workspace%neighbor%ang1(s)%ind)
683 121 : IF (ALLOCATED(workspace%neighbor%ang1(s)%dist)) DEALLOCATE (workspace%neighbor%ang1(s)%dist)
684 : END DO
685 121 : DEALLOCATE (workspace%neighbor%ang1)
686 : END IF
687 35 : IF (ALLOCATED(workspace%neighbor%ang2)) THEN
688 121 : DO s = 1, SIZE(workspace%neighbor%ang2)
689 86 : IF (ALLOCATED(workspace%neighbor%ang2(s)%ind)) DEALLOCATE (workspace%neighbor%ang2(s)%ind)
690 121 : IF (ALLOCATED(workspace%neighbor%ang2(s)%dist)) DEALLOCATE (workspace%neighbor%ang2(s)%dist)
691 : END DO
692 121 : DEALLOCATE (workspace%neighbor%ang2)
693 : END IF
694 35 : IF (ALLOCATED(workspace%neighbor%n_rad)) DEALLOCATE (workspace%neighbor%n_rad)
695 35 : IF (ALLOCATED(workspace%neighbor%n_ang1)) DEALLOCATE (workspace%neighbor%n_ang1)
696 35 : IF (ALLOCATED(workspace%neighbor%n_ang2)) DEALLOCATE (workspace%neighbor%n_ang2)
697 140 : workspace%neighbor%pbc_copies = -1
698 :
699 35 : IF (ALLOCATED(workspace%radial_sym)) DEALLOCATE (workspace%radial_sym)
700 35 : IF (ALLOCATED(workspace%radial_force)) DEALLOCATE (workspace%radial_force)
701 35 : IF (ALLOCATED(workspace%angular_sym)) DEALLOCATE (workspace%angular_sym)
702 35 : IF (ALLOCATED(workspace%angular_force)) DEALLOCATE (workspace%angular_force)
703 35 : IF (ALLOCATED(workspace%fc_cache1)) DEALLOCATE (workspace%fc_cache1)
704 35 : IF (ALLOCATED(workspace%dfc_cache1)) DEALLOCATE (workspace%dfc_cache1)
705 35 : IF (ALLOCATED(workspace%fc_cache2)) DEALLOCATE (workspace%fc_cache2)
706 35 : IF (ALLOCATED(workspace%dfc_cache2)) DEALLOCATE (workspace%dfc_cache2)
707 35 : IF (ALLOCATED(workspace%self_dGdr)) DEALLOCATE (workspace%self_dGdr)
708 :
709 35 : IF (ALLOCATED(workspace%dGdr_rad)) THEN
710 106 : DO s = 1, SIZE(workspace%dGdr_rad)
711 106 : IF (ALLOCATED(workspace%dGdr_rad(s)%data)) DEALLOCATE (workspace%dGdr_rad(s)%data)
712 : END DO
713 106 : DEALLOCATE (workspace%dGdr_rad)
714 : END IF
715 35 : IF (ALLOCATED(workspace%dGdr_ang_jj)) THEN
716 121 : DO s = 1, SIZE(workspace%dGdr_ang_jj)
717 121 : IF (ALLOCATED(workspace%dGdr_ang_jj(s)%data)) DEALLOCATE (workspace%dGdr_ang_jj(s)%data)
718 : END DO
719 121 : DEALLOCATE (workspace%dGdr_ang_jj)
720 : END IF
721 35 : IF (ALLOCATED(workspace%dGdr_ang_kk)) THEN
722 121 : DO s = 1, SIZE(workspace%dGdr_ang_kk)
723 121 : IF (ALLOCATED(workspace%dGdr_ang_kk(s)%data)) DEALLOCATE (workspace%dGdr_ang_kk(s)%data)
724 : END DO
725 121 : DEALLOCATE (workspace%dGdr_ang_kk)
726 : END IF
727 :
728 35 : workspace%max_rad_symf = 0
729 35 : workspace%max_ang_symf = 0
730 35 : workspace%n_input_nodes = 0
731 35 : workspace%cache_cap = 0
732 35 : END SUBROUTINE nnp_workspace_release
733 :
734 : ! **************************************************************************************************
735 : !> \brief Returns various attributes of the nnp environment
736 : !> \param nnp_env ...
737 : !> \param nnp_forces ...
738 : !> \param subsys the particles, molecules,... of this environment
739 : !> \param atomic_kind_set The set of all atomic kinds involved
740 : !> \param particle_set The set of all particles
741 : !> \param local_particles All particles on this particular node
742 : !> \param molecule_kind_set The set of all different molecule kinds involved
743 : !> \param molecule_set The set of all molecules
744 : !> \param local_molecules All molecules on this particular node
745 : !> \param nnp_input ...
746 : !> \param force_env_input Pointer to the force_env input section
747 : !> \param cell The simulation cell
748 : !> \param cell_ref The reference simulation cell
749 : !> \param use_ref_cell Logical which indicates if reference
750 : !> simulation cell is used
751 : !> \param nnp_potential_energy ...
752 : !> \param virial Dummy virial pointer
753 : !> \date 2020-10-10
754 : !> \author Christoph Schran (christoph.schran@rub.de)
755 : !> \note
756 : !> For possible missing arguments see the attributes of
757 : !> nnp_type
758 : ! **************************************************************************************************
759 61998 : SUBROUTINE nnp_env_get(nnp_env, nnp_forces, subsys, &
760 : atomic_kind_set, particle_set, local_particles, &
761 : molecule_kind_set, molecule_set, local_molecules, &
762 : nnp_input, force_env_input, cell, cell_ref, &
763 : use_ref_cell, nnp_potential_energy, virial)
764 :
765 : TYPE(nnp_type), INTENT(IN) :: nnp_env
766 : REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER :: nnp_forces
767 : TYPE(cp_subsys_type), OPTIONAL, POINTER :: subsys
768 : TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
769 : POINTER :: atomic_kind_set
770 : TYPE(particle_type), DIMENSION(:), OPTIONAL, &
771 : POINTER :: particle_set
772 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles
773 : TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
774 : POINTER :: molecule_kind_set
775 : TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
776 : POINTER :: molecule_set
777 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_molecules
778 : TYPE(section_vals_type), OPTIONAL, POINTER :: nnp_input, force_env_input
779 : TYPE(cell_type), OPTIONAL, POINTER :: cell, cell_ref
780 : LOGICAL, INTENT(OUT), OPTIONAL :: use_ref_cell
781 : REAL(KIND=dp), INTENT(OUT), OPTIONAL :: nnp_potential_energy
782 : TYPE(virial_type), OPTIONAL, POINTER :: virial
783 :
784 : TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
785 : TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
786 : TYPE(molecule_list_type), POINTER :: molecules
787 : TYPE(particle_list_type), POINTER :: particles
788 :
789 61998 : NULLIFY (atomic_kinds, particles, molecules, molecule_kinds)
790 :
791 61998 : IF (PRESENT(nnp_potential_energy)) THEN
792 618 : nnp_potential_energy = nnp_env%nnp_potential_energy
793 : END IF
794 61998 : IF (PRESENT(nnp_forces)) nnp_forces = nnp_env%nnp_forces
795 :
796 : ! note cell will be overwritten if subsys is associated
797 : ! helium_env uses nnp without subsys
798 61998 : IF (PRESENT(cell)) cell => nnp_env%cell
799 :
800 61998 : IF (PRESENT(subsys)) subsys => nnp_env%subsys
801 61998 : IF (ASSOCIATED(nnp_env%subsys)) THEN
802 : CALL cp_subsys_get(nnp_env%subsys, &
803 : atomic_kinds=atomic_kinds, &
804 : particles=particles, &
805 : molecule_kinds=molecule_kinds, &
806 : molecules=molecules, &
807 : local_molecules=local_molecules, &
808 : local_particles=local_particles, &
809 : virial=virial, &
810 6826 : cell=cell)
811 : END IF
812 61998 : IF (PRESENT(atomic_kind_set)) atomic_kind_set => atomic_kinds%els
813 61998 : IF (PRESENT(particle_set)) particle_set => particles%els
814 61998 : IF (PRESENT(molecule_kind_set)) molecule_kind_set => molecule_kinds%els
815 61998 : IF (PRESENT(molecule_set)) molecule_set => molecules%els
816 :
817 61998 : IF (PRESENT(nnp_input)) nnp_input => nnp_env%nnp_input
818 61998 : IF (PRESENT(force_env_input)) force_env_input => nnp_env%force_env_input
819 61998 : IF (PRESENT(cell_ref)) cell_ref => nnp_env%cell_ref
820 61998 : IF (PRESENT(use_ref_cell)) use_ref_cell = nnp_env%use_ref_cell
821 :
822 61998 : END SUBROUTINE nnp_env_get
823 :
824 : ! **************************************************************************************************
825 : !> \brief Sets various attributes of the nnp environment
826 : !> \param nnp_env ...
827 : !> \param nnp_forces ...
828 : !> \param subsys the particles, molecules,... of this environment
829 : !> \param atomic_kind_set The set of all atomic kinds involved
830 : !> \param particle_set The set of all particles
831 : !> \param local_particles All particles on this particular node
832 : !> \param molecule_kind_set The set of all different molecule kinds involved
833 : !> \param molecule_set The set of all molecules
834 : !> \param local_molecules All molecules on this particular node
835 : !> \param nnp_input ...
836 : !> \param force_env_input Pointer to the force_env input section
837 : !> \param cell ...
838 : !> \param cell_ref The reference simulation cell
839 : !> \param use_ref_cell Logical which indicates if reference
840 : !> simulation cell is used
841 : !> \param nnp_potential_energy ...
842 : !> \date 2020-10-10
843 : !> \author Christoph Schran (christoph.schran@rub.de)
844 : !> \note
845 : !> For possible missing arguments see the attributes of nnp_type
846 : ! **************************************************************************************************
847 50 : SUBROUTINE nnp_env_set(nnp_env, nnp_forces, subsys, &
848 : atomic_kind_set, particle_set, local_particles, &
849 : molecule_kind_set, molecule_set, local_molecules, &
850 : nnp_input, force_env_input, cell, cell_ref, &
851 : use_ref_cell, nnp_potential_energy)
852 :
853 : TYPE(nnp_type), INTENT(INOUT) :: nnp_env
854 : REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER :: nnp_forces
855 : TYPE(cp_subsys_type), OPTIONAL, POINTER :: subsys
856 : TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
857 : POINTER :: atomic_kind_set
858 : TYPE(particle_type), DIMENSION(:), OPTIONAL, &
859 : POINTER :: particle_set
860 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles
861 : TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
862 : POINTER :: molecule_kind_set
863 : TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
864 : POINTER :: molecule_set
865 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_molecules
866 : TYPE(section_vals_type), OPTIONAL, POINTER :: nnp_input, force_env_input
867 : TYPE(cell_type), OPTIONAL, POINTER :: cell, cell_ref
868 : LOGICAL, INTENT(IN), OPTIONAL :: use_ref_cell
869 : REAL(KIND=dp), INTENT(IN), OPTIONAL :: nnp_potential_energy
870 :
871 : TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
872 : TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
873 : TYPE(molecule_list_type), POINTER :: molecules
874 : TYPE(particle_list_type), POINTER :: particles
875 :
876 50 : IF (PRESENT(nnp_potential_energy)) THEN
877 0 : nnp_env%nnp_potential_energy = nnp_potential_energy
878 : END IF
879 50 : IF (PRESENT(nnp_forces)) nnp_env%nnp_forces(:, :) = nnp_forces
880 :
881 50 : IF (PRESENT(subsys)) THEN
882 16 : IF (ASSOCIATED(nnp_env%subsys)) THEN
883 0 : IF (.NOT. ASSOCIATED(nnp_env%subsys, subsys)) THEN
884 0 : CALL cp_subsys_release(nnp_env%subsys)
885 : END IF
886 : END IF
887 16 : nnp_env%subsys => subsys
888 : END IF
889 50 : IF (PRESENT(cell)) THEN
890 17 : IF (ASSOCIATED(cell)) THEN
891 17 : CALL cell_retain(cell)
892 17 : CALL cell_release(nnp_env%cell)
893 17 : nnp_env%cell => cell
894 : END IF
895 17 : IF (ASSOCIATED(nnp_env%subsys)) THEN
896 16 : CALL cp_subsys_set(nnp_env%subsys, cell=cell)
897 : END IF
898 : END IF
899 50 : IF (PRESENT(atomic_kind_set)) THEN
900 0 : CALL atomic_kind_list_create(atomic_kinds, els_ptr=atomic_kind_set)
901 0 : CALL cp_subsys_set(nnp_env%subsys, atomic_kinds=atomic_kinds)
902 0 : CALL atomic_kind_list_release(atomic_kinds)
903 : END IF
904 50 : IF (PRESENT(particle_set)) THEN
905 0 : CALL particle_list_create(particles, els_ptr=particle_set)
906 0 : CALL cp_subsys_set(nnp_env%subsys, particles=particles)
907 0 : CALL particle_list_release(particles)
908 : END IF
909 50 : IF (PRESENT(molecule_kind_set)) THEN
910 0 : CALL molecule_kind_list_create(molecule_kinds, els_ptr=molecule_kind_set)
911 0 : CALL cp_subsys_set(nnp_env%subsys, molecule_kinds=molecule_kinds)
912 0 : CALL molecule_kind_list_release(molecule_kinds)
913 : END IF
914 50 : IF (PRESENT(molecule_set)) THEN
915 0 : CALL molecule_list_create(molecules, els_ptr=molecule_set)
916 0 : CALL cp_subsys_set(nnp_env%subsys, molecules=molecules)
917 0 : CALL molecule_list_release(molecules)
918 : END IF
919 50 : IF (PRESENT(local_particles)) THEN
920 16 : CALL cp_subsys_set(nnp_env%subsys, local_particles=local_particles)
921 : END IF
922 50 : IF (PRESENT(local_molecules)) THEN
923 16 : CALL cp_subsys_set(nnp_env%subsys, local_molecules=local_molecules)
924 : END IF
925 :
926 50 : IF (PRESENT(nnp_input)) nnp_env%nnp_input => nnp_input
927 50 : IF (PRESENT(force_env_input)) THEN
928 16 : nnp_env%force_env_input => force_env_input
929 : END IF
930 50 : IF (PRESENT(cell_ref)) THEN
931 16 : CALL cell_retain(cell_ref)
932 16 : CALL cell_release(nnp_env%cell_ref)
933 16 : nnp_env%cell_ref => cell_ref
934 : END IF
935 50 : IF (PRESENT(use_ref_cell)) nnp_env%use_ref_cell = use_ref_cell
936 50 : END SUBROUTINE nnp_env_set
937 :
938 0 : END MODULE nnp_environment_types
|