Octopus
ps.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2012 M. Marques, A. Castro, A. Rubio, G. Bertsch, M. Oliveira
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_oct_m
22 use atomic_oct_m
23 use debug_oct_m
24 use global_oct_m
25 use io_oct_m
26 use, intrinsic :: iso_fortran_env
30 use parser_oct_m
31 use logrid_oct_m
32 use math_oct_m
36 use ps_cpi_oct_m
37 use ps_fhi_oct_m
38 use ps_hgh_oct_m
39 use ps_xml_oct_m
41#ifdef HAVE_PSPIO
42 use fpspio_m
43#endif
44 use ps_psf_oct_m
45 use pseudo_oct_m
48 use string_oct_m
49
50 implicit none
51
52 private
53 public :: &
54 ps_t, &
55 ps_init, &
58 ps_filter, &
61 ps_debug, &
62 ps_niwfs, &
64 ps_end, &
68 ps_is_paw, &
73
74 integer, parameter, public :: &
75 PS_FILTER_NONE = 0, &
76 ps_filter_ts = 2, &
78
79 integer, public, parameter :: &
80 PROJ_NONE = 0, &
81 proj_hgh = 1, &
82 proj_kb = 2, &
83 proj_rkb = 3, &
84 proj_uspp = 4
85
86 integer, public, parameter :: &
87 PROJ_J_INDEPENDENT = 0, & !< Non-relativisitic or scalar-relativistic pseudopotentials
88 proj_j_dependent = 1, &
90
91 integer, parameter, public :: INVALID_L = 333
92
93 character(len=4), parameter :: ps_name(PSEUDO_FORMAT_UPF1:PSEUDO_FORMAT_PSP8) = &
94 (/"upf1", "upf2", "qso ", "psml", "psf ", "cpi ", "fhi ", "hgh ", "psp8"/)
95
97 type ps_t
98 ! Components are public by default
99 integer :: projector_type
100 integer :: relativistic_treatment
102
103 character(len=10), private :: label
104
105 integer, private :: ispin
106
107 real(real64), private :: z
108 real(real64) :: z_val
109 type(valconf_t) :: conf
110
111 type(logrid_t), private :: g
112
113 type(spline_t), allocatable :: ur(:, :)
114 logical, allocatable :: bound(:, :)
115
116 ! Kleinman-Bylander projectors stuff
117 integer :: lmax
118 integer :: llocal
119
120 type(spline_t) :: vl
121 logical :: no_vl = .false.
122
123 real(real64) :: projectors_sphere_threshold
130 real(real64) :: rc_max
131
132 integer :: kbc
133 integer :: projectors_per_l(5)
134 real(real64), allocatable :: h(:,:,:), k(:, :, :)
135 real(real64), allocatable :: qij(:, :, :)
136 integer :: radial_augmentation_lmax = -1
137 integer :: radial_augmentation_nprojectors = 0
138 logical :: radial_augmentation_has_angular_channels = .false.
139 type(spline_t), allocatable :: radial_augmentation(:, :)
140 type(spline_t), allocatable :: kb(:, :)
141 type(spline_t), allocatable :: dkb(:, :)
142
143 ! PAW-specific data (only for PAW pseudopotentials).
144 integer :: paw_nwavefunctions = 0
145 integer :: paw_augmentation_lmax = -1
146 integer :: paw_shape = pseudo_paw_shape_unknown
147 real(real64) :: paw_core_energy = m_zero
148 real(real64) :: paw_cutoff_radius = m_zero
149 logical :: paw_has_ae_core = .false.
150 integer, allocatable :: paw_l(:)
151 type(spline_t), allocatable :: paw_phi_ae(:)
152 type(spline_t), allocatable :: paw_phi_ps(:)
153 logical :: paw_has_small = .false.
154 type(spline_t), allocatable :: paw_phi_ae_small(:)
155 type(spline_t) :: paw_ae_core
161 type(spline_t) :: paw_ae_vlocal
162 real(real64), allocatable :: paw_occ(:)
163 integer, allocatable :: paw_2j(:)
164 integer :: paw_ncore = 0
165 type(spline_t), allocatable :: paw_core_orbital(:)
166 integer, allocatable :: paw_core_l(:)
167 real(real64), allocatable :: paw_grid(:)
168 real(real64), allocatable :: paw_rab(:)
169 real(real64), allocatable :: paw_multipoles(:, :, :)
170
171 logical :: nlcc
172 type(spline_t) :: core
173 type(spline_t) :: core_der
174
176 !LONG-RANGE PART OF THE LOCAL POTENTIAL
178 logical, private :: has_long_range
179 logical, private :: is_separated
181 type(spline_t), private :: vlr
182 type(spline_t) :: nlr
184 real(real64) :: sigma_erf
186 logical, private :: has_density
187 type(spline_t), allocatable :: density(:)
188 type(spline_t), allocatable :: density_der(:)
190 logical :: local
191 integer :: file_format
192 integer, private :: pseudo_type
193 integer :: exchange_functional
194 integer :: correlation_functional
195 end type ps_t
196
197 real(real64), parameter :: eps = 1.0e-8_real64
198
199contains
200
201
202 ! ---------------------------------------------------------
203 subroutine ps_init(ps, namespace, label, z, user_lmax, user_llocal, ispin, filename)
204 type(ps_t), intent(out) :: ps
205 type(namespace_t), intent(in) :: namespace
206 character(len=10), intent(in) :: label
207 integer, intent(in) :: user_lmax
208 integer, intent(in) :: user_llocal
209 integer, intent(in) :: ispin
210 real(real64), intent(in) :: z
211 character(len=*), intent(in) :: filename
213 integer :: l, ii, ll, is, ierr
214 type(ps_psf_t) :: ps_psf
215 type(ps_cpi_t) :: ps_cpi
216 type(ps_fhi_t) :: ps_fhi
217 type(ps_hgh_t) :: ps_hgh
218 type(ps_xml_t) :: ps_xml
219 real(real64), allocatable :: eigen(:, :)
221 push_sub(ps_init)
223 ps%exchange_functional = pseudo_exchange_unknown
224 ps%correlation_functional = pseudo_correlation_unknown
226 ! Fix the threshold to calculate the radius of the projector-function localization spheres:
228 call messages_obsolete_variable(namespace, 'SpecieProjectorSphereThreshold', 'SpeciesProjectorSphereThreshold')
229
230 !%Variable SpeciesProjectorSphereThreshold
231 !%Type float
232 !%Default 0.001
233 !%Section System::Species
234 !%Description
235 !% The pseudopotentials may be composed of a local part, and a linear combination of nonlocal
236 !% operators. These nonlocal projectors have "projector" form, <math> \left| v \right> \left< v \right| </math>
237 !% (or, more generally speaking, <math> \left| u \right> \left< v \right| </math>).
238 !% These projectors are localized in real space -- that is, the function <math>v</math>
239 !% has a finite support around the nucleus. This region where the projectors are localized should
240 !% be small or else the computation time required to operate with them will be very large.
241 !%
242 !% In practice, this localization is fixed by requiring the definition of the projectors to be
243 !% contained in a sphere of a certain radius. This radius is computed by making sure that the
244 !% absolute value of the projector functions, at points outside the localization sphere, is
245 !% below a certain threshold. This threshold is set by <tt>SpeciesProjectorSphereThreshold</tt>.
246 !%
247 !% The default is 0.001 for norm-conserving pseudopotentials. For ultrasoft
248 !% pseudopotentials the projectors and augmentation charges are sharper, so a tighter
249 !% default of 0.0001 is used to converge the augmentation-sphere integrals (this only
250 !% applies when the variable is not set explicitly in the input file).
251 !%End
252 call parse_variable(namespace, 'SpeciesProjectorSphereThreshold', 0.001_real64, ps%projectors_sphere_threshold)
253 if (ps%projectors_sphere_threshold <= m_zero) call messages_input_error(namespace, 'SpeciesProjectorSphereThreshold')
255 ps%file_format = pseudo_detect_format(string_f_to_c(filename))
257 if (ps%file_format == pseudo_format_file_not_found) then
258 call messages_write("Cannot open pseudopotential file '"//trim(filename)//"'.")
259 call messages_fatal(namespace=namespace)
260 end if
261
262 if (ps%file_format == pseudo_format_unknown) then
263 call messages_write("Cannot determine the pseudopotential type for species '"//trim(label)//"' from", &
264 new_line = .true.)
265 call messages_write("file '"//trim(filename)//"'.")
266 call messages_fatal(namespace=namespace)
267 end if
268
269 ps%label = label
270 ps%ispin = ispin
271 ps%relativistic_treatment = proj_j_independent
272 ps%projector_type = proj_kb
273 ps%sigma_erf = 0.625_real64 ! This is hard-coded to a reasonable value
274
275 ps%projectors_per_l = 0
276
277 select case (ps%file_format)
279 ps%has_density = .true.
280 case default
281 ps%has_density = .false.
282 end select
283
284 select case (ps%file_format)
285 case (pseudo_format_psf)
286 ps%pseudo_type = pseudo_type_semilocal
287
288 call ps_psf_init(ps_psf, ispin, filename, namespace)
289
290 call valconf_copy(ps%conf, ps_psf%conf)
291 ps%z = z
292 ps%conf%z = nint(z) ! atomic number
293 ps%kbc = 1 ! only one projector per angular momentum
294
295 ps%lmax = ps_psf%ps_grid%no_l_channels - 1
296
297 if (user_lmax /= invalid_l) then
298 ps%lmax = min(ps%lmax, user_lmax) ! Maybe the file does not have enough components.
299 if (user_lmax /= ps%lmax) then
300 message(1) = "lmax in Species block for " // trim(label) // &
301 " is larger than number available in pseudopotential."
302 call messages_fatal(1, namespace=namespace)
303 end if
304 end if
305
306 ps%conf%p = ps_psf%ps_grid%no_l_channels
307 if (ps%lmax == 0) ps%llocal = 0 ! Vanderbilt is not acceptable if ps%lmax == 0.
308
309 ! the local part of the pseudo
310 if (user_llocal == invalid_l) then
311 ps%llocal = 0
312 else
313 ps%llocal = user_llocal
314 end if
315
316 ps%projectors_per_l(1:ps%lmax+1) = 1
317 if (ps%llocal > -1) ps%projectors_per_l(ps%llocal+1) = 0
318
319 call ps_psf_process(ps_psf, namespace, ps%lmax, ps%llocal)
320 call logrid_copy(ps_psf%ps_grid%g, ps%g)
321
323 ps%pseudo_type = pseudo_type_semilocal
324
325 if (ps%file_format == pseudo_format_cpi) then
326 call ps_cpi_init(ps_cpi, trim(filename), namespace)
327 ps%conf%p = ps_cpi%ps_grid%no_l_channels
328 else
329 call ps_fhi_init(ps_fhi, trim(filename), namespace)
330 ps%conf%p = ps_fhi%ps_grid%no_l_channels
331 end if
332
333 ps%conf%z = nint(z)
334 ps%conf%symbol = label(1:2)
335 ps%conf%type = 1
336 do l = 1, ps%conf%p
337 ps%conf%l(l) = l - 1
338 end do
339
340 ps%z = z
341 ps%kbc = 1 ! only one projector per angular momentum
342
343 ps%lmax = ps%conf%p - 1
344
345 if (user_lmax /= invalid_l) then
346 ps%lmax = min(ps%lmax, user_lmax) ! Maybe the file does not have enough components.
347 if (user_lmax /= ps%lmax) then
348 message(1) = "lmax in Species block for " // trim(label) // &
349 " is larger than number available in pseudopotential."
350 call messages_fatal(1, namespace=namespace)
351 end if
352 end if
353
354 if (ps%lmax == 0) ps%llocal = 0 ! Vanderbilt is not acceptable if ps%lmax == 0.
355
356 ! the local part of the pseudo
357 if (user_llocal == invalid_l) then
358 ps%llocal = 0
359 else
360 ps%llocal = user_llocal
361 end if
362
363 ps%projectors_per_l(1:ps%lmax+1) = 1
364 if (ps%llocal > -1) ps%projectors_per_l(ps%llocal+1) = 0
365
366 if (ps%file_format == pseudo_format_cpi) then
367 call ps_cpi_process(ps_cpi, ps%llocal, namespace)
368 call logrid_copy(ps_cpi%ps_grid%g, ps%g)
369 else
370 call ps_fhi_process(ps_fhi, ps%lmax, ps%llocal, namespace)
371 call logrid_copy(ps_fhi%ps_grid%g, ps%g)
372 end if
373
374 case (pseudo_format_hgh)
375 ps%pseudo_type = pseudo_type_kleinman_bylander
376 ps%projector_type = proj_hgh
377
378 call hgh_init(ps_hgh, trim(filename), namespace)
379 call valconf_copy(ps%conf, ps_hgh%conf)
380
381 ps%z = z
382 ps%z_val = ps_hgh%z_val
383 ps%kbc = 3
384 ps%llocal = -1
385 ps%lmax = ps_hgh%l_max
386 ps%conf%symbol = label(1:2)
387 ps%sigma_erf = ps_hgh%rlocal ! We use the correct value
388
389 ps%projectors_per_l(1:ps%lmax+1) = 1
390
391 ! Get the occupations from the valence charge of the atom
392 ps%conf%occ = m_zero
393 ! We impose here non-spin-polarized occupations, to preserve the behavior of the code
394 ! We might want to change this to get a better LCAO guess
395 call ps_guess_atomic_occupations(namespace, ps%z, ps%z_val, 1, ps%conf)
396 ! We need the information to solve the Schrodinder equation
397 call valconf_copy(ps_hgh%conf, ps%conf)
398
399 call hgh_process(ps_hgh, namespace)
400 call logrid_copy(ps_hgh%g, ps%g)
401
402 ! In case of spin-polarized calculations, we properly distribute the electrons
403 if (ispin == 2) then
405 end if
406
407 case (pseudo_format_qso, pseudo_format_upf1, pseudo_format_upf2, pseudo_format_psml, pseudo_format_psp8)
408
409 call ps_xml_init(ps_xml, namespace, trim(filename), ps%file_format, ierr)
410
411 ps%pseudo_type = pseudo_type(ps_xml%pseudo)
412 ps%exchange_functional = pseudo_exchange(ps_xml%pseudo)
413 ps%correlation_functional = pseudo_correlation(ps_xml%pseudo)
414 if (ps%pseudo_type == pseudo_type_ultrasoft .or. ps%pseudo_type == pseudo_type_paw) then
415 ps%projector_type = proj_uspp
416 ! Ultrasoft/PAW projectors and augmentation charges are sharper than norm-conserving
417 ! ones, so the localization sphere must be resolved more tightly to converge the
418 ! augmentation integrals. Use a tighter default threshold unless the user set one.
419 if (.not. parse_is_defined(namespace, 'SpeciesProjectorSphereThreshold')) then
420 ps%projectors_sphere_threshold = 1.0e-4_real64
421 end if
422 if (ps%pseudo_type == pseudo_type_ultrasoft) then
423 call messages_experimental("Ultrasoft pseudopotentials", namespace=namespace)
424 else
425 call messages_experimental("PAW pseudopotentials (reader only; calculations not yet implemented)", &
426 namespace=namespace)
427 end if
428 end if
429
430 ps%z = z
431 ps%conf%z = nint(z)
432
433 if (ps_xml%kleinman_bylander) then
434 ps%conf%p = ps_xml%nwavefunctions
435 else
436 ps%conf%p = ps_xml%lmax + 1
437 end if
438
439 do ll = 0, ps_xml%lmax
440 ps%conf%l(ll + 1) = ll
441 end do
442
443 ps%kbc = ps_xml%nchannels
444 ps%lmax = ps_xml%lmax
445
446 ps%projectors_per_l = 0
447 do ll = 0, ps_xml%lmax
448 ps%projectors_per_l(ll+1) = pseudo_nprojectors_per_l(ps_xml%pseudo, ll)
449 end do
450
451 if (ps_xml%kleinman_bylander) then
452 ps%llocal = ps_xml%llocal
453 else
454 ! we have several options
455 ps%llocal = 0 ! the default
456 if (ps_xml%llocal >= 0) ps%llocal = ps_xml%llocal ! the one given in the pseudopotential file
457 if (user_llocal /= invalid_l) ps%llocal = user_llocal ! user supplied local component
458 assert(ps%llocal >= 0)
459 assert(ps%llocal <= ps%lmax)
460 end if
461
462 ps%g%nrval = ps_xml%grid_size
463
464 safe_allocate(ps%g%rofi(1:ps%g%nrval))
465 safe_allocate(ps%g%r2ofi(1:ps%g%nrval))
466
467 do ii = 1, ps%g%nrval
468 ps%g%rofi(ii) = ps_xml%grid(ii)
469 ps%g%r2ofi(ii) = ps_xml%grid(ii)**2
470 end do
471
472 end select
473
474 ps%local = (ps%lmax == 0 .and. ps%llocal == 0 ) .or. (ps%lmax == -1 .and. ps%llocal == -1)
475
476 ! We allocate all the stuff
477 safe_allocate(ps%kb (0:ps%lmax, 1:ps%kbc))
478 safe_allocate(ps%dkb (0:ps%lmax, 1:ps%kbc))
479 safe_allocate(ps%ur (1:ps%conf%p, 1:ps%ispin))
480 safe_allocate(ps%bound(1:ps%conf%p, 1:ps%ispin))
481 safe_allocate(ps%h (0:ps%lmax, 1:ps%kbc, 1:ps%kbc))
482 safe_allocate(ps%qij (0:ps%lmax, 1:ps%kbc, 1:ps%kbc))
483 safe_allocate(ps%density(1:ps%ispin))
484 safe_allocate(ps%density_der(1:ps%ispin))
485
486 call spline_init(ps%kb)
487 call spline_init(ps%dkb)
488 call spline_init(ps%vl)
489 call spline_init(ps%core)
490 call spline_init(ps%core_der)
491 call spline_init(ps%density)
492 call spline_init(ps%density_der)
493 ps%qij = m_zero
494
495 safe_allocate(eigen(1:ps%conf%p, 1:ps%ispin))
496 eigen = m_zero
497
498 ! Now we load the necessary information.
499 select case (ps%file_format)
500 case (pseudo_format_psf)
501 call ps_psf_get_eigen(ps_psf, eigen)
502 call ps_grid_load(ps, ps_psf%ps_grid)
503 call ps_psf_end(ps_psf)
504 case (pseudo_format_cpi)
505 call ps_grid_load(ps, ps_cpi%ps_grid)
506 call ps_cpi_end(ps_cpi)
507 case (pseudo_format_fhi)
508 call ps_grid_load(ps, ps_fhi%ps_grid)
509 call ps_fhi_end(ps_fhi)
510 case (pseudo_format_hgh)
511 call hgh_get_eigen(ps_hgh, eigen)
512 safe_allocate(ps%k (0:ps%lmax, 1:ps%kbc, 1:ps%kbc))
513 call hgh_load(ps, ps_hgh)
514 call hgh_end(ps_hgh)
515 case (pseudo_format_qso, pseudo_format_upf1, pseudo_format_upf2, pseudo_format_psml, pseudo_format_psp8)
516 call ps_xml_load(ps, ps_xml, namespace)
517 call ps_xml_end(ps_xml)
518 end select
519
520 if (ps_has_density(ps)) then
521 do is = 1, ps%ispin
522 call spline_der(ps%density(is), ps%density_der(is), ps%projectors_sphere_threshold)
523 end do
524 end if
525
526 if (ps_has_nlcc(ps)) then
527 call spline_der(ps%core, ps%core_der, ps%projectors_sphere_threshold)
528 end if
529
530 call ps_check_bound(ps, eigen)
531
532 ps%has_long_range = .true.
533 ps%is_separated = .false.
534
535 call ps_info(ps, filename, namespace)
536
537 safe_deallocate_a(eigen)
538
539 pop_sub(ps_init)
540 end subroutine ps_init
541
542 !------------------------------------------------------------------------
543
544 subroutine ps_info(ps, filename, namespace)
545 type(ps_t), intent(in) :: ps
546 character(len=*), intent(in) :: filename
547 type(namespace_t), intent(in) :: namespace
548
549 call messages_write(" Species '"//trim(ps%label)//"'", new_line = .true.)
550 call messages_write(" type : pseudopotential", new_line = .true.)
551 call messages_write(" file : '"//trim(filename)//"'")
552 call messages_info(namespace=namespace)
553
554 call messages_write(" file format :")
555 select case (ps%file_format)
556 case (pseudo_format_upf1)
557 call messages_write(" UPF1")
558 case (pseudo_format_upf2)
559 call messages_write(" UPF2")
560 case (pseudo_format_qso)
561 call messages_write(" QSO")
562 case (pseudo_format_psml)
563 call messages_write(" PSML")
564 case (pseudo_format_psp8)
565 call messages_write(" PSP8")
566 case (pseudo_format_psf)
567 call messages_write(" PSF")
568 case (pseudo_format_cpi)
569 call messages_write(" CPI")
570 case (pseudo_format_fhi)
571 call messages_write(" FHI")
572 case (pseudo_format_hgh)
573 call messages_write(" HGH")
574 end select
575 call messages_new_line()
576
577 call messages_write(" valence charge :")
578 call messages_write(ps%z_val, align_left = .true., fmt = '(f4.1)')
579 call messages_info(namespace=namespace)
580
581 call messages_write(" atomic number :")
582 call messages_write(nint(ps%z), fmt = '(i4)')
583 call messages_info(namespace=namespace)
584
585 call messages_write(" form on file :")
586 select case (ps%pseudo_type)
588 call messages_write(" ultrasoft")
590 call messages_write(" semilocal")
592 call messages_write(" kleinman-bylander")
593 case (pseudo_type_paw)
594 call messages_write(" paw")
595 end select
596 call messages_info(namespace=namespace)
597
598 if (ps%pseudo_type == pseudo_type_semilocal) then
599 call messages_write(" orbital origin :")
600 select case (ps%file_format)
601 case (pseudo_format_psf)
602 call messages_write(" calculated")
603 case default
604 call messages_write(" from file")
605 end select
606 call messages_info(namespace=namespace)
607 end if
608
609 call messages_write(" lmax :")
610 call messages_write(ps%lmax, fmt = '(i2)')
611 call messages_info(namespace=namespace)
612
613 call messages_write(" llocal :")
614 if (ps%llocal >= 0) then
615 call messages_write(ps%llocal, fmt = '(i2)')
616 else
617 call messages_write(ps%llocal, fmt = '(i3)')
618 end if
619 call messages_info(namespace=namespace)
620
621 call messages_write(" projectors per l :")
622 call messages_write(ps%kbc, fmt = '(i2)')
623 call messages_info(namespace=namespace)
624
625 call messages_write(" total projectors :")
626 if (ps%llocal < 0) then
627 call messages_write(ps%kbc*(ps%lmax + 1), fmt = '(i2)')
628 else
629 call messages_write(ps%kbc*ps%lmax, fmt = '(i2)')
630 end if
631 call messages_info(namespace=namespace)
632
633 if (ps%local) then
634 call messages_write(" application form : local")
635 else
636 call messages_write(" application form : kleinman-bylander")
637 end if
638 call messages_info(namespace=namespace)
639
640 call messages_write(" orbitals :")
641 call messages_write(ps_niwfs(ps), fmt='(i3)')
642 call messages_info(namespace=namespace)
643 call messages_write(" bound orbitals :")
644 call messages_write(ps_bound_niwfs(ps), fmt='(i3)')
645 call messages_info(namespace=namespace)
646
647 call messages_info(namespace=namespace)
648
649 end subroutine ps_info
650
651
652 ! ---------------------------------------------------------
655 subroutine ps_separate(ps)
656 type(ps_t), intent(inout) :: ps
657
658 real(real64), allocatable :: vsr(:), vlr(:), nlr(:)
659 real(real64) :: r, exp_arg, max_val_vsr
660 integer :: ii
661
662 push_sub(ps_separate)
663
664 assert(ps%g%nrval > 0)
665
666 safe_allocate(vsr(1:ps%g%nrval))
667 safe_allocate(vlr(1:ps%g%nrval))
668 safe_allocate(nlr(1:ps%g%nrval))
669
670 ps%no_vl = .false.
671
672 max_val_vsr = m_zero
673
674 do ii = 1, ps%g%nrval
675 r = ps%g%rofi(ii)
676
677 vlr(ii) = long_range_potential(r, ps%sigma_erf, ps%z_val)
678
679 vsr(ii) = spline_eval(ps%vl, r) - vlr(ii)
680 if(abs(vsr(ii)) < 1.0e-14_real64) vsr(ii) = m_zero
681 max_val_vsr = max(max_val_vsr, abs(vsr(ii)))
682
683 exp_arg = -m_half*r**2/ps%sigma_erf**2
684 if (exp_arg > m_min_exp_arg) then
685 nlr(ii) = -ps%z_val/(ps%sigma_erf*sqrt(m_two*m_pi))**3*exp(exp_arg)
686 else
687 nlr(ii) = m_zero
688 end if
689 end do
690
691 call spline_init(ps%vlr)
692 call spline_fit(ps%g%nrval, ps%g%rofi, vlr, ps%vlr, ps%projectors_sphere_threshold)
693
694 call spline_init(ps%nlr)
695 call spline_fit(ps%g%nrval, ps%g%rofi, nlr, ps%nlr, ps%projectors_sphere_threshold)
696
697 !overwrite vl
698 call spline_end(ps%vl)
699 call spline_init(ps%vl)
700 call spline_fit(ps%g%nrval, ps%g%rofi, vsr, ps%vl, ps%projectors_sphere_threshold)
701 if (max_val_vsr < 1.0e-12_real64) ps%no_vl = .true.
702
703 safe_deallocate_a(vsr)
704 safe_deallocate_a(vlr)
705 safe_deallocate_a(nlr)
706
707 ps%is_separated = .true.
708
709 pop_sub(ps_separate)
710 end subroutine ps_separate
711
713 real(real64) pure function long_range_potential(r, sigma, z_val) result(vlr)
714 real(real64), intent(in) :: r, sigma, z_val
715
716 real(real64) :: arg
717
718 arg = r/(sigma*sqrt(m_two))
719 ! Note that the threshold is taken such that the Taylor expansion produces an error smaller than \epsilon
720 ! given a third order Taylor expansion
721 if(arg > 1e-3_real64) then
722 vlr = -z_val * erf(arg) / r
723 else
724 vlr = -z_val * m_two / (sigma*sqrt(m_two*m_pi)) * (m_one - arg**2 / m_three)
725 end if
726 end function long_range_potential
728 ! ---------------------------------------------------------
729 subroutine ps_getradius(ps)
730 type(ps_t), intent(inout) :: ps
731 integer :: l, j
732
733 push_sub(ps_getradius)
734
735 ps%rc_max = m_zero
736
737 do l = 0, ps%lmax
738 if (l == ps%llocal) cycle
739 do j = 1, ps%kbc
740 ps%rc_max = max(ps%rc_max, ps%kb(l, j)%x_threshold)
741 end do
742 end do
743
744 pop_sub(ps_getradius)
745 end subroutine ps_getradius
746
747
748 ! ---------------------------------------------------------
749 subroutine ps_derivatives(ps)
750 type(ps_t), intent(inout) :: ps
751 integer :: l, j
752
753 push_sub(ps_derivatives)
754
755 do l = 0, ps%lmax
756 do j = 1, ps%kbc
757 call spline_der(ps%kb(l, j), ps%dkb(l, j), ps%projectors_sphere_threshold)
758 end do
759 end do
760
761 pop_sub(ps_derivatives)
762 end subroutine ps_derivatives
763
764
765 ! ---------------------------------------------------------
766 subroutine ps_filter(ps, filter, gmax)
767 type(ps_t), intent(inout) :: ps
768 integer, intent(in) :: filter
769 real(real64), intent(in) :: gmax
770
771 integer :: l, k, ispin
772
773 real(real64) :: alpha, beta_fs, rmax, rcut, gamma, beta_rs
774
775 push_sub(ps_filter)
776 call profiling_in("PS_FILTER")
777
778 select case (filter)
779 case (ps_filter_none)
780
781 case (ps_filter_ts)
782 alpha = 1.1_real64
783 gamma = m_two
784
785 if(.not. ps%no_vl) then
786 rmax = ps%vl%x_threshold
787 ! For the special case l=-1, we use l=0 when doing the filtering, but it is not clear this is correct
788 call spline_filter_mask(ps%vl, max(0, ps%llocal), rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
789 end if
790
791 do l = 0, ps%lmax
792 if (l == ps%llocal) cycle
793 do k = 1, ps%kbc
794 call spline_filter_mask(ps%kb(l, k), l, ps%rc_max, gmax, alpha, gamma, ps%projectors_sphere_threshold)
795 end do
796 end do
797
798 if (ps_has_nlcc(ps)) then
799 rmax = ps%core%x_threshold
800 call spline_filter_mask(ps%core, 0, rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
801 end if
802
803 if (ps_has_density(ps)) then
804 do ispin = 1, ps%ispin
805 if (abs(spline_integral(ps%density(ispin))) > 1.0e-12_real64) then
806 rmax = ps%density(ispin)%x_threshold
807 call spline_filter_mask(ps%density(ispin), 0, rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
808 call spline_force_pos(ps%density(ispin), ps%projectors_sphere_threshold)
809 end if
810
811 if (abs(spline_integral(ps%density_der(ispin))) > 1.0e-12_real64) then
812 rmax = ps%density_der(ispin)%x_threshold
813 call spline_filter_mask(ps%density_der(ispin), 0, rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
814 end if
815 end do
816 end if
817
818 case (ps_filter_bsb)
819 alpha = 0.7_real64 ! The original was M_FOUR/7.0_real64
820 beta_fs = 18.0_real64
821 rcut = 2.5_real64
822 beta_rs = 0.4_real64
823
824 ! For the special case l=-1, we use l=0 when doing the filtering, but it is not clear this is correct
825 call spline_filter_bessel(ps%vl, max(0, ps%llocal), gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
826 do l = 0, ps%lmax
827 if (l == ps%llocal) cycle
828 do k = 1, ps%kbc
829 call spline_filter_bessel(ps%kb(l, k), l, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
830 end do
831 end do
832
833 if (ps_has_nlcc(ps)) then
834 call spline_filter_bessel(ps%core, 0, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
835 end if
836
837 if (ps_has_density(ps)) then
838 do ispin = 1, ps%ispin
839 call spline_filter_bessel(ps%density(ispin), 0, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
840 call spline_force_pos(ps%density(ispin), ps%projectors_sphere_threshold)
841 call spline_filter_bessel(ps%density_der(ispin), 0, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
842 end do
843 end if
844
845 end select
846
847 call profiling_out("PS_FILTER")
848 pop_sub(ps_filter)
849 end subroutine ps_filter
850
851 ! ---------------------------------------------------------
852 subroutine ps_check_bound(ps, eigen)
853 type(ps_t), intent(inout) :: ps
854 real(real64), contiguous, intent(in) :: eigen(:,:)
855
856 integer :: i, is, ir
857 real(real64) :: ur1, ur2
858
859 push_sub(ps_check_bound)
860
861 ! Unbound states have positive eigenvalues
862 where(eigen > m_zero)
863 ps%bound = .false.
864 elsewhere
865 ps%bound = .true.
866 end where
867
868 ! We might not have information about the eigenvalues, so we need to check the wavefunctions
869 do i = 1, ps%conf%p
870 do is = 1, ps%ispin
871 if (.not. ps%bound(i, is)) cycle
872
873 do ir = ps%g%nrval, 3, -1
874 ! First we look for the outmost value that is not zero
875 if (abs(spline_eval(ps%ur(i, is), ps%g%rofi(ir))*ps%g%rofi(ir)) > m_zero) then
876 ! Usually bound states have exponentially decaying wavefunctions,
877 ! while unbound states have exponentially diverging
878 ! wavefunctions. Therefore we check if the wavefunctions
879 ! value is increasing with increasing radius. The fact
880 ! that we do not use the wavefunctions outmost value that
881 ! is not zero is on purpose, as some pseudopotential
882 ! generators do funny things with that point.
883 ur1 = spline_eval(ps%ur(i, is), ps%g%rofi(ir-2))*ps%g%rofi(ir-2)
884 ur2 = spline_eval(ps%ur(i, is), ps%g%rofi(ir-1))*ps%g%rofi(ir-1)
885 if ((ur1*ur2 > m_zero) .and. (abs(ur2) > abs(ur1))) ps%bound(i, is) = .false.
886 exit
887 end if
888 end do
889 end do
890 end do
891
892 pop_sub(ps_check_bound)
893 end subroutine ps_check_bound
894
895
896 ! ---------------------------------------------------------
897 subroutine ps_debug(ps, dir, namespace, gmax)
898 type(ps_t), intent(in) :: ps
899 character(len=*), intent(in) :: dir
900 type(namespace_t), intent(in) :: namespace
901 real(real64), intent(in) :: gmax
902
903 ! We will plot also some Fourier transforms.
904 type(spline_t), allocatable :: fw(:, :)
905
906 integer :: iunit
907 integer :: j, k, l
908
909 push_sub(ps_debug)
910
911 ! A text file with some basic data.
912 iunit = io_open(trim(dir)//'/pseudo-info', namespace, action='write')
913 write(iunit,'(a,/)') ps%label
914 write(iunit,'(a,a,/)') 'Format : ', ps_name(ps%file_format)
915 write(iunit,'(a,f6.3)') 'z : ', ps%z
916 write(iunit,'(a,f6.3,/)') 'zval : ', ps%z_val
917 write(iunit,'(a,i4)') 'lmax : ', ps%lmax
918 write(iunit,'(a,i4)') 'lloc : ', ps%llocal
919 write(iunit,'(a,i4,/)') 'kbc : ', ps%kbc
920 write(iunit,'(a,f9.5,/)') 'rcmax : ', ps%rc_max
921 write(iunit,'(a,/)') 'h matrix:'
922 do l = 0, ps%lmax
923 do k = 1, ps%kbc
924 write(iunit,'(10f9.5)') (ps%h(l, k, j), j = 1, ps%kbc)
925 end do
926 end do
927 if (allocated(ps%k)) then
928 write(iunit,'(/,a,/)') 'k matrix:'
929 do l = 0, ps%lmax
930 do k = 1, ps%kbc
931 write(iunit,'(10f9.5)') (ps%k(l, k, j), j = 1, ps%kbc)
932 end do
933 end do
934 end if
935
936 write(iunit,'(/,a)') 'orbitals:'
937 do j = 1, ps%conf%p
938 if (ps%ispin == 2) then
939 write(iunit,'(1x,a,i2,3x,a,i2,3x,a,f5.1,3x,a,l1,3x,a,f5.1,3x,a,f5.1)') 'n = ', ps%conf%n(j), 'l = ', ps%conf%l(j), &
940 'j = ', ps%conf%j(j), 'bound = ', all(ps%bound(j,:)), &
941 'occ(1) = ', ps%conf%occ(j, 1), 'occ(2) = ', ps%conf%occ(j, 2)
942 else
943 write(iunit,'(1x,a,i2,3x,a,i2,3x,a,f5.1,3x,a,l1,3x,a,f5.1)') 'n = ', ps%conf%n(j), 'l = ', ps%conf%l(j), &
944 'j = ', ps%conf%j(j), 'bound = ', all(ps%bound(j,:)), &
945 'occ = ', ps%conf%occ(j, 1)
946 end if
947 end do
948
949
950 call io_close(iunit)
951
952 ! Local part of the pseudopotential
953 iunit = io_open(trim(dir)//'/local', namespace, action='write')
954 call spline_print(ps%vl, iunit)
955 call io_close(iunit)
956
957 ! Local part of the pseudopotential
958 iunit = io_open(trim(dir)//'/local_long_range', namespace, action='write')
959 call spline_print(ps%vlr, iunit)
960 call io_close(iunit)
961
962 ! Local part of the pseudopotential
963 iunit = io_open(trim(dir)//'/local_long_range_density', namespace, action='write')
964 call spline_print(ps%nlr, iunit)
965 call io_close(iunit)
966
967 ! Fourier transform of the local part
968 iunit = io_open(trim(dir)//'/local_ft', namespace, action='write')
969 safe_allocate(fw(1, 1))
970 call spline_init(fw(1, 1))
971 call spline_3dft(ps%vl, fw(1, 1), ps%projectors_sphere_threshold, gmax = gmax)
972 call spline_print(fw(1, 1), iunit)
973 call spline_end(fw(1, 1))
974 safe_deallocate_a(fw)
975 call io_close(iunit)
976
977 ! Kleinman-Bylander projectors
978 iunit = io_open(trim(dir)//'/nonlocal', namespace, action='write')
979 call spline_print(ps%kb, iunit)
980 call io_close(iunit)
981
982 iunit = io_open(trim(dir)//'/nonlocal_derivative', namespace, action='write')
983 call spline_print(ps%dkb, iunit)
984 call io_close(iunit)
985
986 iunit = io_open(trim(dir)//'/nonlocal_ft', namespace, action='write')
987 safe_allocate(fw(0:ps%lmax, 1:ps%kbc))
988 call spline_init(fw)
989 do k = 0, ps%lmax
990 do j = 1, ps%kbc
991 call spline_besselft(ps%kb(k, j), fw(k, j), k, threshold=ps%projectors_sphere_threshold, &
992 gmax=m_four*gmax)
993 end do
994 end do
995 call spline_print(fw, iunit)
996 call spline_end(fw)
997 safe_deallocate_a(fw)
998 call io_close(iunit)
999
1000 ! Pseudo-wavefunctions
1001 iunit = io_open(trim(dir)//'/wavefunctions', namespace, action='write')
1002 call spline_print(ps%ur, iunit)
1003 call io_close(iunit)
1004
1005 ! Density
1006 if (ps%has_density) then
1007 iunit = io_open(trim(dir)//'/density', namespace, action='write')
1008 call spline_print(ps%density, iunit)
1009 call io_close(iunit)
1010
1011 iunit = io_open(trim(dir)//'/density_derivative', namespace, action='write')
1012 call spline_print(ps%density_der, iunit)
1013 call io_close(iunit)
1014 end if
1015
1016 ! Non-linear core-corrections
1017 if (ps_has_nlcc(ps)) then
1018 iunit = io_open(trim(dir)//'/nlcc', namespace, action='write')
1019 call spline_print(ps%core, iunit)
1020 call io_close(iunit)
1021 end if
1022
1023 pop_sub(ps_debug)
1024 end subroutine ps_debug
1025
1026
1027 ! ---------------------------------------------------------
1028 subroutine ps_end(ps)
1029 type(ps_t), intent(inout) :: ps
1030
1031 if (.not. allocated(ps%kb)) return
1032
1033 push_sub(ps_end)
1034
1035 if (ps%is_separated) then
1036 call spline_end(ps%vlr)
1037 call spline_end(ps%nlr)
1038 end if
1039
1040 call spline_end(ps%kb)
1041 call spline_end(ps%dkb)
1042 call spline_end(ps%ur)
1043
1044 call spline_end(ps%vl)
1045 call spline_end(ps%core)
1046 call spline_end(ps%core_der)
1047
1048 if (allocated(ps%density)) call spline_end(ps%density)
1049 if (allocated(ps%density_der)) call spline_end(ps%density_der)
1050 if (allocated(ps%radial_augmentation)) call spline_end(ps%radial_augmentation)
1051
1052 if (ps_is_paw(ps)) then
1053 if (allocated(ps%paw_phi_ae)) call spline_end(ps%paw_phi_ae)
1054 if (allocated(ps%paw_phi_ae_small)) call spline_end(ps%paw_phi_ae_small)
1055 if (allocated(ps%paw_phi_ps)) call spline_end(ps%paw_phi_ps)
1056 ! paw_ae_vlocal is always fitted for a PAW dataset (PP_AE_VLOC is mandatory), whereas the AE core density is optional.
1057 call spline_end(ps%paw_ae_vlocal)
1058 if (ps%paw_has_ae_core) call spline_end(ps%paw_ae_core)
1059 if (allocated(ps%paw_core_orbital)) call spline_end(ps%paw_core_orbital)
1060 end if
1061
1062 call logrid_end(ps%g)
1063
1064 safe_deallocate_a(ps%kb)
1065 safe_deallocate_a(ps%dkb)
1066 safe_deallocate_a(ps%ur)
1067 safe_deallocate_a(ps%bound)
1068 safe_deallocate_a(ps%h)
1069 safe_deallocate_a(ps%qij)
1070 safe_deallocate_a(ps%radial_augmentation)
1071 safe_deallocate_a(ps%k)
1072 safe_deallocate_a(ps%density)
1073 safe_deallocate_a(ps%density_der)
1074 safe_deallocate_a(ps%paw_l)
1075 safe_deallocate_a(ps%paw_phi_ae)
1076 safe_deallocate_a(ps%paw_phi_ae_small)
1077 safe_deallocate_a(ps%paw_phi_ps)
1078 safe_deallocate_a(ps%paw_occ)
1079 safe_deallocate_a(ps%paw_2j)
1080 safe_deallocate_a(ps%paw_core_orbital)
1081 safe_deallocate_a(ps%paw_core_l)
1082 safe_deallocate_a(ps%paw_grid)
1083 safe_deallocate_a(ps%paw_rab)
1084 safe_deallocate_a(ps%paw_multipoles)
1085
1086 pop_sub(ps_end)
1087 end subroutine ps_end
1088
1089
1090 ! ---------------------------------------------------------
1091 subroutine hgh_load(ps, ps_hgh)
1092 type(ps_t), intent(inout) :: ps
1093 type(ps_hgh_t), intent(inout) :: ps_hgh
1094
1095 push_sub(hgh_load)
1096
1097 ! Fixes some components of ps
1098 ps%nlcc = .false.
1099 if (ps%lmax >= 0) then
1100 ps%rc_max = maxval(ps_hgh%kbr(0:ps%lmax))
1101 else
1102 ps%rc_max = m_zero
1103 end if
1104 ps%h(0:ps%lmax, 1:ps%kbc, 1:ps%kbc) = ps_hgh%h(0:ps%lmax, 1:ps%kbc, 1:ps%kbc)
1105 ps%k(0:ps%lmax, 1:ps%kbc, 1:ps%kbc) = ps_hgh%k(0:ps%lmax, 1:ps%kbc, 1:ps%kbc)
1106
1107 ! now we fit the splines
1108 call get_splines()
1109
1110 pop_sub(hgh_load)
1111
1112 contains
1113
1114 ! ---------------------------------------------------------
1115 subroutine get_splines()
1116 integer :: l, is, j, ip
1117 real(real64), allocatable :: hato(:), dens(:)
1118
1119 push_sub(hgh_load.get_splines)
1120
1121 safe_allocate(hato(1:ps_hgh%g%nrval))
1122 safe_allocate(dens(1:ps_hgh%g%nrval))
1123
1124 ! Interpolate the KB-projection functions
1125 do l = 0, ps_hgh%l_max
1126 do j = 1, 3
1127 hato(:) = ps_hgh%kb(:, l, j)
1128 ! Here the function is known on the full support, so we fit it on the full spline
1129 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, hato, ps%kb(l, j), &
1130 ps%projectors_sphere_threshold)
1131 end do
1132 end do
1133
1134 ! Now the part corresponding to the local pseudopotential
1135 ! where the asymptotic part is subtracted
1136 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, ps_hgh%vlocal, ps%vl, ps%projectors_sphere_threshold)
1137
1138 ! Define the table for the pseudo-wavefunction components (using splines)
1139 ! with a correct normalization function
1140 do is = 1, ps%ispin
1141 dens = m_zero
1142 do l = 1, ps%conf%p
1143 hato(2:ps_hgh%g%nrval) = ps_hgh%rphi(2:ps_hgh%g%nrval, l)/ps_hgh%g%rofi(2:ps_hgh%g%nrval)
1144 hato(1) = hato(2)
1145
1146 do ip = 1, ps_hgh%g%nrval
1147 dens(ip) = dens(ip) + ps%conf%occ(l, is)*hato(ip)**2/(m_four*m_pi)
1148 end do
1149
1150 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, hato, ps%ur(l, is), ps%projectors_sphere_threshold)
1151 end do
1152 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, dens, ps%density(is), ps%projectors_sphere_threshold)
1153 end do
1154
1155 safe_deallocate_a(hato)
1156 safe_deallocate_a(dens)
1157
1158 pop_sub(hgh_load.get_splines)
1159 end subroutine get_splines
1160 end subroutine hgh_load
1161
1162
1163 ! ---------------------------------------------------------
1164 subroutine ps_grid_load(ps, ps_grid)
1165 type(ps_t), intent(inout) :: ps
1166 type(ps_in_grid_t), intent(in) :: ps_grid
1167
1168 push_sub(ps_grid_load)
1169
1170 ! Fixes some components of ps, read in ps_grid
1171 ps%z_val = ps_grid%zval
1172
1173 ps%nlcc = ps_grid%core_corrections
1174
1175 ps%h(0:ps%lmax, 1, 1) = ps_grid%dkbcos(1:ps%lmax+1)
1176
1177 ps%rc_max = maxval(ps_grid%kb_radius(1:ps%lmax+1))
1178
1179 ! now we fit the splines
1180 call get_splines(ps_grid%g)
1181
1182 ! Passes from Rydbergs to Hartrees.
1183 ps%h(0:ps%lmax,:,:) = ps%h(0:ps%lmax,:,:) / m_two
1184
1185 pop_sub(ps_grid_load)
1186
1187 contains
1188
1189 subroutine get_splines(g)
1190 type(logrid_t), intent(in) :: g
1191
1192 real(real64), allocatable :: hato(:), dens(:)
1193 integer :: is, l, ir, nrc, ip
1194
1195 push_sub(ps_grid_load.get_splines)
1196
1197 safe_allocate(hato(1:g%nrval))
1198 safe_allocate(dens(1:g%nrval))
1199
1200 ! the wavefunctions
1201 do is = 1, ps%ispin
1202
1203 dens = m_zero
1204
1205 do l = 1, ps_grid%no_l_channels
1206 hato(2:) = ps_grid%rphi(2:, l, 1+is)/g%rofi(2:)
1207 hato(1) = first_point_extrapolate(g%rofi, hato)
1208
1209 if(ps%conf%occ(l, is) > m_epsilon) then
1210 do ip = 1, g%nrval
1211 dens(ip) = dens(ip) + ps%conf%occ(l, is)*hato(ip)**2/(m_four*m_pi)
1212 end do
1213 end if
1214
1215 call spline_fit(g%nrval, g%rofi, hato, ps%ur(l, is), ps%projectors_sphere_threshold)
1216
1217 end do
1218 call spline_fit(g%nrval, g%rofi, dens, ps%density(is), ps%projectors_sphere_threshold)
1219 end do
1220
1221
1222 ! the Kleinman-Bylander projectors
1223 do l = 1, ps%lmax+1
1224 nrc = logrid_index(g, ps_grid%kb_radius(l)) + 1
1225 hato(1:nrc) = ps_grid%KB(1:nrc, l)
1226 hato(nrc+1:g%nrval) = m_zero
1227
1228 nrc = ps_grid%kb_nrval(l) ! Only fit up to the actual cutoff
1229 if (nrc == 0) nrc = g%nrval
1230 call spline_fit(nrc, g%rofi, hato, ps%kb(l-1, 1), ps%projectors_sphere_threshold)
1231 end do
1232
1233 ! Now the part corresponding to the local pseudopotential
1234 ! where the asymptotic part is subtracted
1235 hato(:) = ps_grid%vlocal(:)/m_two
1236 call spline_fit(g%nrval, g%rofi, hato, ps%vl, ps%projectors_sphere_threshold)
1237
1238 if (ps_grid%core_corrections) then
1239 ! find cutoff radius
1240 hato(2:) = ps_grid%chcore(2:)/(m_four*m_pi*g%r2ofi(2:))
1241
1242 do ir = g%nrval-1, 2, -1
1243 if (hato(ir) > eps) then
1244 nrc = ir + 1
1245 exit
1246 end if
1247 end do
1248
1249 hato(nrc:g%nrval) = m_zero
1250 hato(1) = first_point_extrapolate(g%rofi, hato)
1251
1252 call spline_fit(g%nrval, g%rofi, hato, ps%core, ps%projectors_sphere_threshold)
1253 end if
1254
1255 safe_deallocate_a(hato)
1256 safe_deallocate_a(dens)
1257
1258 pop_sub(ps_grid_load.get_splines)
1259 end subroutine get_splines
1260 end subroutine ps_grid_load
1262 ! ---------------------------------------------------------
1266 subroutine ps_xml_load(ps, ps_xml, namespace)
1267 type(ps_t), intent(inout) :: ps
1268 type(ps_xml_t), intent(in) :: ps_xml
1269 type(namespace_t), intent(in) :: namespace
1270
1271 integer :: ll, ip, is, ic, jc, ir, nrc, ii, jj, nproj
1272 real(real64) :: rr, kbcos, kbnorm, dnrm, avgv, volume_element
1273 real(real64), allocatable :: kbprojector(:), wavefunction(:), nlcc_density(:), dens(:,:)
1274 integer, allocatable :: cmap(:, :)
1275 integer, allocatable :: bmap_us(:)
1276 integer :: ib_us, ic_us, jc_us
1277 real(real64), allocatable :: matrix(:, :), eigenvalues(:)
1278 logical :: density_is_known
1279 real(real64), parameter :: tol_diagonal=1.0e-10_real64 ! tolerance for taking d_ij as a diagonal matrix
1280
1281 push_sub(ps_xml_load)
1282
1283 ! Vanderbilt-Kleinman-Bylander, i.e. more than one projector per l. Hamann uses 2 for ONCVPSP.
1284 if (pseudo_has_total_angular_momentum(ps_xml%pseudo)) then
1285 if (ps%file_format == pseudo_format_psp8) then
1286 ps%relativistic_treatment = proj_j_average
1287 message(1) = "SOC from PSP8 is not currently supported."
1288 message(2) = "Only scalar relativistic effects will be considered."
1289 call messages_warning(2, namespace=namespace)
1290 else
1291 ps%relativistic_treatment = proj_j_dependent
1292 end if
1293 end if
1294
1295 ps%nlcc = ps_xml%nlcc
1296
1297 ps%z_val = ps_xml%valence_charge
1298
1299 ps%has_density = ps_xml%has_density
1300
1301 ! We start with the local potential
1302
1303 ! We then fit this by a spline
1304 call spline_fit(ps%g%nrval, ps%g%rofi, ps_xml%potential(:, ps%llocal), ps%vl, ps%projectors_sphere_threshold)
1305
1306 safe_allocate(kbprojector(1:ps%g%nrval))
1307 safe_allocate(wavefunction(1:ps%g%nrval))
1308
1309 kbprojector = m_zero
1310 wavefunction = m_zero
1311
1312 density_is_known = .false.
1313
1314 ! We then proceed with the nonlocal projectors and the orbitals
1315 if (ps_xml%kleinman_bylander) then
1316
1317 safe_allocate(cmap(0:ps_xml%lmax, 1:ps_xml%nchannels))
1318
1319 ! We order the different projectors and create some mappings
1320 ! the order of the channels is determined by spin orbit and the j value
1321 do ll = 0, ps_xml%lmax
1322 do ic = 1, ps_xml%nchannels
1323 cmap(ll, ic) = ic
1324
1325 if (ll == 0) cycle
1326 if (ll == ps_xml%llocal) cycle
1327 if (ps%relativistic_treatment /= proj_j_dependent) cycle
1328 if (ic > pseudo_nprojectors_per_l(ps_xml%pseudo, ll)) cycle ! This occurs for O and F for pseudodojo FR PBE for instance
1329
1330 ! This is Octopus convention:
1331 ! We treat l+1/2 first and l-1/2 after, so we order the projectors this way
1332
1333 assert(mod(ps_xml%nchannels, 2)==0)
1334 if (pseudo_projector_2j(ps_xml%pseudo, ll, ic) == 2*ll - 1) then
1335 cmap(ll, ic) = int((ic-1)/2)*2 + 2
1336 else
1337 assert(pseudo_projector_2j(ps_xml%pseudo, ll, ic) == 2*ll + 1)
1338 cmap(ll, ic) = int((ic-1)/2)*2 + 1
1339 end if
1340
1341 end do
1342
1343 ! check that all numbers are present for each l
1344 assert(sum(cmap(ll, 1:ps_xml%nchannels)) == (ps_xml%nchannels + 1)*ps_xml%nchannels/2)
1345 end do
1346
1347 assert(all(cmap >= 0 .and. cmap <= ps_xml%nchannels))
1348
1349
1350 ! Weight of the projectors. Norm-conserving pseudopotentials keep the
1351 ! historical diagonal representation; ultrasoft projectors keep D_ij.
1352 ps%h = m_zero
1353 ps%qij = m_zero
1355 ! Store the overlap charges q_ij in the same channel order as ps%h (cmap: for
1356 ! fully-relativistic pseudos j = l+1/2 at odd channels). ps_xml%qij is in file order;
1357 ! for non-relativistic pseudos cmap is the identity and this is a plain copy.
1358 do ll = 0, ps_xml%lmax
1359 do ic_us = 1, ps_xml%nchannels
1360 do jc_us = 1, ps_xml%nchannels
1361 ps%qij(ll, cmap(ll, ic_us), cmap(ll, jc_us)) = ps_xml%qij(ll, ic_us, jc_us)
1362 end do
1363 end do
1364 end do
1365 end if
1366
1367 ! Augmentation charge, for ultrasoft pseudopotentials
1368 ps%radial_augmentation_lmax = ps_xml%radial_augmentation_lmax
1369 ps%radial_augmentation_has_angular_channels = ps_xml%radial_augmentation_has_angular_channels
1370
1371 if (ps_xml%has_radial_augmentation) then
1372 nproj = pseudo_nprojectors(ps_xml%pseudo)
1373 ps%radial_augmentation_nprojectors = nproj
1374 assert(ps%radial_augmentation_lmax >= 0)
1375 if (.not. ps%radial_augmentation_has_angular_channels) then
1376 call messages_not_implemented("ultrasoft augmentation density without angular-resolved Q_ij^L functions")
1377 end if
1378
1379 safe_allocate(ps%radial_augmentation(1:nproj*nproj, 0:ps%radial_augmentation_lmax))
1380 call spline_init(ps%radial_augmentation)
1381
1382 ! Global beta map, file order -> cmap (octopus) channel order, per l block, so the
1383 ! augmentation pair indexing matches ps%h / ps%qij / the projector channel counting.
1384 safe_allocate(bmap_us(1:nproj))
1385 ib_us = 0
1386 do ll = 0, ps_xml%lmax
1387 if (ll == ps_xml%llocal) cycle
1388 do ic_us = 1, pseudo_nprojectors_per_l(ps_xml%pseudo, ll)
1389 ib_us = ib_us + 1
1390 bmap_us(ib_us) = ib_us - ic_us + cmap(ll, ic_us)
1391 end do
1392 end do
1393 assert(ib_us == nproj)
1394
1395 do ii = 1, nproj
1396 do jj = 1, nproj
1397 do ll = 0, ps%radial_augmentation_lmax
1398 call spline_fit(ps_xml%grid_size, ps%g%rofi, ps_xml%radial_augmentation(:, ii, jj, ll), &
1399 ps%radial_augmentation((bmap_us(ii) - 1)*nproj + bmap_us(jj), ll), ps%projectors_sphere_threshold)
1400 end do
1401 end do
1402 end do
1403 safe_deallocate_a(bmap_us)
1404
1405 end if
1406
1407 ! We now take the matrix dij and we diagonalize it
1408 ! The nonlocal projectors are changed accordingly, and then fitted by splines
1409 if (pseudo_nprojectors(ps_xml%pseudo) > 0) then
1410 safe_allocate(matrix(1:ps_xml%nchannels, 1:ps_xml%nchannels))
1411 safe_allocate(eigenvalues(1:ps_xml%nchannels))
1412
1413 do ll = 0, ps_xml%lmax
1414
1416 do ic = 1, ps_xml%nchannels
1417 ! Only fit up to the actual cutoff
1418 call spline_fit(ps_xml%kb_radius(ll, ic), ps%g%rofi, ps_xml%projector(:, ll, ic), &
1419 ps%kb(ll, cmap(ll, ic)), ps%projectors_sphere_threshold)
1420 do jc = 1, ps_xml%nchannels
1421 ps%h(ll, cmap(ll, ic), cmap(ll, jc)) = ps_xml%dij(ll, ic, jc)
1422 end do
1423 end do
1424 else if (is_diagonal(ps_xml%nchannels, ps_xml%dij(ll, :, :), tol_diagonal) .or. &
1425 pseudo_has_total_angular_momentum(ps_xml%pseudo)) then
1426 do ic = 1, ps_xml%nchannels
1427 ! Only fit up to the actual cutoff
1428 call spline_fit(ps_xml%kb_radius(ll, ic), ps%g%rofi, ps_xml%projector(:, ll, ic), &
1429 ps%kb(ll, cmap(ll, ic)), ps%projectors_sphere_threshold)
1430 ps%h(ll, cmap(ll, ic), cmap(ll, ic)) = ps_xml%dij(ll, ic, ic)
1431 end do
1432 else
1433 ! diagonalize the coefficient matrix
1434 matrix(1:ps_xml%nchannels, 1:ps_xml%nchannels) = ps_xml%dij(ll, 1:ps_xml%nchannels, 1:ps_xml%nchannels)
1435 call lalg_eigensolve(ps_xml%nchannels, matrix, eigenvalues)
1436
1437 do ic = 1, ps_xml%nchannels
1438 kbprojector = m_zero
1439 do jc = 1, ps_xml%nchannels
1440 call lalg_axpy(ps_xml%grid_size, matrix(jc, ic), ps_xml%projector(:, ll, jc), kbprojector)
1441 end do
1442
1443 call spline_fit(maxval(ps_xml%kb_radius(ll, :)), ps%g%rofi, kbprojector, &
1444 ps%kb(ll, cmap(ll, ic)), ps%projectors_sphere_threshold)
1445 ps%h(ll, cmap(ll, ic), cmap(ll, ic)) = eigenvalues(ic)
1446 end do
1447 end if
1448 end do
1449
1450 safe_deallocate_a(matrix)
1451 safe_deallocate_a(eigenvalues)
1452 end if
1453
1454 ps%conf%p = ps_xml%nwavefunctions
1455
1456 ! If we do not have a density but we have wavefunctions, we compute the
1457 ! pseudo-atomic density, from the pseudo-atomic wavefunctions
1458 ! In case we are doing a spin-polarized calculation, it is better to use the
1459 ! wavefunctions with spin-dependent occupations, instead the spin unresolved density
1460 ! given in the pseudopotential
1461 if ((.not. ps_has_density(ps) .or. ps%ispin == 2) .and. ps_xml%nwavefunctions > 0) then
1462 safe_allocate(dens(1:ps%g%nrval, 1:ps%ispin))
1463 dens = m_zero
1464 end if
1465
1466 do ii = 1, ps_xml%nwavefunctions
1467
1468 ps%conf%n(ii) = ps_xml%wf_n(ii)
1469 ps%conf%l(ii) = ps_xml%wf_l(ii)
1470
1471 if (ps%ispin == 2) then
1472 ps%conf%occ(ii, 1) = min(ps_xml%wf_occ(ii), m_two*ps_xml%wf_l(ii) + m_one)
1473 ps%conf%occ(ii, 2) = ps_xml%wf_occ(ii) - ps%conf%occ(ii, 1)
1474 else
1475 ps%conf%occ(ii, 1) = ps_xml%wf_occ(ii)
1476 end if
1477
1478 ps%conf%j(ii) = m_zero
1479 if (pseudo_has_total_angular_momentum(ps_xml%pseudo)) then
1480 ps%conf%j(ii) = m_half*pseudo_wavefunction_2j(ps_xml%pseudo, ii)
1481 end if
1482
1483 do ip = 1, ps%g%nrval
1484 if (ip <= ps_xml%grid_size) then
1485 wavefunction(ip) = ps_xml%wavefunction(ip, ii)
1486 else
1487 wavefunction(ip) = m_zero
1488 end if
1489 end do
1490
1491 do is = 1, ps%ispin
1492 call spline_fit(ps%g%nrval, ps%g%rofi, wavefunction, ps%ur(ii, is), ps%projectors_sphere_threshold)
1493 end do
1494
1495 if (.not. ps_has_density(ps) .or. ps%ispin == 2) then
1496 do is = 1, ps%ispin
1497 do ip = 1, ps_xml%grid_size
1498 dens(ip, is) = dens(ip, is) + ps%conf%occ(ii, is)*wavefunction(ip)**2/(m_four*m_pi)
1499 end do
1500 end do
1501 end if
1502
1503 end do
1504
1505 !If we assigned all the valence electrons, we can compute the (spin-resolved) atomic density
1506 if ((.not. ps_has_density(ps) .or. ps%ispin == 2) .and. ps_xml%nwavefunctions > 0) then
1507 do is = 1, ps%ispin
1508 call spline_fit(ps%g%nrval, ps%g%rofi, dens(:,is), ps%density(is), ps%projectors_sphere_threshold)
1509 end do
1510 safe_deallocate_a(dens)
1511 density_is_known = .true.
1512 ps%has_density = .true.
1513 end if
1514
1515 safe_deallocate_a(cmap)
1516
1517 else !Not ps_xml%kleinman_bylander
1518
1519 !Get the occupations from the valence charge of the atom
1520 ps%conf%occ = m_zero
1521 ps%conf%symbol = ps%label(1:2)
1522 call ps_guess_atomic_occupations(namespace, ps%z, ps%z_val, ps%ispin, ps%conf)
1523
1524 ! In order to work in the following, we need to sort the occupations by angular momentum
1525 call valconf_sort_by_l(ps%conf, ps_xml%lmax)
1526
1527 !If we assigned all the valence electrons, we can compute the (spin-resolved) atomic density
1528 if (abs(sum(ps%conf%occ) - ps%z_val ) < m_epsilon) then
1529 safe_allocate(dens(1:ps%g%nrval, 1:ps%ispin))
1530 dens = m_zero
1531 end if
1532
1533 do ll = 0, ps_xml%lmax
1534 ! we need to build the KB projectors
1535 ! the procedure was copied from ps_in_grid.F90 (r12967)
1536 dnrm = m_zero
1537 avgv = m_zero
1538 do ip = 1, ps_xml%grid_size
1539 rr = ps_xml%grid(ip)
1540 volume_element = rr**2*ps_xml%weights(ip)
1541 kbprojector(ip) = (ps_xml%potential(ip, ll) - ps_xml%potential(ip, ps%llocal))*ps_xml%wavefunction(ip, ll)
1542 dnrm = dnrm + kbprojector(ip)**2*volume_element
1543 avgv = avgv + kbprojector(ip)*ps_xml%wavefunction(ip, ll)*volume_element
1544 end do
1545
1546 kbcos = dnrm/(safe_tol(avgv,1.0e-20_real64))
1547 kbnorm = m_one/(safe_tol(sqrt(dnrm),1.0e-20_real64))
1548
1549 if (ll /= ps%llocal) then
1550 ps%h(ll, 1, 1) = kbcos
1551 kbprojector = kbprojector*kbnorm
1552 else
1553 ps%h(ll, 1, 1) = m_zero
1554 end if
1555
1556 call spline_fit(ps%g%nrval, ps%g%rofi, kbprojector, ps%kb(ll, 1), ps%projectors_sphere_threshold)
1557
1558 ! wavefunctions, for the moment we pad them with zero
1559 call lalg_copy(ps_xml%grid_size, ps_xml%wavefunction(:, ll), wavefunction)
1560 wavefunction(ps_xml%grid_size+1:ps%g%nrval) = m_zero
1561
1562 do is = 1, ps%ispin
1563 call spline_fit(ps%g%nrval, ps%g%rofi, wavefunction, ps%ur(ll + 1, is), ps%projectors_sphere_threshold)
1564 end do
1565
1566 !If we assigned all the valence electrons, we can compute the (spin-resolved) atomic density
1567 if (abs(sum(ps%conf%occ) - ps%z_val) < m_epsilon) then
1568 do is = 1, ps%ispin
1569 do ip = 1, ps_xml%grid_size
1570 dens(ip, is) = dens(ip, is) + ps%conf%occ(ll+1, is)*wavefunction(ip)**2/(m_four*m_pi)
1571 end do
1572 end do
1573 end if
1574 end do
1575
1576 !If we assigned all the valence electrons, we can compute the (spin-resolved) atomic density
1577 if (abs(sum(ps%conf%occ) - ps%z_val) < m_epsilon) then
1578 do is = 1, ps%ispin
1579 call spline_fit(ps%g%nrval, ps%g%rofi, dens(:,is), ps%density(is), ps%projectors_sphere_threshold)
1580 end do
1581 safe_deallocate_a(dens)
1582 density_is_known = .true.
1583 ps%has_density = .true.
1584 end if
1585 end if ! ps_xml%kleinman_bylander
1586
1587
1588 if (ps_has_density(ps) .and. .not. density_is_known) then
1589
1590 safe_allocate(dens(1:ps%g%nrval, 1))
1591
1592 dens(1:ps_xml%grid_size, 1) = ps_xml%density(1:ps_xml%grid_size)/ps%ispin
1593 dens(ps_xml%grid_size + 1:ps%g%nrval, 1) = m_zero
1594
1595 do is = 1, ps%ispin
1596 call spline_fit(ps%g%nrval, ps%g%rofi, dens(:, 1), ps%density(is), ps%projectors_sphere_threshold)
1597 end do
1598
1599 safe_deallocate_a(dens)
1600 end if
1601
1602 ! Non-linear core-corrections
1603 ! We truncate the NLCC when below eps
1604 if (ps_xml%nlcc) then
1605
1606 safe_allocate(nlcc_density(1:ps%g%nrval))
1607
1608 call lalg_copy(ps_xml%grid_size, ps_xml%nlcc_density, nlcc_density)
1609
1610 ! find cutoff radius
1611 do ir = ps_xml%grid_size - 1, 1, -1
1612 if (nlcc_density(ir) > eps) then
1613 nrc = ir + 1
1614 exit
1615 end if
1616 end do
1617
1618 nlcc_density(nrc:ps%g%nrval) = m_zero
1619
1620 call spline_fit(ps%g%nrval, ps%g%rofi, nlcc_density, ps%core, ps%projectors_sphere_threshold)
1621
1622 safe_deallocate_a(nlcc_density)
1623 end if
1624
1625 ! PAW-specific data: store the AE/PS partial waves, AE core density, AE local
1626 ! potential, occupations and multipole moments.
1627 if (ps_xml%is_paw) then
1628 nproj = pseudo_nprojectors(ps_xml%pseudo)
1629 ps%paw_nwavefunctions = ps_xml%paw_nwavefunctions
1630 ps%paw_augmentation_lmax = ps_xml%paw_augmentation_lmax
1631 ps%paw_shape = ps_xml%paw_shape
1632 ps%paw_core_energy = ps_xml%paw_core_energy
1633 ps%paw_cutoff_radius = ps_xml%paw_cutoff_radius
1634 ps%paw_has_ae_core = ps_xml%paw_has_ae_core
1635
1636 safe_allocate(ps%paw_l(1:nproj))
1637 ps%paw_l(1:nproj) = ps_xml%paw_l(1:nproj)
1638
1639 safe_allocate(ps%paw_phi_ae(1:nproj))
1640 safe_allocate(ps%paw_phi_ps(1:nproj))
1641 call spline_init(ps%paw_phi_ae)
1642 call spline_init(ps%paw_phi_ps)
1643 do ii = 1, nproj
1644 call spline_fit(ps%g%nrval, ps%g%rofi, ps_xml%paw_phi_ae(:, ii), ps%paw_phi_ae(ii), &
1645 ps%projectors_sphere_threshold)
1646 call spline_fit(ps%g%nrval, ps%g%rofi, ps_xml%paw_phi_ps(:, ii), ps%paw_phi_ps(ii), &
1647 ps%projectors_sphere_threshold)
1648 end do
1649
1650 ! Fully-relativistic datasets: small component of the AE partial waves, needed to
1651 ! complete the one-center AE densities (the PS waves have no small component).
1652 ps%paw_has_small = ps_xml%paw_has_small
1653 if (ps%paw_has_small) then
1654 safe_allocate(ps%paw_phi_ae_small(1:nproj))
1655 call spline_init(ps%paw_phi_ae_small)
1656 do ii = 1, nproj
1657 call spline_fit(ps%g%nrval, ps%g%rofi, ps_xml%paw_phi_ae_small(:, ii), ps%paw_phi_ae_small(ii), &
1658 ps%projectors_sphere_threshold)
1659 end do
1660 end if
1661
1662 call spline_init(ps%paw_ae_vlocal)
1663 call spline_fit(ps%g%nrval, ps%g%rofi, ps_xml%paw_ae_vlocal(:), ps%paw_ae_vlocal, &
1664 ps%projectors_sphere_threshold)
1665
1666 if (ps%paw_has_ae_core) then
1667 call spline_init(ps%paw_ae_core)
1668 call spline_fit(ps%g%nrval, ps%g%rofi, ps_xml%paw_ae_core(:), ps%paw_ae_core, &
1669 ps%projectors_sphere_threshold)
1670 end if
1671
1672 safe_allocate(ps%paw_occ(1:nproj))
1673 ps%paw_occ(1:nproj) = ps_xml%paw_occ(1:nproj)
1674
1675 ! j of each partial wave (2j, file order): the partial waves pair with the beta
1676 ! projectors in file order, so the projector j applies. Zero for scalar datasets.
1677 safe_allocate(ps%paw_2j(1:nproj))
1678 ps%paw_2j = 0
1679 if (ps%relativistic_treatment == proj_j_dependent) then
1680 do ii = 1, nproj
1681 ic = 0
1682 do jj = 1, ii
1683 if (ps%paw_l(jj) == ps%paw_l(ii)) ic = ic + 1
1684 end do
1685 ps%paw_2j(ii) = pseudo_projector_2j(ps_xml%pseudo, ps%paw_l(ii), ic)
1686 end do
1687 end if
1688
1689 ! Frozen-core orbitals (for the meta-GGA core kinetic-energy density). Absent
1690 ! (paw_ncore == 0) for hydrogen-like datasets with no core.
1691 ps%paw_ncore = ps_xml%paw_ncore
1692 if (ps%paw_ncore > 0) then
1693 safe_allocate(ps%paw_core_orbital(1:ps%paw_ncore))
1694 call spline_init(ps%paw_core_orbital)
1695 safe_allocate(ps%paw_core_l(1:ps%paw_ncore))
1696 do ii = 1, ps%paw_ncore
1697 call spline_fit(ps%g%nrval, ps%g%rofi, ps_xml%paw_core_orbital(:, ii), &
1698 ps%paw_core_orbital(ii), ps%projectors_sphere_threshold)
1699 ps%paw_core_l(ii) = ps_xml%paw_core_l(ii)
1700 end do
1701 end if
1702
1703 safe_allocate(ps%paw_multipoles(1:nproj, 1:nproj, 0:ps%paw_augmentation_lmax))
1704 ps%paw_multipoles = ps_xml%paw_multipoles
1705
1706 ! Persist the native radial grid and its integration weights (PP_RAB), which
1707 ! the one-center engine needs to reproduce the dataset reference integrals.
1708 safe_allocate(ps%paw_grid(1:ps%g%nrval))
1709 safe_allocate(ps%paw_rab(1:ps%g%nrval))
1710 ps%paw_grid(1:ps%g%nrval) = ps%g%rofi(1:ps%g%nrval)
1711 ps%paw_rab(1:ps%g%nrval) = ps_xml%weights(1:ps%g%nrval)
1712 end if
1713
1714 call ps_getradius(ps)
1715
1716 safe_deallocate_a(kbprojector)
1717 safe_deallocate_a(wavefunction)
1718
1719 pop_sub(ps_xml_load)
1720 end subroutine ps_xml_load
1721
1722
1723 ! ---------------------------------------------------------
1725 pure integer function ps_niwfs(ps)
1726 type(ps_t), intent(in) :: ps
1727
1728 integer :: i, l
1729
1730 ps_niwfs = 0
1731 do i = 1, ps%conf%p
1732 l = ps%conf%l(i)
1733 ps_niwfs = ps_niwfs + (2*l+1)
1734 end do
1735
1736 end function ps_niwfs
1737
1738 ! ---------------------------------------------------------
1740 pure integer function ps_bound_niwfs(ps)
1741 type(ps_t), intent(in) :: ps
1742
1743 integer :: i, l
1744
1745 ps_bound_niwfs = 0
1746 do i = 1, ps%conf%p
1747 l = ps%conf%l(i)
1748 if (any(.not. ps%bound(i,:))) cycle
1749 ps_bound_niwfs = ps_bound_niwfs + (2*l+1)
1750 end do
1751
1752 end function ps_bound_niwfs
1753
1754 !---------------------------------------
1755
1756 pure logical function ps_has_density(ps) result(has_density)
1757 type(ps_t), intent(in) :: ps
1758
1759 has_density = ps%has_density
1760
1761 end function ps_has_density
1762
1763 !---------------------------------------
1764
1765 pure logical function ps_has_nlcc(ps) result(has_nlcc)
1766 type(ps_t), intent(in) :: ps
1767
1768 has_nlcc = ps%nlcc
1769
1770 end function ps_has_nlcc
1771
1772 !---------------------------------------
1773 pure logical function ps_is_ultrasoft(ps) result(is_ultrasoft)
1774 type(ps_t), intent(in) :: ps
1775
1776 is_ultrasoft = (ps%pseudo_type == pseudo_type_ultrasoft)
1777
1778 end function ps_is_ultrasoft
1779
1780 !---------------------------------------
1781 pure logical function ps_is_paw(ps) result(is_paw)
1782 type(ps_t), intent(in) :: ps
1783
1784 is_paw = (ps%pseudo_type == pseudo_type_paw)
1785
1786 end function ps_is_paw
1787
1788 !---------------------------------------
1789 pure logical function ps_requires_generalized_overlap(ps) result(requires_generalized_overlap)
1790 type(ps_t), intent(in) :: ps
1791
1792 requires_generalized_overlap = ps_is_ultrasoft(ps) .or. (ps%pseudo_type == pseudo_type_paw)
1793
1795
1796 !---------------------------------------
1797 real(real64) function ps_density_volume(ps, namespace) result(volume)
1798 type(ps_t), intent(in) :: ps
1799 type(namespace_t), intent(in) :: namespace
1800
1801 integer :: ip, ispin
1802 real(real64) :: rr
1803 real(real64), allocatable ::vol(:)
1804 type(spline_t) :: volspl
1805
1806 push_sub(ps_density_volume)
1807
1808 if (.not. ps_has_density(ps)) then
1809 message(1) = "The pseudopotential does not contain an atomic density"
1810 call messages_fatal(1, namespace=namespace)
1811 end if
1813 safe_allocate(vol(1:ps%g%nrval))
1814
1815 do ip = 1, ps%g%nrval
1816 rr = ps%g%rofi(ip)
1817 vol(ip) = m_zero
1818 do ispin = 1, ps%ispin
1819 vol(ip) = vol(ip) + spline_eval(ps%density(ispin), rr)*m_four*m_pi*rr**5
1820 end do
1821 end do
1822
1823 call spline_init(volspl)
1824 call spline_fit(ps%g%nrval, ps%g%rofi, vol, volspl, ps%projectors_sphere_threshold)
1825 volume = spline_integral(volspl)
1826 call spline_end(volspl)
1827
1828 safe_deallocate_a(vol)
1829
1830 pop_sub(ps_density_volume)
1831 end function ps_density_volume
1832
1836 subroutine ps_guess_atomic_occupations(namespace, zz, valcharge, ispin, conf)
1837 type(namespace_t), intent(in) :: namespace
1838 real(real64), intent(in) :: zz
1839 real(real64), intent(in) :: valcharge
1840 integer, intent(in) :: ispin
1841 type(valconf_t), intent(inout) :: conf
1842
1843 real(real64) :: val
1844
1846
1847 val = valcharge
1848 conf%p = 0
1849 conf%l = 0
1850 conf%j = m_zero
1851 conf%n = 0
1852
1853 write(message(1), '(a,a,a)') 'Debug: Guessing the atomic occupations for ', trim(conf%symbol), "."
1854 call messages_info(1, namespace=namespace, debug_only=.true.)
1855
1856 assert(valcharge <= zz)
1857
1858 ! Here we populate the core states
1859 ! 1s state for all atoms after He
1860 if(int(zz) > 2 .and. val > zz - 2) then
1861 call fill_s_orbs(val, 2, 1)
1862 end if
1863 ! 2s state for all atoms after Be
1864 if(int(zz) > 4 .and. val > zz - 4) then
1865 call fill_s_orbs(val, 2, 2)
1866 end if
1867 ! 2p state for all atoms after Ne
1868 ! For pseudopotentials Al-Ar, we fill the 2s but not the 2p
1869 if(int(zz) > 18 .and. val > zz - 10) then
1870 call fill_p_orbs(val, 6, 2)
1871 end if
1872 ! 3s state for all atoms after Mg
1873 if(int(zz) > 12 .and. val > zz - 12) then
1874 call fill_s_orbs(val, 2, 3)
1875 end if
1876 ! 3p state for all atoms after Ar
1877 if(int(zz) > 18 .and. val > zz - 18) then
1878 call fill_p_orbs(val, 6, 3)
1879 end if
1880 ! 3d states for all atoms after Ni
1881 if(int(zz) > 28 .and. val > zz - 28) then
1882 call fill_d_orbs(val, 10, 3)
1883 end if
1884 ! 4s states for all atoms after Zn
1885 if(int(zz) > 30 .and. val > zz - 30) then
1886 call fill_s_orbs(val, 2, 4)
1887 end if
1888 ! 4p states for all atoms after Kr
1889 if(int(zz) > 36 .and. val > zz - 36) then
1890 call fill_p_orbs(val, 6, 4)
1891 end if
1892 ! 4d states for all atoms after Pd
1893 if(int(zz) > 46 .and. val > zz - 46) then
1894 call fill_d_orbs(val, 10, 4)
1895 end if
1896 ! 5s states for all atoms after Cd
1897 ! For Z=71 ot Z=80, the 4f is filled before the 5s/5p
1898 if((int(zz) > 48 .and. val > zz - 48) .or. &
1899 (int(zz) > 70 .and. int(zz) <= 81 .and. val > zz - 62)) then
1900 call fill_s_orbs(val, 2, 5)
1901 end if
1902 ! 5p states for all atoms after Xe
1903 ! For Z=71 ot Z=80, the 4f is filled before the 5s/5p
1904 if((int(zz) > 54 .and. val > zz - 54) .or. &
1905 (int(zz) > 70 .and. int(zz) <= 81 .and. val > zz - 68) ) then
1906 call fill_p_orbs(val, 6, 5)
1907 end if
1908 ! 4f states for all atoms after Yb
1909 ! Only after Z=80 for pseudopotentials
1910 if(int(zz) > 80 .and. val > zz - 68) then
1911 call fill_f_orbs(val, 14, 4)
1912 end if
1913
1914
1915 ! We leave here the valence states
1916 select case (int(zz))
1917 case (1)
1918 call fill_s_orbs(val, 1, 1) ! H 1s^1
1919 case (2)
1920 call fill_s_orbs(val, 2, 1) ! He 1s^2
1921 case (3)
1922 call fill_s_orbs(val, 1, 2) ! Li 1s^2 2s^1
1923 case (4)
1924 call fill_s_orbs(val, 2, 2) ! Be 1s^2 ; 2s^2
1925 case (5)
1926 call fill_p_orbs(val, 1, 2) ! B 1s^2 ; 2s^2 2p^1
1927 case (6)
1928 call fill_p_orbs(val, 2, 2) ! C 1s^2 ; 2s^2 2p^2
1929 case (7)
1930 call fill_p_orbs(val, 3, 2) ! N 1s^2 ; 2s^2 2
1931 case (8)
1932 call fill_p_orbs(val, 4, 2) ! O 1s^2 ; 2s^2 2p^4
1933 case (9)
1934 call fill_p_orbs(val, 5, 2) ! F 1s^2 ; 2s^2 2p^5
1935 case (10)
1936 call fill_p_orbs(val, 6, 2) ! Ne 1s^2 ; 2s^2 2p^6
1937 case (11)
1938 if(val > 6) call fill_p_orbs(val, 6, 2)
1939 call fill_s_orbs(val, 1, 3) ! Na 1s^2 2s^2 2p^6 ; 3s^1
1940 case (12)
1941 if(val > 6) call fill_p_orbs(val, 6, 2)
1942 call fill_s_orbs(val, 2, 3) ! Mg 1s^2 2s^2 2p^6 ; 3s^2
1943 case (13)
1944 if(val > 6) call fill_p_orbs(val, 6, 2)
1945 call fill_p_orbs(val, 1, 3) ! Al 1s^2 2s^2 2p^6 ; 3s^2 3p^1
1946 case (14)
1947 if(val > 6) call fill_p_orbs(val, 6, 2)
1948 call fill_p_orbs(val, 2, 3) ! Si 1s^2 2s^2 2p^6 ; 3s^2 3p^2
1949 case (15)
1950 if(val > 6) call fill_p_orbs(val, 6, 2)
1951 call fill_p_orbs(val, 3, 3) ! P 1s^2 2s^2 2p^6 ; 3s^2 3p^3
1952 case (16)
1953 if(val > 6) call fill_p_orbs(val, 6, 2)
1954 call fill_p_orbs(val, 4, 3) ! S 1s^2 2s^2 2p^6 ; 3s^2 3p^4
1955 case (17)
1956 if(val > 6) call fill_p_orbs(val, 6, 2)
1957 call fill_p_orbs(val, 5, 3) ! Cl 1s^2 2s^2 2p^6 ; 3s^2 3p^5
1958 case (18)
1959 if(val > 6) call fill_p_orbs(val, 6, 2)
1960 call fill_p_orbs(val, 6, 3) ! Ar 1s^2 2s^2 2p^6 ; 3s^2 3p^6
1961 case (19)
1962 call fill_s_orbs(val, 1, 4) ! K 1s^2 2s^2 2p^6 3s^2 3p^6 ; 4s^1
1963 case (20)
1964 call fill_s_orbs(val, 2, 4) ! Ca 1s^2 2s^2 2p^6 3s^2 3p^6 ; 4s^2
1965 case (21)
1966 if (val > 1) call fill_s_orbs(val, 2, 4)
1967 call fill_d_orbs(val, 1, 3) ! Sc 1s^2 2s^2 2p^6 3s^2 3p^6 ; 4s^2 3d^1
1968 case (22)
1969 if (val > 2) call fill_s_orbs(val, 2, 4)
1970 call fill_d_orbs(val, 2, 3) ! Ti 1s^2 2s^2 2p^6 3s^2 3p^6 ; 4s^2 3d^2
1971 case (23)
1972 if (val > 3) call fill_s_orbs(val, 2, 4)
1973 call fill_d_orbs(val, 3, 3) ! V 1s^2 2s^2 2p^6 3s^2 3p^6 ; 4s^2 3d^3
1974 case (24)
1975 if (val > 4) call fill_s_orbs(val, 2, 4)
1976 call fill_d_orbs(val, 4, 3) ! Cr 1s^2 2s^2 2p^6 3s^2 3p^6 ; 4s^2 3d^4
1977 case (25)
1978 if (val > 5) call fill_s_orbs(val, 2, 4)
1979 call fill_d_orbs(val, 5, 3) ! Mn 1s^2 2s^2 2p^6 3s^2 3p^6 ; 4s^2 3d^5
1980 case (26)
1981 if (val > 6) call fill_s_orbs(val, 2, 4)
1982 call fill_d_orbs(val, 6, 3) ! Fe 1s^2 2s^2 2p^6 3s^2 3p^6 ; 4s^2 3d^6
1983 case (27)
1984 if (val > 7) call fill_s_orbs(val, 2, 4)
1985 call fill_d_orbs(val, 7, 3) ! Co 1s^2 2s^2 2p^6 3s^2 3p^6 ; 4s^2 3d^7
1986 case (28)
1987 if (val > 8 ) call fill_s_orbs(val, 2, 4)
1988 call fill_d_orbs(val, 8, 3) ! Ni 1s^2 2s^2 2p^6 3s^2 3p^6 ; 4s^2 3d^8
1989 case (29)
1990 call fill_s_orbs(val, 1, 4) ! Cu 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 ; 4s^1
1991 case (30)
1992 call fill_s_orbs(val, 2, 4) ! Zn 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 ; 4s^2
1993 case (31)
1994 call fill_p_orbs(val, 1, 4) ! Ga 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 ; 4s^2 4p^1
1995 case (32)
1996 call fill_p_orbs(val, 2, 4) ! Ge 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 ; 4s^2 4p^2
1997 case (33)
1998 call fill_p_orbs(val, 3, 4) ! As 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 ; 4s^2 4p^3
1999 case (34)
2000 call fill_p_orbs(val, 4, 4) ! Se 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 ; 4s^2 4p^4
2001 case (35)
2002 call fill_p_orbs(val, 5, 4) ! Br 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 ; 4s^2 4p^5
2003 case (36)
2004 call fill_p_orbs(val, 6, 4) ! Kr 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 ; 4s^2 4p^6
2005 case (37)
2006 call fill_s_orbs(val, 1, 5) ! Rb 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 ; 5s^1
2007 case (38)
2008 call fill_s_orbs(val, 2, 5) ! Sr 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 ; 5s^2
2009 case (39)
2010 if (val > 2) call fill_d_orbs(val, 1, 4)
2011 call fill_s_orbs(val, 2, 5) ! Y 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 ; 4d^1 5s^2
2012 case (40)
2013 if (val > 2) call fill_d_orbs(val, 2, 4)
2014 call fill_s_orbs(val, 2, 5) ! Zr 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 ; 4d^2 5s^2
2015 case (41)
2016 if (val > 1) call fill_d_orbs(val, 4, 4)
2017 call fill_s_orbs(val, 1, 5) ! Nb 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 ; 4d^4 5s^1
2018 case (42)
2019 if (val > 1) call fill_d_orbs(val, 5, 4)
2020 call fill_s_orbs(val, 1, 5) ! Mo 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 ; 4d^5 5s^1
2021 case (43)
2022 if (val > 2) call fill_d_orbs(val, 5, 4)
2023 call fill_s_orbs(val, 2, 5) ! Tc 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 ; 4d^5 5s^2
2024 case (44)
2025 if (val > 1) call fill_d_orbs(val, 7, 4)
2026 call fill_s_orbs(val, 1, 5) ! Ru 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 ; 4d^7 5s^1
2027 case (45)
2028 if (val > 1) call fill_d_orbs(val, 8, 4)
2029 call fill_s_orbs(val, 1, 5) ! Rh 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 ; 4d^8 5s^1
2030 case (46)
2031 call fill_d_orbs(val, 10, 4) ! Pd 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 ; 4d^10
2032 case (47)
2033 call fill_s_orbs(val, 1, 5) ! Ag 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 ; 5s^1
2034 case (48)
2035 call fill_s_orbs(val, 2, 5) ! Cd 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 ; 5s^2
2036 case (49)
2037 call fill_p_orbs(val, 1, 5) ! In 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 ; 5s^2 5p^1
2038 case (50)
2039 call fill_p_orbs(val, 2, 5) ! Sn 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 ; 5s^2 5p^2
2040 case (51)
2041 call fill_p_orbs(val, 3, 5) ! Sb 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 ; 5s^2 5p^3
2042 case (52)
2043 call fill_p_orbs(val, 4, 5) ! Te 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 ; 5s^2 5p^4
2044 case (53)
2045 call fill_p_orbs(val, 5, 5) ! I 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 ; 5s^2 5p^5
2046 case (54)
2047 call fill_p_orbs(val, 6, 5) ! Xe 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 ; 5s^2 5p^6
2048 case (55)
2049 call fill_s_orbs(val, 1, 6) ! Cs 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 6s^1
2050 case (56)
2051 call fill_s_orbs(val, 2, 6) ! Ba 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 6s^2
2052 case (57)
2053 if (val > 2) call fill_d_orbs(val, 1, 5)
2054 call fill_s_orbs(val, 2, 6) ! La 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 5d^1 6s^2
2055 case (58)
2056 if (val > 3) call fill_f_orbs(val, 1, 4)
2057 if (val > 2) call fill_d_orbs(val, 1, 5)
2058 call fill_s_orbs(val, 2, 6) ! Ce 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^1 5d^1 6s^2
2059 case (59)
2060 if (val > 2) call fill_f_orbs(val, 3, 4)
2061 call fill_s_orbs(val, 2, 6) ! Pr 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^3 6s^2
2062 case (60)
2063 if (val > 2) call fill_f_orbs(val, 4, 4)
2064 call fill_s_orbs(val, 2, 6) ! Nd 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^4 6s^2
2065 case (61)
2066 if (val > 2) call fill_f_orbs(val, 5, 4)
2067 call fill_s_orbs(val, 2, 6) ! Pm 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^5 6s^2
2068 case (62)
2069 if (val > 2) call fill_f_orbs(val, 6, 4)
2070 call fill_s_orbs(val, 2, 6) ! Sm 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^6 6s^2
2071 case (63)
2072 if (val > 2) call fill_f_orbs(val, 7, 4)
2073 call fill_s_orbs(val, 2, 6) ! Eu 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^7 6s^2
2074 case (64)
2075 if (val > 3) call fill_f_orbs(val, 7, 4)
2076 if (val > 2) call fill_d_orbs(val, 1, 5)
2077 call fill_s_orbs(val, 2, 6) ! Gd 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^7 5d^1 6s^2
2078 case (65)
2079 if (val > 2) call fill_f_orbs(val, 9, 4)
2080 call fill_s_orbs(val, 2, 6) ! Tb 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^9 6s^2
2081 case (66)
2082 if (val > 2) call fill_f_orbs(val, 10, 4)
2083 call fill_s_orbs(val, 2, 6) ! Dy 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^10 6s^2
2084 case (67)
2085 if (val > 2) call fill_f_orbs(val, 11, 4)
2086 call fill_s_orbs(val, 2, 6) ! Ho 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^11 6s^2
2087 case (68)
2088 if (val > 2) call fill_f_orbs(val, 12, 4)
2089 call fill_s_orbs(val, 2, 6) ! Er 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^12 6s^2
2090 case (69)
2091 if (val > 2) call fill_f_orbs(val, 13, 4)
2092 call fill_s_orbs(val, 2, 6) ! Tm 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^13 6s^2
2093 case (70)
2094 if (val > 2) call fill_f_orbs(val, 14, 4)
2095 call fill_s_orbs(val, 2, 6) ! Yb 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 ; 4f^14 6s^2
2096 case (71)
2097 if (val > 3) call fill_f_orbs(val, 14, 4)
2098 if (val > 2) call fill_d_orbs(val, 1, 5)
2099 call fill_s_orbs(val, 2, 6) ! Lu 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 ; 5d^1 6s^2
2100 case (72)
2101 if (val > 4) call fill_f_orbs(val, 14, 4)
2102 if (val > 2) call fill_d_orbs(val, 2, 5)
2103 call fill_s_orbs(val, 2, 6) ! Hf 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 ; 5d^2 6s^2
2104 case (73)
2105 if (val > 5) call fill_f_orbs(val, 14, 4)
2106 if (val > 2) call fill_d_orbs(val, 3, 5)
2107 call fill_s_orbs(val, 2, 6) ! Ta 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 ; 5d^3 6s^2
2108 case (74)
2109 if (val > 6) call fill_f_orbs(val, 14, 4)
2110 if (val > 2) call fill_d_orbs(val, 4, 5)
2111 call fill_s_orbs(val, 2, 6) ! W 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 ; 5d^4 6s^2
2112 case (75)
2113 if (val > 7) call fill_f_orbs(val, 14, 4)
2114 if (val > 2) call fill_d_orbs(val, 5, 5)
2115 call fill_s_orbs(val, 2, 6) ! Re 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 ; 5d^5 6s^2
2116 case (76)
2117 if (val > 8) call fill_f_orbs(val, 14, 4)
2118 if (val > 2) call fill_d_orbs(val, 6, 5)
2119 call fill_s_orbs(val, 2, 6) ! Os 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 ; 5d^6 6s^2
2120 case (77)
2121 if (val > 9) call fill_f_orbs(val, 14, 4)
2122 if (val > 2) call fill_d_orbs(val, 7, 5)
2123 call fill_s_orbs(val, 2, 6) ! Ir 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 ; 5d^7 6s^2
2124 case (78)
2125 if (val > 10) call fill_f_orbs(val, 14, 4)
2126 if (val > 1) call fill_d_orbs(val, 9, 5)
2127 call fill_s_orbs(val, 1, 6) ! Pt 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 ; 5d^9 6s^1
2128 case (79)
2129 if (val > 21) call fill_f_orbs(val, 14, 4)
2130 if (val > 1) call fill_d_orbs(val, 10, 5)
2131 call fill_s_orbs(val, 1, 6) ! Au 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 ; 6s^1
2132 case (80)
2133 if (val > 12) call fill_f_orbs(val, 14, 4)
2134 if (val > 2) call fill_d_orbs(val, 10, 5)
2135 call fill_s_orbs(val, 2, 6) ! Hg 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 ; 6s^2
2136 case (81)
2137 if (val > 10) call fill_d_orbs(val, 10, 5)
2138 if (val > 1) call fill_s_orbs(val, 2, 6)
2139 call fill_p_orbs(val, 1, 6) ! Tl 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 ; 6s^2 6p^1
2140 case (82)
2141 if (val > 10) call fill_d_orbs(val, 10, 5)
2142 if (val > 2) call fill_s_orbs(val, 2, 6)
2143 call fill_p_orbs(val, 2, 6) ! Pb 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 ; 6s^2 6p^2
2144 case (83)
2145 if (val > 10) call fill_d_orbs(val, 10, 5)
2146 if (val > 3) call fill_s_orbs(val, 2, 6)
2147 call fill_p_orbs(val, 3, 6) ! Bi 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 ; 6s^2 6p^3
2148 case (84)
2149 if (val > 10) call fill_d_orbs(val, 10, 5)
2150 if (val > 4) call fill_s_orbs(val, 2, 6)
2151 call fill_p_orbs(val, 4, 6) ! Po 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 ; 6s^2 6p^4
2152 case (85)
2153 if (val > 10) call fill_d_orbs(val, 10, 5)
2154 if (val > 5) call fill_s_orbs(val, 2, 6)
2155 call fill_p_orbs(val, 5, 6) ! At 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 ; 6s^2 6p^5
2156 case (86)
2157 if (val > 10) call fill_d_orbs(val, 10, 5)
2158 if (val > 6) call fill_s_orbs(val, 2, 6)
2159 call fill_p_orbs(val, 6, 6) ! Rn 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 ; 6s^2 6p^6
2160 case (87)
2161 if (val > 1) call fill_p_orbs(val, 6, 6)
2162 call fill_s_orbs(val, 1, 7) ! Fr 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 7s1
2163 case (88)
2164 if (val > 2) call fill_p_orbs(val, 6, 6)
2165 call fill_s_orbs(val, 2, 7) ! Ra 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 7s1
2166 case (89)
2167 if (val > 3) call fill_p_orbs(val, 6, 6)
2168 if (val > 2) call fill_d_orbs(val, 1, 6)
2169 call fill_s_orbs(val, 2, 7) ! Ac 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 6d1 7s2
2170 case (90)
2171 if (val > 4) call fill_p_orbs(val, 6, 6)
2172 if (val > 2) call fill_d_orbs(val, 2, 6)
2173 call fill_s_orbs(val, 2, 7) ! Th 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 6d2 7s2
2174 case (91)
2175 if (val > 5) call fill_p_orbs(val, 6, 6)
2176 if (val > 3) call fill_f_orbs(val, 2, 5)
2177 if (val > 2) call fill_d_orbs(val, 1, 6)
2178 call fill_s_orbs(val, 2, 7) ! Pa 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f2 6d1 7s2
2179 case (92)
2180 if (val > 6) call fill_p_orbs(val, 6, 6)
2181 if (val > 3) call fill_f_orbs(val, 3, 5)
2182 if (val > 2) call fill_d_orbs(val, 1, 6)
2183 call fill_s_orbs(val, 2, 7) ! U 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f3 6d1 7s2
2184 case (93)
2185 if (val > 7) call fill_p_orbs(val, 6, 6)
2186 if (val > 3) call fill_f_orbs(val, 4, 5)
2187 if (val > 2) call fill_d_orbs(val, 1, 6)
2188 call fill_s_orbs(val, 2, 7) ! Np 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f4 6d1 7s2
2189 case (94)
2190 if (val > 8) call fill_p_orbs(val, 6, 6)
2191 if (val > 2) call fill_f_orbs(val, 6, 5)
2192 call fill_s_orbs(val, 2, 7) ! Pu 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f6 7s2
2193 case (95)
2194 if (val > 9) call fill_p_orbs(val, 6, 6)
2195 if (val > 2) call fill_f_orbs(val, 7, 5)
2196 call fill_s_orbs(val, 2, 7) ! Am 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f7 7s2
2197 case (96)
2198 if (val > 10) call fill_p_orbs(val, 6, 6)
2199 if (val > 3) call fill_f_orbs(val, 7, 5)
2200 if (val > 2) call fill_d_orbs(val, 1, 6)
2201 call fill_s_orbs(val, 2, 7) ! Cm 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f7 6d1 7s2
2202 case (97)
2203 if (val > 11) call fill_p_orbs(val, 6, 6)
2204 if (val > 2) call fill_f_orbs(val, 9, 5)
2205 call fill_s_orbs(val, 2, 7) ! Bk 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f9 7s2
2206 case (98)
2207 if (val > 12) call fill_p_orbs(val, 6, 6)
2208 if (val > 2) call fill_f_orbs(val, 10, 5)
2209 call fill_s_orbs(val, 2, 7) ! Cf 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f10 7s2
2210 case (99)
2211 if (val > 13) call fill_p_orbs(val, 6, 6)
2212 if (val > 2) call fill_f_orbs(val, 11, 5)
2213 call fill_s_orbs(val, 2, 7) ! Es 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f11 7s2
2214 case (100)
2215 if (val > 14) call fill_p_orbs(val, 6, 6)
2216 if (val > 2) call fill_f_orbs(val, 12, 5)
2217 call fill_s_orbs(val, 2, 7) ! Fm 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f12 7s2
2218 case (101)
2219 if (val > 15) call fill_p_orbs(val, 6, 6)
2220 if (val > 2) call fill_f_orbs(val, 13, 5)
2221 call fill_s_orbs(val, 2, 7) ! Md 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f13 7s2
2222 case (102)
2223 if (val > 16) call fill_p_orbs(val, 6, 6)
2224 if (val > 2) call fill_f_orbs(val, 14, 5)
2225 call fill_s_orbs(val, 2, 7) ! No 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f14 7s2
2226 case (103)
2227 if (val > 3) call fill_f_orbs(val, 14, 5)
2228 if (val > 1) call fill_s_orbs(val, 2, 7)
2229 call fill_p_orbs(val, 1, 7) ! Lr 1s^2 2s^2 2p^6 3s^2 3p^6 3d^10 4s^2 4p^6 4d^10 5s^2 5p^6 4f^14 5d^10 6s^2 6p^6 ; 5f14 7s2 7p1
2230 end select
2231
2232 !If we attributed all the electrons, everything went fine
2233 if (val < m_epsilon) then
2234 !In case of spin-polarized calculations, we properly distribute the electrons
2235 if (ispin == 2) then
2236 call valconf_unpolarized_to_polarized(conf)
2237 end if
2238 else
2239 conf%occ = m_zero
2240 message(1) = "Error in attributing atomic occupations"
2241 call messages_warning(1, namespace=namespace)
2242 end if
2243
2245
2246 contains
2247 subroutine fill_s_orbs(val, max_occ, nn)
2248 real(real64), intent(inout) :: val
2249 integer, intent(in) :: max_occ, nn
2250
2251 conf%p = conf%p + 1
2252 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2253 val = val - conf%occ(conf%p,1)
2254 conf%l(conf%p) = 0
2255 conf%n(conf%p) = nn
2256 end subroutine fill_s_orbs
2257
2258 subroutine fill_p_orbs(val, max_occ, nn)
2259 real(real64), intent(inout) :: val
2260 integer, intent(in) :: max_occ, nn
2261
2262 conf%p = conf%p + 1
2263 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2264 val = val - conf%occ(conf%p,1)
2265 conf%l(conf%p) = 1
2266 conf%n(conf%p) = nn
2267 end subroutine fill_p_orbs
2268
2269 subroutine fill_d_orbs(val, max_occ, nn)
2270 real(real64), intent(inout) :: val
2271 integer, intent(in) :: max_occ, nn
2272
2273 conf%p = conf%p + 1
2274 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2275 val = val - conf%occ(conf%p,1)
2276 conf%l(conf%p) = 2
2277 conf%n(conf%p) = nn
2278 end subroutine fill_d_orbs
2279
2280 subroutine fill_f_orbs(val, max_occ, nn)
2281 real(real64), intent(inout) :: val
2282 integer, intent(in) :: max_occ, nn
2283
2284 conf%p = conf%p + 1
2285 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2286 val = val - conf%occ(conf%p,1)
2287 conf%l(conf%p) = 3
2288 conf%n(conf%p) = nn
2289 end subroutine fill_f_orbs
2290
2291 end subroutine ps_guess_atomic_occupations
2292
2293#include "ps_pspio_inc.F90"
2294
2295end module ps_oct_m
2296
2297!! Local Variables:
2298!! mode: f90
2299!! coding: utf-8
2300!! End:
Some operations may be done for one spline-function, or for an array of them.
Definition: splines.F90:304
double exp(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
subroutine, public valconf_unpolarized_to_polarized(conf)
Definition: atomic.F90:190
subroutine, public valconf_copy(cout, cin)
Definition: atomic.F90:146
real(real64), parameter, public m_two
Definition: global.F90:175
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:171
real(real64), parameter, public m_min_exp_arg
Definition: global.F90:192
real(real64), parameter, public m_half
Definition: global.F90:179
real(real64), parameter, public m_one
Definition: global.F90:174
real(real64), parameter, public m_three
Definition: global.F90:176
Definition: io.F90:93
subroutine, public logrid_copy(grid_in, grid_out)
Definition: logrid.F90:209
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:980
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
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:671
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1020
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:440
/* 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_cpi_end(ps_cpi)
Definition: ps_cpi.F90:162
subroutine, public ps_cpi_init(ps_cpi, filename, namespace)
Definition: ps_cpi.F90:127
subroutine, public ps_cpi_process(ps_cpi, lloc, namespace)
Definition: ps_cpi.F90:200
subroutine, public ps_fhi_end(ps_fhi)
Definition: ps_fhi.F90:162
subroutine, public ps_fhi_init(ps_fhi, filename, namespace)
Definition: ps_fhi.F90:128
subroutine, public ps_fhi_process(ps_fhi, lmax, lloc, namespace)
Definition: ps_fhi.F90:181
subroutine, public hgh_end(psp)
Definition: ps_hgh.F90:207
subroutine, public hgh_get_eigen(psp, eigen)
Definition: ps_hgh.F90:268
subroutine, public hgh_process(psp, namespace)
Definition: ps_hgh.F90:226
subroutine, public hgh_init(psp, filename, namespace)
Definition: ps_hgh.F90:162
Definition: ps.F90:93
pure logical function, public ps_requires_generalized_overlap(ps)
Definition: ps.F90:1862
pure logical function, public ps_has_density(ps)
Definition: ps.F90:1829
integer, parameter, public ps_filter_ts
Definition: ps.F90:146
subroutine, public ps_end(ps)
Definition: ps.F90:1101
subroutine hgh_load(ps, ps_hgh)
Definition: ps.F90:1164
subroutine, public ps_init(ps, namespace, label, z, user_lmax, user_llocal, ispin, filename)
Definition: ps.F90:276
subroutine ps_info(ps, filename, namespace)
Definition: ps.F90:617
subroutine, public ps_separate(ps)
Separate the local potential into (soft) long-ranged and (hard) short-ranged parts.
Definition: ps.F90:728
subroutine ps_check_bound(ps, eigen)
Definition: ps.F90:925
subroutine ps_grid_load(ps, ps_grid)
Definition: ps.F90:1237
subroutine, public ps_debug(ps, dir, namespace, gmax)
Definition: ps.F90:970
real(real64) pure function, public long_range_potential(r, sigma, z_val)
Evaluate the long-range potential at a given distance.
Definition: ps.F90:786
integer, parameter, public proj_hgh
Definition: ps.F90:151
pure integer function, public ps_bound_niwfs(ps)
Returns the number of bound atomic orbitals taking into account then m quantum number multiplicity.
Definition: ps.F90:1813
real(real64), parameter eps
Cutoff for determining the radius of the NLCC.
Definition: ps.F90:269
subroutine, public ps_getradius(ps)
Definition: ps.F90:802
subroutine, public ps_guess_atomic_occupations(namespace, zz, valcharge, ispin, conf)
This routines provides, given Z and the number of valence electron the occupations of the orbitals....
Definition: ps.F90:1909
pure logical function, public ps_is_paw(ps)
Definition: ps.F90:1854
pure logical function, public ps_has_nlcc(ps)
Definition: ps.F90:1838
pure integer function, public ps_niwfs(ps)
Returns the number of atomic orbitals taking into account then m quantum number multiplicity.
Definition: ps.F90:1798
subroutine, public ps_pspio_init(ps, namespace, label, z, lmax, ispin, filename)
Definition: ps.F90:2386
integer, parameter, public ps_filter_none
Definition: ps.F90:146
integer, parameter, public proj_j_average
Fully-relativistic pseudopotentials with separate j-average and SOC terms.
Definition: ps.F90:158
integer, parameter, public proj_uspp
Definition: ps.F90:151
integer, parameter, public proj_rkb
Definition: ps.F90:151
integer, parameter, public proj_j_dependent
Fully-relativistic j-dependent pseudopotentials.
Definition: ps.F90:158
subroutine, public ps_derivatives(ps)
Definition: ps.F90:822
subroutine, public ps_filter(ps, filter, gmax)
Definition: ps.F90:839
pure logical function, public ps_is_ultrasoft(ps)
Definition: ps.F90:1846
real(real64) function, public ps_density_volume(ps, namespace)
Definition: ps.F90:1870
character(len=4), dimension(pseudo_format_upf1:pseudo_format_psp8), parameter ps_name
Definition: ps.F90:165
integer, parameter, public ps_filter_bsb
Definition: ps.F90:146
integer, parameter, public proj_kb
Definition: ps.F90:151
subroutine ps_xml_load(ps, ps_xml, namespace)
Loads XML files for QSO, UPF1, UPF2, PSML, and PSP8 formats.
Definition: ps.F90:1339
subroutine, public ps_psf_init(pstm, ispin, filename, namespace)
Definition: ps_psf.F90:130
subroutine, public ps_psf_process(ps_psf, namespace, lmax, lloc)
Definition: ps_psf.F90:280
subroutine, public ps_psf_get_eigen(ps_psf, eigen)
Definition: ps_psf.F90:314
subroutine, public ps_psf_end(ps_psf)
Definition: ps_psf.F90:181
subroutine, public ps_xml_end(this)
Definition: ps_xml.F90:468
subroutine, public ps_xml_init(this, namespace, filename, fmt, ierr)
Definition: ps_xml.F90:171
integer, parameter, public pseudo_format_file_not_found
Definition: pseudo.F90:177
integer, parameter, public pseudo_type_kleinman_bylander
Definition: pseudo.F90:162
integer, parameter, public pseudo_format_qso
Definition: pseudo.F90:177
integer, parameter, public pseudo_format_hgh
Definition: pseudo.F90:177
integer, parameter, public pseudo_format_upf2
Definition: pseudo.F90:177
integer, parameter, public pseudo_type_paw
Definition: pseudo.F90:162
integer, parameter, public pseudo_format_cpi
Definition: pseudo.F90:177
integer, parameter, public pseudo_exchange_unknown
Definition: pseudo.F90:192
integer, parameter, public pseudo_type_semilocal
Definition: pseudo.F90:162
integer, parameter, public pseudo_type_ultrasoft
Definition: pseudo.F90:162
integer, parameter, public pseudo_correlation_unknown
Definition: pseudo.F90:196
integer, parameter, public pseudo_format_psf
Definition: pseudo.F90:177
integer, parameter, public pseudo_format_fhi
Definition: pseudo.F90:177
integer, parameter, public pseudo_format_unknown
Definition: pseudo.F90:177
integer, parameter, public pseudo_paw_shape_unknown
Definition: pseudo.F90:201
integer, parameter, public pseudo_format_psml
Definition: pseudo.F90:177
subroutine, public spline_der(spl, dspl, threshold)
Definition: splines.F90:1024
subroutine, public spline_fit(nrc, rofi, ffit, spl, threshold)
Definition: splines.F90:550
real(real64) function, public spline_eval(spl, x)
Definition: splines.F90:578
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
subroutine fill_s_orbs(val, max_occ, nn)
Definition: ps.F90:2320
subroutine fill_p_orbs(val, max_occ, nn)
Definition: ps.F90:2331
subroutine fill_d_orbs(val, max_occ, nn)
Definition: ps.F90:2342
subroutine get_splines()
Definition: ps.F90:1188
subroutine fill_f_orbs(val, max_occ, nn)
Definition: ps.F90:2353
remember that the FHI format is basically the CPI format with a header
Definition: ps_fhi.F90:116
The following data type contains: (a) the pseudopotential parameters, as read from a *....
Definition: ps_hgh.F90:123
A type storing the information and data about a pseudopotential.
Definition: ps.F90:169
the basic spline datatype
Definition: splines.F90:281
int true(void)