26 use,
intrinsic :: iso_fortran_env
71 integer,
parameter,
public :: &
76 integer,
public,
parameter :: &
82 integer,
public,
parameter :: &
83 PROJ_J_INDEPENDENT = 0, & !< Non-relativisitic or scalar-relativistic pseudopotentials
87 integer,
parameter,
public :: INVALID_L = 333
89 character(len=4),
parameter :: ps_name(PSEUDO_FORMAT_UPF1:PSEUDO_FORMAT_PSP8) = &
90 (/
"upf1",
"upf2",
"qso ",
"psml",
"psf ",
"cpi ",
"fhi ",
"hgh ",
"psp8"/)
95 integer :: projector_type
96 integer :: relativistic_treatment
99 character(len=10),
private :: label
101 integer,
private :: ispin
103 real(real64),
private :: z
104 real(real64) :: z_val
105 type(valconf_t) :: conf
107 type(logrid_t),
private :: g
109 type(spline_t),
allocatable :: ur(:, :)
110 logical,
allocatable :: bound(:, :)
117 logical :: no_vl = .false.
119 real(real64) :: projectors_sphere_threshold
126 real(real64) :: rc_max
129 integer :: projectors_per_l(5)
130 real(real64),
allocatable :: h(:,:,:), k(:, :, :)
131 type(spline_t),
allocatable :: kb(:, :)
132 type(spline_t),
allocatable :: dkb(:, :)
135 type(spline_t) :: core
136 type(spline_t) :: core_der
141 logical,
private :: has_long_range
142 logical,
private :: is_separated
144 type(spline_t),
private :: vlr
145 type(spline_t) :: nlr
147 real(real64) :: sigma_erf
149 logical,
private :: has_density
150 type(spline_t),
allocatable :: density(:)
151 type(spline_t),
allocatable :: density_der(:)
154 integer :: file_format
155 integer,
private :: pseudo_type
156 integer :: exchange_functional
157 integer :: correlation_functional
160 real(real64),
parameter :: eps = 1.0e-8_real64
166 subroutine ps_init(ps, namespace, label, z, user_lmax, user_llocal, ispin, filename)
167 type(
ps_t),
intent(out) :: ps
169 character(len=10),
intent(in) :: label
170 integer,
intent(in) :: user_lmax
171 integer,
intent(in) :: user_llocal
172 integer,
intent(in) :: ispin
173 real(real64),
intent(in) :: z
174 character(len=*),
intent(in) :: filename
176 integer :: l, ii, ll, is, ierr
182 real(real64),
allocatable :: eigen(:, :)
210 call parse_variable(namespace,
'SpeciesProjectorSphereThreshold', 0.001_real64, ps%projectors_sphere_threshold)
216 call messages_write(
"Cannot open pseudopotential file '"//trim(filename)//
"'.")
221 call messages_write(
"Cannot determine the pseudopotential type for species '"//trim(label)//
"' from", &
229 ps%relativistic_treatment = proj_j_independent
231 ps%sigma_erf = 0.625_real64
233 ps%projectors_per_l = 0
235 select case (ps%file_format)
239 ps%has_density = .false.
242 select case (ps%file_format)
253 ps%lmax = ps_psf%ps_grid%no_l_channels - 1
255 if (user_lmax /= invalid_l)
then
256 ps%lmax = min(ps%lmax, user_lmax)
257 if (user_lmax /= ps%lmax)
then
258 message(1) =
"lmax in Species block for " // trim(label) // &
259 " is larger than number available in pseudopotential."
264 ps%conf%p = ps_psf%ps_grid%no_l_channels
265 if (ps%lmax == 0) ps%llocal = 0
268 if (user_llocal == invalid_l)
then
271 ps%llocal = user_llocal
274 ps%projectors_per_l(1:ps%lmax+1) = 1
275 if (ps%llocal > -1) ps%projectors_per_l(ps%llocal+1) = 0
284 call ps_cpi_init(ps_cpi, trim(filename), namespace)
285 ps%conf%p = ps_cpi%ps_grid%no_l_channels
287 call ps_fhi_init(ps_fhi, trim(filename), namespace)
288 ps%conf%p = ps_fhi%ps_grid%no_l_channels
292 ps%conf%symbol = label(1:2)
301 ps%lmax = ps%conf%p - 1
303 if (user_lmax /= invalid_l)
then
304 ps%lmax = min(ps%lmax, user_lmax)
305 if (user_lmax /= ps%lmax)
then
306 message(1) =
"lmax in Species block for " // trim(label) // &
307 " is larger than number available in pseudopotential."
312 if (ps%lmax == 0) ps%llocal = 0
315 if (user_llocal == invalid_l)
then
318 ps%llocal = user_llocal
321 ps%projectors_per_l(1:ps%lmax+1) = 1
322 if (ps%llocal > -1) ps%projectors_per_l(ps%llocal+1) = 0
336 call hgh_init(ps_hgh, trim(filename), namespace)
340 ps%z_val = ps_hgh%z_val
343 ps%lmax = ps_hgh%l_max
344 ps%conf%symbol = label(1:2)
345 ps%sigma_erf = ps_hgh%rlocal
347 ps%projectors_per_l(1:ps%lmax+1) = 1
367 call ps_xml_init(ps_xml, namespace, trim(filename), ps%file_format, ierr)
376 if (ps_xml%kleinman_bylander)
then
377 ps%conf%p = ps_xml%nwavefunctions
379 ps%conf%p = ps_xml%lmax + 1
382 do ll = 0, ps_xml%lmax
383 ps%conf%l(ll + 1) = ll
386 ps%kbc = ps_xml%nchannels
387 ps%lmax = ps_xml%lmax
389 ps%projectors_per_l = 0
390 do ll = 0, ps_xml%lmax
394 if (ps_xml%kleinman_bylander)
then
395 ps%llocal = ps_xml%llocal
399 if (ps_xml%llocal >= 0) ps%llocal = ps_xml%llocal
400 if (user_llocal /= invalid_l) ps%llocal = user_llocal
401 assert(ps%llocal >= 0)
402 assert(ps%llocal <= ps%lmax)
405 ps%g%nrval = ps_xml%grid_size
407 safe_allocate(ps%g%rofi(1:ps%g%nrval))
408 safe_allocate(ps%g%r2ofi(1:ps%g%nrval))
410 do ii = 1, ps%g%nrval
411 ps%g%rofi(ii) = ps_xml%grid(ii)
412 ps%g%r2ofi(ii) = ps_xml%grid(ii)**2
417 ps%local = (ps%lmax == 0 .and. ps%llocal == 0 ) .or. (ps%lmax == -1 .and. ps%llocal == -1)
420 safe_allocate(ps%kb (0:ps%lmax, 1:ps%kbc))
421 safe_allocate(ps%dkb (0:ps%lmax, 1:ps%kbc))
422 safe_allocate(ps%ur (1:ps%conf%p, 1:ps%ispin))
423 safe_allocate(ps%bound(1:ps%conf%p, 1:ps%ispin))
424 safe_allocate(ps%h (0:ps%lmax, 1:ps%kbc, 1:ps%kbc))
425 safe_allocate(ps%density(1:ps%ispin))
426 safe_allocate(ps%density_der(1:ps%ispin))
436 safe_allocate(eigen(1:ps%conf%p, 1:ps%ispin))
440 select case (ps%file_format)
453 safe_allocate(ps%k (0:ps%lmax, 1:ps%kbc, 1:ps%kbc))
463 call spline_der(ps%density(is), ps%density_der(is), ps%projectors_sphere_threshold)
468 call spline_der(ps%core, ps%core_der, ps%projectors_sphere_threshold)
473 ps%has_long_range = .
true.
474 ps%is_separated = .false.
476 call ps_info(ps, filename, namespace)
478 safe_deallocate_a(eigen)
485 subroutine ps_info(ps, filename, namespace)
486 type(
ps_t),
intent(in) :: ps
487 character(len=*),
intent(in) :: filename
496 select case (ps%file_format)
497 case (pseudo_format_upf1)
505 case (pseudo_format_psp8)
527 select case (ps%pseudo_type)
541 select case (ps%file_format)
555 if (ps%llocal >= 0)
then
567 if (ps%llocal < 0)
then
597 type(
ps_t),
intent(inout) :: ps
599 real(real64),
allocatable :: vsr(:), vlr(:), nlr(:)
600 real(real64) :: r, exp_arg, max_val_vsr
605 assert(ps%g%nrval > 0)
607 safe_allocate(vsr(1:ps%g%nrval))
608 safe_allocate(vlr(1:ps%g%nrval))
609 safe_allocate(nlr(1:ps%g%nrval))
615 do ii = 1, ps%g%nrval
621 if(abs(vsr(ii)) < 1.0e-14_real64) vsr(ii) =
m_zero
622 max_val_vsr = max(max_val_vsr, abs(vsr(ii)))
624 exp_arg = -
m_half*r**2/ps%sigma_erf**2
633 call spline_fit(ps%g%nrval, ps%g%rofi, vlr, ps%vlr, ps%projectors_sphere_threshold)
636 call spline_fit(ps%g%nrval, ps%g%rofi, nlr, ps%nlr, ps%projectors_sphere_threshold)
641 call spline_fit(ps%g%nrval, ps%g%rofi, vsr, ps%vl, ps%projectors_sphere_threshold)
642 if (max_val_vsr < 1.0e-12_real64) ps%no_vl = .
true.
644 safe_deallocate_a(vsr)
645 safe_deallocate_a(vlr)
646 safe_deallocate_a(nlr)
648 ps%is_separated = .
true.
654 real(real64)
pure function long_range_potential(r, sigma, z_val) result(vlr)
655 real(real64),
intent(in) :: r, sigma, z_val
662 if(arg > 1e-3_real64)
then
663 vlr = -z_val * erf(arg) / r
671 type(
ps_t),
intent(inout) :: ps
679 if (l == ps%llocal) cycle
681 ps%rc_max = max(ps%rc_max, ps%kb(l, j)%x_threshold)
691 type(
ps_t),
intent(inout) :: ps
698 call spline_der(ps%kb(l, j), ps%dkb(l, j), ps%projectors_sphere_threshold)
708 type(
ps_t),
intent(inout) :: ps
709 integer,
intent(in) :: filter
710 real(real64),
intent(in) :: gmax
712 integer :: l, k, ispin
714 real(real64) :: alpha, beta_fs, rmax, rcut, gamma, beta_rs
717 call profiling_in(
"PS_FILTER")
726 if(.not. ps%no_vl)
then
727 rmax = ps%vl%x_threshold
729 call spline_filter_mask(ps%vl, max(0, ps%llocal), rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
733 if (l == ps%llocal) cycle
735 call spline_filter_mask(ps%kb(l, k), l, ps%rc_max, gmax, alpha, gamma, ps%projectors_sphere_threshold)
740 rmax = ps%core%x_threshold
741 call spline_filter_mask(ps%core, 0, rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
745 do ispin = 1, ps%ispin
746 if (abs(spline_integral(ps%density(ispin))) > 1.0e-12_real64)
then
747 rmax = ps%density(ispin)%x_threshold
748 call spline_filter_mask(ps%density(ispin), 0, rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
749 call spline_force_pos(ps%density(ispin), ps%projectors_sphere_threshold)
752 if (abs(spline_integral(ps%density_der(ispin))) > 1.0e-12_real64)
then
753 rmax = ps%density_der(ispin)%x_threshold
754 call spline_filter_mask(ps%density_der(ispin), 0, rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
761 beta_fs = 18.0_real64
766 call spline_filter_bessel(ps%vl, max(0, ps%llocal), gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
768 if (l == ps%llocal) cycle
770 call spline_filter_bessel(ps%kb(l, k), l, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
775 call spline_filter_bessel(ps%core, 0, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
779 do ispin = 1, ps%ispin
780 call spline_filter_bessel(ps%density(ispin), 0, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
781 call spline_force_pos(ps%density(ispin), ps%projectors_sphere_threshold)
782 call spline_filter_bessel(ps%density_der(ispin), 0, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
788 call profiling_out(
"PS_FILTER")
794 type(
ps_t),
intent(inout) :: ps
795 real(real64),
intent(in) :: eigen(:,:)
798 real(real64) :: ur1, ur2
803 where(eigen > m_zero)
812 if (.not. ps%bound(i, is)) cycle
814 do ir = ps%g%nrval, 3, -1
816 if (abs(spline_eval(ps%ur(i, is), ps%g%rofi(ir))*ps%g%rofi(ir)) > m_zero)
then
824 ur1 = spline_eval(ps%ur(i, is), ps%g%rofi(ir-2))*ps%g%rofi(ir-2)
825 ur2 = spline_eval(ps%ur(i, is), ps%g%rofi(ir-1))*ps%g%rofi(ir-1)
826 if ((ur1*ur2 > m_zero) .and. (abs(ur2) > abs(ur1))) ps%bound(i, is) = .false.
838 subroutine ps_debug(ps, dir, namespace, gmax)
839 type(
ps_t),
intent(in) :: ps
840 character(len=*),
intent(in) :: dir
841 type(namespace_t),
intent(in) :: namespace
842 real(real64),
intent(in) :: gmax
845 type(spline_t),
allocatable :: fw(:, :)
853 iunit = io_open(trim(dir)//
'/pseudo-info', namespace, action=
'write')
854 write(iunit,
'(a,/)') ps%label
855 write(iunit,
'(a,a,/)')
'Format : ',
ps_name(ps%file_format)
856 write(iunit,
'(a,f6.3)')
'z : ', ps%z
857 write(iunit,
'(a,f6.3,/)')
'zval : ', ps%z_val
858 write(iunit,
'(a,i4)')
'lmax : ', ps%lmax
859 write(iunit,
'(a,i4)')
'lloc : ', ps%llocal
860 write(iunit,
'(a,i4,/)')
'kbc : ', ps%kbc
861 write(iunit,
'(a,f9.5,/)')
'rcmax : ', ps%rc_max
862 write(iunit,
'(a,/)')
'h matrix:'
865 write(iunit,
'(10f9.5)') (ps%h(l, k, j), j = 1, ps%kbc)
868 if (
allocated(ps%k))
then
869 write(iunit,
'(/,a,/)')
'k matrix:'
872 write(iunit,
'(10f9.5)') (ps%k(l, k, j), j = 1, ps%kbc)
877 write(iunit,
'(/,a)')
'orbitals:'
879 if (ps%ispin == 2)
then
880 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), &
881 'j = ', ps%conf%j(j),
'bound = ', all(ps%bound(j,:)), &
882 'occ(1) = ', ps%conf%occ(j, 1),
'occ(2) = ', ps%conf%occ(j, 2)
884 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), &
885 'j = ', ps%conf%j(j),
'bound = ', all(ps%bound(j,:)), &
886 'occ = ', ps%conf%occ(j, 1)
894 iunit = io_open(trim(dir)//
'/local', namespace, action=
'write')
895 call spline_print(ps%vl, iunit)
899 iunit = io_open(trim(dir)//
'/local_long_range', namespace, action=
'write')
900 call spline_print(ps%vlr, iunit)
904 iunit = io_open(trim(dir)//
'/local_long_range_density', namespace, action=
'write')
905 call spline_print(ps%nlr, iunit)
909 iunit = io_open(trim(dir)//
'/local_ft', namespace, action=
'write')
910 safe_allocate(fw(1, 1))
911 call spline_init(fw(1, 1))
912 call spline_3dft(ps%vl, fw(1, 1), ps%projectors_sphere_threshold, gmax = gmax)
913 call spline_print(fw(1, 1), iunit)
914 call spline_end(fw(1, 1))
915 safe_deallocate_a(fw)
919 iunit = io_open(trim(dir)//
'/nonlocal', namespace, action=
'write')
920 call spline_print(ps%kb, iunit)
923 iunit = io_open(trim(dir)//
'/nonlocal_derivative', namespace, action=
'write')
924 call spline_print(ps%dkb, iunit)
927 iunit = io_open(trim(dir)//
'/nonlocal_ft', namespace, action=
'write')
928 safe_allocate(fw(0:ps%lmax, 1:ps%kbc))
932 call spline_besselft(ps%kb(k, j), fw(k, j), k, threshold=ps%projectors_sphere_threshold, &
936 call spline_print(fw, iunit)
938 safe_deallocate_a(fw)
942 iunit = io_open(trim(dir)//
'/wavefunctions', namespace, action=
'write')
943 call spline_print(ps%ur, iunit)
947 if (ps%has_density)
then
948 iunit = io_open(trim(dir)//
'/density', namespace, action=
'write')
949 call spline_print(ps%density, iunit)
952 iunit = io_open(trim(dir)//
'/density_derivative', namespace, action=
'write')
953 call spline_print(ps%density_der, iunit)
959 iunit = io_open(trim(dir)//
'/nlcc', namespace, action=
'write')
960 call spline_print(ps%core, iunit)
970 type(
ps_t),
intent(inout) :: ps
972 if (.not.
allocated(ps%kb))
return
976 if (ps%is_separated)
then
977 call spline_end(ps%vlr)
978 call spline_end(ps%nlr)
981 call spline_end(ps%kb)
982 call spline_end(ps%dkb)
983 call spline_end(ps%ur)
985 call spline_end(ps%vl)
986 call spline_end(ps%core)
987 call spline_end(ps%core_der)
989 if (
allocated(ps%density))
call spline_end(ps%density)
990 if (
allocated(ps%density_der))
call spline_end(ps%density_der)
992 call logrid_end(ps%g)
994 safe_deallocate_a(ps%kb)
995 safe_deallocate_a(ps%dkb)
996 safe_deallocate_a(ps%ur)
997 safe_deallocate_a(ps%bound)
998 safe_deallocate_a(ps%h)
999 safe_deallocate_a(ps%k)
1000 safe_deallocate_a(ps%density)
1001 safe_deallocate_a(ps%density_der)
1009 type(
ps_t),
intent(inout) :: ps
1010 type(ps_hgh_t),
intent(inout) :: ps_hgh
1016 if (ps%lmax >= 0)
then
1017 ps%rc_max = 1.1_real64 * maxval(ps_hgh%kbr(0:ps%lmax))
1021 ps%h(0:ps%lmax, 1:ps%kbc, 1:ps%kbc) = ps_hgh%h(0:ps%lmax, 1:ps%kbc, 1:ps%kbc)
1022 ps%k(0:ps%lmax, 1:ps%kbc, 1:ps%kbc) = ps_hgh%k(0:ps%lmax, 1:ps%kbc, 1:ps%kbc)
1033 integer :: l, is, j, ip
1034 real(real64),
allocatable :: hato(:), dens(:)
1038 safe_allocate(hato(1:ps_hgh%g%nrval))
1039 safe_allocate(dens(1:ps_hgh%g%nrval))
1042 do l = 0, ps_hgh%l_max
1044 hato(:) = ps_hgh%kb(:, l, j)
1045 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, hato, ps%kb(l, j), ps%projectors_sphere_threshold)
1051 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, ps_hgh%vlocal, ps%vl, ps%projectors_sphere_threshold)
1058 hato(2:ps_hgh%g%nrval) = ps_hgh%rphi(2:ps_hgh%g%nrval, l)/ps_hgh%g%rofi(2:ps_hgh%g%nrval)
1061 do ip = 1, ps_hgh%g%nrval
1062 dens(ip) = dens(ip) + ps%conf%occ(l, is)*hato(ip)**2/(m_four*m_pi)
1065 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, hato, ps%ur(l, is), ps%projectors_sphere_threshold)
1067 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, dens, ps%density(is), ps%projectors_sphere_threshold)
1070 safe_deallocate_a(hato)
1071 safe_deallocate_a(dens)
1080 type(
ps_t),
intent(inout) :: ps
1081 type(ps_in_grid_t),
intent(in) :: ps_grid
1086 ps%z_val = ps_grid%zval
1088 ps%nlcc = ps_grid%core_corrections
1090 ps%h(0:ps%lmax, 1, 1) = ps_grid%dkbcos(1:ps%lmax+1)
1094 ps%rc_max = maxval(ps_grid%kb_radius(1:ps%lmax+1)) * 1.5_real64
1100 ps%h(0:ps%lmax,:,:) = ps%h(0:ps%lmax,:,:) / m_two
1107 type(logrid_t),
intent(in) :: g
1109 real(real64),
allocatable :: hato(:), dens(:)
1110 integer :: is, l, ir, nrc, ip
1114 safe_allocate(hato(1:g%nrval))
1115 safe_allocate(dens(1:g%nrval))
1122 do l = 1, ps_grid%no_l_channels
1123 hato(2:) = ps_grid%rphi(2:, l, 1+is)/g%rofi(2:)
1124 hato(1) = first_point_extrapolate(g%rofi, hato)
1126 if(ps%conf%occ(l, is) > m_epsilon)
then
1128 dens(ip) = dens(ip) + ps%conf%occ(l, is)*hato(ip)**2/(m_four*m_pi)
1132 call spline_fit(g%nrval, g%rofi, hato, ps%ur(l, is), ps%projectors_sphere_threshold)
1135 call spline_fit(g%nrval, g%rofi, dens, ps%density(is), ps%projectors_sphere_threshold)
1141 nrc = logrid_index(g, ps_grid%kb_radius(l)) + 1
1142 hato(1:nrc) = ps_grid%KB(1:nrc, l)
1143 hato(nrc+1:g%nrval) = m_zero
1145 call spline_fit(g%nrval, g%rofi, hato, ps%kb(l-1, 1), ps%projectors_sphere_threshold)
1150 hato(:) = ps_grid%vlocal(:)/m_two
1151 call spline_fit(g%nrval, g%rofi, hato, ps%vl, ps%projectors_sphere_threshold)
1153 if (ps_grid%core_corrections)
then
1155 hato(2:) = ps_grid%chcore(2:)/(m_four*m_pi*g%r2ofi(2:))
1157 do ir = g%nrval-1, 2, -1
1158 if (hato(ir) >
eps)
then
1164 hato(nrc:g%nrval) = m_zero
1165 hato(1) = first_point_extrapolate(g%rofi, hato)
1167 call spline_fit(g%nrval, g%rofi, hato, ps%core, ps%projectors_sphere_threshold)
1170 safe_deallocate_a(hato)
1171 safe_deallocate_a(dens)
1182 type(
ps_t),
intent(inout) :: ps
1183 type(ps_xml_t),
intent(in) :: ps_xml
1184 type(namespace_t),
intent(in) :: namespace
1186 integer :: ll, ip, is, ic, jc, ir, nrc, ii
1187 real(real64) :: rr, kbcos, kbnorm, dnrm, avgv, volume_element
1188 real(real64),
allocatable :: vlocal(:), kbprojector(:), wavefunction(:), nlcc_density(:), dens(:,:)
1189 integer,
allocatable :: cmap(:, :)
1190 real(real64),
allocatable :: matrix(:, :), eigenvalues(:)
1191 logical :: density_is_known
1192 real(real64),
parameter :: tol_diagonal=1.0e-10_real64
1197 if (pseudo_has_total_angular_momentum(ps_xml%pseudo))
then
1198 if (ps%file_format == pseudo_format_psp8)
then
1200 message(1) =
"SOC from PSP8 is not currently supported."
1201 message(2) =
"Only scalar relativistic effects will be considered."
1202 call messages_warning(2, namespace=namespace)
1208 ps%nlcc = ps_xml%nlcc
1210 ps%z_val = ps_xml%valence_charge
1212 ps%has_density = ps_xml%has_density
1221 safe_allocate(vlocal(1:ps%g%nrval))
1222 do ip = 1, ps_xml%grid_size
1223 rr = ps_xml%grid(ip)
1224 if (ip <= ps_xml%grid_size)
then
1225 vlocal(ip) = ps_xml%potential(ip, ps%llocal)
1227 vlocal(ip) = -ps_xml%valence_charge/rr
1232 call spline_fit(ps%g%nrval, ps%g%rofi, vlocal, ps%vl, ps%projectors_sphere_threshold)
1234 safe_deallocate_a(vlocal)
1236 safe_allocate(kbprojector(1:ps%g%nrval))
1237 safe_allocate(wavefunction(1:ps%g%nrval))
1239 kbprojector = m_zero
1240 wavefunction = m_zero
1242 density_is_known = .false.
1245 if (ps_xml%kleinman_bylander)
then
1247 safe_allocate(cmap(0:ps_xml%lmax, 1:ps_xml%nchannels))
1251 do ll = 0, ps_xml%lmax
1252 do ic = 1, ps_xml%nchannels
1256 if (ll == ps_xml%llocal) cycle
1258 if (ic > pseudo_nprojectors_per_l(ps_xml%pseudo, ll)) cycle
1263 assert(mod(ps_xml%nchannels, 2)==0)
1264 if (pseudo_projector_2j(ps_xml%pseudo, ll, ic) == 2*ll - 1)
then
1265 cmap(ll, ic) = int((ic-1)/2)*2 + 2
1267 assert(pseudo_projector_2j(ps_xml%pseudo, ll, ic) == 2*ll + 1)
1268 cmap(ll, ic) = int((ic-1)/2)*2 + 1
1274 assert(sum(cmap(ll, 1:ps_xml%nchannels)) == (ps_xml%nchannels + 1)*ps_xml%nchannels/2)
1277 assert(all(cmap >= 0 .and. cmap <= ps_xml%nchannels))
1286 if (pseudo_nprojectors(ps_xml%pseudo) > 0)
then
1287 safe_allocate(matrix(1:ps_xml%nchannels, 1:ps_xml%nchannels))
1288 safe_allocate(eigenvalues(1:ps_xml%nchannels))
1290 do ll = 0, ps_xml%lmax
1292 if (is_diagonal(ps_xml%nchannels, ps_xml%dij(ll, :, :), tol_diagonal) .or. &
1293 pseudo_has_total_angular_momentum(ps_xml%pseudo))
then
1295 do ic = 1, ps_xml%nchannels
1296 eigenvalues(ic) = ps_xml%dij(ll, ic, ic)
1297 matrix(ic, ic) = m_one
1301 matrix(1:ps_xml%nchannels, 1:ps_xml%nchannels) = ps_xml%dij(ll, 1:ps_xml%nchannels, 1:ps_xml%nchannels)
1302 call lalg_eigensolve(ps_xml%nchannels, matrix, eigenvalues)
1305 do ic = 1, ps_xml%nchannels
1306 kbprojector = m_zero
1307 do jc = 1, ps_xml%nchannels
1308 call lalg_axpy(ps_xml%grid_size, matrix(jc, ic), ps_xml%projector(:, ll, jc), kbprojector)
1311 call spline_fit(ps%g%nrval, ps%g%rofi, kbprojector, ps%kb(ll, cmap(ll, ic)), ps%projectors_sphere_threshold)
1313 ps%h(ll, cmap(ll, ic), cmap(ll, ic)) = eigenvalues(ic)
1318 safe_deallocate_a(matrix)
1319 safe_deallocate_a(eigenvalues)
1322 ps%conf%p = ps_xml%nwavefunctions
1329 if ((.not.
ps_has_density(ps) .or. ps%ispin == 2) .and. ps_xml%nwavefunctions > 0)
then
1330 safe_allocate(dens(1:ps%g%nrval, 1:ps%ispin))
1334 do ii = 1, ps_xml%nwavefunctions
1336 ps%conf%n(ii) = ps_xml%wf_n(ii)
1337 ps%conf%l(ii) = ps_xml%wf_l(ii)
1339 if (ps%ispin == 2)
then
1340 ps%conf%occ(ii, 1) = min(ps_xml%wf_occ(ii), m_two*ps_xml%wf_l(ii) + m_one)
1341 ps%conf%occ(ii, 2) = ps_xml%wf_occ(ii) - ps%conf%occ(ii, 1)
1343 ps%conf%occ(ii, 1) = ps_xml%wf_occ(ii)
1346 ps%conf%j(ii) = m_zero
1347 if (pseudo_has_total_angular_momentum(ps_xml%pseudo))
then
1348 ps%conf%j(ii) = m_half*pseudo_wavefunction_2j(ps_xml%pseudo, ii)
1351 do ip = 1, ps%g%nrval
1352 if (ip <= ps_xml%grid_size)
then
1353 wavefunction(ip) = ps_xml%wavefunction(ip, ii)
1355 wavefunction(ip) = m_zero
1360 call spline_fit(ps%g%nrval, ps%g%rofi, wavefunction, ps%ur(ii, is), ps%projectors_sphere_threshold)
1365 do ip = 1, ps_xml%grid_size
1366 dens(ip, is) = dens(ip, is) + ps%conf%occ(ii, is)*wavefunction(ip)**2/(m_four*m_pi)
1374 if ((.not.
ps_has_density(ps) .or. ps%ispin == 2) .and. ps_xml%nwavefunctions > 0)
then
1376 call spline_fit(ps%g%nrval, ps%g%rofi, dens(:,is), ps%density(is), ps%projectors_sphere_threshold)
1378 safe_deallocate_a(dens)
1379 density_is_known = .
true.
1380 ps%has_density = .
true.
1383 safe_deallocate_a(cmap)
1388 ps%conf%occ = m_zero
1389 ps%conf%symbol = ps%label(1:2)
1393 call valconf_sort_by_l(ps%conf, ps_xml%lmax)
1396 if (abs(sum(ps%conf%occ) - ps%z_val ) < m_epsilon)
then
1397 safe_allocate(dens(1:ps%g%nrval, 1:ps%ispin))
1401 do ll = 0, ps_xml%lmax
1406 do ip = 1, ps_xml%grid_size
1407 rr = ps_xml%grid(ip)
1408 volume_element = rr**2*ps_xml%weights(ip)
1409 kbprojector(ip) = (ps_xml%potential(ip, ll) - ps_xml%potential(ip, ps%llocal))*ps_xml%wavefunction(ip, ll)
1410 dnrm = dnrm + kbprojector(ip)**2*volume_element
1411 avgv = avgv + kbprojector(ip)*ps_xml%wavefunction(ip, ll)*volume_element
1414 kbcos = dnrm/(safe_tol(avgv,1.0e-20_real64))
1415 kbnorm = m_one/(safe_tol(
sqrt(dnrm),1.0e-20_real64))
1417 if (ll /= ps%llocal)
then
1418 ps%h(ll, 1, 1) = kbcos
1419 kbprojector = kbprojector*kbnorm
1421 ps%h(ll, 1, 1) = m_zero
1424 call spline_fit(ps%g%nrval, ps%g%rofi, kbprojector, ps%kb(ll, 1), ps%projectors_sphere_threshold)
1427 call lalg_copy(ps_xml%grid_size, ps_xml%wavefunction(:, ll), wavefunction)
1428 wavefunction(ps_xml%grid_size+1:ps%g%nrval) = m_zero
1431 call spline_fit(ps%g%nrval, ps%g%rofi, wavefunction, ps%ur(ll + 1, is), ps%projectors_sphere_threshold)
1435 if (abs(sum(ps%conf%occ) - ps%z_val) < m_epsilon)
then
1437 do ip = 1, ps_xml%grid_size
1438 dens(ip, is) = dens(ip, is) + ps%conf%occ(ll+1, is)*wavefunction(ip)**2/(m_four*m_pi)
1445 if (abs(sum(ps%conf%occ) - ps%z_val) < m_epsilon)
then
1447 call spline_fit(ps%g%nrval, ps%g%rofi, dens(:,is), ps%density(is), ps%projectors_sphere_threshold)
1449 safe_deallocate_a(dens)
1450 density_is_known = .
true.
1451 ps%has_density = .
true.
1458 safe_allocate(dens(1:ps%g%nrval, 1))
1460 dens(1:ps_xml%grid_size, 1) = ps_xml%density(1:ps_xml%grid_size)/ps%ispin
1461 dens(ps_xml%grid_size + 1:ps%g%nrval, 1) = m_zero
1464 call spline_fit(ps%g%nrval, ps%g%rofi, dens(:, 1), ps%density(is), ps%projectors_sphere_threshold)
1467 safe_deallocate_a(dens)
1472 if (ps_xml%nlcc)
then
1474 safe_allocate(nlcc_density(1:ps%g%nrval))
1476 call lalg_copy(ps_xml%grid_size, ps_xml%nlcc_density, nlcc_density)
1479 do ir = ps_xml%grid_size - 1, 1, -1
1480 if (nlcc_density(ir) >
eps)
then
1486 nlcc_density(nrc:ps%g%nrval) = m_zero
1488 call spline_fit(ps%g%nrval, ps%g%rofi, nlcc_density, ps%core, ps%projectors_sphere_threshold)
1490 safe_deallocate_a(nlcc_density)
1496 ps%rc_max = ps%rc_max*1.05_real64
1498 safe_deallocate_a(kbprojector)
1499 safe_deallocate_a(wavefunction)
1508 type(
ps_t),
intent(in) :: ps
1523 type(
ps_t),
intent(in) :: ps
1530 if (any(.not. ps%bound(i,:))) cycle
1539 type(
ps_t),
intent(in) :: ps
1541 has_density = ps%has_density
1547 pure logical function ps_has_nlcc(ps)
result(has_nlcc)
1548 type(
ps_t),
intent(in) :: ps
1555 real(real64) function ps_density_volume(ps, namespace) result(volume)
1556 type(
ps_t),
intent(in) :: ps
1557 type(namespace_t),
intent(in) :: namespace
1559 integer :: ip, ispin
1561 real(real64),
allocatable ::vol(:)
1562 type(spline_t) :: volspl
1567 message(1) =
"The pseudopotential does not contain an atomic density"
1568 call messages_fatal(1, namespace=namespace)
1571 safe_allocate(vol(1:ps%g%nrval))
1573 do ip = 1, ps%g%nrval
1576 do ispin = 1, ps%ispin
1577 vol(ip) = vol(ip) + spline_eval(ps%density(ispin), rr)*m_four*m_pi*rr**5
1581 call spline_init(volspl)
1582 call spline_fit(ps%g%nrval, ps%g%rofi, vol, volspl, ps%projectors_sphere_threshold)
1583 volume = spline_integral(volspl)
1584 call spline_end(volspl)
1586 safe_deallocate_a(vol)
1595 type(namespace_t),
intent(in) :: namespace
1596 real(real64),
intent(in) :: zz
1597 real(real64),
intent(in) :: valcharge
1598 integer,
intent(in) :: ispin
1599 type(valconf_t),
intent(inout) :: conf
1611 write(message(1),
'(a,a,a)')
'Debug: Guessing the atomic occupations for ', trim(conf%symbol),
"."
1612 call messages_info(1, namespace=namespace, debug_only=.
true.)
1614 assert(valcharge <= zz)
1618 if(int(zz) > 2 .and. val > zz - 2)
then
1622 if(int(zz) > 4 .and. val > zz - 4)
then
1627 if(int(zz) > 18 .and. val > zz - 10)
then
1630 print *, val, zz - 12, int(zz) > 12 .and. val > zz - 12
1632 if(int(zz) > 12 .and. val > zz - 12)
then
1633 print *,
'Filling 3s2'
1637 if(int(zz) > 18 .and. val > zz - 18)
then
1638 print *,
'Filling 3p6'
1642 if(int(zz) > 28 .and. val > zz - 28)
then
1646 if(int(zz) > 30 .and. val > zz - 30)
then
1650 if(int(zz) > 36 .and. val > zz - 36)
then
1654 if(int(zz) > 46 .and. val > zz - 46)
then
1659 if((int(zz) > 48 .and. val > zz - 48) .or. &
1660 (int(zz) > 70 .and. int(zz) <= 81 .and. val > zz - 62))
then
1665 if((int(zz) > 54 .and. val > zz - 54) .or. &
1666 (int(zz) > 70 .and. int(zz) <= 81 .and. val > zz - 68) )
then
1671 if(int(zz) > 80 .and. val > zz - 68)
then
1677 select case (int(zz))
1995 if (val < m_epsilon)
then
1997 if (ispin == 2)
then
1998 call valconf_unpolarized_to_polarized(conf)
2002 message(1) =
"Error in attributing atomic occupations"
2003 call messages_warning(1, namespace=namespace)
2010 real(real64),
intent(inout) :: val
2011 integer,
intent(in) :: max_occ, nn
2014 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2015 val = val - conf%occ(conf%p,1)
2018 print *,
'Filling ', conf%n(conf%p), conf%l(conf%p), conf%occ(conf%p,1)
2022 real(real64),
intent(inout) :: val
2023 integer,
intent(in) :: max_occ, nn
2026 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2027 val = val - conf%occ(conf%p,1)
2033 real(real64),
intent(inout) :: val
2034 integer,
intent(in) :: max_occ, nn
2037 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2038 val = val - conf%occ(conf%p,1)
2044 real(real64),
intent(inout) :: val
2045 integer,
intent(in) :: max_occ, nn
2048 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2049 val = val - conf%occ(conf%p,1)
2056#include "ps_pspio_inc.F90"
Some operations may be done for one spline-function, or for an array of them.
double exp(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
subroutine, public valconf_unpolarized_to_polarized(conf)
subroutine, public valconf_copy(cout, cin)
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_pi
some mathematical constants
real(real64), parameter, public m_min_exp_arg
real(real64), parameter, public m_half
real(real64), parameter, public m_one
real(real64), parameter, public m_three
subroutine, public logrid_copy(grid_in, grid_out)
This module is intended to contain "only mathematical" functions and procedures.
subroutine, public messages_obsolete_variable(namespace, name, rep)
subroutine, public messages_new_line()
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
subroutine, public ps_cpi_end(ps_cpi)
subroutine, public ps_cpi_init(ps_cpi, filename, namespace)
subroutine, public ps_cpi_process(ps_cpi, lloc, namespace)
subroutine, public ps_fhi_end(ps_fhi)
subroutine, public ps_fhi_init(ps_fhi, filename, namespace)
subroutine, public ps_fhi_process(ps_fhi, lmax, lloc, namespace)
subroutine, public hgh_end(psp)
subroutine, public hgh_get_eigen(psp, eigen)
subroutine, public hgh_process(psp, namespace)
subroutine, public hgh_init(psp, filename, namespace)
pure logical function, public ps_has_density(ps)
integer, parameter, public ps_filter_ts
subroutine, public ps_end(ps)
subroutine hgh_load(ps, ps_hgh)
subroutine, public ps_init(ps, namespace, label, z, user_lmax, user_llocal, ispin, filename)
subroutine ps_info(ps, filename, namespace)
subroutine, public ps_separate(ps)
Separate the local potential into (soft) long-ranged and (hard) short-ranged parts.
subroutine ps_check_bound(ps, eigen)
subroutine ps_grid_load(ps, ps_grid)
subroutine, public ps_debug(ps, dir, namespace, gmax)
real(real64) pure function, public long_range_potential(r, sigma, z_val)
Evaluate the long-range potential at a given distance.
integer, parameter, public proj_hgh
pure integer function, public ps_bound_niwfs(ps)
Returns the number of bound atomic orbitals taking into account then m quantum number multiplicity.
real(real64), parameter eps
Cutoff for determining the radius of the NLCC.
subroutine, public ps_getradius(ps)
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....
pure logical function, public ps_has_nlcc(ps)
pure integer function, public ps_niwfs(ps)
Returns the number of atomic orbitals taking into account then m quantum number multiplicity.
subroutine, public ps_pspio_init(ps, namespace, label, z, lmax, ispin, filename)
integer, parameter, public ps_filter_none
integer, parameter, public proj_j_average
Fully-relativistic pseudopotentials with separate j-average and SOC terms.
integer, parameter, public proj_rkb
integer, parameter, public proj_j_dependent
Fully-relativistic j-dependent pseudopotentials.
subroutine, public ps_derivatives(ps)
subroutine, public ps_filter(ps, filter, gmax)
real(real64) function, public ps_density_volume(ps, namespace)
character(len=4), dimension(pseudo_format_upf1:pseudo_format_psp8), parameter ps_name
integer, parameter, public ps_filter_bsb
integer, parameter, public proj_kb
subroutine ps_xml_load(ps, ps_xml, namespace)
Loads XML files for QSO, UPF1, UPF2, PSML, and PSP8 formats.
subroutine, public ps_psf_init(pstm, ispin, filename, namespace)
subroutine, public ps_psf_process(ps_psf, namespace, lmax, lloc)
subroutine, public ps_psf_get_eigen(ps_psf, eigen)
subroutine, public ps_psf_end(ps_psf)
subroutine, public ps_xml_end(this)
subroutine, public ps_xml_init(this, namespace, filename, fmt, ierr)
integer, parameter, public pseudo_format_file_not_found
integer, parameter, public pseudo_type_kleinman_bylander
integer, parameter, public pseudo_format_qso
integer, parameter, public pseudo_format_hgh
integer, parameter, public pseudo_format_upf2
integer, parameter, public pseudo_type_paw
integer, parameter, public pseudo_format_cpi
integer, parameter, public pseudo_exchange_unknown
integer, parameter, public pseudo_type_semilocal
integer, parameter, public pseudo_type_ultrasoft
integer, parameter, public pseudo_correlation_unknown
integer, parameter, public pseudo_format_psf
integer, parameter, public pseudo_format_fhi
integer, parameter, public pseudo_format_unknown
integer, parameter, public pseudo_format_psml
subroutine, public spline_der(spl, dspl, threshold)
subroutine, public spline_fit(nrc, rofi, ffit, spl, threshold)
real(real64) function, public spline_eval(spl, x)
character(kind=c_char, len=1) function, dimension(:), allocatable, public string_f_to_c(f_string)
convert a Fortran string to a C string
subroutine fill_s_orbs(val, max_occ, nn)
subroutine fill_p_orbs(val, max_occ, nn)
subroutine fill_d_orbs(val, max_occ, nn)
subroutine fill_f_orbs(val, max_occ, nn)
remember that the FHI format is basically the CPI format with a header
The following data type contains: (a) the pseudopotential parameters, as read from a *....
A type storing the information and data about a pseudopotential.