(git:3d5d2e5)
Loading...
Searching...
No Matches
upf_types.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 Owned UPF dataset and radial conventions shared by ATOM and Quickstep.
10!> Dataset availability does not select an orbital representation or calculation method.
11! **************************************************************************************************
13 USE ieee_arithmetic, ONLY: ieee_is_finite
14 USE kinds, ONLY: default_path_length,&
16 dp
17#include "../base/base_uses.f90"
18
19 IMPLICIT NONE
20 PRIVATE
21
22 ! use same value as in atom_types!
23 INTEGER, PARAMETER :: lmat = 3
24
26 ! Original r*phi(r), one AE/PS pair per beta projector; not the atomic guesses.
27 REAL(dp), ALLOCATABLE :: ae_wfc(:, :), ps_wfc(:, :)
28 INTEGER, ALLOCATABLE :: angular_momenta(:)
30
32 ! Signed u=r*R(r), without a frozen-core assignment or assumed occupations.
33 INTEGER :: data_format = -1
34 REAL(dp), ALLOCATABLE :: wfc(:, :)
35 INTEGER, ALLOCATABLE :: indices(:), principal_quantum_numbers(:), angular_momenta(:)
37
39 INTEGER :: data_format = -1, cutoff_index = -1, lmax_aug = -1
40 CHARACTER(LEN=default_string_length) :: augmentation_shape = ""
41 REAL(dp) :: cutoff_radius = -1.0_dp, augmentation_epsilon = 1.e-12_dp
42 REAL(dp) :: core_energy = 0.0_dp
43 LOGICAL :: has_core_energy = .false.
44 REAL(dp), ALLOCATABLE :: occupations(:), multipoles(:, :, :)
45 ! AE core density per volume; AE local potential and core energy in Hartree.
46 REAL(dp), ALLOCATABLE :: rho_core(:), vlocal(:)
47 TYPE(upf_gipaw_orbitals_type), ALLOCATABLE :: gipaw_core_orbitals
48 END TYPE upf_paw_type
49
51 CHARACTER(LEN=2) :: symbol = ""
52 CHARACTER(LEN=default_string_length) :: pname = ""
53 INTEGER, DIMENSION(0:lmat) :: econf = 0
54 REAL(dp) :: zion = 0.0_dp
55 CHARACTER(LEN=default_string_length) :: version = ""
56 CHARACTER(LEN=default_path_length) :: filename = ""
57 ! <INFO>
58 INTEGER :: maxinfo = 100
59 CHARACTER(LEN=default_string_length), DIMENSION(100) &
60 :: info = ""
61 ! <HEADER>
62 CHARACTER(LEN=default_string_length) :: generated = ""
63 CHARACTER(LEN=default_string_length) :: author = ""
64 CHARACTER(LEN=default_string_length) :: date = ""
65 CHARACTER(LEN=default_string_length) :: comment = ""
66 CHARACTER(LEN=4) :: pseudo_type = ""
67 CHARACTER(LEN=15) :: relativistic = ""
68 CHARACTER(LEN=default_string_length) :: functional = ""
69 LOGICAL :: is_ultrasoft = .false.
70 LOGICAL :: is_paw = .false.
71 LOGICAL :: is_coulomb = .false.
72 LOGICAL :: has_so = .false.
73 LOGICAL :: has_wfc = .false.
74 LOGICAL :: has_gipaw = .false.
75 LOGICAL :: paw_as_gipaw = .false.
76 LOGICAL :: core_correction = .false.
77 LOGICAL :: with_metagga_info = .false.
78 REAL(dp) :: total_psenergy = 0.0_dp
79 REAL(dp) :: wfc_cutoff = 0.0_dp
80 REAL(dp) :: rho_cutoff = 0.0_dp
81 INTEGER :: l_max = -100
82 INTEGER :: l_max_rho = -1
83 INTEGER :: l_local = -1
84 INTEGER :: mesh_size = -1
85 INTEGER :: number_of_wfc = -1
86 INTEGER :: number_of_proj = -1
87 ! <MESH>
88 REAL(dp) :: dx = 0.0_dp
89 REAL(dp) :: xmin = 0.0_dp
90 REAL(dp) :: rmax = 0.0_dp
91 REAL(dp) :: zmesh = 0.0_dp
92 REAL(dp), DIMENSION(:), ALLOCATABLE :: r, rab
93 ! <NLCC>
94 REAL(dp), DIMENSION(:), ALLOCATABLE :: rho_nlcc
95 ! Preserve supplied samples. Only an explicit canonical convention permits XC use.
96 REAL(dp), ALLOCATABLE :: tau_nlcc(:), tau_atom(:)
97 CHARACTER(LEN=default_string_length) :: tau_nlcc_convention = "", tau_atom_convention = ""
98 ! <LOCAL>
99 REAL(dp), DIMENSION(:), ALLOCATABLE :: vlocal
100 ! <NONLOCAL>: keep the tabulated projector amplitude; D includes Ry -> Hartree.
101 ! beta stores beta(r), with the radial prefactor in PP_BETA removed.
102 REAL(dp), DIMENSION(:, :), ALLOCATABLE :: dion
103 REAL(dp), DIMENSION(:, :), ALLOCATABLE :: beta
104 INTEGER, DIMENSION(:), ALLOCATABLE :: lbeta
105 ! <AUGMENTATION>: PP_Q and r**2*Q_ij^L(r), in the original beta convention.
106 ! The pair index is j*(j-1)/2+i for i<=j; the last dimension starts at L=0.
107 REAL(dp), DIMENSION(:, :), ALLOCATABLE :: qij
108 REAL(dp), DIMENSION(:, :, :), ALLOCATABLE :: qijl
109 TYPE(upf_partial_waves_type), ALLOCATABLE :: partial_waves
110 TYPE(upf_paw_type), ALLOCATABLE :: paw
111 ! <SEMILOCAL>
112 REAL(dp), DIMENSION(:, :), ALLOCATABLE :: vsemi
113 END TYPE atom_upfpot_type
114
119CONTAINS
120
121! **************************************************************************************************
122!> \brief Select model-core tau for USPP and for NC with an explicitly supplied table.
123!> \param pot Original UPF metadata and optional model-core table.
124!> \return Whether this dataset uses the model-core convention instead of PAW reconstruction.
125! **************************************************************************************************
126 PURE FUNCTION upf_uses_model_core_tau(pot) RESULT(use_tau)
127 TYPE(atom_upfpot_type), INTENT(IN) :: pot
128 LOGICAL :: use_tau
129
130 use_tau = .NOT. pot%is_paw .AND. (pot%is_ultrasoft .OR. ALLOCATED(pot%tau_nlcc))
131 END FUNCTION upf_uses_model_core_tau
132
133! **************************************************************************************************
134!> \brief Obtain the independently supplied model-core kinetic density in Hartree per cubic bohr.
135!> Charge augmentation and NLCC charge do not determine this field. Unlabelled samples
136!> remain available as raw data, without an assumed generator normalization.
137!> \param pot Original UPF dataset.
138!> \param kinetic Spin-summed canonical core tau, zero for an absent partial core.
139!> \param available Whether the canonical field is defined for this dataset.
140!> \param reason Explanation when the field cannot be used.
141! **************************************************************************************************
142 SUBROUTINE upf_nlcc_kinetic(pot, kinetic, available, reason)
143 TYPE(atom_upfpot_type), INTENT(IN) :: pot
144 REAL(dp), ALLOCATABLE, INTENT(OUT) :: kinetic(:)
145 LOGICAL, INTENT(OUT) :: available
146 CHARACTER(LEN=*), INTENT(OUT) :: reason
147
148 LOGICAL :: has_core
149
150 cpassert(ALLOCATED(pot%r))
151 ALLOCATE (kinetic(SIZE(pot%r)), source=0.0_dp)
152 available = .false.
153 reason = "UPF model-core tau is missing. Supply canonical PP_TAUMOD or prepare an explicit model with add_upf_core_tau.py"
154 has_core = .false.
155 IF (ALLOCATED(pot%rho_nlcc)) has_core = any(pot%rho_nlcc /= 0.0_dp)
156 IF (.NOT. has_core) THEN
157 IF (ALLOCATED(pot%tau_nlcc)) THEN
158 IF (any(pot%tau_nlcc /= 0.0_dp)) THEN
159 reason = "UPF has a nonzero model-core kinetic density without a nonzero NLCC density"
160 RETURN
161 END IF
162 END IF
163 available = .true.
164 reason = ""
165 RETURN
166 END IF
167 IF (.NOT. pot%core_correction) THEN
168 reason = "UPF has a nonzero NLCC density with core_correction disabled"
169 RETURN
170 END IF
171 IF (.NOT. ALLOCATED(pot%tau_nlcc)) RETURN
172 IF (trim(pot%tau_nlcc_convention) /= "HARTREE_PER_VOLUME") THEN
173 reason = "UPF PP_TAUMOD requires an explicit hartree_per_volume convention before use in XC"
174 RETURN
175 END IF
176 cpassert(SIZE(pot%tau_nlcc) == SIZE(pot%r))
177 cpassert(all(ieee_is_finite(pot%tau_nlcc)))
178 kinetic(:) = pot%tau_nlcc
179 available = .true.
180 reason = ""
181 END SUBROUTINE upf_nlcc_kinetic
182
183! **************************************************************************************************
184!> \brief Composite Simpson weights for dr on the supplied UPF mesh index.
185!> \param pot Original radial coordinates and dr/d(index).
186!> \return Radial weights, with a last trapezoidal interval for an even mesh size.
187! **************************************************************************************************
188 FUNCTION upf_radial_weights(pot) RESULT(weights)
189 TYPE(atom_upfpot_type), INTENT(IN) :: pot
190 REAL(dp) :: weights(size(pot%r))
191
192 INTEGER :: n, ns
193
194 n = SIZE(pot%r)
195 cpassert(n >= 3 .AND. SIZE(pot%rab) == n)
196 cpassert(all(pot%r(2:) > pot%r(:n - 1)) .AND. all(pot%rab > 0.0_dp))
197 ns = n - 1 + modulo(n, 2)
198 weights = 0.0_dp
199 weights(1:ns:2) = 2.0_dp/3.0_dp
200 weights(2:ns - 1:2) = 4.0_dp/3.0_dp
201 weights(1) = 1.0_dp/3.0_dp
202 weights(ns) = 1.0_dp/3.0_dp
203 IF (ns < n) weights(n - 1:n) = weights(n - 1:n) + 0.5_dp
204 weights(:) = weights*pot%rab
205 END FUNCTION upf_radial_weights
206
207! **************************************************************************************************
208!> \brief Check for a complete projector-indexed pair of original AE and PS waves.
209!> \param pot Original UPF dataset; atomic guess waves do not satisfy this query.
210!> \return Whether every beta projector has a compatible full-wave pair.
211! **************************************************************************************************
212 PURE FUNCTION upf_has_complete_partial_waves(pot) RESULT(complete)
213 TYPE(atom_upfpot_type), INTENT(IN) :: pot
214 LOGICAL :: complete
215
216 INTEGER :: n, nb
217
218 complete = .false.
219 IF (.NOT. ALLOCATED(pot%lbeta)) RETURN
220 IF (.NOT. ALLOCATED(pot%r) .OR. .NOT. ALLOCATED(pot%rab)) RETURN
221 n = pot%mesh_size
222 nb = pot%number_of_proj
223 IF (n < 3 .OR. nb < 1 .OR. SIZE(pot%lbeta) /= nb) RETURN
224 IF (SIZE(pot%r) /= n .OR. SIZE(pot%rab) /= n) RETURN
225 IF (pot%is_paw) THEN
226 IF (.NOT. ALLOCATED(pot%paw)) RETURN
227 complete = compatible_waves(pot%paw)
228 ELSE
229 IF (.NOT. ALLOCATED(pot%partial_waves)) RETURN
230 complete = compatible_waves(pot%partial_waves)
231 END IF
232 CONTAINS
233! **************************************************************************************************
234!> \brief ...
235!> \param waves ...
236!> \return ...
237! **************************************************************************************************
238 PURE FUNCTION compatible_waves(waves) RESULT(compatible)
239 CLASS(upf_partial_waves_type), INTENT(IN) :: waves
240 LOGICAL :: compatible
241
242 compatible = .false.
243 IF (.NOT. ALLOCATED(waves%ae_wfc) .OR. .NOT. ALLOCATED(waves%ps_wfc)) RETURN
244 IF (.NOT. ALLOCATED(waves%angular_momenta)) RETURN
245 IF (any(shape(waves%ae_wfc) /= [n, nb])) RETURN
246 IF (any(shape(waves%ps_wfc) /= [n, nb])) RETURN
247 IF (SIZE(waves%angular_momenta) /= nb) RETURN
248 compatible = all(waves%angular_momenta == pot%lbeta)
249 END FUNCTION compatible_waves
251
252! **************************************************************************************************
253!> \brief Release every owned field and reset metadata before reusing a dataset.
254!> \param pot Owned UPF dataset.
255! **************************************************************************************************
256 PURE SUBROUTINE upf_release(pot)
257 TYPE(atom_upfpot_type), INTENT(INOUT) :: pot
258
259 pot = atom_upfpot_type()
260 END SUBROUTINE upf_release
261END MODULE upf_types
static int modulo(int a, int m)
Equivalent of Fortran's MODULO which always returns a positive number. https://gcc....
Definition fft_utils.h:60
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Owned UPF dataset and radial conventions shared by ATOM and Quickstep. Dataset availability does not ...
Definition upf_types.F:12
pure logical function, public upf_uses_model_core_tau(pot)
Select model-core tau for USPP and for NC with an explicitly supplied table.
Definition upf_types.F:127
real(dp) function, dimension(size(pot%r)), public upf_radial_weights(pot)
Composite Simpson weights for dr on the supplied UPF mesh index.
Definition upf_types.F:189
pure logical function, public upf_has_complete_partial_waves(pot)
Check for a complete projector-indexed pair of original AE and PS waves.
Definition upf_types.F:213
pure subroutine, public upf_release(pot)
Release every owned field and reset metadata before reusing a dataset.
Definition upf_types.F:257
subroutine, public upf_nlcc_kinetic(pot, kinetic, available, reason)
Obtain the independently supplied model-core kinetic density in Hartree per cubic bohr....
Definition upf_types.F:143