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 :: nlcc_density(:)
60 real(real64),
allocatable :: density(:)
61 integer,
allocatable :: wf_n(:)
62 integer,
allocatable :: wf_l(:)
63 real(real64),
allocatable :: wf_occ(:)
64 type(pseudo_t) :: pseudo
65 integer,
allocatable :: kb_radius(:,:)
71 subroutine ps_xml_init(this, namespace, filename, fmt, ierr)
72 type(ps_xml_t),
intent(inout) :: this
73 type(namespace_t),
intent(in) :: namespace
74 character(len=*),
intent(in) :: filename
75 integer,
intent(in) :: fmt
76 integer,
intent(out) :: ierr
78 integer :: ll, ii, ic, jc, ip
79 type(pseudo_t) :: pseudo
83 this%initialized = .false.
88 call messages_write(
"Pseudopotential file '" // trim(filename) //
"' not found")
93 call messages_write(
"Cannot determine the format for pseudopotential file '" // trim(filename) //
"'")
98 call messages_write(
"Ultrasoft pseudopotential file '" // trim(filename) //
"' not supported")
103 call messages_write(
"PAW pseudopotential file '" // trim(filename) //
"' not supported")
108 call messages_write(
"Pseudopotential file '" // trim(filename) //
"' not supported")
113 call messages_write(
"Pseudopotential file '" // trim(filename) //
"' not supported")
117 this%initialized = .
true.
128 safe_allocate(this%grid(1:this%grid_size))
129 safe_allocate(this%weights(1:this%grid_size))
134 if (.not. this%kleinman_bylander)
then
136 safe_allocate(this%potential(1:this%grid_size, 0:this%lmax))
137 safe_allocate(this%wavefunction(1:this%grid_size, 0:this%lmax))
141 call messages_write(
"The pseudopotential file '"//trim(filename)//
"' does not contain")
153 safe_allocate(this%potential(1:this%grid_size, this%llocal:this%llocal))
157 safe_allocate(this%projector(1:this%grid_size, 0:this%lmax, 1:this%nchannels))
161 safe_allocate(this%kb_radius(0:this%lmax, 1:this%nchannels))
162 this%kb_radius = this%grid_size
165 if (this%llocal == ll) cycle
169 do ip = this%grid_size, 1, -1
170 if (abs(this%projector(ip, ll, ic)) >
m_epsilon)
then
171 this%kb_radius(ll, ic) = ip
179 safe_allocate(this%dij(0:this%lmax, 1:this%nchannels, 1:this%nchannels))
181 this%dij = 0.0_real64
183 do ic = 1, this%nchannels
184 do jc = 1, this%nchannels
185 this%dij(ll, ic, jc) =
pseudo_dij(pseudo, ll, ic, jc)
192 safe_allocate(this%wavefunction(1:this%grid_size, 1:this%nwavefunctions))
193 safe_allocate(this%wf_n(1:this%nwavefunctions))
194 safe_allocate(this%wf_l(1:this%nwavefunctions))
195 safe_allocate(this%wf_occ(1:this%nwavefunctions))
197 do ii = 1, this%nwavefunctions
198 call pseudo_wavefunction(pseudo, ii, this%wf_n(ii), this%wf_l(ii), this%wf_occ(ii), this%wavefunction(1, ii))
205 if (this%has_density)
then
206 safe_allocate(this%density(1:this%grid_size))
212 safe_allocate(this%nlcc_density(1:this%grid_size))
230 real(real64) :: nrm, rr
237 do ip = 1, this%grid_size
239 nrm = nrm + this%wavefunction(ip, ll)**2*this%weights(ip)*rr**2
243 nrm = abs(nrm -
m_one)
244 if (nrm > 1.0e-5_real64)
then
245 write(
message(1),
'(a,i2,a)')
"Eigenstate for l = ", ll,
' is not normalized'
246 write(
message(2),
'(a, f12.6,a)')
'(abs(1 - norm) = ', nrm,
')'
257 type(
ps_xml_t),
intent(inout) :: this
263 safe_deallocate_a(this%grid)
264 safe_deallocate_a(this%weights)
265 safe_deallocate_a(this%potential)
266 safe_deallocate_a(this%wavefunction)
267 safe_deallocate_a(this%projector)
268 safe_deallocate_a(this%dij)
269 safe_deallocate_a(this%nlcc_density)
270 safe_deallocate_a(this%density)
271 safe_deallocate_a(this%wf_n)
272 safe_deallocate_a(this%wf_l)
273 safe_deallocate_a(this%wf_occ)
274 safe_deallocate_a(this%kb_radius)
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)
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_nlcc(pseudo)
integer, parameter, public pseudo_status_unsupported_type
integer, parameter, public pseudo_status_file_not_found
integer, parameter, public pseudo_status_unsupported_type_ultrasoft
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