94 SUBROUTINE build_core_ppl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, &
95 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, &
96 nimages, cell_to_index, basis_type, deltaR, atcore)
98 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_h, matrix_p
101 LOGICAL,
INTENT(IN) :: calculate_forces
102 LOGICAL :: use_virial
104 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
108 POINTER :: sab_orb, sac_ppl
109 INTEGER,
INTENT(IN) :: nimages
110 INTEGER,
DIMENSION(:, :, :),
OPTIONAL,
POINTER :: cell_to_index
111 CHARACTER(LEN=*),
INTENT(IN) :: basis_type
112 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN), &
114 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT), &
117 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_core_ppl'
118 INTEGER,
PARAMETER :: nexp_max = 30
120 INTEGER :: atom_a, handle, i, iatom, icol, ikind, img, irow, iset, jatom, jkind, jset, &
121 katom, kkind, ldai, ldsab, maxco, maxder, maxl, maxlgto, maxlppl, maxnset, maxsgf, mepos, &
122 n_local, natom, ncoa, ncob, nexp_lpot, nexp_ppl, nkind, nloc, nseta, nsetb, nthread, &
123 sgfa, sgfb, slmax, slot
124 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
125 INTEGER,
DIMENSION(0:10) :: npot
126 INTEGER,
DIMENSION(1:10) :: nrloc
127 INTEGER,
DIMENSION(1:15, 0:10) :: nrpot
128 INTEGER,
DIMENSION(3) :: cellind
129 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, lb_max, lb_min, &
130 nct_lpot, npgfa, npgfb, nsgfa, nsgfb
131 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
132 INTEGER,
DIMENSION(nexp_max) :: nct_ppl
133 LOGICAL :: do_dr, doat, dokp, ecp_local, &
134 ecp_semi_local, found, libgrpp_local, &
135 lpotextended, only_gaussians
136 REAL(kind=
dp) :: alpha, atk0, atk1, dab, dac, dbc, f0, &
138 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: work
139 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: hab2_w, ppl_fwork, ppl_work
140 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :, :) :: hab, pab
141 REAL(kind=
dp),
ALLOCATABLE, &
142 DIMENSION(:, :, :, :, :) :: hab2
143 REAL(kind=
dp),
DIMENSION(1:10) :: aloc, bloc
144 REAL(kind=
dp),
DIMENSION(1:15, 0:10) :: apot, bpot
145 REAL(kind=
dp),
DIMENSION(3) :: force_a, force_b, rab, rac, rbc
146 REAL(kind=
dp),
DIMENSION(3, 3) :: pv_thread
148 DIMENSION(:),
POINTER :: ap_iterator
152 REAL(kind=
dp),
DIMENSION(SIZE(particle_set)) :: at_thread
153 REAL(kind=
dp),
DIMENSION(nexp_max) :: alpha_ppl
154 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: cval_lpot, h1_1block, h1_2block, &
155 h1_3block, h_block, p_block, rpgfa, &
156 rpgfb, sphi_a, sphi_b, zeta, zetb
157 REAL(kind=
dp),
DIMENSION(:),
POINTER :: a_local, alpha_lpot, c_local, cexp_ppl, &
158 set_radius_a, set_radius_b
159 REAL(kind=
dp),
DIMENSION(4, nexp_max) :: cval_ppl
160 REAL(kind=
dp),
DIMENSION(3, SIZE(particle_set)) :: force_thread
169 do_dr =
PRESENT(deltar)
170 doat =
PRESENT(atcore)
171 IF ((calculate_forces .OR. doat) .AND. do_dr)
THEN
172 cpabort(
"core_ppl: incompatible options")
178 libgrpp_local = .false.
180 IF (calculate_forces)
THEN
181 CALL timeset(routinen//
"_forces", handle)
183 CALL timeset(routinen, handle)
186 nkind =
SIZE(atomic_kind_set)
187 natom =
SIZE(particle_set)
192 IF (
PRESENT(cell_to_index))
THEN
193 cpassert(
ASSOCIATED(cell_to_index))
195 cpabort(
"Missing cell_to_index for k-point calculation")
199 IF (calculate_forces .OR. doat)
THEN
200 IF (
SIZE(matrix_p, 1) == 2)
THEN
202 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
203 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
204 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
205 alpha_scalar=-2.0_dp, beta_scalar=1.0_dp)
209 force_thread = 0.0_dp
215 maxsgf=maxsgf, maxnset=maxnset, maxlppl=maxlppl, &
216 basis_type=basis_type)
218 maxl = max(maxlgto, maxlppl)
221 ldsab = max(maxco,
ncoset(maxlppl), maxsgf, maxlppl)
222 ldai =
ncoset(maxl + nder + 1)
224 ALLOCATE (basis_set_list(nkind))
226 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set_a, basis_type=basis_type)
227 IF (
ASSOCIATED(basis_set_a))
THEN
228 basis_set_list(ikind)%gto_basis_set => basis_set_a
230 NULLIFY (basis_set_list(ikind)%gto_basis_set)
278 ALLOCATE (hab(ldsab, ldsab, maxnset, maxnset), work(ldsab, ldsab*maxder))
279 ldai =
ncoset(2*maxlgto + 2*nder)
280 ALLOCATE (ppl_work(ldai, ldai, max(maxder, 2*maxlgto + 2*nder + 1)))
281 IF (calculate_forces .OR. doat)
THEN
282 ALLOCATE (pab(maxco, maxco, maxnset, maxnset))
284 ALLOCATE (ppl_fwork(ldai, ldai, maxder))
288 DO slot = 1, sab_orb(1)%nl_size
291 ALLOCATE (hab2(ldsab, ldsab, 4, maxnset, maxnset))
292 ALLOCATE (hab2_w(ldsab, ldsab, 6))
293 ALLOCATE (ppl_fwork(ldai, ldai, maxder))
296 ikind = sab_orb(1)%nlist_task(slot)%ikind
297 jkind = sab_orb(1)%nlist_task(slot)%jkind
298 iatom = sab_orb(1)%nlist_task(slot)%iatom
299 jatom = sab_orb(1)%nlist_task(slot)%jatom
300 cellind(:) = sab_orb(1)%nlist_task(slot)%cell(:)
301 rab(1:3) = sab_orb(1)%nlist_task(slot)%r(1:3)
303 basis_set_a => basis_set_list(ikind)%gto_basis_set
304 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
305 basis_set_b => basis_set_list(jkind)%gto_basis_set
306 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
312 first_sgfa => basis_set_a%first_sgf
313 la_max => basis_set_a%lmax
314 la_min => basis_set_a%lmin
315 npgfa => basis_set_a%npgf
316 nseta = basis_set_a%nset
317 nsgfa => basis_set_a%nsgf_set
318 rpgfa => basis_set_a%pgf_radius
319 set_radius_a => basis_set_a%set_radius
320 sphi_a => basis_set_a%sphi
321 zeta => basis_set_a%zet
323 first_sgfb => basis_set_b%first_sgf
324 lb_max => basis_set_b%lmax
325 lb_min => basis_set_b%lmin
326 npgfb => basis_set_b%npgf
327 nsetb = basis_set_b%nset
328 nsgfb => basis_set_b%nsgf_set
329 rpgfb => basis_set_b%pgf_radius
330 set_radius_b => basis_set_b%set_radius
331 sphi_b => basis_set_b%sphi
332 zetb => basis_set_b%zet
334 dab = sqrt(sum(rab*rab))
337 img = cell_to_index(cellind(1), cellind(2), cellind(3))
343 IF (iatom == jatom)
THEN
350 IF (iatom <= jatom)
THEN
360 NULLIFY (h1_1block, h1_2block, h1_3block)
363 row=irow, col=icol, block=h1_1block, found=found)
365 row=irow, col=icol, block=h1_2block, found=found)
367 row=irow, col=icol, block=h1_3block, found=found)
372 IF (calculate_forces .OR. doat)
THEN
375 IF (
ASSOCIATED(p_block))
THEN
377 ncoa = npgfa(iset)*
ncoset(la_max(iset))
378 sgfa = first_sgfa(1, iset)
380 ncob = npgfb(jset)*
ncoset(lb_max(jset))
381 sgfb = first_sgfb(1, jset)
384 IF (iatom <= jatom)
THEN
385 work(1:ncoa, 1:nsgfb(jset)) = matmul(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1), &
386 p_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1))
388 work(1:ncoa, 1:nsgfb(jset)) = matmul(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1), &
389 transpose(p_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1)))
392 pab(1:ncoa, 1:ncob, iset, jset) = matmul(work(1:ncoa, 1:nsgfb(jset)), &
393 transpose(sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1)))
400 IF (do_dr) hab2 = 0._dp
405 CALL get_qs_kind(qs_kind_set(kkind), gth_potential=gth_potential, &
406 sgp_potential=sgp_potential)
407 ecp_semi_local = .false.
408 only_gaussians = .true.
409 IF (
ASSOCIATED(gth_potential))
THEN
411 alpha_ppl=alpha, cexp_ppl=cexp_ppl, &
412 lpot_present=lpotextended, ppl_radius=ppl_radius)
415 nct_ppl(1) =
SIZE(cexp_ppl)
416 cval_ppl(1:nct_ppl(1), 1) = cexp_ppl(1:nct_ppl(1))
417 IF (lpotextended)
THEN
419 nexp_lpot=nexp_lpot, alpha_lpot=alpha_lpot, nct_lpot=nct_lpot, &
421 cpassert(nexp_lpot < nexp_max)
422 nexp_ppl = nexp_lpot + 1
423 alpha_ppl(2:nexp_lpot + 1) = alpha_lpot(1:nexp_lpot)
424 nct_ppl(2:nexp_lpot + 1) = nct_lpot(1:nexp_lpot)
426 cval_ppl(1:nct_lpot(i), i + 1) = cval_lpot(1:nct_lpot(i), i)
429 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
430 CALL get_potential(potential=sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local, &
431 ppl_radius=ppl_radius)
433 CALL get_potential(potential=sgp_potential, nloc=nloc, nrloc=nrloc, aloc=aloc, bloc=bloc)
435 cpassert(nexp_ppl <= nexp_max)
436 nct_ppl(1:nloc) = nrloc(1:nloc)
437 alpha_ppl(1:nloc) = bloc(1:nloc)
438 cval_ppl(1, 1:nloc) = aloc(1:nloc)
439 only_gaussians = .false.
441 CALL get_potential(potential=sgp_potential, n_local=n_local, a_local=a_local, c_local=c_local)
443 cpassert(nexp_ppl <= nexp_max)
444 nct_ppl(1:n_local) = 1
445 alpha_ppl(1:n_local) = a_local(1:n_local)
446 cval_ppl(1, 1:n_local) = c_local(1:n_local)
448 IF (ecp_semi_local)
THEN
450 npot=npot, nrpot=nrpot, apot=apot, bpot=bpot)
451 ELSE IF (ecp_local)
THEN
452 IF (sum(abs(aloc(1:nloc))) < 1.0e-12_dp) cycle
464 dac = sqrt(sum(rac*rac))
465 rbc(:) = rac(:) - rab(:)
466 dbc = sqrt(sum(rbc*rbc))
467 IF ((maxval(set_radius_a(:)) + ppl_radius < dac) .OR. &
468 (maxval(set_radius_b(:)) + ppl_radius < dbc))
THEN
473 IF (set_radius_a(iset) + ppl_radius < dac) cycle
474 ncoa = npgfa(iset)*
ncoset(la_max(iset))
475 sgfa = first_sgfa(1, iset)
477 IF (set_radius_b(jset) + ppl_radius < dbc) cycle
478 ncob = npgfb(jset)*
ncoset(lb_max(jset))
479 sgfb = first_sgfb(1, jset)
480 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
483 atk0 = f0*sum(hab(1:ncoa, 1:ncob, iset, jset)* &
484 pab(1:ncoa, 1:ncob, iset, jset))
486 IF (calculate_forces)
THEN
491 IF (only_gaussians)
THEN
493 la_max(iset), la_min(iset), npgfa(iset), &
494 rpgfa(:, iset), zeta(:, iset), &
495 lb_max(jset), lb_min(jset), npgfb(jset), &
496 rpgfb(:, jset), zetb(:, jset), &
497 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
498 rab, dab, rac, dac, rbc, dbc, &
499 hab(:, :, iset, jset), ppl_work, pab(:, :, iset, jset), &
500 force_a, force_b, ppl_fwork)
501 ELSE IF (libgrpp_local)
THEN
504 rpgfa(:, iset), zeta(:, iset), &
505 lb_max(jset), lb_min(jset), npgfb(jset), &
506 rpgfb(:, jset), zetb(:, jset), &
507 nexp_ppl, alpha_ppl, cval_ppl(1, :), nct_ppl, &
508 ppl_radius, rab, dab, rac, dac, dbc, &
509 hab(:, :, iset, jset), pab(:, :, iset, jset), &
514 la_max(iset), la_min(iset), npgfa(iset), &
515 rpgfa(:, iset), zeta(:, iset), &
516 lb_max(jset), lb_min(jset), npgfb(jset), &
517 rpgfb(:, jset), zetb(:, jset), &
518 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
519 rab, dab, rac, dac, rbc, dbc, &
520 hab(:, :, iset, jset), ppl_work, pab(:, :, iset, jset), &
521 force_a, force_b, ppl_fwork)
524 IF (ecp_semi_local)
THEN
528 rpgfa(:, iset), zeta(:, iset), &
529 lb_max(jset), lb_min(jset), npgfb(jset), &
530 rpgfb(:, jset), zetb(:, jset), &
531 slmax, npot, bpot, apot, nrpot, &
532 ppl_radius, rab, dab, rac, dac, dbc, &
533 hab(:, :, iset, jset), pab(:, :, iset, jset), &
541 force_thread(1, iatom) = force_thread(1, iatom) + f0*force_a(1)
542 force_thread(2, iatom) = force_thread(2, iatom) + f0*force_a(2)
543 force_thread(3, iatom) = force_thread(3, iatom) + f0*force_a(3)
544 force_thread(1, katom) = force_thread(1, katom) - f0*force_a(1)
545 force_thread(2, katom) = force_thread(2, katom) - f0*force_a(2)
546 force_thread(3, katom) = force_thread(3, katom) - f0*force_a(3)
548 force_thread(1, jatom) = force_thread(1, jatom) + f0*force_b(1)
549 force_thread(2, jatom) = force_thread(2, jatom) + f0*force_b(2)
550 force_thread(3, jatom) = force_thread(3, jatom) + f0*force_b(3)
551 force_thread(1, katom) = force_thread(1, katom) - f0*force_b(1)
552 force_thread(2, katom) = force_thread(2, katom) - f0*force_b(2)
553 force_thread(3, katom) = force_thread(3, katom) - f0*force_b(3)
562 la_max(iset), la_min(iset), npgfa(iset), &
563 rpgfa(:, iset), zeta(:, iset), &
564 lb_max(jset), lb_min(jset), npgfb(jset), &
565 rpgfb(:, jset), zetb(:, jset), &
566 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
567 rab, dab, rac, dac, rbc, dbc, &
568 vab=hab(:, :, iset, jset), s=ppl_work, &
569 hab2=hab2(:, :, :, iset, jset), hab2_work=hab2_w, fs=ppl_fwork, &
570 deltar=deltar, iatom=iatom, jatom=jatom, katom=katom)
571 IF (ecp_semi_local)
THEN
573 cpabort(
"Option not implemented")
576 IF (only_gaussians)
THEN
580 la_max(iset), la_min(iset), npgfa(iset), &
581 rpgfa(:, iset), zeta(:, iset), &
582 lb_max(jset), lb_min(jset), npgfb(jset), &
583 rpgfb(:, jset), zetb(:, jset), &
584 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
585 rab, dab, rac, dac, rbc, dbc, hab(:, :, iset, jset), ppl_work)
587 ELSE IF (libgrpp_local)
THEN
591 rpgfa(:, iset), zeta(:, iset), &
592 lb_max(jset), lb_min(jset), npgfb(jset), &
593 rpgfb(:, jset), zetb(:, jset), &
594 nexp_ppl, alpha_ppl, cval_ppl(1, :), nct_ppl, &
595 ppl_radius, rab, dab, rac, dac, dbc, &
596 hab(:, :, iset, jset))
600 la_max(iset), la_min(iset), npgfa(iset), &
601 rpgfa(:, iset), zeta(:, iset), &
602 lb_max(jset), lb_min(jset), npgfb(jset), &
603 rpgfb(:, jset), zetb(:, jset), &
604 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
605 rab, dab, rac, dac, rbc, dbc, hab(:, :, iset, jset), ppl_work)
608 IF (ecp_semi_local)
THEN
612 rpgfa(:, iset), zeta(:, iset), &
613 lb_max(jset), lb_min(jset), npgfb(jset), &
614 rpgfb(:, jset), zetb(:, jset), &
615 slmax, npot, bpot, apot, nrpot, &
616 ppl_radius, rab, dab, rac, dac, dbc, &
617 hab(:, :, iset, jset))
623 atk1 = f0*sum(hab(1:ncoa, 1:ncob, iset, jset)* &
624 pab(1:ncoa, 1:ncob, iset, jset))
625 at_thread(katom) = at_thread(katom) + (atk1 - atk0)
633 IF (.NOT. do_dr)
THEN
635 ncoa = npgfa(iset)*
ncoset(la_max(iset))
636 sgfa = first_sgfa(1, iset)
638 ncob = npgfb(jset)*
ncoset(lb_max(jset))
639 sgfb = first_sgfb(1, jset)
644 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab(1:ncoa, 1:ncob, iset, jset), &
645 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
647 IF (iatom <= jatom)
THEN
648 h_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
649 h_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
650 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
652 h_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
653 h_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
654 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
662 ncoa = npgfa(iset)*
ncoset(la_max(iset))
663 sgfa = first_sgfa(1, iset)
665 ncob = npgfb(jset)*
ncoset(lb_max(jset))
666 sgfb = first_sgfb(1, jset)
667 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 1, iset, jset), &
668 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
671 IF (iatom <= jatom)
THEN
672 h1_1block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
673 h1_1block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
674 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
677 h1_1block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
678 h1_1block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
679 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
682 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 2, iset, jset), &
683 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
686 IF (iatom <= jatom)
THEN
687 h1_2block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
688 h1_2block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
689 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
692 h1_2block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
693 h1_2block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
694 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
697 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 3, iset, jset), &
698 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
700 IF (iatom <= jatom)
THEN
701 h1_3block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
702 h1_3block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
703 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
706 h1_3block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
707 h1_3block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
708 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
714 IF (do_dr)
DEALLOCATE (hab2, ppl_fwork, hab2_w)
717 DEALLOCATE (hab, work, ppl_work)
718 IF (calculate_forces .OR. doat)
THEN
719 DEALLOCATE (pab, ppl_fwork)
736 DEALLOCATE (basis_set_list)
738 IF (calculate_forces .OR. doat)
THEN
741 IF (
SIZE(matrix_p, 1) == 2)
THEN
743 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
744 alpha_scalar=0.5_dp, beta_scalar=0.5_dp)
745 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
746 alpha_scalar=-1.0_dp, beta_scalar=1.0_dp)
751 IF (calculate_forces)
THEN
755 atom_a = atom_of_kind(iatom)
756 ikind = kind_of(iatom)
757 force(ikind)%gth_ppl(:, atom_a) = force(ikind)%gth_ppl(:, atom_a) + force_thread(:, iatom)
760 DEALLOCATE (atom_of_kind, kind_of)
763 atcore(1:natom) = atcore(1:natom) + at_thread(1:natom)
766 IF (calculate_forces .AND. use_virial)
THEN
767 virial%pv_ppl = virial%pv_ppl + pv_thread
768 virial%pv_virial = virial%pv_virial + pv_thread
771 CALL timestop(handle)
789 qs_kind_set, atomic_kind_set, particle_set, sac_ppl, &
795 LOGICAL,
INTENT(IN) :: calculate_forces
796 LOGICAL :: use_virial
797 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
802 CHARACTER(LEN=*),
INTENT(IN) :: basis_type
804 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_core_ppl_ri'
805 INTEGER,
PARAMETER :: nexp_max = 30
807 INTEGER :: atom_a, handle, i, iatom, ikind, iset, katom, kkind, maxco, maxsgf, n_local, &
808 natom, ncoa, nexp_lpot, nexp_ppl, nfun, nkind, nloc, nseta, sgfa, sgfb, slot
809 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
810 INTEGER,
DIMENSION(1:10) :: nrloc
811 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, nct_lpot, npgfa, nsgfa
812 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa
813 INTEGER,
DIMENSION(nexp_max) :: nct_ppl
814 LOGICAL :: ecp_local, ecp_semi_local, lpotextended
815 REAL(kind=
dp) :: alpha, dac, ppl_radius
816 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: va, work
817 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: dva, dvas
818 REAL(kind=
dp),
DIMENSION(1:10) :: aloc, bloc
819 REAL(kind=
dp),
DIMENSION(3) :: force_a, rac
820 REAL(kind=
dp),
DIMENSION(3, 3) :: pv_thread
824 REAL(kind=
dp),
DIMENSION(nexp_max) :: alpha_ppl
825 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: bcon, cval_lpot, rpgfa, sphi_a, zeta
826 REAL(kind=
dp),
DIMENSION(:),
POINTER :: a_local, alpha_lpot, c_local, cexp_ppl, &
828 REAL(kind=
dp),
DIMENSION(4, nexp_max) :: cval_ppl
829 REAL(kind=
dp),
DIMENSION(3, SIZE(particle_set)) :: force_thread
837 IF (calculate_forces)
THEN
838 CALL timeset(routinen//
"_forces", handle)
840 CALL timeset(routinen, handle)
843 nkind =
SIZE(atomic_kind_set)
844 natom =
SIZE(particle_set)
846 force_thread = 0.0_dp
850 ALLOCATE (basis_set_list(nkind))
852 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set, basis_type=basis_type)
853 IF (
ASSOCIATED(basis_set))
THEN
854 basis_set_list(ikind)%gto_basis_set => basis_set
856 NULLIFY (basis_set_list(ikind)%gto_basis_set)
860 CALL get_qs_kind_set(qs_kind_set, maxco=maxco, maxsgf=maxsgf, basis_type=basis_type)
884 ALLOCATE (va(maxco), work(maxsgf))
885 IF (calculate_forces)
THEN
886 ALLOCATE (dva(maxco, 3), dvas(maxco, 3))
890 DO slot = 1, sac_ppl(1)%nl_size
892 ikind = sac_ppl(1)%nlist_task(slot)%ikind
893 kkind = sac_ppl(1)%nlist_task(slot)%jkind
894 iatom = sac_ppl(1)%nlist_task(slot)%iatom
895 katom = sac_ppl(1)%nlist_task(slot)%jatom
896 rac(1:3) = sac_ppl(1)%nlist_task(slot)%r(1:3)
897 atom_a = atom_of_kind(iatom)
899 basis_set => basis_set_list(ikind)%gto_basis_set
900 IF (.NOT.
ASSOCIATED(basis_set)) cycle
903 first_sgfa => basis_set%first_sgf
904 la_max => basis_set%lmax
905 la_min => basis_set%lmin
906 npgfa => basis_set%npgf
907 nseta = basis_set%nset
908 nsgfa => basis_set%nsgf_set
909 nfun = basis_set%nsgf
910 rpgfa => basis_set%pgf_radius
911 set_radius_a => basis_set%set_radius
912 sphi_a => basis_set%sphi
913 zeta => basis_set%zet
915 CALL get_qs_kind(qs_kind_set(kkind), gth_potential=gth_potential, &
916 sgp_potential=sgp_potential)
917 ecp_semi_local = .false.
918 IF (
ASSOCIATED(gth_potential))
THEN
920 alpha_ppl=alpha, cexp_ppl=cexp_ppl, &
921 lpot_present=lpotextended, ppl_radius=ppl_radius)
924 nct_ppl(1) =
SIZE(cexp_ppl)
925 cval_ppl(1:nct_ppl(1), 1) = cexp_ppl(1:nct_ppl(1))
926 IF (lpotextended)
THEN
928 nexp_lpot=nexp_lpot, alpha_lpot=alpha_lpot, nct_lpot=nct_lpot, cval_lpot=cval_lpot)
929 cpassert(nexp_lpot < nexp_max)
930 nexp_ppl = nexp_lpot + 1
931 alpha_ppl(2:nexp_lpot + 1) = alpha_lpot(1:nexp_lpot)
932 nct_ppl(2:nexp_lpot + 1) = nct_lpot(1:nexp_lpot)
934 cval_ppl(1:nct_lpot(i), i + 1) = cval_lpot(1:nct_lpot(i), i)
937 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
938 CALL get_potential(potential=sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local, &
939 ppl_radius=ppl_radius)
940 cpassert(.NOT. ecp_semi_local)
942 CALL get_potential(potential=sgp_potential, nloc=nloc, nrloc=nrloc, aloc=aloc, bloc=bloc)
943 IF (sum(abs(aloc(1:nloc))) < 1.0e-12_dp) cycle
945 cpassert(nexp_ppl <= nexp_max)
946 nct_ppl(1:nloc) = nrloc(1:nloc)
947 alpha_ppl(1:nloc) = bloc(1:nloc)
948 cval_ppl(1, 1:nloc) = aloc(1:nloc)
950 CALL get_potential(potential=sgp_potential, n_local=n_local, a_local=a_local, c_local=c_local)
952 cpassert(nexp_ppl <= nexp_max)
953 nct_ppl(1:n_local) = 1
954 alpha_ppl(1:n_local) = a_local(1:n_local)
955 cval_ppl(1, 1:n_local) = c_local(1:n_local)
961 dac = sqrt(sum(rac*rac))
962 IF ((maxval(set_radius_a(:)) + ppl_radius < dac)) cycle
963 IF (calculate_forces) force_a = 0.0_dp
964 work(1:nfun) = 0.0_dp
967 IF (set_radius_a(iset) + ppl_radius < dac) cycle
969 IF (calculate_forces)
THEN
973 la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
974 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
979 la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
980 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
984 sgfa = first_sgfa(1, iset)
985 sgfb = sgfa + nsgfa(iset) - 1
986 ncoa = npgfa(iset)*
ncoset(la_max(iset))
987 bcon => sphi_a(1:ncoa, sgfa:sgfb)
988 work(sgfa:sgfb) = matmul(transpose(bcon), va(1:ncoa))
989 IF (calculate_forces)
THEN
990 dvas(1:nsgfa(iset), 1:3) = matmul(transpose(bcon), dva(1:ncoa, 1:3))
991 force_a(1) = force_a(1) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 1))
992 force_a(2) = force_a(2) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 2))
993 force_a(3) = force_a(3) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 3))
998 lri_ppl_coef(ikind)%v_int(atom_a, 1:nfun) = lri_ppl_coef(ikind)%v_int(atom_a, 1:nfun) + work(1:nfun)
1000 IF (calculate_forces)
THEN
1001 force_thread(1, iatom) = force_thread(1, iatom) + force_a(1)
1002 force_thread(2, iatom) = force_thread(2, iatom) + force_a(2)
1003 force_thread(3, iatom) = force_thread(3, iatom) + force_a(3)
1004 force_thread(1, katom) = force_thread(1, katom) - force_a(1)
1005 force_thread(2, katom) = force_thread(2, katom) - force_a(2)
1006 force_thread(3, katom) = force_thread(3, katom) - force_a(3)
1007 IF (use_virial)
THEN
1013 DEALLOCATE (va, work)
1014 IF (calculate_forces)
THEN
1015 DEALLOCATE (dva, dvas)
1020 IF (calculate_forces)
THEN
1022 atom_a = atom_of_kind(iatom)
1023 ikind = kind_of(iatom)
1024 force(ikind)%gth_ppl(1, atom_a) = force(ikind)%gth_ppl(1, atom_a) + force_thread(1, iatom)
1025 force(ikind)%gth_ppl(2, atom_a) = force(ikind)%gth_ppl(2, atom_a) + force_thread(2, iatom)
1026 force(ikind)%gth_ppl(3, atom_a) = force(ikind)%gth_ppl(3, atom_a) + force_thread(3, iatom)
1029 DEALLOCATE (atom_of_kind, kind_of)
1031 IF (calculate_forces .AND. use_virial)
THEN
1032 virial%pv_ppl = virial%pv_ppl + pv_thread
1033 virial%pv_virial = virial%pv_virial + pv_thread
1036 DEALLOCATE (basis_set_list)
1038 CALL timestop(handle)