(git:ed6f26b)
Loading...
Searching...
No Matches
core_ppnl.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 non-local pseudopotential contribution to the core Hamiltonian
9!> <a|V(non-local)|b> = <a|p(l,i)>*h(i,j)*<p(l,j)|b>
10!> \par History
11!> - refactered from qs_core_hamiltian [Joost VandeVondele, 2008-11-01]
12!> - full rewrite [jhu, 2009-01-23]
13!> - Extended by the derivatives for DFPT [Sandra Luber, Edward Ditler, 2021]
14! **************************************************************************************************
16 USE ai_angmom, ONLY: angmom
17 USE ai_overlap, ONLY: overlap
22 USE cp_dbcsr_api, ONLY: dbcsr_add,&
29 USE kinds, ONLY: dp,&
30 int_8
32 nco,&
33 ncoset
36 USE qs_kind_types, ONLY: get_qs_kind,&
40 USE sap_kind_types, ONLY: alist_type,&
42 get_alist,&
47 USE virial_types, ONLY: virial_type
48
49!$ USE OMP_LIB, ONLY: omp_lock_kind, &
50!$ omp_init_lock, omp_set_lock, &
51!$ omp_unset_lock, omp_destroy_lock
52
53#include "./base/base_uses.f90"
54
55 IMPLICIT NONE
56
57 PRIVATE
58
59 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'core_ppnl'
60
61 PUBLIC :: build_core_ppnl
62
63CONTAINS
64
65! **************************************************************************************************
66!> \brief ...
67!> \param matrix_h ...
68!> \param matrix_p ...
69!> \param force ...
70!> \param virial ...
71!> \param calculate_forces ...
72!> \param use_virial ...
73!> \param nder ...
74!> \param qs_kind_set ...
75!> \param atomic_kind_set ...
76!> \param particle_set ...
77!> \param sab_orb ...
78!> \param sap_ppnl ...
79!> \param eps_ppnl ...
80!> \param nimages ...
81!> \param cell_to_index ...
82!> \param basis_type ...
83!> \param deltaR Weighting factors of the derivatives wrt. nuclear positions
84!> \param matrix_l ...
85!> \param atcore ...
86! **************************************************************************************************
87 SUBROUTINE build_core_ppnl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, &
88 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sap_ppnl, eps_ppnl, &
89 nimages, cell_to_index, basis_type, deltaR, matrix_l, atcore)
90
91 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrix_p
92 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
93 TYPE(virial_type), POINTER :: virial
94 LOGICAL, INTENT(IN) :: calculate_forces
95 LOGICAL :: use_virial
96 INTEGER :: nder
97 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
98 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
99 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
100 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
101 POINTER :: sab_orb, sap_ppnl
102 REAL(kind=dp), INTENT(IN) :: eps_ppnl
103 INTEGER, INTENT(IN) :: nimages
104 INTEGER, DIMENSION(:, :, :), OPTIONAL, POINTER :: cell_to_index
105 CHARACTER(LEN=*), INTENT(IN) :: basis_type
106 REAL(kind=dp), DIMENSION(:, :), INTENT(IN), &
107 OPTIONAL :: deltar
108 TYPE(dbcsr_p_type), DIMENSION(:, :), OPTIONAL, &
109 POINTER :: matrix_l
110 REAL(kind=dp), DIMENSION(:), INTENT(INOUT), &
111 OPTIONAL :: atcore
112
113 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_core_ppnl'
114
115 INTEGER :: atom_a, first_col, handle, i, i_dim, iab, iac, iatom, ib, ibc, icol, ikind, &
116 ilist, img, irow, iset, j, jatom, jb, jkind, jneighbor, kac, katom, kbc, kkind, l, &
117 lc_max, lc_min, ldai, ldsab, lppnl, maxco, maxder, maxl, maxlgto, maxlppnl, maxppnl, &
118 maxsgf, na, natom, nb, ncoa, ncoc, nkind, nlist, nneighbor, nnl, np, nppnl, nprjc, nseta, &
119 nsgfa, prjc, sgfa, slot
120 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of
121 INTEGER, DIMENSION(3) :: cell_b, cell_c
122 INTEGER, DIMENSION(:), POINTER :: la_max, la_min, npgfa, nprj_ppnl, &
123 nsgf_seta
124 INTEGER, DIMENSION(:, :), POINTER :: first_sgfa
125 LOGICAL :: do_dr, do_gth, do_kp, do_soc, doat, &
126 found, ppnl_present
127 REAL(kind=dp) :: atk, dac, f0, ppnl_radius
128 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: radp
129 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: sab, work
130 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: ai_work, lab, work_l
131 REAL(kind=dp), DIMENSION(1) :: rprjc, zetc
132 REAL(kind=dp), DIMENSION(3) :: fa, fb, rab, rac, rbc
133 REAL(kind=dp), DIMENSION(3, 3) :: pv_thread
134 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
135 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set
136 TYPE(gth_potential_type), POINTER :: gth_potential
137 TYPE(gth_potential_p_type), DIMENSION(:), POINTER :: gpotential
138 TYPE(clist_type), POINTER :: clist
139 TYPE(alist_type), POINTER :: alist_ac, alist_bc
140 REAL(kind=dp), DIMENSION(SIZE(particle_set)) :: at_thread
141 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: achint, acint, alkint, bchint, bcint, &
142 blkint
143 REAL(kind=dp), DIMENSION(:, :), POINTER :: cprj, h_block, l_block_x, l_block_y, &
144 l_block_z, p_block, r_2block, &
145 r_3block, rpgfa, sphi_a, vprj_ppnl, &
146 wprj_ppnl, zeta
147 REAL(kind=dp), DIMENSION(:), POINTER :: a_nl, alpha_ppnl, hprj, set_radius_a
148 REAL(kind=dp), DIMENSION(3, SIZE(particle_set)) :: force_thread
149 TYPE(sap_int_type), DIMENSION(:), POINTER :: sap_int
150 TYPE(sgp_potential_p_type), DIMENSION(:), POINTER :: spotential
151 TYPE(sgp_potential_type), POINTER :: sgp_potential
152
153!$ INTEGER(kind=omp_lock_kind), &
154!$ ALLOCATABLE, DIMENSION(:) :: locks
155!$ INTEGER(KIND=int_8) :: iatom8
156!$ INTEGER :: lock_num, hash
157!$ INTEGER, PARAMETER :: nlock = 501
158
159 mark_used(int_8)
160
161 do_dr = .false.
162 IF (PRESENT(deltar)) do_dr = .true.
163 doat = .false.
164 IF (PRESENT(atcore)) doat = .true.
165
166 IF (calculate_forces) THEN
167 CALL timeset(routinen//"_forces", handle)
168 ELSE
169 CALL timeset(routinen, handle)
170 END IF
171
172 do_soc = PRESENT(matrix_l)
173
174 ppnl_present = ASSOCIATED(sap_ppnl)
175
176 IF (ppnl_present) THEN
177
178 nkind = SIZE(atomic_kind_set)
179 natom = SIZE(particle_set)
180
181 do_kp = (nimages > 1)
182
183 IF (do_kp) THEN
184 cpassert(PRESENT(cell_to_index) .AND. ASSOCIATED(cell_to_index))
185 END IF
186
187 IF (calculate_forces .OR. doat) THEN
188 IF (SIZE(matrix_p, 1) == 2) THEN
189 DO img = 1, nimages
190 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
191 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
192 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
193 alpha_scalar=-2.0_dp, beta_scalar=1.0_dp)
194 END DO
195 END IF
196 END IF
197
198 maxder = ncoset(nder)
199
200 CALL get_qs_kind_set(qs_kind_set, &
201 maxco=maxco, &
202 maxlgto=maxlgto, &
203 maxsgf=maxsgf, &
204 maxlppnl=maxlppnl, &
205 maxppnl=maxppnl, &
206 basis_type=basis_type)
207
208 maxl = max(maxlgto, maxlppnl)
209 CALL init_orbital_pointers(maxl + nder + 1)
210
211 ldsab = max(maxco, ncoset(maxlppnl), maxsgf, maxppnl)
212 ldai = ncoset(maxl + nder + 1)
213
214 ! sap_int needs to be shared as multiple threads need to access this
215 ALLOCATE (sap_int(nkind*nkind))
216 DO i = 1, nkind*nkind
217 NULLIFY (sap_int(i)%alist, sap_int(i)%asort, sap_int(i)%aindex)
218 sap_int(i)%nalist = 0
219 END DO
220
221 ! Set up direct access to basis and potential
222 ALLOCATE (basis_set(nkind), gpotential(nkind), spotential(nkind))
223 DO ikind = 1, nkind
224 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, basis_type=basis_type)
225 IF (ASSOCIATED(orb_basis_set)) THEN
226 basis_set(ikind)%gto_basis_set => orb_basis_set
227 ELSE
228 NULLIFY (basis_set(ikind)%gto_basis_set)
229 END IF
230 CALL get_qs_kind(qs_kind_set(ikind), gth_potential=gth_potential, sgp_potential=sgp_potential)
231 NULLIFY (gpotential(ikind)%gth_potential)
232 NULLIFY (spotential(ikind)%sgp_potential)
233 IF (ASSOCIATED(gth_potential)) THEN
234 gpotential(ikind)%gth_potential => gth_potential
235 IF (do_soc .AND. (.NOT. gth_potential%soc)) THEN
236 cpabort("Spin-orbit coupling selected, but GTH potential without SOC parameters provided")
237 END IF
238 ELSE IF (ASSOCIATED(sgp_potential)) THEN
239 spotential(ikind)%sgp_potential => sgp_potential
240 END IF
241 END DO
242
243 ! Allocate sap int
244 DO slot = 1, sap_ppnl(1)%nl_size
245
246 ikind = sap_ppnl(1)%nlist_task(slot)%ikind
247 kkind = sap_ppnl(1)%nlist_task(slot)%jkind
248 iatom = sap_ppnl(1)%nlist_task(slot)%iatom
249 katom = sap_ppnl(1)%nlist_task(slot)%jatom
250 nlist = sap_ppnl(1)%nlist_task(slot)%nlist
251 ilist = sap_ppnl(1)%nlist_task(slot)%ilist
252 nneighbor = sap_ppnl(1)%nlist_task(slot)%nnode
253
254 iac = ikind + nkind*(kkind - 1)
255 IF (.NOT. ASSOCIATED(basis_set(ikind)%gto_basis_set)) cycle
256 IF (.NOT. ASSOCIATED(gpotential(kkind)%gth_potential) .AND. &
257 .NOT. ASSOCIATED(spotential(kkind)%sgp_potential)) cycle
258 IF (.NOT. ASSOCIATED(sap_int(iac)%alist)) THEN
259 sap_int(iac)%a_kind = ikind
260 sap_int(iac)%p_kind = kkind
261 sap_int(iac)%nalist = nlist
262 ALLOCATE (sap_int(iac)%alist(nlist))
263 DO i = 1, nlist
264 NULLIFY (sap_int(iac)%alist(i)%clist)
265 sap_int(iac)%alist(i)%aatom = 0
266 sap_int(iac)%alist(i)%nclist = 0
267 END DO
268 END IF
269 IF (.NOT. ASSOCIATED(sap_int(iac)%alist(ilist)%clist)) THEN
270 sap_int(iac)%alist(ilist)%aatom = iatom
271 sap_int(iac)%alist(ilist)%nclist = nneighbor
272 ALLOCATE (sap_int(iac)%alist(ilist)%clist(nneighbor))
273 DO i = 1, nneighbor
274 sap_int(iac)%alist(ilist)%clist(i)%catom = 0
275 END DO
276 END IF
277 END DO
278
279 ! Calculate the overlap integrals <a|p>
280!$OMP PARALLEL &
281!$OMP DEFAULT (NONE) &
282!$OMP SHARED (basis_set, gpotential, spotential, maxder, ncoset, &
283!$OMP sap_ppnl, sap_int, nkind, ldsab, ldai, nder, nco, do_soc ) &
284!$OMP PRIVATE (ikind, kkind, iatom, katom, nlist, ilist, nneighbor, jneighbor, &
285!$OMP cell_c, rac, iac, first_sgfa, la_max, la_min, npgfa, nseta, nsgfa, nsgf_seta, &
286!$OMP slot, sphi_a, zeta, cprj, hprj, lppnl, nppnl, nprj_ppnl, &
287!$OMP clist, iset, ncoa, sgfa, prjc, work, work_l, sab, lab, ai_work, nprjc, &
288!$OMP ppnl_radius, ncoc, rpgfa, first_col, vprj_ppnl, wprj_ppnl, i, j, l, do_gth, &
289!$OMP set_radius_a, rprjc, dac, lc_max, lc_min, zetc, alpha_ppnl, &
290!$OMP na, nb, np, nnl, a_nl, radp, i_dim, ib, jb)
291
292 ALLOCATE (sab(ldsab, ldsab*maxder), work(ldsab, ldsab*maxder))
293 sab = 0.0_dp
294 ALLOCATE (ai_work(ldai, ldai, ncoset(nder + 1)))
295 ai_work = 0.0_dp
296 IF (do_soc) THEN
297 ALLOCATE (lab(ldsab, ldsab, 3), work_l(ldsab, ldsab, 3))
298 lab = 0.0_dp
299 END IF
300
301!$OMP DO SCHEDULE(GUIDED)
302 DO slot = 1, sap_ppnl(1)%nl_size
303
304 ikind = sap_ppnl(1)%nlist_task(slot)%ikind
305 kkind = sap_ppnl(1)%nlist_task(slot)%jkind
306 iatom = sap_ppnl(1)%nlist_task(slot)%iatom
307 katom = sap_ppnl(1)%nlist_task(slot)%jatom
308 nlist = sap_ppnl(1)%nlist_task(slot)%nlist
309 ilist = sap_ppnl(1)%nlist_task(slot)%ilist
310 nneighbor = sap_ppnl(1)%nlist_task(slot)%nnode
311 jneighbor = sap_ppnl(1)%nlist_task(slot)%inode
312 cell_c(:) = sap_ppnl(1)%nlist_task(slot)%cell(:)
313 rac(1:3) = sap_ppnl(1)%nlist_task(slot)%r(1:3)
314
315 iac = ikind + nkind*(kkind - 1)
316 IF (.NOT. ASSOCIATED(basis_set(ikind)%gto_basis_set)) cycle
317 ! Get definition of basis set
318 first_sgfa => basis_set(ikind)%gto_basis_set%first_sgf
319 la_max => basis_set(ikind)%gto_basis_set%lmax
320 la_min => basis_set(ikind)%gto_basis_set%lmin
321 npgfa => basis_set(ikind)%gto_basis_set%npgf
322 nseta = basis_set(ikind)%gto_basis_set%nset
323 nsgfa = basis_set(ikind)%gto_basis_set%nsgf
324 nsgf_seta => basis_set(ikind)%gto_basis_set%nsgf_set
325 rpgfa => basis_set(ikind)%gto_basis_set%pgf_radius
326 set_radius_a => basis_set(ikind)%gto_basis_set%set_radius
327 sphi_a => basis_set(ikind)%gto_basis_set%sphi
328 zeta => basis_set(ikind)%gto_basis_set%zet
329 ! Get definition of PP projectors
330 IF (ASSOCIATED(gpotential(kkind)%gth_potential)) THEN
331 ! GTH potential
332 do_gth = .true.
333 alpha_ppnl => gpotential(kkind)%gth_potential%alpha_ppnl
334 cprj => gpotential(kkind)%gth_potential%cprj
335 lppnl = gpotential(kkind)%gth_potential%lppnl
336 nppnl = gpotential(kkind)%gth_potential%nppnl
337 nprj_ppnl => gpotential(kkind)%gth_potential%nprj_ppnl
338 ppnl_radius = gpotential(kkind)%gth_potential%ppnl_radius
339 vprj_ppnl => gpotential(kkind)%gth_potential%vprj_ppnl
340 wprj_ppnl => gpotential(kkind)%gth_potential%wprj_ppnl
341 ELSE IF (ASSOCIATED(spotential(kkind)%sgp_potential)) THEN
342 ! SGP potential
343 do_gth = .false.
344 nprjc = spotential(kkind)%sgp_potential%nppnl
345 IF (nprjc == 0) cycle
346 nnl = spotential(kkind)%sgp_potential%n_nonlocal
347 lppnl = spotential(kkind)%sgp_potential%lmax
348 a_nl => spotential(kkind)%sgp_potential%a_nonlocal
349 ppnl_radius = spotential(kkind)%sgp_potential%ppnl_radius
350 ALLOCATE (radp(nnl))
351 radp(:) = ppnl_radius
352 cprj => spotential(kkind)%sgp_potential%cprj_ppnl
353 hprj => spotential(kkind)%sgp_potential%vprj_ppnl
354 nppnl = SIZE(cprj, 2)
355 ELSE
356 cycle
357 END IF
358
359 dac = sqrt(sum(rac*rac))
360 clist => sap_int(iac)%alist(ilist)%clist(jneighbor)
361 clist%catom = katom
362 clist%cell = cell_c
363 clist%rac = rac
364 ALLOCATE (clist%acint(nsgfa, nppnl, maxder), &
365 clist%achint(nsgfa, nppnl, maxder), &
366 clist%alint(nsgfa, nppnl, 3), &
367 clist%alkint(nsgfa, nppnl, 3))
368 clist%acint = 0.0_dp
369 clist%achint = 0.0_dp
370 clist%alint = 0.0_dp
371 clist%alkint = 0.0_dp
372
373 clist%nsgf_cnt = 0
374 NULLIFY (clist%sgf_list)
375 DO iset = 1, nseta
376 ncoa = npgfa(iset)*ncoset(la_max(iset))
377 sgfa = first_sgfa(1, iset)
378 IF (do_gth) THEN
379 ! GTH potential
380 prjc = 1
381 work = 0.0_dp
382 DO l = 0, lppnl
383 nprjc = nprj_ppnl(l)*nco(l)
384 IF (nprjc == 0) cycle
385 rprjc(1) = ppnl_radius
386 IF (set_radius_a(iset) + rprjc(1) < dac) cycle
387 lc_max = l + 2*(nprj_ppnl(l) - 1)
388 lc_min = l
389 zetc(1) = alpha_ppnl(l)
390 ncoc = ncoset(lc_max)
391
392 ! Calculate the primitive overlap integrals
393 CALL overlap(la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
394 lc_max, lc_min, 1, rprjc, zetc, rac, dac, sab, nder, .true., ai_work, ldai)
395 ! Transformation step projector functions (Cartesian -> spherical)
396 na = ncoa
397 nb = nprjc
398 np = ncoc
399 DO i = 1, maxder
400 first_col = (i - 1)*ldsab
401 ! CALL dgemm("N", "N", ncoa, nprjc, ncoc, 1.0_dp, sab(1, first_col + 1), SIZE(sab, 1), &
402 ! cprj(1, prjc), SIZE(cprj, 1), 0.0_dp, work(1, first_col + prjc), ldsab)
403 work(1:na, first_col + prjc:first_col + prjc + nb - 1) = &
404 matmul(sab(1:na, first_col + 1:first_col + np), cprj(1:np, prjc:prjc + nb - 1))
405 END DO
406
407 IF (do_soc) THEN
408 ! Calculate the primitive angular momentum integrals needed for spin-orbit coupling
409 lab = 0.0_dp
410 CALL angmom(la_max(iset), npgfa(iset), zeta(:, iset), rpgfa(:, iset), la_min(iset), &
411 lc_max, 1, zetc, rprjc, -rac, (/0._dp, 0._dp, 0._dp/), lab)
412 DO i_dim = 1, 3
413 work_l(1:na, prjc:prjc + nb - 1, i_dim) = &
414 matmul(lab(1:na, 1:np, i_dim), cprj(1:np, prjc:prjc + nb - 1))
415 END DO
416 END IF
417
418 prjc = prjc + nprjc
419
420 END DO
421 na = nsgf_seta(iset)
422 nb = nppnl
423 np = ncoa
424 DO i = 1, maxder
425 first_col = (i - 1)*ldsab + 1
426 ! Contraction step (basis functions)
427 ! CALL dgemm("T", "N", nsgf_seta(iset), nppnl, ncoa, 1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
428 ! work(1, first_col), ldsab, 0.0_dp, clist%acint(sgfa, 1, i), nsgfa)
429 clist%acint(sgfa:sgfa + na - 1, 1:nb, i) = &
430 matmul(transpose(sphi_a(1:np, sgfa:sgfa + na - 1)), work(1:np, first_col:first_col + nb - 1))
431 ! Multiply with interaction matrix(h)
432 ! CALL dgemm("N", "N", nsgf_seta(iset), nppnl, nppnl, 1.0_dp, clist%acint(sgfa, 1, i), nsgfa, &
433 ! vprj_ppnl(1, 1), SIZE(vprj_ppnl, 1), 0.0_dp, clist%achint(sgfa, 1, i), nsgfa)
434 clist%achint(sgfa:sgfa + na - 1, 1:nb, i) = &
435 matmul(clist%acint(sgfa:sgfa + na - 1, 1:nb, i), vprj_ppnl(1:nb, 1:nb))
436 END DO
437 IF (do_soc) THEN
438 DO i_dim = 1, 3
439 clist%alint(sgfa:sgfa + na - 1, 1:nb, i_dim) = &
440 matmul(transpose(sphi_a(1:np, sgfa:sgfa + na - 1)), work_l(1:np, 1:nb, i_dim))
441 clist%alkint(sgfa:sgfa + na - 1, 1:nb, i_dim) = &
442 matmul(clist%alint(sgfa:sgfa + na - 1, 1:nb, i_dim), wprj_ppnl(1:nb, 1:nb))
443 END DO
444 END IF
445 ELSE
446 ! SGP potential
447 ! Calculate the primitive overlap integrals
448 CALL overlap(la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
449 lppnl, 0, nnl, radp, a_nl, rac, dac, sab, nder, .true., ai_work, ldai)
450 na = nsgf_seta(iset)
451 nb = nppnl
452 np = ncoa
453 DO i = 1, maxder
454 first_col = (i - 1)*ldsab + 1
455 ! Transformation step projector functions (cartesian->spherical)
456 ! CALL dgemm("N", "N", ncoa, nppnl, nprjc, 1.0_dp, sab(1, first_col), ldsab, &
457 ! cprj(1, 1), SIZE(cprj, 1), 0.0_dp, work(1, 1), ldsab)
458 work(1:np, 1:nb) = matmul(sab(1:np, first_col:first_col + nprjc - 1), cprj(1:nprjc, 1:nb))
459 ! Contraction step (basis functions)
460 ! CALL dgemm("T", "N", nsgf_seta(iset), nppnl, ncoa, 1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
461 ! work(1, 1), ldsab, 0.0_dp, clist%acint(sgfa, 1, i), nsgfa)
462 clist%acint(sgfa:sgfa + na - 1, 1:nb, i) = &
463 matmul(transpose(sphi_a(1:np, sgfa:sgfa + na - 1)), work(1:np, 1:nb))
464 ! *** Multiply with interaction matrix(h) ***
465 ncoc = sgfa + nsgf_seta(iset) - 1
466 DO j = 1, nppnl
467 clist%achint(sgfa:ncoc, j, i) = clist%acint(sgfa:ncoc, j, i)*hprj(j)
468 END DO
469 END DO
470 END IF
471 END DO
472 clist%maxac = maxval(abs(clist%acint(:, :, 1)))
473 clist%maxach = maxval(abs(clist%achint(:, :, 1)))
474 IF (.NOT. do_gth) DEALLOCATE (radp)
475 END DO
476
477 DEALLOCATE (sab, ai_work, work)
478 IF (do_soc) DEALLOCATE (lab, work_l)
479!$OMP END PARALLEL
480
481 ! Set up a sorting index
482 CALL sap_sort(sap_int)
483 ! All integrals needed have been calculated and stored in sap_int
484 ! We now calculate the Hamiltonian matrix elements
485
486 force_thread = 0.0_dp
487 at_thread = 0.0_dp
488 pv_thread = 0.0_dp
489
490!$OMP PARALLEL &
491!$OMP DEFAULT (NONE) &
492!$OMP SHARED (do_kp, basis_set, matrix_h, matrix_l, cell_to_index,&
493!$OMP sab_orb, matrix_p, sap_int, nkind, eps_ppnl, force, &
494!$OMP doat, do_dR, deltaR, maxder, nder, &
495!$OMP locks, virial, use_virial, calculate_forces, do_soc, natom) &
496!$OMP PRIVATE (ikind, jkind, iatom, jatom, cell_b, rab, &
497!$OMP slot, iab, atom_a, f0, irow, icol, h_block, &
498!$OMP l_block_x, l_block_y, l_block_z, &
499!$OMP r_2block, r_3block, atk, &
500!$OMP found,p_block, iac, ibc, alist_ac, alist_bc, acint, bcint, &
501!$OMP achint, bchint, alkint, blkint, &
502!$OMP na, np, nb, katom, j, fa, fb, rbc, rac, &
503!$OMP kkind, kac, kbc, i, img, hash, iatom8) &
504!$OMP REDUCTION (+ : at_thread, pv_thread, force_thread )
505
506!$OMP SINGLE
507!$ ALLOCATE (locks(nlock))
508!$OMP END SINGLE
509
510!$OMP DO
511!$ DO lock_num = 1, nlock
512!$ call omp_init_lock(locks(lock_num))
513!$ END DO
514!$OMP END DO
515
516!$OMP DO SCHEDULE(GUIDED)
517 DO slot = 1, sab_orb(1)%nl_size
518
519 ikind = sab_orb(1)%nlist_task(slot)%ikind
520 jkind = sab_orb(1)%nlist_task(slot)%jkind
521 iatom = sab_orb(1)%nlist_task(slot)%iatom
522 jatom = sab_orb(1)%nlist_task(slot)%jatom
523 cell_b(:) = sab_orb(1)%nlist_task(slot)%cell(:)
524 rab(1:3) = sab_orb(1)%nlist_task(slot)%r(1:3)
525
526 IF (.NOT. ASSOCIATED(basis_set(ikind)%gto_basis_set)) cycle
527 IF (.NOT. ASSOCIATED(basis_set(jkind)%gto_basis_set)) cycle
528
529 iab = ikind + nkind*(jkind - 1)
530
531 ! Use the symmetry of the first derivatives
532 IF (iatom == jatom) THEN
533 f0 = 1.0_dp
534 ELSE
535 f0 = 2.0_dp
536 END IF
537
538 IF (do_kp) THEN
539 img = cell_to_index(cell_b(1), cell_b(2), cell_b(3))
540 ELSE
541 img = 1
542 END IF
543
544 ! Create matrix blocks for a new matrix block column
545 IF (iatom <= jatom) THEN
546 irow = iatom
547 icol = jatom
548 ELSE
549 irow = jatom
550 icol = iatom
551 END IF
552 NULLIFY (h_block)
553 CALL dbcsr_get_block_p(matrix_h(1, img)%matrix, irow, icol, h_block, found)
554 IF (do_soc) THEN
555 NULLIFY (l_block_x, l_block_y, l_block_z)
556 CALL dbcsr_get_block_p(matrix_l(1, img)%matrix, irow, icol, l_block_x, found)
557 CALL dbcsr_get_block_p(matrix_l(2, img)%matrix, irow, icol, l_block_y, found)
558 CALL dbcsr_get_block_p(matrix_l(3, img)%matrix, irow, icol, l_block_z, found)
559 END IF
560
561 IF (do_dr) THEN
562 NULLIFY (r_2block, r_3block)
563 CALL dbcsr_get_block_p(matrix_h(2, img)%matrix, irow, icol, r_2block, found)
564 CALL dbcsr_get_block_p(matrix_h(3, img)%matrix, irow, icol, r_3block, found)
565 END IF
566
567 IF (calculate_forces .OR. doat) THEN
568 NULLIFY (p_block)
569 CALL dbcsr_get_block_p(matrix_p(1, img)%matrix, irow, icol, p_block, found)
570 END IF
571
572 ! loop over all kinds for projector atom
573 IF (ASSOCIATED(h_block)) THEN
574!$ iatom8 = INT(iatom - 1, int_8)*INT(natom, int_8) + INT(jatom, int_8)
575!$ hash = INT(MOD(iatom8, INT(nlock, int_8)) + 1)
576
577 DO kkind = 1, nkind
578 iac = ikind + nkind*(kkind - 1)
579 ibc = jkind + nkind*(kkind - 1)
580 IF (.NOT. ASSOCIATED(sap_int(iac)%alist)) cycle
581 IF (.NOT. ASSOCIATED(sap_int(ibc)%alist)) cycle
582 CALL get_alist(sap_int(iac), alist_ac, iatom)
583 CALL get_alist(sap_int(ibc), alist_bc, jatom)
584 IF (.NOT. ASSOCIATED(alist_ac)) cycle
585 IF (.NOT. ASSOCIATED(alist_bc)) cycle
586 DO kac = 1, alist_ac%nclist
587 DO kbc = 1, alist_bc%nclist
588 IF (alist_ac%clist(kac)%catom /= alist_bc%clist(kbc)%catom) cycle
589 IF (all(cell_b + alist_bc%clist(kbc)%cell - alist_ac%clist(kac)%cell == 0)) THEN
590 IF (alist_ac%clist(kac)%maxac*alist_bc%clist(kbc)%maxach < eps_ppnl) cycle
591 acint => alist_ac%clist(kac)%acint
592 bcint => alist_bc%clist(kbc)%acint
593 achint => alist_ac%clist(kac)%achint
594 bchint => alist_bc%clist(kbc)%achint
595 IF (do_soc) THEN
596 alkint => alist_ac%clist(kac)%alkint
597 blkint => alist_bc%clist(kbc)%alkint
598 END IF
599 na = SIZE(acint, 1)
600 np = SIZE(acint, 2)
601 nb = SIZE(bcint, 1)
602!$ CALL omp_set_lock(locks(hash))
603 IF (.NOT. do_dr) THEN
604 IF (iatom <= jatom) THEN
605 h_block(1:na, 1:nb) = h_block(1:na, 1:nb) + &
606 matmul(achint(1:na, 1:np, 1), transpose(bcint(1:nb, 1:np, 1)))
607 ELSE
608 h_block(1:nb, 1:na) = h_block(1:nb, 1:na) + &
609 matmul(bchint(1:nb, 1:np, 1), transpose(acint(1:na, 1:np, 1)))
610 END IF
611 END IF
612 IF (do_soc) THEN
613 IF (iatom <= jatom) THEN
614 l_block_x(1:na, 1:nb) = l_block_x(1:na, 1:nb) + &
615 matmul(alkint(1:na, 1:np, 1), transpose(bcint(1:nb, 1:np, 1)))
616 l_block_y(1:na, 1:nb) = l_block_y(1:na, 1:nb) + &
617 matmul(alkint(1:na, 1:np, 2), transpose(bcint(1:nb, 1:np, 1)))
618 l_block_z(1:na, 1:nb) = l_block_z(1:na, 1:nb) + &
619 matmul(alkint(1:na, 1:np, 3), transpose(bcint(1:nb, 1:np, 1)))
620
621 ELSE
622 l_block_x(1:nb, 1:na) = l_block_x(1:nb, 1:na) - &
623 matmul(blkint(1:nb, 1:np, 1), transpose(acint(1:na, 1:np, 1)))
624 l_block_y(1:nb, 1:na) = l_block_y(1:nb, 1:na) - &
625 matmul(blkint(1:nb, 1:np, 2), transpose(acint(1:na, 1:np, 1)))
626 l_block_z(1:nb, 1:na) = l_block_z(1:nb, 1:na) - &
627 matmul(blkint(1:nb, 1:np, 3), transpose(acint(1:na, 1:np, 1)))
628 END IF
629 END IF
630!$ CALL omp_unset_lock(locks(hash))
631 IF (calculate_forces) THEN
632 IF (ASSOCIATED(p_block)) THEN
633 katom = alist_ac%clist(kac)%catom
634 DO i = 1, 3
635 j = i + 1
636 IF (iatom <= jatom) THEN
637 fa(i) = sum(p_block(1:na, 1:nb)* &
638 matmul(acint(1:na, 1:np, j), transpose(bchint(1:nb, 1:np, 1))))
639 fb(i) = sum(p_block(1:na, 1:nb)* &
640 matmul(achint(1:na, 1:np, 1), transpose(bcint(1:nb, 1:np, j))))
641 ELSE
642 fa(i) = sum(p_block(1:nb, 1:na)* &
643 matmul(bchint(1:nb, 1:np, 1), transpose(acint(1:na, 1:np, j))))
644 fb(i) = sum(p_block(1:nb, 1:na)* &
645 matmul(bcint(1:nb, 1:np, j), transpose(achint(1:na, 1:np, 1))))
646 END IF
647 force_thread(i, iatom) = force_thread(i, iatom) + f0*fa(i)
648 force_thread(i, katom) = force_thread(i, katom) - f0*fa(i)
649 force_thread(i, jatom) = force_thread(i, jatom) + f0*fb(i)
650 force_thread(i, katom) = force_thread(i, katom) - f0*fb(i)
651 END DO
652
653 IF (use_virial) THEN
654 rac = alist_ac%clist(kac)%rac
655 rbc = alist_bc%clist(kbc)%rac
656 CALL virial_pair_force(pv_thread, f0, fa, rac)
657 CALL virial_pair_force(pv_thread, f0, fb, rbc)
658 END IF
659 END IF
660 END IF
661
662 IF (do_dr) THEN
663 i = 1; j = 2;
664 katom = alist_ac%clist(kac)%catom
665 IF (iatom <= jatom) THEN
666 h_block(1:na, 1:nb) = h_block(1:na, 1:nb) + &
667 (deltar(i, iatom) - deltar(i, katom))* &
668 matmul(acint(1:na, 1:np, j), transpose(bchint(1:nb, 1:np, 1)))
669
670 h_block(1:na, 1:nb) = h_block(1:na, 1:nb) + &
671 (deltar(i, jatom) - deltar(i, katom))* &
672 matmul(achint(1:na, 1:np, 1), transpose(bcint(1:nb, 1:np, j)))
673 ELSE
674 h_block(1:nb, 1:na) = h_block(1:nb, 1:na) + &
675 (deltar(i, iatom) - deltar(i, katom))* &
676 matmul(bchint(1:nb, 1:np, 1), transpose(acint(1:na, 1:np, j)))
677 h_block(1:nb, 1:na) = h_block(1:nb, 1:na) + &
678 (deltar(i, jatom) - deltar(i, katom))* &
679 matmul(bcint(1:nb, 1:np, j), transpose(achint(1:na, 1:np, 1)))
680 END IF
681
682 i = 2; j = 3;
683 katom = alist_ac%clist(kac)%catom
684 IF (iatom <= jatom) THEN
685 r_2block(1:na, 1:nb) = r_2block(1:na, 1:nb) + &
686 (deltar(i, iatom) - deltar(i, katom))* &
687 matmul(acint(1:na, 1:np, j), transpose(bchint(1:nb, 1:np, 1)))
688
689 r_2block(1:na, 1:nb) = r_2block(1:na, 1:nb) + &
690 (deltar(i, jatom) - deltar(i, katom))* &
691 matmul(achint(1:na, 1:np, 1), transpose(bcint(1:nb, 1:np, j)))
692 ELSE
693 r_2block(1:nb, 1:na) = r_2block(1:nb, 1:na) + &
694 (deltar(i, iatom) - deltar(i, katom))* &
695 matmul(bchint(1:nb, 1:np, 1), transpose(acint(1:na, 1:np, j)))
696 r_2block(1:nb, 1:na) = r_2block(1:nb, 1:na) + &
697 (deltar(i, jatom) - deltar(i, katom))* &
698 matmul(bcint(1:nb, 1:np, j), transpose(achint(1:na, 1:np, 1)))
699 END IF
700
701 i = 3; j = 4;
702 katom = alist_ac%clist(kac)%catom
703 IF (iatom <= jatom) THEN
704 r_3block(1:na, 1:nb) = r_3block(1:na, 1:nb) + &
705 (deltar(i, iatom) - deltar(i, katom))* &
706 matmul(acint(1:na, 1:np, j), transpose(bchint(1:nb, 1:np, 1)))
707
708 r_3block(1:na, 1:nb) = r_3block(1:na, 1:nb) + &
709 (deltar(i, jatom) - deltar(i, katom))* &
710 matmul(achint(1:na, 1:np, 1), transpose(bcint(1:nb, 1:np, j)))
711 ELSE
712 r_3block(1:nb, 1:na) = r_3block(1:nb, 1:na) + &
713 (deltar(i, iatom) - deltar(i, katom))* &
714 matmul(bchint(1:nb, 1:np, 1), transpose(acint(1:na, 1:np, j)))
715 r_3block(1:nb, 1:na) = r_3block(1:nb, 1:na) + &
716 (deltar(i, jatom) - deltar(i, katom))* &
717 matmul(bcint(1:nb, 1:np, j), transpose(achint(1:na, 1:np, 1)))
718 END IF
719
720 END IF
721 IF (doat) THEN
722 IF (ASSOCIATED(p_block)) THEN
723 katom = alist_ac%clist(kac)%catom
724 IF (iatom <= jatom) THEN
725 atk = sum(p_block(1:na, 1:nb)* &
726 matmul(achint(1:na, 1:np, 1), transpose(bcint(1:nb, 1:np, 1))))
727 ELSE
728 atk = sum(p_block(1:nb, 1:na)* &
729 matmul(bchint(1:nb, 1:np, 1), transpose(acint(1:na, 1:np, 1))))
730 END IF
731 at_thread(katom) = at_thread(katom) + f0*atk
732 END IF
733 END IF
734 EXIT ! We have found a match and there can be only one single match
735 END IF
736 END DO
737 END DO
738 END DO
739 END IF
740 END DO
741
742!$OMP DO
743!$ DO lock_num = 1, nlock
744!$ call omp_destroy_lock(locks(lock_num))
745!$ END DO
746!$OMP END DO
747
748!$OMP SINGLE
749!$ DEALLOCATE (locks)
750!$OMP END SINGLE NOWAIT
751
752!$OMP END PARALLEL
753
754 CALL release_sap_int(sap_int)
755
756 DEALLOCATE (basis_set, gpotential, spotential)
757 IF (calculate_forces) THEN
758 CALL get_atomic_kind_set(atomic_kind_set, atom_of_kind=atom_of_kind, kind_of=kind_of)
759!$OMP DO
760 DO iatom = 1, natom
761 atom_a = atom_of_kind(iatom)
762 ikind = kind_of(iatom)
763 force(ikind)%gth_ppnl(:, atom_a) = force(ikind)%gth_ppnl(:, atom_a) + force_thread(:, iatom)
764 END DO
765!$OMP END DO
766 DEALLOCATE (atom_of_kind, kind_of)
767 END IF
768
769 IF (calculate_forces .AND. use_virial) THEN
770 virial%pv_ppnl = virial%pv_ppnl + pv_thread
771 virial%pv_virial = virial%pv_virial + pv_thread
772 END IF
773
774 IF (doat) THEN
775 atcore(1:natom) = atcore(1:natom) + at_thread
776 END IF
777
778 IF (calculate_forces .OR. doat) THEN
779 ! If LSD, then recover alpha density and beta density
780 ! from the total density (1) and the spin density (2)
781 IF (SIZE(matrix_p, 1) == 2) THEN
782 DO img = 1, nimages
783 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
784 alpha_scalar=0.5_dp, beta_scalar=0.5_dp)
785 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
786 alpha_scalar=-1.0_dp, beta_scalar=1.0_dp)
787 END DO
788 END IF
789 END IF
790
791 END IF !ppnl_present
792
793 CALL timestop(handle)
794
795 END SUBROUTINE build_core_ppnl
796
797END MODULE core_ppnl
Calculation of the angular momentum integrals over Cartesian Gaussian-type functions.
Definition ai_angmom.F:17
subroutine, public angmom(la_max, npgfa, zeta, rpgfa, la_min, lb_max, npgfb, zetb, rpgfb, rac, rbc, angab)
...
Definition ai_angmom.F:52
Calculation of the overlap integrals over Cartesian Gaussian-type functions.
Definition ai_overlap.F:18
subroutine, public overlap(la_max_set, la_min_set, npgfa, rpgfa, zeta, lb_max_set, lb_min_set, npgfb, rpgfb, zetb, rab, dab, sab, da_max_set, return_derivatives, s, lds, sdab, pab, force_a)
Purpose: Calculation of the two-center overlap integrals [a|b] over Cartesian Gaussian-type functions...
Definition ai_overlap.F:73
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 non-local pseudopotential contribution to the core Hamiltonian <a|V(non-local)|b> ...
Definition core_ppnl.F:15
subroutine, public build_core_ppnl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sap_ppnl, eps_ppnl, nimages, cell_to_index, basis_type, deltar, matrix_l, atcore)
...
Definition core_ppnl.F:90
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
Provides Cartesian and spherical orbital pointers and indices.
subroutine, public init_orbital_pointers(maxl)
Initialize or update the orbital pointers.
integer, dimension(:), allocatable, public nco
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.
General overlap type integrals containers.
subroutine, public release_sap_int(sap_int)
...
subroutine, public sap_sort(sap_int)
...
subroutine, public get_alist(sap_int, alist, atom)
...
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.