(git:3d5d2e5)
Loading...
Searching...
No Matches
atom_upf_unittest.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
17 USE atom_types, ONLY: &
20 release_atom_potential, sgp_pseudo, upf_pseudo
21 USE atom_upf, ONLY: atom_read_upf,&
23 atom_upfpot_type
24 USE atom_utils, ONLY: atom_core_density,&
26 USE cp_files, ONLY: close_file,&
36 USE ieee_arithmetic, ONLY: ieee_is_finite
49 USE kinds, ONLY: default_path_length,&
50 dp
51 USE libcp2k, ONLY: cp2k_finalize,&
53 USE mathconstants, ONLY: fourpi,&
54 pi
55 USE orbital_pointers, ONLY: co,&
57 nco,&
58 nso
66
67 IMPLICIT NONE
68 LOGICAL :: source_root_argument
69
70 CHARACTER(LEN=default_path_length) :: filename
71 INTEGER :: i, io_unit
72 REAL(kind=dp) :: error(6)
73 TYPE(atom_upfpot_type) :: pot
74 TYPE(atom_sgp_potential_type) :: sgp
75
76 CALL cp2k_init()
78 CALL check_core_derivatives()
79 CALL check_projector_addition_theorem()
80 CALL check_atomic_potential()
81 CALL check_upf_units()
82 CALL check_nlcc_fit()
83 CALL check_basis_origin()
84 CALL check_basis_derivatives()
85 CALL check_radial_grid_endpoints()
86 CALL check_contracted_basis_reader()
87 CALL check_basis_optimization_export()
89 CALL check_uspp_partial_waves()
90 CALL check_paw_import()
91
92 ! The same temporary is reused for successive KIND sections in Quickstep.
93 ALLOCATE (pot%rho_nlcc(3))
94 pot%rho_nlcc = 1.0_dp
95 pot%core_correction = .true.
96 pot%econf = [2, 4, 0, 0]
97 pot%pname = "previous kind"
98 CALL atom_release_upf(pot)
99 IF (ALLOCATED(pot%rho_nlcc)) error stop "UPF release leaked the core density"
100 IF (pot%core_correction) error stop "UPF release retained core-correction metadata"
101 IF (any(pot%econf /= 0)) error stop "UPF release retained the previous electron configuration"
102 IF (pot%pname /= "") error stop "UPF release retained the previous potential name"
103 CALL atom_release_upf(pot)
104
105 ALLOCATE (sgp%a_nlcc(2), sgp%c_nlcc(2))
106 sgp%has_nlcc = .true.
107 sgp%n_nlcc = 2
108 sgp%is_nonlocal(2) = .true.
109 CALL atom_sgp_release(sgp)
110 IF (ASSOCIATED(sgp%a_nlcc) .OR. ASSOCIATED(sgp%c_nlcc)) error stop "SGP release leaked NLCC arrays"
111 IF (sgp%has_nlcc .OR. sgp%n_nlcc /= 0) error stop "SGP release retained NLCC metadata"
112 IF (any(sgp%is_nonlocal)) error stop "SGP release retained nonlocal channels"
113 CALL atom_sgp_release(sgp)
114
115 ! Optional external UPF files exercise the real reader and Gaussian transformation.
116 ! This also permits auditing a complete SSSP library without bundling it in CP2K.
117 DO i = 1, command_argument_count()
118 CALL get_command_argument(i, filename)
119 ! do_regtest.py passes the CP2K source root before any optional UPF audit files.
120 IF (i == 1) THEN
121 INQUIRE (file=trim(filename)//"/tests/UNIT_TESTS", exist=source_root_argument)
122 IF (source_root_argument) cycle
123 END IF
124 CALL atom_read_upf(pot, trim(filename))
125 IF (abs(sum(pot%econf) - pot%zion) > 1.e-10_dp) error stop "UPF valence count mismatch"
126 IF (.NOT. all(ieee_is_finite(pot%vlocal))) error stop "Non-finite UPF local potential"
127 IF (any(pot%r(2:) <= pot%r(:SIZE(pot%r) - 1))) error stop "UPF mesh is not increasing"
128 IF (any(pot%rab <= 0.0_dp)) error stop "Non-positive UPF mesh weights"
129 IF (ALLOCATED(pot%dion)) THEN
130 IF (.NOT. all(ieee_is_finite(pot%dion))) error stop "Non-finite UPF projector coefficients"
131 IF (.NOT. all(ieee_is_finite(pot%beta))) error stop "Non-finite UPF projectors"
132 IF (maxval(abs(pot%dion - transpose(pot%dion))) > 1.e-10_dp) error stop "Non-Hermitian UPF D matrix"
133 END IF
134 CALL sgp_construction(sgp, upf_pot=pot, error=error)
135 IF (.NOT. all(ieee_is_finite(error))) error stop "Non-finite UPF transformation errors"
136 IF (pot%core_correction) THEN
137 IF (.NOT. ASSOCIATED(sgp%a_nlcc)) error stop "Missing transformed UPF core density"
138 IF (.NOT. all(ieee_is_finite(sgp%c_nlcc))) error stop "Non-finite transformed UPF core density"
139 END IF
140 IF (io_unit > 0) WRITE (io_unit, '(A,1X,A,1X,6ES16.7)') "UPF transformation:", trim(filename), error
141 CALL atom_sgp_release(sgp)
142 CALL atom_release_upf(pot)
143 END DO
144
145 CALL cp2k_finalize()
146
147CONTAINS
148
149! **************************************************************************************************
150!> \brief ...
151! **************************************************************************************************
152 SUBROUTINE check_uspp_import()
153 CHARACTER(LEN=*), PARAMETER :: fixture = "uspp-augmentation-test.upf"
154
155 CHARACTER(LEN=256) :: reason
156 INTEGER :: unit
157 LOGICAL :: available
158 REAL(dp), ALLOCATABLE :: kinetic(:)
159 TYPE(atom_upfpot_type) :: pot
160 TYPE(cp_logger_type), POINTER :: logger
161
162 logger => cp_get_default_logger()
163 IF (logger%para_env%is_source()) THEN
164 OPEN (newunit=unit, file=fixture, status='REPLACE', action='WRITE')
165 WRITE (unit, '(A)') &
166 '<UPF version="2.0.1">', &
167 "<PP_HEADER generated='Generated using ""atomic""' element=""Pt"" pseudo_type=""USPP""", &
168 " is_ultrasoft='true' z_valence='16' mesh_size=""3"" number_of_proj=""2"" l_max=""1""", &
169 ' core_correction="true" with_metagga_info="true" />', &
170 '<PP_MESH mesh="3">', &
171 '<PP_R>', &
172 '0.5 1.0 1.5', &
173 '</PP_R>', &
174 '<PP_RAB>', &
175 '0.5 0.5 0.5', &
176 '</PP_RAB>', &
177 '</PP_MESH>', &
178 '<PP_NLCC>', '1 0.5 0.1', '</PP_NLCC>', &
179 '<PP_TAUMOD type="real" size="3" convention="hartree_per_volume">', &
180 '0.2 0.7 0.05', '</PP_TAUMOD>', &
181 '<PP_TAUATOM type="real" size="3">', '3 2 1', '</PP_TAUATOM>', &
182 '<PP_LOCAL type="real" size="3">', &
183 '6 4 2', &
184 '</PP_LOCAL>', &
185 '<PP_NONLOCAL>', &
186 '<PP_BETA.1 type="real" size="3" index="1" angular_momentum="0">', &
187 '1 4 9', &
188 '</PP_BETA.1>', &
189 '<PP_BETA.2 type="real" size="3" index="2" angular_momentum="1">', &
190 '2 -1 3', &
191 '</PP_BETA.2>', &
192 '<PP_DIJ>', &
193 '2 0 0 8', &
194 '</PP_DIJ>', &
195 '<PP_AUGMENTATION q_with_l="T" nqf="0" nqlc="3">', &
196 '<PP_Q>', &
197 '2 0 0 3', &
198 '</PP_Q>', &
199 '<PP_QIJL.2.2.0 first_index="2" second_index="2" composite_index="3" angular_momentum="0">', &
200 '-3 4 5', &
201 '</PP_QIJL.2.2.0>', &
202 '<PP_QIJL.1.1.0 type="real" size="3" first_index="1" second_index="1"', &
203 ' composite_index="1" angular_momentum="0" is_null="false">', &
204 '1 2 3', &
205 '</PP_QIJL.1.1.0>', &
206 '<PP_QIJL.1.2.1 first_index="1" second_index="2" composite_index="2" angular_momentum="1">', &
207 '4 -5 6', &
208 '</PP_QIJL.1.2.1>', &
209 '<PP_QIJL.2.2.2 first_index="2" second_index="2" composite_index="3"', &
210 ' angular_momentum="2" is_null="T" size="0"/>', &
211 '</PP_AUGMENTATION>', &
212 '</PP_NONLOCAL>', &
213 '</UPF>'
214 CLOSE (unit)
215 END IF
216 CALL logger%para_env%sync()
217 CALL atom_read_upf(pot, fixture, read_augmentation=.true.)
218 IF (pot%generated /= 'Generated using "atomic"') error stop 'Quoted UPF header value was changed'
219 IF (any(pot%econf(0:3) /= [1, 6, 9, 0])) error stop 'Wrong 62-electron core subtraction'
220 IF (any(shape(pot%qijl) /= [3, 3, 3]) .OR. lbound(pot%qijl, 3) /= 0) error stop 'Wrong augmentation shape'
221 IF (maxval(abs(pot%qij - reshape([2._dp, 0._dp, 0._dp, 3._dp], [2, 2]))) > 1.e-14_dp) THEN
222 error stop 'PP_Q normalization changed'
223 END IF
224 IF (maxval(abs(pot%qijl(:, 1, 0) - [1._dp, 2._dp, 3._dp])) > 1.e-14_dp) error stop 'Wrong s-s augmentation'
225 IF (maxval(abs(pot%qijl(:, 2, 1) - [4._dp, -5._dp, 6._dp])) > 1.e-14_dp) error stop 'Wrong s-p augmentation'
226 IF (maxval(abs(pot%qijl(:, 3, 0) - [-3._dp, 4._dp, 5._dp])) > 1.e-14_dp) error stop 'Wrong p-p augmentation'
227 IF (any(pot%qijl(:, :, 2) /= 0._dp)) error stop 'Null augmentation was not zero initialized'
228 IF (maxval(abs(pot%beta(:, 2) - [4._dp, -1._dp, 2._dp])) > 1.e-14_dp) error stop 'USPP beta normalization changed'
229 IF (abs(pot%dion(2, 2) - 4._dp) > 1.e-14_dp) error stop 'USPP D is not in Hartree'
230 IF (.NOT. pot%with_metagga_info) error stop 'UPF meta-GGA header flag was not retained'
231 IF (any(pot%tau_atom /= [3._dp, 2._dp, 1._dp]) .OR. pot%tau_atom_convention /= '') THEN
232 error stop 'Raw UPF atomic tau was converted or assigned an unknown convention'
233 END IF
234 CALL upf_nlcc_kinetic(pot, kinetic, available, reason)
235 IF (.NOT. available .OR. any(kinetic /= [0.2_dp, 0.7_dp, 0.05_dp])) THEN
236 error stop 'Explicit canonical UPF core tau was not preserved'
237 END IF
238 pot%tau_nlcc_convention = ''
239 CALL upf_nlcc_kinetic(pot, kinetic, available, reason)
240 IF (available) error stop 'Unlabelled core tau was accepted as canonical'
241 DEALLOCATE (pot%tau_nlcc)
242 CALL upf_nlcc_kinetic(pot, kinetic, available, reason)
243 IF (available) error stop 'NLCC charge was used to infer missing core tau'
244 pot%rho_nlcc = 0.0_dp
245 CALL upf_nlcc_kinetic(pot, kinetic, available, reason)
246 IF (.NOT. available .OR. any(kinetic /= 0.0_dp)) error stop 'Absent core tau was not exact zero'
247 ALLOCATE (pot%tau_nlcc(3), source=1.0_dp)
248 CALL upf_nlcc_kinetic(pot, kinetic, available, reason)
249 IF (available) error stop 'Nonzero core tau without NLCC charge was accepted'
250 CALL atom_release_upf(pot)
251 IF (ALLOCATED(pot%qij) .OR. ALLOCATED(pot%qijl)) error stop 'Augmentation arrays were not released'
252 IF (ALLOCATED(pot%tau_nlcc) .OR. ALLOCATED(pot%tau_atom)) error stop 'UPF kinetic arrays were not released'
253 IF (pot%with_metagga_info .OR. pot%tau_nlcc_convention /= '' .OR. pot%tau_atom_convention /= '') THEN
254 error stop 'UPF kinetic metadata was not reset'
255 END IF
256 CALL logger%para_env%sync()
257 IF (logger%para_env%is_source()) THEN
258 OPEN (newunit=unit, file=fixture, status='OLD')
259 CLOSE (unit, status='DELETE')
260 END IF
261
262 END SUBROUTINE check_uspp_import
263
264! **************************************************************************************************
265!> \brief ...
266! **************************************************************************************************
267 SUBROUTINE check_uspp_partial_waves()
268 CHARACTER(LEN=*), PARAMETER :: fixture = 'uspp-partial-waves-test.upf'
269
270 CHARACTER(LEN=5) :: has_wfc
271 INTEGER :: unit, variant
272 TYPE(atom_upfpot_type) :: potential
273 TYPE(cp_logger_type), POINTER :: logger
274
275 logger => cp_get_default_logger()
276 DO variant = 1, 2
277 has_wfc = 'false'
278 IF (variant == 1) has_wfc = 'true'
279 IF (logger%para_env%is_source()) THEN
280 OPEN (newunit=unit, file=fixture, status='REPLACE', action='WRITE')
281 WRITE (unit, '(A)') &
282 '<UPF version="2.0.1">', &
283 '<PP_HEADER element="H" pseudo_type="US" is_ultrasoft="true" is_paw="false"', &
284 ' has_wfc="'//trim(has_wfc)//'" z_valence="1" mesh_size="3"', &
285 ' number_of_proj="2" number_of_wfc="1" l_max="1"/>', &
286 '<PP_MESH mesh="3">', &
287 '<PP_R>', '0.5 1 1.5', '</PP_R>', &
288 '<PP_RAB>', '0.5 0.5 0.5', '</PP_RAB>', '</PP_MESH>', &
289 '<PP_LOCAL>', '6 4 2', '</PP_LOCAL>', &
290 '<PP_NONLOCAL>', &
291 '<PP_BETA.1 index="1" angular_momentum="0" size="3">', '1 4 9', '</PP_BETA.1>', &
292 '<PP_BETA.2 index="2" angular_momentum="1" size="3">', '2 -1 3', '</PP_BETA.2>', &
293 '<PP_DIJ>', '2 0 0 8', '</PP_DIJ>', &
294 '<PP_AUGMENTATION q_with_l="T" nqf="0" nqlc="3">', &
295 '<PP_Q>', '2 0 0 3', '</PP_Q>', &
296 '<PP_QIJL.1.1.0 first_index="1" second_index="1" composite_index="1" angular_momentum="0">', &
297 '1 2 3', '</PP_QIJL.1.1.0>', &
298 '<PP_QIJL.1.2.1 first_index="1" second_index="2" composite_index="2" angular_momentum="1">', &
299 '4 -5 6', '</PP_QIJL.1.2.1>', &
300 '<PP_QIJL.2.2.0 first_index="2" second_index="2" composite_index="3" angular_momentum="0">', &
301 '-3 4 5', '</PP_QIJL.2.2.0>', &
302 '<PP_QIJL.2.2.2 first_index="2" second_index="2" composite_index="3" angular_momentum="2">', &
303 '0 0 0', '</PP_QIJL.2.2.2>', '</PP_AUGMENTATION>', '</PP_NONLOCAL>', &
304 '<PP_PSWFC>', '<PP_CHI.1 l="0">', '999 999 999', '</PP_CHI.1>', '</PP_PSWFC>'
305 IF (variant == 1) THEN
306 ! Reordered, deliberately unnormalized waves distinguish every index and side.
307 WRITE (unit, '(A)') &
308 '<PP_FULL_WFC number_of_wfc="2">', &
309 '<PP_PSWFC.2 type="real" size="3" l="1">', '2 3 -4', '</PP_PSWFC.2>', &
310 '<PP_AEWFC.1 index="1" l="0">', '-3 5 -7', '</PP_AEWFC.1>', &
311 '<PP_AEWFC.2 index="2" l="1">', '5 -7 9', '</PP_AEWFC.2>', &
312 '<PP_PSWFC.1 l="0">', '1 -2 3', '</PP_PSWFC.1>', '</PP_FULL_WFC>'
313 END IF
314 WRITE (unit, '(A)') '</UPF>'
315 CLOSE (unit)
316 END IF
317 CALL logger%para_env%sync()
318 IF (variant == 1) THEN
319 CALL atom_read_upf(potential, fixture, read_header=.true.)
320 IF (ALLOCATED(potential%partial_waves)) error stop 'USPP full waves imported without augmentation request'
321 CALL atom_release_upf(potential)
322 END IF
323 CALL atom_read_upf(potential, fixture, read_augmentation=.true.)
324 IF (potential%is_paw) error stop 'USPP full waves were classified as PAW'
325 IF (variant == 1) THEN
326 IF (.NOT. ALLOCATED(potential%partial_waves)) error stop 'Missing optional USPP full waves'
327 associate(waves => potential%partial_waves)
328 IF (any(shape(waves%ae_wfc) /= [3, 2])) error stop 'USPP full-wave count differs from beta count'
329 IF (any(waves%ae_wfc /= reshape([-3._dp, 5._dp, -7._dp, 5._dp, -7._dp, 9._dp], [3, 2]))) THEN
330 error stop 'USPP AE full-wave order or original normalization changed'
331 END IF
332 IF (any(waves%ps_wfc /= reshape([1._dp, -2._dp, 3._dp, 2._dp, 3._dp, -4._dp], [3, 2]))) THEN
333 error stop 'USPP PS full waves changed or were confused with atomic guesses'
334 END IF
335 IF (any(waves%angular_momenta /= [0, 1])) error stop 'Wrong USPP full-wave angular momenta'
336 END associate
337 IF (.NOT. upf_has_complete_partial_waves(potential)) error stop 'Complete original full waves not recognized'
338 DEALLOCATE (potential%partial_waves%ps_wfc)
339 IF (upf_has_complete_partial_waves(potential)) error stop 'Incomplete full-wave pair accepted'
340 ELSE
341 IF (upf_has_complete_partial_waves(potential)) error stop 'Atomic guess waves accepted as complete full waves'
342 IF (ALLOCATED(potential%partial_waves)) error stop 'USPP without full waves allocated partial-wave data'
343 END IF
344 CALL atom_release_upf(potential)
345 IF (ALLOCATED(potential%partial_waves)) error stop 'USPP full-wave data not released'
346 CALL logger%para_env%sync()
347 END DO
348 IF (logger%para_env%is_source()) THEN
349 OPEN (newunit=unit, file=fixture, status='OLD')
350 CLOSE (unit, status='DELETE')
351 END IF
352 END SUBROUTINE check_uspp_partial_waves
353
354! **************************************************************************************************
355!> \brief Read PAW one-center data and one optional frozen-core orbital.
356! **************************************************************************************************
357 SUBROUTINE check_paw_import()
358 CHARACTER(LEN=*), PARAMETER :: fixture = 'paw-import-test.upf'
359
360 INTEGER :: unit
361 TYPE(atom_upfpot_type) :: pot
362 TYPE(cp_logger_type), POINTER :: logger
363
364 logger => cp_get_default_logger()
365 IF (logger%para_env%is_source()) THEN
366 OPEN (newunit=unit, file=fixture, status='REPLACE', action='WRITE')
367 WRITE (unit, '(A)') &
368 '<UPF version="2.0.1">', &
369 '<PP_HEADER element="Li" pseudo_type="PAW" is_ultrasoft="true" is_paw="true"', &
370 ' z_valence="1" mesh_size="3" number_of_proj="1" l_max="0"/>', &
371 '<PP_MESH mesh="3">', '<PP_R>', '0.5 1 1.5', '</PP_R>', &
372 '<PP_RAB>', '0.5 0.5 0.5', '</PP_RAB>', '</PP_MESH>', &
373 '<PP_LOCAL>', '-6 -4 -2', '</PP_LOCAL>', '<PP_NONLOCAL>', &
374 '<PP_BETA.1 index="1" angular_momentum="0" size="3">', '1 2 3', '</PP_BETA.1>', &
375 '<PP_DIJ>', '2', '</PP_DIJ>', &
376 '<PP_AUGMENTATION q_with_l="T" nqf="0" nqlc="1" cutoff_r_index="2" l_max_aug="0">', &
377 '<PP_Q>', '0.25', '</PP_Q>', '<PP_MULTIPOLES>', '0.125', '</PP_MULTIPOLES>', &
378 '<PP_QIJL.1.1.0 first_index="1" second_index="1" composite_index="1" angular_momentum="0">', &
379 '1 2 0', '</PP_QIJL.1.1.0>', '</PP_AUGMENTATION>', '</PP_NONLOCAL>', &
380 '<PP_FULL_WFC number_of_wfc="1">', &
381 '<PP_AEWFC.1 l="0">', '-2 3 4', '</PP_AEWFC.1>', &
382 '<PP_PSWFC.1 l="0">', '1 3 4', '</PP_PSWFC.1>', '</PP_FULL_WFC>', &
383 '<PP_PAW paw_data_format="2" core_energy="-8">', &
384 '<PP_OCCUPATIONS>', '1', '</PP_OCCUPATIONS>', &
385 '<PP_AE_NLCC>', '2 1 0', '</PP_AE_NLCC>', &
386 '<PP_AE_VLOC>', '-10 -6 -2', '</PP_AE_VLOC>', '</PP_PAW>', &
387 '<PP_GIPAW gipaw_data_format="2">', '<PP_GIPAW_CORE_ORBITALS number_of_core_orbitals="1">', &
388 '<PP_GIPAW_CORE_ORBITAL.1 index="1" n="1.0" l="0.0">', &
389 '3 -2 1', '</PP_GIPAW_CORE_ORBITAL.1>', '</PP_GIPAW_CORE_ORBITALS>', '</PP_GIPAW>', '</UPF>'
390 CLOSE (unit)
391 END IF
392 CALL logger%para_env%sync()
393 CALL atom_read_upf(pot, fixture, read_header=.true.)
394 IF (.NOT. pot%is_paw .OR. ALLOCATED(pot%paw)) error stop 'Wrong PAW header-only import'
395 CALL atom_release_upf(pot)
396 CALL atom_read_upf(pot, fixture, read_paw=.true.)
397 IF (.NOT. upf_has_complete_partial_waves(pot)) error stop 'Missing complete PAW waves'
398 associate(paw => pot%paw)
399 IF (any(paw%ae_wfc(:, 1) /= [-2._dp, 3._dp, 4._dp]) .OR. &
400 any(paw%ps_wfc(:, 1) /= [1._dp, 3._dp, 4._dp])) error stop 'Changed PAW wave normalization'
401 IF (paw%cutoff_index /= 2 .OR. paw%multipoles(1, 1, 0) /= 0.125_dp .OR. &
402 any(pot%qijl(:, 1, 0) /= [1._dp, 2._dp, 0._dp])) error stop 'Changed PAW augmentation'
403 IF (.NOT. paw%has_core_energy .OR. paw%core_energy /= -4._dp .OR. &
404 any(paw%vlocal /= [-5._dp, -3._dp, -1._dp])) error stop 'Wrong PAW energy units'
405 IF (any(paw%rho_core /= [2._dp, 1._dp, 0._dp]) .OR. &
406 any(paw%occupations /= 1._dp)) error stop 'Changed PAW core charge or occupations'
407 IF (.NOT. ALLOCATED(paw%gipaw_core_orbitals)) error stop 'Missing GIPAW core orbitals'
408 associate(orbitals => paw%gipaw_core_orbitals)
409 IF (any(orbitals%principal_quantum_numbers /= 1) .OR. any(orbitals%angular_momenta /= 0) .OR. &
410 any(orbitals%wfc(:, 1) /= [3._dp, -2._dp, 1._dp])) error stop 'Changed GIPAW core orbital'
411 END associate
412 END associate
413 CALL atom_release_upf(pot)
414 IF (ALLOCATED(pot%paw) .OR. pot%is_paw) error stop 'PAW data were not reset on release'
415 CALL logger%para_env%sync()
416 IF (logger%para_env%is_source()) THEN
417 OPEN (newunit=unit, file=fixture, status='OLD')
418 CLOSE (unit, status='DELETE')
419 END IF
420 END SUBROUTINE check_paw_import
421
422! **************************************************************************************************
423!> \brief Check the repaired radial maps at the size that exposes endpoint cancellation.
424! **************************************************************************************************
425 SUBROUTINE check_radial_grid_endpoints()
426 INTEGER, PARAMETER :: n = 6400, types(2) = [do_gapw_gct, do_gapw_log]
427 REAL(dp), PARAMETER :: inner(2) = [4.83458313724687745e-18_dp, 6.97482911687147684e-18_dp], &
428 outer(2) = [2.06843066219244770e17_dp, 57.5213142095328827_dp]
429
430 INTEGER :: i
431 REAL(dp) :: error
432 TYPE(grid_atom_type), POINTER :: grid
433
434 NULLIFY (grid)
435 DO i = 1, SIZE(types)
436 CALL allocate_grid_atom(grid)
437 CALL create_grid_atom(grid, n, 1, 2, 0, types(i))
438 IF (.NOT. all(ieee_is_finite(grid%rad)) .OR. .NOT. all(ieee_is_finite(grid%wr))) THEN
439 error stop 'Nonfinite radial grid'
440 END IF
441 IF (any(grid%rad <= 0.0_dp) .OR. any(grid%wr <= 0.0_dp)) error stop 'Nonpositive radial grid'
442 IF (any(grid%rad(:n - 1) <= grid%rad(2:))) error stop 'Unordered radial points'
443 ! Independent analytic moments include the r**2 radial measure.
444 error = abs(sum(grid%wr*exp(-grid%rad)) - 2.0_dp)
445 error = max(error, abs(sum(grid%wr*exp(-grid%rad)/grid%rad) - 1.0_dp))
446 error = max(error, abs(sum(grid%wr*exp(-grid%rad2)) - sqrt(pi)/4.0_dp))
447 IF (error > 1.e-10_dp) error stop 'Radial moment error'
448 ! Independent high-precision endpoints reject clipping rounded cosines.
449 IF (abs(grid%rad(n)/inner(i) - 1.0_dp) > 1.e-13_dp .OR. &
450 abs(grid%rad(1)/outer(i) - 1.0_dp) > 1.e-13_dp) error stop 'Radial grid endpoint error'
451 CALL deallocate_grid_atom(grid)
452 END DO
453 END SUBROUTINE check_radial_grid_endpoints
454
455! **************************************************************************************************
456!> \brief Check primitive and contracted Gaussian derivatives on UPF meshes starting at zero.
457! **************************************************************************************************
458 SUBROUTINE check_basis_origin()
459 INTEGER :: i, l, n, variant
460 REAL(KIND=dp) :: expected(3), r(6001), rab(6001), scale
461 TYPE(atom_basis_type) :: basis, radial
462
463 CALL init_atom_basis_default_pp(basis)
464 n = maxval(basis%nbas)
465 ! A long supplied mesh must not generate an unused singular auxiliary grid.
466 r = [(0.002_dp*real(i - 1, dp), i=1, SIZE(r))]
467 rab = 0.002_dp
468 CALL atom_basis_gridrep(basis, radial, r, rab)
469 IF (any(radial%grid%rad /= r) .OR. any(radial%grid%wr /= rab*r**2)) THEN
470 error stop "Supplied UPF mesh changed during basis evaluation"
471 END IF
472 IF (maxval(abs(radial%bf(:, 1, 0) - exp(-basis%am(1, 0)*r**2))) > 1.e-14_dp) THEN
473 error stop "Incorrect basis values on long UPF mesh"
474 END IF
475 CALL release_atom_basis(radial)
476 DO variant = 1, 2
477 scale = real(variant, dp)
478 IF (variant == 2) THEN
479 basis%basis_type = cgto_basis
480 ALLOCATE (basis%cm(n, n, 0:ubound(basis%am, 2)))
481 basis%cm = 0.0_dp
482 DO i = 1, n
483 basis%cm(i, i, :) = scale
484 END DO
485 END IF
486 CALL atom_basis_gridrep(basis, radial, [0.0_dp, 1.e-16_dp, 0.1_dp], [0.1_dp, 0.1_dp, 0.1_dp])
487 IF (.NOT. all(ieee_is_finite(radial%bf)) .OR. .NOT. all(ieee_is_finite(radial%dbf)) .OR. &
488 .NOT. all(ieee_is_finite(radial%ddbf))) error stop "Nonfinite Gaussian derivatives at the UPF origin"
489 DO l = 0, ubound(basis%am, 2)
490 DO i = 1, basis%nbas(l)
491 expected = 0.0_dp
492 IF (l == 0) expected = [1.0_dp, 0.0_dp, -2.0_dp*basis%am(i, l)]
493 IF (l == 1) expected(2) = 1.0_dp
494 IF (l == 2) expected(3) = 2.0_dp
495 IF (maxval(abs([radial%bf(1, i, l), radial%dbf(1, i, l), radial%ddbf(1, i, l)] - &
496 scale*expected)) > 1.e-12_dp) error stop "Incorrect Gaussian origin limit"
497 END DO
498 END DO
499 CALL release_atom_basis(radial)
500 END DO
501 CALL release_atom_basis(basis)
502 END SUBROUTINE check_basis_origin
503
504! **************************************************************************************************
505!> \brief Differentiate radial basis values and densities independently at finite radii.
506! **************************************************************************************************
507 SUBROUTINE check_basis_derivatives()
508 REAL(dp), PARAMETER :: radius(4) = [0.08_dp, 0.3_dp, 0.9_dp, 2.1_dp], step = 2.e-4_dp
509
510 INTEGER :: i, k, l, n, variant
511 REAL(dp) :: derivative(5), errors(3), first, lap(5), &
512 r(5), reference, rho(5), second
513 REAL(dp), ALLOCATABLE :: pmat(:, :, :)
514 TYPE(atom_basis_type) :: basis, radial
515
516 CALL init_atom_basis_default_pp(basis)
517 n = maxval(basis%nbas)
518 ! Nonunit exponents and signed mixing exercise primitives and genuine contractions.
519 basis%nbas = 2
520 basis%nprim = 2
521 basis%am(1, :) = 0.37_dp
522 basis%am(2, :) = 2.3_dp
523 ALLOCATE (pmat(n, n, 0:ubound(basis%am, 2)))
524 pmat = 0.0_dp
525 pmat(1, 1, :) = 0.8_dp
526 pmat(2, 2, :) = 0.4_dp
527 pmat(1, 2, :) = -0.17_dp
528 pmat(2, 1, :) = -0.17_dp
529 errors = 0.0_dp
530 DO variant = 1, 2
531 IF (variant == 2) THEN
532 basis%basis_type = cgto_basis
533 ALLOCATE (basis%cm(n, n, 0:ubound(basis%am, 2)))
534 basis%cm = 0.0_dp
535 basis%cm(1, 1, :) = 0.7_dp
536 basis%cm(2, 1, :) = -0.2_dp
537 basis%cm(1, 2, :) = 0.1_dp
538 basis%cm(2, 2, :) = 1.3_dp
539 END IF
540 DO k = 1, SIZE(radius)
541 r = radius(k) + step*[-2.0_dp, -1.0_dp, 0.0_dp, 1.0_dp, 2.0_dp]
542 CALL atom_basis_gridrep(basis, radial, r, spread(step, 1, 5))
543 DO l = 0, ubound(basis%am, 2)
544 DO i = 1, 2
545 first = dot_product(radial%bf(:, i, l), [1.0_dp, -8.0_dp, 0.0_dp, 8.0_dp, -1.0_dp])/(12*step)
546 second = dot_product(radial%bf(:, i, l), [-1.0_dp, 16.0_dp, -30.0_dp, 16.0_dp, -1.0_dp])/(12*step**2)
547 errors(1) = max(errors(1), abs(first - radial%dbf(3, i, l))/(1 + abs(first)))
548 errors(2) = max(errors(2), abs(second - radial%ddbf(3, i, l))/(1 + abs(second)))
549 END DO
550 END DO
551 CALL atom_density(rho, pmat, radial, ubound(basis%am, 2), typ="RHO")
552 CALL atom_density(derivative, pmat, radial, ubound(basis%am, 2), typ="DER")
553 CALL atom_density(lap, pmat, radial, ubound(basis%am, 2), typ="LAP", rr=r*r)
554 first = dot_product(rho, [1.0_dp, -8.0_dp, 0.0_dp, 8.0_dp, -1.0_dp])/(12*step)
555 second = dot_product(rho, [-1.0_dp, 16.0_dp, -30.0_dp, 16.0_dp, -1.0_dp])/(12*step**2)
556 errors(1) = max(errors(1), abs(first - derivative(3))/(1 + abs(first)))
557 reference = second + 2*first/radius(k)
558 errors(3) = max(errors(3), abs(reference - lap(3))/(1 + abs(reference)))
559 CALL release_atom_basis(radial)
560 END DO
561 END DO
562 IF (io_unit > 0) WRITE (io_unit, '(A,3ES24.15)') "Atomic radial derivative/Laplacian scaled errors: ", errors
563 DEALLOCATE (pmat)
564 CALL release_atom_basis(basis)
565 IF (maxval(errors) > 2.e-7_dp) error stop "Atomic radial finite-difference derivatives disagree"
566 END SUBROUTINE check_basis_derivatives
567
568! **************************************************************************************************
569!> \brief Check fitted densities and their derivatives against an analytic reference.
570!> Evaluation points differ from the input mesh, and neither input mesh
571!> nor reference exponents coincide with the internal fitting sequence.
572! **************************************************************************************************
573 SUBROUTINE check_nlcc_fit()
574 INTEGER, PARAMETER :: nr = 1601
575 REAL(dp), PARAMETER :: amplitudes(3) = [0.02_dp, 1.7_dp, 0.4_dp], &
576 exponents(3) = [0.15_dp, 2.3_dp, 35.0_dp]
577
578 INTEGER :: i, mesh
579 REAL(dp) :: density_error, derivative, derivative_error, dx, r(nr), rab(nr), radius, &
580 reference, reference_derivative, rho(nr), value
581 REAL(dp), ALLOCATABLE :: alpha(:), coeff(:)
582
583 DO mesh = 1, 2
584 dx = log(20.0_dp/1.e-6_dp)/real(nr - 1, dp)
585 DO i = 1, nr
586 IF (mesh == 1) THEN
587 r(i) = 20.0_dp*real(i - 1, dp)/real(nr - 1, dp)
588 rab(i) = 20.0_dp/real(nr - 1, dp)
589 ELSE
590 r(i) = 1.e-6_dp*exp(dx*real(i - 1, dp))
591 rab(i) = dx*r(i)
592 END IF
593 rho(i) = sum(amplitudes*exp(-exponents*r(i)**2))
594 END DO
595 CALL fit_core_density_gaussians(r, rab, rho, alpha, coeff)
596 density_error = 0.0_dp
597 derivative_error = 0.0_dp
598 DO i = 0, 1200
599 radius = real(i, dp)*0.017_dp
600 reference = sum(amplitudes*exp(-exponents*radius**2))
601 reference_derivative = -2.0_dp*radius*sum(exponents*amplitudes*exp(-exponents*radius**2))
602 value = sum(coeff*exp(-alpha*radius**2))
603 derivative = -2.0_dp*radius*sum(alpha*coeff*exp(-alpha*radius**2))
604 density_error = max(density_error, abs(value - reference))
605 derivative_error = max(derivative_error, abs(derivative - reference_derivative))
606 END DO
607 IF (io_unit > 0) WRITE (io_unit, '(A,I2,2ES16.7)') &
608 "Core Gaussian fit, density and derivative:", mesh, density_error, derivative_error
609 IF (density_error > 2.e-7_dp) error stop "Gaussian core-density fit is inaccurate"
610 IF (derivative_error > 3.e-6_dp) error stop "Gaussian core-density derivative is inaccurate"
611 rho = 0.0_dp
612 CALL fit_core_density_gaussians(r, rab, rho, alpha, coeff)
613 IF (any(coeff /= 0.0_dp)) error stop "Zero core density generated nonzero Gaussian coefficients"
614 END DO
615 END SUBROUTINE check_nlcc_fit
616
617! **************************************************************************************************
618!> \brief Read an independent miniature UPF fixture and check its numerical convention.
619!> The values are deliberately simple and are not a physical pseudopotential.
620!> Checking beta separately matters: an inverse rescaling of D leaves the NC
621!> operator unchanged but would require rescaling USPP augmentation data too.
622! **************************************************************************************************
623 SUBROUTINE check_upf_units()
624 CHARACTER(LEN=*), PARAMETER :: fixture = &
625 'upf-units-test-with-a-potential-filename-longer-than-'// &
626 'the-default-eighty-character-string-buffer.upf'
627
628 INTEGER :: unit
629 TYPE(atom_potential_type) :: atomic
630 TYPE(cp_logger_type), POINTER :: logger
631 TYPE(section_type), POINTER :: specification
632 TYPE(section_vals_type), POINTER :: input, potential_section
633
634 logger => cp_get_default_logger()
635 IF (logger%para_env%is_source()) THEN
636 CALL open_file(fixture, unit_number=unit, file_status="REPLACE", file_action="WRITE")
637 WRITE (unit, '(A)') &
638 '<UPF version="2.0.1">', &
639 '<PP_HEADER element="He" pseudo_type="NC" z_valence="2"', &
640 ' mesh_size="3" number_of_proj="2" l_max="0" />', &
641 '<PP_MESH mesh="3">', &
642 '<PP_R type="real" size="3">', &
643 '0.5 1.0 1.5', &
644 '</PP_R>', &
645 '<PP_RAB type="real" size="3">', &
646 '0.5 0.5 0.5', &
647 '</PP_RAB>', &
648 '</PP_MESH>', &
649 '<PP_LOCAL type="real" size="3">', &
650 '6.0 4.0 2.0', &
651 '</PP_LOCAL>', &
652 '<PP_NONLOCAL>', &
653 '<PP_BETA.1 type="real" size="3" index="1" angular_momentum="0">', &
654 '1.0 4.0 9.0', &
655 '</PP_BETA.1>', &
656 '<PP_BETA.2 type="real" size="3" index="2" angular_momentum="0">', &
657 '2.0 -1.0 3.0', &
658 '</PP_BETA.2>', &
659 '<PP_DIJ type="real" size="4">', &
660 '2.0 0.4 0.4 8.0', &
661 '</PP_DIJ>', &
662 '</PP_NONLOCAL>', &
663 '</UPF>'
664 CALL close_file(unit)
665 END IF
666 CALL logger%para_env%sync()
667 NULLIFY (specification, input)
668 CALL create_atom_section(specification)
669 CALL section_vals_create(input, specification)
670 potential_section => section_vals_get_subs_vals(input, 'POTENTIAL')
671 CALL section_vals_val_set(potential_section, 'PSEUDO_TYPE', i_val=upf_pseudo)
672 CALL section_vals_val_set(potential_section, 'POTENTIAL_FILE_NAME', c_val=fixture)
673 CALL init_atom_potential(atomic, potential_section, 2)
674 associate(potential => atomic%upf_pot)
675 IF (maxval(abs(potential%vlocal - [3.0_dp, 2.0_dp, 1.0_dp])) > 1.e-14_dp) THEN
676 error stop "UPF local potential is not in Hartree"
677 END IF
678 IF (maxval(abs(potential%beta(:, 1) - [2.0_dp, 4.0_dp, 6.0_dp])) > 1.e-14_dp) THEN
679 error stop "UPF changed the first tabulated projector amplitude"
680 END IF
681 IF (maxval(abs(potential%beta(:, 2) - [4.0_dp, -1.0_dp, 2.0_dp])) > 1.e-14_dp) THEN
682 error stop "UPF changed the second tabulated projector amplitude"
683 END IF
684 IF (maxval(abs(potential%dion - reshape([1.0_dp, 0.2_dp, 0.2_dp, 4.0_dp], [2, 2]))) > 1.e-14_dp) THEN
685 error stop "UPF D matrix is not in the tabulated-projector convention"
686 END IF
687 END associate
688 CALL release_atom_potential(atomic)
689 CALL section_vals_release(input)
690 CALL section_release(specification)
691 CALL logger%para_env%sync()
692 IF (logger%para_env%is_source()) THEN
693 CALL open_file(fixture, unit_number=unit, file_status="OLD")
694 CALL close_file(unit, file_status="DELETE")
695 END IF
696 END SUBROUTINE check_upf_units
697
698! **************************************************************************************************
699!> \brief Compare the converted atomic SGP operator with analytic Gaussian integrals.
700!> This checks that atomic guesses and the Quickstep Hamiltonian describe
701!> the same radial projectors and erf-regularized local Coulomb potential.
702! **************************************************************************************************
703 SUBROUTINE check_atomic_potential()
704 INTEGER :: l
705 REAL(KIND=dp) :: a, b, p, reference
706 TYPE(atom_basis_type) :: basis
707 TYPE(atom_integrals) :: integrals
708 TYPE(atom_potential_type) :: atomic
709 TYPE(sgp_potential_type), POINTER :: potential
710
711 NULLIFY (potential)
712 CALL allocate_potential(potential)
713 potential%zeff = 1.0_dp
714 potential%core_charge_radius = 0.4_dp
715 potential%alpha_core_charge = 0.5_dp/potential%core_charge_radius**2
716 potential%n_nonlocal = 1
717 potential%lmax = 2
718 potential%is_nonlocal(0:2) = .true.
719 potential%n_local = 1
720 ALLOCATE (potential%elec_conf(0:3), potential%a_nonlocal(1), &
721 potential%c_nonlocal(1, 1, 0:2), potential%h_nonlocal(1, 0:2), &
722 potential%a_local(1), potential%c_local(1))
723 potential%elec_conf = [1, 0, 0, 0]
724 potential%a_nonlocal = 0.7_dp
725 potential%c_nonlocal = 1.0_dp/sqrt(fourpi)
726 potential%h_nonlocal = 1.0_dp
727 potential%a_local = 1.2_dp
728 potential%c_local = 0.3_dp
729 atomic%ppot_type = sgp_pseudo
730 CALL sgp_potential_conversion(potential, atomic%sgp_pot)
731 CALL init_atom_basis_default_pp(basis)
732 CALL atom_ppint_setup(integrals, basis, atomic)
733 DO l = 0, 2
734 a = basis%am(8, l) + potential%a_nonlocal(1)
735 reference = (gamma(l + 1.5_dp)/(2.0_dp*a**(l + 1.5_dp)))**2
736 IF (abs(integrals%hnl(8, 8, l) - reference) > 1.e-9_dp*abs(reference)) THEN
737 error stop "Atomic SGP nonlocal operator differs from analytic Gaussian integrals"
738 END IF
739 END DO
740 p = 2.0_dp*basis%am(8, 0)
741 b = 1.0_dp/(sqrt(2.0_dp)*potential%core_charge_radius)
742 reference = -potential%zeff*b/(2.0_dp*p*sqrt(p + b*b)) + &
743 potential%c_local(1)*gamma(1.5_dp)/(2.0_dp*(p + potential%a_local(1))**1.5_dp)
744 IF (abs(integrals%core(8, 8, 0) - reference) > 1.e-9_dp*abs(reference)) THEN
745 error stop "Atomic SGP local operator differs from analytic Gaussian integrals"
746 END IF
747 CALL atom_ppint_release(integrals)
748 CALL release_atom_basis(basis)
749 CALL deallocate_potential(potential)
750 END SUBROUTINE check_atomic_potential
751
752! **************************************************************************************************
753!> \brief Verify the physical angular kernel of Gaussian UPF projectors through l=5.
754!> For beta_l(r) = r**l exp(-a*r**2), stripping off the radial exponentials
755!> at unit vectors leaves sum_m Y_lm(u) Y_lm(v) = (2*l+1) P_l(u.v)/(4*pi).
756!> The reference uses the Legendre recurrence, independently of the Cartesian
757!> to spherical transformation used by the production projector integrals.
758! **************************************************************************************************
759 SUBROUTINE check_projector_addition_theorem()
760 INTEGER, PARAMETER :: lmax = 5
761
762 INTEGER :: i, j, l, lx, ly, lz, nc, ns
763 REAL(KIND=dp) :: cross, diagonal, p(0:lmax), u(3), v(3), x
764 REAL(KIND=dp), ALLOCATABLE :: pu(:), pv(:)
765 TYPE(sgp_potential_type), POINTER :: potential
766
767 NULLIFY (potential)
768 CALL init_orbital_pointers(lmax)
769 CALL init_spherical_harmonics(lmax, -1)
770 CALL allocate_potential(potential)
771 potential%n_nonlocal = 1
772 potential%lmax = lmax
773 potential%nppnl = sum(nco(0:lmax))
774 ALLOCATE (potential%c_nonlocal(1, 1, 0:lmax), potential%h_nonlocal(1, 0:lmax))
775 ! atom_sgp stores the radial coefficients divided by sqrt(4*pi).
776 potential%c_nonlocal = 1.0_dp/sqrt(fourpi)
777 potential%h_nonlocal = 1.0_dp
778 CALL init_potential(potential)
779 u = [0.6_dp, 0.0_dp, 0.8_dp]
780 v = [0.3_dp, -0.4_dp, 0.5_dp]
781 v = v/norm2(v)
782 x = dot_product(u, v)
783 p(0) = 1.0_dp
784 p(1) = x
785 DO l = 2, lmax
786 p(l) = ((2*l - 1)*x*p(l - 1) - (l - 1)*p(l - 2))/l
787 END DO
788 nc = 0
789 ns = 0
790 DO l = 0, lmax
791 ALLOCATE (pu(nso(l)), pv(nso(l)))
792 pu = 0.0_dp
793 pv = 0.0_dp
794 DO lx = 0, l
795 DO ly = 0, l - lx
796 lz = l - lx - ly
797 i = nc + co(lx, ly, lz)
798 DO j = 1, nso(l)
799 pu(j) = pu(j) + potential%cprj_ppnl(i, ns + j)*u(1)**lx*u(2)**ly*u(3)**lz
800 pv(j) = pv(j) + potential%cprj_ppnl(i, ns + j)*v(1)**lx*v(2)**ly*v(3)**lz
801 END DO
802 END DO
803 END DO
804 diagonal = real(2*l + 1, dp)/fourpi
805 cross = diagonal*p(l)
806 IF (abs(dot_product(pu, pu) - diagonal) > 1.e-12_dp .OR. &
807 abs(dot_product(pv, pv) - diagonal) > 1.e-12_dp .OR. &
808 abs(dot_product(pu, pv) - cross) > 1.e-12_dp) THEN
809 error stop "SGP projector kernel violates the spherical-harmonic addition theorem"
810 END IF
811 nc = nc + nco(l)
812 ns = ns + nso(l)
813 DEALLOCATE (pu, pv)
814 END DO
815 CALL deallocate_potential(potential)
816 END SUBROUTINE check_projector_addition_theorem
817
818! **************************************************************************************************
819!> \brief Verify radial derivatives and the spherical Laplacian against finite differences.
820! **************************************************************************************************
821 SUBROUTINE check_core_derivatives()
822 REAL(kind=dp), PARAMETER :: h = 1.e-4_dp
823
824 REAL(kind=dp) :: deriv(4), lap(4), lap_fd(4), minus(4), &
825 plus(4), r(4), rho(4)
826 TYPE(atom_potential_type) :: potential
827
828 potential%ppot_type = sgp_pseudo
829 potential%sgp_pot%has_nlcc = .true.
830 potential%sgp_pot%n_nlcc = 2
831 potential%sgp_pot%a_nlcc(1:2) = [0.7_dp, 2.3_dp]
832 potential%sgp_pot%c_nlcc(1:2) = [1.8_dp, -0.2_dp]
833 r = [0.0_dp, 0.1_dp, 0.7_dp, 2.0_dp]
834 rho = 0.0_dp
835 plus = 0.0_dp
836 minus = 0.0_dp
837 deriv = 0.0_dp
838 lap = 0.0_dp
839 CALL atom_core_density(rho, potential, "RHO", r)
840 CALL atom_core_density(plus, potential, "RHO", r + h)
841 CALL atom_core_density(minus, potential, "RHO", r - h)
842 CALL atom_core_density(deriv, potential, "DER", r)
843 CALL atom_core_density(lap, potential, "LAP", r)
844 IF (maxval(abs(deriv - (plus - minus)/(2.0_dp*h))) > 1.e-7_dp) THEN
845 error stop "SGP core-density derivative differs from finite differences"
846 END IF
847 lap_fd = (plus - 2.0_dp*rho + minus)/h**2
848 lap_fd(1) = 3.0_dp*lap_fd(1)
849 lap_fd(2:) = lap_fd(2:) + (plus(2:) - minus(2:))/(h*r(2:))
850 IF (maxval(abs(lap - lap_fd)) > 1.e-6_dp) error stop "SGP core-density Laplacian differs from finite differences"
851 END SUBROUTINE check_core_derivatives
852
853! **************************************************************************************************
854!> \brief Check independent shell, primitive and set counts in file and inline atomic bases.
855! **************************************************************************************************
856 SUBROUTINE check_contracted_basis_reader()
857 INTEGER, PARAMETER :: contractions(3) = [11, 1, 1], lower_l(3) = [0, 1, 2], &
858 primitives(3) = [11, 41, 2], sets(3) = [1, 1, 21], upper_l(3) = [3, 6, 3]
859 CHARACTER(LEN=1600), ALLOCATABLE :: lines(:)
860 INTEGER :: b, c, i, j, l, mode, n, nc, np, ns, row, &
861 s, t, unit
862 REAL(dp) :: alpha, coefficient, expected, &
863 normalization
864 TYPE(atom_basis_type) :: basis
865 CHARACTER(LEN=*), PARAMETER :: fixture = "atom-contracted-basis-test"
866
867 TYPE(cp_logger_type), POINTER :: logger
868 TYPE(section_type), POINTER :: specification
869 TYPE(section_vals_type), POINTER :: input, pp_basis
870
871 logger => cp_get_default_logger()
872 DO b = 1, SIZE(sets)
873 np = primitives(b)
874 nc = contractions(b)
875 ns = sets(b)
876 ALLOCATE (lines(1 + ns*(np + 1)))
877 WRITE (lines(1), '(I0)') ns
878 row = 1
879 DO s = 1, ns
880 row = row + 1
881 WRITE (lines(row), '(*(I0,1X))') 1, lower_l(b), upper_l(b), np, (nc, l=lower_l(b), upper_l(b))
882 DO i = 1, np
883 row = row + 1
884 alpha = real(10*s + i, dp)/20.0_dp
885 WRITE (lines(row), '(*(F12.6,1X))') alpha, &
886 ((real(100*s + 10*i + c + 5*l, dp)/1000.0_dp, c=1, nc), l=lower_l(b), upper_l(b))
887 END DO
888 END DO
889 IF (logger%para_env%is_source()) THEN
890 OPEN (newunit=unit, file=fixture, status="REPLACE", action="WRITE")
891 WRITE (unit, '(A)') 'H READER-TEST', (trim(lines(i)), i=1, SIZE(lines))
892 CLOSE (unit)
893 END IF
894 CALL logger%para_env%sync()
895 DO mode = 1, 2
896 NULLIFY (specification, input)
897 CALL create_atom_section(specification)
898 CALL section_vals_create(input, specification)
899 pp_basis => section_vals_get_subs_vals(input, 'PP_BASIS')
900 CALL section_vals_val_set(pp_basis, 'BASIS_TYPE', i_val=contracted_gto)
901 CALL section_vals_val_set(pp_basis, 'GRID_POINTS', i_val=32)
902 CALL section_vals_val_set(pp_basis, 'BASIS_SET', c_val='READER-TEST')
903 CALL section_vals_val_set(pp_basis, 'BASIS_SET_FILE_NAME', c_val=fixture)
904 IF (mode == 2) THEN
905 DO i = 1, SIZE(lines)
906 CALL section_vals_val_set(pp_basis, 'BASIS%_DEFAULT_KEYWORD_', i_rep_val=i, c_val=trim(lines(i)))
907 END DO
908 END IF
909 CALL init_atom_basis(basis, pp_basis, 1, 'PP')
910 DO l = 0, ubound(basis%nbas, 1)
911 n = 0
912 IF (l >= lower_l(b) .AND. l <= upper_l(b)) n = ns
913 IF (basis%nprim(l) /= n*np .OR. basis%nbas(l) /= n*nc) THEN
914 error stop "Incorrect atomic contracted basis dimensions"
915 END IF
916 DO s = 1, n
917 DO i = 1, np
918 alpha = real(10*s + i, dp)/20.0_dp
919 j = (s - 1)*np + i
920 IF (abs(basis%am(j, l) - alpha) > 1.e-14_dp) error stop "Incorrect contracted basis exponent"
921 ! Inverse square root of the analytic radial Gaussian norm.
922 normalization = sqrt(2.0_dp*(2.0_dp*alpha)**(l + 1.5_dp)/gamma(l + 1.5_dp))
923 DO t = 1, n
924 DO c = 1, nc
925 coefficient = 0.0_dp
926 IF (s == t) coefficient = real(100*s + 10*i + c + 5*l, dp)/1000.0_dp
927 expected = normalization*coefficient
928 IF (abs(basis%cm(j, (t - 1)*nc + c, l) - expected) > 1.e-12_dp*max(1.0_dp, abs(expected))) THEN
929 error stop "Incorrect contracted basis coefficient or normalization"
930 END IF
931 END DO
932 END DO
933 END DO
934 END DO
935 END DO
936 CALL release_atom_basis(basis)
937 CALL section_vals_release(input)
938 CALL section_release(specification)
939 END DO
940 CALL logger%para_env%sync()
941 IF (logger%para_env%is_source()) THEN
942 OPEN (newunit=unit, file=fixture, status="OLD")
943 CLOSE (unit, status="DELETE")
944 END IF
945 DEALLOCATE (lines)
946 END DO
947 END SUBROUTINE check_contracted_basis_reader
948
949! **************************************************************************************************
950!> \brief Verify exported orbitals use the best basis restored after Powell optimization.
951! **************************************************************************************************
952 SUBROUTINE check_basis_optimization_export()
953 CHARACTER(LEN=160) :: line
954 INTEGER :: i, j, status, unit
955 REAL(dp) :: alpha(2), coefficient(2), norm
956 REAL(dp), POINTER :: exponents(:)
957 TYPE(cp_logger_type), POINTER :: logger
958 TYPE(section_type), POINTER :: specification
959 TYPE(section_vals_type), POINTER :: input
960
961 NULLIFY (specification, input)
962 CALL create_atom_section(specification)
963 CALL section_vals_create(input, specification)
964 CALL section_vals_val_set(input, 'ELEMENT', c_val='He')
965 CALL section_vals_val_set(input, 'ELECTRON_CONFIGURATION', c_val='1s2')
966 CALL section_vals_val_set(input, 'MAX_ANGULAR_MOMENTUM', i_val=0)
967 CALL section_vals_val_set(input, 'AE_BASIS%NUM_GTO', i_val=2)
968 ALLOCATE (exponents(2))
969 exponents = [2.0_dp, 0.4_dp]
970 CALL section_vals_val_set(input, 'AE_BASIS%S_EXPONENTS', r_vals_ptr=exponents)
971 CALL section_vals_val_set(input, 'METHOD%METHOD_TYPE', i_val=do_rhf_atom)
972 CALL section_vals_val_set(input, 'OPTIMIZATION%EPS_SCF', r_val=1.e-10_dp)
973 CALL section_vals_val_set(input, 'OPTIMIZATION%N_DIIS', i_val=8)
974 CALL section_vals_val_set(input, 'OPTIMIZATION%MAX_ITER', i_val=100)
975 CALL section_vals_val_set(input, 'POWELL%MAX_FUN', i_val=5)
976 CALL section_vals_val_set(input, 'POWELL%STEP_SIZE', r_val=0.15_dp)
977 CALL section_vals_val_set(input, 'POWELL%ACCURACY', r_val=1.e-5_dp)
978 CALL section_vals_val_set(input, 'PRINT%FIT_BASIS%_SECTION_PARAMETERS_', i_val=silent_print_level)
979 CALL atom_basis_opt(input)
980 CALL section_vals_release(input)
981 CALL section_release(specification)
982
983 logger => cp_get_default_logger()
984 CALL logger%para_env%sync()
985 OPEN (newunit=unit, file='OPT_BASIS', status='OLD', action='READ')
986 DO
987 READ (unit, '(A)', iostat=status) line
988 IF (status /= 0) error stop 'Missing optimized basis orbital coefficients'
989 IF (index(line, 'L Quantum Number:') > 0) EXIT
990 END DO
991 DO i = 1, 2
992 READ (unit, *) alpha(i), coefficient(i)
993 END DO
994 CLOSE (unit)
995 IF (alpha(1) <= 2.0_dp) error stop 'Optimization did not restore the earlier best exponent'
996 norm = 0.0_dp
997 DO i = 1, 2
998 DO j = 1, 2
999 norm = norm + coefficient(i)*coefficient(j)* &
1000 (2.0_dp*sqrt(alpha(i)*alpha(j))/(alpha(i) + alpha(j)))**1.5_dp
1001 END DO
1002 END DO
1003 ! The export rounds its coefficients to eight decimal places.
1004 IF (.NOT. ieee_is_finite(norm) .OR. abs(norm - 1.0_dp) > 1.e-7_dp) THEN
1005 error stop 'Exported orbital is inconsistent with the optimized basis'
1006 END IF
1007 CALL logger%para_env%sync()
1008 IF (logger%para_env%is_source()) THEN
1009 OPEN (newunit=unit, file='OPT_BASIS', status='OLD')
1010 CLOSE (unit, status='DELETE')
1011 END IF
1012 END SUBROUTINE check_basis_optimization_export
1013
1014END PROGRAM atom_upf_unittest
subroutine check_uspp_import()
...
program atom_upf_unittest
subroutine, public atom_basis_opt(atom_section)
Optimize the atomic basis set.
Definition atom_basis.F:53
calculate the orbitals for a given atomic kind type
subroutine, public sgp_potential_conversion(sgp_potential, sgp_atompot)
...
Calculate the atomic operator matrices.
subroutine, public atom_ppint_release(integrals)
Release memory allocated for atomic integrals (core electrons).
subroutine, public atom_ppint_setup(integrals, basis, potential)
...
subroutine, public atom_sgp_release(sgp_pot)
...
Definition atom_sgp.F:801
subroutine, public sgp_construction(sgp_pot, ecp_pot, upf_pot, orb_basis, error)
...
Definition atom_sgp.F:79
subroutine, public fit_core_density_gaussians(r, rab, rho, alpha, coeff)
Fit a tabulated core density without forming ill-conditioned normal equations. Column-normalized,...
Definition atom_sgp.F:749
Define the atom type and its sub types.
Definition atom_types.F:15
integer, parameter, public cgto_basis
Definition atom_types.F:70
subroutine, public release_atom_potential(potential)
...
subroutine, public init_atom_basis(basis, basis_section, zval, btyp)
Initialize the basis for the atomic code.
Definition atom_types.F:384
subroutine, public init_atom_potential(potential, potential_section, zval)
...
subroutine, public release_atom_basis(basis)
...
Definition atom_types.F:934
subroutine, public init_atom_basis_default_pp(basis)
...
Definition atom_types.F:723
subroutine, public atom_basis_gridrep(basis, gbasis, r, rab)
...
Definition atom_types.F:800
Routines that process Quantum Espresso UPF files.
Definition atom_upf.F:14
subroutine, public atom_read_upf(pot, upf_filename, read_header, read_augmentation, read_paw)
...
Definition atom_upf.F:55
pure subroutine, public atom_release_upf(upfpot)
...
Definition atom_upf.F:1498
Some basic routines for atomic calculations.
Definition atom_utils.F:15
subroutine, public atom_core_density(corden, potential, typ, rr)
...
Definition atom_utils.F:689
subroutine, public atom_density(density, pmat, basis, maxl, typ, rr)
Map the electron density on an atomic radial grid.
Definition atom_utils.F:365
Utility routines to open and close files.
Definition cp_files.F:22
subroutine, public open_file(file_name, unit_number, file_status, file_form, file_action, file_position, file_pad, file_access, debug)
Opens a file and returns its logical unit number.
Definition cp_files.F:197
subroutine, public close_file(unit_number, file_status)
Closes an open file given by its logical unit number.
Definition cp_files.F:64
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public silent_print_level
Definition of the atomic potential types.
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
Definition gamma.F:15
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_rhf_atom
integer, parameter, public do_gapw_gct
integer, parameter, public contracted_gto
integer, parameter, public do_gapw_log
builds the input structure for the ATOM module
subroutine, public create_atom_section(section)
Creates the input section for the atom code.
objects that represent the structure of input sections and the data contained in an input section
recursive subroutine, public section_vals_create(section_vals, section)
creates a object where to store the values of a section
subroutine, public section_vals_val_set(section_vals, keyword_name, i_rep_section, i_rep_val, val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
sets the requested value
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
recursive subroutine, public section_release(section)
releases the given keyword list (see doc/ReferenceCounting.html)
recursive subroutine, public section_vals_release(section_vals)
releases the given object
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_path_length
Definition kinds.F:58
CP2K C/C++ interface.
Definition libcp2k.F:20
subroutine, public cp2k_finalize()
...
Definition libcp2k.F:139
subroutine, public cp2k_init()
...
Definition libcp2k.F:104
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
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 co
integer, dimension(:), allocatable, public nco
integer, dimension(:), allocatable, public nso
Calculation of the spherical harmonics and the corresponding orbital transformation matrices.
subroutine, public init_spherical_harmonics(maxl, output_unit)
Initialize or update the orbital transformation matrices.
subroutine, public deallocate_grid_atom(grid_atom)
Deallocate a Gaussian-type orbital (GTO) basis set data set.
subroutine, public allocate_grid_atom(grid_atom)
Initialize components of the grid_atom_type structure.
subroutine, public create_grid_atom(grid_atom, nr, na, llmax, ll, quadrature)
...
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_has_complete_partial_waves(pot)
Check for a complete projector-indexed pair of original AE and PS waves.
Definition upf_types.F:213
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
Provides all information about a basis set.
Definition atom_types.F:79
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represent a section of the input file