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 cpassert(
PRESENT(cell_to_index) .AND.
ASSOCIATED(cell_to_index))
195 IF (calculate_forces .OR. doat)
THEN
196 IF (
SIZE(matrix_p, 1) == 2)
THEN
198 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
199 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
200 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
201 alpha_scalar=-2.0_dp, beta_scalar=1.0_dp)
205 force_thread = 0.0_dp
211 maxsgf=maxsgf, maxnset=maxnset, maxlppl=maxlppl, &
212 basis_type=basis_type)
214 maxl = max(maxlgto, maxlppl)
217 ldsab = max(maxco,
ncoset(maxlppl), maxsgf, maxlppl)
218 ldai =
ncoset(maxl + nder + 1)
220 ALLOCATE (basis_set_list(nkind))
222 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set_a, basis_type=basis_type)
223 IF (
ASSOCIATED(basis_set_a))
THEN
224 basis_set_list(ikind)%gto_basis_set => basis_set_a
226 NULLIFY (basis_set_list(ikind)%gto_basis_set)
274 ALLOCATE (hab(ldsab, ldsab, maxnset, maxnset), work(ldsab, ldsab*maxder))
275 ldai =
ncoset(2*maxlgto + 2*nder)
276 ALLOCATE (ppl_work(ldai, ldai, max(maxder, 2*maxlgto + 2*nder + 1)))
277 IF (calculate_forces .OR. doat)
THEN
278 ALLOCATE (pab(maxco, maxco, maxnset, maxnset))
280 ALLOCATE (ppl_fwork(ldai, ldai, maxder))
284 DO slot = 1, sab_orb(1)%nl_size
287 ALLOCATE (hab2(ldsab, ldsab, 4, maxnset, maxnset))
288 ALLOCATE (hab2_w(ldsab, ldsab, 6))
289 ALLOCATE (ppl_fwork(ldai, ldai, maxder))
292 ikind = sab_orb(1)%nlist_task(slot)%ikind
293 jkind = sab_orb(1)%nlist_task(slot)%jkind
294 iatom = sab_orb(1)%nlist_task(slot)%iatom
295 jatom = sab_orb(1)%nlist_task(slot)%jatom
296 cellind(:) = sab_orb(1)%nlist_task(slot)%cell(:)
297 rab(1:3) = sab_orb(1)%nlist_task(slot)%r(1:3)
299 basis_set_a => basis_set_list(ikind)%gto_basis_set
300 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
301 basis_set_b => basis_set_list(jkind)%gto_basis_set
302 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
308 first_sgfa => basis_set_a%first_sgf
309 la_max => basis_set_a%lmax
310 la_min => basis_set_a%lmin
311 npgfa => basis_set_a%npgf
312 nseta = basis_set_a%nset
313 nsgfa => basis_set_a%nsgf_set
314 rpgfa => basis_set_a%pgf_radius
315 set_radius_a => basis_set_a%set_radius
316 sphi_a => basis_set_a%sphi
317 zeta => basis_set_a%zet
319 first_sgfb => basis_set_b%first_sgf
320 lb_max => basis_set_b%lmax
321 lb_min => basis_set_b%lmin
322 npgfb => basis_set_b%npgf
323 nsetb = basis_set_b%nset
324 nsgfb => basis_set_b%nsgf_set
325 rpgfb => basis_set_b%pgf_radius
326 set_radius_b => basis_set_b%set_radius
327 sphi_b => basis_set_b%sphi
328 zetb => basis_set_b%zet
330 dab = sqrt(sum(rab*rab))
333 img = cell_to_index(cellind(1), cellind(2), cellind(3))
339 IF (iatom == jatom)
THEN
346 IF (iatom <= jatom)
THEN
356 NULLIFY (h1_1block, h1_2block, h1_3block)
359 row=irow, col=icol, block=h1_1block, found=found)
361 row=irow, col=icol, block=h1_2block, found=found)
363 row=irow, col=icol, block=h1_3block, found=found)
368 IF (calculate_forces .OR. doat)
THEN
371 IF (
ASSOCIATED(p_block))
THEN
373 ncoa = npgfa(iset)*
ncoset(la_max(iset))
374 sgfa = first_sgfa(1, iset)
376 ncob = npgfb(jset)*
ncoset(lb_max(jset))
377 sgfb = first_sgfb(1, jset)
380 IF (iatom <= jatom)
THEN
381 work(1:ncoa, 1:nsgfb(jset)) = matmul(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1), &
382 p_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1))
384 work(1:ncoa, 1:nsgfb(jset)) = matmul(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1), &
385 transpose(p_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1)))
388 pab(1:ncoa, 1:ncob, iset, jset) = matmul(work(1:ncoa, 1:nsgfb(jset)), &
389 transpose(sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1)))
396 IF (do_dr) hab2 = 0._dp
401 CALL get_qs_kind(qs_kind_set(kkind), gth_potential=gth_potential, &
402 sgp_potential=sgp_potential)
403 ecp_semi_local = .false.
404 only_gaussians = .true.
405 IF (
ASSOCIATED(gth_potential))
THEN
407 alpha_ppl=alpha, cexp_ppl=cexp_ppl, &
408 lpot_present=lpotextended, ppl_radius=ppl_radius)
411 nct_ppl(1) =
SIZE(cexp_ppl)
412 cval_ppl(1:nct_ppl(1), 1) = cexp_ppl(1:nct_ppl(1))
413 IF (lpotextended)
THEN
415 nexp_lpot=nexp_lpot, alpha_lpot=alpha_lpot, nct_lpot=nct_lpot, &
417 cpassert(nexp_lpot < nexp_max)
418 nexp_ppl = nexp_lpot + 1
419 alpha_ppl(2:nexp_lpot + 1) = alpha_lpot(1:nexp_lpot)
420 nct_ppl(2:nexp_lpot + 1) = nct_lpot(1:nexp_lpot)
422 cval_ppl(1:nct_lpot(i), i + 1) = cval_lpot(1:nct_lpot(i), i)
425 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
426 CALL get_potential(potential=sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local, &
427 ppl_radius=ppl_radius)
429 CALL get_potential(potential=sgp_potential, nloc=nloc, nrloc=nrloc, aloc=aloc, bloc=bloc)
431 cpassert(nexp_ppl <= nexp_max)
432 nct_ppl(1:nloc) = nrloc(1:nloc)
433 alpha_ppl(1:nloc) = bloc(1:nloc)
434 cval_ppl(1, 1:nloc) = aloc(1:nloc)
435 only_gaussians = .false.
437 CALL get_potential(potential=sgp_potential, n_local=n_local, a_local=a_local, c_local=c_local)
439 cpassert(nexp_ppl <= nexp_max)
440 nct_ppl(1:n_local) = 1
441 alpha_ppl(1:n_local) = a_local(1:n_local)
442 cval_ppl(1, 1:n_local) = c_local(1:n_local)
444 IF (ecp_semi_local)
THEN
446 npot=npot, nrpot=nrpot, apot=apot, bpot=bpot)
447 ELSEIF (ecp_local)
THEN
448 IF (sum(abs(aloc(1:nloc))) < 1.0e-12_dp) cycle
460 dac = sqrt(sum(rac*rac))
461 rbc(:) = rac(:) - rab(:)
462 dbc = sqrt(sum(rbc*rbc))
463 IF ((maxval(set_radius_a(:)) + ppl_radius < dac) .OR. &
464 (maxval(set_radius_b(:)) + ppl_radius < dbc))
THEN
469 IF (set_radius_a(iset) + ppl_radius < dac) cycle
470 ncoa = npgfa(iset)*
ncoset(la_max(iset))
471 sgfa = first_sgfa(1, iset)
473 IF (set_radius_b(jset) + ppl_radius < dbc) cycle
474 ncob = npgfb(jset)*
ncoset(lb_max(jset))
475 sgfb = first_sgfb(1, jset)
476 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
479 atk0 = f0*sum(hab(1:ncoa, 1:ncob, iset, jset)* &
480 pab(1:ncoa, 1:ncob, iset, jset))
482 IF (calculate_forces)
THEN
487 IF (only_gaussians)
THEN
489 la_max(iset), la_min(iset), npgfa(iset), &
490 rpgfa(:, iset), zeta(:, iset), &
491 lb_max(jset), lb_min(jset), npgfb(jset), &
492 rpgfb(:, jset), zetb(:, jset), &
493 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
494 rab, dab, rac, dac, rbc, dbc, &
495 hab(:, :, iset, jset), ppl_work, pab(:, :, iset, jset), &
496 force_a, force_b, ppl_fwork)
497 ELSEIF (libgrpp_local)
THEN
500 rpgfa(:, iset), zeta(:, iset), &
501 lb_max(jset), lb_min(jset), npgfb(jset), &
502 rpgfb(:, jset), zetb(:, jset), &
503 nexp_ppl, alpha_ppl, cval_ppl(1, :), nct_ppl, &
504 ppl_radius, rab, dab, rac, dac, dbc, &
505 hab(:, :, iset, jset), pab(:, :, iset, jset), &
510 la_max(iset), la_min(iset), npgfa(iset), &
511 rpgfa(:, iset), zeta(:, iset), &
512 lb_max(jset), lb_min(jset), npgfb(jset), &
513 rpgfb(:, jset), zetb(:, jset), &
514 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
515 rab, dab, rac, dac, rbc, dbc, &
516 hab(:, :, iset, jset), ppl_work, pab(:, :, iset, jset), &
517 force_a, force_b, ppl_fwork)
520 IF (ecp_semi_local)
THEN
524 rpgfa(:, iset), zeta(:, iset), &
525 lb_max(jset), lb_min(jset), npgfb(jset), &
526 rpgfb(:, jset), zetb(:, jset), &
527 slmax, npot, bpot, apot, nrpot, &
528 ppl_radius, rab, dab, rac, dac, dbc, &
529 hab(:, :, iset, jset), pab(:, :, iset, jset), &
537 force_thread(1, iatom) = force_thread(1, iatom) + f0*force_a(1)
538 force_thread(2, iatom) = force_thread(2, iatom) + f0*force_a(2)
539 force_thread(3, iatom) = force_thread(3, iatom) + f0*force_a(3)
540 force_thread(1, katom) = force_thread(1, katom) - f0*force_a(1)
541 force_thread(2, katom) = force_thread(2, katom) - f0*force_a(2)
542 force_thread(3, katom) = force_thread(3, katom) - f0*force_a(3)
544 force_thread(1, jatom) = force_thread(1, jatom) + f0*force_b(1)
545 force_thread(2, jatom) = force_thread(2, jatom) + f0*force_b(2)
546 force_thread(3, jatom) = force_thread(3, jatom) + f0*force_b(3)
547 force_thread(1, katom) = force_thread(1, katom) - f0*force_b(1)
548 force_thread(2, katom) = force_thread(2, katom) - f0*force_b(2)
549 force_thread(3, katom) = force_thread(3, katom) - f0*force_b(3)
558 la_max(iset), la_min(iset), npgfa(iset), &
559 rpgfa(:, iset), zeta(:, iset), &
560 lb_max(jset), lb_min(jset), npgfb(jset), &
561 rpgfb(:, jset), zetb(:, jset), &
562 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
563 rab, dab, rac, dac, rbc, dbc, &
564 vab=hab(:, :, iset, jset), s=ppl_work, &
565 hab2=hab2(:, :, :, iset, jset), hab2_work=hab2_w, fs=ppl_fwork, &
566 deltar=deltar, iatom=iatom, jatom=jatom, katom=katom)
567 IF (ecp_semi_local)
THEN
569 cpabort(
"Option not implemented")
572 IF (only_gaussians)
THEN
576 la_max(iset), la_min(iset), npgfa(iset), &
577 rpgfa(:, iset), zeta(:, iset), &
578 lb_max(jset), lb_min(jset), npgfb(jset), &
579 rpgfb(:, jset), zetb(:, jset), &
580 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
581 rab, dab, rac, dac, rbc, dbc, hab(:, :, iset, jset), ppl_work)
583 ELSEIF (libgrpp_local)
THEN
587 rpgfa(:, iset), zeta(:, iset), &
588 lb_max(jset), lb_min(jset), npgfb(jset), &
589 rpgfb(:, jset), zetb(:, jset), &
590 nexp_ppl, alpha_ppl, cval_ppl(1, :), nct_ppl, &
591 ppl_radius, rab, dab, rac, dac, dbc, &
592 hab(:, :, iset, jset))
596 la_max(iset), la_min(iset), npgfa(iset), &
597 rpgfa(:, iset), zeta(:, iset), &
598 lb_max(jset), lb_min(jset), npgfb(jset), &
599 rpgfb(:, jset), zetb(:, jset), &
600 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
601 rab, dab, rac, dac, rbc, dbc, hab(:, :, iset, jset), ppl_work)
604 IF (ecp_semi_local)
THEN
608 rpgfa(:, iset), zeta(:, iset), &
609 lb_max(jset), lb_min(jset), npgfb(jset), &
610 rpgfb(:, jset), zetb(:, jset), &
611 slmax, npot, bpot, apot, nrpot, &
612 ppl_radius, rab, dab, rac, dac, dbc, &
613 hab(:, :, iset, jset))
619 atk1 = f0*sum(hab(1:ncoa, 1:ncob, iset, jset)* &
620 pab(1:ncoa, 1:ncob, iset, jset))
621 at_thread(katom) = at_thread(katom) + (atk1 - atk0)
629 IF (.NOT. do_dr)
THEN
631 ncoa = npgfa(iset)*
ncoset(la_max(iset))
632 sgfa = first_sgfa(1, iset)
634 ncob = npgfb(jset)*
ncoset(lb_max(jset))
635 sgfb = first_sgfb(1, jset)
640 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab(1:ncoa, 1:ncob, iset, jset), &
641 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
643 IF (iatom <= jatom)
THEN
644 h_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
645 h_block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
646 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
648 h_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
649 h_block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
650 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
658 ncoa = npgfa(iset)*
ncoset(la_max(iset))
659 sgfa = first_sgfa(1, iset)
661 ncob = npgfb(jset)*
ncoset(lb_max(jset))
662 sgfb = first_sgfb(1, jset)
663 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 1, iset, jset), &
664 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
667 IF (iatom <= jatom)
THEN
668 h1_1block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
669 h1_1block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
670 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
673 h1_1block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
674 h1_1block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
675 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
678 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 2, iset, jset), &
679 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
682 IF (iatom <= jatom)
THEN
683 h1_2block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
684 h1_2block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
685 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
688 h1_2block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
689 h1_2block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
690 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
693 work(1:ncoa, 1:nsgfb(jset)) = matmul(hab2(1:ncoa, 1:ncob, 3, iset, jset), &
694 sphi_b(1:ncob, sgfb:sgfb + nsgfb(jset) - 1))
696 IF (iatom <= jatom)
THEN
697 h1_3block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) = &
698 h1_3block(sgfa:sgfa + nsgfa(iset) - 1, sgfb:sgfb + nsgfb(jset) - 1) + &
699 matmul(transpose(sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1)), work(1:ncoa, 1:nsgfb(jset)))
702 h1_3block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) = &
703 h1_3block(sgfb:sgfb + nsgfb(jset) - 1, sgfa:sgfa + nsgfa(iset) - 1) + &
704 matmul(transpose(work(1:ncoa, 1:nsgfb(jset))), sphi_a(1:ncoa, sgfa:sgfa + nsgfa(iset) - 1))
710 IF (do_dr)
DEALLOCATE (hab2, ppl_fwork, hab2_w)
713 DEALLOCATE (hab, work, ppl_work)
714 IF (calculate_forces .OR. doat)
THEN
715 DEALLOCATE (pab, ppl_fwork)
732 DEALLOCATE (basis_set_list)
734 IF (calculate_forces .OR. doat)
THEN
737 IF (
SIZE(matrix_p, 1) == 2)
THEN
739 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
740 alpha_scalar=0.5_dp, beta_scalar=0.5_dp)
741 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
742 alpha_scalar=-1.0_dp, beta_scalar=1.0_dp)
747 IF (calculate_forces)
THEN
751 atom_a = atom_of_kind(iatom)
752 ikind = kind_of(iatom)
753 force(ikind)%gth_ppl(:, atom_a) = force(ikind)%gth_ppl(:, atom_a) + force_thread(:, iatom)
756 DEALLOCATE (atom_of_kind, kind_of)
759 atcore(1:natom) = atcore(1:natom) + at_thread(1:natom)
762 IF (calculate_forces .AND. use_virial)
THEN
763 virial%pv_ppl = virial%pv_ppl + pv_thread
764 virial%pv_virial = virial%pv_virial + pv_thread
767 CALL timestop(handle)
785 qs_kind_set, atomic_kind_set, particle_set, sac_ppl, &
791 LOGICAL,
INTENT(IN) :: calculate_forces
792 LOGICAL :: use_virial
793 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
798 CHARACTER(LEN=*),
INTENT(IN) :: basis_type
800 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_core_ppl_ri'
801 INTEGER,
PARAMETER :: nexp_max = 30
803 INTEGER :: atom_a, handle, i, iatom, ikind, iset, katom, kkind, maxco, maxsgf, n_local, &
804 natom, ncoa, nexp_lpot, nexp_ppl, nfun, nkind, nloc, nseta, sgfa, sgfb, slot
805 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind, kind_of
806 INTEGER,
DIMENSION(1:10) :: nrloc
807 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, nct_lpot, npgfa, nsgfa
808 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa
809 INTEGER,
DIMENSION(nexp_max) :: nct_ppl
810 LOGICAL :: ecp_local, ecp_semi_local, lpotextended
811 REAL(kind=
dp) :: alpha, dac, ppl_radius
812 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: va, work
813 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: dva, dvas
814 REAL(kind=
dp),
DIMENSION(1:10) :: aloc, bloc
815 REAL(kind=
dp),
DIMENSION(3) :: force_a, rac
816 REAL(kind=
dp),
DIMENSION(3, 3) :: pv_thread
820 REAL(kind=
dp),
DIMENSION(nexp_max) :: alpha_ppl
821 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: bcon, cval_lpot, rpgfa, sphi_a, zeta
822 REAL(kind=
dp),
DIMENSION(:),
POINTER :: a_local, alpha_lpot, c_local, cexp_ppl, &
824 REAL(kind=
dp),
DIMENSION(4, nexp_max) :: cval_ppl
825 REAL(kind=
dp),
DIMENSION(3, SIZE(particle_set)) :: force_thread
833 IF (calculate_forces)
THEN
834 CALL timeset(routinen//
"_forces", handle)
836 CALL timeset(routinen, handle)
839 nkind =
SIZE(atomic_kind_set)
840 natom =
SIZE(particle_set)
842 force_thread = 0.0_dp
846 ALLOCATE (basis_set_list(nkind))
848 CALL get_qs_kind(qs_kind_set(ikind), basis_set=basis_set, basis_type=basis_type)
849 IF (
ASSOCIATED(basis_set))
THEN
850 basis_set_list(ikind)%gto_basis_set => basis_set
852 NULLIFY (basis_set_list(ikind)%gto_basis_set)
856 CALL get_qs_kind_set(qs_kind_set, maxco=maxco, maxsgf=maxsgf, basis_type=basis_type)
880 ALLOCATE (va(maxco), work(maxsgf))
881 IF (calculate_forces)
THEN
882 ALLOCATE (dva(maxco, 3), dvas(maxco, 3))
886 DO slot = 1, sac_ppl(1)%nl_size
888 ikind = sac_ppl(1)%nlist_task(slot)%ikind
889 kkind = sac_ppl(1)%nlist_task(slot)%jkind
890 iatom = sac_ppl(1)%nlist_task(slot)%iatom
891 katom = sac_ppl(1)%nlist_task(slot)%jatom
892 rac(1:3) = sac_ppl(1)%nlist_task(slot)%r(1:3)
893 atom_a = atom_of_kind(iatom)
895 basis_set => basis_set_list(ikind)%gto_basis_set
896 IF (.NOT.
ASSOCIATED(basis_set)) cycle
899 first_sgfa => basis_set%first_sgf
900 la_max => basis_set%lmax
901 la_min => basis_set%lmin
902 npgfa => basis_set%npgf
903 nseta = basis_set%nset
904 nsgfa => basis_set%nsgf_set
905 nfun = basis_set%nsgf
906 rpgfa => basis_set%pgf_radius
907 set_radius_a => basis_set%set_radius
908 sphi_a => basis_set%sphi
909 zeta => basis_set%zet
911 CALL get_qs_kind(qs_kind_set(kkind), gth_potential=gth_potential, &
912 sgp_potential=sgp_potential)
913 ecp_semi_local = .false.
914 IF (
ASSOCIATED(gth_potential))
THEN
916 alpha_ppl=alpha, cexp_ppl=cexp_ppl, &
917 lpot_present=lpotextended, ppl_radius=ppl_radius)
920 nct_ppl(1) =
SIZE(cexp_ppl)
921 cval_ppl(1:nct_ppl(1), 1) = cexp_ppl(1:nct_ppl(1))
922 IF (lpotextended)
THEN
924 nexp_lpot=nexp_lpot, alpha_lpot=alpha_lpot, nct_lpot=nct_lpot, cval_lpot=cval_lpot)
925 cpassert(nexp_lpot < nexp_max)
926 nexp_ppl = nexp_lpot + 1
927 alpha_ppl(2:nexp_lpot + 1) = alpha_lpot(1:nexp_lpot)
928 nct_ppl(2:nexp_lpot + 1) = nct_lpot(1:nexp_lpot)
930 cval_ppl(1:nct_lpot(i), i + 1) = cval_lpot(1:nct_lpot(i), i)
933 ELSE IF (
ASSOCIATED(sgp_potential))
THEN
934 CALL get_potential(potential=sgp_potential, ecp_local=ecp_local, ecp_semi_local=ecp_semi_local, &
935 ppl_radius=ppl_radius)
936 cpassert(.NOT. ecp_semi_local)
938 CALL get_potential(potential=sgp_potential, nloc=nloc, nrloc=nrloc, aloc=aloc, bloc=bloc)
939 IF (sum(abs(aloc(1:nloc))) < 1.0e-12_dp) cycle
941 cpassert(nexp_ppl <= nexp_max)
942 nct_ppl(1:nloc) = nrloc(1:nloc)
943 alpha_ppl(1:nloc) = bloc(1:nloc)
944 cval_ppl(1, 1:nloc) = aloc(1:nloc)
946 CALL get_potential(potential=sgp_potential, n_local=n_local, a_local=a_local, c_local=c_local)
948 cpassert(nexp_ppl <= nexp_max)
949 nct_ppl(1:n_local) = 1
950 alpha_ppl(1:n_local) = a_local(1:n_local)
951 cval_ppl(1, 1:n_local) = c_local(1:n_local)
957 dac = sqrt(sum(rac*rac))
958 IF ((maxval(set_radius_a(:)) + ppl_radius < dac)) cycle
959 IF (calculate_forces) force_a = 0.0_dp
960 work(1:nfun) = 0.0_dp
963 IF (set_radius_a(iset) + ppl_radius < dac) cycle
965 IF (calculate_forces)
THEN
969 la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
970 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
975 la_max(iset), la_min(iset), npgfa(iset), rpgfa(:, iset), zeta(:, iset), &
976 nexp_ppl, alpha_ppl, nct_ppl, cval_ppl, ppl_radius, &
980 sgfa = first_sgfa(1, iset)
981 sgfb = sgfa + nsgfa(iset) - 1
982 ncoa = npgfa(iset)*
ncoset(la_max(iset))
983 bcon => sphi_a(1:ncoa, sgfa:sgfb)
984 work(sgfa:sgfb) = matmul(transpose(bcon), va(1:ncoa))
985 IF (calculate_forces)
THEN
986 dvas(1:nsgfa(iset), 1:3) = matmul(transpose(bcon), dva(1:ncoa, 1:3))
987 force_a(1) = force_a(1) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 1))
988 force_a(2) = force_a(2) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 2))
989 force_a(3) = force_a(3) + sum(lri_ppl_coef(ikind)%acoef(atom_a, sgfa:sgfb)*dvas(1:nsgfa(iset), 3))
994 lri_ppl_coef(ikind)%v_int(atom_a, 1:nfun) = lri_ppl_coef(ikind)%v_int(atom_a, 1:nfun) + work(1:nfun)
996 IF (calculate_forces)
THEN
997 force_thread(1, iatom) = force_thread(1, iatom) + force_a(1)
998 force_thread(2, iatom) = force_thread(2, iatom) + force_a(2)
999 force_thread(3, iatom) = force_thread(3, iatom) + force_a(3)
1000 force_thread(1, katom) = force_thread(1, katom) - force_a(1)
1001 force_thread(2, katom) = force_thread(2, katom) - force_a(2)
1002 force_thread(3, katom) = force_thread(3, katom) - force_a(3)
1003 IF (use_virial)
THEN
1009 DEALLOCATE (va, work)
1010 IF (calculate_forces)
THEN
1011 DEALLOCATE (dva, dvas)
1016 IF (calculate_forces)
THEN
1018 atom_a = atom_of_kind(iatom)
1019 ikind = kind_of(iatom)
1020 force(ikind)%gth_ppl(1, atom_a) = force(ikind)%gth_ppl(1, atom_a) + force_thread(1, iatom)
1021 force(ikind)%gth_ppl(2, atom_a) = force(ikind)%gth_ppl(2, atom_a) + force_thread(2, iatom)
1022 force(ikind)%gth_ppl(3, atom_a) = force(ikind)%gth_ppl(3, atom_a) + force_thread(3, iatom)
1025 DEALLOCATE (atom_of_kind, kind_of)
1027 IF (calculate_forces .AND. use_virial)
THEN
1028 virial%pv_ppl = virial%pv_ppl + pv_thread
1029 virial%pv_virial = virial%pv_virial + pv_thread
1032 DEALLOCATE (basis_set_list)
1034 CALL timestop(handle)