(git:97501a3)
Loading...
Searching...
No Matches
core_ppl.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7! **************************************************************************************************
8!> \brief Calculation of the local pseudopotential contribution to the core Hamiltonian
9!> <a|V(local)|b> = <a|Sum e^a*rc**2|b>
10!> \par History
11!> - core_ppnl refactored from qs_core_hamiltonian [Joost VandeVondele, 2008-11-01]
12!> - adapted for PPL [jhu, 2009-02-23]
13!> - OpenMP added [Iain Bethune, Fiona Reid, 2013-11-13]
14!> - Bug fix: correct orbital pointer range [07.2014,JGH]
15!> - k-point aware [07.2015,JGH]
16!> - Extended by the derivatives for DFPT [Sandra Luber, Edward Ditler, 2021]
17! **************************************************************************************************
19
27 USE cp_dbcsr_api, ONLY: dbcsr_add,&
33 USE kinds, ONLY: dp,&
34 int_8
41 ncoset
44 USE qs_kind_types, ONLY: get_qs_kind,&
55 USE virial_types, ONLY: virial_type
56
57!$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num, omp_get_num_threads
58!$ USE OMP_LIB, ONLY: omp_lock_kind, &
59!$ omp_init_lock, omp_set_lock, &
60!$ omp_unset_lock, omp_destroy_lock
61
62#include "./base/base_uses.f90"
63
64 IMPLICIT NONE
65
66 PRIVATE
67
68 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'core_ppl'
69
71
72CONTAINS
73
74! **************************************************************************************************
75!> \brief ...
76!> \param matrix_h ...
77!> \param matrix_p ...
78!> \param force ...
79!> \param virial ...
80!> \param calculate_forces ...
81!> \param use_virial ...
82!> \param nder ...
83!> \param qs_kind_set ...
84!> \param atomic_kind_set ...
85!> \param particle_set ...
86!> \param sab_orb ...
87!> \param sac_ppl ...
88!> \param nimages ...
89!> \param cell_to_index ...
90!> \param basis_type ...
91!> \param deltaR Weighting factors of the derivatives wrt. nuclear positions
92!> \param atcore ...
93! **************************************************************************************************
94 SUBROUTINE build_core_ppl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, &
95 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, &
96 nimages, cell_to_index, basis_type, deltaR, atcore)
97
98 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrix_p
99 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
100 TYPE(virial_type), POINTER :: virial
101 LOGICAL, INTENT(IN) :: calculate_forces
102 LOGICAL :: use_virial
103 INTEGER :: nder
104 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
105 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
106 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
107 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
108 POINTER :: sab_orb, sac_ppl
109 INTEGER, INTENT(IN) :: nimages
110 INTEGER, DIMENSION(:, :, :), OPTIONAL, POINTER :: cell_to_index
111 CHARACTER(LEN=*), INTENT(IN) :: basis_type
112 REAL(kind=dp), DIMENSION(:, :), INTENT(IN), &
113 OPTIONAL :: deltar
114 REAL(kind=dp), DIMENSION(:), INTENT(INOUT), &
115 OPTIONAL :: atcore
116
117 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_core_ppl'
118 INTEGER, PARAMETER :: nexp_max = 30
119
120 INTEGER :: atom_a, handle, i, iatom, icol, ikind, img, irow, iset, jatom, jkind, jset, &
121 katom, kkind, ldai, ldsab, maxco, maxder, maxl, maxlgto, maxlppl, maxnset, maxsgf, mepos, &
122 n_local, natom, ncoa, ncob, nexp_lpot, nexp_ppl, nkind, nloc, nseta, nsetb, nthread, &
123 sgfa, sgfb, slmax, slot
124 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of
125 INTEGER, DIMENSION(0:10) :: npot
126 INTEGER, DIMENSION(1:10) :: nrloc
127 INTEGER, DIMENSION(1:15, 0:10) :: nrpot
128 INTEGER, DIMENSION(3) :: cellind
129 INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, &
130 nct_lpot, npgfa, npgfb, nsgfa, nsgfb
131 INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
132 INTEGER, DIMENSION(nexp_max) :: nct_ppl
133 LOGICAL :: do_dr, doat, dokp, ecp_local, &
134 ecp_semi_local, found, libgrpp_local, &
135 lpotextended, only_gaussians
136 REAL(kind=dp) :: alpha, atk0, atk1, dab, dac, dbc, f0, &
137 ppl_radius
138 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: work
139 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: hab2_w, ppl_fwork, ppl_work
140 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :, :) :: hab, pab
141 REAL(kind=dp), ALLOCATABLE, &
142 DIMENSION(:, :, :, :, :) :: hab2
143 REAL(kind=dp), DIMENSION(1:10) :: aloc, bloc
144 REAL(kind=dp), DIMENSION(1:15, 0:10) :: apot, bpot
145 REAL(kind=dp), DIMENSION(3) :: force_a, force_b, rab, rac, rbc
146 REAL(kind=dp), DIMENSION(3, 3) :: pv_thread
148 DIMENSION(:), POINTER :: ap_iterator
149 TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
150 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
151 TYPE(gth_potential_type), POINTER :: gth_potential
152 REAL(kind=dp), DIMENSION(SIZE(particle_set)) :: at_thread
153 REAL(kind=dp), DIMENSION(nexp_max) :: alpha_ppl
154 REAL(kind=dp), DIMENSION(:, :), POINTER :: cval_lpot, h1_1block, h1_2block, &
155 h1_3block, h_block, p_block, rpgfa, &
156 rpgfb, sphi_a, sphi_b, zeta, zetb
157 REAL(kind=dp), DIMENSION(:), POINTER :: a_local, alpha_lpot, c_local, cexp_ppl, &
158 set_radius_a, set_radius_b
159 REAL(kind=dp), DIMENSION(4, nexp_max) :: cval_ppl
160 REAL(kind=dp), DIMENSION(3, SIZE(particle_set)) :: force_thread
161 TYPE(sgp_potential_type), POINTER :: sgp_potential
162
163!$ INTEGER(kind=omp_lock_kind), &
164!$ ALLOCATABLE, DIMENSION(:) :: locks
165!$ INTEGER :: lock_num, hash, hash1, hash2
166!$ INTEGER(KIND=int_8) :: iatom8
167!$ INTEGER, PARAMETER :: nlock = 501
168
169 do_dr = PRESENT(deltar)
170 doat = PRESENT(atcore)
171 IF ((calculate_forces .OR. doat) .AND. do_dr) THEN
172 cpabort("core_ppl: incompatible options")
173 END IF
174
175 mark_used(int_8)
176
177 ! Use internal integral routine for local ECP terms or use libgrrp
178 libgrpp_local = .false.
179
180 IF (calculate_forces) THEN
181 CALL timeset(routinen//"_forces", handle)
182 ELSE
183 CALL timeset(routinen, handle)
184 END IF
185
186 nkind = SIZE(atomic_kind_set)
187 natom = SIZE(particle_set)
188
189 dokp = (nimages > 1)
190
191 IF (dokp) THEN
192 cpassert(PRESENT(cell_to_index) .AND. ASSOCIATED(cell_to_index))
193 END IF
194
195 IF (calculate_forces .OR. doat) THEN
196 IF (SIZE(matrix_p, 1) == 2) THEN
197 DO img = 1, nimages
198 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
199 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
200 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
201 alpha_scalar=-2.0_dp, beta_scalar=1.0_dp)
202 END DO
203 END IF
204 END IF
205 force_thread = 0.0_dp
206 at_thread = 0.0_dp
207
208 maxder = ncoset(nder)
209
210 CALL get_qs_kind_set(qs_kind_set, maxco=maxco, maxlgto=maxlgto, &
211 maxsgf=maxsgf, maxnset=maxnset, maxlppl=maxlppl, &
212 basis_type=basis_type)
213
214 maxl = max(maxlgto, maxlppl)
215 CALL init_orbital_pointers(2*maxl + 2*nder + 1)
216
217 ldsab = max(maxco, ncoset(maxlppl), maxsgf, maxlppl)
218 ldai = ncoset(maxl + nder + 1)
219
220 ALLOCATE (basis_set_list(nkind))
221 DO ikind = 1, nkind
222 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set_a, basis_type=basis_type)
223 IF (ASSOCIATED(basis_set_a)) THEN
224 basis_set_list(ikind)%gto_basis_set => basis_set_a
225 ELSE
226 NULLIFY (basis_set_list(ikind)%gto_basis_set)
227 END IF
228 END DO
229
230 pv_thread = 0.0_dp
231
232 nthread = 1
233!$ nthread = omp_get_max_threads()
234
235 ! iterator for basis/potential list
236 CALL neighbor_list_iterator_create(ap_iterator, sac_ppl, search=.true., nthread=nthread)
237
238!$OMP PARALLEL &
239!$OMP DEFAULT (NONE) &
240!$OMP SHARED (ap_iterator, basis_set_list, calculate_forces, use_virial, &
241!$OMP matrix_h, matrix_p, atomic_kind_set, qs_kind_set, particle_set, &
242!$OMP sab_orb, sac_ppl, nthread, ncoset, nkind, cell_to_index, &
243!$OMP ldsab, maxnset, maxder, do_dR, deltaR, doat, libgrpp_local, &
244!$OMP maxlgto, nder, maxco, dokp, locks, natom) &
245!$OMP PRIVATE (ikind, jkind, iatom, jatom, rab, basis_set_a, basis_set_b, &
246!$OMP first_sgfa, la_max, la_min, npgfa, nsgfa, sphi_a, &
247!$OMP zeta, first_sgfb, lb_max, lb_min, npgfb, nsetb, rpgfb, set_radius_b, sphi_b, &
248!$OMP zetb, dab, irow, icol, h_block, found, iset, ncoa, lock_num, &
249!$OMP sgfa, jset, ncob, sgfb, nsgfb, p_block, work, pab, hab, hab2, hab2_w, &
250!$OMP atk0, atk1, h1_1block, h1_2block, h1_3block, kkind, nseta, &
251!$OMP gth_potential, sgp_potential, alpha, cexp_ppl, lpotextended, &
252!$OMP ppl_radius, nexp_lpot, nexp_ppl, alpha_ppl, alpha_lpot, nct_ppl, &
253!$OMP nct_lpot, cval_ppl, cval_lpot, rac, dac, rbc, dbc, &
254!$OMP set_radius_a, rpgfa, force_a, force_b, ppl_fwork, mepos, &
255!$OMP slot, f0, katom, ppl_work, cellind, img, ecp_local, ecp_semi_local, &
256!$OMP nloc, nrloc, aloc, bloc, n_local, a_local, c_local, &
257!$OMP slmax, npot, nrpot, apot, bpot, only_gaussians, &
258!$OMP ldai, hash, hash1, hash2, iatom8) &
259!$OMP REDUCTION (+ : pv_thread, force_thread, at_thread )
260
261!$OMP SINGLE
262!$ ALLOCATE (locks(nlock))
263!$OMP END SINGLE
264
265!$OMP DO
266!$ DO lock_num = 1, nlock
267!$ call omp_init_lock(locks(lock_num))
268!$ END DO
269!$OMP END DO
270
271 mepos = 0
272!$ mepos = omp_get_thread_num()
273
274 ALLOCATE (hab(ldsab, ldsab, maxnset, maxnset), work(ldsab, ldsab*maxder))
275 ldai = ncoset(2*maxlgto + 2*nder)
276 ALLOCATE (ppl_work(ldai, ldai, max(maxder, 2*maxlgto + 2*nder + 1)))
277 IF (calculate_forces .OR. doat) THEN
278 ALLOCATE (pab(maxco, maxco, maxnset, maxnset))
279 ldai = ncoset(maxlgto)
280 ALLOCATE (ppl_fwork(ldai, ldai, maxder))
281 END IF
282
283!$OMP DO SCHEDULE(GUIDED)
284 DO slot = 1, sab_orb(1)%nl_size
285 !SL
286 IF (do_dr) THEN
287 ALLOCATE (hab2(ldsab, ldsab, 4, maxnset, maxnset))
288 ALLOCATE (hab2_w(ldsab, ldsab, 6))
289 ALLOCATE (ppl_fwork(ldai, ldai, maxder))
290 END IF
291
292 ikind = sab_orb(1)%nlist_task(slot)%ikind
293 jkind = sab_orb(1)%nlist_task(slot)%jkind
294 iatom = sab_orb(1)%nlist_task(slot)%iatom
295 jatom = sab_orb(1)%nlist_task(slot)%jatom
296 cellind(:) = sab_orb(1)%nlist_task(slot)%cell(:)
297 rab(1:3) = sab_orb(1)%nlist_task(slot)%r(1:3)
298
299 basis_set_a => basis_set_list(ikind)%gto_basis_set
300 IF (.NOT. ASSOCIATED(basis_set_a)) cycle
301 basis_set_b => basis_set_list(jkind)%gto_basis_set
302 IF (.NOT. ASSOCIATED(basis_set_b)) cycle
303
304!$ iatom8 = INT(iatom - 1, int_8)*INT(natom, int_8) + INT(jatom, int_8)
305!$ hash1 = INT(MOD(iatom8, INT(nlock, int_8)) + 1)
306
307 ! basis ikind
308 first_sgfa => basis_set_a%first_sgf
309 la_max => basis_set_a%lmax
310 la_min => basis_set_a%lmin
311 npgfa => basis_set_a%npgf
312 nseta = basis_set_a%nset
313 nsgfa => basis_set_a%nsgf_set
314 rpgfa => basis_set_a%pgf_radius
315 set_radius_a => basis_set_a%set_radius
316 sphi_a => basis_set_a%sphi
317 zeta => basis_set_a%zet
318 ! basis jkind
319 first_sgfb => basis_set_b%first_sgf
320 lb_max => basis_set_b%lmax
321 lb_min => basis_set_b%lmin
322 npgfb => basis_set_b%npgf
323 nsetb = basis_set_b%nset
324 nsgfb => basis_set_b%nsgf_set
325 rpgfb => basis_set_b%pgf_radius
326 set_radius_b => basis_set_b%set_radius
327 sphi_b => basis_set_b%sphi
328 zetb => basis_set_b%zet
329
330 dab = sqrt(sum(rab*rab))
331
332 IF (dokp) THEN
333 img = cell_to_index(cellind(1), cellind(2), cellind(3))
334 ELSE
335 img = 1
336 END IF
337
338 ! *** Use the symmetry of the first derivatives ***
339 IF (iatom == jatom) THEN
340 f0 = 1.0_dp
341 ELSE
342 f0 = 2.0_dp
343 END IF
344
345 ! *** Create matrix blocks for a new matrix block column ***
346 IF (iatom <= jatom) THEN
347 irow = iatom
348 icol = jatom
349 ELSE
350 irow = jatom
351 icol = iatom
352 END IF
353 NULLIFY (h_block)
354
355 IF (do_dr) THEN
356 NULLIFY (h1_1block, h1_2block, h1_3block)
357
358 CALL dbcsr_get_block_p(matrix=matrix_h(1, img)%matrix, &
359 row=irow, col=icol, block=h1_1block, found=found)
360 CALL dbcsr_get_block_p(matrix=matrix_h(2, img)%matrix, &
361 row=irow, col=icol, block=h1_2block, found=found)
362 CALL dbcsr_get_block_p(matrix=matrix_h(3, img)%matrix, &
363 row=irow, col=icol, block=h1_3block, found=found)
364 END IF
365
366 CALL dbcsr_get_block_p(matrix_h(1, img)%matrix, irow, icol, h_block, found)
367 cpassert(found)
368 IF (calculate_forces .OR. doat) THEN
369 NULLIFY (p_block)
370 CALL dbcsr_get_block_p(matrix_p(1, img)%matrix, irow, icol, p_block, found)
371 IF (ASSOCIATED(p_block)) THEN
372 DO iset = 1, nseta
373 ncoa = npgfa(iset)*ncoset(la_max(iset))
374 sgfa = first_sgfa(1, iset)
375 DO jset = 1, nsetb
376 ncob = npgfb(jset)*ncoset(lb_max(jset))
377 sgfb = first_sgfb(1, jset)
378
379 ! *** Decontract density matrix block ***
380 IF (iatom <= jatom) THEN
381 work(1:ncoa, 1:nsgfb(jset)) = matmul(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1), &
382 p_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1))
383 ELSE
384 work(1:ncoa, 1:nsgfb(jset)) = matmul(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1), &
385 transpose(p_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1)))
386 END IF
387
388 pab(1:ncoa, 1:ncob, iset, jset) = matmul(work(1:ncoa, 1:nsgfb(jset)), &
389 transpose(sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1)))
390 END DO
391 END DO
392 END IF
393 END IF
394
395 hab = 0._dp
396 IF (do_dr) hab2 = 0._dp
397
398 ! loop over all kinds for pseudopotential atoms
399 DO kkind = 1, nkind
400
401 CALL get_qs_kind(qs_kind_set(kkind), gth_potential=gth_potential, &
402 sgp_potential=sgp_potential)
403 ecp_semi_local = .false.
404 only_gaussians = .true.
405 IF (ASSOCIATED(gth_potential)) THEN
406 CALL get_potential(potential=gth_potential, &
407 alpha_ppl=alpha, cexp_ppl=cexp_ppl, &
408 lpot_present=lpotextended, ppl_radius=ppl_radius)
409 nexp_ppl = 1
410 alpha_ppl(1) = alpha
411 nct_ppl(1) = SIZE(cexp_ppl)
412 cval_ppl(1:nct_ppl(1), 1) = cexp_ppl(1:nct_ppl(1))
413 IF (lpotextended) THEN
414 CALL get_potential(potential=gth_potential, &
415 nexp_lpot=nexp_lpot, alpha_lpot=alpha_lpot, nct_lpot=nct_lpot, &
416 cval_lpot=cval_lpot)
417 cpassert(nexp_lpot < nexp_max)
418 nexp_ppl = nexp_lpot + 1
419 alpha_ppl(2:nexp_lpot + 1) = alpha_lpot(1:nexp_lpot)
420 nct_ppl(2:nexp_lpot + 1) = nct_lpot(1:nexp_lpot)
421 DO i = 1, nexp_lpot
422 cval_ppl(1:nct_lpot(i), i + 1) = cval_lpot(1:nct_lpot(i), i)
423 END DO
424 END IF
425 ELSE IF (ASSOCIATED(sgp_potential)) THEN
426 CALL get_potential(potential=sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local, &
427 ppl_radius=ppl_radius)
428 IF (ecp_local) THEN
429 CALL get_potential(potential=sgp_potential, nloc=nloc, nrloc=nrloc, aloc=aloc, bloc=bloc)
430 nexp_ppl = nloc
431 cpassert(nexp_ppl <= nexp_max)
432 nct_ppl(1:nloc) = nrloc(1:nloc)
433 alpha_ppl(1:nloc) = bloc(1:nloc)
434 cval_ppl(1, 1:nloc) = aloc(1:nloc)
435 only_gaussians = .false.
436 ELSE
437 CALL get_potential(potential=sgp_potential, n_local=n_local, a_local=a_local, c_local=c_local)
438 nexp_ppl = n_local
439 cpassert(nexp_ppl <= nexp_max)
440 nct_ppl(1:n_local) = 1
441 alpha_ppl(1:n_local) = a_local(1:n_local)
442 cval_ppl(1, 1:n_local) = c_local(1:n_local)
443 END IF
444 IF (ecp_semi_local) THEN
445 CALL get_potential(potential=sgp_potential, sl_lmax=slmax, &
446 npot=npot, nrpot=nrpot, apot=apot, bpot=bpot)
447 ELSEIF (ecp_local) THEN
448 IF (sum(abs(aloc(1:nloc))) < 1.0e-12_dp) cycle
449 END IF
450 ELSE
451 cycle
452 END IF
453
454 CALL nl_set_sub_iterator(ap_iterator, ikind, kkind, iatom, mepos=mepos)
455
456 DO WHILE (nl_sub_iterate(ap_iterator, mepos=mepos) == 0)
457
458 CALL get_iterator_info(ap_iterator, mepos=mepos, jatom=katom, r=rac)
459
460 dac = sqrt(sum(rac*rac))
461 rbc(:) = rac(:) - rab(:)
462 dbc = sqrt(sum(rbc*rbc))
463 IF ((maxval(set_radius_a(:)) + ppl_radius < dac) .OR. &
464 (maxval(set_radius_b(:)) + ppl_radius < dbc)) THEN
465 cycle
466 END IF
467
468 DO iset = 1, nseta
469 IF (set_radius_a(iset) + ppl_radius < dac) cycle
470 ncoa = npgfa(iset)*ncoset(la_max(iset))
471 sgfa = first_sgfa(1, iset)
472 DO jset = 1, nsetb
473 IF (set_radius_b(jset) + ppl_radius < dbc) cycle
474 ncob = npgfb(jset)*ncoset(lb_max(jset))
475 sgfb = first_sgfb(1, jset)
476 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
477 ! *** Calculate the GTH pseudo potential forces ***
478 IF (doat) THEN
479 atk0 = f0*sum(hab(1:ncoa, 1:ncob, iset, jset)* &
480 pab(1:ncoa, 1:ncob, iset, jset))
481 END IF
482 IF (calculate_forces) THEN
483
484 force_a(:) = 0.0_dp
485 force_b(:) = 0.0_dp
486
487 IF (only_gaussians) THEN
488 CALL ppl_integral( &
489 la_max(iset), la_min(iset), npgfa(iset), &
490 rpgfa(:, iset), zeta(:, iset), &
491 lb_max(jset), lb_min(jset), npgfb(jset), &
492 rpgfb(:, jset), zetb(:, jset), &
493 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
494 rab, dab, rac, dac, rbc, dbc, &
495 hab(:, :, iset, jset), ppl_work, pab(:, :, iset, jset), &
496 force_a, force_b, ppl_fwork)
497 ELSEIF (libgrpp_local) THEN
498!$OMP CRITICAL(type1)
499 CALL libgrpp_local_forces_ref(la_max(iset), la_min(iset), npgfa(iset), &
500 rpgfa(:, iset), zeta(:, iset), &
501 lb_max(jset), lb_min(jset), npgfb(jset), &
502 rpgfb(:, jset), zetb(:, jset), &
503 nexp_ppl, alpha_ppl, cval_ppl(1, :), nct_ppl, &
504 ppl_radius, rab, dab, rac, dac, dbc, &
505 hab(:, :, iset, jset), pab(:, :, iset, jset), &
506 force_a, force_b)
507!$OMP END CRITICAL(type1)
508 ELSE
509 CALL ecploc_integral( &
510 la_max(iset), la_min(iset), npgfa(iset), &
511 rpgfa(:, iset), zeta(:, iset), &
512 lb_max(jset), lb_min(jset), npgfb(jset), &
513 rpgfb(:, jset), zetb(:, jset), &
514 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
515 rab, dab, rac, dac, rbc, dbc, &
516 hab(:, :, iset, jset), ppl_work, pab(:, :, iset, jset), &
517 force_a, force_b, ppl_fwork)
518 END IF
519
520 IF (ecp_semi_local) THEN
521
522!$OMP CRITICAL(type2)
523 CALL libgrpp_semilocal_forces_ref(la_max(iset), la_min(iset), npgfa(iset), &
524 rpgfa(:, iset), zeta(:, iset), &
525 lb_max(jset), lb_min(jset), npgfb(jset), &
526 rpgfb(:, jset), zetb(:, jset), &
527 slmax, npot, bpot, apot, nrpot, &
528 ppl_radius, rab, dab, rac, dac, dbc, &
529 hab(:, :, iset, jset), pab(:, :, iset, jset), &
530 force_a, force_b)
531!$OMP END CRITICAL(type2)
532 END IF
533 ! *** The derivatives w.r.t. atomic center c are ***
534 ! *** calculated using the translational invariance ***
535 ! *** of the first derivatives ***
536
537 force_thread(1, iatom) = force_thread(1, iatom) + f0*force_a(1)
538 force_thread(2, iatom) = force_thread(2, iatom) + f0*force_a(2)
539 force_thread(3, iatom) = force_thread(3, iatom) + f0*force_a(3)
540 force_thread(1, katom) = force_thread(1, katom) - f0*force_a(1)
541 force_thread(2, katom) = force_thread(2, katom) - f0*force_a(2)
542 force_thread(3, katom) = force_thread(3, katom) - f0*force_a(3)
543
544 force_thread(1, jatom) = force_thread(1, jatom) + f0*force_b(1)
545 force_thread(2, jatom) = force_thread(2, jatom) + f0*force_b(2)
546 force_thread(3, jatom) = force_thread(3, jatom) + f0*force_b(3)
547 force_thread(1, katom) = force_thread(1, katom) - f0*force_b(1)
548 force_thread(2, katom) = force_thread(2, katom) - f0*force_b(2)
549 force_thread(3, katom) = force_thread(3, katom) - f0*force_b(3)
550
551 IF (use_virial) THEN
552 CALL virial_pair_force(pv_thread, f0, force_a, rac)
553 CALL virial_pair_force(pv_thread, f0, force_b, rbc)
554 END IF
555 ELSEIF (do_dr) THEN
556 hab2_w = 0._dp
557 CALL ppl_integral( &
558 la_max(iset), la_min(iset), npgfa(iset), &
559 rpgfa(:, iset), zeta(:, iset), &
560 lb_max(jset), lb_min(jset), npgfb(jset), &
561 rpgfb(:, jset), zetb(:, jset), &
562 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
563 rab, dab, rac, dac, rbc, dbc, &
564 vab=hab(:, :, iset, jset), s=ppl_work, &
565 hab2=hab2(:, :, :, iset, jset), hab2_work=hab2_w, fs=ppl_fwork, &
566 deltar=deltar, iatom=iatom, jatom=jatom, katom=katom)
567 IF (ecp_semi_local) THEN
568 ! semi local ECP part
569 cpabort("Option not implemented")
570 END IF
571 ELSE
572 IF (only_gaussians) THEN
573 !If the local part of the pseudo-potential only has Gaussian functions
574 !we can use CP2K native code, that can run without libgrpp installation
575 CALL ppl_integral( &
576 la_max(iset), la_min(iset), npgfa(iset), &
577 rpgfa(:, iset), zeta(:, iset), &
578 lb_max(jset), lb_min(jset), npgfb(jset), &
579 rpgfb(:, jset), zetb(:, jset), &
580 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
581 rab, dab, rac, dac, rbc, dbc, hab(:, :, iset, jset), ppl_work)
582
583 ELSEIF (libgrpp_local) THEN
584 !If the local part of the potential is more complex, we need libgrpp
585!$OMP CRITICAL(type1)
586 CALL libgrpp_local_integrals(la_max(iset), la_min(iset), npgfa(iset), &
587 rpgfa(:, iset), zeta(:, iset), &
588 lb_max(jset), lb_min(jset), npgfb(jset), &
589 rpgfb(:, jset), zetb(:, jset), &
590 nexp_ppl, alpha_ppl, cval_ppl(1, :), nct_ppl, &
591 ppl_radius, rab, dab, rac, dac, dbc, &
592 hab(:, :, iset, jset))
593!$OMP END CRITICAL(type1)
594 ELSE
595 CALL ecploc_integral( &
596 la_max(iset), la_min(iset), npgfa(iset), &
597 rpgfa(:, iset), zeta(:, iset), &
598 lb_max(jset), lb_min(jset), npgfb(jset), &
599 rpgfb(:, jset), zetb(:, jset), &
600 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
601 rab, dab, rac, dac, rbc, dbc, hab(:, :, iset, jset), ppl_work)
602 END IF
603
604 IF (ecp_semi_local) THEN
605 ! semi local ECP part
606!$OMP CRITICAL(type2)
607 CALL libgrpp_semilocal_integrals(la_max(iset), la_min(iset), npgfa(iset), &
608 rpgfa(:, iset), zeta(:, iset), &
609 lb_max(jset), lb_min(jset), npgfb(jset), &
610 rpgfb(:, jset), zetb(:, jset), &
611 slmax, npot, bpot, apot, nrpot, &
612 ppl_radius, rab, dab, rac, dac, dbc, &
613 hab(:, :, iset, jset))
614!$OMP END CRITICAL(type2)
615 END IF
616 END IF
617 ! calculate atomic contributions
618 IF (doat) THEN
619 atk1 = f0*sum(hab(1:ncoa, 1:ncob, iset, jset)* &
620 pab(1:ncoa, 1:ncob, iset, jset))
621 at_thread(katom) = at_thread(katom) + (atk1 - atk0)
622 END IF
623 END DO
624 END DO
625 END DO
626 END DO
627
628 ! *** Contract PPL integrals
629 IF (.NOT. do_dr) THEN
630 DO iset = 1, nseta
631 ncoa = npgfa(iset)*ncoset(la_max(iset))
632 sgfa = first_sgfa(1, iset)
633 DO jset = 1, nsetb
634 ncob = npgfb(jset)*ncoset(lb_max(jset))
635 sgfb = first_sgfb(1, jset)
636
637!$ hash2 = MOD((iset - 1)*nsetb + jset, nlock) + 1
638!$ hash = MOD(hash1 + hash2, nlock) + 1
639
640 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab(1:ncoa, 1:ncob, iset, jset), &
641 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
642!$ CALL omp_set_lock(locks(hash))
643 IF (iatom <= jatom) THEN
644 h_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
645 h_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
646 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
647 ELSE
648 h_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
649 h_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
650 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
651 END IF
652!$ CALL omp_unset_lock(locks(hash))
653
654 END DO
655 END DO
656 ELSE ! do_dr == .true.
657 DO iset = 1, nseta
658 ncoa = npgfa(iset)*ncoset(la_max(iset))
659 sgfa = first_sgfa(1, iset)
660 DO jset = 1, nsetb
661 ncob = npgfb(jset)*ncoset(lb_max(jset))
662 sgfb = first_sgfb(1, jset)
663 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 1, iset, jset), &
664 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
665
666!$OMP CRITICAL(h1_1block_critical)
667 IF (iatom <= jatom) THEN
668 h1_1block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
669 h1_1block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
670 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
671
672 ELSE
673 h1_1block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
674 h1_1block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
675 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
676 END IF
677!$OMP END CRITICAL(h1_1block_critical)
678 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 2, iset, jset), &
679 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
680
681!$OMP CRITICAL(h1_2block_critical)
682 IF (iatom <= jatom) THEN
683 h1_2block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
684 h1_2block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
685 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
686
687 ELSE
688 h1_2block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
689 h1_2block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
690 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
691 END IF
692!$OMP END CRITICAL(h1_2block_critical)
693 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 3, iset, jset), &
694 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
695!$OMP CRITICAL(h1_3block_critical)
696 IF (iatom <= jatom) THEN
697 h1_3block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
698 h1_3block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
699 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
700
701 ELSE
702 h1_3block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
703 h1_3block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
704 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
705 END IF
706!$OMP END CRITICAL(h1_3block_critical)
707 END DO
708 END DO
709 END IF
710 IF (do_dr) DEALLOCATE (hab2, ppl_fwork, hab2_w)
711 END DO ! slot
712
713 DEALLOCATE (hab, work, ppl_work)
714 IF (calculate_forces .OR. doat) THEN
715 DEALLOCATE (pab, ppl_fwork)
716 END IF
717
718!$OMP DO
719!$ DO lock_num = 1, nlock
720!$ call omp_destroy_lock(locks(lock_num))
721!$ END DO
722!$OMP END DO
723
724!$OMP SINGLE
725!$ DEALLOCATE (locks)
726!$OMP END SINGLE NOWAIT
727
728!$OMP END PARALLEL
729
730 CALL neighbor_list_iterator_release(ap_iterator)
731
732 DEALLOCATE (basis_set_list)
733
734 IF (calculate_forces .OR. doat) THEN
735 ! *** If LSD, then recover alpha density and beta density ***
736 ! *** from the total density (1) and the spin density (2) ***
737 IF (SIZE(matrix_p, 1) == 2) THEN
738 DO img = 1, nimages
739 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
740 alpha_scalar=0.5_dp, beta_scalar=0.5_dp)
741 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
742 alpha_scalar=-1.0_dp, beta_scalar=1.0_dp)
743 END DO
744 END IF
745 END IF
746
747 IF (calculate_forces) THEN
748 CALL get_atomic_kind_set(atomic_kind_set, atom_of_kind=atom_of_kind, kind_of=kind_of)
749!$OMP DO
750 DO iatom = 1, natom
751 atom_a = atom_of_kind(iatom)
752 ikind = kind_of(iatom)
753 force(ikind)%gth_ppl(:, atom_a) = force(ikind)%gth_ppl(:, atom_a) + force_thread(:, iatom)
754 END DO
755!$OMP END DO
756 DEALLOCATE (atom_of_kind, kind_of)
757 END IF
758 IF (doat) THEN
759 atcore(1:natom) = atcore(1:natom) + at_thread(1:natom)
760 END IF
761
762 IF (calculate_forces .AND. use_virial) THEN
763 virial%pv_ppl = virial%pv_ppl + pv_thread
764 virial%pv_virial = virial%pv_virial + pv_thread
765 END IF
766
767 CALL timestop(handle)
768
769 END SUBROUTINE build_core_ppl
770
771! **************************************************************************************************
772!> \brief ...
773!> \param lri_ppl_coef ...
774!> \param force ...
775!> \param virial ...
776!> \param calculate_forces ...
777!> \param use_virial ...
778!> \param qs_kind_set ...
779!> \param atomic_kind_set ...
780!> \param particle_set ...
781!> \param sac_ppl ...
782!> \param basis_type ...
783! **************************************************************************************************
784 SUBROUTINE build_core_ppl_ri(lri_ppl_coef, force, virial, calculate_forces, use_virial, &
785 qs_kind_set, atomic_kind_set, particle_set, sac_ppl, &
786 basis_type)
787
788 TYPE(lri_kind_type), DIMENSION(:), POINTER :: lri_ppl_coef
789 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
790 TYPE(virial_type), POINTER :: virial
791 LOGICAL, INTENT(IN) :: calculate_forces
792 LOGICAL :: use_virial
793 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
794 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
795 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
796 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
797 POINTER :: sac_ppl
798 CHARACTER(LEN=*), INTENT(IN) :: basis_type
799
800 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_core_ppl_ri'
801 INTEGER, PARAMETER :: nexp_max = 30
802
803 INTEGER :: atom_a, handle, i, iatom, ikind, iset, katom, kkind, maxco, maxsgf, n_local, &
804 natom, ncoa, nexp_lpot, nexp_ppl, nfun, nkind, nloc, nseta, sgfa, sgfb, slot
805 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of
806 INTEGER, DIMENSION(1:10) :: nrloc
807 INTEGER, DIMENSION(:), POINTER :: la_max, la_min, nct_lpot, npgfa, nsgfa
808 INTEGER, DIMENSION(:, :), POINTER :: first_sgfa
809 INTEGER, DIMENSION(nexp_max) :: nct_ppl
810 LOGICAL :: ecp_local, ecp_semi_local, lpotextended
811 REAL(kind=dp) :: alpha, dac, ppl_radius
812 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: va, work
813 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: dva, dvas
814 REAL(kind=dp), DIMENSION(1:10) :: aloc, bloc
815 REAL(kind=dp), DIMENSION(3) :: force_a, rac
816 REAL(kind=dp), DIMENSION(3, 3) :: pv_thread
817 TYPE(gto_basis_set_type), POINTER :: basis_set
818 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
819 TYPE(gth_potential_type), POINTER :: gth_potential
820 REAL(kind=dp), DIMENSION(nexp_max) :: alpha_ppl
821 REAL(kind=dp), DIMENSION(:, :), POINTER :: bcon, cval_lpot, rpgfa, sphi_a, zeta
822 REAL(kind=dp), DIMENSION(:), POINTER :: a_local, alpha_lpot, c_local, cexp_ppl, &
823 set_radius_a
824 REAL(kind=dp), DIMENSION(4, nexp_max) :: cval_ppl
825 REAL(kind=dp), DIMENSION(3, SIZE(particle_set)) :: force_thread
826 TYPE(sgp_potential_type), POINTER :: sgp_potential
827
828!$ INTEGER(kind=omp_lock_kind), &
829!$ ALLOCATABLE, DIMENSION(:) :: locks
830!$ INTEGER :: lock_num, hash
831!$ INTEGER, PARAMETER :: nlock = 501
832
833 IF (calculate_forces) THEN
834 CALL timeset(routinen//"_forces", handle)
835 ELSE
836 CALL timeset(routinen, handle)
837 END IF
838
839 nkind = SIZE(atomic_kind_set)
840 natom = SIZE(particle_set)
841
842 force_thread = 0.0_dp
843 pv_thread = 0.0_dp
844 CALL get_atomic_kind_set(atomic_kind_set, atom_of_kind=atom_of_kind, kind_of=kind_of)
845
846 ALLOCATE (basis_set_list(nkind))
847 DO ikind = 1, nkind
848 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set, basis_type=basis_type)
849 IF (ASSOCIATED(basis_set)) THEN
850 basis_set_list(ikind)%gto_basis_set => basis_set
851 ELSE
852 NULLIFY (basis_set_list(ikind)%gto_basis_set)
853 END IF
854 END DO
855
856 CALL get_qs_kind_set(qs_kind_set, maxco=maxco, maxsgf=maxsgf, basis_type=basis_type)
857
858!$OMP PARALLEL &
859!$OMP DEFAULT (NONE) &
860!$OMP SHARED (maxco,maxsgf,basis_set_list,calculate_forces,lri_ppl_coef,qs_kind_set,&
861!$OMP locks,natom,use_virial,virial,ncoset,atom_of_kind,sac_ppl) &
862!$OMP PRIVATE (ikind,kkind,iatom,katom,atom_a,rac,va,dva,dvas,basis_set,slot,&
863!$OMP first_sgfa,la_max,la_min,npgfa,nseta,nsgfa,rpgfa,set_radius_a,lock_num,&
864!$OMP sphi_a,zeta,gth_potential,sgp_potential,alpha,cexp_ppl,lpotextended,ppl_radius,&
865!$OMP nexp_ppl,alpha_ppl,nct_ppl,cval_ppl,nloc,n_local,nrloc,a_local,aloc,bloc,c_local,nfun,work,&
866!$OMP hash,dac,force_a,iset,sgfa,sgfb,ncoa,bcon,cval_lpot,nct_lpot,alpha_lpot,nexp_lpot,&
867!$OMP ecp_local,ecp_semi_local) &
868!$OMP REDUCTION (+ : pv_thread, force_thread )
869
870!$OMP SINGLE
871!$ ALLOCATE (locks(nlock))
872!$OMP END SINGLE
873
874!$OMP DO
875!$ DO lock_num = 1, nlock
876!$ call omp_init_lock(locks(lock_num))
877!$ END DO
878!$OMP END DO
879
880 ALLOCATE (va(maxco), work(maxsgf))
881 IF (calculate_forces) THEN
882 ALLOCATE (dva(maxco, 3), dvas(maxco, 3))
883 END IF
884
885!$OMP DO SCHEDULE(GUIDED)
886 DO slot = 1, sac_ppl(1)%nl_size
887
888 ikind = sac_ppl(1)%nlist_task(slot)%ikind
889 kkind = sac_ppl(1)%nlist_task(slot)%jkind
890 iatom = sac_ppl(1)%nlist_task(slot)%iatom
891 katom = sac_ppl(1)%nlist_task(slot)%jatom
892 rac(1:3) = sac_ppl(1)%nlist_task(slot)%r(1:3)
893 atom_a = atom_of_kind(iatom)
894
895 basis_set => basis_set_list(ikind)%gto_basis_set
896 IF (.NOT. ASSOCIATED(basis_set)) cycle
897
898 ! basis ikind
899 first_sgfa => basis_set%first_sgf
900 la_max => basis_set%lmax
901 la_min => basis_set%lmin
902 npgfa => basis_set%npgf
903 nseta = basis_set%nset
904 nsgfa => basis_set%nsgf_set
905 nfun = basis_set%nsgf
906 rpgfa => basis_set%pgf_radius
907 set_radius_a => basis_set%set_radius
908 sphi_a => basis_set%sphi
909 zeta => basis_set%zet
910
911 CALL get_qs_kind(qs_kind_set(kkind), gth_potential=gth_potential, &
912 sgp_potential=sgp_potential)
913 ecp_semi_local = .false.
914 IF (ASSOCIATED(gth_potential)) THEN
915 CALL get_potential(potential=gth_potential, &
916 alpha_ppl=alpha, cexp_ppl=cexp_ppl, &
917 lpot_present=lpotextended, ppl_radius=ppl_radius)
918 nexp_ppl = 1
919 alpha_ppl(1) = alpha
920 nct_ppl(1) = SIZE(cexp_ppl)
921 cval_ppl(1:nct_ppl(1), 1) = cexp_ppl(1:nct_ppl(1))
922 IF (lpotextended) THEN
923 CALL get_potential(potential=gth_potential, &
924 nexp_lpot=nexp_lpot, alpha_lpot=alpha_lpot, nct_lpot=nct_lpot, cval_lpot=cval_lpot)
925 cpassert(nexp_lpot < nexp_max)
926 nexp_ppl = nexp_lpot + 1
927 alpha_ppl(2:nexp_lpot + 1) = alpha_lpot(1:nexp_lpot)
928 nct_ppl(2:nexp_lpot + 1) = nct_lpot(1:nexp_lpot)
929 DO i = 1, nexp_lpot
930 cval_ppl(1:nct_lpot(i), i + 1) = cval_lpot(1:nct_lpot(i), i)
931 END DO
932 END IF
933 ELSE IF (ASSOCIATED(sgp_potential)) THEN
934 CALL get_potential(potential=sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local, &
935 ppl_radius=ppl_radius)
936 cpassert(.NOT. ecp_semi_local)
937 IF (ecp_local) THEN
938 CALL get_potential(potential=sgp_potential, nloc=nloc, nrloc=nrloc, aloc=aloc, bloc=bloc)
939 IF (sum(abs(aloc(1:nloc))) < 1.0e-12_dp) cycle
940 nexp_ppl = nloc
941 cpassert(nexp_ppl <= nexp_max)
942 nct_ppl(1:nloc) = nrloc(1:nloc)
943 alpha_ppl(1:nloc) = bloc(1:nloc)
944 cval_ppl(1, 1:nloc) = aloc(1:nloc)
945 ELSE
946 CALL get_potential(potential=sgp_potential, n_local=n_local, a_local=a_local, c_local=c_local)
947 nexp_ppl = n_local
948 cpassert(nexp_ppl <= nexp_max)
949 nct_ppl(1:n_local) = 1
950 alpha_ppl(1:n_local) = a_local(1:n_local)
951 cval_ppl(1, 1:n_local) = c_local(1:n_local)
952 END IF
953 ELSE
954 cycle
955 END IF
956
957 dac = sqrt(sum(rac*rac))
958 IF ((maxval(set_radius_a(:)) + ppl_radius < dac)) cycle
959 IF (calculate_forces) force_a = 0.0_dp
960 work(1:nfun) = 0.0_dp
961
962 DO iset = 1, nseta
963 IF (set_radius_a(iset) + ppl_radius < dac) cycle
964 ! integrals
965 IF (calculate_forces) THEN
966 va = 0.0_dp
967 dva = 0.0_dp
968 CALL ppl_integral_ri( &
969 la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
970 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
971 -rac, dac, va, dva)
972 ELSE
973 va = 0.0_dp
974 CALL ppl_integral_ri( &
975 la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
976 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
977 -rac, dac, va)
978 END IF
979 ! contraction
980 sgfa = first_sgfa(1, iset)
981 sgfb = sgfa + nsgfa(iset) - 1
982 ncoa = npgfa(iset)*ncoset(la_max(iset))
983 bcon => sphi_a(1:ncoa, sgfa:sgfb)
984 work(sgfa:sgfb) = matmul(transpose(bcon), va(1:ncoa))
985 IF (calculate_forces) THEN
986 dvas(1:nsgfa(iset), 1:3) = matmul(transpose(bcon), dva(1:ncoa, 1:3))
987 force_a(1) = force_a(1) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 1))
988 force_a(2) = force_a(2) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 2))
989 force_a(3) = force_a(3) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 3))
990 END IF
991 END DO
992!$ hash = MOD(iatom, nlock) + 1
993!$ CALL omp_set_lock(locks(hash))
994 lri_ppl_coef(ikind)%v_int(atom_a, 1:nfun) = lri_ppl_coef(ikind)%v_int(atom_a, 1:nfun) + work(1:nfun)
995!$ CALL omp_unset_lock(locks(hash))
996 IF (calculate_forces) THEN
997 force_thread(1, iatom) = force_thread(1, iatom) + force_a(1)
998 force_thread(2, iatom) = force_thread(2, iatom) + force_a(2)
999 force_thread(3, iatom) = force_thread(3, iatom) + force_a(3)
1000 force_thread(1, katom) = force_thread(1, katom) - force_a(1)
1001 force_thread(2, katom) = force_thread(2, katom) - force_a(2)
1002 force_thread(3, katom) = force_thread(3, katom) - force_a(3)
1003 IF (use_virial) THEN
1004 CALL virial_pair_force(pv_thread, 1.0_dp, force_a, rac)
1005 END IF
1006 END IF
1007 END DO
1008
1009 DEALLOCATE (va, work)
1010 IF (calculate_forces) THEN
1011 DEALLOCATE (dva, dvas)
1012 END IF
1013
1014!$OMP END PARALLEL
1015
1016 IF (calculate_forces) THEN
1017 DO iatom = 1, natom
1018 atom_a = atom_of_kind(iatom)
1019 ikind = kind_of(iatom)
1020 force(ikind)%gth_ppl(1, atom_a) = force(ikind)%gth_ppl(1, atom_a) + force_thread(1, iatom)
1021 force(ikind)%gth_ppl(2, atom_a) = force(ikind)%gth_ppl(2, atom_a) + force_thread(2, iatom)
1022 force(ikind)%gth_ppl(3, atom_a) = force(ikind)%gth_ppl(3, atom_a) + force_thread(3, iatom)
1023 END DO
1024 END IF
1025 DEALLOCATE (atom_of_kind, kind_of)
1026
1027 IF (calculate_forces .AND. use_virial) THEN
1028 virial%pv_ppl = virial%pv_ppl + pv_thread
1029 virial%pv_virial = virial%pv_virial + pv_thread
1030 END IF
1031
1032 DEALLOCATE (basis_set_list)
1033
1034 CALL timestop(handle)
1035
1036 END SUBROUTINE build_core_ppl_ri
1037
1038! **************************************************************************************************
1039
1040END MODULE core_ppl
Calculation of three-center overlap integrals over Cartesian Gaussian-type functions for the second t...
subroutine, public ppl_integral(la_max_set, la_min_set, npgfa, rpgfa, zeta, lb_max_set, lb_min_set, npgfb, rpgfb, zetb, nexp_ppl, alpha_ppl, nct_ppl, cexp_ppl, rpgfc, rab, dab, rac, dac, rbc, dbc, vab, s, pab, force_a, force_b, fs, hab2, hab2_work, deltar, iatom, jatom, katom)
Calculation of three-center overlap integrals <a|c|b> over Cartesian Gaussian functions for the local...
subroutine, public ecploc_integral(la_max_set, la_min_set, npgfa, rpgfa, zeta, lb_max_set, lb_min_set, npgfb, rpgfb, zetb, nexp_ppl, alpha_ppl, nct_ppl, cexp_ppl, rpgfc, rab, dab, rac, dac, rbc, dbc, vab, s, pab, force_a, force_b, fs, hab2, hab2_work, deltar, iatom, jatom, katom)
Calculation of three-center potential integrals <a|V(r)|b> over Cartesian Gaussian functions for the ...
subroutine, public ppl_integral_ri(la_max_set, la_min_set, npgfa, rpgfa, zeta, nexp_ppl, alpha_ppl, nct_ppl, cexp_ppl, rpgfc, rac, dac, va, dva)
Calculation of two-center overlap integrals <a|c> over Cartesian Gaussian functions for the local par...
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
Calculation of the local pseudopotential contribution to the core Hamiltonian <a|V(local)|b> = <a|Sum...
Definition core_ppl.F:18
subroutine, public build_core_ppl_ri(lri_ppl_coef, force, virial, calculate_forces, use_virial, qs_kind_set, atomic_kind_set, particle_set, sac_ppl, basis_type)
...
Definition core_ppl.F:787
subroutine, public build_core_ppl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, nimages, cell_to_index, basis_type, deltar, atcore)
...
Definition core_ppl.F:97
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
Definition of the atomic potential types.
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public int_8
Definition kinds.F:54
integer, parameter, public dp
Definition kinds.F:34
Local and semi-local ECP integrals using the libgrpp library.
subroutine, public libgrpp_semilocal_integrals(la_max_set, la_min_set, npgfa, rpgfa, zeta, lb_max_set, lb_min_set, npgfb, rpgfb, zetb, lmax_ecp, npot_ecp, alpha_ecp, coeffs_ecp, nrpot_ecp, rpgfc, rab, dab, rac, dac, dbc, vab, pab, force_a, force_b)
Semi-local ECP integrals using libgrpp.
subroutine, public libgrpp_local_integrals(la_max_set, la_min_set, npgfa, rpgfa, zeta, lb_max_set, lb_min_set, npgfb, rpgfb, zetb, npot_ecp, alpha_ecp, coeffs_ecp, nrpot_ecp, rpgfc, rab, dab, rac, dac, dbc, vab, pab, force_a, force_b)
Local ECP integrals using libgrpp.
subroutine, public libgrpp_local_forces_ref(la_max_set, la_min_set, npgfa, rpgfa, zeta, lb_max_set, lb_min_set, npgfb, rpgfb, zetb, npot_ecp, alpha_ecp, coeffs_ecp, nrpot_ecp, rpgfc, rab, dab, rac, dac, dbc, vab, pab, force_a, force_b)
Reference local ECP force routine using l+-1 integrals. No call is made to the numerically unstable g...
subroutine, public libgrpp_semilocal_forces_ref(la_max_set, la_min_set, npgfa, rpgfa, zeta, lb_max_set, lb_min_set, npgfb, rpgfb, zetb, lmax_ecp, npot_ecp, alpha_ecp, coeffs_ecp, nrpot_ecp, rpgfc, rab, dab, rac, dac, dbc, vab, pab, force_a, force_b)
Reference semi-local ECP forces using l+-1 integrals. No call is made to the numerically unstable gra...
contains the types and subroutines for dealing with the lri_env lri : local resolution of the identit...
Provides Cartesian and spherical orbital pointers and indices.
subroutine, public init_orbital_pointers(maxl)
Initialize or update the orbital pointers.
integer, dimension(:), allocatable, public ncoset
Define the data structure for the particle information.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, basis_type, total_zeff_corr, npgf_seg)
Get attributes of an atomic kind set.
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public nl_set_sub_iterator(iterator_set, ikind, jkind, iatom, mepos)
...
subroutine, public neighbor_list_iterator_release(iterator_set)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
pure subroutine, public virial_pair_force(pv_virial, f0, force, rab)
Computes the contribution to the stress tensor from two-body pair-wise forces.
Provides all information about an atomic kind.
Provides all information about a quickstep kind.