Line data Source code
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 Routines that process Quantum Espresso UPF files.
10 : !> \par History
11 : !> * 07.2018 CP2K-SIRIUS interface [Juerg Hutter]
12 : !> * 02.2016 created [Juerg Hutter]
13 : ! **************************************************************************************************
14 : MODULE atom_upf
15 : USE cp_parser_methods, ONLY: parser_get_next_line,&
16 : parser_get_object,&
17 : parser_test_next_token
18 : USE cp_parser_types, ONLY: cp_parser_type,&
19 : parser_create,&
20 : parser_release
21 : USE ieee_arithmetic, ONLY: ieee_is_finite
22 : USE kinds, ONLY: default_string_length,&
23 : dp
24 : USE periodic_table, ONLY: get_ptable_info,&
25 : ptable
26 : USE upf_types, ONLY: atom_upfpot_type,&
27 : upf_gipaw_orbitals_type,&
28 : upf_partial_waves_type,&
29 : upf_radial_weights,&
30 : upf_release
31 : #include "../base/base_uses.f90"
32 :
33 : IMPLICIT NONE
34 :
35 : PRIVATE
36 : PUBLIC :: atom_read_upf, atom_upfpot_type, atom_release_upf, upf_radial_weights, upf_partial_waves_type
37 :
38 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'atom_upf'
39 :
40 : ! **************************************************************************************************
41 :
42 : CONTAINS
43 :
44 : ! **************************************************************************************************
45 : !> \brief ...
46 : !> \param pot ...
47 : !> \param upf_filename ...
48 : !> \param read_header ...
49 : !> \param read_augmentation Import scalar USPP augmentation and optional full partial waves explicitly.
50 : !> This reader option does not enable USPP in a calculation method.
51 : !> \param read_paw Import original scalar PAW one-center data and optional GIPAW orbitals.
52 : ! **************************************************************************************************
53 42 : SUBROUTINE atom_read_upf(pot, upf_filename, read_header, read_augmentation, read_paw)
54 :
55 : TYPE(atom_upfpot_type) :: pot
56 : CHARACTER(len=*), INTENT(IN) :: upf_filename
57 : LOGICAL, INTENT(IN), OPTIONAL :: read_header, read_augmentation, read_paw
58 :
59 : CHARACTER(LEN=2) :: symbol
60 : INTEGER :: l, ncore, nel
61 : LOGICAL :: readall, readaug, readpaw
62 :
63 42 : IF (PRESENT(read_header)) THEN
64 4 : readall = .NOT. read_header
65 : ELSE
66 38 : readall = .TRUE.
67 : END IF
68 42 : readaug = .FALSE.
69 42 : IF (PRESENT(read_augmentation)) readaug = read_augmentation
70 42 : readpaw = .FALSE.
71 42 : IF (PRESENT(read_paw)) readpaw = read_paw
72 42 : readaug = readaug .OR. readpaw
73 :
74 : ! filename
75 42 : pot%filename = ADJUSTL(TRIM(upf_filename))
76 :
77 : ! Ignore json potentials as SIRIUS will parse those on its own.
78 42 : l = LEN_TRIM(pot%filename)
79 42 : IF (l >= 5) THEN
80 42 : IF (pot%filename(l - 4:l) == '.json') THEN
81 0 : pot%zion = 0.0_dp
82 0 : RETURN
83 : END IF
84 : END IF
85 :
86 42 : CALL atom_read_upf_v2(pot, upf_filename, readall, readaug, readpaw)
87 :
88 : ! set up econf
89 210 : IF (SUM(pot%econf) == 0) THEN
90 42 : symbol = ADJUSTL(TRIM(pot%symbol))
91 42 : CALL get_ptable_info(symbol, number=ncore)
92 210 : pot%econf(0:3) = ptable(ncore)%e_conv(0:3)
93 42 : nel = NINT(ncore - pot%zion)
94 0 : SELECT CASE (nel)
95 : CASE DEFAULT
96 0 : CPABORT("Unknown Core State")
97 : CASE (0)
98 : ! no core electron
99 : CASE (2)
100 70 : pot%econf(0:3) = pot%econf(0:3) - ptable(2)%e_conv(0:3)
101 : CASE (10)
102 0 : pot%econf(0:3) = pot%econf(0:3) - ptable(10)%e_conv(0:3)
103 : CASE (12)
104 : ! [Ne] 3s2 core, with 3p semicore in the valence (e.g. GBRV Ga).
105 0 : pot%econf(0:3) = pot%econf(0:3) - ptable(10)%e_conv(0:3) - [2, 0, 0, 0]
106 : CASE (18)
107 0 : pot%econf(0:3) = pot%econf(0:3) - ptable(18)%e_conv(0:3)
108 : CASE (28)
109 30 : pot%econf(0:3) = pot%econf(0:3) - ptable(18)%e_conv(0:3)
110 6 : pot%econf(2) = pot%econf(2) - 10
111 : CASE (30)
112 : ! [Ar] 3d10 4s2 core, with 4p semicore in the valence (e.g. GBRV Pd).
113 0 : pot%econf(0:3) = pot%econf(0:3) - ptable(18)%e_conv(0:3) - [2, 0, 10, 0]
114 : CASE (36)
115 0 : pot%econf(0:3) = pot%econf(0:3) - ptable(36)%e_conv(0:3)
116 : CASE (46)
117 0 : pot%econf(0:3) = pot%econf(0:3) - ptable(36)%e_conv(0:3)
118 0 : pot%econf(2) = pot%econf(2) - 10
119 : CASE (54)
120 0 : pot%econf(0:3) = pot%econf(0:3) - ptable(54)%e_conv(0:3)
121 : CASE (60)
122 0 : pot%econf(0:3) = pot%econf(0:3) - ptable(36)%e_conv(0:3)
123 0 : pot%econf(2) = pot%econf(2) - 10
124 0 : pot%econf(3) = pot%econf(3) - 14
125 : CASE (62)
126 : ! [Kr] 4d10 4f14 5s2 core, with 5p semicore in the valence (e.g. Pt).
127 10 : pot%econf(0:3) = pot%econf(0:3) - [10, 18, 20, 14]
128 : CASE (68)
129 0 : pot%econf(0:3) = pot%econf(0:3) - ptable(54)%e_conv(0:3)
130 0 : pot%econf(3) = pot%econf(3) - 14
131 : CASE (78)
132 0 : pot%econf(0:3) = pot%econf(0:3) - ptable(54)%e_conv(0:3)
133 0 : pot%econf(2) = pot%econf(2) - 10
134 42 : pot%econf(3) = pot%econf(3) - 14
135 : END SELECT
136 : !
137 210 : CPASSERT(ALL(pot%econf >= 0))
138 : END IF
139 :
140 : ! name
141 42 : IF (pot%pname == "") THEN
142 42 : pot%pname = ADJUSTL(TRIM(pot%symbol))
143 : END IF
144 :
145 : END SUBROUTINE atom_read_upf
146 :
147 : ! **************************************************************************************************
148 : !> \brief ...
149 : !> \param pot ...
150 : !> \param upf_filename ...
151 : !> \param readall ...
152 : !> \param readaug Read scalar augmentation arrays.
153 : !> \param readpaw Read original PAW one-center data.
154 : ! **************************************************************************************************
155 42 : SUBROUTINE atom_read_upf_v2(pot, upf_filename, readall, readaug, readpaw)
156 :
157 : TYPE(atom_upfpot_type) :: pot
158 : CHARACTER(len=*), INTENT(IN) :: upf_filename
159 : LOGICAL, INTENT(IN) :: readall, readaug, readpaw
160 :
161 : CHARACTER(LEN=default_string_length) :: nametag
162 : INTEGER :: ib, ntag
163 : LOGICAL :: at_end
164 : TYPE(cp_parser_type) :: parser
165 :
166 42 : ntag = 0
167 42 : CALL parser_create(parser, upf_filename, apply_preprocessing=.FALSE.)
168 : DO
169 : at_end = .FALSE.
170 19036 : CALL parser_get_next_line(parser, 1, at_end)
171 19036 : IF (at_end) EXIT
172 19036 : CALL parser_get_object(parser, nametag, lower_to_upper=.TRUE.)
173 19036 : IF (nametag(1:1) /= "<") CYCLE
174 720 : IF (ntag == 0) THEN
175 : ! we are looking for UPF tag
176 42 : IF (nametag(2:4) == "UPF") THEN
177 42 : CALL parser_get_object(parser, nametag, lower_to_upper=.TRUE.)
178 : ! read UPF file version
179 42 : CALL parser_get_object(parser, nametag, lower_to_upper=.TRUE.)
180 42 : pot%version = TRIM(nametag)
181 42 : CPASSERT(nametag(1:5) == "2.0.1")
182 42 : CALL parser_get_object(parser, nametag, lower_to_upper=.TRUE.)
183 42 : CPASSERT(nametag(1:1) == ">")
184 : ntag = 1
185 : END IF
186 636 : ELSE IF (ntag == 1) THEN
187 : ! we are looking for 1st level tags
188 636 : IF (nametag(2:8) == "PP_INFO") THEN
189 28 : CPASSERT(nametag(9:9) == ">")
190 28 : CALL upf_info_section(parser, pot)
191 608 : ELSE IF (nametag(2:10) == "PP_HEADER") THEN
192 42 : IF (.NOT. (nametag(11:11) == ">")) THEN
193 42 : CALL upf_header_option(parser, pot)
194 : END IF
195 42 : IF (readaug .AND. pot%is_ultrasoft .AND. .NOT. pot%is_paw .AND. pot%has_wfc) THEN
196 2 : CPASSERT(.NOT. ALLOCATED(pot%partial_waves))
197 2 : ALLOCATE (pot%partial_waves)
198 : END IF
199 42 : IF (readpaw .AND. pot%is_paw) THEN
200 2 : IF (pot%has_so) THEN
201 0 : CPABORT("Native PAW import requires scalar-relativistic data")
202 : END IF
203 2 : CPASSERT(.NOT. ALLOCATED(pot%paw))
204 2 : ALLOCATE (pot%paw)
205 : END IF
206 566 : ELSE IF (nametag(2:8) == "PP_MESH") THEN
207 42 : IF (.NOT. (nametag(9:9) == ">")) THEN
208 36 : CALL upf_mesh_option(parser, pot)
209 : END IF
210 42 : CALL upf_mesh_section(parser, pot)
211 524 : ELSE IF (nametag(2:8) == "PP_NLCC") THEN
212 8 : IF (nametag(9:9) == ">") THEN
213 2 : CALL upf_nlcc_section(parser, pot, .FALSE.)
214 : ELSE
215 6 : CALL upf_nlcc_section(parser, pot, .TRUE.)
216 : END IF
217 516 : ELSE IF (nametag(2:10) == "PP_TAUMOD") THEN
218 2 : CPASSERT(pot%mesh_size > 0 .AND. .NOT. ALLOCATED(pot%tau_nlcc))
219 6 : ALLOCATE (pot%tau_nlcc(pot%mesh_size))
220 2 : CALL upf_real_array(parser, nametag, pot%tau_nlcc, convention=pot%tau_nlcc_convention)
221 514 : ELSE IF (nametag(2:11) == "PP_TAUATOM") THEN
222 2 : CPASSERT(pot%mesh_size > 0 .AND. .NOT. ALLOCATED(pot%tau_atom))
223 6 : ALLOCATE (pot%tau_atom(pot%mesh_size))
224 2 : CALL upf_real_array(parser, nametag, pot%tau_atom, convention=pot%tau_atom_convention)
225 512 : ELSE IF (nametag(2:9) == "PP_LOCAL") THEN
226 42 : IF (nametag(10:10) == ">") THEN
227 10 : CALL upf_local_section(parser, pot, .FALSE.)
228 : ELSE
229 32 : CALL upf_local_section(parser, pot, .TRUE.)
230 : END IF
231 470 : ELSE IF (nametag(2:12) == "PP_NONLOCAL") THEN
232 42 : CPASSERT(nametag(13:13) == ">")
233 76 : CALL upf_nonlocal_section(parser, pot, readaug .AND. (.NOT. pot%is_paw .OR. readpaw))
234 428 : ELSE IF (nametag(2:13) == "PP_SEMILOCAL") THEN
235 2 : CALL upf_semilocal_section(parser, pot)
236 426 : ELSE IF (nametag(2:9) == "PP_PSWFC") THEN
237 : ! skip section for now
238 386 : ELSE IF (nametag(2:12) == "PP_FULL_WFC") THEN
239 8 : IF (ALLOCATED(pot%partial_waves)) THEN
240 2 : CALL upf_full_wfc_section(parser, pot%partial_waves, nametag, pot%mesh_size, pot%number_of_proj)
241 : END IF
242 8 : IF (ALLOCATED(pot%paw)) THEN
243 2 : CALL upf_full_wfc_section(parser, pot%paw, nametag, pot%mesh_size, pot%number_of_proj)
244 : END IF
245 378 : ELSE IF (nametag(2:11) == "PP_RHOATOM") THEN
246 : ! skip section for now
247 350 : ELSE IF (nametag(2:7) == "PP_PAW") THEN
248 4 : IF (ALLOCATED(pot%paw)) CALL upf_paw_section(parser, pot)
249 346 : ELSE IF (nametag == "<PP_GIPAW" .OR. nametag == "<PP_GIPAW>") THEN
250 4 : IF (ALLOCATED(pot%paw)) CALL upf_gipaw_section(parser, pot, nametag)
251 342 : ELSE IF (nametag(2:6) == "/UPF>") THEN
252 : EXIT
253 : END IF
254 : END IF
255 : END DO
256 42 : CALL parser_release(parser)
257 :
258 42 : CPASSERT(ntag > 0)
259 :
260 : ! rescale projectors
261 42 : IF (ALLOCATED(pot%beta)) THEN
262 42 : CPASSERT(ALLOCATED(pot%r) .AND. ALLOCATED(pot%rab))
263 116 : DO ib = 1, pot%number_of_proj
264 116 : IF (pot%r(1) == 0.0_dp) THEN
265 39456 : pot%beta(2:, ib) = pot%beta(2:, ib)/pot%r(2:)
266 : ELSE
267 11548 : pot%beta(:, ib) = pot%beta(:, ib)/pot%r(:)
268 : END IF
269 : END DO
270 : END IF
271 :
272 : ! test for not supported options
273 42 : IF (readall) THEN
274 38 : IF (pot%is_ultrasoft .AND. .NOT. readaug) THEN
275 0 : CPABORT("UPF ultrasoft pseudopotential not implemented")
276 : END IF
277 38 : IF (pot%is_paw .AND. .NOT. readpaw) THEN
278 0 : CPABORT("UPF PAW potential not implemented")
279 : END IF
280 : END IF
281 42 : IF (readaug .AND. (pot%is_ultrasoft .OR. pot%is_paw) .AND. (.NOT. pot%is_paw .OR. readpaw)) THEN
282 8 : CPASSERT(ALLOCATED(pot%qij) .AND. ALLOCATED(pot%qijl))
283 : END IF
284 :
285 42 : IF (ALLOCATED(pot%paw)) THEN
286 2 : CPASSERT(ALLOCATED(pot%paw%ae_wfc) .AND. ALLOCATED(pot%paw%ps_wfc))
287 2 : CPASSERT(ALLOCATED(pot%paw%occupations) .AND. ALLOCATED(pot%paw%rho_core))
288 2 : CPASSERT(ALLOCATED(pot%paw%vlocal) .AND. ALLOCATED(pot%paw%multipoles))
289 4 : CPASSERT(ALL(pot%paw%angular_momenta == pot%lbeta))
290 16 : CPASSERT(ALL(ieee_is_finite(pot%qij)) .AND. ALL(ieee_is_finite(pot%qijl)))
291 : END IF
292 :
293 42 : IF (ALLOCATED(pot%partial_waves)) THEN
294 2 : CPASSERT(ALLOCATED(pot%partial_waves%ae_wfc))
295 2 : CPASSERT(ALLOCATED(pot%partial_waves%ps_wfc))
296 6 : CPASSERT(ALL(pot%partial_waves%angular_momenta == pot%lbeta))
297 : END IF
298 :
299 126 : END SUBROUTINE atom_read_upf_v2
300 :
301 : ! **************************************************************************************************
302 : !> \brief ...
303 : !> \param parser ...
304 : !> \param pot ...
305 : ! **************************************************************************************************
306 28 : SUBROUTINE upf_info_section(parser, pot)
307 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
308 : TYPE(atom_upfpot_type) :: pot
309 :
310 : CHARACTER(LEN=default_string_length) :: line, string
311 : INTEGER :: icount, iline
312 : LOGICAL :: at_end
313 :
314 28 : icount = 0
315 : DO
316 558 : CALL parser_get_next_line(parser, 1, at_end)
317 558 : CPASSERT(.NOT. at_end)
318 558 : iline = parser%buffer%present_line_number
319 558 : line = TRIM(parser%buffer%input_lines(iline))
320 558 : CALL parser_get_object(parser, string)
321 558 : IF (string(1:10) == "</PP_INFO>") EXIT
322 530 : icount = icount + 1
323 530 : IF (icount > pot%maxinfo) CYCLE
324 530 : pot%info(icount) = line
325 : END DO
326 28 : pot%maxinfo = icount
327 :
328 28 : END SUBROUTINE upf_info_section
329 :
330 : ! **************************************************************************************************
331 : !> \brief ...
332 : !> \param parser ...
333 : !> \param pot ...
334 : ! **************************************************************************************************
335 42 : SUBROUTINE upf_header_option(parser, pot)
336 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
337 : TYPE(atom_upfpot_type) :: pot
338 :
339 : CHARACTER(LEN=1) :: quote
340 : CHARACTER(LEN=default_string_length) :: string
341 : INTEGER :: value_start
342 : LOGICAL :: at_end
343 :
344 42 : quote = parser%quote_character
345 834 : DO
346 876 : IF (parser_test_next_token(parser) == "EOL") THEN
347 710 : CALL parser_get_next_line(parser, 1, at_end)
348 1586 : CPASSERT(.NOT. at_end)
349 : END IF
350 876 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
351 876 : IF (string == "/>") EXIT
352 : ! Legacy UPFs can enclose header values containing double quotes in single quotes.
353 834 : IF (parser%icol < LEN(parser%input_line)) THEN
354 834 : value_start = VERIFY(parser%input_line(parser%icol + 1:), " "//ACHAR(9)//TRIM(parser%separators))
355 834 : IF (value_start > 0) THEN
356 834 : value_start = value_start + parser%icol
357 834 : IF (parser%input_line(value_start:value_start) == "'") parser%quote_character = "'"
358 : END IF
359 : END IF
360 30 : SELECT CASE (string)
361 : CASE ("GENERATED")
362 30 : CALL parser_get_object(parser, pot%generated, allow_empty=.TRUE.)
363 : CASE ("AUTHOR")
364 28 : CALL parser_get_object(parser, pot%author, allow_empty=.TRUE.)
365 : CASE ("DATE")
366 28 : CALL parser_get_object(parser, pot%date, allow_empty=.TRUE.)
367 : CASE ("COMMENT")
368 28 : CALL parser_get_object(parser, pot%comment, allow_empty=.TRUE.)
369 : CASE ("ELEMENT")
370 42 : CALL parser_get_object(parser, pot%symbol)
371 42 : CPASSERT(2 <= LEN(pot%symbol))
372 : CASE ("PSEUDO_TYPE")
373 42 : CALL parser_get_object(parser, pot%pseudo_type)
374 : CASE ("RELATIVISTIC")
375 28 : CALL parser_get_object(parser, pot%relativistic)
376 : CASE ("IS_ULTRASOFT")
377 40 : CALL parser_get_object(parser, pot%is_ultrasoft)
378 : CASE ("IS_PAW")
379 38 : CALL parser_get_object(parser, pot%is_paw)
380 : CASE ("IS_COULOMB")
381 28 : CALL parser_get_object(parser, pot%is_coulomb)
382 : CASE ("HAS_SO")
383 28 : CALL parser_get_object(parser, pot%has_so)
384 : CASE ("HAS_WFC")
385 34 : CALL parser_get_object(parser, pot%has_wfc)
386 : CASE ("HAS_GIPAW")
387 28 : CALL parser_get_object(parser, pot%has_gipaw)
388 : CASE ("PAW_AS_GIPAW")
389 22 : CALL parser_get_object(parser, pot%paw_as_gipaw)
390 : CASE ("CORE_CORRECTION")
391 30 : CALL parser_get_object(parser, pot%core_correction)
392 : CASE ("WITH_METAGGA_INFO")
393 2 : CALL parser_get_object(parser, pot%with_metagga_info)
394 : CASE ("FUNCTIONAL")
395 28 : CALL parser_get_object(parser, pot%functional)
396 : CASE ("Z_VALENCE")
397 42 : CALL parser_get_object(parser, pot%zion)
398 : CASE ("TOTAL_PSENERGY")
399 28 : CALL parser_get_object(parser, pot%total_psenergy)
400 : CASE ("WFC_CUTOFF")
401 22 : CALL parser_get_object(parser, pot%wfc_cutoff)
402 : CASE ("RHO_CUTOFF")
403 28 : CALL parser_get_object(parser, pot%rho_cutoff)
404 : CASE ("L_MAX")
405 42 : CALL parser_get_object(parser, pot%l_max)
406 : CASE ("L_MAX_RHO")
407 22 : CALL parser_get_object(parser, pot%l_max_rho)
408 : CASE ("L_LOCAL")
409 28 : CALL parser_get_object(parser, pot%l_local)
410 : CASE ("MESH_SIZE")
411 42 : CALL parser_get_object(parser, pot%mesh_size)
412 : CASE ("NUMBER_OF_WFC")
413 34 : CALL parser_get_object(parser, pot%number_of_wfc)
414 : CASE ("NUMBER_OF_PROJ")
415 42 : CALL parser_get_object(parser, pot%number_of_proj)
416 : CASE DEFAULT
417 834 : CPABORT("Unknown UPF header attribute "//TRIM(string))
418 : END SELECT
419 834 : parser%quote_character = quote
420 : END DO
421 :
422 42 : END SUBROUTINE upf_header_option
423 :
424 : ! **************************************************************************************************
425 : !> \brief ...
426 : !> \param parser ...
427 : !> \param pot ...
428 : ! **************************************************************************************************
429 36 : SUBROUTINE upf_mesh_option(parser, pot)
430 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
431 : TYPE(atom_upfpot_type) :: pot
432 :
433 : CHARACTER(LEN=default_string_length) :: string
434 : INTEGER :: jj
435 : LOGICAL :: at_end
436 :
437 : DO
438 160 : IF (parser_test_next_token(parser) == "EOL") THEN
439 22 : CALL parser_get_next_line(parser, 1, at_end)
440 182 : CPASSERT(.NOT. at_end)
441 : END IF
442 160 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
443 160 : IF (string == ">") EXIT
444 36 : SELECT CASE (string)
445 : CASE ("DX")
446 22 : CALL parser_get_object(parser, pot%dx)
447 : CASE ("XMIN")
448 22 : CALL parser_get_object(parser, pot%xmin)
449 : CASE ("RMAX")
450 22 : CALL parser_get_object(parser, pot%rmax)
451 : CASE ("MESH")
452 36 : CALL parser_get_object(parser, jj)
453 36 : CPASSERT(pot%mesh_size == jj)
454 : CASE ("ZMESH")
455 22 : CALL parser_get_object(parser, pot%zmesh)
456 : CASE DEFAULT
457 124 : CPABORT("Unknown UPF PP_MESH option <"//TRIM(string)//"> found")
458 : END SELECT
459 :
460 : END DO
461 :
462 36 : END SUBROUTINE upf_mesh_option
463 :
464 : ! **************************************************************************************************
465 : !> \brief ...
466 : !> \param parser ...
467 : !> \param pot ...
468 : ! **************************************************************************************************
469 42 : SUBROUTINE upf_mesh_section(parser, pot)
470 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
471 : TYPE(atom_upfpot_type) :: pot
472 :
473 : CHARACTER(LEN=default_string_length) :: line, string, string2
474 : INTEGER :: icount, m, mc, ms
475 : LOGICAL :: at_end
476 :
477 : DO
478 210 : CALL parser_get_next_line(parser, 1, at_end)
479 210 : CPASSERT(.NOT. at_end)
480 210 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
481 42 : SELECT CASE (string)
482 : CASE ("<PP_R", "<PP_R>")
483 42 : m = pot%mesh_size
484 42 : ms = pot%mesh_size
485 : mc = 1
486 42 : IF (string /= "<PP_R>") THEN
487 : ! options
488 : DO
489 118 : IF (parser_test_next_token(parser) == "EOL") THEN
490 0 : CALL parser_get_next_line(parser, 1, at_end)
491 118 : CPASSERT(.NOT. at_end)
492 : END IF
493 118 : CALL parser_get_object(parser, string2, lower_to_upper=.TRUE.)
494 118 : IF (string2 == ">") EXIT
495 30 : SELECT CASE (string2)
496 : CASE ("TYPE")
497 30 : CALL parser_get_object(parser, line, lower_to_upper=.TRUE.)
498 30 : CPASSERT(line == "REAL")
499 : CASE ("SIZE")
500 30 : CALL parser_get_object(parser, ms)
501 30 : CPASSERT(ms <= m)
502 : CASE ("COLUMNS")
503 28 : CALL parser_get_object(parser, mc)
504 : CASE DEFAULT
505 88 : CPABORT("Unknown UPF PP_R option <"//TRIM(string2)//"> found")
506 : END SELECT
507 : END DO
508 : END IF
509 126 : ALLOCATE (pot%r(m))
510 27402 : pot%r = 0.0_dp
511 : icount = 1
512 33438 : DO WHILE (icount <= ms)
513 33438 : IF (parser_test_next_token(parser) == "EOL") THEN
514 6036 : CALL parser_get_next_line(parser, 1, at_end)
515 6036 : CPASSERT(.NOT. at_end)
516 : ELSE
517 27360 : CALL parser_get_object(parser, pot%r(icount))
518 60756 : icount = icount + 1
519 : END IF
520 : END DO
521 : CASE ("<PP_RAB", "<PP_RAB>")
522 42 : m = pot%mesh_size
523 42 : ms = pot%mesh_size
524 : mc = 1
525 42 : IF (string /= "<PP_RAB>") THEN
526 : ! options
527 : DO
528 118 : IF (parser_test_next_token(parser) == "EOL") THEN
529 0 : CALL parser_get_next_line(parser, 1, at_end)
530 118 : CPASSERT(.NOT. at_end)
531 : END IF
532 118 : CALL parser_get_object(parser, string2, lower_to_upper=.TRUE.)
533 118 : IF (string2 == ">") EXIT
534 30 : SELECT CASE (string2)
535 : CASE ("TYPE")
536 30 : CALL parser_get_object(parser, line, lower_to_upper=.TRUE.)
537 30 : CPASSERT(line == "REAL")
538 : CASE ("SIZE")
539 30 : CALL parser_get_object(parser, ms)
540 30 : CPASSERT(ms <= m)
541 : CASE ("COLUMNS")
542 28 : CALL parser_get_object(parser, mc)
543 : CASE DEFAULT
544 88 : CPABORT("Unknown UPF PP_RAB option <"//TRIM(string2)//"> found")
545 : END SELECT
546 : END DO
547 : END IF
548 126 : ALLOCATE (pot%rab(m))
549 27402 : pot%rab = 0.0_dp
550 : icount = 1
551 33438 : DO WHILE (icount <= ms)
552 33438 : IF (parser_test_next_token(parser) == "EOL") THEN
553 6036 : CALL parser_get_next_line(parser, 1, at_end)
554 6036 : CPASSERT(.NOT. at_end)
555 : ELSE
556 27360 : CALL parser_get_object(parser, pot%rab(icount))
557 60756 : icount = icount + 1
558 : END IF
559 : END DO
560 : CASE ("</PP_MESH>")
561 210 : EXIT
562 : CASE DEFAULT
563 : !
564 : END SELECT
565 : END DO
566 :
567 42 : END SUBROUTINE upf_mesh_section
568 :
569 : ! **************************************************************************************************
570 : !> \brief ...
571 : !> \param parser ...
572 : !> \param pot ...
573 : !> \param options ...
574 : ! **************************************************************************************************
575 8 : SUBROUTINE upf_nlcc_section(parser, pot, options)
576 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
577 : TYPE(atom_upfpot_type) :: pot
578 : LOGICAL, INTENT(IN) :: options
579 :
580 : CHARACTER(LEN=default_string_length) :: line, string
581 : INTEGER :: icount, m, mc, ms
582 : LOGICAL :: at_end
583 :
584 8 : m = pot%mesh_size
585 8 : ms = m
586 : mc = 1
587 8 : IF (options) THEN
588 : DO
589 24 : IF (parser_test_next_token(parser) == "EOL") THEN
590 0 : CALL parser_get_next_line(parser, 1, at_end)
591 24 : CPASSERT(.NOT. at_end)
592 : END IF
593 24 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
594 24 : IF (string == ">") EXIT
595 6 : SELECT CASE (string)
596 : CASE ("TYPE")
597 6 : CALL parser_get_object(parser, line, lower_to_upper=.TRUE.)
598 6 : CPASSERT(line == "REAL")
599 : CASE ("SIZE")
600 6 : CALL parser_get_object(parser, ms)
601 6 : CPASSERT(ms <= m)
602 : CASE ("COLUMNS")
603 6 : CALL parser_get_object(parser, mc)
604 : CASE DEFAULT
605 18 : CPABORT("Unknown UPF PP_NLCC option <"//TRIM(string)//"> found")
606 : END SELECT
607 : END DO
608 : END IF
609 :
610 24 : ALLOCATE (pot%rho_nlcc(m))
611 6590 : pot%rho_nlcc = 0.0_dp
612 : icount = 1
613 8236 : DO WHILE (icount <= ms)
614 8236 : IF (parser_test_next_token(parser) == "EOL") THEN
615 1646 : CALL parser_get_next_line(parser, 1, at_end)
616 1646 : CPASSERT(.NOT. at_end)
617 : ELSE
618 6582 : CALL parser_get_object(parser, pot%rho_nlcc(icount))
619 14810 : icount = icount + 1
620 : END IF
621 : END DO
622 :
623 8 : CALL parser_get_next_line(parser, 1, at_end)
624 8 : CPASSERT(.NOT. at_end)
625 8 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
626 8 : CPASSERT(string == "</PP_NLCC>")
627 :
628 8 : END SUBROUTINE upf_nlcc_section
629 :
630 : ! **************************************************************************************************
631 : !> \brief ...
632 : !> \param parser ...
633 : !> \param pot ...
634 : !> \param options ...
635 : ! **************************************************************************************************
636 42 : SUBROUTINE upf_local_section(parser, pot, options)
637 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
638 : TYPE(atom_upfpot_type) :: pot
639 : LOGICAL, INTENT(IN) :: options
640 :
641 : CHARACTER(LEN=default_string_length) :: line, string
642 : INTEGER :: icount, m, mc, ms
643 : LOGICAL :: at_end
644 :
645 42 : m = pot%mesh_size
646 42 : ms = m
647 : mc = 1
648 42 : IF (options) THEN
649 : DO
650 124 : IF (parser_test_next_token(parser) == "EOL") THEN
651 0 : CALL parser_get_next_line(parser, 1, at_end)
652 124 : CPASSERT(.NOT. at_end)
653 : END IF
654 124 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
655 124 : IF (string == ">") EXIT
656 32 : SELECT CASE (string)
657 : CASE ("TYPE")
658 32 : CALL parser_get_object(parser, line, lower_to_upper=.TRUE.)
659 32 : CPASSERT(line == "REAL")
660 : CASE ("SIZE")
661 32 : CALL parser_get_object(parser, ms)
662 32 : CPASSERT(ms <= m)
663 : CASE ("COLUMNS")
664 28 : CALL parser_get_object(parser, mc)
665 : CASE DEFAULT
666 92 : CPABORT("Unknown UPF PP_LOCAL option <"//TRIM(string)//"> found")
667 : END SELECT
668 : END DO
669 : END IF
670 :
671 126 : ALLOCATE (pot%vlocal(m))
672 27402 : pot%vlocal = 0.0_dp
673 : icount = 1
674 34260 : DO WHILE (icount <= ms)
675 34260 : IF (parser_test_next_token(parser) == "EOL") THEN
676 6858 : CALL parser_get_next_line(parser, 1, at_end)
677 6858 : CPASSERT(.NOT. at_end)
678 : ELSE
679 27360 : CALL parser_get_object(parser, pot%vlocal(icount))
680 61578 : icount = icount + 1
681 : END IF
682 : END DO
683 :
684 : ! Ry -> Hartree
685 27402 : pot%vlocal = 0.5_dp*pot%vlocal
686 :
687 42 : CALL parser_get_next_line(parser, 1, at_end)
688 42 : CPASSERT(.NOT. at_end)
689 42 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
690 42 : CPASSERT(string == "</PP_LOCAL>")
691 :
692 42 : END SUBROUTINE upf_local_section
693 :
694 : ! **************************************************************************************************
695 : !> \brief ...
696 : !> \param parser ...
697 : !> \param pot ...
698 : !> \param readaug Import angular-resolved USPP augmentation data.
699 : ! **************************************************************************************************
700 42 : SUBROUTINE upf_nonlocal_section(parser, pot, readaug)
701 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
702 : TYPE(atom_upfpot_type) :: pot
703 : LOGICAL, INTENT(IN) :: readaug
704 :
705 : CHARACTER(LEN=default_string_length) :: line, string
706 : INTEGER :: i1, i2, ibeta, icount, la, m, mc, ms, &
707 : nbeta
708 : LOGICAL :: at_end
709 :
710 42 : m = pot%mesh_size
711 42 : nbeta = pot%number_of_proj
712 330 : ALLOCATE (pot%dion(nbeta, nbeta), pot%beta(m, nbeta), pot%lbeta(nbeta))
713 402 : pot%dion = 0.0_dp
714 51082 : pot%beta = 0.0_dp
715 116 : pot%lbeta = -1
716 :
717 : ibeta = 0
718 : DO
719 338 : CALL parser_get_next_line(parser, 1, at_end)
720 338 : CPASSERT(.NOT. at_end)
721 338 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
722 380 : IF (string(1:8) == "<PP_BETA") THEN
723 74 : ms = m
724 74 : ibeta = ibeta + 1
725 74 : i1 = ibeta
726 74 : la = 0
727 74 : CPASSERT(ibeta <= nbeta)
728 : DO
729 532 : IF (parser_test_next_token(parser) == "EOL") THEN
730 266 : CALL parser_get_next_line(parser, 1, at_end)
731 798 : CPASSERT(.NOT. at_end)
732 : END IF
733 532 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
734 532 : IF (string == ">") EXIT
735 74 : SELECT CASE (string)
736 : CASE ("TYPE")
737 58 : CALL parser_get_object(parser, line, lower_to_upper=.TRUE.)
738 58 : CPASSERT(line == "REAL")
739 : CASE ("SIZE")
740 74 : CALL parser_get_object(parser, ms)
741 74 : CPASSERT(ms <= m)
742 : CASE ("COLUMNS")
743 50 : CALL parser_get_object(parser, mc)
744 : CASE ("INDEX")
745 74 : CALL parser_get_object(parser, i1)
746 74 : CPASSERT(i1 <= nbeta)
747 : CASE ("ANGULAR_MOMENTUM")
748 88 : CALL parser_get_object(parser, la)
749 : CASE ("LABEL")
750 14 : CALL parser_get_object(parser, line, allow_empty=.TRUE.)
751 : ! not used currently
752 : CASE ("CUTOFF_RADIUS_INDEX")
753 50 : CALL parser_get_object(parser, line)
754 : ! not used currently
755 : CASE ("CUTOFF_RADIUS")
756 50 : CALL parser_get_object(parser, line)
757 : ! not used currently
758 : CASE ("ULTRASOFT_CUTOFF_RADIUS")
759 14 : CALL parser_get_object(parser, line)
760 : ! not used currently
761 : CASE ("NORM_CONSERVING_RADIUS")
762 0 : CALL parser_get_object(parser, line)
763 : ! Generator metadata; the operator uses the complete tabulated beta.
764 : CASE DEFAULT
765 458 : CPABORT("Unknown UPF PP_BETA option <"//TRIM(string)//"> found")
766 : END SELECT
767 : END DO
768 74 : pot%lbeta(i1) = la
769 74 : icount = 1
770 63796 : DO WHILE (icount <= ms)
771 63796 : IF (parser_test_next_token(parser) == "EOL") THEN
772 12756 : CALL parser_get_next_line(parser, 1, at_end)
773 12756 : CPASSERT(.NOT. at_end)
774 : ELSE
775 50966 : CALL parser_get_object(parser, pot%beta(icount, i1))
776 114688 : icount = icount + 1
777 : END IF
778 : END DO
779 264 : ELSE IF (string(1:7) == "<PP_DIJ") THEN
780 42 : ms = nbeta*nbeta
781 42 : IF (string /= "<PP_DIJ>") THEN
782 : DO
783 118 : IF (parser_test_next_token(parser) == "EOL") THEN
784 0 : CALL parser_get_next_line(parser, 1, at_end)
785 118 : CPASSERT(.NOT. at_end)
786 : END IF
787 118 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
788 118 : IF (string == ">") EXIT
789 30 : SELECT CASE (string)
790 : CASE ("TYPE")
791 30 : CALL parser_get_object(parser, line, lower_to_upper=.TRUE.)
792 30 : CPASSERT(line == "REAL")
793 : CASE ("SIZE")
794 30 : CALL parser_get_object(parser, ms)
795 30 : CPASSERT(ms == nbeta*nbeta)
796 : CASE ("COLUMNS")
797 28 : CALL parser_get_object(parser, mc)
798 : CASE DEFAULT
799 88 : CPABORT("Unknown UPF PP_DIJ option <"//TRIM(string)//"> found")
800 : END SELECT
801 : END DO
802 : END IF
803 : icount = 1
804 410 : DO WHILE (icount <= ms)
805 410 : IF (parser_test_next_token(parser) == "EOL") THEN
806 82 : CALL parser_get_next_line(parser, 1, at_end)
807 82 : CPASSERT(.NOT. at_end)
808 : ELSE
809 286 : i1 = (icount - 1)/nbeta + 1
810 286 : i2 = MOD(icount - 1, nbeta) + 1
811 286 : CALL parser_get_object(parser, pot%dion(i1, i2))
812 654 : icount = icount + 1
813 : END IF
814 : END DO
815 222 : ELSE IF (string(1:16) == "<PP_AUGMENTATION") THEN
816 12 : IF (readaug) CALL upf_augmentation_section(parser, pot)
817 210 : ELSE IF (string(1:14) == "</PP_NONLOCAL>") THEN
818 : EXIT
819 : END IF
820 : END DO
821 :
822 : ! Convert the complete beta*D*beta operator from Ry to Hartree without
823 : ! changing the tabulated projector amplitude. This also preserves the
824 : ! projector convention needed by augmentation charges and PAW duality.
825 : ! Some NC converters put energy units into beta and inverse energy into D;
826 : ! preserving their numerical beta still gives the correct operator here.
827 : ! The radial prefactor in PP_BETA is removed after reading the whole file.
828 402 : pot%dion = 0.5_dp*pot%dion
829 :
830 42 : END SUBROUTINE upf_nonlocal_section
831 :
832 : ! **************************************************************************************************
833 : !> \brief Read angular-momentum-resolved USPP augmentation in its tabulated convention.
834 : !> PP_Q is retained independently of the radial quadrature of PP_QIJL. Those
835 : !> quantities need not agree exactly in a finite-precision dataset. No energy
836 : !> conversion or projector normalization is applied to either augmentation array.
837 : !> \param parser UPF token stream, positioned after the PP_AUGMENTATION tag name.
838 : !> \param pot UPF data with the mesh and all beta angular momenta already read.
839 : ! **************************************************************************************************
840 8 : SUBROUTINE upf_augmentation_section(parser, pot)
841 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
842 : TYPE(atom_upfpot_type), INTENT(INOUT) :: pot
843 :
844 : CHARACTER(LEN=default_string_length) :: string, tag, value
845 : INTEGER :: i, iraug, j, k, l, lmax, m, nb, nc, nqf, &
846 : nqlc, pair, size_data, tag_i, tag_j, &
847 : tag_l
848 : LOGICAL :: at_end, is_null, q_with_l, read_q, &
849 : self_closing
850 8 : LOGICAL, ALLOCATABLE :: present_channel(:, :)
851 8 : REAL(dp), ALLOCATABLE :: multipoles(:)
852 :
853 8 : CPASSERT(.NOT. ALLOCATED(pot%qij) .AND. .NOT. ALLOCATED(pot%qijl))
854 22 : CPASSERT(ALL(pot%lbeta >= 0))
855 8 : nb = pot%number_of_proj
856 8 : m = pot%mesh_size
857 22 : lmax = 2*MAXVAL(pot%lbeta)
858 8 : q_with_l = .FALSE.
859 8 : nqf = -1
860 8 : nqlc = lmax + 1
861 8 : iraug = -1
862 : DO
863 36 : IF (parser_test_next_token(parser) == "EOL") THEN
864 0 : CALL upf_next_line(parser, at_end)
865 36 : CPASSERT(.NOT. at_end)
866 : END IF
867 36 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
868 36 : IF (string == ">") EXIT
869 8 : SELECT CASE (string)
870 : CASE ("Q_WITH_L")
871 8 : CALL parser_get_object(parser, q_with_l)
872 : CASE ("NQF")
873 16 : CALL parser_get_object(parser, nqf)
874 : CASE ("NQLC")
875 8 : CALL parser_get_object(parser, nqlc)
876 : CASE ("SHAPE")
877 0 : CPASSERT(ALLOCATED(pot%paw))
878 0 : CALL parser_get_object(parser, pot%paw%augmentation_shape)
879 : CASE ("CUTOFF_R")
880 0 : CPASSERT(ALLOCATED(pot%paw))
881 0 : CALL parser_get_object(parser, pot%paw%cutoff_radius)
882 : CASE ("CUTOFF_R_INDEX")
883 2 : CPASSERT(ALLOCATED(pot%paw))
884 2 : CALL parser_get_object(parser, pot%paw%cutoff_index)
885 : CASE ("IRAUG")
886 0 : CPASSERT(ALLOCATED(pot%paw))
887 2 : CALL parser_get_object(parser, iraug)
888 : CASE ("L_MAX_AUG", "LMAX_AUG")
889 2 : CPASSERT(ALLOCATED(pot%paw))
890 2 : CALL parser_get_object(parser, pot%paw%lmax_aug)
891 : CASE ("AUGMENTATION_EPSILON")
892 0 : CPASSERT(ALLOCATED(pot%paw))
893 0 : CALL parser_get_object(parser, pot%paw%augmentation_epsilon)
894 : CASE DEFAULT
895 28 : CPABORT("Unknown UPF PP_AUGMENTATION option <"//TRIM(string)//"> found")
896 : END SELECT
897 : END DO
898 8 : IF (.NOT. q_with_l .OR. nqf /= 0) THEN
899 0 : CPABORT("Native augmentation import requires angular-resolved PP_QIJL with nqf=0")
900 : END IF
901 8 : IF (nqlc == 0) nqlc = lmax + 1
902 8 : CPASSERT(nqlc >= lmax + 1)
903 8 : IF (ALLOCATED(pot%paw)) THEN
904 2 : IF (pot%paw%cutoff_index < 0) pot%paw%cutoff_index = iraug
905 2 : IF (iraug >= 0) THEN
906 0 : CPASSERT(iraug == pot%paw%cutoff_index)
907 : END IF
908 2 : CPASSERT(pot%paw%cutoff_index >= 1 .AND. pot%paw%cutoff_index <= m)
909 2 : CPASSERT(pot%paw%lmax_aug >= 0 .AND. pot%paw%lmax_aug <= lmax)
910 2 : CPASSERT(ieee_is_finite(pot%paw%augmentation_epsilon))
911 2 : CPASSERT(pot%paw%augmentation_epsilon >= 0.0_dp)
912 : END IF
913 8 : nc = nb*(nb + 1)/2
914 88 : ALLOCATE (pot%qij(nb, nb), pot%qijl(m, nc, 0:lmax), present_channel(nc, 0:lmax))
915 48 : pot%qij = 0.0_dp
916 252 : pot%qijl = 0.0_dp
917 8 : present_channel = .FALSE.
918 8 : read_q = .FALSE.
919 76 : DO
920 76 : CALL upf_next_line(parser, at_end)
921 76 : CPASSERT(.NOT. at_end)
922 76 : CALL parser_get_object(parser, tag, lower_to_upper=.TRUE.)
923 76 : IF (tag == "</PP_AUGMENTATION>") EXIT
924 68 : IF (tag(1:2) == "</") CYCLE
925 36 : IF (tag == "<PP_MULTIPOLES" .OR. tag == "<PP_MULTIPOLES>") THEN
926 2 : CPASSERT(ALLOCATED(pot%paw))
927 2 : CPASSERT(.NOT. ALLOCATED(pot%paw%multipoles))
928 14 : ALLOCATE (multipoles(nb*nb*(lmax + 1)), pot%paw%multipoles(nb, nb, 0:lmax))
929 2 : CALL upf_real_array(parser, tag, multipoles)
930 14 : pot%paw%multipoles(:, :, :) = RESHAPE(multipoles, [nb, nb, lmax + 1])
931 2 : DEALLOCATE (multipoles)
932 2 : CYCLE
933 : END IF
934 34 : IF (.NOT. (tag(1:8) == "<PP_QIJL" .OR. tag == "<PP_Q" .OR. tag == "<PP_Q>")) THEN
935 0 : CPABORT("Unexpected UPF augmentation tag "//TRIM(tag)//" in "//TRIM(pot%filename))
936 : END IF
937 34 : i = -1
938 34 : j = -1
939 34 : l = -1
940 34 : pair = -1
941 34 : size_data = m
942 34 : IF (tag == "<PP_Q" .OR. tag == "<PP_Q>") size_data = nb*nb
943 34 : is_null = .FALSE.
944 34 : self_closing = .FALSE.
945 34 : IF (tag /= "<PP_Q>") THEN
946 : DO
947 140 : IF (parser_test_next_token(parser) == "EOL") THEN
948 4 : CALL upf_next_line(parser, at_end)
949 144 : CPASSERT(.NOT. at_end)
950 : END IF
951 140 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
952 140 : IF (string == ">") EXIT
953 116 : IF (string == "/>") THEN
954 : self_closing = .TRUE.
955 : EXIT
956 : END IF
957 24 : SELECT CASE (string)
958 : CASE ("TYPE")
959 2 : CALL parser_get_object(parser, value, lower_to_upper=.TRUE.)
960 2 : CPASSERT(value == "REAL")
961 : CASE ("SIZE")
962 4 : CALL parser_get_object(parser, size_data)
963 : CASE ("COLUMNS")
964 0 : CALL parser_get_object(parser, value)
965 : CASE ("FIRST_INDEX")
966 52 : CALL parser_get_object(parser, i)
967 : CASE ("SECOND_INDEX")
968 52 : CALL parser_get_object(parser, j)
969 : CASE ("COMPOSITE_INDEX")
970 52 : CALL parser_get_object(parser, pair)
971 : CASE ("ANGULAR_MOMENTUM")
972 30 : CALL parser_get_object(parser, l)
973 : CASE ("IS_NULL")
974 4 : CALL parser_get_object(parser, is_null)
975 : CASE DEFAULT
976 114 : CPABORT("Unknown UPF augmentation array option <"//TRIM(string)//"> found")
977 : END SELECT
978 : END DO
979 : END IF
980 42 : IF (tag(1:8) == "<PP_QIJL") THEN
981 26 : CPASSERT(i >= 1 .AND. i <= j .AND. j <= nb)
982 26 : CPASSERT(pair == j*(j - 1)/2 + i)
983 26 : CPASSERT(l >= ABS(pot%lbeta(i) - pot%lbeta(j)))
984 26 : CPASSERT(l <= pot%lbeta(i) + pot%lbeta(j))
985 26 : CPASSERT(MODULO(pot%lbeta(i) + pot%lbeta(j) - l, 2) == 0)
986 : ! Cross-check the tag suffix as well as the explicit attributes.
987 26 : string = tag(10:)
988 156 : DO k = 1, LEN_TRIM(string)
989 156 : IF (string(k:k) == ".") string(k:k) = " "
990 : END DO
991 26 : READ (string, *) tag_i, tag_j, tag_l
992 26 : CPASSERT(tag_i == i .AND. tag_j == j .AND. tag_l == l)
993 26 : CPASSERT(.NOT. present_channel(pair, l))
994 26 : present_channel(pair, l) = .TRUE.
995 26 : IF (is_null) THEN
996 2 : CPASSERT(self_closing .AND. size_data == 0)
997 : CYCLE
998 : END IF
999 24 : CPASSERT(.NOT. self_closing .AND. size_data == m)
1000 96 : DO k = 1, m
1001 96 : DO WHILE (parser_test_next_token(parser) == "EOL")
1002 24 : CALL upf_next_line(parser, at_end)
1003 24 : CPASSERT(.NOT. at_end)
1004 : END DO
1005 96 : CALL parser_get_object(parser, pot%qijl(k, pair, l))
1006 : END DO
1007 : ELSE
1008 8 : CPASSERT(.NOT. read_q .AND. .NOT. self_closing .AND. .NOT. is_null)
1009 8 : CPASSERT(size_data == nb*nb)
1010 22 : DO j = 1, nb
1011 48 : DO i = 1, nb
1012 34 : DO WHILE (parser_test_next_token(parser) == "EOL")
1013 8 : CALL upf_next_line(parser, at_end)
1014 8 : CPASSERT(.NOT. at_end)
1015 : END DO
1016 40 : CALL parser_get_object(parser, pot%qij(i, j))
1017 : END DO
1018 : END DO
1019 : read_q = .TRUE.
1020 : END IF
1021 : END DO
1022 8 : CPASSERT(read_q)
1023 8 : IF (ALLOCATED(pot%paw)) THEN
1024 2 : CPASSERT(ALLOCATED(pot%paw%multipoles))
1025 : END IF
1026 22 : DO j = 1, nb
1027 42 : DO i = 1, j
1028 20 : pair = j*(j - 1)/2 + i
1029 60 : DO l = ABS(pot%lbeta(i) - pot%lbeta(j)), pot%lbeta(i) + pot%lbeta(j), 2
1030 : ! PAW writers may omit channels below the stored multipole threshold.
1031 26 : IF (.NOT. present_channel(pair, l) .AND. ALLOCATED(pot%paw)) THEN
1032 0 : IF (ABS(pot%paw%multipoles(i, j, l)) < pot%paw%augmentation_epsilon) CYCLE
1033 : END IF
1034 46 : CPASSERT(present_channel(pair, l))
1035 : END DO
1036 : END DO
1037 : END DO
1038 8 : END SUBROUTINE upf_augmentation_section
1039 :
1040 : ! **************************************************************************************************
1041 : !> \brief ...
1042 : !> \brief Import original PAW occupations, AE core density and local potential in Hartree.
1043 : !> \param parser ...
1044 : !> \param pot ...
1045 : ! **************************************************************************************************
1046 2 : SUBROUTINE upf_paw_section(parser, pot)
1047 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
1048 : TYPE(atom_upfpot_type), INTENT(INOUT) :: pot
1049 :
1050 : CHARACTER(LEN=default_string_length) :: string, tag
1051 : LOGICAL :: at_end
1052 :
1053 : DO
1054 6 : IF (parser_test_next_token(parser) == "EOL") THEN
1055 0 : CALL upf_next_line(parser, at_end)
1056 6 : CPASSERT(.NOT. at_end)
1057 : END IF
1058 6 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
1059 6 : IF (string == ">") EXIT
1060 2 : SELECT CASE (string)
1061 : CASE ("PAW_DATA_FORMAT")
1062 2 : CPASSERT(pot%paw%data_format == -1)
1063 2 : CALL parser_get_object(parser, pot%paw%data_format)
1064 : CASE ("CORE_ENERGY")
1065 2 : CPASSERT(.NOT. pot%paw%has_core_energy)
1066 2 : CALL parser_get_object(parser, pot%paw%core_energy)
1067 2 : CPASSERT(ieee_is_finite(pot%paw%core_energy))
1068 2 : pot%paw%core_energy = 0.5_dp*pot%paw%core_energy
1069 2 : pot%paw%has_core_energy = .TRUE.
1070 : CASE DEFAULT
1071 4 : CPABORT("Unknown UPF PP_PAW option <"//TRIM(string)//"> found")
1072 : END SELECT
1073 : END DO
1074 2 : IF (pot%paw%data_format /= 2) CPABORT("Native PAW import requires paw_data_format=2")
1075 8 : DO
1076 8 : CALL upf_next_line(parser, at_end)
1077 8 : CPASSERT(.NOT. at_end)
1078 8 : CALL parser_get_object(parser, tag, lower_to_upper=.TRUE.)
1079 : SELECT CASE (tag)
1080 : CASE ("</PP_PAW>")
1081 2 : EXIT
1082 : CASE ("<PP_OCCUPATIONS", "<PP_OCCUPATIONS>")
1083 2 : CPASSERT(.NOT. ALLOCATED(pot%paw%occupations))
1084 6 : ALLOCATE (pot%paw%occupations(pot%number_of_proj))
1085 2 : CALL upf_real_array(parser, tag, pot%paw%occupations)
1086 : CASE ("<PP_AE_NLCC", "<PP_AE_NLCC>")
1087 2 : CPASSERT(.NOT. ALLOCATED(pot%paw%rho_core))
1088 6 : ALLOCATE (pot%paw%rho_core(pot%mesh_size))
1089 2 : CALL upf_real_array(parser, tag, pot%paw%rho_core)
1090 : CASE ("<PP_AE_VLOC", "<PP_AE_VLOC>")
1091 2 : CPASSERT(.NOT. ALLOCATED(pot%paw%vlocal))
1092 6 : ALLOCATE (pot%paw%vlocal(pot%mesh_size))
1093 2 : CALL upf_real_array(parser, tag, pot%paw%vlocal)
1094 8 : pot%paw%vlocal = 0.5_dp*pot%paw%vlocal
1095 : CASE DEFAULT
1096 8 : CPABORT("Unknown UPF PAW data tag "//TRIM(tag))
1097 : END SELECT
1098 : END DO
1099 2 : END SUBROUTINE upf_paw_section
1100 :
1101 : ! **************************************************************************************************
1102 : !> \brief Retain optional GIPAW orbitals without assuming occupations or core assignments.
1103 : !> \param parser ...
1104 : !> \param pot ...
1105 : !> \param opening_tag ...
1106 : ! **************************************************************************************************
1107 2 : SUBROUTINE upf_gipaw_section(parser, pot, opening_tag)
1108 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
1109 : TYPE(atom_upfpot_type), INTENT(INOUT) :: pot
1110 : CHARACTER(LEN=*), INTENT(IN) :: opening_tag
1111 :
1112 : CHARACTER(LEN=default_string_length) :: string, tag
1113 : INTEGER :: data_format
1114 : LOGICAL :: at_end
1115 :
1116 2 : data_format = -1
1117 2 : IF (opening_tag /= "<PP_GIPAW>") THEN
1118 2 : DO
1119 4 : IF (parser_test_next_token(parser) == "EOL") THEN
1120 0 : CALL upf_next_line(parser, at_end)
1121 4 : CPASSERT(.NOT. at_end)
1122 : END IF
1123 4 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
1124 4 : IF (string == ">") EXIT
1125 2 : CPASSERT(string == "GIPAW_DATA_FORMAT" .AND. data_format == -1)
1126 2 : CALL parser_get_object(parser, data_format)
1127 4 : CPASSERT(data_format >= 0)
1128 : END DO
1129 : END IF
1130 4 : DO
1131 4 : CALL upf_next_line(parser, at_end)
1132 4 : CPASSERT(.NOT. at_end)
1133 4 : CALL parser_get_object(parser, tag, lower_to_upper=.TRUE.)
1134 4 : IF (tag == "</PP_GIPAW>") EXIT
1135 4 : IF (tag == "<PP_GIPAW_CORE_ORBITALS" .OR. tag == "<PP_GIPAW_CORE_ORBITALS>") THEN
1136 2 : CPASSERT(.NOT. ALLOCATED(pot%paw%gipaw_core_orbitals))
1137 2 : ALLOCATE (pot%paw%gipaw_core_orbitals)
1138 2 : pot%paw%gipaw_core_orbitals%data_format = data_format
1139 2 : CALL upf_gipaw_core_section(parser, pot%paw%gipaw_core_orbitals, tag, pot%mesh_size)
1140 : END IF
1141 : ! Other GIPAW reconstruction sections do not describe this orbital table.
1142 : END DO
1143 2 : END SUBROUTINE upf_gipaw_section
1144 :
1145 : ! **************************************************************************************************
1146 : !> \brief Read indexed signed GIPAW radial orbitals, including an explicitly empty table.
1147 : !> \param parser ...
1148 : !> \param orbitals ...
1149 : !> \param opening_tag ...
1150 : !> \param mesh_size ...
1151 : ! **************************************************************************************************
1152 2 : SUBROUTINE upf_gipaw_core_section(parser, orbitals, opening_tag, mesh_size)
1153 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
1154 : TYPE(upf_gipaw_orbitals_type), INTENT(INOUT) :: orbitals
1155 : CHARACTER(LEN=*), INTENT(IN) :: opening_tag
1156 : INTEGER, INTENT(IN) :: mesh_size
1157 :
1158 : CHARACTER(LEN=*), PARAMETER :: prefix = "<PP_GIPAW_CORE_ORBITAL."
1159 :
1160 : CHARACTER(LEN=default_string_length) :: string, tag
1161 : INTEGER :: count, i, index_value, ios, l, last, n
1162 : LOGICAL :: at_end, self_closing
1163 2 : LOGICAL, ALLOCATABLE :: found(:)
1164 2 : REAL(dp), ALLOCATABLE :: values(:)
1165 :
1166 2 : count = -1
1167 2 : self_closing = .FALSE.
1168 2 : CPASSERT(mesh_size > 0)
1169 2 : CPASSERT(opening_tag /= "<PP_GIPAW_CORE_ORBITALS>")
1170 2 : DO
1171 4 : IF (parser_test_next_token(parser) == "EOL") THEN
1172 0 : CALL upf_next_line(parser, at_end)
1173 4 : CPASSERT(.NOT. at_end)
1174 : END IF
1175 4 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
1176 4 : IF (string == ">") EXIT
1177 2 : IF (string == "/>") THEN
1178 : self_closing = .TRUE.
1179 : EXIT
1180 : END IF
1181 2 : CPASSERT(string == "NUMBER_OF_CORE_ORBITALS" .AND. count == -1)
1182 2 : CALL parser_get_object(parser, count)
1183 4 : CPASSERT(count >= 0)
1184 : END DO
1185 2 : CPASSERT(count >= 0)
1186 0 : ALLOCATE (orbitals%wfc(mesh_size, count), orbitals%indices(count), &
1187 16 : orbitals%principal_quantum_numbers(count), orbitals%angular_momenta(count))
1188 8 : ALLOCATE (found(count), values(mesh_size))
1189 2 : found = .FALSE.
1190 2 : IF (self_closing) THEN
1191 0 : CPASSERT(count == 0)
1192 0 : RETURN
1193 : END IF
1194 6 : DO
1195 4 : CALL upf_next_line(parser, at_end)
1196 4 : CPASSERT(.NOT. at_end)
1197 4 : CALL parser_get_object(parser, tag, lower_to_upper=.TRUE.)
1198 4 : IF (tag == "</PP_GIPAW_CORE_ORBITALS>") EXIT
1199 2 : CPASSERT(tag(1:LEN(prefix)) == prefix)
1200 2 : last = LEN_TRIM(tag)
1201 2 : IF (tag(last:last) == ">") last = last - 1
1202 2 : string = tag(LEN(prefix) + 1:last)
1203 2 : READ (string, *, IOSTAT=ios) i
1204 2 : CPASSERT(ios == 0)
1205 2 : CPASSERT(i >= 1 .AND. i <= count)
1206 2 : CPASSERT(.NOT. found(i))
1207 2 : CALL upf_real_array(parser, tag, values, index_value, l, principal_quantum_number=n)
1208 2 : CPASSERT(index_value == i)
1209 2 : CPASSERT(n >= 1 .AND. l >= 0 .AND. n > l)
1210 8 : orbitals%wfc(:, i) = values
1211 2 : orbitals%indices(i) = index_value
1212 2 : orbitals%principal_quantum_numbers(i) = n
1213 2 : orbitals%angular_momenta(i) = l
1214 2 : found(i) = .TRUE.
1215 : END DO
1216 4 : CPASSERT(ALL(found))
1217 2 : END SUBROUTINE upf_gipaw_core_section
1218 :
1219 : ! **************************************************************************************************
1220 : !> \brief Read semilocal radial potentials in Hartree.
1221 : !> \param parser ...
1222 : !> \param pot ...
1223 : ! **************************************************************************************************
1224 2 : SUBROUTINE upf_semilocal_section(parser, pot)
1225 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
1226 : TYPE(atom_upfpot_type) :: pot
1227 :
1228 : CHARACTER(LEN=default_string_length) :: line, string
1229 : INTEGER :: i1, ib, icount, la, lmax, m, mc, ms
1230 : LOGICAL :: at_end
1231 :
1232 2 : m = pot%mesh_size
1233 2 : lmax = pot%l_max
1234 8 : ALLOCATE (pot%vsemi(m, lmax + 1))
1235 3698 : pot%vsemi = 0.0_dp
1236 :
1237 : ib = 0
1238 : DO
1239 14 : CALL parser_get_next_line(parser, 1, at_end)
1240 14 : CPASSERT(.NOT. at_end)
1241 14 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
1242 16 : IF (string(1:7) == "<PP_VNL") THEN
1243 6 : ms = m
1244 6 : ib = ib + 1
1245 6 : i1 = ib
1246 6 : la = 0
1247 6 : CPASSERT(ib <= lmax + 1)
1248 : DO
1249 30 : IF (parser_test_next_token(parser) == "EOL") THEN
1250 0 : CALL parser_get_next_line(parser, 1, at_end)
1251 30 : CPASSERT(.NOT. at_end)
1252 : END IF
1253 30 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
1254 30 : IF (string == ">") EXIT
1255 6 : SELECT CASE (string)
1256 : CASE ("TYPE")
1257 6 : CALL parser_get_object(parser, line, lower_to_upper=.TRUE.)
1258 6 : CPASSERT(line == "REAL")
1259 : CASE ("SIZE")
1260 6 : CALL parser_get_object(parser, ms)
1261 6 : CPASSERT(ms <= m)
1262 : CASE ("COLUMNS")
1263 6 : CALL parser_get_object(parser, mc)
1264 : CASE ("L")
1265 6 : CALL parser_get_object(parser, la)
1266 : CASE DEFAULT
1267 24 : CPABORT("Unknown UPF PP_VNL option <"//TRIM(string)//"> found")
1268 : END SELECT
1269 : END DO
1270 6 : i1 = la + 1
1271 6 : icount = 1
1272 3468 : DO WHILE (icount <= ms)
1273 3468 : IF (parser_test_next_token(parser) == "EOL") THEN
1274 696 : CALL parser_get_next_line(parser, 1, at_end)
1275 696 : CPASSERT(.NOT. at_end)
1276 : ELSE
1277 2766 : CALL parser_get_object(parser, pot%vsemi(icount, i1))
1278 6228 : icount = icount + 1
1279 : END IF
1280 : END DO
1281 8 : ELSE IF (string(1:15) == "</PP_SEMILOCAL>") THEN
1282 : EXIT
1283 : ELSE
1284 : !
1285 : END IF
1286 : END DO
1287 : ! Ry -> Hartree
1288 3698 : pot%vsemi = 0.5_dp*pot%vsemi
1289 :
1290 2 : END SUBROUTINE upf_semilocal_section
1291 :
1292 : ! **************************************************************************************************
1293 : !> \brief Skip complete XML comment lines before original full-wave data.
1294 : !> \param parser ...
1295 : !> \param at_end ...
1296 : ! **************************************************************************************************
1297 196 : SUBROUTINE upf_next_line(parser, at_end)
1298 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
1299 : LOGICAL, INTENT(OUT) :: at_end
1300 :
1301 196 : CHARACTER(LEN=:), ALLOCATABLE :: line
1302 : LOGICAL :: in_comment
1303 :
1304 196 : in_comment = .FALSE.
1305 0 : DO
1306 196 : CALL parser_get_next_line(parser, 1, at_end)
1307 196 : IF (at_end) THEN
1308 0 : CPASSERT(.NOT. in_comment)
1309 196 : RETURN
1310 : END IF
1311 196 : line = ADJUSTL(parser%buffer%input_lines(parser%buffer%present_line_number))
1312 196 : IF (.NOT. in_comment .AND. INDEX(line, '<!--') /= 1) RETURN
1313 0 : in_comment = INDEX(line, '-->') == 0
1314 : END DO
1315 392 : END SUBROUTINE upf_next_line
1316 :
1317 : ! **************************************************************************************************
1318 : !> \brief Read an original radial array without normalization or unit conversion.
1319 : !> \param parser ...
1320 : !> \param tag ...
1321 : !> \param values ...
1322 : !> \param index_value ...
1323 : !> \param angular_momentum ...
1324 : !> \param convention Optional explicit normalization metadata.
1325 : !> \param principal_quantum_number Original integral principal quantum number, if supplied.
1326 : ! **************************************************************************************************
1327 78 : SUBROUTINE upf_real_array(parser, tag, values, index_value, angular_momentum, convention, principal_quantum_number)
1328 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
1329 : CHARACTER(LEN=*), INTENT(IN) :: tag
1330 : REAL(dp), INTENT(OUT) :: values(:)
1331 : INTEGER, INTENT(OUT), OPTIONAL :: index_value, angular_momentum
1332 : CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: convention
1333 : INTEGER, INTENT(OUT), OPTIONAL :: principal_quantum_number
1334 :
1335 : CHARACTER(LEN=default_string_length) :: name, string, value
1336 : INTEGER :: i, last, n
1337 : LOGICAL :: at_end
1338 : REAL(dp) :: quantum_number
1339 :
1340 26 : n = SIZE(values)
1341 26 : last = LEN_TRIM(tag)
1342 26 : IF (PRESENT(index_value)) index_value = -1
1343 26 : IF (PRESENT(angular_momentum)) angular_momentum = -1
1344 26 : IF (PRESENT(principal_quantum_number)) principal_quantum_number = -1
1345 26 : IF (PRESENT(convention)) convention = ''
1346 26 : IF (tag(last:last) == ">") THEN
1347 8 : name = tag(2:last - 1)
1348 : ELSE
1349 18 : name = tag(2:last)
1350 : DO
1351 54 : IF (parser_test_next_token(parser) == "EOL") THEN
1352 0 : CALL upf_next_line(parser, at_end)
1353 54 : CPASSERT(.NOT. at_end)
1354 : END IF
1355 54 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
1356 54 : IF (string == ">") EXIT
1357 18 : SELECT CASE (string)
1358 : CASE ("TYPE")
1359 6 : CALL parser_get_object(parser, value, lower_to_upper=.TRUE.)
1360 6 : CPASSERT(value == "REAL")
1361 : CASE ("SIZE")
1362 6 : CALL parser_get_object(parser, n)
1363 6 : CPASSERT(n == SIZE(values))
1364 : CASE ("COLUMNS")
1365 0 : CALL parser_get_object(parser, value)
1366 : CASE ("CONVENTION")
1367 2 : CPASSERT(PRESENT(convention))
1368 2 : CALL parser_get_object(parser, convention, lower_to_upper=.TRUE.)
1369 : CASE ("INDEX")
1370 6 : CPASSERT(PRESENT(index_value))
1371 6 : CALL parser_get_object(parser, index_value)
1372 : CASE ("L")
1373 14 : CPASSERT(PRESENT(angular_momentum))
1374 : ! QE also writes these integer-valued attributes as REAL literals.
1375 14 : CALL parser_get_object(parser, quantum_number)
1376 14 : CPASSERT(ieee_is_finite(quantum_number))
1377 14 : CPASSERT(quantum_number >= 0.0_dp)
1378 14 : CPASSERT(quantum_number < REAL(HUGE(0), dp))
1379 14 : CPASSERT(quantum_number == REAL(NINT(quantum_number), dp))
1380 14 : angular_momentum = NINT(quantum_number)
1381 : CASE ("N")
1382 2 : CPASSERT(PRESENT(principal_quantum_number))
1383 2 : CALL parser_get_object(parser, quantum_number)
1384 2 : CPASSERT(ieee_is_finite(quantum_number))
1385 2 : CPASSERT(quantum_number >= 1.0_dp)
1386 2 : CPASSERT(quantum_number < REAL(HUGE(0), dp))
1387 2 : CPASSERT(quantum_number == REAL(NINT(quantum_number), dp))
1388 2 : principal_quantum_number = NINT(quantum_number)
1389 : CASE ("LABEL")
1390 0 : CALL parser_get_object(parser, value, allow_empty=.TRUE.)
1391 : CASE DEFAULT
1392 58 : CPABORT("Unknown UPF "//TRIM(name)//" option <"//TRIM(string)//"> found")
1393 : END SELECT
1394 : END DO
1395 : END IF
1396 96 : DO i = 1, n
1397 96 : DO WHILE (parser_test_next_token(parser) == "EOL")
1398 26 : CALL upf_next_line(parser, at_end)
1399 26 : CPASSERT(.NOT. at_end)
1400 : END DO
1401 96 : CALL parser_get_object(parser, values(i))
1402 : END DO
1403 96 : CPASSERT(ALL(ieee_is_finite(values)))
1404 26 : CALL upf_next_line(parser, at_end)
1405 26 : CPASSERT(.NOT. at_end)
1406 26 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
1407 26 : CPASSERT(string == "</"//TRIM(name)//">")
1408 26 : END SUBROUTINE upf_real_array
1409 :
1410 : ! **************************************************************************************************
1411 : !> \brief Import projector-indexed AE and PS partial waves, retaining r*phi(r).
1412 : !> \param parser ...
1413 : !> \param waves ...
1414 : !> \param opening_tag ...
1415 : !> \param mesh_size ...
1416 : !> \param number_of_proj ...
1417 : ! **************************************************************************************************
1418 4 : SUBROUTINE upf_full_wfc_section(parser, waves, opening_tag, mesh_size, number_of_proj)
1419 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
1420 :
1421 : CLASS(upf_partial_waves_type), INTENT(INOUT) :: waves
1422 : CHARACTER(LEN=*), INTENT(IN) :: opening_tag
1423 : INTEGER, INTENT(IN) :: mesh_size, number_of_proj
1424 :
1425 : CHARACTER(LEN=default_string_length) :: string, suffix, tag
1426 : INTEGER :: i, index_value, ios, l, last, m, n, nb, &
1427 : wave_type
1428 : LOGICAL :: at_end
1429 4 : LOGICAL, ALLOCATABLE :: found(:, :)
1430 4 : REAL(dp), ALLOCATABLE :: values(:)
1431 :
1432 4 : nb = number_of_proj
1433 4 : m = mesh_size
1434 4 : CPASSERT(nb > 0 .AND. m > 0)
1435 4 : CPASSERT(.NOT. ALLOCATED(waves%ae_wfc) .AND. .NOT. ALLOCATED(waves%ps_wfc))
1436 4 : CPASSERT(.NOT. ALLOCATED(waves%angular_momenta))
1437 4 : IF (opening_tag /= "<PP_FULL_WFC>") THEN
1438 4 : DO
1439 8 : IF (parser_test_next_token(parser) == "EOL") THEN
1440 0 : CALL upf_next_line(parser, at_end)
1441 8 : CPASSERT(.NOT. at_end)
1442 : END IF
1443 8 : CALL parser_get_object(parser, string, lower_to_upper=.TRUE.)
1444 8 : IF (string == ">") EXIT
1445 4 : CPASSERT(string == "NUMBER_OF_WFC")
1446 4 : CALL parser_get_object(parser, n)
1447 8 : CPASSERT(n == nb)
1448 : END DO
1449 : END IF
1450 32 : ALLOCATE (waves%ae_wfc(m, nb), waves%ps_wfc(m, nb), waves%angular_momenta(nb))
1451 20 : ALLOCATE (found(nb, 2), values(m))
1452 4 : found = .FALSE.
1453 10 : waves%angular_momenta = -1
1454 28 : DO
1455 16 : CALL upf_next_line(parser, at_end)
1456 16 : CPASSERT(.NOT. at_end)
1457 16 : CALL parser_get_object(parser, tag, lower_to_upper=.TRUE.)
1458 16 : IF (tag == "</PP_FULL_WFC>") EXIT
1459 : SELECT CASE (tag(1:10))
1460 : CASE ("<PP_AEWFC.")
1461 6 : wave_type = 1
1462 : CASE ("<PP_PSWFC.")
1463 6 : wave_type = 2
1464 : CASE DEFAULT
1465 12 : CPABORT("Unknown UPF full partial-wave tag "//TRIM(tag))
1466 : END SELECT
1467 12 : last = LEN_TRIM(tag)
1468 12 : IF (tag(last:last) == ">") last = last - 1
1469 12 : suffix = tag(11:last)
1470 12 : READ (suffix, *, IOSTAT=ios) i
1471 12 : CPASSERT(ios == 0)
1472 12 : CPASSERT(i >= 1 .AND. i <= nb)
1473 12 : CPASSERT(.NOT. found(i, wave_type))
1474 12 : CALL upf_real_array(parser, tag, values, index_value, l)
1475 12 : IF (index_value /= -1) THEN
1476 4 : CPASSERT(index_value == i)
1477 : END IF
1478 12 : CPASSERT(l >= 0)
1479 12 : IF (waves%angular_momenta(i) >= 0) THEN
1480 6 : CPASSERT(l == waves%angular_momenta(i))
1481 : END IF
1482 12 : waves%angular_momenta(i) = l
1483 12 : IF (wave_type == 1) THEN
1484 24 : waves%ae_wfc(:, i) = values
1485 : ELSE
1486 24 : waves%ps_wfc(:, i) = values
1487 : END IF
1488 12 : found(i, wave_type) = .TRUE.
1489 : END DO
1490 24 : CPASSERT(ALL(found))
1491 4 : END SUBROUTINE upf_full_wfc_section
1492 :
1493 : ! **************************************************************************************************
1494 : !> \brief ...
1495 : !> \param upfpot ...
1496 : ! **************************************************************************************************
1497 11972 : PURE SUBROUTINE atom_release_upf(upfpot)
1498 :
1499 : TYPE(atom_upfpot_type), INTENT(INOUT) :: upfpot
1500 :
1501 : ! Intrinsic assignment releases all allocatable components, including NLCC,
1502 : ! and clears metadata before this temporary is reused for another KIND.
1503 11972 : CALL upf_release(upfpot)
1504 :
1505 11972 : END SUBROUTINE atom_release_upf
1506 : ! **************************************************************************************************
1507 :
1508 : END MODULE atom_upf
|