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)
174 libgrpp_local = .false.
176 IF (calculate_forces)
THEN
177 CALL timeset(routinen//
"_forces", handle)
179 CALL timeset(routinen, handle)
182 nkind =
SIZE(atomic_kind_set)
183 natom =
SIZE(particle_set)
188 cpassert(
PRESENT(cell_to_index) .AND.
ASSOCIATED(cell_to_index))
191 IF (calculate_forces .OR. doat)
THEN
192 IF (
SIZE(matrix_p, 1) == 2)
THEN
194 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
195 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
196 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
197 alpha_scalar=-2.0_dp, beta_scalar=1.0_dp)
201 force_thread = 0.0_dp
207 maxsgf=maxsgf, maxnset=maxnset, maxlppl=maxlppl, &
208 basis_type=basis_type)
210 maxl = max(maxlgto, maxlppl)
213 ldsab = max(maxco,
ncoset(maxlppl), maxsgf, maxlppl)
214 ldai =
ncoset(maxl + nder + 1)
216 ALLOCATE (basis_set_list(nkind))
218 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set_a, basis_type=basis_type)
219 IF (
ASSOCIATED(basis_set_a))
THEN
220 basis_set_list(ikind)%gto_basis_set => basis_set_a
222 NULLIFY (basis_set_list(ikind)%gto_basis_set)
270 ALLOCATE (hab(ldsab, ldsab, maxnset, maxnset), work(ldsab, ldsab*maxder))
271 ldai =
ncoset(2*maxlgto + 2*nder)
272 ALLOCATE (ppl_work(ldai, ldai, max(maxder, 2*maxlgto + 2*nder + 1)))
273 IF (calculate_forces .OR. doat)
THEN
274 ALLOCATE (pab(maxco, maxco, maxnset, maxnset))
276 ALLOCATE (ppl_fwork(ldai, ldai, maxder))
280 DO slot = 1, sab_orb(1)%nl_size
283 ALLOCATE (hab2(ldsab, ldsab, 4, maxnset, maxnset))
284 ALLOCATE (hab2_w(ldsab, ldsab, 6))
285 ALLOCATE (ppl_fwork(ldai, ldai, maxder))
288 ikind = sab_orb(1)%nlist_task(slot)%ikind
289 jkind = sab_orb(1)%nlist_task(slot)%jkind
290 iatom = sab_orb(1)%nlist_task(slot)%iatom
291 jatom = sab_orb(1)%nlist_task(slot)%jatom
292 cellind(:) = sab_orb(1)%nlist_task(slot)%cell(:)
293 rab(1:3) = sab_orb(1)%nlist_task(slot)%r(1:3)
295 basis_set_a => basis_set_list(ikind)%gto_basis_set
296 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
297 basis_set_b => basis_set_list(jkind)%gto_basis_set
298 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
304 first_sgfa => basis_set_a%first_sgf
305 la_max => basis_set_a%lmax
306 la_min => basis_set_a%lmin
307 npgfa => basis_set_a%npgf
308 nseta = basis_set_a%nset
309 nsgfa => basis_set_a%nsgf_set
310 rpgfa => basis_set_a%pgf_radius
311 set_radius_a => basis_set_a%set_radius
312 sphi_a => basis_set_a%sphi
313 zeta => basis_set_a%zet
315 first_sgfb => basis_set_b%first_sgf
316 lb_max => basis_set_b%lmax
317 lb_min => basis_set_b%lmin
318 npgfb => basis_set_b%npgf
319 nsetb = basis_set_b%nset
320 nsgfb => basis_set_b%nsgf_set
321 rpgfb => basis_set_b%pgf_radius
322 set_radius_b => basis_set_b%set_radius
323 sphi_b => basis_set_b%sphi
324 zetb => basis_set_b%zet
326 dab = sqrt(sum(rab*rab))
329 img = cell_to_index(cellind(1), cellind(2), cellind(3))
335 IF (iatom == jatom)
THEN
342 IF (iatom <= jatom)
THEN
352 NULLIFY (h1_1block, h1_2block, h1_3block)
355 row=irow, col=icol, block=h1_1block, found=found)
357 row=irow, col=icol, block=h1_2block, found=found)
359 row=irow, col=icol, block=h1_3block, found=found)
364 IF (calculate_forces .OR. doat)
THEN
367 IF (
ASSOCIATED(p_block))
THEN
369 ncoa = npgfa(iset)*
ncoset(la_max(iset))
370 sgfa = first_sgfa(1, iset)
372 ncob = npgfb(jset)*
ncoset(lb_max(jset))
373 sgfb = first_sgfb(1, jset)
376 IF (iatom <= jatom)
THEN
377 work(1:ncoa, 1:nsgfb(jset)) = matmul(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1), &
378 p_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1))
380 work(1:ncoa, 1:nsgfb(jset)) = matmul(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1), &
381 transpose(p_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1)))
384 pab(1:ncoa, 1:ncob, iset, jset) = matmul(work(1:ncoa, 1:nsgfb(jset)), &
385 transpose(sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1)))
392 IF (do_dr) hab2 = 0._dp
397 CALL get_qs_kind(qs_kind_set(kkind), gth_potential=gth_potential, &
398 sgp_potential=sgp_potential)
399 ecp_semi_local = .false.
400 only_gaussians = .true.
401 IF (
ASSOCIATED(gth_potential))
THEN
403 alpha_ppl=alpha, cexp_ppl=cexp_ppl, &
404 lpot_present=lpotextended, ppl_radius=ppl_radius)
407 nct_ppl(1) =
SIZE(cexp_ppl)
408 cval_ppl(1:nct_ppl(1), 1) = cexp_ppl(1:nct_ppl(1))
409 IF (lpotextended)
THEN
411 nexp_lpot=nexp_lpot, alpha_lpot=alpha_lpot, nct_lpot=nct_lpot, &
413 cpassert(nexp_lpot < nexp_max)
414 nexp_ppl = nexp_lpot + 1
415 alpha_ppl(2:nexp_lpot + 1) = alpha_lpot(1:nexp_lpot)
416 nct_ppl(2:nexp_lpot + 1) = nct_lpot(1:nexp_lpot)
418 cval_ppl(1:nct_lpot(i), i + 1) = cval_lpot(1:nct_lpot(i), i)
421 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
422 CALL get_potential(potential=sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local, &
423 ppl_radius=ppl_radius)
425 CALL get_potential(potential=sgp_potential, nloc=nloc, nrloc=nrloc, aloc=aloc, bloc=bloc)
427 cpassert(nexp_ppl <= nexp_max)
428 nct_ppl(1:nloc) = nrloc(1:nloc)
429 alpha_ppl(1:nloc) = bloc(1:nloc)
430 cval_ppl(1, 1:nloc) = aloc(1:nloc)
431 only_gaussians = .false.
433 CALL get_potential(potential=sgp_potential, n_local=n_local, a_local=a_local, c_local=c_local)
435 cpassert(nexp_ppl <= nexp_max)
436 nct_ppl(1:n_local) = 1
437 alpha_ppl(1:n_local) = a_local(1:n_local)
438 cval_ppl(1, 1:n_local) = c_local(1:n_local)
440 IF (ecp_semi_local)
THEN
442 npot=npot, nrpot=nrpot, apot=apot, bpot=bpot)
443 ELSEIF (ecp_local)
THEN
444 IF (sum(abs(aloc(1:nloc))) < 1.0e-12_dp) cycle
456 dac = sqrt(sum(rac*rac))
457 rbc(:) = rac(:) - rab(:)
458 dbc = sqrt(sum(rbc*rbc))
459 IF ((maxval(set_radius_a(:)) + ppl_radius < dac) .OR. &
460 (maxval(set_radius_b(:)) + ppl_radius < dbc))
THEN
465 IF (set_radius_a(iset) + ppl_radius < dac) cycle
466 ncoa = npgfa(iset)*
ncoset(la_max(iset))
467 sgfa = first_sgfa(1, iset)
469 IF (set_radius_b(jset) + ppl_radius < dbc) cycle
470 ncob = npgfb(jset)*
ncoset(lb_max(jset))
471 sgfb = first_sgfb(1, jset)
472 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
475 atk0 = f0*sum(hab(1:ncoa, 1:ncob, iset, jset)* &
476 pab(1:ncoa, 1:ncob, iset, jset))
478 IF (calculate_forces)
THEN
483 IF (only_gaussians)
THEN
485 la_max(iset), la_min(iset), npgfa(iset), &
486 rpgfa(:, iset), zeta(:, iset), &
487 lb_max(jset), lb_min(jset), npgfb(jset), &
488 rpgfb(:, jset), zetb(:, jset), &
489 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
490 rab, dab, rac, dac, rbc, dbc, &
491 hab(:, :, iset, jset), ppl_work, pab(:, :, iset, jset), &
492 force_a, force_b, ppl_fwork)
493 ELSEIF (libgrpp_local)
THEN
496 rpgfa(:, iset), zeta(:, iset), &
497 lb_max(jset), lb_min(jset), npgfb(jset), &
498 rpgfb(:, jset), zetb(:, jset), &
499 nexp_ppl, alpha_ppl, cval_ppl(1, :), nct_ppl, &
500 ppl_radius, rab, dab, rac, dac, dbc, &
501 hab(:, :, iset, jset), pab(:, :, iset, jset), &
506 la_max(iset), la_min(iset), npgfa(iset), &
507 rpgfa(:, iset), zeta(:, iset), &
508 lb_max(jset), lb_min(jset), npgfb(jset), &
509 rpgfb(:, jset), zetb(:, jset), &
510 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
511 rab, dab, rac, dac, rbc, dbc, &
512 hab(:, :, iset, jset), ppl_work, pab(:, :, iset, jset), &
513 force_a, force_b, ppl_fwork)
516 IF (ecp_semi_local)
THEN
520 rpgfa(:, iset), zeta(:, iset), &
521 lb_max(jset), lb_min(jset), npgfb(jset), &
522 rpgfb(:, jset), zetb(:, jset), &
523 slmax, npot, bpot, apot, nrpot, &
524 ppl_radius, rab, dab, rac, dac, dbc, &
525 hab(:, :, iset, jset), pab(:, :, iset, jset), &
533 force_thread(1, iatom) = force_thread(1, iatom) + f0*force_a(1)
534 force_thread(2, iatom) = force_thread(2, iatom) + f0*force_a(2)
535 force_thread(3, iatom) = force_thread(3, iatom) + f0*force_a(3)
536 force_thread(1, katom) = force_thread(1, katom) - f0*force_a(1)
537 force_thread(2, katom) = force_thread(2, katom) - f0*force_a(2)
538 force_thread(3, katom) = force_thread(3, katom) - f0*force_a(3)
540 force_thread(1, jatom) = force_thread(1, jatom) + f0*force_b(1)
541 force_thread(2, jatom) = force_thread(2, jatom) + f0*force_b(2)
542 force_thread(3, jatom) = force_thread(3, jatom) + f0*force_b(3)
543 force_thread(1, katom) = force_thread(1, katom) - f0*force_b(1)
544 force_thread(2, katom) = force_thread(2, katom) - f0*force_b(2)
545 force_thread(3, katom) = force_thread(3, katom) - f0*force_b(3)
554 la_max(iset), la_min(iset), npgfa(iset), &
555 rpgfa(:, iset), zeta(:, iset), &
556 lb_max(jset), lb_min(jset), npgfb(jset), &
557 rpgfb(:, jset), zetb(:, jset), &
558 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
559 rab, dab, rac, dac, rbc, dbc, &
560 vab=hab(:, :, iset, jset), s=ppl_work, &
561 hab2=hab2(:, :, :, iset, jset), hab2_work=hab2_w, fs=ppl_fwork, &
562 deltar=deltar, iatom=iatom, jatom=jatom, katom=katom)
563 IF (ecp_semi_local)
THEN
565 cpabort(
"Option not implemented")
568 IF (only_gaussians)
THEN
572 la_max(iset), la_min(iset), npgfa(iset), &
573 rpgfa(:, iset), zeta(:, iset), &
574 lb_max(jset), lb_min(jset), npgfb(jset), &
575 rpgfb(:, jset), zetb(:, jset), &
576 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
577 rab, dab, rac, dac, rbc, dbc, hab(:, :, iset, jset), ppl_work)
579 ELSEIF (libgrpp_local)
THEN
583 rpgfa(:, iset), zeta(:, iset), &
584 lb_max(jset), lb_min(jset), npgfb(jset), &
585 rpgfb(:, jset), zetb(:, jset), &
586 nexp_ppl, alpha_ppl, cval_ppl(1, :), nct_ppl, &
587 ppl_radius, rab, dab, rac, dac, dbc, &
588 hab(:, :, iset, jset))
592 la_max(iset), la_min(iset), npgfa(iset), &
593 rpgfa(:, iset), zeta(:, iset), &
594 lb_max(jset), lb_min(jset), npgfb(jset), &
595 rpgfb(:, jset), zetb(:, jset), &
596 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
597 rab, dab, rac, dac, rbc, dbc, hab(:, :, iset, jset), ppl_work)
600 IF (ecp_semi_local)
THEN
604 rpgfa(:, iset), zeta(:, iset), &
605 lb_max(jset), lb_min(jset), npgfb(jset), &
606 rpgfb(:, jset), zetb(:, jset), &
607 slmax, npot, bpot, apot, nrpot, &
608 ppl_radius, rab, dab, rac, dac, dbc, &
609 hab(:, :, iset, jset))
615 atk1 = f0*sum(hab(1:ncoa, 1:ncob, iset, jset)* &
616 pab(1:ncoa, 1:ncob, iset, jset))
617 at_thread(katom) = at_thread(katom) + (atk1 - atk0)
625 IF (.NOT. do_dr)
THEN
627 ncoa = npgfa(iset)*
ncoset(la_max(iset))
628 sgfa = first_sgfa(1, iset)
630 ncob = npgfb(jset)*
ncoset(lb_max(jset))
631 sgfb = first_sgfb(1, jset)
636 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab(1:ncoa, 1:ncob, iset, jset), &
637 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
639 IF (iatom <= jatom)
THEN
640 h_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
641 h_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
642 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
644 h_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
645 h_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
646 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
654 ncoa = npgfa(iset)*
ncoset(la_max(iset))
655 sgfa = first_sgfa(1, iset)
657 ncob = npgfb(jset)*
ncoset(lb_max(jset))
658 sgfb = first_sgfb(1, jset)
659 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 1, iset, jset), &
660 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
663 IF (iatom <= jatom)
THEN
664 h1_1block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
665 h1_1block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
666 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
669 h1_1block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
670 h1_1block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
671 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
674 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 2, iset, jset), &
675 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
678 IF (iatom <= jatom)
THEN
679 h1_2block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
680 h1_2block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
681 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
684 h1_2block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
685 h1_2block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
686 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
689 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 3, iset, jset), &
690 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
692 IF (iatom <= jatom)
THEN
693 h1_3block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
694 h1_3block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
695 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
698 h1_3block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
699 h1_3block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
700 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
706 IF (do_dr)
DEALLOCATE (hab2, ppl_fwork, hab2_w)
709 DEALLOCATE (hab, work, ppl_work)
710 IF (calculate_forces .OR. doat)
THEN
711 DEALLOCATE (pab, ppl_fwork)
728 DEALLOCATE (basis_set_list)
730 IF (calculate_forces .OR. doat)
THEN
733 IF (
SIZE(matrix_p, 1) == 2)
THEN
735 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
736 alpha_scalar=0.5_dp, beta_scalar=0.5_dp)
737 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
738 alpha_scalar=-1.0_dp, beta_scalar=1.0_dp)
743 IF (calculate_forces)
THEN
747 atom_a = atom_of_kind(iatom)
748 ikind = kind_of(iatom)
749 force(ikind)%gth_ppl(:, atom_a) = force(ikind)%gth_ppl(:, atom_a) + force_thread(:, iatom)
752 DEALLOCATE (atom_of_kind, kind_of)
755 atcore(1:natom) = atcore(1:natom) + at_thread(1:natom)
758 IF (calculate_forces .AND. use_virial)
THEN
759 virial%pv_ppl = virial%pv_ppl + pv_thread
760 virial%pv_virial = virial%pv_virial + pv_thread
763 CALL timestop(handle)
781 qs_kind_set, atomic_kind_set, particle_set, sac_ppl, &
787 LOGICAL,
INTENT(IN) :: calculate_forces
788 LOGICAL :: use_virial
789 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
794 CHARACTER(LEN=*),
INTENT(IN) :: basis_type
796 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_core_ppl_ri'
797 INTEGER,
PARAMETER :: nexp_max = 30
799 INTEGER :: atom_a, handle, i, iatom, ikind, iset, katom, kkind, maxco, maxsgf, n_local, &
800 natom, ncoa, nexp_lpot, nexp_ppl, nfun, nkind, nloc, nseta, sgfa, sgfb, slot
801 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
802 INTEGER,
DIMENSION(1:10) :: nrloc
803 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, nct_lpot, npgfa, nsgfa
804 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa
805 INTEGER,
DIMENSION(nexp_max) :: nct_ppl
806 LOGICAL :: ecp_local, ecp_semi_local, lpotextended
807 REAL(kind=
dp) :: alpha, dac, ppl_radius
808 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: va, work
809 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: dva, dvas
810 REAL(kind=
dp),
DIMENSION(1:10) :: aloc, bloc
811 REAL(kind=
dp),
DIMENSION(3) :: force_a, rac
812 REAL(kind=
dp),
DIMENSION(3, 3) :: pv_thread
816 REAL(kind=
dp),
DIMENSION(nexp_max) :: alpha_ppl
817 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: bcon, cval_lpot, rpgfa, sphi_a, zeta
818 REAL(kind=
dp),
DIMENSION(:),
POINTER :: a_local, alpha_lpot, c_local, cexp_ppl, &
820 REAL(kind=
dp),
DIMENSION(4, nexp_max) :: cval_ppl
821 REAL(kind=
dp),
DIMENSION(3, SIZE(particle_set)) :: force_thread
829 IF (calculate_forces)
THEN
830 CALL timeset(routinen//
"_forces", handle)
832 CALL timeset(routinen, handle)
835 nkind =
SIZE(atomic_kind_set)
836 natom =
SIZE(particle_set)
838 force_thread = 0.0_dp
842 ALLOCATE (basis_set_list(nkind))
844 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set, basis_type=basis_type)
845 IF (
ASSOCIATED(basis_set))
THEN
846 basis_set_list(ikind)%gto_basis_set => basis_set
848 NULLIFY (basis_set_list(ikind)%gto_basis_set)
852 CALL get_qs_kind_set(qs_kind_set, maxco=maxco, maxsgf=maxsgf, basis_type=basis_type)
876 ALLOCATE (va(maxco), work(maxsgf))
877 IF (calculate_forces)
THEN
878 ALLOCATE (dva(maxco, 3), dvas(maxco, 3))
882 DO slot = 1, sac_ppl(1)%nl_size
884 ikind = sac_ppl(1)%nlist_task(slot)%ikind
885 kkind = sac_ppl(1)%nlist_task(slot)%jkind
886 iatom = sac_ppl(1)%nlist_task(slot)%iatom
887 katom = sac_ppl(1)%nlist_task(slot)%jatom
888 rac(1:3) = sac_ppl(1)%nlist_task(slot)%r(1:3)
889 atom_a = atom_of_kind(iatom)
891 basis_set => basis_set_list(ikind)%gto_basis_set
892 IF (.NOT.
ASSOCIATED(basis_set)) cycle
895 first_sgfa => basis_set%first_sgf
896 la_max => basis_set%lmax
897 la_min => basis_set%lmin
898 npgfa => basis_set%npgf
899 nseta = basis_set%nset
900 nsgfa => basis_set%nsgf_set
901 nfun = basis_set%nsgf
902 rpgfa => basis_set%pgf_radius
903 set_radius_a => basis_set%set_radius
904 sphi_a => basis_set%sphi
905 zeta => basis_set%zet
907 CALL get_qs_kind(qs_kind_set(kkind), gth_potential=gth_potential, &
908 sgp_potential=sgp_potential)
909 ecp_semi_local = .false.
910 IF (
ASSOCIATED(gth_potential))
THEN
912 alpha_ppl=alpha, cexp_ppl=cexp_ppl, &
913 lpot_present=lpotextended, ppl_radius=ppl_radius)
916 nct_ppl(1) =
SIZE(cexp_ppl)
917 cval_ppl(1:nct_ppl(1), 1) = cexp_ppl(1:nct_ppl(1))
918 IF (lpotextended)
THEN
920 nexp_lpot=nexp_lpot, alpha_lpot=alpha_lpot, nct_lpot=nct_lpot, cval_lpot=cval_lpot)
921 cpassert(nexp_lpot < nexp_max)
922 nexp_ppl = nexp_lpot + 1
923 alpha_ppl(2:nexp_lpot + 1) = alpha_lpot(1:nexp_lpot)
924 nct_ppl(2:nexp_lpot + 1) = nct_lpot(1:nexp_lpot)
926 cval_ppl(1:nct_lpot(i), i + 1) = cval_lpot(1:nct_lpot(i), i)
929 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
930 CALL get_potential(potential=sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local, &
931 ppl_radius=ppl_radius)
932 cpassert(.NOT. ecp_semi_local)
934 CALL get_potential(potential=sgp_potential, nloc=nloc, nrloc=nrloc, aloc=aloc, bloc=bloc)
935 IF (sum(abs(aloc(1:nloc))) < 1.0e-12_dp) cycle
937 cpassert(nexp_ppl <= nexp_max)
938 nct_ppl(1:nloc) = nrloc(1:nloc)
939 alpha_ppl(1:nloc) = bloc(1:nloc)
940 cval_ppl(1, 1:nloc) = aloc(1:nloc)
942 CALL get_potential(potential=sgp_potential, n_local=n_local, a_local=a_local, c_local=c_local)
944 cpassert(nexp_ppl <= nexp_max)
945 nct_ppl(1:n_local) = 1
946 alpha_ppl(1:n_local) = a_local(1:n_local)
947 cval_ppl(1, 1:n_local) = c_local(1:n_local)
953 dac = sqrt(sum(rac*rac))
954 IF ((maxval(set_radius_a(:)) + ppl_radius < dac)) cycle
955 IF (calculate_forces) force_a = 0.0_dp
956 work(1:nfun) = 0.0_dp
959 IF (set_radius_a(iset) + ppl_radius < dac) cycle
961 IF (calculate_forces)
THEN
965 la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
966 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
971 la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
972 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
976 sgfa = first_sgfa(1, iset)
977 sgfb = sgfa + nsgfa(iset) - 1
978 ncoa = npgfa(iset)*
ncoset(la_max(iset))
979 bcon => sphi_a(1:ncoa, sgfa:sgfb)
980 work(sgfa:sgfb) = matmul(transpose(bcon), va(1:ncoa))
981 IF (calculate_forces)
THEN
982 dvas(1:nsgfa(iset), 1:3) = matmul(transpose(bcon), dva(1:ncoa, 1:3))
983 force_a(1) = force_a(1) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 1))
984 force_a(2) = force_a(2) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 2))
985 force_a(3) = force_a(3) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 3))
990 lri_ppl_coef(ikind)%v_int(atom_a, 1:nfun) = lri_ppl_coef(ikind)%v_int(atom_a, 1:nfun) + work(1:nfun)
992 IF (calculate_forces)
THEN
993 force_thread(1, iatom) = force_thread(1, iatom) + force_a(1)
994 force_thread(2, iatom) = force_thread(2, iatom) + force_a(2)
995 force_thread(3, iatom) = force_thread(3, iatom) + force_a(3)
996 force_thread(1, katom) = force_thread(1, katom) - force_a(1)
997 force_thread(2, katom) = force_thread(2, katom) - force_a(2)
998 force_thread(3, katom) = force_thread(3, katom) - force_a(3)
1005 DEALLOCATE (va, work)
1006 IF (calculate_forces)
THEN
1007 DEALLOCATE (dva, dvas)
1012 IF (calculate_forces)
THEN
1014 atom_a = atom_of_kind(iatom)
1015 ikind = kind_of(iatom)
1016 force(ikind)%gth_ppl(1, atom_a) = force(ikind)%gth_ppl(1, atom_a) + force_thread(1, iatom)
1017 force(ikind)%gth_ppl(2, atom_a) = force(ikind)%gth_ppl(2, atom_a) + force_thread(2, iatom)
1018 force(ikind)%gth_ppl(3, atom_a) = force(ikind)%gth_ppl(3, atom_a) + force_thread(3, iatom)
1021 DEALLOCATE (atom_of_kind, kind_of)
1023 IF (calculate_forces .AND. use_virial)
THEN
1024 virial%pv_ppl = virial%pv_ppl + pv_thread
1025 virial%pv_virial = virial%pv_virial + pv_thread
1028 DEALLOCATE (basis_set_list)
1030 CALL timestop(handle)