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