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 :: 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(:)
70 ! PAW-specific raw data
71 logical :: is_paw
72 integer :: paw_nwavefunctions
73 integer :: paw_augmentation_lmax
74 integer :: paw_shape
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(:,:)
93 end type ps_xml_t
94
95contains
96
97 ! ---------------------------------------------------------
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
104
105 integer :: ll, ii, jj, ic, jc, ip, nproj
106 type(pseudo_t) :: pseudo
107
108 push_sub(ps_xml_init)
109
110 this%initialized = .false.
112 call pseudo_init(pseudo, string_f_to_c(filename), fmt, ierr)
115 call messages_write("Pseudopotential file '" // trim(filename) // "' not found")
116 call messages_fatal(namespace=namespace)
117 end if
120 call messages_write("Cannot determine the format for pseudopotential file '" // trim(filename) // "'")
121 call messages_fatal(namespace=namespace)
122 end if
125 call messages_write("Ultrasoft pseudopotential file '" // trim(filename) // "' not supported")
126 call messages_fatal(namespace=namespace)
127 end if
130 call messages_write("PAW pseudopotential file '" // trim(filename) // "' not supported")
131 call messages_fatal(namespace=namespace)
132 end if
135 call messages_write("Pseudopotential file '" // trim(filename) // "' not supported")
136 call messages_fatal(namespace=namespace)
137 end if
140 call messages_write("Pseudopotential file '" // trim(filename) // "' not supported")
141 call messages_fatal(namespace=namespace)
142 end if
144 this%initialized = .true.
145 this%is_paw = .false.
146 this%valence_charge = pseudo_valence_charge(pseudo)
147 this%mass = pseudo_mass(pseudo)
148 this%lmax = pseudo_lmax(pseudo)
149 this%llocal = pseudo_llocal(pseudo)
150 this%nchannels = pseudo_nchannels(pseudo)
152 ! PAW uses the same projector representation as ultrasoft
153 this%kleinman_bylander = (pseudo_type(pseudo) == pseudo_type_kleinman_bylander .or. &
156 this%has_qij_integrals = pseudo_has_qij_integrals(pseudo)
157 if (pseudo_type(pseudo) == pseudo_type_ultrasoft .and. .not. this%has_qij_integrals) then
158 call messages_write("Ultrasoft pseudopotential file '" // trim(filename) // "' does not contain PP_Q or PP_QIJ")
159 call messages_fatal(namespace=namespace)
160 end if
161 this%has_radial_augmentation = pseudo_has_radial_augmentation(pseudo)
162 this%radial_augmentation_has_angular_channels = pseudo_radial_augmentation_has_angular_channels(pseudo)
163 this%radial_augmentation_lmax = pseudo_radial_augmentation_lmax(pseudo)
165 this%grid_size = pseudo_mesh_size(pseudo)
166 nproj = pseudo_nprojectors(pseudo)
167
168 safe_allocate(this%grid(1:this%grid_size))
169 safe_allocate(this%weights(1:this%grid_size))
171 call pseudo_grid(pseudo, this%grid(1))
172 call pseudo_grid_weights(pseudo, this%weights(1))
173
174 if (.not. this%kleinman_bylander) then
175
176 safe_allocate(this%potential(1:this%grid_size, 0:this%lmax))
177 safe_allocate(this%wavefunction(1:this%grid_size, 0:this%lmax))
178
179 do ll = 0, this%lmax
180 if (.not. pseudo_has_radial_function(pseudo, ll)) then
181 call messages_write("The pseudopotential file '"//trim(filename)//"' does not contain")
182 call messages_new_line()
183 call messages_write("the wave functions. Octopus cannot use it.")
184 call messages_fatal(namespace=namespace)
185 end if
186
187 call pseudo_radial_function(pseudo, ll, this%wavefunction(1, ll))
188 call pseudo_radial_potential(pseudo, ll, this%potential(1, ll))
189 end do
190
191 else
192
193 safe_allocate(this%potential(1:this%grid_size, this%llocal:this%llocal))
194
195 call pseudo_local_potential(pseudo, this%potential(1, this%llocal))
196
197 safe_allocate(this%projector(1:this%grid_size, 0:this%lmax, 1:this%nchannels))
198
199 this%projector = m_zero
200
201 safe_allocate(this%kb_radius(0:this%lmax, 1:this%nchannels))
202 this%kb_radius = this%grid_size
203
204 do ll = 0, this%lmax
205 if (this%llocal == ll) cycle
206 do ic = 1, pseudo_nprojectors_per_l(pseudo, ll)
207 call pseudo_projector(pseudo, ll, ic, this%projector(1, ll, ic))
208
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
212 exit
213 end if
214 end do
215 end do
216 end do
217
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))
220
221 do ii = 1, nproj
222 do jj = 1, nproj
223 do ll = 0, this%radial_augmentation_lmax
224 call pseudo_radial_augmentation(pseudo, ii, jj, ll, this%radial_augmentation(1, ii, jj, ll))
225 end do
226 end do
227 end do
228 end if
229
230
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))
233
234 this%dij = 0.0_real64
235 this%qij = 0.0_real64
236 do ll = 0, this%lmax
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)
241 end do
242 end do
243 end do
244
245 this%nwavefunctions = pseudo_nwavefunctions(pseudo)
246
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))
251
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))
254 end do
255
256 ! PAW-specific data: AE/PS partial waves, AE core density, AE local potential,
257 ! reference occupations, augmentation multipoles.
258 this%is_paw = pseudo_has_paw(pseudo)
259 if (this%is_paw) then
260 this%paw_nwavefunctions = pseudo_paw_nwavefunctions(pseudo)
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."
264 call messages_fatal(1, namespace=namespace)
265 end if
266 this%paw_augmentation_lmax = pseudo_paw_augmentation_lmax(pseudo)
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)."
270 call messages_fatal(1, namespace=namespace)
271 end if
272 this%paw_shape = pseudo_paw_shape_code(pseudo)
273 this%paw_core_energy = pseudo_paw_core_energy(pseudo)
274 this%paw_cutoff_radius = pseudo_paw_cutoff_radius(pseudo)
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)."
278 call messages_fatal(1, namespace=namespace)
279 end if
280
281 ! Angular momentum of each partial wave, in file order. As for the ultrasoft
282 ! augmentation (see ps_xml_t%radial_augmentation), the projectors are assumed
283 ! to be stored grouped by increasing l.
284 safe_allocate(this%paw_l(1:nproj))
285 ip = 0
286 do ll = 0, this%lmax
287 if (ll == this%llocal) cycle
288 do ic = 1, pseudo_nprojectors_per_l(pseudo, ll)
289 ip = ip + 1
290 this%paw_l(ip) = ll
291 end do
292 end do
293 assert(ip == nproj)
294
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))
297 do ii = 1, nproj
298 call pseudo_paw_ae_wavefunction(pseudo, ii, this%paw_phi_ae(1, ii))
299 call pseudo_paw_ps_wavefunction(pseudo, ii, this%paw_phi_ps(1, ii))
300 end do
301
302 ! Fully-relativistic datasets: small component of the AE partial waves
303 this%paw_has_small = pseudo_paw_has_rel_wavefunctions(pseudo) /= 0
304 if (this%paw_has_small) then
305 safe_allocate(this%paw_phi_ae_small(1:this%grid_size, 1:nproj))
306 do ii = 1, nproj
307 call pseudo_paw_ae_wavefunction_rel(pseudo, ii, this%paw_phi_ae_small(1, ii))
308 end do
309 end if
310
311 this%paw_has_ae_core = pseudo_has_paw_ae_nlcc(pseudo)
312 if (this%paw_has_ae_core) then
313 safe_allocate(this%paw_ae_core(1:this%grid_size))
314 call pseudo_paw_ae_nlcc(pseudo, this%paw_ae_core(1))
315 end if
316
317 safe_allocate(this%paw_ae_vlocal(1:this%grid_size))
318 call pseudo_paw_ae_vlocal(pseudo, this%paw_ae_vlocal(1))
319
320 safe_allocate(this%paw_occ(1:nproj))
321 call pseudo_paw_occupations(pseudo, this%paw_occ(1))
322
323 ! Frozen-core orbitals
324 this%paw_ncore = pseudo_paw_ncore_orbitals(pseudo)
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
330 call pseudo_paw_core_orbital(pseudo, ii, this%paw_core_orbital(1, ii))
331 this%paw_core_l(ii) = pseudo_paw_core_orbital_l(pseudo, ii)
332 this%paw_core_n(ii) = pseudo_paw_core_orbital_n(pseudo, ii)
333 end do
334 end if
335
336 safe_allocate(this%paw_multipoles(1:nproj, 1:nproj, 0:this%paw_augmentation_lmax))
337 call pseudo_paw_multipoles(pseudo, this%paw_multipoles(1, 1, 0))
338 end if
339
340 end if
341
342 this%has_density = pseudo_has_density(pseudo)
343
344 if (this%has_density) then
345 safe_allocate(this%density(1:this%grid_size))
346 call pseudo_density(pseudo, this%density(1))
347 end if
348
349 this%nlcc = pseudo_has_nlcc(pseudo)
350 if (this%nlcc) then
351 safe_allocate(this%nlcc_density(1:this%grid_size))
352 call pseudo_nlcc_density(pseudo, this%nlcc_density(1))
353 end if
354
355 if (.not. this%kleinman_bylander) call ps_xml_check_normalization(this, namespace)
356
357 this%pseudo = pseudo
358
359 pop_sub(ps_xml_init)
360 end subroutine ps_xml_init
361
362 ! ---------------------------------------------------------
364 subroutine ps_xml_check_normalization(this, namespace)
365 type(ps_xml_t), intent(in) :: this
366 type(namespace_t), intent(in) :: namespace
367
368 integer :: ll, ip
369 real(real64) :: nrm, rr
370
372
373 ! checking normalization of the wavefunctions
374 do ll = 0, this%lmax
375 nrm = m_zero
376 do ip = 1, this%grid_size
377 rr = this%grid(ip)
378 nrm = nrm + this%wavefunction(ip, ll)**2*this%weights(ip)*rr**2
379 end do
380 nrm = sqrt(nrm)
381
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, ')'
386 call messages_warning(2, namespace=namespace)
387 end if
388
389 end do
390
392 end subroutine ps_xml_check_normalization
393
394 ! ---------------------------------------------------------
395 subroutine ps_xml_end(this)
396 type(ps_xml_t), intent(inout) :: this
397
398 push_sub(ps_xml_end)
399
400 call pseudo_end(this%pseudo)
401
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)
427
428 this%initialized = .false.
429
430 pop_sub(ps_xml_end)
431 end subroutine ps_xml_end
432
433end module ps_xml_oct_m
434
435!! Local Variables:
436!! mode: f90
437!! coding: utf-8
438!! End:
double sqrt(double __x) __attribute__((__nothrow__
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_epsilon
Definition: global.F90:189
real(real64), parameter, public m_one
Definition: global.F90:174
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:501
subroutine, public messages_new_line()
Definition: messages.F90:1069
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public ps_xml_end(this)
Definition: ps_xml.F90:468
subroutine ps_xml_check_normalization(this, namespace)
checks normalization of the pseudo wavefunctions
Definition: ps_xml.F90:437
subroutine, public ps_xml_init(this, namespace, filename, fmt, ierr)
Definition: ps_xml.F90:171
integer, parameter, public pseudo_type_kleinman_bylander
Definition: pseudo.F90:162
logical function, public pseudo_has_radial_function(pseudo, l)
Definition: pseudo.F90:851
logical function, public pseudo_has_density(pseudo)
Definition: pseudo.F90:756
logical function, public pseudo_has_paw_ae_nlcc(pseudo)
Definition: pseudo.F90:889
logical function, public pseudo_has_paw(pseudo)
Definition: pseudo.F90:871
logical function, public pseudo_has_radial_augmentation(pseudo)
Definition: pseudo.F90:794
integer, parameter, public pseudo_type_paw
Definition: pseudo.F90:162
logical function, public pseudo_has_nlcc(pseudo)
Definition: pseudo.F90:738
integer, parameter, public pseudo_status_unsupported_type
Definition: pseudo.F90:168
integer, parameter, public pseudo_status_file_not_found
Definition: pseudo.F90:168
logical function, public pseudo_has_qij_integrals(pseudo)
Definition: pseudo.F90:775
integer, parameter, public pseudo_type_ultrasoft
Definition: pseudo.F90:162
integer, parameter, public pseudo_status_unsupported_type_ultrasoft
Definition: pseudo.F90:168
logical function, public pseudo_radial_augmentation_has_angular_channels(pseudo)
Definition: pseudo.F90:813
integer, parameter, public pseudo_status_unknown_format
Definition: pseudo.F90:168
integer, parameter, public pseudo_status_unsupported_type_paw
Definition: pseudo.F90:168
integer, parameter, public pseudo_status_format_not_supported
Definition: pseudo.F90:168
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:234
int true(void)