(git:3d5d2e5)
Loading...
Searching...
No Matches
upf_local_integrals.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Local UPF matrix elements from the original radial potential.
10!> The Gaussian core electrostatics supplies -Z erf(sqrt(alpha)*r)/r.
11!> Its complement is integrated with analytic angles and radial quadrature.
12!> Gaussian products, center derivatives and RI integrals share this operator.
13! **************************************************************************************************
15 USE bessel_lib, ONLY: bessel0
16 USE kinds, ONLY: dp
17 USE mathconstants, ONLY: fourpi,&
18 pi
19 USE mathlib, ONLY: binomial
20 USE orbital_pointers, ONLY: coset,&
21 indco,&
22 ncoset
27#include "../base/base_uses.f90"
28
29 IMPLICIT NONE
30 PRIVATE
31 CHARACTER(LEN=*), PARAMETER, PRIVATE :: moduleN = 'upf_local_integrals'
32
34 TYPE(upf_projector_type) :: radial
35 REAL(kind=dp) :: eps = 0.0_dp
36 END TYPE upf_local_type
37
39
40CONTAINS
41
42! **************************************************************************************************
43!> \brief Prepare the short-range local potential outside parallel regions.
44!> \param pot Original UPF data, with PP_LOCAL already converted to Hartree.
45!> \param alpha Gaussian core-charge exponent, not its screening radius.
46!> \param degree Largest Gaussian product degree, including derivatives or moments.
47!> \param local Immutable integration data. Reinitialization retains its threshold.
48!> \param eps Optional threshold for estimating the potential's neighbor-list radius.
49!> This is NOT an integration tolerance: EPS_PPL is normally 1e-2.
50!> All original radial samples, including the tail, enter the quadrature.
51! **************************************************************************************************
52 SUBROUTINE upf_local_init(pot, alpha, degree, local, eps)
53 TYPE(atom_upfpot_type), INTENT(IN) :: pot
54 REAL(kind=dp), INTENT(IN) :: alpha
55 INTEGER, INTENT(IN) :: degree
56 TYPE(upf_local_type), INTENT(INOUT) :: local
57 REAL(kind=dp), INTENT(IN), OPTIONAL :: eps
58
59 INTEGER :: i, last, n
60 REAL(kind=dp), ALLOCATABLE :: short_range(:)
61 TYPE(atom_upfpot_type) :: scalar
62
63 cpassert(alpha > 0.0_dp)
64 cpassert(SIZE(pot%r) == SIZE(pot%vlocal))
65 cpassert(SIZE(pot%r) >= 3)
66 IF (PRESENT(eps)) local%eps = eps
67 cpassert(local%eps >= 0.0_dp)
68 ALLOCATE (short_range(SIZE(pot%vlocal)))
69 short_range(:) = pot%vlocal
70 DO i = 1, SIZE(pot%r)
71 IF (pot%r(i) > 0.0_dp) THEN
72 short_range(i) = short_range(i) + pot%zion*erf(sqrt(alpha)*pot%r(i))/pot%r(i)
73 ELSE
74 short_range(i) = short_range(i) + 2.0_dp*pot%zion*sqrt(alpha/pi)
75 END IF
76 END DO
77 last = 0
78 DO i = SIZE(short_range), 1, -1
79 IF (abs(short_range(i)) > local%eps) THEN
80 last = i
81 EXIT
82 END IF
83 END DO
84 n = SIZE(short_range)
85 scalar%number_of_proj = 1
86 ALLOCATE (scalar%r(n), scalar%rab(n), scalar%lbeta(1))
87 scalar%r(:) = pot%r(:n)
88 scalar%rab(:) = pot%rab(:n)
89 scalar%lbeta = 0
90 ALLOCATE (scalar%beta(n, 1), scalar%dion(1, 1))
91 ! Y00 = 1/sqrt(4*pi); absorb it to integrate a scalar radial potential.
92 scalar%beta(:, 1) = sqrt(fourpi)*short_range(:n)
93 scalar%dion = 0.0_dp
94 CALL upf_projector_init(scalar, degree, local%radial)
95 ! Screening estimates the support in a pair-list bound. It must never
96 ! truncate the function actually integrated within a retained pair.
97 local%radial%radius = 0.0_dp
98 IF (last > 0) local%radial%radius = pot%r(last)
99 END SUBROUTINE upf_local_init
100
101! **************************************************************************************************
102!> \brief Fourier transform of the same short-range potential used in the AO integrals.
103!> USPP augmentation must couple to the local potentials of all ionic centers.
104!> The Gaussian-core Coulomb contribution is excluded here to avoid double counting.
105!> \param local Prepared radial potential; its screening radius does not truncate this integral.
106!> \param gvecs Cartesian reciprocal vectors (3,ng), in inverse bohr.
107!> \param position Potential center in bohr.
108!> \param volume Cell volume in bohr cubed.
109!> \param vg Fourier coefficients, integral divided by volume, overwritten.
110!> \param dv_position Optional derivatives with respect to the potential center (3,ng).
111!> \param dv_g Optional derivatives with respect to Cartesian G, holding position/volume fixed.
112!> The separate volume derivative is -vg/volume; combine all terms for cell strain.
113! **************************************************************************************************
114 SUBROUTINE upf_local_fourier(local, gvecs, position, volume, vg, dv_position, dv_g)
115 TYPE(upf_local_type), INTENT(IN) :: local
116 REAL(kind=dp), INTENT(IN) :: gvecs(:, :), position(3), volume
117 COMPLEX(KIND=dp), INTENT(OUT) :: vg(:)
118 COMPLEX(KIND=dp), INTENT(OUT), OPTIONAL :: dv_position(:, :), dv_g(:, :)
119
120 COMPLEX(KIND=dp) :: phase
121 INTEGER :: ig
122 REAL(kind=dp) :: norm_g, radial, radial_derivative
123
124 cpassert(volume > 0.0_dp)
125 cpassert(SIZE(gvecs, 1) == 3 .AND. SIZE(gvecs, 2) == SIZE(vg))
126 cpassert(local%radial%nproj == 1 .AND. local%radial%lmax == 0)
127 IF (PRESENT(dv_position)) THEN
128 cpassert(all(shape(dv_position) == shape(gvecs)))
129 END IF
130 IF (PRESENT(dv_g)) THEN
131 cpassert(all(shape(dv_g) == shape(gvecs)))
132 END IF
133 DO ig = 1, SIZE(vg)
134 norm_g = sqrt(sum(gvecs(:, ig)**2))
135 ! weighted_beta contains sqrt(4*pi)*r^2*V_sr(r) times radial weights.
136 phase = sqrt(fourpi)/volume*exp(cmplx(0.0_dp, -dot_product(gvecs(:, ig), position), dp))
137 IF (norm_g == 0.0_dp) THEN
138 radial = sum(local%radial%weighted_beta(:, 1))
139 ELSE
140 radial = dot_product(bessel0(norm_g*local%radial%r, 0), local%radial%weighted_beta(:, 1))
141 END IF
142 vg(ig) = phase*radial
143 IF (PRESENT(dv_position)) dv_position(:, ig) = cmplx(0.0_dp, -gvecs(:, ig), dp)*vg(ig)
144 IF (PRESENT(dv_g)) THEN
145 dv_g(:, ig) = cmplx(0.0_dp, -position, dp)*vg(ig)
146 IF (norm_g > 0.0_dp) THEN
147 radial_derivative = -sum(local%radial%r*bessel0(norm_g*local%radial%r, 1)* &
148 local%radial%weighted_beta(:, 1))
149 dv_g(:, ig) = dv_g(:, ig) + phase*radial_derivative*gvecs(:, ig)/norm_g
150 END IF
151 END IF
152 END DO
153 END SUBROUTINE upf_local_fourier
154
155! **************************************************************************************************
156!> \brief Evaluate primitive three-center local integrals by the Gaussian product theorem.
157!> \param local Prepared radial potential.
158!> \param la Largest Cartesian degree at A; all degrees 0..la are returned.
159!> \param alpha Primitive exponents at A.
160!> \param lb Largest Cartesian degree at B; all degrees 0..lb are returned.
161!> \param beta Primitive exponents at B.
162!> \param rab B minus A.
163!> \param rac Potential center C minus A.
164!> \param v Matrix elements in primitive-major Cartesian order.
165!> \param da Optional derivatives with respect to A, at fixed B and C.
166!> \param db Optional derivatives with respect to B, at fixed A and C.
167!> The derivative with respect to C is -(da+db).
168! **************************************************************************************************
169 SUBROUTINE upf_local_matrix(local, la, alpha, lb, beta, rab, rac, v, da, db)
170 TYPE(upf_local_type), INTENT(IN) :: local
171 INTEGER, INTENT(IN) :: la
172 REAL(kind=dp), INTENT(IN) :: alpha(:)
173 INTEGER, INTENT(IN) :: lb
174 REAL(kind=dp), INTENT(IN) :: beta(:), rab(3), rac(3)
175 REAL(kind=dp), INTENT(OUT) :: v(:, :)
176 REAL(kind=dp), INTENT(OUT), OPTIONAL :: da(:, :, :), db(:, :, :)
177
178 INTEGER :: a, aa, axis, b, bb, da_max, db_max, &
179 degree, i, ia, ib, ix, iy, iz, j, k, &
180 pa(3), pb(3), shifted(3)
181 REAL(kind=dp) :: center(3), p, pref, shift_a(3), &
182 shift_b(3), value
183 REAL(kind=dp), ALLOCATABLE :: moments(:, :, :), &
184 polynomial(:, :, :, :), work(:, :)
185
186 cpassert(la >= 0 .AND. lb >= 0)
187 cpassert(all(alpha > 0.0_dp) .AND. all(beta > 0.0_dp))
188 cpassert(SIZE(v, 1) == SIZE(alpha)*ncoset(la))
189 cpassert(SIZE(v, 2) == SIZE(beta)*ncoset(lb))
190 degree = la + lb
191 IF (PRESENT(da) .OR. PRESENT(db)) degree = degree + 1
192 da_max = la
193 db_max = lb
194 IF (PRESENT(da)) THEN
195 cpassert(all(shape(da) == [SIZE(v, 1), SIZE(v, 2), 3]))
196 da = 0.0_dp
197 da_max = la + 1
198 END IF
199 IF (PRESENT(db)) THEN
200 cpassert(all(shape(db) == [SIZE(v, 1), SIZE(v, 2), 3]))
201 db = 0.0_dp
202 db_max = lb + 1
203 END IF
204 ALLOCATE (moments(ncoset(degree), 1, 1), polynomial(0:da_max, 0:db_max, 0:degree, 3))
205 ALLOCATE (work(ncoset(da_max), ncoset(db_max)))
206 v = 0.0_dp
207 DO ib = 1, SIZE(beta)
208 DO ia = 1, SIZE(alpha)
209 p = alpha(ia) + beta(ib)
210 shift_a = beta(ib)*rab/p
211 shift_b = -alpha(ia)*rab/p
212 center = rac - shift_a
213 pref = exp(-alpha(ia)*beta(ib)/p*sum(rab**2))
214 IF (pref == 0.0_dp) cycle
215 CALL upf_projector_overlap(local%radial, degree, [p], center, 0, moments)
216 polynomial = 0.0_dp
217 DO axis = 1, 3
218 DO a = 0, da_max
219 DO b = 0, min(db_max, degree - a)
220 DO i = 0, a
221 DO j = 0, b
222 polynomial(a, b, i + j, axis) = polynomial(a, b, i + j, axis) &
223 + binomial(a, i)*binomial(b, j)*shift_a(axis)**(a - i)*shift_b(axis)**(b - j)
224 END DO
225 END DO
226 END DO
227 END DO
228 END DO
229 DO b = 1, ncoset(db_max)
230 pb = indco(:, b)
231 DO a = 1, ncoset(da_max)
232 pa = indco(:, a)
233 IF (sum(pa + pb) > degree) cycle
234 value = 0.0_dp
235 DO iz = 0, pa(3) + pb(3)
236 DO iy = 0, pa(2) + pb(2)
237 DO ix = 0, pa(1) + pb(1)
238 k = coset(ix, iy, iz)
239 value = value + polynomial(pa(1), pb(1), ix, 1)*polynomial(pa(2), pb(2), iy, 2) &
240 *polynomial(pa(3), pb(3), iz, 3)*moments(k, 1, 1)
241 END DO
242 END DO
243 END DO
244 work(a, b) = pref*value
245 END DO
246 END DO
247 DO b = 1, ncoset(lb)
248 pb = indco(:, b)
249 bb = (ib - 1)*ncoset(lb) + b
250 DO a = 1, ncoset(la)
251 pa = indco(:, a)
252 aa = (ia - 1)*ncoset(la) + a
253 v(aa, bb) = work(a, b)
254 DO axis = 1, 3
255 IF (PRESENT(da)) THEN
256 shifted = pa
257 shifted(axis) = shifted(axis) + 1
258 da(aa, bb, axis) = 2*alpha(ia)*work(coset(shifted(1), shifted(2), shifted(3)), b)
259 IF (pa(axis) > 0) THEN
260 shifted = pa
261 shifted(axis) = shifted(axis) - 1
262 da(aa, bb, axis) = da(aa, bb, axis) &
263 - pa(axis)*work(coset(shifted(1), shifted(2), shifted(3)), b)
264 END IF
265 END IF
266 IF (PRESENT(db)) THEN
267 shifted = pb
268 shifted(axis) = shifted(axis) + 1
269 db(aa, bb, axis) = 2*beta(ib)*work(a, coset(shifted(1), shifted(2), shifted(3)))
270 IF (pb(axis) > 0) THEN
271 shifted = pb
272 shifted(axis) = shifted(axis) - 1
273 db(aa, bb, axis) = db(aa, bb, axis) &
274 - pb(axis)*work(a, coset(shifted(1), shifted(2), shifted(3)))
275 END IF
276 END IF
277 END DO
278 END DO
279 END DO
280 END DO
281 END DO
282 END SUBROUTINE upf_local_matrix
283
284! **************************************************************************************************
285!> \brief Local potential against a single Cartesian Gaussian for RI.
286!> \param local Prepared radial potential.
287!> \param la Largest Cartesian degree.
288!> \param zeta Primitive exponents.
289!> \param rac Potential center minus Gaussian center.
290!> \param v Primitive-major Cartesian integrals.
291!> \param dv Optional Gaussian-center derivatives, in x,y,z order.
292! **************************************************************************************************
293 SUBROUTINE upf_local_ri(local, la, zeta, rac, v, dv)
294 TYPE(upf_local_type), INTENT(IN) :: local
295 INTEGER, INTENT(IN) :: la
296 REAL(kind=dp), INTENT(IN) :: zeta(:), rac(3)
297 REAL(kind=dp), INTENT(OUT) :: v(:)
298 REAL(kind=dp), INTENT(OUT), OPTIONAL :: dv(:, :)
299
300 INTEGER :: n, nder
301 REAL(kind=dp), ALLOCATABLE :: integrals(:, :, :)
302
303 nder = 0
304 IF (PRESENT(dv)) nder = 1
305 n = SIZE(zeta)*ncoset(la)
306 cpassert(SIZE(v) == n)
307 ALLOCATE (integrals(n, 1, ncoset(nder)))
308 CALL upf_projector_overlap(local%radial, la, zeta, rac, nder, integrals)
309 v = integrals(:, 1, 1)
310 IF (PRESENT(dv)) THEN
311 cpassert(all(shape(dv) == [n, 3]))
312 dv = integrals(:, 1, 2:4)
313 END IF
314 END SUBROUTINE upf_local_ri
315END MODULE upf_local_integrals
Calculates Bessel functions.
Definition bessel_lib.F:16
elemental impure real(kind=dp) function, public bessel0(x, l)
...
Definition bessel_lib.F:161
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
real(kind=dp), parameter, public degree
real(kind=dp), parameter, public fourpi
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
elemental real(kind=dp) function, public binomial(n, k)
The binomial coefficient n over k for 0 <= k <= n is calculated, otherwise zero is returned.
Definition mathlib.F:217
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
integer, dimension(:, :, :), allocatable, public coset
integer, dimension(:, :), allocatable, public indco
Local UPF matrix elements from the original radial potential. The Gaussian core electrostatics suppli...
subroutine, public upf_local_matrix(local, la, alpha, lb, beta, rab, rac, v, da, db)
Evaluate primitive three-center local integrals by the Gaussian product theorem.
subroutine, public upf_local_init(pot, alpha, degree, local, eps)
Prepare the short-range local potential outside parallel regions.
subroutine, public upf_local_ri(local, la, zeta, rac, v, dv)
Local potential against a single Cartesian Gaussian for RI.
subroutine, public upf_local_fourier(local, gvecs, position, volume, vg, dv_position, dv_g)
Fourier transform of the same short-range potential used in the AO integrals. USPP augmentation must ...
Half-numerical overlaps with the original scalar UPF radial projectors. Cartesian polynomials and ang...
subroutine, public upf_projector_init(pot, degree, projectors)
Prepare immutable radial and angular data outside parallel regions.
subroutine, public upf_projector_overlap(projectors, la, zeta, rac, nder, integrals, moment_origin)
Evaluate <Cartesian Gaussian|beta_i Y_lm> and AO-center derivatives.
Owned UPF dataset and radial conventions shared by ATOM and Quickstep. Dataset availability does not ...
Definition upf_types.F:12