(git:71983cd)
Loading...
Searching...
No Matches
manybody_potential.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!> \par History
10!> Efficient tersoff implementation and general "lifting" of manybody_potential module
11!> 12.2007 [tlaino] - Splitting manybody module : In this module we should only
12!> keep the main routines for computing energy and forces of
13!> manybody potentials. Each potential should have his own module!
14!> \author CJM, I-Feng W. Kuo, Teodoro Laino
15! **************************************************************************************************
17
19 USE cell_types, ONLY: cell_type
28 USE kinds, ONLY: dp
61 USE pair_potential_types, ONLY: &
67 USE util, ONLY: sort
68#include "./base/base_uses.f90"
69
70 IMPLICIT NONE
71
72 PRIVATE
73 PUBLIC :: energy_manybody
75 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'manybody_potential'
76
77CONTAINS
78
79! **************************************************************************************************
80!> \brief computes the embedding contribution to the energy
81!> \param fist_nonbond_env ...
82!> \param atomic_kind_set ...
83!> \param local_particles ...
84!> \param particle_set ...
85!> \param cell ...
86!> \param pot_manybody ...
87!> \param para_env ...
88!> \param mm_section ...
89!> \param use_virial ...
90!> \par History
91!> tlaino [2007] - New algorithm for tersoff potential
92!> \author CJM, I-Feng W. Kuo, Teodoro Laino
93! **************************************************************************************************
94 SUBROUTINE energy_manybody(fist_nonbond_env, atomic_kind_set, local_particles, &
95 particle_set, cell, pot_manybody, para_env, mm_section, use_virial)
96
97 TYPE(fist_nonbond_env_type), POINTER :: fist_nonbond_env
98 TYPE(atomic_kind_type), POINTER :: atomic_kind_set(:)
99 TYPE(distribution_1d_type), POINTER :: local_particles
100 TYPE(particle_type), POINTER :: particle_set(:)
101 TYPE(cell_type), POINTER :: cell
102 REAL(dp), INTENT(INOUT) :: pot_manybody
103 TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
104 TYPE(section_vals_type), POINTER :: mm_section
105 LOGICAL, INTENT(IN) :: use_virial
106
107 CHARACTER(LEN=*), PARAMETER :: routinen = 'energy_manybody'
108
109 INTEGER :: atom_a, atom_b, handle, i, iend, ifirst, igrp, ikind, ilast, ilist, indexa, &
110 ipair, iparticle, iparticle_local, istart, iunique, jkind, junique, mpair, nkinds, &
111 nloc_size, npairs, nparticle, nparticle_local, nr_h3o, nr_o, nr_oh, nunique
112 INTEGER, DIMENSION(:), POINTER :: glob_loc_list_a, unique_list_a, work_list
113 INTEGER, DIMENSION(:, :), POINTER :: glob_loc_list, list, sort_list
114 LOGICAL :: any_ace, any_allegro, any_deepmd, &
115 any_gal, any_gal21, any_nequip, &
116 any_siepmann, any_tersoff
117 REAL(kind=dp) :: drij, embed, pot_ace, pot_allegro, &
118 pot_deepmd, pot_loc, pot_nequip, qr, &
119 rab2_max, rij(3)
120 REAL(kind=dp), DIMENSION(3) :: cell_v, cvi
121 REAL(kind=dp), DIMENSION(:, :), POINTER :: glob_cell_v
122 REAL(kind=dp), POINTER :: fembed(:)
123 TYPE(allegro_pot_type), POINTER :: allegro
124 TYPE(eam_pot_type), POINTER :: eam
125 TYPE(eam_type), DIMENSION(:), POINTER :: eam_data
126 TYPE(fist_neighbor_type), POINTER :: nonbonded
127 TYPE(gal21_pot_type), POINTER :: gal21
128 TYPE(gal_pot_type), POINTER :: gal
129 TYPE(neighbor_kind_pairs_type), POINTER :: neighbor_kind_pair
130 TYPE(nequip_pot_type), POINTER :: nequip
131 TYPE(pair_potential_pp_type), POINTER :: potparm
132 TYPE(pair_potential_single_type), POINTER :: pot
133 TYPE(pos_type), DIMENSION(:), POINTER :: r_last_update_pbc
134 TYPE(siepmann_pot_type), POINTER :: siepmann
135 TYPE(tersoff_pot_type), POINTER :: tersoff
136
137 NULLIFY (eam, siepmann, tersoff, gal, gal21)
138 any_tersoff = .false.
139 any_siepmann = .false.
140 any_gal = .false.
141 any_gal21 = .false.
142 any_nequip = .false.
143 any_allegro = .false.
144 any_ace = .false.
145 any_deepmd = .false.
146 CALL timeset(routinen, handle)
147 CALL fist_nonbond_env_get(fist_nonbond_env, r_last_update_pbc=r_last_update_pbc, &
148 potparm=potparm, eam_data=eam_data)
149 ! EAM requires a single loop
150 DO ikind = 1, SIZE(atomic_kind_set)
151 pot => potparm%pot(ikind, ikind)%pot
152 DO i = 1, SIZE(pot%type)
153 IF (pot%type(i) /= ea_type) cycle
154 eam => pot%set(i)%eam
155 nparticle = SIZE(particle_set)
156 ALLOCATE (fembed(nparticle))
157 fembed(:) = 0._dp
158 cpassert(ASSOCIATED(eam_data))
159 ! computation of embedding function and energy
160 nparticle_local = local_particles%n_el(ikind)
161 DO iparticle_local = 1, nparticle_local
162 iparticle = local_particles%list(ikind)%array(iparticle_local)
163 indexa = int(eam_data(iparticle)%rho/eam%drhoar) + 1
164 IF (indexa > eam%npoints - 1) indexa = eam%npoints - 1
165 qr = eam_data(iparticle)%rho - eam%rhoval(indexa)
166
167 embed = eam%frho(indexa) + qr*eam%frhop(indexa)
168 fembed(iparticle) = eam%frhop(indexa) + qr*(eam%frhop(indexa + 1) - eam%frhop(indexa))/eam%drhoar
169
170 pot_manybody = pot_manybody + embed
171 END DO
172 ! communicate data
173 CALL para_env%sum(fembed)
174 DO iparticle = 1, nparticle
175 IF (particle_set(iparticle)%atomic_kind%kind_number == ikind) THEN
176 eam_data(iparticle)%f_embed = fembed(iparticle)
177 END IF
178 END DO
179
180 DEALLOCATE (fembed)
181 END DO
182 END DO
183 ! Other manybody potential
184 DO ikind = 1, SIZE(atomic_kind_set)
185 DO jkind = ikind, SIZE(atomic_kind_set)
186 pot => potparm%pot(ikind, jkind)%pot
187 any_tersoff = any_tersoff .OR. any(pot%type == tersoff_type)
188 any_nequip = any_nequip .OR. any(pot%type == nequip_type)
189 any_allegro = any_allegro .OR. any(pot%type == allegro_type)
190 any_ace = any_ace .OR. any(pot%type == ace_type)
191 any_deepmd = any_deepmd .OR. any(pot%type == deepmd_type)
192 any_siepmann = any_siepmann .OR. any(pot%type == siepmann_type)
193 any_gal = any_gal .OR. any(pot%type == gal_type)
194 any_gal21 = any_gal21 .OR. any(pot%type == gal21_type)
195 END DO
196 END DO
197 CALL fist_nonbond_env_get(fist_nonbond_env, nonbonded=nonbonded, natom_types=nkinds)
198 ! NEQUIP
199 IF (any_nequip) THEN
200 NULLIFY (glob_loc_list, glob_cell_v, glob_loc_list_a)
201 CALL setup_nequip_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
202 CALL nequip_energy_store_force_virial(nonbonded, particle_set, cell, atomic_kind_set, potparm, &
203 nequip, glob_loc_list_a, r_last_update_pbc, pot_nequip, &
204 fist_nonbond_env, para_env, use_virial)
205 pot_manybody = pot_manybody + pot_nequip
206 CALL destroy_nequip_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
207 END IF
208 ! ALLEGRO
209 IF (any_allegro) THEN
210 NULLIFY (glob_loc_list, glob_cell_v, glob_loc_list_a, unique_list_a)
211 CALL setup_allegro_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, &
212 unique_list_a, cell)
213 CALL allegro_energy_store_force_virial(nonbonded, particle_set, cell, atomic_kind_set, potparm, &
214 allegro, glob_loc_list_a, r_last_update_pbc, pot_allegro, &
215 fist_nonbond_env, unique_list_a, para_env, use_virial)
216 pot_manybody = pot_manybody + pot_allegro
217 CALL destroy_allegro_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a, unique_list_a)
218 END IF
219 ! ACE
220 IF (any_ace) THEN
221 CALL ace_energy_store_force_virial(particle_set, cell, atomic_kind_set, potparm, &
222 fist_nonbond_env, pot_ace)
223 pot_manybody = pot_manybody + pot_ace
224 END IF
225 ! DEEPMD
226 IF (any_deepmd) THEN
227 CALL deepmd_energy_store_force_virial(particle_set, cell, atomic_kind_set, potparm, &
228 fist_nonbond_env, pot_deepmd, para_env)
229 pot_manybody = pot_manybody + pot_deepmd
230 END IF
231
232 ! TERSOFF
233 IF (any_tersoff) THEN
234 NULLIFY (glob_loc_list, glob_cell_v, glob_loc_list_a)
235 CALL setup_tersoff_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
236 DO ilist = 1, nonbonded%nlists
237 neighbor_kind_pair => nonbonded%neighbor_kind_pairs(ilist)
238 npairs = neighbor_kind_pair%npairs
239 IF (npairs == 0) cycle
240 kind_group_loop: DO igrp = 1, neighbor_kind_pair%ngrp_kind
241 istart = neighbor_kind_pair%grp_kind_start(igrp)
242 iend = neighbor_kind_pair%grp_kind_end(igrp)
243 ikind = neighbor_kind_pair%ij_kind(1, igrp)
244 jkind = neighbor_kind_pair%ij_kind(2, igrp)
245 list => neighbor_kind_pair%list
246 cvi = neighbor_kind_pair%cell_vector
247 pot => potparm%pot(ikind, jkind)%pot
248 DO i = 1, SIZE(pot%type)
249 IF (pot%type(i) /= tersoff_type) cycle
250 rab2_max = pot%set(i)%tersoff%rcutsq
251 cell_v = matmul(cell%hmat, cvi)
252 pot => potparm%pot(ikind, jkind)%pot
253 tersoff => pot%set(i)%tersoff
254 npairs = iend - istart + 1
255 IF (npairs /= 0) THEN
256 ALLOCATE (sort_list(2, npairs), work_list(npairs))
257 sort_list = list(:, istart:iend)
258 ! Sort the list of neighbors, this increases the efficiency for single
259 ! potential contributions
260 CALL sort(sort_list(1, :), npairs, work_list)
261 DO ipair = 1, npairs
262 work_list(ipair) = sort_list(2, work_list(ipair))
263 END DO
264 sort_list(2, :) = work_list
265 ! find number of unique elements of array index 1
266 nunique = 1
267 DO ipair = 1, npairs - 1
268 IF (sort_list(1, ipair + 1) /= sort_list(1, ipair)) nunique = nunique + 1
269 END DO
270 ipair = 1
271 junique = sort_list(1, ipair)
272 ifirst = 1
273 DO iunique = 1, nunique
274 atom_a = junique
275 IF (glob_loc_list_a(ifirst) > atom_a) cycle
276 DO mpair = ifirst, SIZE(glob_loc_list_a)
277 IF (glob_loc_list_a(mpair) == atom_a) EXIT
278 END DO
279 ifirst = mpair
280 DO mpair = ifirst, SIZE(glob_loc_list_a)
281 IF (glob_loc_list_a(mpair) /= atom_a) EXIT
282 END DO
283 ilast = mpair - 1
284 nloc_size = 0
285 IF (ifirst /= 0) nloc_size = ilast - ifirst + 1
286 DO WHILE (ipair <= npairs)
287 IF (sort_list(1, ipair) /= junique) EXIT
288 atom_b = sort_list(2, ipair)
289 ! Energy terms
290 pot_loc = 0.0_dp
291 rij(:) = r_last_update_pbc(atom_b)%r(:) - r_last_update_pbc(atom_a)%r(:) + cell_v
292 drij = dot_product(rij, rij)
293 ipair = ipair + 1
294 IF (drij > rab2_max) cycle
295 drij = sqrt(drij)
296 CALL tersoff_energy(pot_loc, tersoff, r_last_update_pbc, atom_a, atom_b, nloc_size, &
297 glob_loc_list(:, ifirst:ilast), glob_cell_v(:, ifirst:ilast), cell_v, drij)
298 pot_manybody = pot_manybody + 0.5_dp*pot_loc
299 END DO
300 ifirst = ilast + 1
301 IF (ipair <= npairs) junique = sort_list(1, ipair)
302 END DO
303 DEALLOCATE (sort_list, work_list)
304 END IF
305 END DO
306 END DO kind_group_loop
307 END DO
308 CALL destroy_tersoff_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
309 END IF
310
311 !SIEPMANN POTENTIAL
312 IF (any_siepmann) THEN
313 NULLIFY (glob_loc_list, glob_cell_v, glob_loc_list_a)
314 nr_oh = 0
315 nr_h3o = 0
316 nr_o = 0
317 CALL setup_siepmann_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
318 DO ilist = 1, nonbonded%nlists
319 neighbor_kind_pair => nonbonded%neighbor_kind_pairs(ilist)
320 npairs = neighbor_kind_pair%npairs
321 IF (npairs == 0) cycle
322 kind_group_loop_2: DO igrp = 1, neighbor_kind_pair%ngrp_kind
323 istart = neighbor_kind_pair%grp_kind_start(igrp)
324 iend = neighbor_kind_pair%grp_kind_end(igrp)
325 ikind = neighbor_kind_pair%ij_kind(1, igrp)
326 jkind = neighbor_kind_pair%ij_kind(2, igrp)
327 list => neighbor_kind_pair%list
328 cvi = neighbor_kind_pair%cell_vector
329 pot => potparm%pot(ikind, jkind)%pot
330 DO i = 1, SIZE(pot%type)
331 IF (pot%type(i) /= siepmann_type) cycle
332 rab2_max = pot%set(i)%siepmann%rcutsq
333 cell_v = matmul(cell%hmat, cvi)
334 pot => potparm%pot(ikind, jkind)%pot
335 siepmann => pot%set(i)%siepmann
336 npairs = iend - istart + 1
337 IF (npairs /= 0) THEN
338 ALLOCATE (sort_list(2, npairs), work_list(npairs))
339 sort_list = list(:, istart:iend)
340 ! Sort the list of neighbors, this increases the efficiency for single
341 ! potential contributions
342 CALL sort(sort_list(1, :), npairs, work_list)
343 DO ipair = 1, npairs
344 work_list(ipair) = sort_list(2, work_list(ipair))
345 END DO
346 sort_list(2, :) = work_list
347 ! find number of unique elements of array index 1
348 nunique = 1
349 DO ipair = 1, npairs - 1
350 IF (sort_list(1, ipair + 1) /= sort_list(1, ipair)) nunique = nunique + 1
351 END DO
352 ipair = 1
353 junique = sort_list(1, ipair)
354 ifirst = 1
355 DO iunique = 1, nunique
356 atom_a = junique
357 IF (glob_loc_list_a(ifirst) > atom_a) cycle
358 DO mpair = ifirst, SIZE(glob_loc_list_a)
359 IF (glob_loc_list_a(mpair) == atom_a) EXIT
360 END DO
361 ifirst = mpair
362 DO mpair = ifirst, SIZE(glob_loc_list_a)
363 IF (glob_loc_list_a(mpair) /= atom_a) EXIT
364 END DO
365 ilast = mpair - 1
366 nloc_size = 0
367 IF (ifirst /= 0) nloc_size = ilast - ifirst + 1
368 DO WHILE (ipair <= npairs)
369 IF (sort_list(1, ipair) /= junique) EXIT
370 atom_b = sort_list(2, ipair)
371 ! Energy terms
372 pot_loc = 0.0_dp
373 rij(:) = r_last_update_pbc(atom_b)%r(:) - r_last_update_pbc(atom_a)%r(:) + cell_v
374 drij = dot_product(rij, rij)
375 ipair = ipair + 1
376 IF (drij > rab2_max) cycle
377 drij = sqrt(drij)
378 CALL siepmann_energy(pot_loc, siepmann, r_last_update_pbc, atom_a, atom_b, nloc_size, &
379 glob_loc_list(:, ifirst:ilast), cell_v, cell, drij, &
380 particle_set, nr_oh, nr_h3o, nr_o)
381 pot_manybody = pot_manybody + pot_loc
382 END DO
383 ifirst = ilast + 1
384 IF (ipair <= npairs) junique = sort_list(1, ipair)
385 END DO
386 DEALLOCATE (sort_list, work_list)
387 END IF
388 END DO
389 END DO kind_group_loop_2
390 END DO
391 CALL destroy_siepmann_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
392 CALL print_nr_ions_siepmann(nr_oh, mm_section, para_env, print_oh=.true., &
393 print_h3o=.false., print_o=.false.)
394 CALL print_nr_ions_siepmann(nr_h3o, mm_section, para_env, print_oh=.false., &
395 print_h3o=.true., print_o=.false.)
396 CALL print_nr_ions_siepmann(nr_o, mm_section, para_env, print_oh=.false., &
397 print_h3o=.false., print_o=.true.)
398 END IF
399
400 !GAL19 POTENTIAL
401 IF (any_gal) THEN
402 NULLIFY (glob_loc_list, glob_cell_v, glob_loc_list_a)
403 CALL setup_gal_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
404 DO ilist = 1, nonbonded%nlists
405 neighbor_kind_pair => nonbonded%neighbor_kind_pairs(ilist)
406 npairs = neighbor_kind_pair%npairs
407 IF (npairs == 0) cycle
408 kind_group_loop_3: DO igrp = 1, neighbor_kind_pair%ngrp_kind
409 istart = neighbor_kind_pair%grp_kind_start(igrp)
410 iend = neighbor_kind_pair%grp_kind_end(igrp)
411 ikind = neighbor_kind_pair%ij_kind(1, igrp)
412 jkind = neighbor_kind_pair%ij_kind(2, igrp)
413 list => neighbor_kind_pair%list
414 cvi = neighbor_kind_pair%cell_vector
415 pot => potparm%pot(ikind, jkind)%pot
416 DO i = 1, SIZE(pot%type)
417 IF (pot%type(i) /= gal_type) cycle
418 rab2_max = pot%set(i)%gal%rcutsq
419 cell_v = matmul(cell%hmat, cvi)
420 pot => potparm%pot(ikind, jkind)%pot
421 gal => pot%set(i)%gal
422 npairs = iend - istart + 1
423 IF (npairs /= 0) THEN
424 ALLOCATE (sort_list(2, npairs), work_list(npairs))
425 sort_list = list(:, istart:iend)
426 ! Sort the list of neighbors, this increases the efficiency for single
427 ! potential contributions
428 CALL sort(sort_list(1, :), npairs, work_list)
429 DO ipair = 1, npairs
430 work_list(ipair) = sort_list(2, work_list(ipair))
431 END DO
432 sort_list(2, :) = work_list
433 ! find number of unique elements of array index 1
434 nunique = 1
435 DO ipair = 1, npairs - 1
436 IF (sort_list(1, ipair + 1) /= sort_list(1, ipair)) nunique = nunique + 1
437 END DO
438 ipair = 1
439 junique = sort_list(1, ipair)
440 ifirst = 1
441 DO iunique = 1, nunique
442 atom_a = junique
443 IF (glob_loc_list_a(ifirst) > atom_a) cycle
444 DO mpair = ifirst, SIZE(glob_loc_list_a)
445 IF (glob_loc_list_a(mpair) == atom_a) EXIT
446 END DO
447 ifirst = mpair
448 DO mpair = ifirst, SIZE(glob_loc_list_a)
449 IF (glob_loc_list_a(mpair) /= atom_a) EXIT
450 END DO
451 ilast = mpair - 1
452 nloc_size = 0
453 IF (ifirst /= 0) nloc_size = ilast - ifirst + 1
454 DO WHILE (ipair <= npairs)
455 IF (sort_list(1, ipair) /= junique) EXIT
456 atom_b = sort_list(2, ipair)
457 ! Energy terms
458 pot_loc = 0.0_dp
459 rij(:) = r_last_update_pbc(atom_b)%r(:) - r_last_update_pbc(atom_a)%r(:) + cell_v
460 drij = dot_product(rij, rij)
461 ipair = ipair + 1
462 IF (drij > rab2_max) cycle
463 drij = sqrt(drij)
464 CALL gal_energy(pot_loc, gal, r_last_update_pbc, atom_a, atom_b, &
465 cell, particle_set, mm_section)
466
467 pot_manybody = pot_manybody + pot_loc
468 END DO
469 ifirst = ilast + 1
470 IF (ipair <= npairs) junique = sort_list(1, ipair)
471 END DO
472 DEALLOCATE (sort_list, work_list)
473 END IF
474 END DO
475 END DO kind_group_loop_3
476 END DO
477 CALL destroy_gal_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
478 END IF
479
480 !GAL21 POTENTIAL
481 IF (any_gal21) THEN
482 NULLIFY (glob_loc_list, glob_cell_v, glob_loc_list_a)
483 CALL setup_gal21_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
484 DO ilist = 1, nonbonded%nlists
485 neighbor_kind_pair => nonbonded%neighbor_kind_pairs(ilist)
486 npairs = neighbor_kind_pair%npairs
487 IF (npairs == 0) cycle
488 kind_group_loop_5: DO igrp = 1, neighbor_kind_pair%ngrp_kind
489 istart = neighbor_kind_pair%grp_kind_start(igrp)
490 iend = neighbor_kind_pair%grp_kind_end(igrp)
491 ikind = neighbor_kind_pair%ij_kind(1, igrp)
492 jkind = neighbor_kind_pair%ij_kind(2, igrp)
493 list => neighbor_kind_pair%list
494 cvi = neighbor_kind_pair%cell_vector
495 pot => potparm%pot(ikind, jkind)%pot
496 DO i = 1, SIZE(pot%type)
497 IF (pot%type(i) /= gal21_type) cycle
498 rab2_max = pot%set(i)%gal21%rcutsq
499 cell_v = matmul(cell%hmat, cvi)
500 pot => potparm%pot(ikind, jkind)%pot
501 gal21 => pot%set(i)%gal21
502 npairs = iend - istart + 1
503 IF (npairs /= 0) THEN
504 ALLOCATE (sort_list(2, npairs), work_list(npairs))
505 sort_list = list(:, istart:iend)
506 ! Sort the list of neighbors, this increases the efficiency for single
507 ! potential contributions
508 CALL sort(sort_list(1, :), npairs, work_list)
509 DO ipair = 1, npairs
510 work_list(ipair) = sort_list(2, work_list(ipair))
511 END DO
512 sort_list(2, :) = work_list
513 ! find number of unique elements of array index 1
514 nunique = 1
515 DO ipair = 1, npairs - 1
516 IF (sort_list(1, ipair + 1) /= sort_list(1, ipair)) nunique = nunique + 1
517 END DO
518 ipair = 1
519 junique = sort_list(1, ipair)
520 ifirst = 1
521 DO iunique = 1, nunique
522 atom_a = junique
523 IF (glob_loc_list_a(ifirst) > atom_a) cycle
524 DO mpair = ifirst, SIZE(glob_loc_list_a)
525 IF (glob_loc_list_a(mpair) == atom_a) EXIT
526 END DO
527 ifirst = mpair
528 DO mpair = ifirst, SIZE(glob_loc_list_a)
529 IF (glob_loc_list_a(mpair) /= atom_a) EXIT
530 END DO
531 ilast = mpair - 1
532 nloc_size = 0
533 IF (ifirst /= 0) nloc_size = ilast - ifirst + 1
534 DO WHILE (ipair <= npairs)
535 IF (sort_list(1, ipair) /= junique) EXIT
536 atom_b = sort_list(2, ipair)
537 ! Energy terms
538 pot_loc = 0.0_dp
539 rij(:) = r_last_update_pbc(atom_b)%r(:) - r_last_update_pbc(atom_a)%r(:) + cell_v
540 drij = dot_product(rij, rij)
541 ipair = ipair + 1
542 IF (drij > rab2_max) cycle
543 drij = sqrt(drij)
544 CALL gal21_energy(pot_loc, gal21, r_last_update_pbc, atom_a, atom_b, &
545 cell, particle_set, mm_section)
546
547 pot_manybody = pot_manybody + pot_loc
548 END DO
549 ifirst = ilast + 1
550 IF (ipair <= npairs) junique = sort_list(1, ipair)
551 END DO
552 DEALLOCATE (sort_list, work_list)
553 END IF
554 END DO
555 END DO kind_group_loop_5
556 END DO
557 CALL destroy_gal21_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
558 END IF
559
560 CALL timestop(handle)
561 END SUBROUTINE energy_manybody
562
563! **************************************************************************************************
564!> \brief ...
565!> \param fist_nonbond_env ...
566!> \param particle_set ...
567!> \param cell ...
568!> \param f_nonbond ...
569!> \param pv_nonbond ...
570!> \param use_virial ...
571!> \par History
572!> Fast implementation of the tersoff potential - [tlaino] 2007
573!> \author I-Feng W. Kuo, Teodoro Laino
574! **************************************************************************************************
575 SUBROUTINE force_nonbond_manybody(fist_nonbond_env, particle_set, cell, &
576 f_nonbond, pv_nonbond, use_virial)
577
578 TYPE(fist_nonbond_env_type), POINTER :: fist_nonbond_env
579 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
580 TYPE(cell_type), POINTER :: cell
581 REAL(kind=dp), DIMENSION(:, :), INTENT(INOUT) :: f_nonbond, pv_nonbond
582 LOGICAL, INTENT(IN) :: use_virial
583
584 CHARACTER(LEN=*), PARAMETER :: routinen = 'force_nonbond_manybody'
585
586 INTEGER :: atom_a, atom_b, handle, i, i_a, i_b, iend, ifirst, igrp, ikind, ilast, ilist, &
587 ipair, istart, iunique, jkind, junique, kind_a, kind_b, mpair, nkinds, nloc_size, npairs, &
588 nunique
589 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: eam_kinds_index
590 INTEGER, DIMENSION(:), POINTER :: glob_loc_list_a, work_list
591 INTEGER, DIMENSION(:, :), POINTER :: glob_loc_list, list, sort_list
592 LOGICAL :: any_ace, any_allegro, any_deepmd, &
593 any_gal, any_gal21, any_nequip, &
594 any_siepmann, any_tersoff
595 REAL(kind=dp) :: f_eam, fac, fr(3), ptens11, ptens12, ptens13, ptens21, ptens22, ptens23, &
596 ptens31, ptens32, ptens33, rab(3), rab2, rab2_max, rtmp(3)
597 REAL(kind=dp), DIMENSION(3) :: cell_v, cvi
598 REAL(kind=dp), DIMENSION(:, :), POINTER :: glob_cell_v
599 TYPE(eam_pot_type), POINTER :: eam_a, eam_b
600 TYPE(eam_type), DIMENSION(:), POINTER :: eam_data
601 TYPE(fist_neighbor_type), POINTER :: nonbonded
602 TYPE(gal21_pot_type), POINTER :: gal21
603 TYPE(gal_pot_type), POINTER :: gal
604 TYPE(neighbor_kind_pairs_type), POINTER :: neighbor_kind_pair
605 TYPE(pair_potential_pp_type), POINTER :: potparm
606 TYPE(pair_potential_single_type), POINTER :: pot
607 TYPE(pos_type), DIMENSION(:), POINTER :: r_last_update_pbc
608 TYPE(siepmann_pot_type), POINTER :: siepmann
609 TYPE(tersoff_pot_type), POINTER :: tersoff
610
611 any_tersoff = .false.
612 any_nequip = .false.
613 any_allegro = .false.
614 any_siepmann = .false.
615 any_ace = .false.
616 any_deepmd = .false.
617 any_gal = .false.
618 any_gal21 = .false.
619 CALL timeset(routinen, handle)
620 NULLIFY (eam_a, eam_b, tersoff, siepmann, gal, gal21)
621
622 CALL fist_nonbond_env_get(fist_nonbond_env, nonbonded=nonbonded, potparm=potparm, &
623 natom_types=nkinds, eam_data=eam_data, r_last_update_pbc=r_last_update_pbc)
624
625 ! Initializing the potential energy, pressure tensor and force
626 IF (use_virial) THEN
627 ptens11 = 0.0_dp; ptens12 = 0.0_dp; ptens13 = 0.0_dp
628 ptens21 = 0.0_dp; ptens22 = 0.0_dp; ptens23 = 0.0_dp
629 ptens31 = 0.0_dp; ptens32 = 0.0_dp; ptens33 = 0.0_dp
630 END IF
631
632 nkinds = SIZE(potparm%pot, 1)
633 ALLOCATE (eam_kinds_index(nkinds, nkinds))
634 eam_kinds_index = -1
635 DO ikind = 1, nkinds
636 DO jkind = ikind, nkinds
637 DO i = 1, SIZE(potparm%pot(ikind, jkind)%pot%type)
638 IF (potparm%pot(ikind, jkind)%pot%type(i) == ea_type) THEN
639 ! At the moment we allow only 1 EAM per each kinds pair..
640 cpassert(eam_kinds_index(ikind, jkind) == -1)
641 cpassert(eam_kinds_index(jkind, ikind) == -1)
642 eam_kinds_index(ikind, jkind) = i
643 eam_kinds_index(jkind, ikind) = i
644 END IF
645 END DO
646 END DO
647 END DO
648 DO ikind = 1, nkinds
649 DO jkind = ikind, nkinds
650 any_ace = any_ace .OR. any(potparm%pot(ikind, jkind)%pot%type == ace_type)
651 END DO
652 END DO
653 ! ACE
654 IF (any_ace) &
655 CALL ace_add_force_virial(fist_nonbond_env, f_nonbond, pv_nonbond, use_virial)
656
657 DO ikind = 1, nkinds
658 DO jkind = ikind, nkinds
659 any_deepmd = any_deepmd .OR. any(potparm%pot(ikind, jkind)%pot%type == deepmd_type)
660 END DO
661 END DO
662 ! DEEPMD
663 IF (any_deepmd) &
664 CALL deepmd_add_force_virial(fist_nonbond_env, f_nonbond, pv_nonbond, use_virial)
665
666 ! starting the force loop
667 DO ilist = 1, nonbonded%nlists
668 neighbor_kind_pair => nonbonded%neighbor_kind_pairs(ilist)
669 npairs = neighbor_kind_pair%npairs
670 IF (npairs == 0) cycle
671 kind_group_loop1: DO igrp = 1, neighbor_kind_pair%ngrp_kind
672 istart = neighbor_kind_pair%grp_kind_start(igrp)
673 iend = neighbor_kind_pair%grp_kind_end(igrp)
674 ikind = neighbor_kind_pair%ij_kind(1, igrp)
675 jkind = neighbor_kind_pair%ij_kind(2, igrp)
676 list => neighbor_kind_pair%list
677 cvi = neighbor_kind_pair%cell_vector
678 pot => potparm%pot(ikind, jkind)%pot
679 IF (pot%no_mb) cycle kind_group_loop1
680 rab2_max = pot%rcutsq
681 cell_v = matmul(cell%hmat, cvi)
682 any_tersoff = any_tersoff .OR. any(pot%type == tersoff_type)
683 any_siepmann = any_siepmann .OR. any(pot%type == siepmann_type)
684 any_ace = any_ace .OR. any(pot%type == ace_type)
685 any_deepmd = any_deepmd .OR. any(pot%type == deepmd_type)
686 any_gal = any_gal .OR. any(pot%type == gal_type)
687 any_gal21 = any_gal21 .OR. any(pot%type == gal21_type)
688 any_nequip = any_nequip .OR. any(pot%type == nequip_type)
689 any_allegro = any_allegro .OR. any(pot%type == allegro_type)
690 i = eam_kinds_index(ikind, jkind)
691 IF (i == -1) cycle kind_group_loop1
692 ! EAM
693 cpassert(ASSOCIATED(eam_data))
694 DO ipair = istart, iend
695 atom_a = list(1, ipair)
696 atom_b = list(2, ipair)
697 fac = 1.0_dp
698 IF (atom_a == atom_b) fac = 0.5_dp
699 kind_a = particle_set(atom_a)%atomic_kind%kind_number
700 kind_b = particle_set(atom_b)%atomic_kind%kind_number
701 i_a = eam_kinds_index(kind_a, kind_a)
702 i_b = eam_kinds_index(kind_b, kind_b)
703 eam_a => potparm%pot(kind_a, kind_a)%pot%set(i_a)%eam
704 eam_b => potparm%pot(kind_b, kind_b)%pot%set(i_b)%eam
705
706 !set this outside the potential type in case need multiple potentials
707 !Do everything necessary for EAM here
708 rab = r_last_update_pbc(atom_b)%r - r_last_update_pbc(atom_a)%r
709 rab = rab + cell_v
710 rab2 = rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3)
711 IF (rab2 <= rab2_max) THEN
712 CALL get_force_eam(rab2, eam_a, eam_b, eam_data, atom_a, atom_b, f_eam)
713 f_eam = f_eam*fac
714
715 fr(1) = -f_eam*rab(1)
716 fr(2) = -f_eam*rab(2)
717 fr(3) = -f_eam*rab(3)
718 f_nonbond(1, atom_a) = f_nonbond(1, atom_a) - fr(1)
719 f_nonbond(2, atom_a) = f_nonbond(2, atom_a) - fr(2)
720 f_nonbond(3, atom_a) = f_nonbond(3, atom_a) - fr(3)
721
722 f_nonbond(1, atom_b) = f_nonbond(1, atom_b) + fr(1)
723 f_nonbond(2, atom_b) = f_nonbond(2, atom_b) + fr(2)
724 f_nonbond(3, atom_b) = f_nonbond(3, atom_b) + fr(3)
725 IF (use_virial) THEN
726 ptens11 = ptens11 + rab(1)*fr(1)
727 ptens21 = ptens21 + rab(2)*fr(1)
728 ptens31 = ptens31 + rab(3)*fr(1)
729 ptens12 = ptens12 + rab(1)*fr(2)
730 ptens22 = ptens22 + rab(2)*fr(2)
731 ptens32 = ptens32 + rab(3)*fr(2)
732 ptens13 = ptens13 + rab(1)*fr(3)
733 ptens23 = ptens23 + rab(2)*fr(3)
734 ptens33 = ptens33 + rab(3)*fr(3)
735 END IF
736 END IF
737 END DO
738 END DO kind_group_loop1
739 END DO
740 DEALLOCATE (eam_kinds_index)
741
742 ! Special way of handling the tersoff potential..
743 IF (any_tersoff) THEN
744 NULLIFY (glob_loc_list, glob_cell_v, glob_loc_list_a)
745 CALL setup_tersoff_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
746 DO ilist = 1, nonbonded%nlists
747 neighbor_kind_pair => nonbonded%neighbor_kind_pairs(ilist)
748 npairs = neighbor_kind_pair%npairs
749 IF (npairs == 0) cycle
750 kind_group_loop2: DO igrp = 1, neighbor_kind_pair%ngrp_kind
751 istart = neighbor_kind_pair%grp_kind_start(igrp)
752 iend = neighbor_kind_pair%grp_kind_end(igrp)
753 ikind = neighbor_kind_pair%ij_kind(1, igrp)
754 jkind = neighbor_kind_pair%ij_kind(2, igrp)
755 list => neighbor_kind_pair%list
756 cvi = neighbor_kind_pair%cell_vector
757 pot => potparm%pot(ikind, jkind)%pot
758
759 IF (pot%no_mb) cycle kind_group_loop2
760 rab2_max = pot%rcutsq
761 cell_v = matmul(cell%hmat, cvi)
762 DO i = 1, SIZE(pot%type)
763 ! TERSOFF
764 IF (pot%type(i) == tersoff_type) THEN
765 npairs = iend - istart + 1
766 tersoff => pot%set(i)%tersoff
767 ALLOCATE (sort_list(2, npairs), work_list(npairs))
768 sort_list = list(:, istart:iend)
769 ! Sort the list of neighbors, this increases the efficiency for single
770 ! potential contributions
771 CALL sort(sort_list(1, :), npairs, work_list)
772 DO ipair = 1, npairs
773 work_list(ipair) = sort_list(2, work_list(ipair))
774 END DO
775 sort_list(2, :) = work_list
776 ! find number of unique elements of array index 1
777 nunique = 1
778 DO ipair = 1, npairs - 1
779 IF (sort_list(1, ipair + 1) /= sort_list(1, ipair)) nunique = nunique + 1
780 END DO
781 ipair = 1
782 junique = sort_list(1, ipair)
783 ifirst = 1
784 DO iunique = 1, nunique
785 atom_a = junique
786 IF (glob_loc_list_a(ifirst) > atom_a) cycle
787 DO mpair = ifirst, SIZE(glob_loc_list_a)
788 IF (glob_loc_list_a(mpair) == atom_a) EXIT
789 END DO
790 ifirst = mpair
791 DO mpair = ifirst, SIZE(glob_loc_list_a)
792 IF (glob_loc_list_a(mpair) /= atom_a) EXIT
793 END DO
794 ilast = mpair - 1
795 nloc_size = 0
796 IF (ifirst /= 0) nloc_size = ilast - ifirst + 1
797 DO WHILE (ipair <= npairs)
798 IF (sort_list(1, ipair) /= junique) EXIT
799 atom_b = sort_list(2, ipair)
800 ! Derivative terms
801 rtmp = r_last_update_pbc(atom_b)%r(:) - r_last_update_pbc(atom_a)%r(:) + cell_v
802 ipair = ipair + 1
803 IF (dot_product(rtmp, rtmp) <= tersoff%rcutsq) THEN
804 CALL tersoff_forces(tersoff, r_last_update_pbc, cell_v, &
805 nloc_size, glob_loc_list(:, ifirst:ilast), glob_cell_v(:, ifirst:ilast), &
806 atom_a, atom_b, f_nonbond, pv_nonbond, use_virial, tersoff%rcutsq)
807 END IF
808 END DO
809 ifirst = ilast + 1
810 IF (ipair <= npairs) junique = sort_list(1, ipair)
811 END DO
812 DEALLOCATE (sort_list, work_list)
813 END IF
814 END DO
815 END DO kind_group_loop2
816 END DO
817 CALL destroy_tersoff_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
818 END IF
819 ! Special way of handling the siepmann potential..
820 IF (any_siepmann) THEN
821 NULLIFY (glob_loc_list, glob_cell_v, glob_loc_list_a)
822 CALL setup_siepmann_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
823 DO ilist = 1, nonbonded%nlists
824 neighbor_kind_pair => nonbonded%neighbor_kind_pairs(ilist)
825 npairs = neighbor_kind_pair%npairs
826 IF (npairs == 0) cycle
827 kind_group_loop3: DO igrp = 1, neighbor_kind_pair%ngrp_kind
828 istart = neighbor_kind_pair%grp_kind_start(igrp)
829 iend = neighbor_kind_pair%grp_kind_end(igrp)
830 ikind = neighbor_kind_pair%ij_kind(1, igrp)
831 jkind = neighbor_kind_pair%ij_kind(2, igrp)
832 list => neighbor_kind_pair%list
833 cvi = neighbor_kind_pair%cell_vector
834 pot => potparm%pot(ikind, jkind)%pot
835
836 IF (pot%no_mb) cycle kind_group_loop3
837 rab2_max = pot%rcutsq
838 cell_v = matmul(cell%hmat, cvi)
839 DO i = 1, SIZE(pot%type)
840 ! SIEPMANN
841 IF (pot%type(i) == siepmann_type) THEN
842 npairs = iend - istart + 1
843 siepmann => pot%set(i)%siepmann
844 ALLOCATE (sort_list(2, npairs), work_list(npairs))
845 sort_list = list(:, istart:iend)
846 ! Sort the list of neighbors, this increases the efficiency for single
847 ! potential contributions
848 CALL sort(sort_list(1, :), npairs, work_list)
849 DO ipair = 1, npairs
850 work_list(ipair) = sort_list(2, work_list(ipair))
851 END DO
852 sort_list(2, :) = work_list
853 ! find number of unique elements of array index 1
854 nunique = 1
855 DO ipair = 1, npairs - 1
856 IF (sort_list(1, ipair + 1) /= sort_list(1, ipair)) nunique = nunique + 1
857 END DO
858 ipair = 1
859 junique = sort_list(1, ipair)
860 ifirst = 1
861 DO iunique = 1, nunique
862 atom_a = junique
863 IF (glob_loc_list_a(ifirst) > atom_a) cycle
864 DO mpair = ifirst, SIZE(glob_loc_list_a)
865 IF (glob_loc_list_a(mpair) == atom_a) EXIT
866 END DO
867 ifirst = mpair
868 DO mpair = ifirst, SIZE(glob_loc_list_a)
869 IF (glob_loc_list_a(mpair) /= atom_a) EXIT
870 END DO
871 ilast = mpair - 1
872 nloc_size = 0
873 IF (ifirst /= 0) nloc_size = ilast - ifirst + 1
874 DO WHILE (ipair <= npairs)
875 IF (sort_list(1, ipair) /= junique) EXIT
876 atom_b = sort_list(2, ipair)
877 ! Derivative terms
878 rtmp = r_last_update_pbc(atom_b)%r(:) - r_last_update_pbc(atom_a)%r(:) + cell_v
879 ipair = ipair + 1
880 IF (dot_product(rtmp, rtmp) <= siepmann%rcutsq) THEN
881 CALL siepmann_forces_v2(siepmann, r_last_update_pbc, cell_v, cell, &
882 atom_a, atom_b, f_nonbond, use_virial, siepmann%rcutsq, &
883 particle_set)
884 CALL siepmann_forces_v3(siepmann, r_last_update_pbc, cell_v, &
885 nloc_size, glob_loc_list(:, ifirst:ilast), &
886 atom_a, atom_b, f_nonbond, use_virial, siepmann%rcutsq, &
887 cell, particle_set)
888 END IF
889 END DO
890 ifirst = ilast + 1
891 IF (ipair <= npairs) junique = sort_list(1, ipair)
892 END DO
893 DEALLOCATE (sort_list, work_list)
894 END IF
895 END DO
896 END DO kind_group_loop3
897 END DO
898 CALL destroy_siepmann_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
899 END IF
900
901 ! GAL19 potential..
902 IF (any_gal) THEN
903 NULLIFY (glob_loc_list, glob_cell_v, glob_loc_list_a)
904 CALL setup_gal_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
905 DO ilist = 1, nonbonded%nlists
906 neighbor_kind_pair => nonbonded%neighbor_kind_pairs(ilist)
907 npairs = neighbor_kind_pair%npairs
908 IF (npairs == 0) cycle
909 kind_group_loop4: DO igrp = 1, neighbor_kind_pair%ngrp_kind
910 istart = neighbor_kind_pair%grp_kind_start(igrp)
911 iend = neighbor_kind_pair%grp_kind_end(igrp)
912 ikind = neighbor_kind_pair%ij_kind(1, igrp)
913 jkind = neighbor_kind_pair%ij_kind(2, igrp)
914 list => neighbor_kind_pair%list
915 cvi = neighbor_kind_pair%cell_vector
916 pot => potparm%pot(ikind, jkind)%pot
917
918 IF (pot%no_mb) cycle kind_group_loop4
919 rab2_max = pot%rcutsq
920 cell_v = matmul(cell%hmat, cvi)
921 DO i = 1, SIZE(pot%type)
922 ! GAL19
923 IF (pot%type(i) == gal_type) THEN
924 npairs = iend - istart + 1
925 gal => pot%set(i)%gal
926 ALLOCATE (sort_list(2, npairs), work_list(npairs))
927 sort_list = list(:, istart:iend)
928 ! Sort the list of neighbors, this increases the efficiency for single
929 ! potential contributions
930 CALL sort(sort_list(1, :), npairs, work_list)
931 DO ipair = 1, npairs
932 work_list(ipair) = sort_list(2, work_list(ipair))
933 END DO
934 sort_list(2, :) = work_list
935 ! find number of unique elements of array index 1
936 nunique = 1
937 DO ipair = 1, npairs - 1
938 IF (sort_list(1, ipair + 1) /= sort_list(1, ipair)) nunique = nunique + 1
939 END DO
940 ipair = 1
941 junique = sort_list(1, ipair)
942 ifirst = 1
943 DO iunique = 1, nunique
944 atom_a = junique
945 IF (glob_loc_list_a(ifirst) > atom_a) cycle
946 DO mpair = ifirst, SIZE(glob_loc_list_a)
947 IF (glob_loc_list_a(mpair) == atom_a) EXIT
948 END DO
949 ifirst = mpair
950 DO mpair = ifirst, SIZE(glob_loc_list_a)
951 IF (glob_loc_list_a(mpair) /= atom_a) EXIT
952 END DO
953 ilast = mpair - 1
954 nloc_size = 0
955 IF (ifirst /= 0) nloc_size = ilast - ifirst + 1
956 DO WHILE (ipair <= npairs)
957 IF (sort_list(1, ipair) /= junique) EXIT
958 atom_b = sort_list(2, ipair)
959 ! Derivative terms
960 rtmp = r_last_update_pbc(atom_b)%r(:) - r_last_update_pbc(atom_a)%r(:) + cell_v
961 ipair = ipair + 1
962 IF (dot_product(rtmp, rtmp) <= gal%rcutsq) THEN
963 CALL gal_forces(gal, r_last_update_pbc, &
964 atom_a, atom_b, f_nonbond, use_virial, &
965 cell, particle_set)
966 END IF
967 END DO
968 ifirst = ilast + 1
969 IF (ipair <= npairs) junique = sort_list(1, ipair)
970 END DO
971 DEALLOCATE (sort_list, work_list)
972 END IF
973 END DO
974 END DO kind_group_loop4
975 END DO
976 CALL destroy_gal_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
977 END IF
978
979 ! GAL21 potential..
980 IF (any_gal21) THEN
981 NULLIFY (glob_loc_list, glob_cell_v, glob_loc_list_a)
982 CALL setup_gal21_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
983 DO ilist = 1, nonbonded%nlists
984 neighbor_kind_pair => nonbonded%neighbor_kind_pairs(ilist)
985 npairs = neighbor_kind_pair%npairs
986 IF (npairs == 0) cycle
987 kind_group_loop6: DO igrp = 1, neighbor_kind_pair%ngrp_kind
988 istart = neighbor_kind_pair%grp_kind_start(igrp)
989 iend = neighbor_kind_pair%grp_kind_end(igrp)
990 ikind = neighbor_kind_pair%ij_kind(1, igrp)
991 jkind = neighbor_kind_pair%ij_kind(2, igrp)
992 list => neighbor_kind_pair%list
993 cvi = neighbor_kind_pair%cell_vector
994 pot => potparm%pot(ikind, jkind)%pot
995
996 IF (pot%no_mb) cycle kind_group_loop6
997 rab2_max = pot%rcutsq
998 cell_v = matmul(cell%hmat, cvi)
999 DO i = 1, SIZE(pot%type)
1000 ! GAL21
1001 IF (pot%type(i) == gal21_type) THEN
1002 npairs = iend - istart + 1
1003 gal21 => pot%set(i)%gal21
1004 ALLOCATE (sort_list(2, npairs), work_list(npairs))
1005 sort_list = list(:, istart:iend)
1006 ! Sort the list of neighbors, this increases the efficiency for single
1007 ! potential contributions
1008 CALL sort(sort_list(1, :), npairs, work_list)
1009 DO ipair = 1, npairs
1010 work_list(ipair) = sort_list(2, work_list(ipair))
1011 END DO
1012 sort_list(2, :) = work_list
1013 ! find number of unique elements of array index 1
1014 nunique = 1
1015 DO ipair = 1, npairs - 1
1016 IF (sort_list(1, ipair + 1) /= sort_list(1, ipair)) nunique = nunique + 1
1017 END DO
1018 ipair = 1
1019 junique = sort_list(1, ipair)
1020 ifirst = 1
1021 DO iunique = 1, nunique
1022 atom_a = junique
1023 IF (glob_loc_list_a(ifirst) > atom_a) cycle
1024 DO mpair = ifirst, SIZE(glob_loc_list_a)
1025 IF (glob_loc_list_a(mpair) == atom_a) EXIT
1026 END DO
1027 ifirst = mpair
1028 DO mpair = ifirst, SIZE(glob_loc_list_a)
1029 IF (glob_loc_list_a(mpair) /= atom_a) EXIT
1030 END DO
1031 ilast = mpair - 1
1032 nloc_size = 0
1033 IF (ifirst /= 0) nloc_size = ilast - ifirst + 1
1034 DO WHILE (ipair <= npairs)
1035 IF (sort_list(1, ipair) /= junique) EXIT
1036 atom_b = sort_list(2, ipair)
1037 ! Derivative terms
1038 rtmp = r_last_update_pbc(atom_b)%r(:) - r_last_update_pbc(atom_a)%r(:) + cell_v
1039 ipair = ipair + 1
1040 IF (dot_product(rtmp, rtmp) <= gal21%rcutsq) THEN
1041 CALL gal21_forces(gal21, r_last_update_pbc, &
1042 atom_a, atom_b, f_nonbond, pv_nonbond, use_virial, &
1043 cell, particle_set)
1044 END IF
1045 END DO
1046 ifirst = ilast + 1
1047 IF (ipair <= npairs) junique = sort_list(1, ipair)
1048 END DO
1049 DEALLOCATE (sort_list, work_list)
1050 END IF
1051 END DO
1052 END DO kind_group_loop6
1053 END DO
1054 CALL destroy_gal_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
1055 END IF
1056
1057 ! NEQUIP
1058 IF (any_nequip) THEN
1059 CALL nequip_add_force_virial(fist_nonbond_env, f_nonbond, pv_nonbond, use_virial)
1060 END IF
1061
1062 ! ALLEGRO
1063 IF (any_allegro) THEN
1064 CALL allegro_add_force_virial(fist_nonbond_env, f_nonbond, pv_nonbond, use_virial)
1065 END IF
1066
1067 IF (use_virial) THEN
1068 pv_nonbond(1, 1) = pv_nonbond(1, 1) + ptens11
1069 pv_nonbond(1, 2) = pv_nonbond(1, 2) + ptens12
1070 pv_nonbond(1, 3) = pv_nonbond(1, 3) + ptens13
1071 pv_nonbond(2, 1) = pv_nonbond(2, 1) + ptens21
1072 pv_nonbond(2, 2) = pv_nonbond(2, 2) + ptens22
1073 pv_nonbond(2, 3) = pv_nonbond(2, 3) + ptens23
1074 pv_nonbond(3, 1) = pv_nonbond(3, 1) + ptens31
1075 pv_nonbond(3, 2) = pv_nonbond(3, 2) + ptens32
1076 pv_nonbond(3, 3) = pv_nonbond(3, 3) + ptens33
1077 END IF
1078 CALL timestop(handle)
1079 END SUBROUTINE force_nonbond_manybody
1080
1081END MODULE manybody_potential
1082
static GRID_HOST_DEVICE double fac(const int i)
Factorial function, e.g. fac(5) = 5! = 120.
Definition grid_common.h:51
Define the atomic kind types and their sub types.
Handles all functions related to the CELL.
Definition cell_types.F:15
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
Define the neighbor list data types and the corresponding functionality.
subroutine, public fist_nonbond_env_get(fist_nonbond_env, potparm14, potparm, nonbonded, rlist_cut, rlist_lowsq, aup, lup, ei_scale14, vdw_scale14, shift_cutoff, do_electrostatics, r_last_update, r_last_update_pbc, rshell_last_update_pbc, rcore_last_update_pbc, cell_last_update, num_update, last_update, counter, natom_types, long_range_correction, ij_kind_full_fac, eam_data, nequip_data, allegro_data, deepmd_data, ace_data, charges)
sets a fist_nonbond_env
objects that represent the structure of input sections and the data contained in an input section
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Definition list.F:24
subroutine, public ace_energy_store_force_virial(particle_set, cell, atomic_kind_set, potparm, fist_nonbond_env, pot_ace)
... >
subroutine, public ace_add_force_virial(fist_nonbond_env, force, pv_nonbond, use_virial)
...
subroutine, public setup_allegro_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, unique_list_a, cell)
...
subroutine, public allegro_add_force_virial(fist_nonbond_env, f_nonbond, pv_nonbond, use_virial)
...
subroutine, public allegro_energy_store_force_virial(nonbonded, particle_set, cell, atomic_kind_set, potparm, allegro, glob_loc_list_a, r_last_update_pbc, pot_allegro, fist_nonbond_env, unique_list_a, para_env, use_virial)
...
subroutine, public destroy_allegro_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a, unique_list_a)
...
subroutine, public deepmd_energy_store_force_virial(particle_set, cell, atomic_kind_set, potparm, fist_nonbond_env, pot_deepmd, para_env)
...
subroutine, public deepmd_add_force_virial(fist_nonbond_env, force, pv_nonbond, use_virial)
...
subroutine, public get_force_eam(rab2, eam_a, eam_b, eam_data, atom_a, atom_b, f_eam)
...
Implementation of the GAL21 potential.
subroutine, public destroy_gal21_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
...
subroutine, public gal21_forces(gal21, r_last_update_pbc, iparticle, jparticle, f_nonbond, pv_nonbond, use_virial, cell, particle_set)
forces generated by the GAL2119 potential
subroutine, public setup_gal21_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
...
subroutine, public gal21_energy(pot_loc, gal21, r_last_update_pbc, iparticle, jparticle, cell, particle_set, mm_section)
Main part of the energy evaluation of GAL2119.
Implementation of the GAL19 potential.
subroutine, public destroy_gal_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
...
subroutine, public setup_gal_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
...
subroutine, public gal_energy(pot_loc, gal, r_last_update_pbc, iparticle, jparticle, cell, particle_set, mm_section)
Main part of the energy evaluation of GAL19.
subroutine, public gal_forces(gal, r_last_update_pbc, iparticle, jparticle, f_nonbond, use_virial, cell, particle_set)
forces generated by the GAL19 potential
subroutine, public nequip_add_force_virial(fist_nonbond_env, f_nonbond, pv_nonbond, use_virial)
...
subroutine, public destroy_nequip_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
...
subroutine, public nequip_energy_store_force_virial(nonbonded, particle_set, cell, atomic_kind_set, potparm, nequip, glob_loc_list_a, r_last_update_pbc, pot_nequip, fist_nonbond_env, para_env, use_virial)
...
subroutine, public setup_nequip_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
...
subroutine, public force_nonbond_manybody(fist_nonbond_env, particle_set, cell, f_nonbond, pv_nonbond, use_virial)
...
subroutine, public energy_manybody(fist_nonbond_env, atomic_kind_set, local_particles, particle_set, cell, pot_manybody, para_env, mm_section, use_virial)
computes the embedding contribution to the energy
implementation of dipole and three-body part of Siepmann-Sprik potential dipole term: 3rd term in Eq....
subroutine, public siepmann_energy(pot_loc, siepmann, r_last_update_pbc, atom_a, atom_b, nloc_size, full_loc_list, cell_v, cell, drij, particle_set, nr_oh, nr_h3o, nr_o)
energy of two-body dipole term and three-body term
subroutine, public setup_siepmann_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
...
subroutine, public siepmann_forces_v2(siepmann, r_last_update_pbc, cell_v, cell, iparticle, jparticle, f_nonbond, use_virial, rcutsq, particle_set)
forces generated by the dipole term
subroutine, public siepmann_forces_v3(siepmann, r_last_update_pbc, cell_v, n_loc_size, full_loc_list, iparticle, jparticle, f_nonbond, use_virial, rcutsq, cell, particle_set)
forces generated by the three-body term
subroutine, public print_nr_ions_siepmann(nr_ions, mm_section, para_env, print_oh, print_h3o, print_o)
prints the number of OH- ions or H3O+ ions near surface
subroutine, public destroy_siepmann_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
...
subroutine, public setup_tersoff_arrays(nonbonded, potparm, glob_loc_list, glob_cell_v, glob_loc_list_a, cell)
...
subroutine, public tersoff_forces(tersoff, r_last_update_pbc, cell_v, n_loc_size, full_loc_list, loc_cell_v, iparticle, jparticle, f_nonbond, pv_nonbond, use_virial, rcutsq)
...
subroutine, public destroy_tersoff_arrays(glob_loc_list, glob_cell_v, glob_loc_list_a)
...
subroutine, public tersoff_energy(pot_loc, tersoff, r_last_update_pbc, atom_a, atom_b, nloc_size, full_loc_list, loc_cell_v, cell_v, drij)
...
Interface to the message passing library MPI.
integer, parameter, public allegro_type
integer, parameter, public gal_type
integer, parameter, public nequip_type
integer, parameter, public deepmd_type
integer, parameter, public siepmann_type
integer, parameter, public ace_type
integer, parameter, public gal21_type
integer, parameter, public ea_type
integer, parameter, public tersoff_type
Define the data structure for the particle information.
All kind of helpful little routines.
Definition util.F:14
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
structure to store local (to a processor) ordered lists of integers.
stores all the informations relevant to an mpi environment