35#include "../base/base_uses.f90"
40 LOGICAL :: has_nonlocal = .false.
41 INTEGER :: n_nonlocal = 0
43 LOGICAL,
DIMENSION(0:5) :: is_nonlocal = .false.
44 REAL(kind=
dp),
DIMENSION(:),
POINTER :: a_nonlocal => null()
45 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: h_nonlocal => null()
46 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: c_nonlocal => null()
47 LOGICAL :: has_local = .false.
48 INTEGER :: n_local = 0
49 REAL(kind=
dp) :: zval = 0.0_dp
50 REAL(kind=
dp) :: ac_local = 0.0_dp
51 REAL(kind=
dp),
DIMENSION(:),
POINTER :: a_local => null()
52 REAL(kind=
dp),
DIMENSION(:),
POINTER :: c_local => null()
53 LOGICAL :: has_nlcc = .false.
55 REAL(kind=
dp),
DIMENSION(:),
POINTER :: a_nlcc => null()
56 REAL(kind=
dp),
DIMENSION(:),
POINTER :: c_nlcc => null()
64 CHARACTER(len=*),
PARAMETER,
PRIVATE :: modulen =
'atom_sgp'
84 REAL(kind=
dp),
DIMENSION(6) :: error
87 INTEGER,
DIMENSION(3) :: mloc
88 LOGICAL :: is_ecp, is_upf
89 REAL(kind=
dp) :: errcc, rcut
90 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: cgauss, cutpots, cutpotu
92 TYPE(
opmat_type),
POINTER :: core, hnl, score, shnl
95 IF (
PRESENT(orb_basis))
THEN
102 IF (
PRESENT(ecp_pot)) is_ecp = .true.
104 IF (
PRESENT(upf_pot)) is_upf = .true.
105 cpassert(.NOT. (is_ecp .AND. is_upf))
110 ALLOCATE (cutpotu(n))
111 rcut = maxval(upf_pot%r)
112 CALL cutpot(cutpotu, upf_pot%r, rcut, 2.5_dp)
114 ALLOCATE (cutpots(n))
115 CALL cutpot(cutpots, basis%grid%rad, rcut, 2.5_dp)
118 ALLOCATE (cutpots(n))
124 CALL ecp_sgp_constr(ecp_pot, sgp_pot, basis)
125 ELSE IF (is_upf)
THEN
126 CALL upf_sgp_constr(upf_pot, sgp_pot, basis)
128 cpabort(
"Either ecp_pot or upf_pot is needed for sgp_construction")
134 NULLIFY (score, shnl)
139 CALL ecpints(hnl%op, basis, ecp_pot)
140 ELSE IF (is_upf)
THEN
141 CALL upfints(core%op, hnl%op, basis, upf_pot, cutpotu, sgp_pot%ac_local)
143 cpabort(
"Either ecp_pot or upf_pot is needed for sgp_construction")
146 CALL sgpints(score%op, shnl%op, basis, sgp_pot, cutpots)
149 IF (sgp_pot%has_local)
THEN
150 n = min(3, ubound(core%op, 3))
151 error(1) = maxval(abs(core%op(:, :, 0:n) - score%op(:, :, 0:n)))
152 mloc = maxloc(abs(core%op(:, :, 0:n) - score%op(:, :, 0:n)))
154 mloc(3) = mloc(3) - 1
155 error(4) = error(1)/max(abs(core%op(mloc(1), mloc(2), mloc(3))), 1.e-6_dp)
157 IF (sgp_pot%has_nonlocal)
THEN
158 n = min(3, ubound(hnl%op, 3))
159 error(2) = maxval(abs(hnl%op(:, :, 0:n) - shnl%op(:, :, 0:n)))
160 mloc = maxloc(abs(hnl%op(:, :, 0:n) - shnl%op(:, :, 0:n)))
161 mloc(3) = mloc(3) - 1
162 error(5) = error(2)/max(abs(hnl%op(mloc(1), mloc(2), mloc(3))), 1.e-6_dp)
164 IF (sgp_pot%has_nlcc)
THEN
169 DO i = 1, sgp_pot%n_nlcc
170 cgauss(:) = cgauss(:) + sgp_pot%c_nlcc(i)*exp(-sgp_pot%a_nlcc(i)*upf_pot%r(:)**2)
172 errcc = sum((cgauss(:) - upf_pot%rho_nlcc(:))**2*upf_pot%r(:)**2*upf_pot%rab(:))
173 errcc = sqrt(errcc/real(n, kind=
dp))
176 cpabort(
"sgp_pot%has_nlcc requires is_upf")
205 TYPE(
atom_p_type),
DIMENSION(:, :),
POINTER :: atom_info
207 INTEGER,
INTENT(IN) :: iw
209 INTEGER :: i, n, ppot_type
210 LOGICAL :: do_transform, explicit, is_ecp, is_upf
211 REAL(kind=
dp) :: errcc, rcut
212 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: cgauss, cutpots, cutpotu
217 TYPE(
opmat_type),
POINTER :: core, hnl, score, shnl
220 IF (.NOT. explicit)
RETURN
222 IF (iw > 0)
WRITE (iw,
'(/," ",79("*"),/,T24,A,/," ",79("*"))')
"SEPARABLE GAUSSIAN PSEUDOPOTENTIAL"
224 atom_ref => atom_info(1, 1)%atom
226 ppot_type = atom_ref%potential%ppot_type
227 SELECT CASE (ppot_type)
229 IF (iw > 0)
WRITE (iw,
'(" GTH Pseudopotential is already in SGP form. ")')
230 do_transform = .false.
232 do_transform = .true.
235 ecp_pot => atom_ref%potential%ecp_pot
237 do_transform = .true.
240 upf_pot => atom_ref%potential%upf_pot
242 IF (iw > 0)
WRITE (iw,
'(" No Pseudopotential available for transformation. ")')
243 do_transform = .false.
245 cpabort(
"Unknown ppot_type")
249 IF (do_transform)
THEN
251 CALL ecp_sgp_constr(ecp_pot, sgp_pot, atom_ref%basis)
252 ELSE IF (is_upf)
THEN
253 CALL upf_sgp_constr(upf_pot, sgp_pot, atom_ref%basis)
255 cpabort(
"Either ecp_pseudo or upf_pseudo is needed for atom_sgp_construction")
260 IF (do_transform)
THEN
264 NULLIFY (score, shnl)
271 ALLOCATE (cutpotu(n))
272 rcut = maxval(upf_pot%r)
273 CALL cutpot(cutpotu, upf_pot%r, rcut, 2.5_dp)
274 n = atom_ref%basis%grid%nr
275 ALLOCATE (cutpots(n))
276 CALL cutpot(cutpots, atom_ref%basis%grid%rad, rcut, 2.5_dp)
278 n = atom_ref%basis%grid%nr
279 ALLOCATE (cutpots(n))
284 CALL ecpints(hnl%op, atom_ref%basis, ecp_pot)
285 ELSE IF (is_upf)
THEN
286 CALL upfints(core%op, hnl%op, atom_ref%basis, upf_pot, cutpotu, sgp_pot%ac_local)
288 cpabort(
"Either ecp_pseudo or upf_pseudo is needed for atom_sgp_construction")
291 CALL sgpints(score%op, shnl%op, atom_ref%basis, sgp_pot, cutpots)
293 IF (sgp_pot%has_local)
THEN
294 n = min(3, ubound(core%op, 3))
295 errcc = maxval(abs(core%op(:, :, 0:n) - score%op(:, :, 0:n)))
297 WRITE (iw,
'(" Local part of pseudopotential")')
298 WRITE (iw,
'(" Number of basis functions ",T77,i4)') sgp_pot%n_local
299 WRITE (iw,
'(" Max. abs. error of matrix elements ",T65,f16.8)') errcc
302 IF (sgp_pot%has_nonlocal)
THEN
304 WRITE (iw,
'(" Nonlocal part of pseudopotential")')
305 WRITE (iw,
'(" Max. l-quantum number",T77,i4)') sgp_pot%lmax
306 WRITE (iw,
'(" Number of projector basis functions ",T77,i4)') sgp_pot%n_nonlocal
307 DO i = 0, sgp_pot%lmax
308 errcc = maxval(abs(hnl%op(:, :, i) - shnl%op(:, :, i)))
309 WRITE (iw,
'(" Max. abs. error of matrix elements: l=",i2,T69,f12.8)') i, errcc
313 IF (sgp_pot%has_nlcc)
THEN
318 DO i = 1, sgp_pot%n_nlcc
319 cgauss(:) = cgauss(:) + sgp_pot%c_nlcc(i)*exp(-sgp_pot%a_nlcc(i)*upf_pot%r(:)**2)
321 errcc = sum((cgauss(:) - upf_pot%rho_nlcc(:))**2*upf_pot%r(:)**2*upf_pot%rab(:))
322 errcc = sqrt(errcc/real(n, kind=
dp))
325 cpabort(
"sgp_pot%has_nlcc requires is_upf")
328 WRITE (iw,
'(" Non-linear core correction: core density")')
329 WRITE (iw,
'(" Number of basis functions ",T77,i4)') sgp_pot%n_nlcc
330 WRITE (iw,
'(" RMS error of core density ",T69,f12.8)') errcc
349 IF (iw > 0)
WRITE (iw,
'(" ",79("*"))')
359 SUBROUTINE ecp_sgp_constr(ecp_pot, sgp_pot, basis)
365 INTEGER :: i, ia, ir, j, k, l, n, na, nl, nr
366 REAL(kind=
dp) :: alpha, amx, cmx
367 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: al, cl, cpot, pgauss
368 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: cmat, qmat, score, sinv, smat, tmat
369 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rad
371 sgp_pot%has_nlcc = .false.
373 sgp_pot%has_local = .false.
377 sgp_pot%has_nonlocal = .true.
382 sgp_pot%n_nonlocal = nl
383 sgp_pot%lmax = ecp_pot%lmax
384 ALLOCATE (sgp_pot%a_nonlocal(nl))
385 ALLOCATE (sgp_pot%h_nonlocal(nl, 0:ecp_pot%lmax))
386 ALLOCATE (sgp_pot%c_nonlocal(nl, nl, 0:ecp_pot%lmax))
388 ALLOCATE (al(nl), cl(nl))
389 ALLOCATE (smat(nl, nl), sinv(nl, nl))
390 ALLOCATE (tmat(nl, nl), cmat(nl, nl))
392 amx = maxval(ecp_pot%bpot)
394 cmx = cmx**(1._dp/real(nl - 1,
dp))
397 al(ir) = amx*cmx**(ir - 1)
400 sgp_pot%a_nonlocal(1:nl) = al(1:nl)
403 rad => basis%grid%rad
404 ALLOCATE (cpot(nr), pgauss(nr))
405 DO l = 0, ecp_pot%lmax
407 ALLOCATE (score(na, na), qmat(na, nl))
409 DO k = 1, ecp_pot%npot(l)
410 n = ecp_pot%nrpot(k, l)
411 alpha = ecp_pot%bpot(k, l)
412 cpot(:) = cpot + ecp_pot%apot(k, l)*rad**(n - 2)*exp(-alpha*rad**2)
416 score(i, j) =
integrate_grid(cpot, basis%bf(:, i, l), basis%bf(:, j, l), basis%grid)
417 score(j, i) = score(i, j)
422 pgauss(:) = exp(-al(i)*rad(:)**2)*rad(:)**l
424 qmat(ia, i) =
integrate_grid(basis%bf(:, ia, l), pgauss(:), basis%grid)
429 tmat(1:nl, 1:nl) = matmul(transpose(qmat(1:na, 1:nl)), matmul(score(1:na, 1:na), qmat(1:na, 1:nl)))
430 smat(1:nl, 1:nl) = matmul(transpose(qmat(1:na, 1:nl)), qmat(1:na, 1:nl))
432 cmat(1:nl, 1:nl) = matmul(sinv(1:nl, 1:nl), matmul(tmat(1:nl, 1:nl), sinv(1:nl, 1:nl)))
433 cmat(1:nl, 1:nl) = (cmat(1:nl, 1:nl) + transpose(cmat(1:nl, 1:nl)))*0.5_dp
437 CALL diamat_all(cmat(1:nl, 1:nl), cl(1:nl), .true.)
439 sgp_pot%h_nonlocal(1:nl, l) = cl(1:nl)
440 sgp_pot%c_nonlocal(1:nl, 1:nl, l) = cmat(1:nl, 1:nl)
441 sgp_pot%is_nonlocal(l) = .true.
443 DEALLOCATE (score, qmat)
445 DEALLOCATE (cpot, pgauss)
446 DEALLOCATE (al, cl, smat, sinv, tmat, cmat)
448 END SUBROUTINE ecp_sgp_constr
456 SUBROUTINE upf_sgp_constr(upf_pot, sgp_pot, basis)
462 CHARACTER(len=4) :: ptype
463 INTEGER :: ia, ib, ipa, ipb, ir, la, lb, na, nl, &
466 REAL(kind=
dp) :: cpa, cpb, eee, ei, errloc, rc, x(2), zval
467 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: al, cl, pgauss, pproa, pprob, vgauss, &
469 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: cmat, qmat, score, sinv, smat, tmat
473 IF (upf_pot%is_ultrasoft .OR. upf_pot%is_paw .OR. upf_pot%is_coulomb)
THEN
474 sgp_pot%has_nonlocal = .false.
475 sgp_pot%n_nonlocal = 0
476 sgp_pot%has_local = .false.
478 sgp_pot%has_nlcc = .false.
487 ww(:) = upf_pot%r(:)**2*upf_pot%rab(:)
490 sgp_pot%has_local = .true.
492 ALLOCATE (vloc(nr), vgauss(nr))
496 CALL erffit(sgp_pot%ac_local, upf_pot%vlocal, upf_pot%r, zval)
499 IF (upf_pot%r(ir) < 1.e-12_dp)
THEN
500 vgauss(ir) = -sqrt(2.0_dp)*zval/
rootpi/sgp_pot%ac_local
502 rc = upf_pot%r(ir)/sgp_pot%ac_local/sqrt(2.0_dp)
503 vgauss(ir) = -zval/upf_pot%r(ir)*erf(rc)
506 vloc(:) = upf_pot%vlocal(:) - vgauss(:)
511 ALLOCATE (al(nl), cl(nl))
516 ostate%rhoend = 1.e-12_dp
517 ostate%rhobeg = 5.e-2_dp
523 IF (ostate%state == 2)
THEN
525 al(ir) = x(1)*x(2)**(ir - 1)
527 CALL pplocal_error(nl, al, cl, vloc, vgauss, gbasis, upf_pot%r, ww, 1, ostate%f)
529 IF (ostate%state == -1)
EXIT
535 al(ir) = x(1)*x(2)**(ir - 1)
537 CALL pplocal_error(nl, al, cl, vloc, vgauss, gbasis, upf_pot%r, ww, 1, errloc)
539 ALLOCATE (sgp_pot%a_local(nl), sgp_pot%c_local(nl))
541 sgp_pot%a_local(1:nl) = al(1:nl)
542 sgp_pot%c_local(1:nl) = cl(1:nl)
543 DEALLOCATE (vloc, vgauss)
547 ptype = adjustl(trim(upf_pot%pseudo_type))
548 IF (ptype(1:2) ==
"NC" .OR. ptype(1:2) ==
"US")
THEN
550 ELSE IF (ptype(1:2) ==
"SL")
THEN
553 cpabort(
"Pseudopotential type: ["//adjustl(trim(ptype))//
"] not known")
557 IF (upf_pot%l_max < 0)
THEN
558 sgp_pot%n_nonlocal = 0
560 sgp_pot%has_nonlocal = .false.
564 sgp_pot%has_nonlocal = .true.
570 sgp_pot%n_nonlocal = nl
571 sgp_pot%lmax = upf_pot%l_max
572 ALLOCATE (sgp_pot%a_nonlocal(nl))
573 ALLOCATE (sgp_pot%h_nonlocal(nl, 0:upf_pot%l_max))
574 ALLOCATE (sgp_pot%c_nonlocal(nl, nl, 0:upf_pot%l_max))
576 ALLOCATE (al(nl), cl(nl))
577 ALLOCATE (smat(nl, nl), sinv(nl, nl))
578 ALLOCATE (tmat(nl, nl), cmat(nl, nl))
581 al(ir) = 10.0_dp*0.60_dp**(ir - 1)
584 sgp_pot%a_nonlocal(1:nl) = al(1:nl)
587 ALLOCATE (pgauss(nr), vloc(nr))
588 DO la = 0, upf_pot%l_max
589 IF (la == upf_pot%l_local) cycle
590 sgp_pot%is_nonlocal(la) = .true.
592 ALLOCATE (score(na, na), qmat(na, nl))
594 vloc(:) = upf_pot%vsemi(:, la + 1) - upf_pot%vlocal(:)
597 score(ia, ib) = sum(vloc(:)*gbasis%bf(:, ia, la)*gbasis%bf(:, ib, la)*ww(:))
598 score(ib, ia) = score(ia, ib)
603 pgauss(:) = exp(-al(ir)*upf_pot%r(:)**2)*upf_pot%r(:)**la
604 eee =
rootpi/(2._dp**(la + 2)*
dfac(2*la + 1))/(2._dp*al(ir))**(la + 1.5_dp)
605 pgauss(:) = pgauss(:)/sqrt(eee)
607 qmat(ia, ir) = sum(gbasis%bf(:, ia, la)*pgauss(:)*ww)
611 tmat(1:nl, 1:nl) = matmul(transpose(qmat(1:na, 1:nl)), matmul(score(1:na, 1:na), qmat(1:na, 1:nl)))
612 smat(1:nl, 1:nl) = matmul(transpose(qmat(1:na, 1:nl)), qmat(1:na, 1:nl))
614 cmat(1:nl, 1:nl) = matmul(sinv(1:nl, 1:nl), matmul(tmat(1:nl, 1:nl), sinv(1:nl, 1:nl)))
615 cmat(1:nl, 1:nl) = (cmat(1:nl, 1:nl) + transpose(cmat(1:nl, 1:nl)))*0.5_dp
616 CALL diamat_all(cmat(1:nl, 1:nl), cl(1:nl), .true.)
620 ei =
rootpi/(2._dp**(la + 2)*
dfac(2*la + 1))/(2._dp*al(ir))**(la + 1.5_dp)
621 cmat(ir, 1:nl) = cmat(ir, 1:nl)/sqrt(ei)
623 sgp_pot%h_nonlocal(1:nl, la) = cl(1:nl)
624 sgp_pot%c_nonlocal(1:nl, 1:nl, la) = cmat(1:nl, 1:nl)
625 sgp_pot%is_nonlocal(la) = .true.
626 DEALLOCATE (score, qmat)
629 sgp_pot%c_nonlocal = sgp_pot%c_nonlocal/sqrt(
fourpi)
631 DEALLOCATE (pgauss, vloc)
632 DEALLOCATE (al, cl, smat, sinv, tmat, cmat)
634 sgp_pot%has_nonlocal = .true.
636 ALLOCATE (pproa(nr), pprob(nr), pgauss(nr))
637 np = upf_pot%number_of_proj
639 ALLOCATE (al(nl), cl(nl))
640 ALLOCATE (smat(nl, nl), sinv(nl, nl))
641 ALLOCATE (tmat(nl, nl), cmat(nl, nl))
645 al(ir) = 10.0_dp*0.60_dp**(ir - 1)
648 sgp_pot%lmax = maxval(upf_pot%lbeta(:))
649 sgp_pot%n_nonlocal = nl
650 ALLOCATE (sgp_pot%a_nonlocal(nl))
651 ALLOCATE (sgp_pot%h_nonlocal(nl, 0:sgp_pot%lmax))
652 ALLOCATE (sgp_pot%c_nonlocal(nl, nl, 0:sgp_pot%lmax))
654 sgp_pot%a_nonlocal(1:nl) = al(1:nl)
657 DO la = 0, sgp_pot%lmax
658 sgp_pot%is_nonlocal(la) = .true.
660 ALLOCATE (score(na, na), qmat(na, nl))
664 lb = upf_pot%lbeta(ipa)
666 pproa(:) = upf_pot%beta(:, ipa)
668 lb = upf_pot%lbeta(ipb)
670 pprob(:) = upf_pot%beta(:, ipb)
671 eee = upf_pot%dion(ipa, ipb)
673 cpa = sum(pproa(:)*gbasis%bf(:, ia, la)*ww(:))
675 cpb = sum(pprob(:)*gbasis%bf(:, ib, la)*ww(:))
676 score(ia, ib) = score(ia, ib) + cpa*eee*cpb
677 score(ib, ia) = score(ia, ib)
684 pgauss(:) = exp(-al(ir)*upf_pot%r(:)**2)*upf_pot%r(:)**la
685 eee =
rootpi/(2._dp**(la + 2)*
dfac(2*la + 1))/(2._dp*al(ir))**(la + 1.5_dp)
686 pgauss(:) = pgauss(:)/sqrt(eee)
688 qmat(ia, ir) = sum(gbasis%bf(:, ia, la)*pgauss(:)*ww)
692 tmat(1:nl, 1:nl) = matmul(transpose(qmat(1:na, 1:nl)), matmul(score(1:na, 1:na), qmat(1:na, 1:nl)))
693 smat(1:nl, 1:nl) = matmul(transpose(qmat(1:na, 1:nl)), qmat(1:na, 1:nl))
695 cmat(1:nl, 1:nl) = matmul(sinv(1:nl, 1:nl), matmul(tmat(1:nl, 1:nl), sinv(1:nl, 1:nl)))
696 cmat(1:nl, 1:nl) = (cmat(1:nl, 1:nl) + transpose(cmat(1:nl, 1:nl)))*0.5_dp
697 CALL diamat_all(cmat(1:nl, 1:nl), cl(1:nl), .true.)
701 ei =
rootpi/(2._dp**(la + 2)*
dfac(2*la + 1))/(2._dp*al(ir))**(la + 1.5_dp)
702 cmat(ir, 1:nl) = cmat(ir, 1:nl)/sqrt(ei)
704 sgp_pot%h_nonlocal(1:nl, la) = cl(1:nl)
705 sgp_pot%c_nonlocal(1:nl, 1:nl, la) = cmat(1:nl, 1:nl)
706 sgp_pot%is_nonlocal(la) = .true.
707 DEALLOCATE (score, qmat)
710 sgp_pot%c_nonlocal = sgp_pot%c_nonlocal/sqrt(
fourpi)
712 DEALLOCATE (pgauss, pproa, pprob)
713 DEALLOCATE (al, cl, smat, sinv, tmat, cmat)
717 IF (upf_pot%core_correction)
THEN
718 sgp_pot%has_nlcc = .true.
720 sgp_pot%has_nlcc = .false.
725 IF (sgp_pot%has_nlcc)
THEN
727 sgp_pot%n_nlcc =
SIZE(al)
728 ALLOCATE (sgp_pot%a_nlcc, source=al)
729 ALLOCATE (sgp_pot%c_nlcc, source=cl)
735 END SUBROUTINE upf_sgp_constr
749 REAL(
dp),
INTENT(IN) :: r(:), rab(:), rho(:)
750 REAL(
dp),
ALLOCATABLE,
INTENT(OUT) :: alpha(:), coeff(:)
752 INTEGER,
PARAMETER :: ng = 48, ntail = 200
753 REAL(
dp),
PARAMETER :: amax = 300.0_dp, amin = 0.03_dp, &
756 INTEGER :: i, info, lwork, m, nr, rank
757 REAL(
dp) :: dr, extent, norms(ng), singular(ng), &
759 REAL(
dp),
ALLOCATABLE :: matrix(:, :), rhs(:, :), rr(:), sw(:), &
763 cpassert(nr >= 2 .AND.
SIZE(rab) == nr .AND.
SIZE(rho) == nr)
764 cpassert(all(r >= 0.0_dp) .AND. all(rab > 0.0_dp))
765 cpassert(all(r(2:) > r(:nr - 1)))
767 ALLOCATE (alpha(ng), coeff(ng), matrix(m, ng), rhs(m, 1), rr(m), sw(m))
769 sw(:nr) = r*sqrt(rab)
771 extent = max(r(nr) + 1.0_dp, 50.0_dp)
772 dr = (extent - r(nr))/real(ntail,
dp)
774 rr(nr + i) = r(nr) + real(i,
dp)*dr
775 sw(nr + i) = rr(nr + i)*sqrt(dr)
777 sw(m) = sw(m)/sqrt(2.0_dp)
779 rhs(:nr, 1) = rho*sw(:nr)
781 alpha(i) = amin*exp(log(amax/amin)*real(i - 1,
dp)/real(ng - 1,
dp))
782 matrix(:, i) = exp(-alpha(i)*rr**2)*sw
783 norms(i) = sqrt(sum(matrix(:, i)**2))
784 cpassert(norms(i) > 0.0_dp)
785 matrix(:, i) = matrix(:, i)/norms(i)
787 CALL dgelss(m, ng, 1, matrix, m, rhs, m, singular, rcond, rank, work_query, -1, info)
789 lwork = max(1, ceiling(work_query(1)))
790 ALLOCATE (work(lwork))
791 CALL dgelss(m, ng, 1, matrix, m, rhs, m, singular, rcond, rank, work, lwork, info)
792 IF (info /= 0) cpabort(
"SVD failed while fitting the UPF core density")
793 coeff(:) = rhs(:ng, 1)/norms
804 IF (
ASSOCIATED(sgp_pot%a_nonlocal))
DEALLOCATE (sgp_pot%a_nonlocal)
805 IF (
ASSOCIATED(sgp_pot%h_nonlocal))
DEALLOCATE (sgp_pot%h_nonlocal)
806 IF (
ASSOCIATED(sgp_pot%c_nonlocal))
DEALLOCATE (sgp_pot%c_nonlocal)
808 IF (
ASSOCIATED(sgp_pot%a_local))
DEALLOCATE (sgp_pot%a_local)
809 IF (
ASSOCIATED(sgp_pot%c_local))
DEALLOCATE (sgp_pot%c_local)
811 IF (
ASSOCIATED(sgp_pot%a_nlcc))
DEALLOCATE (sgp_pot%a_nlcc)
812 IF (
ASSOCIATED(sgp_pot%c_nlcc))
DEALLOCATE (sgp_pot%c_nlcc)
827 SUBROUTINE upfints(core, hnl, basis, upf_pot, cutpotu, ac_local)
828 REAL(kind=
dp),
DIMENSION(:, :, 0:) :: core, hnl
831 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: cutpotu
832 REAL(kind=
dp),
INTENT(IN) :: ac_local
834 CHARACTER(len=4) :: ptype
835 INTEGER :: i, j, k1, k2, la, lb, m, n
836 REAL(kind=
dp) :: rc, zval
837 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: spot
838 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: spmat
848 spot(:) = upf_pot%vlocal(:)
851 IF (upf_pot%r(i) < 1.e-12_dp)
THEN
854 rc = upf_pot%r(i)/ac_local/
sqrt2
855 spot(i) = spot(i) + zval/upf_pot%r(i)*erf(rc)
858 spot(:) = spot(:)*cutpotu(:)
864 ptype = adjustl(trim(upf_pot%pseudo_type))
865 IF (ptype(1:2) ==
"NC" .OR. ptype(1:2) ==
"US")
THEN
867 n = maxval(gbasis%nbas(:))
868 m = upf_pot%number_of_proj
869 ALLOCATE (spmat(n, m))
872 la = upf_pot%lbeta(i)
873 DO j = 1, gbasis%nbas(la)
874 spmat(j, i) =
integrate_grid(upf_pot%beta(:, i), gbasis%bf(:, j, la), gbasis%grid)
878 la = upf_pot%lbeta(i)
880 lb = upf_pot%lbeta(j)
882 DO k1 = 1, gbasis%nbas(la)
883 DO k2 = 1, gbasis%nbas(la)
884 hnl(k1, k2, la) = hnl(k1, k2, la) + spmat(k1, i)*upf_pot%dion(i, j)*spmat(k2, j)
891 ELSE IF (ptype(1:2) ==
"SL")
THEN
893 DO la = 0, upf_pot%l_max
894 IF (la == upf_pot%l_local) cycle
895 m =
SIZE(upf_pot%vsemi(:, la + 1))
897 spot(:) = upf_pot%vsemi(:, la + 1) - upf_pot%vlocal(:)
898 spot(:) = spot(:)*cutpotu(:)
902 hnl(i, j, la) = hnl(i, j, la) + &
904 gbasis%bf(:, i, la), gbasis%bf(:, j, la), gbasis%grid)
905 hnl(j, i, la) = hnl(i, j, la)
911 cpabort(
"Pseudopotential type: ["//adjustl(trim(ptype))//
"] not known")
917 END SUBROUTINE upfints
925 SUBROUTINE ecpints(hnl, basis, ecp_pot)
926 REAL(kind=
dp),
DIMENSION(:, :, 0:) :: hnl
930 INTEGER :: i, j, k, l, m, n
931 REAL(kind=
dp) :: alpha
932 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: cpot
933 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rad
935 rad => basis%grid%rad
941 DO l = 0, ecp_pot%lmax
943 DO k = 1, ecp_pot%npot(l)
944 n = ecp_pot%nrpot(k, l)
945 alpha = ecp_pot%bpot(k, l)
946 cpot(:) = cpot(:) + ecp_pot%apot(k, l)*rad(:)**(n - 2)*exp(-alpha*rad(:)**2)
948 DO i = 1, basis%nbas(l)
949 DO j = i, basis%nbas(l)
950 hnl(i, j, l) =
integrate_grid(cpot, basis%bf(:, i, l), basis%bf(:, j, l), basis%grid)
951 hnl(j, i, l) = hnl(i, j, l)
957 END SUBROUTINE ecpints
967 SUBROUTINE sgpints(core, hnl, basis, sgp_pot, cutpots)
968 REAL(kind=
dp),
DIMENSION(:, :, 0:) :: core, hnl
971 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: cutpots
973 INTEGER :: i, ia, j, l, m, n, na
974 REAL(kind=
dp) :: a, zval
975 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: cpot, pgauss
976 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: qmat
977 REAL(kind=
dp),
DIMENSION(:),
POINTER :: rad
979 rad => basis%grid%rad
984 IF (sgp_pot%has_local)
THEN
988 DO i = 1, sgp_pot%n_local
989 cpot(:) = cpot(:) + sgp_pot%c_local(i)*exp(-sgp_pot%a_local(i)*rad(:)**2)
991 cpot(:) = cpot(:)*cutpots(:)
997 IF (sgp_pot%has_nonlocal)
THEN
999 ALLOCATE (pgauss(1:m))
1000 n = sgp_pot%n_nonlocal
1002 DO l = 0, sgp_pot%lmax
1003 cpassert(l <= ubound(basis%nbas, 1))
1004 IF (.NOT. sgp_pot%is_nonlocal(l)) cycle
1007 ALLOCATE (qmat(na, n))
1009 a = sgp_pot%a_nonlocal(i)
1010 pgauss(:) = cutpots(:)*exp(-a*rad(:)**2)*rad(:)**l
1012 qmat(ia, i) =
integrate_grid(basis%bf(:, ia, l), pgauss(:), basis%grid)
1015 qmat(1:na, 1:n) = sqrt(
fourpi)*matmul(qmat(1:na, 1:n), sgp_pot%c_nonlocal(1:n, 1:n, l))
1019 hnl(i, j, l) = hnl(i, j, l) + qmat(i, ia)*qmat(j, ia)*sgp_pot%h_nonlocal(ia, l)
1021 hnl(j, i, l) = hnl(i, j, l)
1029 END SUBROUTINE sgpints
1038 SUBROUTINE erffit(ac, vlocal, r, z)
1039 REAL(kind=
dp),
INTENT(OUT) :: ac
1040 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: vlocal, r
1041 REAL(kind=
dp),
INTENT(IN) :: z
1043 REAL(kind=
dp),
PARAMETER :: rcut = 1.4_dp
1045 INTEGER :: i, j, m, m1
1046 REAL(kind=
dp) :: a1, a2, an, e2, en, rc
1047 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: epot, rval, vpot
1050 ALLOCATE (epot(m), vpot(m), rval(m))
1051 cpassert(
SIZE(vlocal) == m)
1052 IF (r(1) > r(m))
THEN
1054 vpot(m - i + 1) = vlocal(i)
1055 rval(m - i + 1) = r(i)
1058 vpot(1:m) = vlocal(1:m)
1063 IF (rval(i) > rcut)
THEN
1074 an = a1 + i*0.025_dp
1075 rc = 1._dp/(an*sqrt(2.0_dp))
1077 epot(j) = vpot(j) + z/rval(j)*erf(rval(j)*rc)
1079 en = sum(abs(epot(m1:m)*rval(m1:m)**2))
1087 DEALLOCATE (epot, vpot, rval)
1089 END SUBROUTINE erffit
1104 SUBROUTINE pplocal_error(nl, al, cl, vloc, vgauss, gbasis, rad, ww, method, errloc)
1106 REAL(kind=
dp),
DIMENSION(:) :: al, cl, vloc, vgauss
1108 REAL(kind=
dp),
DIMENSION(:) :: rad, ww
1109 INTEGER,
INTENT(IN) :: method
1110 REAL(kind=
dp) :: errloc
1112 INTEGER :: ia, ib, ir, ix, la, na
1113 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: tv
1114 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: rmat, sinv, smat
1115 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :, :) :: gmat
1118 IF (method == 1)
THEN
1119 ALLOCATE (tv(nl), smat(nl, nl), sinv(nl, nl))
1121 vgauss(:) = exp(-al(ir)*rad(:)**2)
1123 smat(ir, ix) = sum(vgauss(:)*exp(-al(ix)*rad(:)**2)*ww(:))
1125 tv(ir) = sum(vloc(:)*vgauss(:)*ww(:))
1128 cl(1:nl) = matmul(sinv(1:nl, 1:nl), tv(1:nl))
1131 ALLOCATE (tv(nl), smat(nl, nl), sinv(nl, nl))
1135 DO la = 0, min(ubound(gbasis%nbas, 1), 3)
1136 na = gbasis%nbas(la)
1137 ALLOCATE (rmat(na, na), gmat(na, na, nl))
1142 rmat(ia, ib) = sum(gbasis%bf(:, ia, la)*gbasis%bf(:, ib, la)*vloc(:)*ww(:))
1143 rmat(ib, ia) = rmat(ia, ib)
1147 vgauss(:) = exp(-al(ir)*rad(:)**2)
1150 gmat(ia, ib, ir) = sum(gbasis%bf(:, ia, la)*gbasis%bf(:, ib, la)*vgauss(:)*ww(:))
1151 gmat(ib, ia, ir) = gmat(ia, ib, ir)
1159 smat(ix, ir) = smat(ir, ix)
1162 DEALLOCATE (rmat, gmat)
1166 cl(1:nl) = matmul(sinv(1:nl, 1:nl), tv(1:nl))
1171 vgauss(:) = vgauss(:) + cl(ir)*exp(-al(ir)*rad(:)**2)
1173 errloc = sum((vgauss - vloc)**2*ww)
1175 DEALLOCATE (tv, smat, sinv)
1177 END SUBROUTINE pplocal_error
1186 SUBROUTINE cutpot(pot, r, rcut, rsmooth)
1187 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: pot
1188 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: r
1189 REAL(kind=
dp),
INTENT(IN) :: rcut, rsmooth
1192 REAL(kind=
dp) :: rab, rx, x
1195 cpassert(n <=
SIZE(r))
1200 IF (rab > rcut)
THEN
1202 ELSE IF (rab > rcut - rsmooth)
THEN
1203 rx = rab - (rcut - rsmooth)
1205 pot(i) = -6._dp*x**5 + 15._dp*x**4 - 10._dp*x**3 + 1._dp
1209 END SUBROUTINE cutpot
subroutine, public set_kind_basis_atomic(basis, orb_basis_set, has_pp, agrid, cp2k_norm)
...
subroutine, public atom_sgp_release(sgp_pot)
...
subroutine, public sgp_construction(sgp_pot, ecp_pot, upf_pot, orb_basis, error)
...
subroutine, public fit_core_density_gaussians(r, rab, rho, alpha, coeff)
Fit a tabulated core density without forming ill-conditioned normal equations. Column-normalized,...
subroutine, public atom_sgp_construction(atom_info, input_section, iw)
...
Define the atom type and its sub types.
subroutine, public release_opmat(opmat)
...
subroutine, public release_atom_basis(basis)
...
subroutine, public init_atom_basis_default_pp(basis)
...
subroutine, public create_opmat(opmat, n, lmax)
...
subroutine, public atom_basis_gridrep(basis, gbasis, r, rab)
...
Some basic routines for atomic calculations.
subroutine, public numpot_matrix(imat, cpot, basis, derivatives)
Calculate a potential matrix by integrating the potential on an atomic radial grid.
sums arrays of real/complex numbers with much reduced round-off as compared to a naive implementation...
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
real(kind=dp), dimension(-1:2 *maxfac+1), parameter, public dfac
real(kind=dp), parameter, public rootpi
real(kind=dp), parameter, public fourpi
real(kind=dp), parameter, public sqrt2
Collection of simple mathematical functions and subroutines.
subroutine, public get_pseudo_inverse_diag(a, a_pinverse, rskip)
returns the pseudoinverse of a real, symmetric and positive definite matrix using diagonalization.
subroutine, public diamat_all(a, eigval, dac)
Diagonalize the symmetric n by n matrix a using the LAPACK library. Only the upper triangle of matrix...
subroutine, public powell_optimize(n, x, optstate)
...
Owned UPF dataset and radial conventions shared by ATOM and Quickstep. Dataset availability does not ...
Provides all information about a basis set.
Provides all information about an atomic kind.