14 USE atom_upf,
ONLY: atom_upfpot_type,&
30#include "../base/base_uses.f90"
34 CHARACTER(LEN=*),
PARAMETER,
PRIVATE :: moduleN =
'uspp_augmentation'
37 INTEGER :: nproj = 0, lmax = -1
38 INTEGER,
ALLOCATABLE :: radial_index(:), angular_index(:), lbeta(:), radial_end(:, :)
39 REAL(
dp) :: realspace_radius = 0.0_dp
41 REAL(kind=
dp),
ALLOCATABLE :: r(:), weighted_q(:, :, :), gaunt(:, :, :), q(:, :)
42 REAL(kind=
dp),
ALLOCATABLE :: radial_x(:), radial_value(:, :, :), radial_slope(:, :, :)
43 INTEGER(int_8) :: fourier_budget = -1_int_8
44 INTEGER,
ALLOCATABLE :: fourier_map(:)
45 REAL(
dp),
ALLOCATABLE :: fourier_norm(:), fourier_radial(:, :, :), fourier_next(:, :, :)
63 TYPE(atom_upfpot_type),
INTENT(IN) :: pot
67 INTEGER :: i, j, l, m, n, nc, p, pair, q, s
68 REAL(kind=
dp),
ALLOCATABLE :: weights(:)
70 cpassert(.NOT. pot%has_so .AND. .NOT. pot%is_paw)
71 cpassert(
ALLOCATED(pot%qijl))
72 cpassert(projectors%degree >= maxval(pot%lbeta))
73 cpassert(all(projectors%lbeta == pot%lbeta))
75 cpassert(n >= 3 .AND.
SIZE(pot%rab) == n)
76 cpassert(all(pot%r >= 0.0_dp) .AND. all(pot%rab > 0.0_dp))
77 cpassert(all(pot%r(2:) > pot%r(:n - 1)))
78 nc = pot%number_of_proj*(pot%number_of_proj + 1)/2
79 augmentation%nproj = projectors%nproj
80 augmentation%lmax = 2*maxval(pot%lbeta)
83 cpassert(all(shape(pot%qijl) == [n, nc, augmentation%lmax + 1]))
84 cpassert(lbound(pot%qijl, 3) == 0)
85 ALLOCATE (augmentation%r(n), weights(n))
86 augmentation%r(:) = pot%r
87 weights(:) = upf_radial_weights(pot)
92 IF (any(pot%qijl(n, :, :) /= 0.0_dp))
EXIT
95 ALLOCATE (augmentation%weighted_q(n, nc, 0:augmentation%lmax))
96 DO l = 0, augmentation%lmax
98 augmentation%weighted_q(:, pair, l) = weights(:n)*pot%qijl(:n, pair, l)
101 n = augmentation%nproj
102 ALLOCATE (augmentation%radial_index(n), augmentation%angular_index(n), &
103 augmentation%lbeta(pot%number_of_proj))
104 augmentation%radial_index(:) = projectors%radial_index
105 augmentation%angular_index(:) = projectors%angular_index
106 augmentation%lbeta(:) = pot%lbeta
107 ALLOCATE (augmentation%gaunt(n, n, (augmentation%lmax + 1)**2), augmentation%q(n, n))
108 augmentation%gaunt = 0.0_dp
109 augmentation%q = 0.0_dp
111 j = projectors%radial_index(q)
113 m = projectors%angular_index(q) - l*l
115 i = projectors%radial_index(p)
118 augmentation%gaunt(p, q, :) = augmentation%gaunt(p, q, :) + &
120 projectors%angular_index(p), :(augmentation%lmax + 1)**2)
122 pair = max(i, j)*(max(i, j) - 1)/2 + min(i, j)
123 IF (projectors%angular_index(p) == projectors%angular_index(q))
THEN
124 augmentation%q(p, q) = sum(augmentation%weighted_q(:, pair, 0))
139 TYPE(atom_upfpot_type),
INTENT(IN) :: pot
142 INTEGER :: first, l, last, n, nc, pair
143 REAL(kind=
dp),
ALLOCATABLE :: values(:), x(:)
145 cpassert(
ALLOCATED(pot%qijl) .AND.
ALLOCATED(augmentation%r))
146 cpassert(
SIZE(pot%r) ==
SIZE(augmentation%r))
147 cpassert(all(pot%r == augmentation%r))
148 cpassert(all(pot%lbeta == augmentation%lbeta))
149 IF (
ALLOCATED(augmentation%radial_x))
RETURN
151 IF (pot%r(1) == 0.0_dp) first = 2
152 n =
SIZE(pot%r) - first + 1
154 nc =
SIZE(pot%qijl, 2)
155 ALLOCATE (x(n), values(n), augmentation%radial_x(n + 1), &
156 augmentation%radial_value(n + 1, nc, 0:augmentation%lmax), &
157 augmentation%radial_slope(n + 1, nc, 0:augmentation%lmax), &
158 augmentation%radial_end(nc, 0:augmentation%lmax))
159 x(:) = pot%r(first:)**2
160 augmentation%radial_x(1) = 0.0_dp
161 augmentation%radial_x(2:) = x
162 augmentation%radial_value = 0.0_dp
163 augmentation%radial_slope = 0.0_dp
164 augmentation%radial_end = 1
165 augmentation%realspace_radius = 0.0_dp
166 DO l = 0, augmentation%lmax
168 IF (all(pot%qijl(:, pair, l) == 0.0_dp)) cycle
172 DO WHILE (pot%qijl(last, pair, l) == 0.0_dp)
175 augmentation%radial_end(pair, l) = last - first + 3
176 augmentation%realspace_radius = max(augmentation%realspace_radius, pot%r(min(last + 1,
SIZE(pot%r))))
177 values(:) = pot%qijl(first:, pair, l)/pot%r(first:)**(l + 2)
180 CALL spline3ders(x, values, augmentation%radial_x, &
181 ynew=augmentation%radial_value(:, pair, l), &
182 dynew=augmentation%radial_slope(:, pair, l))
200 REAL(kind=
dp),
INTENT(IN) :: displacement(3)
201 REAL(kind=
dp),
INTENT(OUT) :: qr(:, :)
202 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: gradient(:, :, :), hessian(:, :, :, :)
204 REAL(
dp),
ALLOCATABLE :: ddharmonics(:, :, :), dharmonics(:, :), &
207 ALLOCATE (harmonics((augmentation%lmax + 1)**2), &
208 dharmonics(3, (augmentation%lmax + 1)**2), &
209 ddharmonics(3, 3, (augmentation%lmax + 1)**2))
210 CALL realspace_with_workspace(augmentation, displacement, qr, gradient, hessian, &
211 harmonics, dharmonics, ddharmonics)
225 SUBROUTINE realspace_with_workspace(augmentation, displacement, qr, gradient, hessian, &
226 harmonics, dharmonics, ddharmonics)
228 REAL(kind=
dp),
INTENT(IN) :: displacement(3)
229 REAL(kind=
dp),
INTENT(OUT) :: qr(:, :)
230 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: gradient(:, :, :), hessian(:, :, :, :)
231 REAL(kind=
dp),
INTENT(OUT) :: harmonics(:), dharmonics(:, :), &
234 INTEGER :: a, axis, axis2, hi, i, j, l, lm, lo, m, &
235 mid, p, pair, powers(3), q, reduced(3)
236 REAL(kind=
dp) :: angular, angular_gradient(3), angular_hessian(3, 3), c0, c1, c2, c3, c4, &
237 c5, factor, h, radial, radial_d, radial_dd, s, t, term,
value, value_gradient(3), &
240 cpassert(
ALLOCATED(augmentation%radial_x))
241 cpassert(all(shape(qr) == augmentation%nproj))
243 IF (
PRESENT(gradient))
THEN
244 IF (.NOT. (all(shape(gradient) == [augmentation%nproj, augmentation%nproj, 3])))
THEN
245 cpabort(
"Invalid USPP augmentation array dimensions")
249 IF (
PRESENT(hessian))
THEN
250 IF (.NOT. (all(shape(hessian) == [augmentation%nproj, augmentation%nproj, 3, 3])))
THEN
251 cpabort(
"Invalid USPP augmentation array dimensions")
255 s = sum(displacement**2)
256 hi =
SIZE(augmentation%radial_x)
257 IF (s > augmentation%realspace_radius**2)
RETURN
259 DO WHILE (hi - lo > 1)
261 IF (s < augmentation%radial_x(mid))
THEN
267 h = augmentation%radial_x(hi) - augmentation%radial_x(lo)
268 t = (s - augmentation%radial_x(lo))/h
272 DO l = 0, augmentation%lmax
278 harmonics(lm) = harmonics(lm) + factor*product(displacement**powers)
280 IF (powers(axis) == 0) cycle
282 reduced(axis) = reduced(axis) - 1
283 term = factor*real(powers(axis),
dp)
284 dharmonics(axis, lm) = dharmonics(axis, lm) + term*product(displacement**reduced)
285 IF (
PRESENT(hessian))
THEN
287 IF (reduced(axis2) == 0) cycle
288 reduced(axis2) = reduced(axis2) - 1
289 ddharmonics(axis, axis2, lm) = ddharmonics(axis, axis2, lm) + &
290 term*real(reduced(axis2) + 1,
dp)*product(displacement**reduced)
291 reduced(axis2) = reduced(axis2) + 1
298 DO q = 1, augmentation%nproj
299 j = augmentation%radial_index(q)
301 i = augmentation%radial_index(p)
302 pair = max(i, j)*(max(i, j) - 1)/2 + min(i, j)
303 DO l = abs(augmentation%lbeta(i) - augmentation%lbeta(j)), &
304 augmentation%lbeta(i) + augmentation%lbeta(j), 2
305 IF (lo >= augmentation%radial_end(pair, l)) cycle
306 c0 = augmentation%radial_value(lo, pair, l)
307 c1 = h*augmentation%radial_slope(lo, pair, l)
308 c2 = 3.0_dp*(augmentation%radial_value(hi, pair, l) - c0) - &
309 2.0_dp*c1 - h*augmentation%radial_slope(hi, pair, l)
310 c3 = 2.0_dp*(c0 - augmentation%radial_value(hi, pair, l)) + &
311 c1 + h*augmentation%radial_slope(hi, pair, l)
314 IF (hi == augmentation%radial_end(pair, l))
THEN
317 c3 = -10.0_dp*c0 - 6.0_dp*c1 - 3.0_dp*c2
318 c4 = 15.0_dp*c0 + 8.0_dp*c1 + 3.0_dp*c2
319 c5 = -6.0_dp*c0 - 3.0_dp*c1 - c2
321 radial = c0 + t*(c1 + t*(c2 + t*(c3 + t*(c4 + t*c5))))
322 radial_d = (c1 + t*(2.0_dp*c2 + t*(3.0_dp*c3 + t*(4.0_dp*c4 + t*5.0_dp*c5))))/h
323 IF (
PRESENT(hessian)) radial_dd = (2.0_dp*c2 + t*(6.0_dp*c3 + t*(12.0_dp*c4 + t*20.0_dp*c5)))/h**2
325 angular_gradient = 0.0_dp
326 angular_hessian = 0.0_dp
327 DO lm = l*l + 1, (l + 1)**2
328 factor = augmentation%gaunt(p, q, lm)
329 angular = angular + factor*harmonics(lm)
330 angular_gradient = angular_gradient + factor*dharmonics(:, lm)
331 IF (
PRESENT(hessian)) angular_hessian = angular_hessian + factor*ddharmonics(:, :, lm)
333 value = radial*angular
334 qr(p, q) = qr(p, q) +
value
335 IF (
PRESENT(gradient))
THEN
336 value_gradient = 2.0_dp*displacement*radial_d*angular + radial*angular_gradient
337 gradient(p, q, :) = gradient(p, q, :) + value_gradient
339 IF (
PRESENT(hessian))
THEN
342 value_hessian(axis, axis2) = &
343 4.0_dp*displacement(axis)*displacement(axis2)*radial_dd*angular + &
344 2.0_dp*radial_d*(displacement(axis)*angular_gradient(axis2) + &
345 displacement(axis2)*angular_gradient(axis)) + &
346 radial*angular_hessian(axis, axis2)
348 value_hessian(axis2, axis2) = value_hessian(axis2, axis2) + 2.0_dp*radial_d*angular
350 hessian(p, q, :, :) = hessian(p, q, :, :) + value_hessian
354 IF (
PRESENT(gradient)) gradient(q, p, :) = gradient(p, q, :)
355 IF (
PRESENT(hessian)) hessian(q, p, :, :) = hessian(p, q, :, :)
358 END SUBROUTINE realspace_with_workspace
370 REAL(kind=
dp),
INTENT(IN) :: displacements(:, :), density(:, :)
371 REAL(kind=
dp),
INTENT(INOUT) :: rho(:), gradient(:, :)
373 INTEGER :: axis, n, point
374 REAL(
dp),
ALLOCATABLE :: ddharmonics(:, :, :), dharmonics(:, :), &
376 REAL(kind=
dp),
ALLOCATABLE :: dqr(:, :, :), qr(:, :)
378 n = augmentation%nproj
379 cpassert(all(shape(density) == n))
380 cpassert(all(shape(displacements) == [3,
SIZE(rho)]))
381 cpassert(all(shape(gradient) == shape(displacements)))
382 IF (
SIZE(rho) > 0)
THEN
383 cpassert(
ALLOCATED(augmentation%radial_x))
385 ALLOCATE (qr(n, n), dqr(n, n, 3))
386 ALLOCATE (harmonics((augmentation%lmax + 1)**2), &
387 dharmonics(3, (augmentation%lmax + 1)**2), &
388 ddharmonics(3, 3, (augmentation%lmax + 1)**2))
389 DO point = 1,
SIZE(rho)
391 IF (sum(displacements(:, point)**2) > augmentation%realspace_radius**2) cycle
392 CALL realspace_with_workspace(augmentation, displacements(:, point), qr, dqr, &
393 harmonics=harmonics, dharmonics=dharmonics, ddharmonics=ddharmonics)
394 rho(point) = rho(point) + sum(density*qr)
396 gradient(axis, point) = gradient(axis, point) + sum(density*dqr(:, :, axis))
415 matrix, density, center_gradient, point_gradient)
417 REAL(kind=
dp),
INTENT(IN) :: displacements(:, :), weights(:), &
418 v_rho(:), v_gradient(:, :)
419 REAL(kind=
dp),
INTENT(OUT) :: matrix(:, :)
420 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: density(:, :)
421 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: center_gradient(3), point_gradient(:, :)
423 INTEGER :: axis, axis2, n, point
424 REAL(
dp),
ALLOCATABLE :: ddharmonics(:, :, :), dharmonics(:, :), &
426 REAL(kind=
dp) :: derivative
427 REAL(kind=
dp),
ALLOCATABLE :: ddqr(:, :, :, :), dqr(:, :, :), qr(:, :)
429 n = augmentation%nproj
430 cpassert(all(shape(matrix) == n))
431 cpassert(all(shape(displacements) == [3,
SIZE(weights)]))
432 cpassert(
SIZE(v_rho) ==
SIZE(weights))
433 cpassert(all(shape(v_gradient) == shape(displacements)))
434 ALLOCATE (qr(n, n), dqr(n, n, 3))
435 ALLOCATE (harmonics((augmentation%lmax + 1)**2), &
436 dharmonics(3, (augmentation%lmax + 1)**2), &
437 ddharmonics(3, 3, (augmentation%lmax + 1)**2))
439 IF (
PRESENT(center_gradient) .OR.
PRESENT(point_gradient))
THEN
440 cpassert(
PRESENT(density))
441 cpassert(all(shape(density) == n))
442 ALLOCATE (ddqr(n, n, 3, 3))
444 IF (
PRESENT(center_gradient)) center_gradient = 0.0_dp
445 IF (
PRESENT(point_gradient))
THEN
446 cpassert(all(shape(point_gradient) == shape(displacements)))
447 point_gradient = 0.0_dp
449 DO point = 1,
SIZE(weights)
450 IF (weights(point) == 0.0_dp) cycle
451 IF (v_rho(point) == 0.0_dp .AND. all(v_gradient(:, point) == 0.0_dp)) cycle
452 cpassert(
ALLOCATED(augmentation%radial_x))
453 IF (sum(displacements(:, point)**2) > augmentation%realspace_radius**2) cycle
454 IF (
ALLOCATED(ddqr))
THEN
455 CALL realspace_with_workspace(augmentation, displacements(:, point), qr, dqr, ddqr, &
456 harmonics, dharmonics, ddharmonics)
458 CALL realspace_with_workspace(augmentation, displacements(:, point), qr, dqr, &
459 harmonics=harmonics, dharmonics=dharmonics, ddharmonics=ddharmonics)
461 matrix(:, :) = matrix + weights(point)*v_rho(point)*qr
463 matrix(:, :) = matrix + weights(point)*v_gradient(axis, point)*dqr(:, :, axis)
465 IF (
ALLOCATED(ddqr))
THEN
467 derivative = v_rho(point)*sum(density*dqr(:, :, axis))
469 derivative = derivative + v_gradient(axis2, point)*sum(density*ddqr(:, :, axis2, axis))
471 IF (
PRESENT(center_gradient)) center_gradient(axis) = center_gradient(axis) - weights(point)*derivative
472 IF (
PRESENT(point_gradient)) point_gradient(axis, point) = weights(point)*derivative
488 REAL(
dp),
INTENT(IN) :: gvecs(:, :)
489 INTEGER(int_8),
INTENT(IN),
OPTIONAL :: max_bytes
491 INTEGER :: capacity, ig, index, lmax, nc, ng, unique
492 INTEGER(int_8) :: budget, entry_bytes, index_bytes
493 INTEGER,
ALLOCATABLE :: order(:)
495 REAL(
dp),
ALLOCATABLE :: norms(:), sorted(:)
497 cpassert(
SIZE(gvecs, 1) == 3)
498 budget = 64_int_8*1024*1024
499 IF (
PRESENT(max_bytes)) budget = max_bytes
500 cpassert(budget >= 0_int_8)
502 nc =
SIZE(augmentation%weighted_q, 2)
503 lmax = augmentation%lmax
504 cpassert(nc > 0 .AND. lmax >= 0)
505 index_bytes = int(ng,
int_8)*(storage_size(0.0_dp) + storage_size(0))/8
506 entry_bytes = 2_int_8*nc*(lmax + 1)*storage_size(0.0_dp)/8
507 capacity = int(min(int(ng,
int_8), max(0_int_8, (budget - index_bytes)/entry_bytes)))
508 IF (capacity > 0)
THEN
511 norms(ig) = sqrt(sum(gvecs(:, ig)*gvecs(:, ig)))
513 IF (
ALLOCATED(augmentation%fourier_norm) .AND. augmentation%fourier_budget == budget)
THEN
514 IF (
SIZE(augmentation%fourier_norm) == ng)
THEN
515 IF (all(augmentation%fourier_norm == norms))
RETURN
519 IF (
ALLOCATED(augmentation%fourier_norm))
THEN
520 DEALLOCATE (augmentation%fourier_norm, augmentation%fourier_map, &
521 augmentation%fourier_radial, augmentation%fourier_next)
523 augmentation%fourier_budget = budget
524 IF (capacity == 0)
RETURN
525 ALLOCATE (augmentation%fourier_norm, source=norms)
526 ALLOCATE (augmentation%fourier_map(ng), order(ng), sorted(ng))
527 augmentation%fourier_map = 0
533 IF (sorted(ig) == 0.0_dp) cycle
534 IF (sorted(ig) /= previous) unique = unique + 1
535 previous = sorted(ig)
537 capacity = min(capacity, unique)
538 ALLOCATE (augmentation%fourier_radial(nc, 0:lmax, capacity), &
539 augmentation%fourier_next(nc, 0:lmax, capacity))
543 IF (sorted(ig) == 0.0_dp) cycle
544 IF (sorted(ig) /= previous)
THEN
545 IF (index == capacity)
EXIT
547 previous = sorted(ig)
548 CALL augmentation_radial(augmentation%r, augmentation%weighted_q, previous, &
549 augmentation%fourier_radial(:, :, index), augmentation%fourier_next(:, :, index))
551 augmentation%fourier_map(order(ig)) = index
563 SUBROUTINE augmentation_radial(r, weighted_q, norm_g, radial, radial_next)
564 REAL(
dp),
INTENT(IN) :: r(:), weighted_q(:, :, 0:), norm_g
565 REAL(
dp),
INTENT(OUT) :: radial(:, 0:)
566 REAL(
dp),
INTENT(OUT),
OPTIONAL :: radial_next(:, 0:)
569 REAL(
dp),
ALLOCATABLE :: work(:)
571 nr =
SIZE(weighted_q, 1)
573 DO l = 0, ubound(weighted_q, 3)
574 IF (
PRESENT(radial_next))
THEN
575 work(:) = r(:nr)*
bessel0(norm_g*r(:nr), l + 1)
576 radial_next(:, l) = matmul(work, weighted_q(:, :, l))
578 work(:) =
bessel0(norm_g*r(:nr), l)
579 radial(:, l) = matmul(work, weighted_q(:, :, l))
581 END SUBROUTINE augmentation_radial
597 REAL(kind=
dp),
INTENT(IN) :: g(3), position(3), volume
598 COMPLEX(KIND=dp),
INTENT(OUT) :: qg(:, :)
599 COMPLEX(KIND=dp),
INTENT(OUT),
OPTIONAL :: strain(:, :, :, :)
600 INTEGER,
INTENT(IN),
OPTIONAL :: grid_index
602 COMPLEX(KIND=dp) :: phase, phase_l
603 INTEGER :: a, axis, cached, i, j, l, lm, m, p, &
605 REAL(kind=
dp) :: angular, angular_derivative(3), &
606 direction(3, 1), monomial, norm_g, &
608 REAL(kind=
dp),
ALLOCATABLE :: harmonics(:), radial(:, :), &
609 radial_next(:, :), solid_gradient(:, :)
611 cpassert(volume > 0.0_dp)
612 cpassert(all(shape(qg) == augmentation%nproj))
613 IF (
PRESENT(strain))
THEN
614 IF (.NOT. (all(shape(strain) == [augmentation%nproj, augmentation%nproj, 3, 3])))
THEN
615 cpabort(
"Invalid USPP augmentation array dimensions")
617 strain = cmplx(0.0_dp, 0.0_dp,
dp)
619 norm_g = sqrt(sum(g*g))
620 IF (norm_g == 0.0_dp)
THEN
621 qg(:, :) = cmplx(augmentation%q/volume, 0.0_dp, kind=
dp)
622 IF (
PRESENT(strain))
THEN
624 strain(:, :, axis, axis) = -qg
629 direction(:, 1) = g/norm_g
630 ALLOCATE (harmonics((augmentation%lmax + 1)**2))
631 ALLOCATE (radial(
SIZE(augmentation%weighted_q, 2), 0:augmentation%lmax))
632 IF (
PRESENT(strain))
THEN
633 ALLOCATE (solid_gradient(3, (augmentation%lmax + 1)**2), &
634 radial_next(
SIZE(radial, 1), 0:augmentation%lmax))
635 solid_gradient = 0.0_dp
638 IF (
PRESENT(grid_index) .AND.
ALLOCATED(augmentation%fourier_map))
THEN
641 IF (grid_index >= 1 .AND. grid_index <=
SIZE(augmentation%fourier_map))
THEN
642 IF (augmentation%fourier_norm(grid_index) == norm_g) cached = augmentation%fourier_map(grid_index)
646 radial(:, :) = augmentation%fourier_radial(:, :, cached)
647 IF (
PRESENT(strain)) radial_next(:, :) = augmentation%fourier_next(:, :, cached)
649 CALL augmentation_radial(augmentation%r, augmentation%weighted_q, norm_g, radial, radial_next)
651 DO l = 0, augmentation%lmax
654 CALL y_lm(direction,
value, l, m)
655 harmonics(lm) = value(1)
656 IF (
PRESENT(strain))
THEN
661 IF (powers(axis) == 0) cycle
662 monomial = real(powers(axis),
dp)
663 powers(axis) = powers(axis) - 1
664 solid_gradient(axis, lm) = solid_gradient(axis, lm) + &
665 orbtramat(l)%slm(l + m + 1, a)*monomial*product(direction(:, 1)**powers)
671 phase = exp(cmplx(0.0_dp, -dot_product(g, position), kind=
dp))*
fourpi/volume
672 qg = cmplx(0.0_dp, 0.0_dp, kind=
dp)
673 DO q = 1, augmentation%nproj
674 j = augmentation%radial_index(q)
676 i = augmentation%radial_index(p)
677 pair = max(i, j)*(max(i, j) - 1)/2 + min(i, j)
678 DO l = abs(augmentation%lbeta(i) - augmentation%lbeta(j)), &
679 augmentation%lbeta(i) + augmentation%lbeta(j), 2
680 angular = dot_product(augmentation%gaunt(p, q, l*l + 1:(l + 1)**2), &
681 harmonics(l*l + 1:(l + 1)**2))
682 phase_l = cmplx(0.0_dp, -1.0_dp, kind=
dp)**l
683 qg(p, q) = qg(p, q) + phase_l*angular*radial(pair, l)
684 IF (
PRESENT(strain))
THEN
685 angular_derivative = matmul(solid_gradient(:, l*l + 1:(l + 1)**2), &
686 augmentation%gaunt(p, q, l*l + 1:(l + 1)**2))
688 angular_derivative = radial(pair, l)/norm_g*angular_derivative &
689 - radial_next(pair, l)*angular*direction(:, 1)
691 strain(p, q, :, axis) = strain(p, q, :, axis) - phase*phase_l*g*angular_derivative(axis)
695 qg(p, q) = phase*qg(p, q)
697 IF (
PRESENT(strain))
THEN
699 strain(p, q, axis, axis) = strain(p, q, axis, axis) - qg(p, q)
701 strain(q, p, :, :) = strain(p, q, :, :)
718 REAL(kind=
dp),
INTENT(IN) :: gvecs(:, :), position(3), volume, &
720 COMPLEX(KIND=dp),
INTENT(INOUT) :: rho(:)
722 COMPLEX(KIND=dp),
ALLOCATABLE :: qg(:, :)
725 cpassert(
SIZE(gvecs, 1) == 3 .AND.
SIZE(gvecs, 2) ==
SIZE(rho))
726 cpassert(all(shape(density_matrix) == augmentation%nproj))
727 ALLOCATE (qg(augmentation%nproj, augmentation%nproj))
730 rho(ig) = rho(ig) + sum(density_matrix*qg)
748 REAL(kind=
dp),
INTENT(IN) :: gvecs(:, :), position(3), volume
749 COMPLEX(KIND=dp),
INTENT(IN) :: vg(:)
750 REAL(kind=
dp),
INTENT(IN) :: multiplicity(:)
751 REAL(kind=
dp),
INTENT(OUT) :: matrix(:, :)
752 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: derivative(:, :, :), strain(:, :, :, :)
754 COMPLEX(KIND=dp),
ALLOCATABLE :: dq(:, :, :, :), qg(:, :)
755 INTEGER :: idir, ig, jdir
757 cpassert(
SIZE(gvecs, 1) == 3 .AND.
SIZE(gvecs, 2) ==
SIZE(vg))
758 cpassert(
SIZE(multiplicity) ==
SIZE(vg))
759 cpassert(all(shape(matrix) == augmentation%nproj))
760 ALLOCATE (qg(augmentation%nproj, augmentation%nproj))
762 IF (
PRESENT(derivative))
THEN
763 IF (.NOT. (all(shape(derivative) == [augmentation%nproj, augmentation%nproj, 3])))
THEN
764 cpabort(
"Invalid USPP augmentation array dimensions")
768 IF (
PRESENT(strain))
THEN
769 IF (.NOT. (all(shape(strain) == [augmentation%nproj, augmentation%nproj, 3, 3])))
THEN
770 cpabort(
"Invalid USPP augmentation array dimensions")
772 ALLOCATE (dq(augmentation%nproj, augmentation%nproj, 3, 3))
777 IF (
PRESENT(strain))
THEN
780 strain(:, :, idir, jdir) = strain(:, :, idir, jdir) + volume*multiplicity(ig)* &
781 REAL(conjg(dq(:, :, idir, jdir))*vg(ig), kind=
dp)
785 matrix(:, :) = matrix + volume*multiplicity(ig)*real(conjg(qg)*vg(ig), kind=
dp)
786 IF (
PRESENT(derivative))
THEN
788 derivative(:, :, idir) = derivative(:, :, idir) + volume*multiplicity(ig)* &
789 REAL(cmplx(0.0_dp, gvecs(idir, ig),
dp)*conjg(qg)*vg(ig), kind=
dp)
Routines that process Quantum Espresso UPF files.
Calculates Bessel functions.
elemental impure real(kind=dp) function, public bessel0(x, l)
...
Routine for sorting an array.
subroutine, public cp_1d_r_sort(arr, n, indices)
Sorts an array inplace using a combination of merge- and bubble-sort. It also returns the indices,...
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
Definition of mathematical constants and functions.
real(kind=dp), parameter, public fourpi
Provides Cartesian and spherical orbital pointers and indices.
subroutine, public init_orbital_pointers(maxl)
Initialize or update the orbital pointers.
integer, dimension(:), allocatable, public nco
integer, dimension(:), allocatable, public ncoset
integer, dimension(:, :), allocatable, public indco
Calculate spherical harmonics.
Simple splines Splines are fully specified by the interpolation points, except that at the ends,...
subroutine, public spline3ders(x, y, xnew, ynew, dynew, d2ynew)
...
Half-numerical overlaps with the original scalar UPF radial projectors. Cartesian polynomials and ang...
Direct reciprocal-space reference for scalar UPF augmentation. Uses the complete tabulated radial mes...
subroutine, public uspp_augmentation_collocate_atom(augmentation, displacements, density, rho, gradient)
Add one center's augmentation density and gradient to arbitrary atom-grid points.
subroutine, public uspp_augmentation_collocate(augmentation, gvecs, position, volume, density_matrix, rho)
Add the augmentation density on a list of reciprocal vectors.
subroutine, public uspp_augmentation_integrate(augmentation, gvecs, position, volume, vg, multiplicity, matrix, derivative, strain)
Adjoint of augmentation collocation: integrate a real local potential against Q.
subroutine, public uspp_augmentation_prepare_fourier(augmentation, gvecs, max_bytes)
Cache exact radial transforms for repeated reciprocal-vector lengths. The retained arrays are bounded...
subroutine, public uspp_augmentation_prepare_realspace(pot, augmentation)
Prepare regular radial splines for atom-grid augmentation quadrature. UPF stores r**2 Q_ij^L(r)....
subroutine, public uspp_augmentation_realspace(augmentation, displacement, qr, gradient, hessian)
Evaluate the augmentation matrix and derivatives at a Cartesian displacement. Uses cubic splines with...
subroutine, public uspp_augmentation_init(pot, projectors, augmentation)
Prepare radial quadrature and Gaunt coefficients in the native beta convention.
subroutine, public uspp_augmentation_fourier(augmentation, g, position, volume, qg, strain, grid_index)
Evaluate Q_ij(G) = integral Q_ij(r-R) exp(-i G.r) dr / volume. Direct radial quadrature is a referenc...
subroutine, public uspp_augmentation_integrate_atom(augmentation, displacements, weights, v_rho, v_gradient, matrix, density, center_gradient, point_gradient)
Adjoint of the atom-grid density map, including the GGA gradient term.