(git:27c966b)
Loading...
Searching...
No Matches
qs_vcd_ao.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!--------------------------------------------------------------------------------------------------!
8
10 USE ai_contraction, ONLY: block_add,&
12 USE ai_kinetic, ONLY: kinetic
21 USE cell_types, ONLY: cell_type,&
22 pbc
24 USE cp_dbcsr_api, ONLY: &
36 USE kinds, ONLY: default_string_length,&
37 dp,&
38 int_8
42 ncoset
44 USE pw_env_types, ONLY: pw_env_get,&
46 USE pw_methods, ONLY: pw_axpy,&
49 USE pw_types, ONLY: pw_r3d_rs_type
55 USE qs_integrate_potential, ONLY: integrate_pgf_product
56 USE qs_kind_types, ONLY: get_qs_kind,&
62 USE qs_neighbor_list_types, ONLY: &
67 USE qs_rho_types, ONLY: qs_rho_type
68 USE qs_vxc, ONLY: qs_vxc_create
71 USE sap_kind_types, ONLY: alist_type,&
73 get_alist,&
82 USE virial_types, ONLY: virial_type
83
84!$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num, omp_get_num_threads
85!$ USE OMP_LIB, ONLY: omp_lock_kind, &
86!$ omp_init_lock, omp_set_lock, &
87!$ omp_unset_lock, omp_destroy_lock
88
89#include "./base/base_uses.f90"
90
91 IMPLICIT NONE
92
93 PRIVATE
94
95! *** Global parameters ***
96
97 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_vcd_ao'
98 INTEGER, PARAMETER :: bi_1 = 1, bi_x = 2, bi_y = 3, bi_z = 4, bi_xx = 5, &
99 bi_xy = 6, bi_xz = 7, bi_yy = 8, bi_yz = 9, bi_zz = 10
100 INTEGER, DIMENSION(3), PARAMETER :: bi_r = [bi_x, bi_y, bi_z]
101 INTEGER, DIMENSION(3, 3), PARAMETER :: bi_rr = reshape([bi_xx, bi_xy, bi_xz, bi_xy, bi_yy, bi_yz, &
102 bi_xz, bi_yz, bi_zz], [3, 3])
103
104! *** Public subroutines ***
105
109
110CONTAINS
111
112! **************************************************************************************************
113!> \brief Build the matrix Hr*delta_nu^\lambda - rH*delta_mu^\lambda
114!> \param vcd_env ...
115!> \param qs_env ...
116!> \param rc ...
117!> \author Edward Ditler
118! **************************************************************************************************
119 SUBROUTINE build_matrix_hr_rh(vcd_env, qs_env, rc)
120 TYPE(vcd_env_type) :: vcd_env
121 TYPE(qs_environment_type), POINTER :: qs_env
122 REAL(dp), DIMENSION(3) :: rc
123
124 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_matrix_hr_rh'
125 INTEGER, PARAMETER :: ispin = 1
126
127 INTEGER :: handle, i
128 TYPE(cell_type), POINTER :: cell
129 TYPE(dft_control_type), POINTER :: dft_control
130 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
131 POINTER :: sab_all, sap_ppnl
132 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
133 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
134
135 CALL timeset(routinen, handle)
136
137 CALL get_qs_env(qs_env=qs_env, &
138 dft_control=dft_control, &
139 particle_set=particle_set, &
140 sab_all=sab_all, &
141 sap_ppnl=sap_ppnl, &
142 qs_kind_set=qs_kind_set, &
143 cell=cell)
144
145 DO i = 1, 3
146 CALL dbcsr_set(vcd_env%matrix_hr(ispin, i)%matrix, 0._dp)
147 CALL dbcsr_set(vcd_env%matrix_rh(ispin, i)%matrix, 0._dp)
148 END DO
149
150 associate(matrix_hr_1d => vcd_env%matrix_hr(ispin, 1:3), &
151 matrix_rh_1d => vcd_env%matrix_rh(ispin, 1:3))
152 CALL build_rpnl_matrices(matrix_hr_1d, matrix_rh_1d, qs_kind_set, particle_set, sab_all, sap_ppnl, &
153 dft_control%qs_control%eps_ppnl, cell, rc)
154 CALL build_tr_matrices(matrix_hr_1d, matrix_rh_1d, qs_env, qs_kind_set, "ORB", sab_all, rc)
155 CALL build_rcore_matrices(matrix_hr_1d, matrix_rh_1d, qs_env, qs_kind_set, "ORB", sab_all, rc)
156 CALL build_vhxc_matrices(vcd_env%matrix_hr, vcd_env%matrix_rh, qs_env, rc)
157 END associate
158
159 CALL timestop(handle)
160 END SUBROUTINE build_matrix_hr_rh
161
162! **************************************************************************************************
163!> \brief Build the ordered products V_nl*r and r*V_nl.
164!> \param matrix_vr ...
165!> \param matrix_rv ...
166!> \param qs_kind_set ...
167!> \param particle_set ...
168!> \param sab_all ...
169!> \param sap_ppnl ...
170!> \param eps_ppnl ...
171!> \param cell ...
172!> \param ref_point ...
173!> \author Edward Ditler, Tomas Zimmermann
174! **************************************************************************************************
175 SUBROUTINE build_rpnl_matrices(matrix_vr, matrix_rv, qs_kind_set, particle_set, sab_all, sap_ppnl, eps_ppnl, &
176 cell, ref_point)
177
178 TYPE(dbcsr_p_type), DIMENSION(:) :: matrix_vr, matrix_rv
179 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
180 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
181 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
182 POINTER :: sab_all, sap_ppnl
183 REAL(kind=dp), INTENT(IN) :: eps_ppnl
184 TYPE(cell_type), INTENT(IN), OPTIONAL, POINTER :: cell
185 REAL(kind=dp), DIMENSION(3) :: ref_point
186
187 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_rpnl_matrices'
188
189 INTEGER :: handle, i, iab, iac, iatom, ibc, icol, &
190 ikind, irow, jatom, jkind, kac, kbc, &
191 kkind, na, natom, nb, nkind, np, slot
192 INTEGER, DIMENSION(3) :: cell_b
193 LOGICAL :: found, ppnl_present
194 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: achint, acint, bchint, bcint
195 TYPE(alist_type), POINTER :: alist_ac, alist_bc
196 TYPE(block_p_type), DIMENSION(3) :: blocks_rv, blocks_vr
197 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set
198 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
199 TYPE(sap_int_type), DIMENSION(:), POINTER :: sap_int
200
201!$ INTEGER(kind=omp_lock_kind), &
202!$ ALLOCATABLE, DIMENSION(:) :: locks
203!$ INTEGER :: lock_num, hash
204!$ INTEGER, PARAMETER :: nlock = 501
205
206 ppnl_present = ASSOCIATED(sap_ppnl)
207 IF (.NOT. ppnl_present) RETURN
208
209 CALL timeset(routinen, handle)
210 nkind = SIZE(qs_kind_set)
211 natom = SIZE(particle_set)
212
213 ! sap_int needs to be shared as multiple threads need to access this
214 NULLIFY (sap_int)
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 mark_used(ref_point)
222 ! "nder" in moment_mode is "order"
223 CALL build_sap_ints(sap_int, sap_ppnl, qs_kind_set, nder=1, moment_mode=.true., &
224 particle_set=particle_set, cell=cell, refpoint=ref_point)
225
226 ! *** Set up a sorting index
227 CALL sap_sort(sap_int)
228
229 ALLOCATE (basis_set(nkind))
230 DO ikind = 1, nkind
231 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set)
232 IF (ASSOCIATED(orb_basis_set)) THEN
233 basis_set(ikind)%gto_basis_set => orb_basis_set
234 ELSE
235 NULLIFY (basis_set(ikind)%gto_basis_set)
236 END IF
237 END DO
238
239 ! *** All integrals needed have been calculated and stored in sap_int
240 ! *** We now calculate the ordered product matrix elements
241
242!$OMP PARALLEL &
243!$OMP DEFAULT (NONE) &
244!$OMP SHARED (basis_set, matrix_vr, matrix_rv, &
245!$OMP sap_int, nkind, eps_ppnl, locks, sab_all) &
246!$OMP PRIVATE (ikind, jkind, iatom, jatom, cell_b, &
247!$OMP iab, irow, icol, blocks_vr, blocks_rv, &
248!$OMP found, iac, ibc, alist_ac, alist_bc, &
249!$OMP na, np, nb, kkind, kac, kbc, i, lock_num, &
250!$OMP hash, natom, acint, bcint, achint, bchint)
251
252!$OMP SINGLE
253!$ ALLOCATE (locks(nlock))
254!$OMP END SINGLE
255
256!$OMP DO
257!$ DO lock_num = 1, nlock
258!$ call omp_init_lock(locks(lock_num))
259!$ END DO
260!$OMP END DO
261
262!$OMP DO SCHEDULE(GUIDED)
263
264 DO slot = 1, sab_all(1)%nl_size
265
266 ikind = sab_all(1)%nlist_task(slot)%ikind
267 jkind = sab_all(1)%nlist_task(slot)%jkind
268 iatom = sab_all(1)%nlist_task(slot)%iatom
269 jatom = sab_all(1)%nlist_task(slot)%jatom
270 cell_b(:) = sab_all(1)%nlist_task(slot)%cell(:)
271
272 IF (.NOT. ASSOCIATED(basis_set(ikind)%gto_basis_set)) cycle
273 IF (.NOT. ASSOCIATED(basis_set(jkind)%gto_basis_set)) cycle
274 iab = ikind + nkind*(jkind - 1)
275
276 ! *** Create matrix blocks for a new matrix block column ***
277 irow = iatom
278 icol = jatom
279 DO i = 1, 3
280 CALL dbcsr_get_block_p(matrix_vr(i)%matrix, irow, icol, blocks_vr(i)%block, found)
281 cpassert(found)
282 CALL dbcsr_get_block_p(matrix_rv(i)%matrix, irow, icol, blocks_rv(i)%block, found)
283 cpassert(found)
284 END DO
285
286 ! loop over all kinds for projector atom
287 DO kkind = 1, nkind
288 iac = ikind + nkind*(kkind - 1)
289 ibc = jkind + nkind*(kkind - 1)
290 IF (.NOT. ASSOCIATED(sap_int(iac)%alist)) cycle
291 IF (.NOT. ASSOCIATED(sap_int(ibc)%alist)) cycle
292 CALL get_alist(sap_int(iac), alist_ac, iatom)
293 CALL get_alist(sap_int(ibc), alist_bc, jatom)
294
295 IF (.NOT. ASSOCIATED(alist_ac)) cycle
296 IF (.NOT. ASSOCIATED(alist_bc)) cycle
297 DO kac = 1, alist_ac%nclist
298 DO kbc = 1, alist_bc%nclist
299 IF (alist_ac%clist(kac)%catom /= alist_bc%clist(kbc)%catom) cycle
300 IF (all(cell_b + alist_bc%clist(kbc)%cell - alist_ac%clist(kac)%cell == 0)) THEN
301 IF (alist_ac%clist(kac)%maxac*alist_bc%clist(kbc)%maxach < eps_ppnl) cycle
302 acint => alist_ac%clist(kac)%acint
303 bcint => alist_bc%clist(kbc)%acint
304 achint => alist_ac%clist(kac)%achint
305 bchint => alist_bc%clist(kbc)%achint
306 na = SIZE(acint, 1)
307 np = SIZE(acint, 2)
308 nb = SIZE(bcint, 1)
309!$ hash = MOD((iatom - 1)*natom + jatom, nlock) + 1
310!$ CALL omp_set_lock(locks(hash))
311 DO i = 1, 3
312 ! Vnl*r
313 blocks_vr(i)%block(1:na, 1:nb) = blocks_vr(i)%block(1:na, 1:nb) + &
314 matmul(achint(1:na, 1:np, 1), &
315 transpose(bcint(1:nb, 1:np, i + 1)))
316 ! r*Vnl
317 blocks_rv(i)%block(1:na, 1:nb) = blocks_rv(i)%block(1:na, 1:nb) + &
318 matmul(achint(1:na, 1:np, i + 1), &
319 transpose(bcint(1:nb, 1:np, 1)))
320 END DO
321!$ CALL omp_unset_lock(locks(hash))
322 EXIT ! We have found a match and there can be only one single match
323 END IF
324 END DO
325 END DO
326 END DO
327 DO i = 1, 3
328 NULLIFY (blocks_vr(i)%block)
329 NULLIFY (blocks_rv(i)%block)
330 END DO
331 END DO
332
333!$OMP DO
334!$ DO lock_num = 1, nlock
335!$ call omp_destroy_lock(locks(lock_num))
336!$ END DO
337!$OMP END DO
338
339!$OMP SINGLE
340!$ DEALLOCATE (locks)
341!$OMP END SINGLE NOWAIT
342
343!$OMP END PARALLEL
344
345 CALL release_sap_int(sap_int)
346
347 DEALLOCATE (basis_set)
348
349 CALL timestop(handle)
350
351 END SUBROUTINE build_rpnl_matrices
352
353! **************************************************************************************************
354!> \brief Calculation of the product Tr or rT over Cartesian Gaussian functions.
355!> \param matrix_tr ...
356!> \param matrix_rt ...
357!> \param qs_env ...
358!> \param qs_kind_set ...
359!> \param basis_type basis set to be used
360!> \param sab_nl pair list (must be consistent with basis sets!)
361!> \param rc ...
362!> \date 11.10.2010
363!> \par History
364!> Ported from qs_overlap, replaces code in build_core_hamiltonian
365!> Refactoring [07.2014] JGH
366!> Simplify options and use new kinetic energy integral routine
367!> Adapted from qs_kinetic [07.2016]
368!> Adapted from the kinetic position-product recurrence [2021] by ED
369!> \author JGH
370!> \version 1.0
371! **************************************************************************************************
372 SUBROUTINE build_tr_matrices(matrix_tr, matrix_rt, qs_env, qs_kind_set, basis_type, sab_nl, rc)
373
374 TYPE(dbcsr_p_type), DIMENSION(:) :: matrix_tr, matrix_rt
375 TYPE(qs_environment_type), POINTER :: qs_env
376 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
377 CHARACTER(LEN=*), INTENT(IN) :: basis_type
378 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
379 POINTER :: sab_nl
380 REAL(kind=dp), DIMENSION(3) :: rc
381
382 CHARACTER(len=*), PARAMETER :: routinen = 'build_tr_matrices'
383
384 INTEGER :: handle, i, iatom, icol, ikind, ir, irow, &
385 iset, jatom, jkind, jset, ldsab, ltab, &
386 natom, ncoa, ncob, nkind, nseta, &
387 nsetb, sgfa, sgfb, slot
388 INTEGER, DIMENSION(3) :: cell
389 INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
390 npgfb, nsgfa, nsgfb
391 INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
392 LOGICAL :: do_symmetric, found, trans
393 REAL(kind=dp) :: tab
394 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: qab, tkab
395 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: kab
396 REAL(kind=dp), DIMENSION(3) :: ra, rab, rac, rb, rbc
397 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_a, set_radius_b
398 REAL(kind=dp), DIMENSION(:, :), POINTER :: rpgfa, rpgfb, scon_a, scon_b, zeta, zetb
399 TYPE(block_p_type), DIMENSION(3, 2) :: blocks_tr
400 TYPE(cell_type), POINTER :: qs_cell
401 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
402 TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
403 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
404
405!$ INTEGER(kind=omp_lock_kind), &
406!$ ALLOCATABLE, DIMENSION(:) :: locks
407!$ INTEGER :: lock_num, hash, hash1, hash2
408!$ INTEGER(KIND=int_8) :: iatom8
409!$ INTEGER, PARAMETER :: nlock = 501
410
411 mark_used(int_8)
412
413 CALL timeset(routinen, handle)
414
415 nkind = SIZE(qs_kind_set)
416
417 ! check for symmetry
418 cpassert(SIZE(sab_nl) > 0)
419 CALL get_neighbor_list_set_p(neighbor_list_sets=sab_nl, symmetric=do_symmetric)
420
421 ! prepare basis set
422 ALLOCATE (basis_set_list(nkind))
423 CALL basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
424
425 ! *** Allocate work storage ***
426 ldsab = get_memory_usage(qs_kind_set, basis_type)
427
428 CALL get_qs_env(qs_env=qs_env, &
429 particle_set=particle_set, &
430 cell=qs_cell, &
431 natom=natom)
432
433!$OMP PARALLEL DEFAULT(NONE) &
434!$OMP SHARED (ldsab,do_symmetric, sab_nl, rc,&
435!$OMP ncoset,matrix_tr,matrix_rt,basis_set_list,qs_cell,natom,locks) &
436!$OMP PRIVATE (blocks_tr,kab,qab,tab,ikind,jkind,iatom,jatom,rab,rac,rbc,cell, &
437!$OMP basis_set_a, basis_set_b, nseta, ncoa, ncob, ltab, nsetb, tkab, &
438!$OMP irow, icol, found, trans, sgfa, sgfb, iset, jset, i, &
439!$OMP hash, hash1, hash2, iatom8, slot, lock_num) &
440!$OMP PRIVATE (first_sgfa, la_max, la_min, npgfa, nsgfa, rpgfa, set_radius_a, zeta, scon_a) &
441!$OMP PRIVATE (first_sgfb, lb_max, lb_min, npgfb, nsgfb, rpgfb, set_radius_b, zetb, scon_b) &
442!$OMP SHARED(particle_set) &
443!$OMP PRIVATE(ra, rb)
444
445!$OMP SINGLE
446!$ ALLOCATE (locks(nlock))
447!$OMP END SINGLE
448
449!$OMP DO
450!$ DO lock_num = 1, nlock
451!$ call omp_init_lock(locks(lock_num))
452!$ END DO
453!$OMP END DO
454
455 ALLOCATE (kab(ldsab, ldsab, 3), qab(ldsab, ldsab))
456
457!$OMP DO SCHEDULE(GUIDED)
458 DO slot = 1, sab_nl(1)%nl_size
459
460 ikind = sab_nl(1)%nlist_task(slot)%ikind
461 jkind = sab_nl(1)%nlist_task(slot)%jkind
462 iatom = sab_nl(1)%nlist_task(slot)%iatom
463 jatom = sab_nl(1)%nlist_task(slot)%jatom
464 cell(:) = sab_nl(1)%nlist_task(slot)%cell(:)
465 rab(1:3) = sab_nl(1)%nlist_task(slot)%r(1:3)
466
467 basis_set_a => basis_set_list(ikind)%gto_basis_set
468 IF (.NOT. ASSOCIATED(basis_set_a)) cycle
469 basis_set_b => basis_set_list(jkind)%gto_basis_set
470 IF (.NOT. ASSOCIATED(basis_set_b)) cycle
471
472!$ iatom8 = INT(iatom - 1, int_8)*INT(natom, int_8) + INT(jatom, int_8)
473!$ hash1 = INT(MOD(iatom8, INT(nlock, int_8)) + 1)
474
475 ! basis ikind
476 first_sgfa => basis_set_a%first_sgf
477 la_max => basis_set_a%lmax
478 la_min => basis_set_a%lmin
479 npgfa => basis_set_a%npgf
480 nsgfa => basis_set_a%nsgf_set
481 rpgfa => basis_set_a%pgf_radius
482 set_radius_a => basis_set_a%set_radius
483 scon_a => basis_set_a%scon
484 zeta => basis_set_a%zet
485 ! basis jkind
486 first_sgfb => basis_set_b%first_sgf
487 lb_max => basis_set_b%lmax
488 lb_min => basis_set_b%lmin
489 npgfb => basis_set_b%npgf
490 nsgfb => basis_set_b%nsgf_set
491 rpgfb => basis_set_b%pgf_radius
492 set_radius_b => basis_set_b%set_radius
493 scon_b => basis_set_b%scon
494 zetb => basis_set_b%zet
495
496 nseta = basis_set_a%nset
497 nsetb = basis_set_b%nset
498
499 IF (do_symmetric) THEN
500 IF (iatom <= jatom) THEN
501 irow = iatom
502 icol = jatom
503 ELSE
504 irow = jatom
505 icol = iatom
506 END IF
507 ELSE
508 irow = iatom
509 icol = jatom
510 END IF
511 DO ir = 1, 3
512 NULLIFY (blocks_tr(ir, 1)%block)
513 CALL dbcsr_get_block_p(matrix=matrix_tr(ir)%matrix, &
514 row=irow, col=icol, block=blocks_tr(ir, 1)%block, found=found)
515 cpassert(found)
516 NULLIFY (blocks_tr(ir, 2)%block)
517 CALL dbcsr_get_block_p(matrix=matrix_rt(ir)%matrix, &
518 row=irow, col=icol, block=blocks_tr(ir, 2)%block, found=found)
519 cpassert(found)
520 END DO
521
522 ! The kinetic integrals depend only on rab (also for the screening)
523 tab = norm2(rab)
524
525 ! With and without MIC, rab(:) is the vector giving us the coordinates of rb.
526 ra = pbc(particle_set(iatom)%r(:), qs_cell)
527 rb(:) = ra(:) + rab(:)
528 rac = pbc(rc, ra, qs_cell)
529 rbc = rac + rab
530
531 trans = do_symmetric .AND. (iatom > jatom)
532
533 DO iset = 1, nseta
534
535 ncoa = npgfa(iset)*(ncoset(la_max(iset)) - ncoset(la_min(iset) - 1))
536 sgfa = first_sgfa(1, iset)
537
538 DO jset = 1, nsetb
539
540 IF (set_radius_a(iset) + set_radius_b(jset) < tab) cycle
541
542!$ hash2 = MOD((iset - 1)*nsetb + jset, nlock) + 1
543!$ hash = MOD(hash1 + hash2, nlock) + 1
544
545 ncob = npgfb(jset)*(ncoset(lb_max(jset)) - ncoset(lb_min(jset) - 1))
546 sgfb = first_sgfb(1, jset)
547
548 ! calculate integrals
549 ltab = max(npgfa(iset)*ncoset(la_max(iset) + 1), npgfb(jset)*ncoset(lb_max(jset) + 1))
550 ALLOCATE (tkab(ltab, ltab))
551 CALL kinetic(la_max(iset) + 1, la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
552 lb_max(jset) + 1, lb_min(jset), npgfb(jset), rpgfb(:, jset), zetb(:, jset), &
553 rab, tkab)
554 ! Ordered products T*r and r*T
555 DO i = 1, 2
556 CALL apply_cartesian_operator(la_max(iset), la_min(iset), npgfa(iset), &
557 lb_max(jset), lb_min(jset), npgfb(jset), tkab, kab, &
558 right=(i == 1), derivative=.false., origin=merge(rbc, rac, i == 1))
559 DO ir = 1, 3
560 CALL contraction(kab(:, :, ir), qab, ca=scon_a(:, sgfa:), na=ncoa, ma=nsgfa(iset), &
561 cb=scon_b(:, sgfb:), nb=ncob, mb=nsgfb(jset), trans=trans)
562
563!$ CALL omp_set_lock(locks(hash))
564 CALL block_add("IN", qab, nsgfa(iset), nsgfb(jset), blocks_tr(ir, i)%block, &
565 sgfa, sgfb, trans=trans)
566!$ CALL omp_unset_lock(locks(hash))
567 END DO
568 END DO
569 DEALLOCATE (tkab)
570
571 END DO
572 END DO
573 END DO !iterator
574 DEALLOCATE (kab, qab)
575!$OMP DO
576!$ DO lock_num = 1, nlock
577!$ call omp_destroy_lock(locks(lock_num))
578!$ END DO
579!$OMP END DO
580
581!$OMP SINGLE
582!$ DEALLOCATE (locks)
583!$OMP END SINGLE NOWAIT
584
585!$OMP END PARALLEL
586
587 ! Release work storage
588 DEALLOCATE (basis_set_list)
589 CALL timestop(handle)
590
591 END SUBROUTINE build_tr_matrices
592
593! **************************************************************************************************
594!> \brief Build the ordered products V_core*r and r*V_core.
595!> \param matrix_rcore_hr ...
596!> \param matrix_rcore_rh ...
597!> \param qs_env ...
598!> \param qs_kind_set ...
599!> \param basis_type ...
600!> \param sab_nl ...
601!> \param rf ...
602!> \author Edward Ditler, Tomas Zimmermann
603! **************************************************************************************************
604 SUBROUTINE build_rcore_matrices(matrix_rcore_hr, matrix_rcore_rh, qs_env, qs_kind_set, basis_type, sab_nl, rf)
605 TYPE(dbcsr_p_type), DIMENSION(:) :: matrix_rcore_hr, matrix_rcore_rh
606 TYPE(qs_environment_type), POINTER :: qs_env
607 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
608 CHARACTER(LEN=*) :: basis_type
609 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
610 POINTER :: sab_nl
611 REAL(kind=dp), DIMENSION(3) :: rf
612
613 CHARACTER(len=*), PARAMETER :: routinen = 'build_rcore_matrices'
614 INTEGER, PARAMETER :: nexp_max = 30
615
616 INTEGER :: atom_a, atom_b, handle, i, iatom, icol, idir, ikind, inode, irow, iset, jatom, &
617 jkind, jset, katom, kkind, ldai, ldsab, maxco, maxder, maxl, maxlgto, maxlppl, maxnset, &
618 maxsgf, mepos, n_local, ncoa, ncob, nder, nexp_lpot, nexp_ppl, nimages, nkind, nloc, &
619 nseta, nsetb, nthread, sgfa, sgfb
620 INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind
621 INTEGER, DIMENSION(1:10) :: nrloc
622 INTEGER, DIMENSION(3) :: cellind
623 INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, &
624 nct_lpot, npgfa, npgfb, nsgfa, nsgfb
625 INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
626 INTEGER, DIMENSION(nexp_max) :: nct_ppl
627 LOGICAL :: do_symmetric, do_upf, dokp, ecp_local, &
628 ecp_semi_local, found, lpotextended
629 REAL(kind=dp) :: alpha, dab, dac, dbc, ppl_radius
630 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: hab, qab
631 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: ppl_work, rhab, work
632 REAL(kind=dp), DIMENSION(1:10) :: aloc, bloc
633 REAL(kind=dp), DIMENSION(3) :: ra, rab, rac, raf, rb, rbc
634 REAL(kind=dp), DIMENSION(4, nexp_max) :: cval_ppl
635 REAL(kind=dp), DIMENSION(:), POINTER :: a_local, alpha_lpot, c_local, cexp_ppl, &
636 set_radius_a, set_radius_b
637 REAL(kind=dp), DIMENSION(:, :), POINTER :: cval_lpot, rpgfa, rpgfb, scon_a, scon_b, &
638 sphi_a, sphi_b, zeta, zetb
639 REAL(kind=dp), DIMENSION(nexp_max) :: alpha_ppl
640 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
641 TYPE(block_p_type), DIMENSION(3, 2) :: blocks_rcore
642 TYPE(cell_type), POINTER :: cell
643 TYPE(gth_potential_type), POINTER :: gth_potential
644 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
645 TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
646 TYPE(neighbor_list_iterator_p_type), &
647 DIMENSION(:), POINTER :: ap_iterator, nl_iterator
648 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
649 POINTER :: sac_ppl
650 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
651 TYPE(sgp_potential_type), POINTER :: sgp_potential
652
653 CALL timeset(routinen, handle)
654
655 CALL get_qs_env(qs_env=qs_env, &
656 atomic_kind_set=atomic_kind_set, &
657 qs_kind_set=qs_kind_set, &
658 particle_set=particle_set, &
659 sac_ppl=sac_ppl, &
660 cell=cell)
661
662 ! check for symmetry
663 cpassert(SIZE(sab_nl) > 0)
664 CALL get_neighbor_list_set_p(neighbor_list_sets=sab_nl, symmetric=do_symmetric)
665
666 nkind = SIZE(qs_kind_set)
667
668 ! prepare basis set
669 ALLOCATE (basis_set_list(nkind))
670 CALL basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
671
672 nder = 0
673 nimages = 1
674
675 alpha_ppl = 0
676 nct_ppl = 0
677 cval_ppl = 0
678
679 nkind = SIZE(atomic_kind_set)
680
681 dokp = (nimages > 1)
682
683 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, atom_of_kind=atom_of_kind)
684
685 maxder = ncoset(nder)
686
687 CALL get_qs_kind_set(qs_kind_set, maxco=maxco, maxlgto=maxlgto, &
688 maxsgf=maxsgf, maxnset=maxnset, maxlppl=maxlppl, &
689 basis_type=basis_type)
690
691 maxl = max(maxlgto, maxlppl)
692 CALL init_orbital_pointers(2*maxl + 2*nder + 2)
693
694 !tz: maxco in maxco*ncoset(maxlgto+1) is an overkill,
695 ! properly there should be maxpgf*ncoset(maxlgto+1), but maxpgf is difficult to get
696 ldsab = max(maxco, ncoset(maxlppl), maxsgf, maxlppl, maxco*ncoset(maxlgto + 1))
697 ldai = ncoset(2*maxlgto + 2)
698
699 DO ikind = 1, nkind
700 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set_a, basis_type=basis_type, &
701 sgp_potential=sgp_potential)
702 IF (ASSOCIATED(sgp_potential)) THEN
703 IF (ALLOCATED(sgp_potential%upf_data)) THEN
704 IF (sgp_potential%upf_local%radial%degree < 2*maxlgto + 2) THEN
705 CALL upf_local_init(sgp_potential%upf_data, sgp_potential%alpha_core_charge, &
706 2*maxlgto + 2, sgp_potential%upf_local)
707 END IF
708 END IF
709 END IF
710 IF (ASSOCIATED(basis_set_a)) THEN
711 basis_set_list(ikind)%gto_basis_set => basis_set_a
712 ELSE
713 NULLIFY (basis_set_list(ikind)%gto_basis_set)
714 END IF
715 END DO
716
717 nthread = 1
718!$ nthread = omp_get_max_threads()
719
720 CALL neighbor_list_iterator_create(nl_iterator, sab_nl, nthread=nthread)
721
722 ! iterator for basis/potential list
723 CALL neighbor_list_iterator_create(ap_iterator, sac_ppl, search=.true., nthread=nthread)
724
725!$OMP PARALLEL &
726!$OMP DEFAULT (NONE) &
727!$OMP SHARED (nl_iterator, ap_iterator, basis_set_list, &
728!$OMP atomic_kind_set, qs_kind_set, particle_set, &
729!$OMP sab_nl, sac_ppl, nthread, ncoset, nkind, &
730!$OMP atom_of_kind, ldsab, maxnset, maxder, &
731!$OMP maxlgto, nder, maxco, dokp, cell) &
732!$OMP SHARED (matrix_rcore_hr, matrix_rcore_rh, rf) &
733!$OMP PRIVATE (ikind, jkind, inode, iatom, jatom, rab, basis_set_a, basis_set_b, atom_a) &
734!$OMP PRIVATE (atom_b) &
735!$OMP PRIVATE (nsetb) &
736!$OMP PRIVATE (dab, irow, icol, blocks_rcore, found, iset, ncoa, i) &
737!$OMP PRIVATE (sgfa, jset, ncob, sgfb, work, hab, rhab, kkind, nseta) &
738!$OMP PRIVATE (gth_potential, sgp_potential, alpha, cexp_ppl, lpotextended) &
739!$OMP PRIVATE (ppl_radius, nexp_lpot, nexp_ppl, alpha_ppl, alpha_lpot, nct_ppl) &
740!$OMP PRIVATE (ecp_semi_local, nct_lpot, cval_ppl, cval_lpot, rac, dac, rbc, dbc) &
741!$OMP PRIVATE (mepos) &
742!$OMP PRIVATE (katom, ppl_work, cellind, ecp_local) &
743!$OMP PRIVATE (first_sgfa, la_max, la_min, npgfa, nsgfa, rpgfa, set_radius_a, sphi_a, zeta, scon_a) &
744!$OMP PRIVATE (first_sgfb, lb_max, lb_min, npgfb, nsgfb, rpgfb, set_radius_b, sphi_b, zetb, scon_b) &
745!$OMP PRIVATE (nloc, nrloc, aloc, bloc, n_local, a_local, c_local, ldai) &
746!$OMP PRIVATE (ra, rb, qab, raf, do_upf)
747
748 mepos = 0
749!$ mepos = omp_get_thread_num()
750
751 ALLOCATE (hab(ldsab, ldsab), rhab(ldsab, ldsab, 3), work(ldsab, ldsab*(nder + 1), 3))
752 ALLOCATE (qab(ldsab, ldsab))
753
754 ldai = ncoset(2*maxlgto + 2)
755 ALLOCATE (ppl_work(ldai, ldai, max(maxder, 2*maxlgto + 2 + 1)))
756
757 DO WHILE (neighbor_list_iterate(nl_iterator, mepos=mepos) == 0)
758
759 CALL get_iterator_info(nl_iterator, mepos=mepos, ikind=ikind, jkind=jkind, inode=inode, &
760 iatom=iatom, jatom=jatom, r=rab, cell=cellind)
761
762 basis_set_a => basis_set_list(ikind)%gto_basis_set
763 IF (.NOT. ASSOCIATED(basis_set_a)) cycle
764 basis_set_b => basis_set_list(jkind)%gto_basis_set
765 IF (.NOT. ASSOCIATED(basis_set_b)) cycle
766
767 atom_a = atom_of_kind(iatom)
768 atom_b = atom_of_kind(jatom)
769
770 ! basis ikind
771 first_sgfa => basis_set_a%first_sgf
772 la_max => basis_set_a%lmax
773 la_min => basis_set_a%lmin
774 npgfa => basis_set_a%npgf
775 nsgfa => basis_set_a%nsgf_set
776 rpgfa => basis_set_a%pgf_radius
777 set_radius_a => basis_set_a%set_radius
778 sphi_a => basis_set_a%sphi
779 zeta => basis_set_a%zet
780 scon_a => basis_set_a%scon
781 ! basis jkind
782 first_sgfb => basis_set_b%first_sgf
783 lb_max => basis_set_b%lmax
784 lb_min => basis_set_b%lmin
785 npgfb => basis_set_b%npgf
786 nsgfb => basis_set_b%nsgf_set
787 rpgfb => basis_set_b%pgf_radius
788 set_radius_b => basis_set_b%set_radius
789 sphi_b => basis_set_b%sphi
790 zetb => basis_set_b%zet
791 scon_b => basis_set_b%scon
792
793 nseta = basis_set_a%nset
794 nsetb = basis_set_b%nset
795
796 ! *** Create matrix blocks for a new matrix block column ***
797 irow = iatom
798 icol = jatom
799
800 DO idir = 1, 3
801 NULLIFY (blocks_rcore(idir, 1)%block)
802 CALL dbcsr_get_block_p(matrix=matrix_rcore_hr(idir)%matrix, &
803 row=irow, col=icol, block=blocks_rcore(idir, 1)%block, found=found)
804 cpassert(found)
805 NULLIFY (blocks_rcore(idir, 2)%block)
806 CALL dbcsr_get_block_p(matrix=matrix_rcore_rh(idir)%matrix, &
807 row=irow, col=icol, block=blocks_rcore(idir, 2)%block, found=found)
808 cpassert(found)
809 END DO
810
811 dab = norm2(rab)
812 ra = pbc(particle_set(iatom)%r(:), cell)
813 rb(:) = ra(:) + rab(:)
814
815 raf = pbc(rf, ra, cell)
816
817 ! loop over all kinds for pseudopotential atoms
818 DO kkind = 1, nkind
819 CALL get_qs_kind(qs_kind_set(kkind), gth_potential=gth_potential, &
820 sgp_potential=sgp_potential)
821 do_upf = .false.
822 IF (ASSOCIATED(gth_potential)) THEN
823 CALL get_potential(potential=gth_potential, &
824 alpha_ppl=alpha, cexp_ppl=cexp_ppl, &
825 lpot_present=lpotextended, ppl_radius=ppl_radius)
826 nexp_ppl = 1
827 alpha_ppl(1) = alpha
828 nct_ppl(1) = SIZE(cexp_ppl)
829 cval_ppl(1:nct_ppl(1), 1) = cexp_ppl(1:nct_ppl(1))
830 IF (lpotextended) THEN
831 CALL get_potential(potential=gth_potential, &
832 nexp_lpot=nexp_lpot, alpha_lpot=alpha_lpot, nct_lpot=nct_lpot, cval_lpot=cval_lpot)
833 cpassert(nexp_lpot < nexp_max)
834 nexp_ppl = nexp_lpot + 1
835 alpha_ppl(2:nexp_lpot + 1) = alpha_lpot(1:nexp_lpot)
836 nct_ppl(2:nexp_lpot + 1) = nct_lpot(1:nexp_lpot)
837 DO i = 1, nexp_lpot
838 cval_ppl(1:nct_lpot(i), i + 1) = cval_lpot(1:nct_lpot(i), i)
839 END DO
840 END IF
841 ELSE IF (ASSOCIATED(sgp_potential)) THEN
842 CALL get_potential(potential=sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local, &
843 ppl_radius=ppl_radius)
844 do_upf = ALLOCATED(sgp_potential%upf_data)
845 IF (do_upf) THEN
846 cpassert(.NOT. ecp_local .AND. .NOT. ecp_semi_local)
847 ELSE IF (ecp_local) THEN
848 CALL get_potential(potential=sgp_potential, nloc=nloc, nrloc=nrloc, aloc=aloc, bloc=bloc)
849 IF (sum(abs(aloc(1:nloc))) < 1.0e-12_dp) cycle
850 nexp_ppl = nloc
851 cpassert(nexp_ppl <= nexp_max)
852 nct_ppl(1:nloc) = nrloc(1:nloc) - 1
853 alpha_ppl(1:nloc) = bloc(1:nloc)
854 cval_ppl(1, 1:nloc) = aloc(1:nloc)
855 ELSE
856 CALL get_potential(potential=sgp_potential, n_local=n_local, a_local=a_local, c_local=c_local)
857 nexp_ppl = n_local
858 cpassert(nexp_ppl <= nexp_max)
859 nct_ppl(1:n_local) = 1
860 alpha_ppl(1:n_local) = a_local(1:n_local)
861 cval_ppl(1, 1:n_local) = c_local(1:n_local)
862 END IF
863 IF (ecp_semi_local) THEN
864 cpabort("VCD with semi-local ECPs not implemented")
865 END IF
866 ELSE
867 cycle
868 END IF
869
870 CALL nl_set_sub_iterator(ap_iterator, ikind, kkind, iatom, mepos=mepos)
871
872 DO WHILE (nl_sub_iterate(ap_iterator, mepos=mepos) == 0)
873
874 CALL get_iterator_info(ap_iterator, mepos=mepos, jatom=katom, r=rac)
875 dac = sqrt(sum(rac*rac))
876 rbc(:) = rac(:) - rab(:)
877 dbc = sqrt(sum(rbc*rbc))
878 IF ((maxval(set_radius_a(:)) + ppl_radius < dac) .OR. &
879 (maxval(set_radius_b(:)) + ppl_radius < dbc)) THEN
880 cycle
881 END IF
882 DO iset = 1, nseta
883 IF (set_radius_a(iset) + ppl_radius < dac) cycle
884 ncoa = npgfa(iset)*ncoset(la_max(iset))
885 ! ncoa = npgfa(iset)*(ncoset(la_max(iset))-ncoset(la_min(iset)-1))
886 sgfa = first_sgfa(1, iset)
887 DO jset = 1, nsetb
888 IF (set_radius_b(jset) + ppl_radius < dbc) cycle
889 ncob = npgfb(jset)*ncoset(lb_max(jset))
890 ! ncob = npgfb(jset)*(ncoset(lb_max(jset))-ncoset(lb_min(jset)-1))
891 sgfb = first_sgfb(1, jset)
892 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
893 ! *** Calculate the GTH pseudo potential forces ***
894 hab = 0
895 rhab = 0
896 ppl_work = 0
897 work = 0
898
899 IF (do_upf) THEN
900 CALL upf_local_matrix(sgp_potential%upf_local, &
901 la_max(iset) + 1, zeta(:npgfa(iset), iset), &
902 lb_max(jset) + 1, zetb(:npgfb(jset), jset), rab, rac, &
903 hab(:npgfa(iset)*ncoset(la_max(iset) + 1), :npgfb(jset)*ncoset(lb_max(jset) + 1)))
904 ELSE
905 CALL ppl_integral( &
906 la_max(iset) + 1, la_min(iset), npgfa(iset), &
907 rpgfa(:, iset), zeta(:, iset), &
908 lb_max(jset) + 1, lb_min(jset), npgfb(jset), &
909 rpgfb(:, jset), zetb(:, jset), &
910 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
911 rab, dab, rac, dac, rbc, dbc, hab(:, :), ppl_work)
912 END IF
913
914 ! product with r
915 CALL apply_cartesian_operator(la_max(iset), 0, npgfa(iset), lb_max(jset), 0, npgfb(jset), &
916 hab, rhab, right=.false., derivative=.false., origin=raf)
917
918 DO idir = 1, 3
919 CALL dgemm("N", "N", ncoa, nsgfb(jset), ncob, &
920 1.0_dp, rhab(1, 1, idir), SIZE(rhab, 1), &
921 sphi_b(1, sgfb), SIZE(sphi_b, 1), &
922 0.0_dp, work(1, 1, idir), SIZE(work, 1))
923!$OMP CRITICAL(h_block_critical)
924 DO i = 1, 2
925 CALL dgemm("T", "N", nsgfa(iset), nsgfb(jset), ncoa, &
926 1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
927 work(1, 1, idir), SIZE(work, 1), &
928 1.0_dp, blocks_rcore(idir, i)%block(sgfa, sgfb), &
929 SIZE(blocks_rcore(idir, i)%block, 1))
930 END DO
931!$OMP END CRITICAL(h_block_critical)
932 END DO
933 END DO
934 END DO
935 END DO
936 END DO
937 END DO ! iterator
938
939 DEALLOCATE (hab, rhab, work, ppl_work)
940
941!$OMP END PARALLEL
942
943 CALL neighbor_list_iterator_release(ap_iterator)
944 CALL neighbor_list_iterator_release(nl_iterator)
945
946 DEALLOCATE (atom_of_kind, basis_set_list)
947
948 CALL timestop(handle)
949
950 END SUBROUTINE build_rcore_matrices
951
952! **************************************************************************************************
953!> \brief Build the ordered Hartree+XC products V_HXC*r and r*V_HXC.
954!> \param matrix_hr ...
955!> \param matrix_rh ...
956!> \param qs_env ...
957!> \param rc ...
958!> \author Edward Ditler, Tomas Zimmermann
959! **************************************************************************************************
960 SUBROUTINE build_vhxc_matrices(matrix_hr, matrix_rh, qs_env, rc)
961 TYPE(dbcsr_p_type), DIMENSION(:, :), &
962 INTENT(INOUT), POINTER :: matrix_hr, matrix_rh
963 TYPE(qs_environment_type), POINTER :: qs_env
964 REAL(kind=dp), DIMENSION(3) :: rc
965
966 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_vhxc_matrices'
967 INTEGER, PARAMETER :: nspins = 1
968
969 INTEGER :: handle, idir, ispin
970 REAL(kind=dp) :: edisp
971 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks
972 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_rvxc, matrix_rvxc_desymm
973 TYPE(pw_env_type), POINTER :: pw_env
974 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
975 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_rspace, v_tau_rspace
976 TYPE(pw_r3d_rs_type), POINTER :: v_hartree_rspace
977 TYPE(qs_energy_type), POINTER :: energy
978 TYPE(qs_ks_env_type), POINTER :: ks_env
979 TYPE(qs_rho_type), POINTER :: rho_struct
980 TYPE(section_vals_type), POINTER :: input, xc_section
981
982 CALL timeset(routinen, handle)
983
984 CALL get_qs_env(qs_env, matrix_ks=matrix_ks, &
985 ks_env=ks_env, &
986 pw_env=pw_env, &
987 input=input, &
988 v_hartree_rspace=v_hartree_rspace, &
989 energy=energy)
990
991 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
992
993 NULLIFY (matrix_rvxc, matrix_rvxc_desymm)
994 CALL dbcsr_allocate_matrix_set(matrix_rvxc, nspins, 3)
995 CALL dbcsr_allocate_matrix_set(matrix_rvxc_desymm, nspins, 3)
996
997 DO ispin = 1, nspins
998 DO idir = 1, 3
999 CALL dbcsr_init_p(matrix_rvxc(ispin, idir)%matrix)
1000 CALL dbcsr_init_p(matrix_rvxc_desymm(ispin, idir)%matrix)
1001
1002 CALL dbcsr_copy(matrix_rvxc_desymm(ispin, idir)%matrix, matrix_hr(1, 1)%matrix)
1003 CALL dbcsr_set(matrix_rvxc_desymm(ispin, idir)%matrix, 0._dp)
1004
1005 CALL dbcsr_copy(matrix_rvxc(ispin, idir)%matrix, matrix_ks(ispin)%matrix)
1006 CALL dbcsr_set(matrix_rvxc(ispin, idir)%matrix, 0.0_dp)
1007 END DO
1008 END DO
1009
1010 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
1011 CALL get_qs_env(qs_env=qs_env, rho=rho_struct)
1012
1013 NULLIFY (v_rspace)
1014 NULLIFY (v_tau_rspace)
1015 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=xc_section, &
1016 vxc_rho=v_rspace, vxc_tau=v_tau_rspace, exc=energy%exc, &
1017 edisp=edisp, dispersion_env=qs_env%dispersion_env, &
1018 just_energy=.false.)
1019
1020 IF (.NOT. ASSOCIATED(v_rspace)) THEN
1021 ALLOCATE (v_rspace(nspins))
1022 DO ispin = 1, nspins
1023 CALL auxbas_pw_pool%create_pw(v_rspace(ispin))
1024 CALL pw_zero(v_rspace(ispin))
1025 END DO
1026 END IF
1027
1028 DO ispin = 1, nspins
1029 CALL pw_axpy(v_hartree_rspace, v_rspace(ispin), 1.0_dp/v_hartree_rspace%pw_grid%dvol)
1030 CALL integrate_rv_rspace(v_rspace=v_rspace(ispin), hmat=matrix_rvxc(ispin, :), qs_env=qs_env, &
1031 rc=rc)
1032
1033 DO idir = 1, 3
1034 CALL dbcsr_scale(matrix_rvxc(ispin, idir)%matrix, v_rspace(ispin)%pw_grid%dvol)
1035 CALL dbcsr_desymmetrize(matrix_rvxc(ispin, idir)%matrix, matrix_rvxc_desymm(ispin, idir)%matrix)
1036 CALL dbcsr_add(matrix_hr(ispin, idir)%matrix, matrix_rvxc_desymm(ispin, idir)%matrix, 1.0_dp, 1.0_dp)
1037 CALL dbcsr_add(matrix_rh(ispin, idir)%matrix, matrix_rvxc_desymm(ispin, idir)%matrix, 1.0_dp, 1.0_dp)
1038 END DO
1039 END DO
1040
1041 ! return pw grids
1042 DO ispin = 1, nspins
1043 CALL auxbas_pw_pool%give_back_pw(v_rspace(ispin))
1044 END DO
1045 DEALLOCATE (v_rspace)
1046
1047 CALL dbcsr_deallocate_matrix_set(matrix_rvxc)
1048 CALL dbcsr_deallocate_matrix_set(matrix_rvxc_desymm)
1049
1050 CALL timestop(handle)
1051
1052 END SUBROUTINE build_vhxc_matrices
1053
1054! **************************************************************************************************
1055!> \brief Calculates the integrals < mu | r * V | nu >
1056!> There is no direction_Or argument, because the potentials commute with r
1057!> This routine uses integrate_pgf_product directly. It could probably be rewritten to use
1058!> the new task_list interface.
1059!> \param v_rspace ...
1060!> \param hmat ...
1061!> \param qs_env ...
1062!> \param rc ...
1063!> \author Edward Ditler
1064! **************************************************************************************************
1065 SUBROUTINE integrate_rv_rspace(v_rspace, hmat, qs_env, rc)
1066
1067 TYPE(pw_r3d_rs_type) :: v_rspace
1068 TYPE(dbcsr_p_type), DIMENSION(:), INTENT(INOUT) :: hmat
1069 TYPE(qs_environment_type), POINTER :: qs_env
1070 REAL(kind=dp), DIMENSION(3) :: rc
1071
1072 CHARACTER(len=*), PARAMETER :: routinen = 'integrate_rv_rspace'
1073
1074 CHARACTER(len=default_string_length) :: my_basis_type
1075 INTEGER :: bcol, brow, handle, iatom, idir, igrid_level, ikind, ikind_old, ilevel, img, &
1076 ipair, ipgf, ipgf_new, iset, iset_new, iset_old, itask, ithread, jatom, jkind, jkind_old, &
1077 jpgf, jpgf_new, jset, jset_new, jset_old, ldsab, maxco, maxlgto, maxpgf, maxset, &
1078 maxsgf_set, na1, na2, natom, nb1, nb2, ncoa, ncoa_full, ncob, ncob_full, nkind, nseta, &
1079 nsetb, nthread, offset, sgfa, sgfb
1080 INTEGER, DIMENSION(:), POINTER :: col_blk_size, la_max, la_min, lb_max, &
1081 lb_min, npgfa, npgfb, nsgfa, nsgfb, &
1082 row_blk_size
1083 INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
1084 LOGICAL :: atom_pair_changed, atom_pair_done, &
1085 found, has_threads, my_compute_tau, &
1086 my_gapw, new_set_pair_coming
1087 REAL(kind=dp) :: eps_rho_rspace, f, prefactor, radius, &
1088 zetp
1089 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :), &
1090 TARGET :: h_buffer
1091 REAL(kind=dp), DIMENSION(3) :: ra, rab, rab_inv, rac, rb, rbc, rp
1092 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_a, set_radius_b
1093 REAL(kind=dp), DIMENSION(:, :), POINTER :: hab, sphi_a, sphi_b, work, zeta, zetb
1094 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: habt, rhab, workt
1095 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1096 TYPE(block_p_type), ALLOCATABLE, DIMENSION(:) :: h_block
1097 TYPE(cell_type), POINTER :: cell
1098 TYPE(dbcsr_distribution_type) :: dist
1099 TYPE(dbcsr_p_type) :: matrix_image(1)
1100 TYPE(dft_control_type), POINTER :: dft_control
1101 TYPE(gridlevel_info_type), POINTER :: gridlevel_info
1102 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
1103 TYPE(mp_comm_type) :: group
1104 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1105 TYPE(pw_env_type), POINTER :: pw_env
1106 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1107 TYPE(realspace_grid_type), DIMENSION(:), POINTER :: rs_v
1108 TYPE(task_list_type), POINTER :: task_list, task_list_soft
1109 TYPE(task_type), DIMENSION(:), POINTER :: tasks
1110 TYPE(virial_type), POINTER :: virial
1111
1112 CALL timeset(routinen, handle)
1113
1114 my_compute_tau = .false.
1115 my_gapw = .false.
1116 my_basis_type = "ORB"
1117
1118 ! get the task lists
1119 CALL get_qs_env(qs_env=qs_env, &
1120 task_list=task_list, &
1121 task_list_soft=task_list_soft)
1122 cpassert(ASSOCIATED(task_list))
1123
1124 ! the information on the grids is provided through pw_env
1125 ! pw_env has to be the parent env for the potential grid (input)
1126 ! there is an option to provide an external grid
1127 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1128 cpassert(ASSOCIATED(pw_env))
1129
1130 ! get all the general information on the system we are working on
1131 CALL get_qs_env(qs_env=qs_env, &
1132 atomic_kind_set=atomic_kind_set, &
1133 qs_kind_set=qs_kind_set, &
1134 cell=cell, &
1135 dft_control=dft_control, &
1136 particle_set=particle_set, &
1137 virial=virial, &
1138 natom=natom)
1139
1140 rab = 0._dp
1141 rac = 0._dp
1142 rbc = 0._dp
1143
1144 ! short cuts to task list variables
1145 tasks => task_list%tasks
1146
1147 cpassert(ASSOCIATED(pw_env))
1148 CALL pw_env_get(pw_env, rs_grids=rs_v)
1149
1150 ! get mpi group from rs_v
1151 group = rs_v(1)%desc%group
1152
1153 ! assign from pw_env
1154 gridlevel_info => pw_env%gridlevel_info
1155
1156 ! transform the potential on the rs_multigrids
1157 CALL potential_pw2rs(rs_v, v_rspace, pw_env)
1158
1159 nkind = SIZE(qs_kind_set)
1160
1161 ! needs to be consistent with rho_rspace
1162 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
1163
1164 CALL get_qs_kind_set(qs_kind_set=qs_kind_set, &
1165 maxco=maxco, &
1166 maxlgto=maxlgto, &
1167 maxsgf_set=maxsgf_set, &
1168 basis_type=my_basis_type)
1169
1170 nthread = 1
1171!$ nthread = omp_get_max_threads()
1172
1173 ! get maximum numbers
1174 maxset = 0
1175 maxpgf = 0
1176 DO ikind = 1, nkind
1177 CALL get_qs_kind(qs_kind_set(ikind), &
1178 basis_set=orb_basis_set, basis_type=my_basis_type)
1179
1180 IF (.NOT. ASSOCIATED(orb_basis_set)) cycle
1181
1182 CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
1183 npgf=npgfa, nset=nseta)
1184
1185 maxset = max(nseta, maxset)
1186 maxpgf = max(maxval(npgfa), maxpgf)
1187 END DO
1188
1189 ldsab = max(maxco, maxsgf_set, maxpgf*ncoset(maxlgto + 1))
1190
1191 ! *** Allocate work storage ***
1192 NULLIFY (habt, workt)
1193 CALL reallocate(habt, 1, ldsab, 1, ldsab, 0, nthread)
1194 CALL reallocate(workt, 1, ldsab, 1, maxsgf_set, 0, nthread)
1195 ALLOCATE (rhab(ldsab, ldsab, 3))
1196
1197 ALLOCATE (h_block(3))
1198
1199 IF (ASSOCIATED(task_list%atom_pair_send)) THEN
1200 ! Accumulate on task ranks, then return each partial block to its matrix owner.
1201 ALLOCATE (h_buffer(task_list%buffer_size_recv, 3))
1202 h_buffer(:, :) = 0.0_dp
1203 CALL dbcsr_get_info(hmat(1)%matrix, row_blk_size=row_blk_size, col_blk_size=col_blk_size)
1204 END IF
1205
1206 ithread = 0
1207!$ ithread = omp_get_thread_num()
1208 work => workt(:, :, ithread)
1209 hab => habt(:, :, ithread)
1210 hab(:, :) = 0._dp
1211
1212 iset_old = -1; jset_old = -1
1213 ikind_old = -1; jkind_old = -1
1214
1215 ! Here we loop over gridlevels first, finalising the matrix after each grid level is
1216 ! completed. On each grid level, we loop over atom pairs, which will only access
1217 ! a single block of each matrix, so with OpenMP, each matrix block is only touched
1218 ! by a single thread for each grid level
1219 loop_gridlevels: DO igrid_level = 1, gridlevel_info%ngrid_levels
1220 IF (.NOT. ALLOCATED(h_buffer)) THEN
1221 DO idir = 1, 3
1222 CALL dbcsr_work_create(hmat(idir)%matrix, work_mutable=.true., n=nthread)
1223 CALL dbcsr_get_info(hmat(idir)%matrix, distribution=dist)
1224 CALL dbcsr_distribution_get(dist, has_threads=has_threads)
1225!$ IF (.NOT. has_threads) &
1226!$ CPABORT("No thread distribution defined.")
1227 END DO
1228 END IF
1229
1230 loop_pairs: DO ipair = 1, task_list%npairs(igrid_level)
1231 loop_tasks: DO itask = task_list%taskstart(ipair, igrid_level), task_list%taskstop(ipair, igrid_level)
1232 ilevel = tasks(itask)%grid_level
1233 img = tasks(itask)%image
1234 iatom = tasks(itask)%iatom
1235 jatom = tasks(itask)%jatom
1236 iset = tasks(itask)%iset
1237 jset = tasks(itask)%jset
1238 ipgf = tasks(itask)%ipgf
1239 jpgf = tasks(itask)%jpgf
1240 cpassert(img == 1)
1241
1242 ! At the start of a block of tasks, get atom data (and kind data, if needed)
1243 IF (itask == task_list%taskstart(ipair, igrid_level)) THEN
1244
1245 ikind = particle_set(iatom)%atomic_kind%kind_number
1246 jkind = particle_set(jatom)%atomic_kind%kind_number
1247
1248 IF (iatom <= jatom) THEN
1249 brow = iatom
1250 bcol = jatom
1251 ELSE
1252 brow = jatom
1253 bcol = iatom
1254 END IF
1255
1256 IF (ikind /= ikind_old) THEN
1257 CALL get_qs_kind(qs_kind_set(ikind), &
1258 basis_set=orb_basis_set, basis_type=my_basis_type)
1259
1260 CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
1261 first_sgf=first_sgfa, &
1262 lmax=la_max, &
1263 lmin=la_min, &
1264 npgf=npgfa, &
1265 nset=nseta, &
1266 nsgf_set=nsgfa, &
1267 set_radius=set_radius_a, &
1268 sphi=sphi_a, &
1269 zet=zeta)
1270 END IF
1271
1272 IF (jkind /= jkind_old) THEN
1273 CALL get_qs_kind(qs_kind_set(jkind), &
1274 basis_set=orb_basis_set, basis_type=my_basis_type)
1275 CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
1276 first_sgf=first_sgfb, &
1277 lmax=lb_max, &
1278 lmin=lb_min, &
1279 npgf=npgfb, &
1280 nset=nsetb, &
1281 nsgf_set=nsgfb, &
1282 set_radius=set_radius_b, &
1283 sphi=sphi_b, &
1284 zet=zetb)
1285
1286 END IF
1287
1288 DO idir = 1, 3
1289 NULLIFY (h_block(idir)%block)
1290 IF (ALLOCATED(h_buffer)) THEN
1291 offset = task_list%pair_offsets_recv(tasks(itask)%pair_index)
1292 h_block(idir)%block(1:row_blk_size(brow), 1:col_blk_size(bcol)) => &
1293 h_buffer(offset + 1:offset + row_blk_size(brow)*col_blk_size(bcol), idir)
1294 ELSE
1295 CALL dbcsr_get_block_p(hmat(idir)%matrix, brow, bcol, h_block(idir)%block, found)
1296 cpassert(found)
1297 END IF
1298 END DO
1299
1300 ikind_old = ikind
1301 jkind_old = jkind
1302
1303 atom_pair_changed = .true.
1304
1305 ELSE
1306
1307 atom_pair_changed = .false.
1308
1309 END IF
1310
1311 IF (atom_pair_changed .OR. iset_old /= iset .OR. jset_old /= jset) THEN
1312 ! We reuse the hab(:, :) array to put the new integrals in.
1313
1314 ncoa = npgfa(iset)*ncoset(la_max(iset))
1315 ncoa_full = npgfa(iset)*ncoset(la_max(iset) + 1)
1316 sgfa = first_sgfa(1, iset)
1317 ncob = npgfb(jset)*ncoset(lb_max(jset))
1318 ncob_full = npgfb(jset)*ncoset(lb_max(jset) + 1)
1319 sgfb = first_sgfb(1, jset)
1320
1321 IF (iatom <= jatom) THEN
1322 hab(1:ncoa_full, 1:ncob_full) = 0._dp
1323 ELSE
1324 hab(1:ncob_full, 1:ncoa_full) = 0._dp
1325 END IF
1326
1327 iset_old = iset
1328 jset_old = jset
1329
1330 END IF
1331
1332 rab = tasks(itask)%rab
1333 ! With and without MIC, rab(:) is the vector giving us the coordinates of rb.
1334 ra = pbc(particle_set(iatom)%r(:), cell)
1335 rb(:) = ra(:) + rab(:)
1336 rac = pbc(rc, ra, cell)
1337 rbc = rac + rab
1338
1339 zetp = zeta(ipgf, iset) + zetb(jpgf, jset)
1340 f = zetb(jpgf, jset)/zetp
1341 rp(:) = ra(:) + f*rab(:)
1342
1343 prefactor = exp(-zeta(ipgf, iset)*f*dot_product(rab, rab))
1344 radius = exp_radius_very_extended(la_min=la_min(iset), la_max=la_max(iset), &
1345 lb_min=lb_min(jset), lb_max=lb_max(jset), &
1346 ra=ra, rb=rb, rp=rp, &
1347 zetp=zetp, eps=eps_rho_rspace, &
1348 prefactor=prefactor, cutoff=1.0_dp)
1349
1350 na1 = (ipgf - 1)*ncoset(la_max(iset) + 1) + 1
1351 na2 = ipgf*ncoset(la_max(iset) + 1)
1352 nb1 = (jpgf - 1)*ncoset(lb_max(jset) + 1) + 1
1353 nb2 = jpgf*ncoset(lb_max(jset) + 1)
1354
1355 IF (iatom <= jatom) THEN
1356 CALL integrate_pgf_product( &
1357 la_max(iset) + 1, zeta(ipgf, iset), la_min(iset), &
1358 lb_max(jset) + 1, zetb(jpgf, jset), lb_min(jset), &
1359 ra, rab, rs_v(igrid_level), &
1360 hab, o1=na1 - 1, o2=nb1 - 1, &
1361 radius=radius, &
1362 calculate_forces=.false.)
1363 ELSE
1364 rab_inv = -rab
1365 CALL integrate_pgf_product( &
1366 lb_max(jset) + 1, zetb(jpgf, jset), lb_min(jset), &
1367 la_max(iset) + 1, zeta(ipgf, iset), la_min(iset), &
1368 rb, rab_inv, rs_v(igrid_level), &
1369 hab, o1=nb1 - 1, o2=na1 - 1, &
1370 radius=radius, &
1371 calculate_forces=.false.)
1372 END IF
1373
1374 new_set_pair_coming = .false.
1375 atom_pair_done = .false.
1376 IF (itask < task_list%taskstop(ipair, igrid_level)) THEN
1377 ilevel = tasks(itask + 1)%grid_level
1378 img = tasks(itask + 1)%image
1379 iatom = tasks(itask + 1)%iatom
1380 jatom = tasks(itask + 1)%jatom
1381 iset_new = tasks(itask + 1)%iset
1382 jset_new = tasks(itask + 1)%jset
1383 ipgf_new = tasks(itask + 1)%ipgf
1384 jpgf_new = tasks(itask + 1)%jpgf
1385 IF (iset_new /= iset .OR. jset_new /= jset) THEN
1386 new_set_pair_coming = .true.
1387 END IF
1388 ELSE
1389 ! do not forget the last block
1390 new_set_pair_coming = .true.
1391 atom_pair_done = .true.
1392 END IF
1393
1394 IF (new_set_pair_coming) THEN
1395 ! Increase lx, ly, lz by one to account for the | r * b >
1396 IF (iatom <= jatom) THEN
1397 CALL apply_cartesian_operator(la_max(iset), 0, npgfa(iset), lb_max(jset), 0, npgfb(jset), &
1398 hab, rhab, right=.false., derivative=.false., origin=rac)
1399
1400 ELSE
1401 CALL apply_cartesian_operator(lb_max(jset), 0, npgfb(jset), la_max(iset), 0, npgfa(iset), &
1402 hab, rhab, right=.true., derivative=.false., origin=rac)
1403 END IF
1404
1405 ! contract the block into h if we're done with the current set pair
1406 DO idir = 1, 3
1407 IF (iatom <= jatom) THEN
1408 work = 0._dp
1409 work(1:ncoa, 1:nsgfb(jset)) = matmul(rhab(1:ncoa, 1:ncob, idir), sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
1410 h_block(idir)%block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
1411 h_block(idir)%block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
1412 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
1413 ELSE
1414 work(1:ncob, 1:nsgfa(iset)) = matmul(rhab(1:ncob, 1:ncoa, idir), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
1415 h_block(idir)%block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
1416 h_block(idir)%block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
1417 matmul(transpose(sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1)), work(1:ncob, 1:nsgfa(iset)))
1418 END IF
1419 END DO
1420 END IF
1421
1422 END DO loop_tasks
1423 END DO loop_pairs
1424
1425 IF (.NOT. ALLOCATED(h_buffer)) THEN
1426 DO idir = 1, 3
1427 CALL dbcsr_finalize(hmat(idir)%matrix)
1428 END DO
1429 END IF
1430
1431 END DO loop_gridlevels
1432
1433 IF (ALLOCATED(h_buffer)) THEN
1434 DO idir = 1, 3
1435 task_list%hab_buffer%host_buffer(:) = h_buffer(:, idir)
1436 matrix_image(1)%matrix => hmat(idir)%matrix
1437 CALL rs_gather_matrices(task_list%hab_buffer, matrix_image, task_list, group)
1438 END DO
1439 END IF
1440
1441 ! *** Release work storage ***
1442 DEALLOCATE (habt, rhab, workt, h_block)
1443
1444 CALL timestop(handle)
1445
1446 END SUBROUTINE integrate_rv_rspace
1447
1448! **************************************************************************************************
1449!> \brief Builds the overlap derivative wrt nuclear velocities
1450!> dS/dV = < mu | r | nu > * (nu - mu)
1451!> \param qs_env ...
1452!> \param matrix_dsdv ...
1453!> \param deltaR ...
1454!> \param rcc ...
1455!> \author Edward Ditler
1456! **************************************************************************************************
1457 SUBROUTINE build_dsdv_matrix(qs_env, matrix_dsdv, deltaR, rcc)
1458 TYPE(qs_environment_type), POINTER :: qs_env
1459 TYPE(dbcsr_p_type), DIMENSION(:) :: matrix_dsdv
1460 REAL(kind=dp), DIMENSION(:, :) :: deltar
1461 REAL(kind=dp), DIMENSION(3) :: rcc
1462
1463 CHARACTER(len=*), PARAMETER :: routinen = 'build_dSdV_matrix'
1464
1465 INTEGER :: handle, i
1466 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, my_matrix_dsdv, &
1467 my_matrix_dsdv2, my_matrix_mom
1468 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
1469 POINTER :: sab_all
1470 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1471
1472 CALL timeset(routinen, handle)
1473
1474 NULLIFY (my_matrix_mom, my_matrix_dsdv, my_matrix_dsdv2, sab_all, qs_kind_set)
1475
1476 CALL get_qs_env(qs_env=qs_env, &
1477 sab_all=sab_all, &
1478 qs_kind_set=qs_kind_set, &
1479 matrix_ks=matrix_ks)
1480
1481 ! my_matrix_mom is needed because build_local_moment only works correctly with symmetric matrices
1482 CALL dbcsr_allocate_matrix_set(my_matrix_dsdv, 3)
1483 CALL dbcsr_allocate_matrix_set(my_matrix_dsdv2, 3)
1484 CALL dbcsr_allocate_matrix_set(my_matrix_mom, 3)
1485
1486 DO i = 1, 3
1487 ALLOCATE (my_matrix_dsdv(i)%matrix)
1488 ALLOCATE (my_matrix_dsdv2(i)%matrix)
1489 ALLOCATE (my_matrix_mom(i)%matrix)
1490
1491 CALL dbcsr_copy(my_matrix_dsdv(i)%matrix, matrix_dsdv(i)%matrix)
1492 CALL dbcsr_copy(my_matrix_dsdv2(i)%matrix, matrix_dsdv(i)%matrix)
1493 CALL dbcsr_copy(my_matrix_mom(i)%matrix, matrix_ks(1)%matrix)
1494
1495 CALL dbcsr_set(my_matrix_dsdv2(i)%matrix, 0.0_dp)
1496 CALL dbcsr_set(my_matrix_dsdv(i)%matrix, 0.0_dp)
1497 CALL dbcsr_set(my_matrix_mom(i)%matrix, 0.0_dp)
1498 CALL dbcsr_set(matrix_dsdv(i)%matrix, 0.0_dp)
1499 END DO
1500
1501 CALL build_local_moment_matrix(qs_env, my_matrix_mom, 1, ref_point=rcc, &
1502 neighbor_image=.true.)
1503
1504 DO i = 1, 3
1505 CALL dbcsr_desymmetrize(my_matrix_mom(i)%matrix, my_matrix_dsdv(i)%matrix)
1506 CALL dbcsr_copy(my_matrix_dsdv2(i)%matrix, my_matrix_dsdv(i)%matrix)
1507 END DO
1508
1509 ! delta_nu^A <mu|r|nu>
1510 CALL hr_mult_by_delta_3d(my_matrix_dsdv, qs_kind_set, "ORB", sab_all, &
1511 deltar, direction_or=.true.)
1512 ! -delta_mu^A <mu|r|nu>
1513 CALL hr_mult_by_delta_3d(my_matrix_dsdv2, qs_kind_set, "ORB", sab_all, &
1514 deltar, direction_or=.false.)
1515 DO i = 1, 3
1516 CALL dbcsr_copy(matrix_dsdv(i)%matrix, my_matrix_dsdv(i)%matrix)
1517 CALL dbcsr_add(matrix_dsdv(i)%matrix, my_matrix_dsdv2(i)%matrix, 1.0_dp, -1.0_dp)
1518 END DO
1519
1520 CALL dbcsr_deallocate_matrix_set(my_matrix_dsdv)
1521 CALL dbcsr_deallocate_matrix_set(my_matrix_dsdv2)
1522 CALL dbcsr_deallocate_matrix_set(my_matrix_mom)
1523
1524 CALL timestop(handle)
1525
1526 END SUBROUTINE build_dsdv_matrix
1527
1528! **************************************************************************************************
1529!> \brief Build the two ordered nonlocal second-position products.
1530!> \param matrix_rcomr ...
1531!> \param matrix_rrcom ...
1532!> \param qs_kind_set ...
1533!> \param sab_all ...
1534!> \param sap_ppnl ...
1535!> \param eps_ppnl ...
1536!> \param particle_set ...
1537!> \param cell ...
1538!> \author Edward Ditler, Tomas Zimmermann
1539! **************************************************************************************************
1540 SUBROUTINE build_com_rpnl_r(matrix_rcomr, matrix_rrcom, qs_kind_set, sab_all, sap_ppnl, eps_ppnl, &
1541 particle_set, cell)
1542
1543 TYPE(dbcsr_p_type), DIMENSION(:, :) :: matrix_rcomr, matrix_rrcom
1544 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1545 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
1546 POINTER :: sab_all, sap_ppnl
1547 REAL(kind=dp), INTENT(IN) :: eps_ppnl
1548 TYPE(particle_type), DIMENSION(:), INTENT(IN), &
1549 POINTER :: particle_set
1550 TYPE(cell_type), POINTER :: cell
1551
1552 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_com_rpnl_r'
1553
1554 INTEGER :: handle, i, iab, iac, iatom, ibc, icol, &
1555 ikind, irow, j, jatom, jkind, kac, &
1556 kbc, kkind, na, natom, nb, nkind, np, &
1557 slot
1558 INTEGER, DIMENSION(3) :: cell_b
1559 LOGICAL :: found, ppnl_present
1560 REAL(kind=dp), DIMENSION(3) :: rab
1561 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: achint, acint, bchint, bcint
1562 TYPE(alist_type), POINTER :: alist_ac, alist_bc
1563 TYPE(block_p_type), DIMENSION(3, 3, 2) :: blocks_rvr
1564 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set
1565 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
1566 TYPE(sap_int_type), DIMENSION(:), POINTER :: sap_int
1567
1568!$ INTEGER(kind=omp_lock_kind), &
1569!$ ALLOCATABLE, DIMENSION(:) :: locks
1570!$ INTEGER :: lock_num, hash
1571!$ INTEGER, PARAMETER :: nlock = 501
1572
1573 ppnl_present = ASSOCIATED(sap_ppnl)
1574 IF (.NOT. ppnl_present) RETURN
1575
1576 CALL timeset(routinen, handle)
1577 nkind = SIZE(qs_kind_set)
1578 natom = SIZE(particle_set)
1579
1580 ! sap_int needs to be shared as multiple threads need to access this
1581 NULLIFY (sap_int)
1582 ALLOCATE (sap_int(nkind*nkind))
1583 DO i = 1, nkind*nkind
1584 NULLIFY (sap_int(i)%alist, sap_int(i)%asort, sap_int(i)%aindex)
1585 sap_int(i)%nalist = 0
1586 END DO
1587
1588 ! We put zero as a reference point, because actually in the integrals we need two different ones:
1589 ! < a | (r - R^\lambda_\beta) * [V, r_\alpha - R^\eta_\alpha] | b >
1590 ! The first reference point can be added in a seperate step as the term will be
1591 ! - R^\lambda_\beta * < a | [V, r_\alpha] | b >
1592 ! = + R^\lambda_\beta * < a | [r_\alpha, V] | b >
1593 ! The second reference point is not important, because it disappears in the commutator
1594 CALL build_sap_ints(sap_int, sap_ppnl, qs_kind_set, nder=2, moment_mode=.true., &
1595 particle_set=particle_set, cell=cell, refpoint=[0._dp, 0._dp, 0._dp])
1596
1597 ! *** Set up a sorting index
1598 CALL sap_sort(sap_int)
1599
1600 ALLOCATE (basis_set(nkind))
1601 DO ikind = 1, nkind
1602 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set)
1603 IF (ASSOCIATED(orb_basis_set)) THEN
1604 basis_set(ikind)%gto_basis_set => orb_basis_set
1605 ELSE
1606 NULLIFY (basis_set(ikind)%gto_basis_set)
1607 END IF
1608 END DO
1609
1610 ! *** All integrals needed have been calculated and stored in sap_int
1611 ! *** We now calculate the ordered second-position product matrix elements
1612
1613!$OMP PARALLEL &
1614!$OMP DEFAULT (NONE) &
1615!$OMP SHARED (basis_set, matrix_rcomr, matrix_rrcom, &
1616!$OMP sap_int, nkind, eps_ppnl, locks, sab_all) &
1617!$OMP PRIVATE (ikind, jkind, iatom, jatom, cell_b, rab, &
1618!$OMP iab, irow, icol, blocks_rvr, lock_num, &
1619!$OMP found, iac, ibc, alist_ac, alist_bc, &
1620!$OMP na, np, nb, kkind, kac, kbc, i, j, &
1621!$OMP hash, natom, acint, bcint, achint, bchint)
1622
1623!$OMP SINGLE
1624!$ ALLOCATE (locks(nlock))
1625!$OMP END SINGLE
1626
1627!$OMP DO
1628!$ DO lock_num = 1, nlock
1629!$ call omp_init_lock(locks(lock_num))
1630!$ END DO
1631!$OMP END DO
1632
1633!$OMP DO SCHEDULE(GUIDED)
1634
1635 DO slot = 1, sab_all(1)%nl_size
1636
1637 ikind = sab_all(1)%nlist_task(slot)%ikind
1638 jkind = sab_all(1)%nlist_task(slot)%jkind
1639 iatom = sab_all(1)%nlist_task(slot)%iatom
1640 jatom = sab_all(1)%nlist_task(slot)%jatom
1641 cell_b(:) = sab_all(1)%nlist_task(slot)%cell(:)
1642 rab(1:3) = sab_all(1)%nlist_task(slot)%r(1:3)
1643
1644 IF (.NOT. ASSOCIATED(basis_set(ikind)%gto_basis_set)) cycle
1645 IF (.NOT. ASSOCIATED(basis_set(jkind)%gto_basis_set)) cycle
1646 iab = ikind + nkind*(jkind - 1)
1647
1648 ! *** Create matrix blocks for a new matrix block column ***
1649 irow = iatom
1650 icol = jatom
1651 DO i = 1, 3
1652 DO j = 1, 3
1653 ! t_alpha = MOD(i - 1, 3) + 1
1654 ! t_beta = FLOOR(REAL(i - 1, dp)/3._dp) + 1
1655
1656 CALL dbcsr_get_block_p(matrix_rcomr(i, j)%matrix, irow, icol, blocks_rvr(i, j, 1)%block, found)
1657 cpassert(found)
1658 CALL dbcsr_get_block_p(matrix_rrcom(i, j)%matrix, irow, icol, blocks_rvr(i, j, 2)%block, found)
1659 cpassert(found)
1660 END DO
1661 END DO
1662
1663 ! loop over all kinds for projector atom
1664 DO kkind = 1, nkind
1665 iac = ikind + nkind*(kkind - 1)
1666 ibc = jkind + nkind*(kkind - 1)
1667 IF (.NOT. ASSOCIATED(sap_int(iac)%alist)) cycle
1668 IF (.NOT. ASSOCIATED(sap_int(ibc)%alist)) cycle
1669 CALL get_alist(sap_int(iac), alist_ac, iatom)
1670 CALL get_alist(sap_int(ibc), alist_bc, jatom)
1671 IF (.NOT. ASSOCIATED(alist_ac)) cycle
1672 IF (.NOT. ASSOCIATED(alist_bc)) cycle
1673 DO kac = 1, alist_ac%nclist
1674 DO kbc = 1, alist_bc%nclist
1675 IF (alist_ac%clist(kac)%catom /= alist_bc%clist(kbc)%catom) cycle
1676
1677 ! Some documention, considering the C1 O1 O2 molecule
1678 ! The integrals are <a|p>
1679 ! sap_int(1:2, 1:2) -> [(a=C, p=C), (a=C, p=O), (a=O, p=C), (a=O, p=0)]
1680 ! the (a=O, p=C) entry has an alist
1681 ! alist has two elements: O1, O2
1682 ! alist(O1) -> clist(C1)%acint are the integrals
1683 ! alist(O2) -> clist(C1)%acint are the integrals
1684
1685 IF (all(cell_b + alist_bc%clist(kbc)%cell - alist_ac%clist(kac)%cell == 0)) THEN
1686 IF (alist_ac%clist(kac)%maxac*alist_bc%clist(kbc)%maxach < eps_ppnl) cycle
1687 acint => alist_ac%clist(kac)%acint
1688 bcint => alist_bc%clist(kbc)%acint
1689 achint => alist_ac%clist(kac)%achint
1690 bchint => alist_bc%clist(kbc)%achint
1691 na = SIZE(acint, 1)
1692 np = SIZE(acint, 2)
1693 nb = SIZE(bcint, 1)
1694!$ hash = MOD((iatom - 1)*natom + jatom, nlock) + 1
1695!$ CALL omp_set_lock(locks(hash))
1696
1697 DO i = 1, 3
1698 DO j = 1, 3
1699 ! matrix_rcomr(i, j) = (Vnl*r_i)*r_j - (r_i*Vnl)*r_j
1700 blocks_rvr(i, j, 1)%block(1:na, 1:nb) = blocks_rvr(i, j, 1)%block(1:na, 1:nb) + &
1701 matmul(achint(1:na, 1:np, bi_1), transpose(bcint(1:nb, 1:np, bi_rr(i, j)))) - &
1702 matmul(achint(1:na, 1:np, bi_r(i)), transpose(bcint(1:nb, 1:np, bi_r(j))))
1703
1704 ! matrix_rrcom(i, j) = r_j*(Vnl*r_i) - r_j*(r_i*Vnl)
1705 blocks_rvr(i, j, 2)%block(1:na, 1:nb) = blocks_rvr(i, j, 2)%block(1:na, 1:nb) + &
1706 matmul(achint(1:na, 1:np, bi_r(j)), transpose(bcint(1:nb, 1:np, bi_r(i)))) - &
1707 matmul(achint(1:na, 1:np, bi_rr(i, j)), transpose(bcint(1:nb, 1:np, bi_1)))
1708 END DO
1709 END DO
1710
1711!$ CALL omp_unset_lock(locks(hash))
1712 EXIT ! We have found a match and there can be only one single match
1713 END IF
1714 END DO
1715 END DO
1716 END DO
1717 DO i = 1, 3
1718 DO j = 1, 3
1719 NULLIFY (blocks_rvr(i, j, 1)%block)
1720 NULLIFY (blocks_rvr(i, j, 2)%block)
1721 END DO
1722 END DO
1723 END DO
1724
1725!$OMP DO
1726!$ DO lock_num = 1, nlock
1727!$ call omp_destroy_lock(locks(lock_num))
1728!$ END DO
1729!$OMP END DO
1730
1731!$OMP SINGLE
1732!$ DEALLOCATE (locks)
1733!$OMP END SINGLE NOWAIT
1734
1735!$OMP END PARALLEL
1736
1737 CALL release_sap_int(sap_int)
1738
1739 DEALLOCATE (basis_set)
1740
1741 CALL timestop(handle)
1742
1743 END SUBROUTINE build_com_rpnl_r
1744
1745! **************************************************************************************************
1746!> \brief Calculate the double commutator [[Vnl, r], r]
1747!> \param matrix_rv ...
1748!> \param qs_kind_set ...
1749!> \param sab_orb ...
1750!> \param sap_ppnl ...
1751!> \param eps_ppnl ...
1752!> \param particle_set ...
1753!> \param pseudoatom Only consider pseudopotentials on atom lambda
1754!> \author Edward Ditler
1755! **************************************************************************************************
1756 SUBROUTINE build_dcom_rpnl(matrix_rv, qs_kind_set, sab_orb, sap_ppnl, eps_ppnl, particle_set, pseudoatom)
1757
1758 TYPE(dbcsr_p_type), DIMENSION(:, :) :: matrix_rv
1759 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1760 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
1761 POINTER :: sab_orb, sap_ppnl
1762 REAL(kind=dp), INTENT(IN) :: eps_ppnl
1763 TYPE(particle_type), DIMENSION(:), INTENT(IN), &
1764 POINTER :: particle_set
1765 INTEGER, INTENT(IN) :: pseudoatom
1766
1767 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_dcom_rpnl'
1768
1769 INTEGER :: handle, i, iab, iac, iatom, ibc, icol, &
1770 ikind, irow, j, jatom, jkind, kac, &
1771 kbc, kkind, na, natom, nb, nkind, np, &
1772 slot
1773 INTEGER, DIMENSION(3) :: cell_b
1774 LOGICAL :: found, ppnl_present
1775 REAL(kind=dp), DIMENSION(3) :: rab
1776 REAL(kind=dp), DIMENSION(:, :, :), POINTER :: achint, acint, bchint, bcint
1777 TYPE(alist_type), POINTER :: alist_ac, alist_bc
1778 TYPE(block_p_type), DIMENSION(3, 3) :: blocks_rv
1779 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set
1780 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
1781 TYPE(sap_int_type), DIMENSION(:), POINTER :: sap_int
1782
1783!$ INTEGER(kind=omp_lock_kind), &
1784!$ ALLOCATABLE, DIMENSION(:) :: locks
1785!$ INTEGER :: lock_num, hash
1786!$ INTEGER, PARAMETER :: nlock = 501
1787
1788 ppnl_present = ASSOCIATED(sap_ppnl)
1789 IF (.NOT. ppnl_present) RETURN
1790
1791 CALL timeset(routinen, handle)
1792 nkind = SIZE(qs_kind_set)
1793 natom = SIZE(particle_set)
1794
1795 ! sap_int needs to be shared as multiple threads need to access this
1796 NULLIFY (sap_int)
1797 ALLOCATE (sap_int(nkind*nkind))
1798 DO i = 1, nkind*nkind
1799 NULLIFY (sap_int(i)%alist, sap_int(i)%asort, sap_int(i)%aindex)
1800 sap_int(i)%nalist = 0
1801 END DO
1802
1803 ! "nder" in moment_mode is "order"
1804 CALL build_sap_ints(sap_int, sap_ppnl, qs_kind_set, nder=2, moment_mode=.true., &
1805 particle_set=particle_set, pseudoatom=pseudoatom)
1806
1807 ! *** Set up a sorting index
1808 CALL sap_sort(sap_int)
1809
1810 ALLOCATE (basis_set(nkind))
1811 DO ikind = 1, nkind
1812 CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set)
1813 IF (ASSOCIATED(orb_basis_set)) THEN
1814 basis_set(ikind)%gto_basis_set => orb_basis_set
1815 ELSE
1816 NULLIFY (basis_set(ikind)%gto_basis_set)
1817 END IF
1818 END DO
1819
1820 ! *** All integrals needed have been calculated and stored in sap_int
1821 ! *** We now calculate the commutator matrix elements
1822
1823!$OMP PARALLEL &
1824!$OMP DEFAULT (NONE) &
1825!$OMP SHARED (basis_set, matrix_rv, &
1826!$OMP sap_int, nkind, eps_ppnl, locks, sab_orb) &
1827!$OMP PRIVATE (ikind, jkind, iatom, jatom, cell_b, rab, &
1828!$OMP iab, irow, icol, blocks_rv, lock_num, &
1829!$OMP found, iac, ibc, alist_ac, alist_bc, &
1830!$OMP na, np, nb, kkind, kac, kbc, i, j, &
1831!$OMP hash, natom, acint, bcint, achint, bchint)
1832
1833!$OMP SINGLE
1834!$ ALLOCATE (locks(nlock))
1835!$OMP END SINGLE
1836
1837!$OMP DO
1838!$ DO lock_num = 1, nlock
1839!$ call omp_init_lock(locks(lock_num))
1840!$ END DO
1841!$OMP END DO
1842
1843!$OMP DO SCHEDULE(GUIDED)
1844
1845 DO slot = 1, sab_orb(1)%nl_size
1846
1847 ikind = sab_orb(1)%nlist_task(slot)%ikind
1848 jkind = sab_orb(1)%nlist_task(slot)%jkind
1849 iatom = sab_orb(1)%nlist_task(slot)%iatom
1850 jatom = sab_orb(1)%nlist_task(slot)%jatom
1851 cell_b(:) = sab_orb(1)%nlist_task(slot)%cell(:)
1852 rab(1:3) = sab_orb(1)%nlist_task(slot)%r(1:3)
1853
1854 IF (.NOT. ASSOCIATED(basis_set(ikind)%gto_basis_set)) cycle
1855 IF (.NOT. ASSOCIATED(basis_set(jkind)%gto_basis_set)) cycle
1856 iab = ikind + nkind*(jkind - 1)
1857
1858 ! *** Create matrix blocks for a new matrix block column ***
1859 IF (iatom <= jatom) THEN
1860 irow = iatom
1861 icol = jatom
1862 ELSE
1863 irow = jatom
1864 icol = iatom
1865 END IF
1866
1867 DO i = 1, 3
1868 DO j = 1, 3
1869 CALL dbcsr_get_block_p(matrix_rv(i, j)%matrix, irow, icol, blocks_rv(i, j)%block, found)
1870 blocks_rv(i, j)%block = 0._dp
1871 cpassert(found)
1872 END DO
1873 END DO
1874
1875 ! loop over all kinds for projector atom
1876 DO kkind = 1, nkind
1877 iac = ikind + nkind*(kkind - 1)
1878 ibc = jkind + nkind*(kkind - 1)
1879 IF (.NOT. ASSOCIATED(sap_int(iac)%alist)) cycle
1880 IF (.NOT. ASSOCIATED(sap_int(ibc)%alist)) cycle
1881 CALL get_alist(sap_int(iac), alist_ac, iatom)
1882 CALL get_alist(sap_int(ibc), alist_bc, jatom)
1883 IF (.NOT. ASSOCIATED(alist_ac)) cycle
1884 IF (.NOT. ASSOCIATED(alist_bc)) cycle
1885 DO kac = 1, alist_ac%nclist
1886 DO kbc = 1, alist_bc%nclist
1887 IF (alist_ac%clist(kac)%catom /= alist_bc%clist(kbc)%catom) cycle
1888 IF (all(cell_b + alist_bc%clist(kbc)%cell - alist_ac%clist(kac)%cell == 0)) THEN
1889 IF (alist_ac%clist(kac)%maxac*alist_bc%clist(kbc)%maxach < eps_ppnl) cycle
1890 acint => alist_ac%clist(kac)%acint
1891 bcint => alist_bc%clist(kbc)%acint
1892 achint => alist_ac%clist(kac)%achint
1893 bchint => alist_bc%clist(kbc)%achint
1894 na = SIZE(acint, 1)
1895 np = SIZE(acint, 2)
1896 nb = SIZE(bcint, 1)
1897!$ hash = MOD((iatom - 1)*natom + jatom, nlock) + 1
1898!$ CALL omp_set_lock(locks(hash))
1899 ! Template:
1900 ! blocks_rv(1)%block(1:na, 1:nb) = blocks_rv(1)%block(1:na, 1:nb) + &
1901 ! MATMUL(achint(1:na, 1:np, 2), TRANSPOSE(bcint(1:nb, 1:np, 1))) ! xV
1902 IF (iatom <= jatom) THEN
1903 ! r_alpha*Vnl*r_beta
1904 blocks_rv(1, 1)%block(1:na, 1:nb) = blocks_rv(1, 1)%block(1:na, 1:nb) + &
1905 matmul(achint(1:na, 1:np, bi_x), transpose(bcint(1:nb, 1:np, bi_x)))
1906
1907 blocks_rv(1, 2)%block(1:na, 1:nb) = blocks_rv(1, 2)%block(1:na, 1:nb) + &
1908 matmul(achint(1:na, 1:np, bi_x), transpose(bcint(1:nb, 1:np, bi_y)))
1909
1910 blocks_rv(1, 3)%block(1:na, 1:nb) = blocks_rv(1, 3)%block(1:na, 1:nb) + &
1911 matmul(achint(1:na, 1:np, bi_x), transpose(bcint(1:nb, 1:np, bi_z)))
1912
1913 blocks_rv(2, 1)%block(1:na, 1:nb) = blocks_rv(2, 1)%block(1:na, 1:nb) + &
1914 matmul(achint(1:na, 1:np, bi_y), transpose(bcint(1:nb, 1:np, bi_x)))
1915
1916 blocks_rv(2, 2)%block(1:na, 1:nb) = blocks_rv(2, 2)%block(1:na, 1:nb) + &
1917 matmul(achint(1:na, 1:np, bi_y), transpose(bcint(1:nb, 1:np, bi_y)))
1918
1919 blocks_rv(2, 3)%block(1:na, 1:nb) = blocks_rv(2, 3)%block(1:na, 1:nb) + &
1920 matmul(achint(1:na, 1:np, bi_y), transpose(bcint(1:nb, 1:np, bi_z)))
1921
1922 blocks_rv(3, 1)%block(1:na, 1:nb) = blocks_rv(3, 1)%block(1:na, 1:nb) + &
1923 matmul(achint(1:na, 1:np, bi_z), transpose(bcint(1:nb, 1:np, bi_x)))
1924
1925 blocks_rv(3, 2)%block(1:na, 1:nb) = blocks_rv(3, 2)%block(1:na, 1:nb) + &
1926 matmul(achint(1:na, 1:np, bi_z), transpose(bcint(1:nb, 1:np, bi_y)))
1927
1928 blocks_rv(3, 3)%block(1:na, 1:nb) = blocks_rv(3, 3)%block(1:na, 1:nb) + &
1929 matmul(achint(1:na, 1:np, bi_z), transpose(bcint(1:nb, 1:np, bi_z)))
1930
1931 ! -r_alpha*r_beta*Vnl
1932 blocks_rv(1, 1)%block(1:na, 1:nb) = blocks_rv(1, 1)%block(1:na, 1:nb) - &
1933 matmul(achint(1:na, 1:np, bi_xx), transpose(bcint(1:nb, 1:np, bi_1)))
1934
1935 blocks_rv(1, 2)%block(1:na, 1:nb) = blocks_rv(1, 2)%block(1:na, 1:nb) - &
1936 matmul(achint(1:na, 1:np, bi_xy), transpose(bcint(1:nb, 1:np, bi_1)))
1937
1938 blocks_rv(1, 3)%block(1:na, 1:nb) = blocks_rv(1, 3)%block(1:na, 1:nb) - &
1939 matmul(achint(1:na, 1:np, bi_xz), transpose(bcint(1:nb, 1:np, bi_1)))
1940
1941 blocks_rv(2, 1)%block(1:na, 1:nb) = blocks_rv(2, 1)%block(1:na, 1:nb) - &
1942 matmul(achint(1:na, 1:np, bi_xy), transpose(bcint(1:nb, 1:np, bi_1)))
1943
1944 blocks_rv(2, 2)%block(1:na, 1:nb) = blocks_rv(2, 2)%block(1:na, 1:nb) - &
1945 matmul(achint(1:na, 1:np, bi_yy), transpose(bcint(1:nb, 1:np, bi_1)))
1946
1947 blocks_rv(2, 3)%block(1:na, 1:nb) = blocks_rv(2, 3)%block(1:na, 1:nb) - &
1948 matmul(achint(1:na, 1:np, bi_yz), transpose(bcint(1:nb, 1:np, bi_1)))
1949
1950 blocks_rv(3, 1)%block(1:na, 1:nb) = blocks_rv(3, 1)%block(1:na, 1:nb) - &
1951 matmul(achint(1:na, 1:np, bi_xz), transpose(bcint(1:nb, 1:np, bi_1)))
1952
1953 blocks_rv(3, 2)%block(1:na, 1:nb) = blocks_rv(3, 2)%block(1:na, 1:nb) - &
1954 matmul(achint(1:na, 1:np, bi_yz), transpose(bcint(1:nb, 1:np, bi_1)))
1955
1956 blocks_rv(3, 3)%block(1:na, 1:nb) = blocks_rv(3, 3)%block(1:na, 1:nb) - &
1957 matmul(achint(1:na, 1:np, bi_zz), transpose(bcint(1:nb, 1:np, bi_1)))
1958
1959 ! -Vnl*r_beta*r_alpha
1960 blocks_rv(1, 1)%block(1:na, 1:nb) = blocks_rv(1, 1)%block(1:na, 1:nb) - &
1961 matmul(achint(1:na, 1:np, bi_1), transpose(bcint(1:nb, 1:np, bi_xx)))
1962
1963 blocks_rv(1, 2)%block(1:na, 1:nb) = blocks_rv(1, 2)%block(1:na, 1:nb) - &
1964 matmul(achint(1:na, 1:np, bi_1), transpose(bcint(1:nb, 1:np, bi_xy)))
1965
1966 blocks_rv(1, 3)%block(1:na, 1:nb) = blocks_rv(1, 3)%block(1:na, 1:nb) - &
1967 matmul(achint(1:na, 1:np, bi_1), transpose(bcint(1:nb, 1:np, bi_xz)))
1968
1969 blocks_rv(2, 1)%block(1:na, 1:nb) = blocks_rv(2, 1)%block(1:na, 1:nb) - &
1970 matmul(achint(1:na, 1:np, bi_1), transpose(bcint(1:nb, 1:np, bi_xy)))
1971
1972 blocks_rv(2, 2)%block(1:na, 1:nb) = blocks_rv(2, 2)%block(1:na, 1:nb) - &
1973 matmul(achint(1:na, 1:np, bi_1), transpose(bcint(1:nb, 1:np, bi_yy)))
1974
1975 blocks_rv(2, 3)%block(1:na, 1:nb) = blocks_rv(2, 3)%block(1:na, 1:nb) - &
1976 matmul(achint(1:na, 1:np, bi_1), transpose(bcint(1:nb, 1:np, bi_yz)))
1977
1978 blocks_rv(3, 1)%block(1:na, 1:nb) = blocks_rv(3, 1)%block(1:na, 1:nb) - &
1979 matmul(achint(1:na, 1:np, bi_1), transpose(bcint(1:nb, 1:np, bi_xz)))
1980
1981 blocks_rv(3, 2)%block(1:na, 1:nb) = blocks_rv(3, 2)%block(1:na, 1:nb) - &
1982 matmul(achint(1:na, 1:np, bi_1), transpose(bcint(1:nb, 1:np, bi_yz)))
1983
1984 blocks_rv(3, 3)%block(1:na, 1:nb) = blocks_rv(3, 3)%block(1:na, 1:nb) - &
1985 matmul(achint(1:na, 1:np, bi_1), transpose(bcint(1:nb, 1:np, bi_zz)))
1986
1987 ! +r_beta*Vnl*r_alpha
1988 blocks_rv(1, 1)%block(1:na, 1:nb) = blocks_rv(1, 1)%block(1:na, 1:nb) + &
1989 matmul(achint(1:na, 1:np, bi_x), transpose(bcint(1:nb, 1:np, bi_x)))
1990
1991 blocks_rv(1, 2)%block(1:na, 1:nb) = blocks_rv(1, 2)%block(1:na, 1:nb) + &
1992 matmul(achint(1:na, 1:np, bi_y), transpose(bcint(1:nb, 1:np, bi_x)))
1993
1994 blocks_rv(1, 3)%block(1:na, 1:nb) = blocks_rv(1, 3)%block(1:na, 1:nb) + &
1995 matmul(achint(1:na, 1:np, bi_z), transpose(bcint(1:nb, 1:np, bi_x)))
1996
1997 blocks_rv(2, 1)%block(1:na, 1:nb) = blocks_rv(2, 1)%block(1:na, 1:nb) + &
1998 matmul(achint(1:na, 1:np, bi_x), transpose(bcint(1:nb, 1:np, bi_y)))
1999
2000 blocks_rv(2, 2)%block(1:na, 1:nb) = blocks_rv(2, 2)%block(1:na, 1:nb) + &
2001 matmul(achint(1:na, 1:np, bi_y), transpose(bcint(1:nb, 1:np, bi_y)))
2002
2003 blocks_rv(2, 3)%block(1:na, 1:nb) = blocks_rv(2, 3)%block(1:na, 1:nb) + &
2004 matmul(achint(1:na, 1:np, bi_z), transpose(bcint(1:nb, 1:np, bi_y)))
2005
2006 blocks_rv(3, 1)%block(1:na, 1:nb) = blocks_rv(3, 1)%block(1:na, 1:nb) + &
2007 matmul(achint(1:na, 1:np, bi_x), transpose(bcint(1:nb, 1:np, bi_z)))
2008
2009 blocks_rv(3, 2)%block(1:na, 1:nb) = blocks_rv(3, 2)%block(1:na, 1:nb) + &
2010 matmul(achint(1:na, 1:np, bi_y), transpose(bcint(1:nb, 1:np, bi_z)))
2011
2012 blocks_rv(3, 3)%block(1:na, 1:nb) = blocks_rv(3, 3)%block(1:na, 1:nb) + &
2013 matmul(achint(1:na, 1:np, bi_z), transpose(bcint(1:nb, 1:np, bi_z)))
2014 ELSE
2015 ! r_alpha*Vnl*r_beta
2016 blocks_rv(1, 1)%block(1:nb, 1:na) = blocks_rv(1, 1)%block(1:nb, 1:na) + &
2017 matmul(bchint(1:nb, 1:np, bi_x), transpose(acint(1:na, 1:np, bi_x)))
2018
2019 blocks_rv(1, 2)%block(1:nb, 1:na) = blocks_rv(1, 2)%block(1:nb, 1:na) + &
2020 matmul(bchint(1:nb, 1:np, bi_x), transpose(acint(1:na, 1:np, bi_y)))
2021
2022 blocks_rv(1, 3)%block(1:nb, 1:na) = blocks_rv(1, 3)%block(1:nb, 1:na) + &
2023 matmul(bchint(1:nb, 1:np, bi_x), transpose(acint(1:na, 1:np, bi_z)))
2024
2025 blocks_rv(2, 1)%block(1:nb, 1:na) = blocks_rv(2, 1)%block(1:nb, 1:na) + &
2026 matmul(bchint(1:nb, 1:np, bi_y), transpose(acint(1:na, 1:np, bi_x)))
2027
2028 blocks_rv(2, 2)%block(1:nb, 1:na) = blocks_rv(2, 2)%block(1:nb, 1:na) + &
2029 matmul(bchint(1:nb, 1:np, bi_y), transpose(acint(1:na, 1:np, bi_y)))
2030
2031 blocks_rv(2, 3)%block(1:nb, 1:na) = blocks_rv(2, 3)%block(1:nb, 1:na) + &
2032 matmul(bchint(1:nb, 1:np, bi_y), transpose(acint(1:na, 1:np, bi_z)))
2033
2034 blocks_rv(3, 1)%block(1:nb, 1:na) = blocks_rv(3, 1)%block(1:nb, 1:na) + &
2035 matmul(bchint(1:nb, 1:np, bi_z), transpose(acint(1:na, 1:np, bi_x)))
2036
2037 blocks_rv(3, 2)%block(1:nb, 1:na) = blocks_rv(3, 2)%block(1:nb, 1:na) + &
2038 matmul(bchint(1:nb, 1:np, bi_z), transpose(acint(1:na, 1:np, bi_y)))
2039
2040 blocks_rv(3, 3)%block(1:nb, 1:na) = blocks_rv(3, 3)%block(1:nb, 1:na) + &
2041 matmul(bchint(1:nb, 1:np, bi_z), transpose(acint(1:na, 1:np, bi_z)))
2042
2043 ! -r_alpha*r_beta*Vnl
2044 blocks_rv(1, 1)%block(1:nb, 1:na) = blocks_rv(1, 1)%block(1:nb, 1:na) - &
2045 matmul(bchint(1:nb, 1:np, bi_xx), transpose(acint(1:na, 1:np, bi_1)))
2046
2047 blocks_rv(1, 2)%block(1:nb, 1:na) = blocks_rv(1, 2)%block(1:nb, 1:na) - &
2048 matmul(bchint(1:nb, 1:np, bi_xy), transpose(acint(1:na, 1:np, bi_1)))
2049
2050 blocks_rv(1, 3)%block(1:nb, 1:na) = blocks_rv(1, 3)%block(1:nb, 1:na) - &
2051 matmul(bchint(1:nb, 1:np, bi_xz), transpose(acint(1:na, 1:np, bi_1)))
2052
2053 blocks_rv(2, 1)%block(1:nb, 1:na) = blocks_rv(2, 1)%block(1:nb, 1:na) - &
2054 matmul(bchint(1:nb, 1:np, bi_xy), transpose(acint(1:na, 1:np, bi_1)))
2055
2056 blocks_rv(2, 2)%block(1:nb, 1:na) = blocks_rv(2, 2)%block(1:nb, 1:na) - &
2057 matmul(bchint(1:nb, 1:np, bi_yy), transpose(acint(1:na, 1:np, bi_1)))
2058
2059 blocks_rv(2, 3)%block(1:nb, 1:na) = blocks_rv(2, 3)%block(1:nb, 1:na) - &
2060 matmul(bchint(1:nb, 1:np, bi_yz), transpose(acint(1:na, 1:np, bi_1)))
2061
2062 blocks_rv(3, 1)%block(1:nb, 1:na) = blocks_rv(3, 1)%block(1:nb, 1:na) - &
2063 matmul(bchint(1:nb, 1:np, bi_xz), transpose(acint(1:na, 1:np, bi_1)))
2064
2065 blocks_rv(3, 2)%block(1:nb, 1:na) = blocks_rv(3, 2)%block(1:nb, 1:na) - &
2066 matmul(bchint(1:nb, 1:np, bi_yz), transpose(acint(1:na, 1:np, bi_1)))
2067
2068 blocks_rv(3, 3)%block(1:nb, 1:na) = blocks_rv(3, 3)%block(1:nb, 1:na) - &
2069 matmul(bchint(1:nb, 1:np, bi_zz), transpose(acint(1:na, 1:np, bi_1)))
2070
2071 ! -Vnl*r_beta*r_alpha
2072 blocks_rv(1, 1)%block(1:nb, 1:na) = blocks_rv(1, 1)%block(1:nb, 1:na) - &
2073 matmul(bchint(1:nb, 1:np, bi_1), transpose(acint(1:na, 1:np, bi_xx)))
2074
2075 blocks_rv(1, 2)%block(1:nb, 1:na) = blocks_rv(1, 2)%block(1:nb, 1:na) - &
2076 matmul(bchint(1:nb, 1:np, bi_1), transpose(acint(1:na, 1:np, bi_xy)))
2077
2078 blocks_rv(1, 3)%block(1:nb, 1:na) = blocks_rv(1, 3)%block(1:nb, 1:na) - &
2079 matmul(bchint(1:nb, 1:np, bi_1), transpose(acint(1:na, 1:np, bi_xz)))
2080
2081 blocks_rv(2, 1)%block(1:nb, 1:na) = blocks_rv(2, 1)%block(1:nb, 1:na) - &
2082 matmul(bchint(1:nb, 1:np, bi_1), transpose(acint(1:na, 1:np, bi_xy)))
2083
2084 blocks_rv(2, 2)%block(1:nb, 1:na) = blocks_rv(2, 2)%block(1:nb, 1:na) - &
2085 matmul(bchint(1:nb, 1:np, bi_1), transpose(acint(1:na, 1:np, bi_yy)))
2086
2087 blocks_rv(2, 3)%block(1:nb, 1:na) = blocks_rv(2, 3)%block(1:nb, 1:na) - &
2088 matmul(bchint(1:nb, 1:np, bi_1), transpose(acint(1:na, 1:np, bi_yz)))
2089
2090 blocks_rv(3, 1)%block(1:nb, 1:na) = blocks_rv(3, 1)%block(1:nb, 1:na) - &
2091 matmul(bchint(1:nb, 1:np, bi_1), transpose(acint(1:na, 1:np, bi_xz)))
2092
2093 blocks_rv(3, 2)%block(1:nb, 1:na) = blocks_rv(3, 2)%block(1:nb, 1:na) - &
2094 matmul(bchint(1:nb, 1:np, bi_1), transpose(acint(1:na, 1:np, bi_yz)))
2095
2096 blocks_rv(3, 3)%block(1:nb, 1:na) = blocks_rv(3, 3)%block(1:nb, 1:na) - &
2097 matmul(bchint(1:nb, 1:np, bi_1), transpose(acint(1:na, 1:np, bi_zz)))
2098
2099 ! +r_beta*Vnl*r_alpha
2100 blocks_rv(1, 1)%block(1:nb, 1:na) = blocks_rv(1, 1)%block(1:nb, 1:na) + &
2101 matmul(bchint(1:nb, 1:np, bi_x), transpose(acint(1:na, 1:np, bi_x)))
2102
2103 blocks_rv(1, 2)%block(1:nb, 1:na) = blocks_rv(1, 2)%block(1:nb, 1:na) + &
2104 matmul(bchint(1:nb, 1:np, bi_y), transpose(acint(1:na, 1:np, bi_x)))
2105
2106 blocks_rv(1, 3)%block(1:nb, 1:na) = blocks_rv(1, 3)%block(1:nb, 1:na) + &
2107 matmul(bchint(1:nb, 1:np, bi_z), transpose(acint(1:na, 1:np, bi_x)))
2108
2109 blocks_rv(2, 1)%block(1:nb, 1:na) = blocks_rv(2, 1)%block(1:nb, 1:na) + &
2110 matmul(bchint(1:nb, 1:np, bi_x), transpose(acint(1:na, 1:np, bi_y)))
2111
2112 blocks_rv(2, 2)%block(1:nb, 1:na) = blocks_rv(2, 2)%block(1:nb, 1:na) + &
2113 matmul(bchint(1:nb, 1:np, bi_y), transpose(acint(1:na, 1:np, bi_y)))
2114
2115 blocks_rv(2, 3)%block(1:nb, 1:na) = blocks_rv(2, 3)%block(1:nb, 1:na) + &
2116 matmul(bchint(1:nb, 1:np, bi_z), transpose(acint(1:na, 1:np, bi_y)))
2117
2118 blocks_rv(3, 1)%block(1:nb, 1:na) = blocks_rv(3, 1)%block(1:nb, 1:na) + &
2119 matmul(bchint(1:nb, 1:np, bi_x), transpose(acint(1:na, 1:np, bi_z)))
2120
2121 blocks_rv(3, 2)%block(1:nb, 1:na) = blocks_rv(3, 2)%block(1:nb, 1:na) + &
2122 matmul(bchint(1:nb, 1:np, bi_y), transpose(acint(1:na, 1:np, bi_z)))
2123
2124 blocks_rv(3, 3)%block(1:nb, 1:na) = blocks_rv(3, 3)%block(1:nb, 1:na) + &
2125 matmul(bchint(1:nb, 1:np, bi_z), transpose(acint(1:na, 1:np, bi_z)))
2126
2127 END IF
2128!$ CALL omp_unset_lock(locks(hash))
2129 EXIT ! We have found a match and there can be only one single match
2130 END IF
2131 END DO
2132 END DO
2133 END DO
2134 DO i = 1, 3
2135 NULLIFY (blocks_rv(i, 1)%block)
2136 NULLIFY (blocks_rv(i, 2)%block)
2137 NULLIFY (blocks_rv(i, 3)%block)
2138 END DO
2139 END DO
2140
2141!$OMP DO
2142!$ DO lock_num = 1, nlock
2143!$ call omp_destroy_lock(locks(lock_num))
2144!$ END DO
2145!$OMP END DO
2146
2147!$OMP SINGLE
2148!$ DEALLOCATE (locks)
2149!$OMP END SINGLE NOWAIT
2150
2151!$OMP END PARALLEL
2152
2153 CALL release_sap_int(sap_int)
2154
2155 DEALLOCATE (basis_set)
2156
2157 CALL timestop(handle)
2158
2159 END SUBROUTINE build_dcom_rpnl
2160
2161! **************************************************************************************************
2162!> \brief Apply the operator \delta_\mu^\lambda to zero out all elements of the matrix
2163!> which don't fulfill the condition.
2164!> Operates on matrix_hr(1:3) instead of a single matrix
2165!> \param matrix_hr ...
2166!> \param qs_kind_set ...
2167!> \param basis_type ...
2168!> \param sab_nl ...
2169!> \param deltaR ...
2170!> \param direction_Or ...
2171!> \author Edward Ditler
2172! **************************************************************************************************
2173 SUBROUTINE hr_mult_by_delta_3d(matrix_hr, qs_kind_set, basis_type, sab_nl, deltaR, direction_Or)
2174
2175 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hr
2176 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2177 CHARACTER(LEN=*), INTENT(IN) :: basis_type
2178 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2179 POINTER :: sab_nl
2180 REAL(kind=dp), DIMENSION(:, :) :: deltar
2181 LOGICAL :: direction_or
2182
2183 CHARACTER(len=*), PARAMETER :: routinen = 'hr_mult_by_delta_3d'
2184
2185 INTEGER :: handle, iatom, icol, ikind, ir, irow, &
2186 jatom, jkind, ldsab, mepos, nkind, &
2187 nseta, nsetb, nthread
2188 INTEGER, DIMENSION(3) :: cell
2189 INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
2190 npgfb, nsgfa, nsgfb
2191 INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
2192 LOGICAL :: do_symmetric, found
2193 REAL(kind=dp), DIMENSION(3) :: rab
2194 REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_a, set_radius_b
2195 REAL(kind=dp), DIMENSION(:, :), POINTER :: kx_block, ky_block, kz_block, rpgfa, &
2196 rpgfb, scon_a, scon_b, sphi_a, sphi_b, &
2197 zeta, zetb
2198 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
2199 TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
2200 TYPE(neighbor_list_iterator_p_type), &
2201 DIMENSION(:), POINTER :: nl_iterator
2202
2203 CALL timeset(routinen, handle)
2204
2205 nkind = SIZE(qs_kind_set)
2206
2207 ! check for symmetry
2208 cpassert(SIZE(sab_nl) > 0)
2209 CALL get_neighbor_list_set_p(neighbor_list_sets=sab_nl, symmetric=do_symmetric)
2210
2211 ! prepare basis set
2212 ALLOCATE (basis_set_list(nkind))
2213 CALL basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
2214
2215 ! *** Allocate work storage ***
2216 ldsab = get_memory_usage(qs_kind_set, basis_type)
2217
2218 nthread = 1
2219!$ nthread = omp_get_max_threads()
2220 ! Iterate of neighbor list
2221 CALL neighbor_list_iterator_create(nl_iterator, sab_nl, nthread=nthread)
2222
2223!$OMP PARALLEL DEFAULT(NONE) &
2224!$OMP SHARED (nthread,ldsab,nl_iterator, do_symmetric) &
2225!$OMP SHARED (ncoset,matrix_hr,basis_set_list) &
2226!$OMP SHARED (direction_or, deltar) &
2227!$OMP PRIVATE (kx_block,ky_block,kz_block,mepos,ikind,jkind,iatom,jatom,rab,cell) &
2228!$OMP PRIVATE (basis_set_a,basis_set_b) &
2229!$OMP PRIVATE (nseta, nsetb) &
2230!$OMP PRIVATE (first_sgfa, la_max, la_min, npgfa, nsgfa, rpgfa, set_radius_a, sphi_a, zeta, scon_a) &
2231!$OMP PRIVATE (first_sgfb, lb_max, lb_min, npgfb, nsgfb, rpgfb, set_radius_b, sphi_b, zetb, scon_b) &
2232!$OMP PRIVATE (irow, icol, found)
2233
2234 mepos = 0
2235!$ mepos = omp_get_thread_num()
2236
2237 DO WHILE (neighbor_list_iterate(nl_iterator, mepos=mepos) == 0)
2238 CALL get_iterator_info(nl_iterator, mepos=mepos, ikind=ikind, jkind=jkind, &
2239 iatom=iatom, jatom=jatom, r=rab, cell=cell)
2240 basis_set_a => basis_set_list(ikind)%gto_basis_set
2241 IF (.NOT. ASSOCIATED(basis_set_a)) cycle
2242 basis_set_b => basis_set_list(jkind)%gto_basis_set
2243 IF (.NOT. ASSOCIATED(basis_set_b)) cycle
2244 ! basis ikind
2245 first_sgfa => basis_set_a%first_sgf
2246 la_max => basis_set_a%lmax
2247 la_min => basis_set_a%lmin
2248 npgfa => basis_set_a%npgf
2249 nsgfa => basis_set_a%nsgf_set
2250 rpgfa => basis_set_a%pgf_radius
2251 set_radius_a => basis_set_a%set_radius
2252 sphi_a => basis_set_a%sphi
2253 zeta => basis_set_a%zet
2254 scon_a => basis_set_a%scon
2255 ! basis jkind
2256 first_sgfb => basis_set_b%first_sgf
2257 lb_max => basis_set_b%lmax
2258 lb_min => basis_set_b%lmin
2259 npgfb => basis_set_b%npgf
2260 nsgfb => basis_set_b%nsgf_set
2261 rpgfb => basis_set_b%pgf_radius
2262 set_radius_b => basis_set_b%set_radius
2263 sphi_b => basis_set_b%sphi
2264 zetb => basis_set_b%zet
2265 scon_b => basis_set_b%scon
2266
2267 nseta = basis_set_a%nset
2268 nsetb = basis_set_b%nset
2269
2270 IF (do_symmetric) THEN
2271 IF (iatom <= jatom) THEN
2272 irow = iatom
2273 icol = jatom
2274 ELSE
2275 irow = jatom
2276 icol = iatom
2277 END IF
2278 ELSE
2279 irow = iatom
2280 icol = jatom
2281 END IF
2282
2283 NULLIFY (kx_block, ky_block, kz_block)
2284 CALL dbcsr_get_block_p(matrix_hr(1)%matrix, irow, icol, kx_block, found)
2285 cpassert(found)
2286 CALL dbcsr_get_block_p(matrix_hr(2)%matrix, irow, icol, ky_block, found)
2287 cpassert(found)
2288 CALL dbcsr_get_block_p(matrix_hr(3)%matrix, irow, icol, kz_block, found)
2289 cpassert(found)
2290
2291 IF (direction_or) THEN
2292 DO ir = 1, 3
2293!$OMP CRITICAL(blockadd)
2294 SELECT CASE (ir)
2295 CASE (1)
2296 kx_block(:, :) = kx_block(:, :)*deltar(ir, jatom)
2297 CASE (2)
2298 ky_block(:, :) = ky_block(:, :)*deltar(ir, jatom)
2299 CASE (3)
2300 kz_block(:, :) = kz_block(:, :)*deltar(ir, jatom)
2301 END SELECT
2302!$OMP END CRITICAL(blockadd)
2303 END DO
2304 ELSE
2305 DO ir = 1, 3
2306!$OMP CRITICAL(blockadd)
2307 SELECT CASE (ir)
2308 CASE (1)
2309 kx_block(:, :) = kx_block(:, :)*deltar(ir, iatom)
2310 CASE (2)
2311 ky_block(:, :) = ky_block(:, :)*deltar(ir, iatom)
2312 CASE (3)
2313 kz_block(:, :) = kz_block(:, :)*deltar(ir, iatom)
2314 END SELECT
2315!$OMP END CRITICAL(blockadd)
2316 END DO
2317 END IF
2318 END DO
2319!$OMP END PARALLEL
2320 CALL neighbor_list_iterator_release(nl_iterator)
2321
2322 ! Release work storage
2323 DEALLOCATE (basis_set_list)
2324
2325 CALL timestop(handle)
2326
2327 END SUBROUTINE hr_mult_by_delta_3d
2328
2329END MODULE qs_vcd_ao
static GRID_HOST_DEVICE int ncoset(const int l)
Number of Cartesian orbitals up to given angular momentum quantum.
Definition grid_common.h:82
static void dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Convenient wrapper to hide Fortran nature of dgemm_, swapping a and b.
Coordinate and basis-center derivative ladders for Cartesian Gaussian integrals. Derivatives act on a...
subroutine, public apply_cartesian_operator(la_max, la_min, npgfa, lb_max, lb_min, npgfb, ab, values, right, derivative, exponents, origin)
Apply a Cartesian operator on either side of a primitive integral block. The input includes one extra...
Set of routines to: Contract integrals over primitive Gaussians Decontract (density) matrices Trace m...
Calculation of the kinetic energy integrals over Cartesian Gaussian-type functions.
Definition ai_kinetic.F:20
subroutine, public kinetic(la_max, la_min, npgfa, rpgfa, zeta, lb_max, lb_min, npgfb, rpgfb, zetb, rab, kab, dab)
Calculation of the two-center kinetic energy integrals [a|T|b] over Cartesian Gaussian-type functions...
Definition ai_kinetic.F:65
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...
All kind of helpful little routines.
Definition ao_util.F:14
real(kind=dp) function, public exp_radius_very_extended(la_min, la_max, lb_min, lb_max, pab, o1, o2, ra, rb, rp, zetp, eps, prefactor, cutoff, epsabs)
computes the radius of the Gaussian outside of which it is smaller than eps
Definition ao_util.F:208
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.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum, ccon)
...
collect pointers to a block of reals
Handles all functions related to the CELL.
Definition cell_types.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_init_p(matrix)
...
subroutine, public dbcsr_work_create(matrix, nblks_guess, sizedata_guess, n, work_mutable)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_distribution_get(dist, row_dist, col_dist, nrows, ncols, has_threads, group, mynode, numnodes, nprows, npcols, myprow, mypcol, pgrid, subgroups_defined, prow_group, pcol_group)
...
DBCSR operations in CP2K.
Definition of the atomic potential types.
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
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
integer, parameter, public default_string_length
Definition kinds.F:57
Utility routines for the memory handling.
Interface to the message passing library MPI.
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.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Some utility functions for the calculation of integrals.
subroutine, public basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
Set up an easy accessible list of the basis sets for all kinds.
Integrate single or product functions over a potential on a RS grid.
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, cneo_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, hund_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, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, 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, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
Type definitiona for linear response calculations.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>.
Definition qs_moments.F:14
subroutine, public build_local_moment_matrix(qs_env, moments, nmoments, ref_point, ref_points, basis_type, all_images, minimum_image, neighbor_image, first_component)
...
Definition qs_moments.F:178
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_neighbor_list_set_p(neighbor_list_sets, nlist, symmetric)
Return the components of the first neighbor list set.
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public build_dcom_rpnl(matrix_rv, qs_kind_set, sab_orb, sap_ppnl, eps_ppnl, particle_set, pseudoatom)
Calculate the double commutator [[Vnl, r], r].
Definition qs_vcd_ao.F:1757
subroutine, public build_com_rpnl_r(matrix_rcomr, matrix_rrcom, qs_kind_set, sab_all, sap_ppnl, eps_ppnl, particle_set, cell)
Build the two ordered nonlocal second-position products.
Definition qs_vcd_ao.F:1542
subroutine, public hr_mult_by_delta_3d(matrix_hr, qs_kind_set, basis_type, sab_nl, deltar, direction_or)
Apply the operator \delta_\mu^\lambda to zero out all elements of the matrix which don't fulfill the ...
Definition qs_vcd_ao.F:2174
subroutine, public build_dsdv_matrix(qs_env, matrix_dsdv, deltar, rcc)
Builds the overlap derivative wrt nuclear velocities dS/dV = < mu | r | nu > * (nu - mu).
Definition qs_vcd_ao.F:1458
subroutine, public build_matrix_hr_rh(vcd_env, qs_env, rc)
Build the matrix Hr*delta_nu^\lambda - rH*delta_mu^\lambda.
Definition qs_vcd_ao.F:120
subroutine, public qs_vxc_create(ks_env, rho_struct, xc_section, vxc_rho, vxc_tau, exc, just_energy, edisp, dispersion_env, adiabatic_rescale_factor, pw_env_external, native_skala_atom_force, qs_env_external, native_gapw_composite_override, native_skala_defer_to_atom_composite)
calculates and allocates the xc potential, already reducing it to the dependence on rho and the one o...
Definition qs_vxc.F:120
Transfers densities from PW to RS grids and potentials from PW to RS.
subroutine, public potential_pw2rs(rs_v, v_rspace, pw_env)
transfers a potential from a pw_grid to a vector of realspace multigrids
General overlap type integrals containers.
subroutine, public build_sap_ints(sap_int, sap_ppnl, qs_kind_set, nder, moment_mode, refpoint, particle_set, cell, pseudoatom)
Calculate overlap and optionally momenta <a|x^n|p> between GTOs and nl. pseudo potential projectors a...
generate the tasks lists used by collocate and integrate routines
subroutine, public rs_gather_matrices(src_buffer, dest_matrices, task_list, group)
Gather the dbcsr matrix blocks and receives them into a buffer as needed after integration.
types for task lists
Local UPF matrix elements from the original radial potential. The Gaussian core electrostatics suppli...
subroutine, public upf_local_matrix(local, la, alpha, lb, beta, rab, rac, v, da, db)
Evaluate primitive three-center local integrals by the Gaussian product theorem.
subroutine, public upf_local_init(pot, alpha, degree, local, eps)
Prepare the short-range local potential outside parallel regions.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.