24 use,
intrinsic :: iso_fortran_env
41 logical :: initialized
42 logical :: kleinman_bylander
44 logical :: has_density
45 integer :: atomic_number
47 real(real64) :: valence_charge
52 integer :: nwavefunctions
53 real(real64),
allocatable :: grid(:)
54 real(real64),
allocatable :: weights(:)
55 real(real64),
allocatable :: potential(:, :)
56 real(real64),
allocatable :: wavefunction(:, :)
57 real(real64),
allocatable :: projector(:, :, :)
58 real(real64),
allocatable :: dij(:, :, :)
59 real(real64),
allocatable :: qij(:, :, :)
60 logical :: has_qij_integrals
61 logical :: has_radial_augmentation
62 logical :: radial_augmentation_has_angular_channels
63 integer :: radial_augmentation_lmax
64 real(real64),
allocatable :: radial_augmentation(:, :, :, :)
65 real(real64),
allocatable :: nlcc_density(:)
66 real(real64),
allocatable :: density(:)
67 integer,
allocatable :: wf_n(:)
68 integer,
allocatable :: wf_l(:)
69 real(real64),
allocatable :: wf_occ(:)
72 integer :: paw_nwavefunctions
73 integer :: paw_augmentation_lmax
75 real(real64) :: paw_core_energy
76 real(real64) :: paw_cutoff_radius
77 logical :: paw_has_ae_core
78 integer,
allocatable :: paw_l(:)
79 logical :: paw_has_small = .false.
80 real(real64),
allocatable :: paw_phi_ae(:, :)
81 real(real64),
allocatable :: paw_phi_ae_small(:, :)
82 real(real64),
allocatable :: paw_phi_ps(:, :)
83 real(real64),
allocatable :: paw_ae_core(:)
84 real(real64),
allocatable :: paw_ae_vlocal(:)
85 real(real64),
allocatable :: paw_occ(:)
86 integer :: paw_ncore = 0
87 real(real64),
allocatable :: paw_core_orbital(:, :)
88 integer,
allocatable :: paw_core_l(:)
89 integer,
allocatable :: paw_core_n(:)
90 real(real64),
allocatable :: paw_multipoles(:, :, :)
91 type(pseudo_t) :: pseudo
92 integer,
allocatable :: kb_radius(:,:)
98 subroutine ps_xml_init(this, namespace, filename, fmt, ierr)
99 type(ps_xml_t),
intent(inout) :: this
100 type(namespace_t),
intent(in) :: namespace
101 character(len=*),
intent(in) :: filename
102 integer,
intent(in) :: fmt
103 integer,
intent(out) :: ierr
105 integer :: ll, ii, jj, ic, jc, ip, nproj
106 type(pseudo_t) :: pseudo
110 this%initialized = .false.
120 call messages_write(
"Cannot determine the format for pseudopotential file '" // trim(filename) //
"'")
125 call messages_write(
"Ultrasoft pseudopotential file '" // trim(filename) //
"' not supported")
130 call messages_write(
"PAW pseudopotential file '" // trim(filename) //
"' not supported")
135 call messages_write(
"Pseudopotential file '" // trim(filename) //
"' not supported")
140 call messages_write(
"Pseudopotential file '" // trim(filename) //
"' not supported")
145 this%is_paw = .false.
158 call messages_write(
"Ultrasoft pseudopotential file '" // trim(filename) //
"' does not contain PP_Q or PP_QIJ")
168 safe_allocate(this%grid(1:this%grid_size))
169 safe_allocate(this%weights(1:this%grid_size))
174 if (.not. this%kleinman_bylander)
then
176 safe_allocate(this%potential(1:this%grid_size, 0:this%lmax))
177 safe_allocate(this%wavefunction(1:this%grid_size, 0:this%lmax))
181 call messages_write(
"The pseudopotential file '"//trim(filename)//
"' does not contain")
193 safe_allocate(this%potential(1:this%grid_size, this%llocal:this%llocal))
197 safe_allocate(this%projector(1:this%grid_size, 0:this%lmax, 1:this%nchannels))
201 safe_allocate(this%kb_radius(0:this%lmax, 1:this%nchannels))
202 this%kb_radius = this%grid_size
205 if (this%llocal == ll) cycle
209 do ip = this%grid_size, 1, -1
210 if (abs(this%projector(ip, ll, ic)) >
m_epsilon)
then
211 this%kb_radius(ll, ic) = ip
218 if (this%has_radial_augmentation)
then
219 safe_allocate(this%radial_augmentation(1:this%grid_size, 1:nproj, 1:nproj, 0:this%radial_augmentation_lmax))
223 do ll = 0, this%radial_augmentation_lmax
231 safe_allocate(this%dij(0:this%lmax, 1:this%nchannels, 1:this%nchannels))
232 safe_allocate(this%qij(0:this%lmax, 1:this%nchannels, 1:this%nchannels))
234 this%dij = 0.0_real64
235 this%qij = 0.0_real64
237 do ic = 1, this%nchannels
238 do jc = 1, this%nchannels
239 this%dij(ll, ic, jc) =
pseudo_dij(pseudo, ll, ic, jc)
240 if (this%has_qij_integrals) this%qij(ll, ic, jc) =
pseudo_qij(pseudo, ll, ic, jc)
247 safe_allocate(this%wavefunction(1:this%grid_size, 1:this%nwavefunctions))
248 safe_allocate(this%wf_n(1:this%nwavefunctions))
249 safe_allocate(this%wf_l(1:this%nwavefunctions))
250 safe_allocate(this%wf_occ(1:this%nwavefunctions))
252 do ii = 1, this%nwavefunctions
253 call pseudo_wavefunction(pseudo, ii, this%wf_n(ii), this%wf_l(ii), this%wf_occ(ii), this%wavefunction(1, ii))
259 if (this%is_paw)
then
261 if (this%paw_nwavefunctions /= nproj)
then
262 write(
message(1),
'(a,i0,a,i0,a)')
"PAW pseudopotential file '" // trim(filename) // &
263 "' has ", this%paw_nwavefunctions,
" partial waves but ", nproj,
" projectors."
267 if (this%paw_augmentation_lmax < 0)
then
268 message(1) =
"PAW pseudopotential file '" // trim(filename) // &
269 "' does not define the augmentation lmax (lmax_aug or l_max_aug)."
275 if (this%paw_cutoff_radius <=
m_zero)
then
276 message(1) =
"PAW pseudopotential file '" // trim(filename) // &
277 "' does not define the augmentation radius (PP_AUGMENTATION/cutoff_r)."
284 safe_allocate(this%paw_l(1:nproj))
287 if (ll == this%llocal) cycle
295 safe_allocate(this%paw_phi_ae(1:this%grid_size, 1:nproj))
296 safe_allocate(this%paw_phi_ps(1:this%grid_size, 1:nproj))
304 if (this%paw_has_small)
then
305 safe_allocate(this%paw_phi_ae_small(1:this%grid_size, 1:nproj))
312 if (this%paw_has_ae_core)
then
313 safe_allocate(this%paw_ae_core(1:this%grid_size))
317 safe_allocate(this%paw_ae_vlocal(1:this%grid_size))
320 safe_allocate(this%paw_occ(1:nproj))
325 if (this%paw_ncore > 0)
then
326 safe_allocate(this%paw_core_orbital(1:this%grid_size, 1:this%paw_ncore))
327 safe_allocate(this%paw_core_l(1:this%paw_ncore))
328 safe_allocate(this%paw_core_n(1:this%paw_ncore))
329 do ii = 1, this%paw_ncore
336 safe_allocate(this%paw_multipoles(1:nproj, 1:nproj, 0:this%paw_augmentation_lmax))
344 if (this%has_density)
then
345 safe_allocate(this%density(1:this%grid_size))
351 safe_allocate(this%nlcc_density(1:this%grid_size))
369 real(real64) :: nrm, rr
376 do ip = 1, this%grid_size
378 nrm = nrm + this%wavefunction(ip, ll)**2*this%weights(ip)*rr**2
382 nrm = abs(nrm -
m_one)
383 if (nrm > 1.0e-5_real64)
then
384 write(
message(1),
'(a,i2,a)')
"Eigenstate for l = ", ll,
' is not normalized'
385 write(
message(2),
'(a, f12.6,a)')
'(abs(1 - norm) = ', nrm,
')'
396 type(
ps_xml_t),
intent(inout) :: this
402 safe_deallocate_a(this%grid)
403 safe_deallocate_a(this%weights)
404 safe_deallocate_a(this%potential)
405 safe_deallocate_a(this%wavefunction)
406 safe_deallocate_a(this%projector)
407 safe_deallocate_a(this%dij)
408 safe_deallocate_a(this%qij)
409 safe_deallocate_a(this%radial_augmentation)
410 safe_deallocate_a(this%nlcc_density)
411 safe_deallocate_a(this%density)
412 safe_deallocate_a(this%wf_n)
413 safe_deallocate_a(this%wf_l)
414 safe_deallocate_a(this%wf_occ)
415 safe_deallocate_a(this%kb_radius)
416 safe_deallocate_a(this%paw_l)
417 safe_deallocate_a(this%paw_phi_ae)
418 safe_deallocate_a(this%paw_phi_ae_small)
419 safe_deallocate_a(this%paw_phi_ps)
420 safe_deallocate_a(this%paw_ae_core)
421 safe_deallocate_a(this%paw_ae_vlocal)
422 safe_deallocate_a(this%paw_occ)
423 safe_deallocate_a(this%paw_core_orbital)
424 safe_deallocate_a(this%paw_core_l)
425 safe_deallocate_a(this%paw_core_n)
426 safe_deallocate_a(this%paw_multipoles)
428 this%initialized = .false.
double sqrt(double __x) __attribute__((__nothrow__
real(real64), parameter, public m_zero
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_one
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_new_line()
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
subroutine, public ps_xml_end(this)
subroutine ps_xml_check_normalization(this, namespace)
checks normalization of the pseudo wavefunctions
subroutine, public ps_xml_init(this, namespace, filename, fmt, ierr)
integer, parameter, public pseudo_type_kleinman_bylander
logical function, public pseudo_has_radial_function(pseudo, l)
logical function, public pseudo_has_density(pseudo)
logical function, public pseudo_has_paw_ae_nlcc(pseudo)
logical function, public pseudo_has_paw(pseudo)
logical function, public pseudo_has_radial_augmentation(pseudo)
integer, parameter, public pseudo_type_paw
logical function, public pseudo_has_nlcc(pseudo)
integer, parameter, public pseudo_status_unsupported_type
integer, parameter, public pseudo_status_file_not_found
logical function, public pseudo_has_qij_integrals(pseudo)
integer, parameter, public pseudo_type_ultrasoft
integer, parameter, public pseudo_status_unsupported_type_ultrasoft
logical function, public pseudo_radial_augmentation_has_angular_channels(pseudo)
integer, parameter, public pseudo_status_unknown_format
integer, parameter, public pseudo_status_unsupported_type_paw
integer, parameter, public pseudo_status_format_not_supported
character(kind=c_char, len=1) function, dimension(:), allocatable, public string_f_to_c(f_string)
convert a Fortran string to a C string