Octopus
ps_xml.F90
Go to the documentation of this file.
1!! Copyright (C) 2015-2018 Xavier Andrade
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
21module ps_xml_oct_m
22 use debug_oct_m
23 use global_oct_m
24 use, intrinsic :: iso_fortran_env
28 use pseudo_oct_m
29 use string_oct_m
30
31 implicit none
32
33 private
34 public :: &
35 ps_xml_t, &
38
39 type ps_xml_t
40 ! Components are public by default
41 logical :: initialized
42 logical :: kleinman_bylander
43 logical :: nlcc
44 logical :: has_density
45 integer :: atomic_number
46 real(real64) :: mass
47 real(real64) :: valence_charge
48 integer :: lmax
49 integer :: llocal
50 integer :: nchannels
51 integer :: grid_size
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(:,:)
66 end type ps_xml_t
67
68contains
69
70 ! ---------------------------------------------------------
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
77
78 integer :: ll, ii, ic, jc, ip
79 type(pseudo_t) :: pseudo
80
81 push_sub(ps_xml_init)
82
83 this%initialized = .false.
84
85 call pseudo_init(pseudo, string_f_to_c(filename), fmt, ierr)
86
87 if (ierr == pseudo_status_file_not_found) then
88 call messages_write("Pseudopotential file '" // trim(filename) // "' not found")
89 call messages_fatal(namespace=namespace)
90 end if
91
92 if (ierr == pseudo_status_unknown_format) then
93 call messages_write("Cannot determine the format for pseudopotential file '" // trim(filename) // "'")
94 call messages_fatal(namespace=namespace)
95 end if
96
98 call messages_write("Ultrasoft pseudopotential file '" // trim(filename) // "' not supported")
99 call messages_fatal(namespace=namespace)
100 end if
101
102 if (ierr == pseudo_status_unsupported_type_paw) then
103 call messages_write("PAW pseudopotential file '" // trim(filename) // "' not supported")
104 call messages_fatal(namespace=namespace)
105 end if
106
107 if (ierr == pseudo_status_unsupported_type) then
108 call messages_write("Pseudopotential file '" // trim(filename) // "' not supported")
109 call messages_fatal(namespace=namespace)
110 end if
111
112 if (ierr == pseudo_status_format_not_supported) then
113 call messages_write("Pseudopotential file '" // trim(filename) // "' not supported")
114 call messages_fatal(namespace=namespace)
115 end if
117 this%initialized = .true.
118 this%valence_charge = pseudo_valence_charge(pseudo)
119 this%mass = pseudo_mass(pseudo)
120 this%lmax = pseudo_lmax(pseudo)
121 this%llocal = pseudo_llocal(pseudo)
122 this%nchannels = pseudo_nchannels(pseudo)
123
124 this%kleinman_bylander = (pseudo_type(pseudo) == pseudo_type_kleinman_bylander)
125
126 this%grid_size = pseudo_mesh_size(pseudo)
127
128 safe_allocate(this%grid(1:this%grid_size))
129 safe_allocate(this%weights(1:this%grid_size))
130
131 call pseudo_grid(pseudo, this%grid(1))
132 call pseudo_grid_weights(pseudo, this%weights(1))
133
134 if (.not. this%kleinman_bylander) then
135
136 safe_allocate(this%potential(1:this%grid_size, 0:this%lmax))
137 safe_allocate(this%wavefunction(1:this%grid_size, 0:this%lmax))
139 do ll = 0, this%lmax
140 if (.not. pseudo_has_radial_function(pseudo, ll)) then
141 call messages_write("The pseudopotential file '"//trim(filename)//"' does not contain")
143 call messages_write("the wave functions. Octopus cannot use it.")
144 call messages_fatal(namespace=namespace)
145 end if
147 call pseudo_radial_function(pseudo, ll, this%wavefunction(1, ll))
148 call pseudo_radial_potential(pseudo, ll, this%potential(1, ll))
149 end do
151 else
153 safe_allocate(this%potential(1:this%grid_size, this%llocal:this%llocal))
155 call pseudo_local_potential(pseudo, this%potential(1, this%llocal))
157 safe_allocate(this%projector(1:this%grid_size, 0:this%lmax, 1:this%nchannels))
159 this%projector = m_zero
161 safe_allocate(this%kb_radius(0:this%lmax, 1:this%nchannels))
162 this%kb_radius = this%grid_size
163
164 do ll = 0, this%lmax
165 if (this%llocal == ll) cycle
166 do ic = 1, pseudo_nprojectors_per_l(pseudo, ll)
167 call pseudo_projector(pseudo, ll, ic, this%projector(1, ll, ic))
168
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
172 exit
173 end if
174 end do
175 end do
176 end do
177
178
179 safe_allocate(this%dij(0:this%lmax, 1:this%nchannels, 1:this%nchannels))
180
181 this%dij = 0.0_real64
182 do ll = 0, this%lmax
183 do ic = 1, this%nchannels
184 do jc = 1, this%nchannels
185 this%dij(ll, ic, jc) = pseudo_dij(pseudo, ll, ic, jc)
186 end do
187 end do
188 end do
189
190 this%nwavefunctions = pseudo_nwavefunctions(pseudo)
191
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))
196
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))
199 end do
200
201 end if
202
203 this%has_density = pseudo_has_density(pseudo)
204
205 if (this%has_density) then
206 safe_allocate(this%density(1:this%grid_size))
207 call pseudo_density(pseudo, this%density(1))
208 end if
209
210 this%nlcc = pseudo_has_nlcc(pseudo)
211 if (this%nlcc) then
212 safe_allocate(this%nlcc_density(1:this%grid_size))
213 call pseudo_nlcc_density(pseudo, this%nlcc_density(1))
214 end if
215
216 if (.not. this%kleinman_bylander) call ps_xml_check_normalization(this, namespace)
217
218 this%pseudo = pseudo
219
220 pop_sub(ps_xml_init)
221 end subroutine ps_xml_init
222
223 ! ---------------------------------------------------------
225 subroutine ps_xml_check_normalization(this, namespace)
226 type(ps_xml_t), intent(in) :: this
227 type(namespace_t), intent(in) :: namespace
228
229 integer :: ll, ip
230 real(real64) :: nrm, rr
231
233
234 ! checking normalization of the wavefunctions
235 do ll = 0, this%lmax
236 nrm = m_zero
237 do ip = 1, this%grid_size
238 rr = this%grid(ip)
239 nrm = nrm + this%wavefunction(ip, ll)**2*this%weights(ip)*rr**2
240 end do
241 nrm = sqrt(nrm)
242
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, ')'
247 call messages_warning(2, namespace=namespace)
248 end if
249
250 end do
251
253 end subroutine ps_xml_check_normalization
254
255 ! ---------------------------------------------------------
256 subroutine ps_xml_end(this)
257 type(ps_xml_t), intent(inout) :: this
258
259 push_sub(ps_xml_end)
260
261 call pseudo_end(this%pseudo)
262
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)
275
276 pop_sub(ps_xml_end)
277 end subroutine ps_xml_end
278
279end module ps_xml_oct_m
280
281!! Local Variables:
282!! mode: f90
283!! coding: utf-8
284!! End:
double sqrt(double __x) __attribute__((__nothrow__
real(real64), parameter, public m_zero
Definition: global.F90:191
real(real64), parameter, public m_epsilon
Definition: global.F90:207
real(real64), parameter, public m_one
Definition: global.F90:192
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:524
subroutine, public messages_new_line()
Definition: messages.F90:1088
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:161
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:409
subroutine, public ps_xml_end(this)
Definition: ps_xml.F90:352
subroutine ps_xml_check_normalization(this, namespace)
checks normalization of the pseudo wavefunctions
Definition: ps_xml.F90:321
subroutine, public ps_xml_init(this, namespace, filename, fmt, ierr)
Definition: ps_xml.F90:167
integer, parameter, public pseudo_type_kleinman_bylander
Definition: pseudo.F90:160
logical function, public pseudo_has_radial_function(pseudo, l)
Definition: pseudo.F90:570
logical function, public pseudo_has_density(pseudo)
Definition: pseudo.F90:533
logical function, public pseudo_has_nlcc(pseudo)
Definition: pseudo.F90:515
integer, parameter, public pseudo_status_unsupported_type
Definition: pseudo.F90:166
integer, parameter, public pseudo_status_file_not_found
Definition: pseudo.F90:166
integer, parameter, public pseudo_status_unsupported_type_ultrasoft
Definition: pseudo.F90:166
integer, parameter, public pseudo_status_unknown_format
Definition: pseudo.F90:166
integer, parameter, public pseudo_status_unsupported_type_paw
Definition: pseudo.F90:166
integer, parameter, public pseudo_status_format_not_supported
Definition: pseudo.F90:166
character(kind=c_char, len=1) function, dimension(:), allocatable, public string_f_to_c(f_string)
convert a Fortran string to a C string
Definition: string.F90:273
int true(void)