26 use,
intrinsic :: iso_fortran_env
72 integer,
parameter,
public :: &
77 integer,
public,
parameter :: &
83 integer,
public,
parameter :: &
84 PROJ_J_INDEPENDENT = 0, & !< Non-relativisitic or scalar-relativistic pseudopotentials
88 integer,
parameter,
public :: INVALID_L = 333
90 character(len=4),
parameter :: ps_name(PSEUDO_FORMAT_UPF1:PSEUDO_FORMAT_PSP8) = &
91 (/
"upf1",
"upf2",
"qso ",
"psml",
"psf ",
"cpi ",
"fhi ",
"hgh ",
"psp8"/)
96 integer :: projector_type
97 integer :: relativistic_treatment
100 character(len=10),
private :: label
102 integer,
private :: ispin
104 real(real64),
private :: z
105 real(real64) :: z_val
106 type(valconf_t) :: conf
108 type(logrid_t),
private :: g
110 type(spline_t),
allocatable :: ur(:, :)
111 logical,
allocatable :: bound(:, :)
118 logical :: no_vl = .false.
120 real(real64) :: projectors_sphere_threshold
127 real(real64) :: rc_max
130 integer :: projectors_per_l(5)
131 real(real64),
allocatable :: h(:,:,:), k(:, :, :)
132 type(spline_t),
allocatable :: kb(:, :)
133 type(spline_t),
allocatable :: dkb(:, :)
136 type(spline_t) :: core
137 type(spline_t) :: core_der
142 logical,
private :: has_long_range
143 logical,
private :: is_separated
145 type(spline_t),
private :: vlr
146 type(spline_t) :: nlr
148 real(real64) :: sigma_erf
150 logical,
private :: has_density
151 type(spline_t),
allocatable :: density(:)
152 type(spline_t),
allocatable :: density_der(:)
155 integer :: file_format
156 integer,
private :: pseudo_type
157 integer :: exchange_functional
158 integer :: correlation_functional
161 real(real64),
parameter :: eps = 1.0e-8_real64
167 subroutine ps_init(ps, namespace, label, z, user_lmax, user_llocal, ispin, filename)
168 type(
ps_t),
intent(out) :: ps
170 character(len=10),
intent(in) :: label
171 integer,
intent(in) :: user_lmax
172 integer,
intent(in) :: user_llocal
173 integer,
intent(in) :: ispin
174 real(real64),
intent(in) :: z
175 character(len=*),
intent(in) :: filename
177 integer :: l, ii, ll, is, ierr
183 real(real64),
allocatable :: eigen(:, :)
211 call parse_variable(namespace,
'SpeciesProjectorSphereThreshold', 0.001_real64, ps%projectors_sphere_threshold)
217 call messages_write(
"Cannot open pseudopotential file '"//trim(filename)//
"'.")
222 call messages_write(
"Cannot determine the pseudopotential type for species '"//trim(label)//
"' from", &
230 ps%relativistic_treatment = proj_j_independent
232 ps%sigma_erf = 0.625_real64
234 ps%projectors_per_l = 0
236 select case (ps%file_format)
240 ps%has_density = .false.
243 select case (ps%file_format)
254 ps%lmax = ps_psf%ps_grid%no_l_channels - 1
256 if (user_lmax /= invalid_l)
then
257 ps%lmax = min(ps%lmax, user_lmax)
258 if (user_lmax /= ps%lmax)
then
259 message(1) =
"lmax in Species block for " // trim(label) // &
260 " is larger than number available in pseudopotential."
265 ps%conf%p = ps_psf%ps_grid%no_l_channels
266 if (ps%lmax == 0) ps%llocal = 0
269 if (user_llocal == invalid_l)
then
272 ps%llocal = user_llocal
275 ps%projectors_per_l(1:ps%lmax+1) = 1
276 if (ps%llocal > -1) ps%projectors_per_l(ps%llocal+1) = 0
285 call ps_cpi_init(ps_cpi, trim(filename), namespace)
286 ps%conf%p = ps_cpi%ps_grid%no_l_channels
288 call ps_fhi_init(ps_fhi, trim(filename), namespace)
289 ps%conf%p = ps_fhi%ps_grid%no_l_channels
293 ps%conf%symbol = label(1:2)
302 ps%lmax = ps%conf%p - 1
304 if (user_lmax /= invalid_l)
then
305 ps%lmax = min(ps%lmax, user_lmax)
306 if (user_lmax /= ps%lmax)
then
307 message(1) =
"lmax in Species block for " // trim(label) // &
308 " is larger than number available in pseudopotential."
313 if (ps%lmax == 0) ps%llocal = 0
316 if (user_llocal == invalid_l)
then
319 ps%llocal = user_llocal
322 ps%projectors_per_l(1:ps%lmax+1) = 1
323 if (ps%llocal > -1) ps%projectors_per_l(ps%llocal+1) = 0
337 call hgh_init(ps_hgh, trim(filename), namespace)
341 ps%z_val = ps_hgh%z_val
344 ps%lmax = ps_hgh%l_max
345 ps%conf%symbol = label(1:2)
346 ps%sigma_erf = ps_hgh%rlocal
348 ps%projectors_per_l(1:ps%lmax+1) = 1
368 call ps_xml_init(ps_xml, namespace, trim(filename), ps%file_format, ierr)
377 if (ps_xml%kleinman_bylander)
then
378 ps%conf%p = ps_xml%nwavefunctions
380 ps%conf%p = ps_xml%lmax + 1
383 do ll = 0, ps_xml%lmax
384 ps%conf%l(ll + 1) = ll
387 ps%kbc = ps_xml%nchannels
388 ps%lmax = ps_xml%lmax
390 ps%projectors_per_l = 0
391 do ll = 0, ps_xml%lmax
395 if (ps_xml%kleinman_bylander)
then
396 ps%llocal = ps_xml%llocal
400 if (ps_xml%llocal >= 0) ps%llocal = ps_xml%llocal
401 if (user_llocal /= invalid_l) ps%llocal = user_llocal
402 assert(ps%llocal >= 0)
403 assert(ps%llocal <= ps%lmax)
406 ps%g%nrval = ps_xml%grid_size
408 safe_allocate(ps%g%rofi(1:ps%g%nrval))
409 safe_allocate(ps%g%r2ofi(1:ps%g%nrval))
411 do ii = 1, ps%g%nrval
412 ps%g%rofi(ii) = ps_xml%grid(ii)
413 ps%g%r2ofi(ii) = ps_xml%grid(ii)**2
418 ps%local = (ps%lmax == 0 .and. ps%llocal == 0 ) .or. (ps%lmax == -1 .and. ps%llocal == -1)
421 safe_allocate(ps%kb (0:ps%lmax, 1:ps%kbc))
422 safe_allocate(ps%dkb (0:ps%lmax, 1:ps%kbc))
423 safe_allocate(ps%ur (1:ps%conf%p, 1:ps%ispin))
424 safe_allocate(ps%bound(1:ps%conf%p, 1:ps%ispin))
425 safe_allocate(ps%h (0:ps%lmax, 1:ps%kbc, 1:ps%kbc))
426 safe_allocate(ps%density(1:ps%ispin))
427 safe_allocate(ps%density_der(1:ps%ispin))
437 safe_allocate(eigen(1:ps%conf%p, 1:ps%ispin))
441 select case (ps%file_format)
454 safe_allocate(ps%k (0:ps%lmax, 1:ps%kbc, 1:ps%kbc))
464 call spline_der(ps%density(is), ps%density_der(is), ps%projectors_sphere_threshold)
469 call spline_der(ps%core, ps%core_der, ps%projectors_sphere_threshold)
474 ps%has_long_range = .
true.
475 ps%is_separated = .false.
477 call ps_info(ps, filename, namespace)
479 safe_deallocate_a(eigen)
486 subroutine ps_info(ps, filename, namespace)
487 type(
ps_t),
intent(in) :: ps
488 character(len=*),
intent(in) :: filename
497 select case (ps%file_format)
498 case (pseudo_format_upf1)
506 case (pseudo_format_psp8)
528 select case (ps%pseudo_type)
542 select case (ps%file_format)
556 if (ps%llocal >= 0)
then
568 if (ps%llocal < 0)
then
598 type(
ps_t),
intent(inout) :: ps
600 real(real64),
allocatable :: vsr(:), vlr(:), nlr(:)
601 real(real64) :: r, exp_arg, max_val_vsr
606 assert(ps%g%nrval > 0)
608 safe_allocate(vsr(1:ps%g%nrval))
609 safe_allocate(vlr(1:ps%g%nrval))
610 safe_allocate(nlr(1:ps%g%nrval))
616 do ii = 1, ps%g%nrval
622 if(abs(vsr(ii)) < 1.0e-14_real64) vsr(ii) =
m_zero
623 max_val_vsr = max(max_val_vsr, abs(vsr(ii)))
625 exp_arg = -
m_half*r**2/ps%sigma_erf**2
634 call spline_fit(ps%g%nrval, ps%g%rofi, vlr, ps%vlr, ps%projectors_sphere_threshold)
637 call spline_fit(ps%g%nrval, ps%g%rofi, nlr, ps%nlr, ps%projectors_sphere_threshold)
642 call spline_fit(ps%g%nrval, ps%g%rofi, vsr, ps%vl, ps%projectors_sphere_threshold)
643 if (max_val_vsr < 1.0e-12_real64) ps%no_vl = .
true.
645 safe_deallocate_a(vsr)
646 safe_deallocate_a(vlr)
647 safe_deallocate_a(nlr)
649 ps%is_separated = .
true.
655 real(real64)
pure function long_range_potential(r, sigma, z_val) result(vlr)
656 real(real64),
intent(in) :: r, sigma, z_val
663 if(arg > 1e-3_real64)
then
664 vlr = -z_val * erf(arg) / r
672 type(
ps_t),
intent(inout) :: ps
680 if (l == ps%llocal) cycle
682 ps%rc_max = max(ps%rc_max, ps%kb(l, j)%x_threshold)
692 type(
ps_t),
intent(inout) :: ps
699 call spline_der(ps%kb(l, j), ps%dkb(l, j), ps%projectors_sphere_threshold)
709 type(
ps_t),
intent(inout) :: ps
710 integer,
intent(in) :: filter
711 real(real64),
intent(in) :: gmax
713 integer :: l, k, ispin
715 real(real64) :: alpha, beta_fs, rmax, rcut, gamma, beta_rs
718 call profiling_in(
"PS_FILTER")
727 if(.not. ps%no_vl)
then
728 rmax = ps%vl%x_threshold
730 call spline_filter_mask(ps%vl, max(0, ps%llocal), rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
734 if (l == ps%llocal) cycle
736 call spline_filter_mask(ps%kb(l, k), l, ps%rc_max, gmax, alpha, gamma, ps%projectors_sphere_threshold)
741 rmax = ps%core%x_threshold
742 call spline_filter_mask(ps%core, 0, rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
746 do ispin = 1, ps%ispin
747 if (abs(spline_integral(ps%density(ispin))) > 1.0e-12_real64)
then
748 rmax = ps%density(ispin)%x_threshold
749 call spline_filter_mask(ps%density(ispin), 0, rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
750 call spline_force_pos(ps%density(ispin), ps%projectors_sphere_threshold)
753 if (abs(spline_integral(ps%density_der(ispin))) > 1.0e-12_real64)
then
754 rmax = ps%density_der(ispin)%x_threshold
755 call spline_filter_mask(ps%density_der(ispin), 0, rmax, gmax, alpha, gamma, ps%projectors_sphere_threshold)
762 beta_fs = 18.0_real64
767 call spline_filter_bessel(ps%vl, max(0, ps%llocal), gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
769 if (l == ps%llocal) cycle
771 call spline_filter_bessel(ps%kb(l, k), l, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
776 call spline_filter_bessel(ps%core, 0, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
780 do ispin = 1, ps%ispin
781 call spline_filter_bessel(ps%density(ispin), 0, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
782 call spline_force_pos(ps%density(ispin), ps%projectors_sphere_threshold)
783 call spline_filter_bessel(ps%density_der(ispin), 0, gmax, alpha, beta_fs, rcut, beta_rs, ps%projectors_sphere_threshold)
789 call profiling_out(
"PS_FILTER")
795 type(
ps_t),
intent(inout) :: ps
796 real(real64),
intent(in) :: eigen(:,:)
799 real(real64) :: ur1, ur2
804 where(eigen > m_zero)
813 if (.not. ps%bound(i, is)) cycle
815 do ir = ps%g%nrval, 3, -1
817 if (abs(spline_eval(ps%ur(i, is), ps%g%rofi(ir))*ps%g%rofi(ir)) > m_zero)
then
825 ur1 = spline_eval(ps%ur(i, is), ps%g%rofi(ir-2))*ps%g%rofi(ir-2)
826 ur2 = spline_eval(ps%ur(i, is), ps%g%rofi(ir-1))*ps%g%rofi(ir-1)
827 if ((ur1*ur2 > m_zero) .and. (abs(ur2) > abs(ur1))) ps%bound(i, is) = .false.
839 subroutine ps_debug(ps, dir, namespace, gmax)
840 type(
ps_t),
intent(in) :: ps
841 character(len=*),
intent(in) :: dir
842 type(namespace_t),
intent(in) :: namespace
843 real(real64),
intent(in) :: gmax
846 type(spline_t),
allocatable :: fw(:, :)
854 iunit = io_open(trim(dir)//
'/pseudo-info', namespace, action=
'write')
855 write(iunit,
'(a,/)') ps%label
856 write(iunit,
'(a,a,/)')
'Format : ',
ps_name(ps%file_format)
857 write(iunit,
'(a,f6.3)')
'z : ', ps%z
858 write(iunit,
'(a,f6.3,/)')
'zval : ', ps%z_val
859 write(iunit,
'(a,i4)')
'lmax : ', ps%lmax
860 write(iunit,
'(a,i4)')
'lloc : ', ps%llocal
861 write(iunit,
'(a,i4,/)')
'kbc : ', ps%kbc
862 write(iunit,
'(a,f9.5,/)')
'rcmax : ', ps%rc_max
863 write(iunit,
'(a,/)')
'h matrix:'
866 write(iunit,
'(10f9.5)') (ps%h(l, k, j), j = 1, ps%kbc)
869 if (
allocated(ps%k))
then
870 write(iunit,
'(/,a,/)')
'k matrix:'
873 write(iunit,
'(10f9.5)') (ps%k(l, k, j), j = 1, ps%kbc)
878 write(iunit,
'(/,a)')
'orbitals:'
880 if (ps%ispin == 2)
then
881 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), &
882 'j = ', ps%conf%j(j),
'bound = ', all(ps%bound(j,:)), &
883 'occ(1) = ', ps%conf%occ(j, 1),
'occ(2) = ', ps%conf%occ(j, 2)
885 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), &
886 'j = ', ps%conf%j(j),
'bound = ', all(ps%bound(j,:)), &
887 'occ = ', ps%conf%occ(j, 1)
895 iunit = io_open(trim(dir)//
'/local', namespace, action=
'write')
896 call spline_print(ps%vl, iunit)
900 iunit = io_open(trim(dir)//
'/local_long_range', namespace, action=
'write')
901 call spline_print(ps%vlr, iunit)
905 iunit = io_open(trim(dir)//
'/local_long_range_density', namespace, action=
'write')
906 call spline_print(ps%nlr, iunit)
910 iunit = io_open(trim(dir)//
'/local_ft', namespace, action=
'write')
911 safe_allocate(fw(1, 1))
912 call spline_init(fw(1, 1))
913 call spline_3dft(ps%vl, fw(1, 1), ps%projectors_sphere_threshold, gmax = gmax)
914 call spline_print(fw(1, 1), iunit)
915 call spline_end(fw(1, 1))
916 safe_deallocate_a(fw)
920 iunit = io_open(trim(dir)//
'/nonlocal', namespace, action=
'write')
921 call spline_print(ps%kb, iunit)
924 iunit = io_open(trim(dir)//
'/nonlocal_derivative', namespace, action=
'write')
925 call spline_print(ps%dkb, iunit)
928 iunit = io_open(trim(dir)//
'/nonlocal_ft', namespace, action=
'write')
929 safe_allocate(fw(0:ps%lmax, 1:ps%kbc))
933 call spline_besselft(ps%kb(k, j), fw(k, j), k, threshold=ps%projectors_sphere_threshold, &
937 call spline_print(fw, iunit)
939 safe_deallocate_a(fw)
943 iunit = io_open(trim(dir)//
'/wavefunctions', namespace, action=
'write')
944 call spline_print(ps%ur, iunit)
948 if (ps%has_density)
then
949 iunit = io_open(trim(dir)//
'/density', namespace, action=
'write')
950 call spline_print(ps%density, iunit)
953 iunit = io_open(trim(dir)//
'/density_derivative', namespace, action=
'write')
954 call spline_print(ps%density_der, iunit)
960 iunit = io_open(trim(dir)//
'/nlcc', namespace, action=
'write')
961 call spline_print(ps%core, iunit)
971 type(
ps_t),
intent(inout) :: ps
973 if (.not.
allocated(ps%kb))
return
977 if (ps%is_separated)
then
978 call spline_end(ps%vlr)
979 call spline_end(ps%nlr)
982 call spline_end(ps%kb)
983 call spline_end(ps%dkb)
984 call spline_end(ps%ur)
986 call spline_end(ps%vl)
987 call spline_end(ps%core)
988 call spline_end(ps%core_der)
990 if (
allocated(ps%density))
call spline_end(ps%density)
991 if (
allocated(ps%density_der))
call spline_end(ps%density_der)
993 call logrid_end(ps%g)
995 safe_deallocate_a(ps%kb)
996 safe_deallocate_a(ps%dkb)
997 safe_deallocate_a(ps%ur)
998 safe_deallocate_a(ps%bound)
999 safe_deallocate_a(ps%h)
1000 safe_deallocate_a(ps%k)
1001 safe_deallocate_a(ps%density)
1002 safe_deallocate_a(ps%density_der)
1010 type(
ps_t),
intent(inout) :: ps
1011 type(ps_hgh_t),
intent(inout) :: ps_hgh
1017 if (ps%lmax >= 0)
then
1018 ps%rc_max = 1.1_real64 * maxval(ps_hgh%kbr(0:ps%lmax))
1022 ps%h(0:ps%lmax, 1:ps%kbc, 1:ps%kbc) = ps_hgh%h(0:ps%lmax, 1:ps%kbc, 1:ps%kbc)
1023 ps%k(0:ps%lmax, 1:ps%kbc, 1:ps%kbc) = ps_hgh%k(0:ps%lmax, 1:ps%kbc, 1:ps%kbc)
1034 integer :: l, is, j, ip
1035 real(real64),
allocatable :: hato(:), dens(:)
1039 safe_allocate(hato(1:ps_hgh%g%nrval))
1040 safe_allocate(dens(1:ps_hgh%g%nrval))
1043 do l = 0, ps_hgh%l_max
1045 hato(:) = ps_hgh%kb(:, l, j)
1046 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, hato, ps%kb(l, j), ps%projectors_sphere_threshold)
1052 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, ps_hgh%vlocal, ps%vl, ps%projectors_sphere_threshold)
1059 hato(2:ps_hgh%g%nrval) = ps_hgh%rphi(2:ps_hgh%g%nrval, l)/ps_hgh%g%rofi(2:ps_hgh%g%nrval)
1062 do ip = 1, ps_hgh%g%nrval
1063 dens(ip) = dens(ip) + ps%conf%occ(l, is)*hato(ip)**2/(m_four*m_pi)
1066 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, hato, ps%ur(l, is), ps%projectors_sphere_threshold)
1068 call spline_fit(ps_hgh%g%nrval, ps_hgh%g%rofi, dens, ps%density(is), ps%projectors_sphere_threshold)
1071 safe_deallocate_a(hato)
1072 safe_deallocate_a(dens)
1081 type(
ps_t),
intent(inout) :: ps
1082 type(ps_in_grid_t),
intent(in) :: ps_grid
1087 ps%z_val = ps_grid%zval
1089 ps%nlcc = ps_grid%core_corrections
1091 ps%h(0:ps%lmax, 1, 1) = ps_grid%dkbcos(1:ps%lmax+1)
1095 ps%rc_max = maxval(ps_grid%kb_radius(1:ps%lmax+1)) * 1.5_real64
1101 ps%h(0:ps%lmax,:,:) = ps%h(0:ps%lmax,:,:) / m_two
1108 type(logrid_t),
intent(in) :: g
1110 real(real64),
allocatable :: hato(:), dens(:)
1111 integer :: is, l, ir, nrc, ip
1115 safe_allocate(hato(1:g%nrval))
1116 safe_allocate(dens(1:g%nrval))
1123 do l = 1, ps_grid%no_l_channels
1124 hato(2:) = ps_grid%rphi(2:, l, 1+is)/g%rofi(2:)
1125 hato(1) = first_point_extrapolate(g%rofi, hato)
1127 if(ps%conf%occ(l, is) > m_epsilon)
then
1129 dens(ip) = dens(ip) + ps%conf%occ(l, is)*hato(ip)**2/(m_four*m_pi)
1133 call spline_fit(g%nrval, g%rofi, hato, ps%ur(l, is), ps%projectors_sphere_threshold)
1136 call spline_fit(g%nrval, g%rofi, dens, ps%density(is), ps%projectors_sphere_threshold)
1142 nrc = logrid_index(g, ps_grid%kb_radius(l)) + 1
1143 hato(1:nrc) = ps_grid%KB(1:nrc, l)
1144 hato(nrc+1:g%nrval) = m_zero
1146 call spline_fit(g%nrval, g%rofi, hato, ps%kb(l-1, 1), ps%projectors_sphere_threshold)
1151 hato(:) = ps_grid%vlocal(:)/m_two
1152 call spline_fit(g%nrval, g%rofi, hato, ps%vl, ps%projectors_sphere_threshold)
1154 if (ps_grid%core_corrections)
then
1156 hato(2:) = ps_grid%chcore(2:)/(m_four*m_pi*g%r2ofi(2:))
1158 do ir = g%nrval-1, 2, -1
1159 if (hato(ir) >
eps)
then
1165 hato(nrc:g%nrval) = m_zero
1166 hato(1) = first_point_extrapolate(g%rofi, hato)
1168 call spline_fit(g%nrval, g%rofi, hato, ps%core, ps%projectors_sphere_threshold)
1171 safe_deallocate_a(hato)
1172 safe_deallocate_a(dens)
1183 type(
ps_t),
intent(inout) :: ps
1184 type(ps_xml_t),
intent(in) :: ps_xml
1185 type(namespace_t),
intent(in) :: namespace
1187 integer :: ll, ip, is, ic, jc, ir, nrc, ii
1188 real(real64) :: rr, kbcos, kbnorm, dnrm, avgv, volume_element
1189 real(real64),
allocatable :: vlocal(:), kbprojector(:), wavefunction(:), nlcc_density(:), dens(:,:)
1190 integer,
allocatable :: cmap(:, :)
1191 real(real64),
allocatable :: matrix(:, :), eigenvalues(:)
1192 logical :: density_is_known
1193 integer,
allocatable :: order(:)
1194 real(real64),
allocatable :: occ_tmp(:,:)
1195 real(real64),
parameter :: tol_diagonal=1.0e-10_real64
1200 if (pseudo_has_total_angular_momentum(ps_xml%pseudo))
then
1201 if (ps%file_format == pseudo_format_psp8)
then
1203 message(1) =
"SOC from PSP8 is not currently supported."
1204 message(2) =
"Only scalar relativistic effects will be considered."
1205 call messages_warning(2, namespace=namespace)
1211 ps%nlcc = ps_xml%nlcc
1213 ps%z_val = ps_xml%valence_charge
1215 ps%has_density = ps_xml%has_density
1224 safe_allocate(vlocal(1:ps%g%nrval))
1225 do ip = 1, ps_xml%grid_size
1226 rr = ps_xml%grid(ip)
1227 if (ip <= ps_xml%grid_size)
then
1228 vlocal(ip) = ps_xml%potential(ip, ps%llocal)
1230 vlocal(ip) = -ps_xml%valence_charge/rr
1235 call spline_fit(ps%g%nrval, ps%g%rofi, vlocal, ps%vl, ps%projectors_sphere_threshold)
1237 safe_deallocate_a(vlocal)
1239 safe_allocate(kbprojector(1:ps%g%nrval))
1240 safe_allocate(wavefunction(1:ps%g%nrval))
1242 kbprojector = m_zero
1243 wavefunction = m_zero
1245 density_is_known = .false.
1248 if (ps_xml%kleinman_bylander)
then
1250 safe_allocate(cmap(0:ps_xml%lmax, 1:ps_xml%nchannels))
1254 do ll = 0, ps_xml%lmax
1255 do ic = 1, ps_xml%nchannels
1259 if (ll == ps_xml%llocal) cycle
1261 if (ic > pseudo_nprojectors_per_l(ps_xml%pseudo, ll)) cycle
1266 assert(mod(ps_xml%nchannels, 2)==0)
1267 if (pseudo_projector_2j(ps_xml%pseudo, ll, ic) == 2*ll - 1)
then
1268 cmap(ll, ic) = int((ic-1)/2)*2 + 2
1270 assert(pseudo_projector_2j(ps_xml%pseudo, ll, ic) == 2*ll + 1)
1271 cmap(ll, ic) = int((ic-1)/2)*2 + 1
1277 assert(sum(cmap(ll, 1:ps_xml%nchannels)) == (ps_xml%nchannels + 1)*ps_xml%nchannels/2)
1280 assert(all(cmap >= 0 .and. cmap <= ps_xml%nchannels))
1289 if (pseudo_nprojectors(ps_xml%pseudo) > 0)
then
1290 safe_allocate(matrix(1:ps_xml%nchannels, 1:ps_xml%nchannels))
1291 safe_allocate(eigenvalues(1:ps_xml%nchannels))
1293 do ll = 0, ps_xml%lmax
1295 if (is_diagonal(ps_xml%nchannels, ps_xml%dij(ll, :, :), tol_diagonal) .or. &
1296 pseudo_has_total_angular_momentum(ps_xml%pseudo))
then
1298 do ic = 1, ps_xml%nchannels
1299 eigenvalues(ic) = ps_xml%dij(ll, ic, ic)
1300 matrix(ic, ic) = m_one
1304 matrix(1:ps_xml%nchannels, 1:ps_xml%nchannels) = ps_xml%dij(ll, 1:ps_xml%nchannels, 1:ps_xml%nchannels)
1305 call lalg_eigensolve(ps_xml%nchannels, matrix, eigenvalues)
1308 do ic = 1, ps_xml%nchannels
1309 kbprojector = m_zero
1310 do jc = 1, ps_xml%nchannels
1311 call lalg_axpy(ps_xml%grid_size, matrix(jc, ic), ps_xml%projector(:, ll, jc), kbprojector)
1314 call spline_fit(ps%g%nrval, ps%g%rofi, kbprojector, ps%kb(ll, cmap(ll, ic)), ps%projectors_sphere_threshold)
1316 ps%h(ll, cmap(ll, ic), cmap(ll, ic)) = eigenvalues(ic)
1321 safe_deallocate_a(matrix)
1322 safe_deallocate_a(eigenvalues)
1325 ps%conf%p = ps_xml%nwavefunctions
1332 if ((.not.
ps_has_density(ps) .or. ps%ispin == 2) .and. ps_xml%nwavefunctions > 0)
then
1333 safe_allocate(dens(1:ps%g%nrval, 1:ps%ispin))
1337 do ii = 1, ps_xml%nwavefunctions
1339 ps%conf%n(ii) = ps_xml%wf_n(ii)
1340 ps%conf%l(ii) = ps_xml%wf_l(ii)
1342 if (ps%ispin == 2)
then
1343 ps%conf%occ(ii, 1) = min(ps_xml%wf_occ(ii), m_two*ps_xml%wf_l(ii) + m_one)
1344 ps%conf%occ(ii, 2) = ps_xml%wf_occ(ii) - ps%conf%occ(ii, 1)
1346 ps%conf%occ(ii, 1) = ps_xml%wf_occ(ii)
1349 ps%conf%j(ii) = m_zero
1350 if (pseudo_has_total_angular_momentum(ps_xml%pseudo))
then
1351 ps%conf%j(ii) = m_half*pseudo_wavefunction_2j(ps_xml%pseudo, ii)
1354 do ip = 1, ps%g%nrval
1355 if (ip <= ps_xml%grid_size)
then
1356 wavefunction(ip) = ps_xml%wavefunction(ip, ii)
1358 wavefunction(ip) = m_zero
1363 call spline_fit(ps%g%nrval, ps%g%rofi, wavefunction, ps%ur(ii, is), ps%projectors_sphere_threshold)
1368 do ip = 1, ps_xml%grid_size
1369 dens(ip, is) = dens(ip, is) + ps%conf%occ(ii, is)*wavefunction(ip)**2/(m_four*m_pi)
1377 if ((.not.
ps_has_density(ps) .or. ps%ispin == 2) .and. ps_xml%nwavefunctions > 0)
then
1379 call spline_fit(ps%g%nrval, ps%g%rofi, dens(:,is), ps%density(is), ps%projectors_sphere_threshold)
1381 safe_deallocate_a(dens)
1382 density_is_known = .
true.
1383 ps%has_density = .
true.
1386 safe_deallocate_a(cmap)
1391 ps%conf%occ = m_zero
1392 ps%conf%symbol = ps%label(1:2)
1396 safe_allocate(order(1:ps_xml%lmax+1))
1397 safe_allocate(occ_tmp(1:ps_xml%lmax+1, 1:2))
1398 occ_tmp(:,:) = ps%conf%occ(1:ps_xml%lmax+1,1:2)
1399 call sort(ps%conf%l(1:ps_xml%lmax+1), order)
1400 do ll = 0, ps_xml%lmax
1401 ps%conf%occ(ll+1, 1:2) = occ_tmp(order(ll+1), 1:2)
1403 safe_deallocate_a(order)
1404 safe_deallocate_a(occ_tmp)
1407 if (abs(sum(ps%conf%occ) - ps%z_val ) < m_epsilon)
then
1408 safe_allocate(dens(1:ps%g%nrval, 1:ps%ispin))
1412 do ll = 0, ps_xml%lmax
1417 do ip = 1, ps_xml%grid_size
1418 rr = ps_xml%grid(ip)
1419 volume_element = rr**2*ps_xml%weights(ip)
1420 kbprojector(ip) = (ps_xml%potential(ip, ll) - ps_xml%potential(ip, ps%llocal))*ps_xml%wavefunction(ip, ll)
1421 dnrm = dnrm + kbprojector(ip)**2*volume_element
1422 avgv = avgv + kbprojector(ip)*ps_xml%wavefunction(ip, ll)*volume_element
1425 kbcos = dnrm/(safe_tol(avgv,1.0e-20_real64))
1426 kbnorm = m_one/(safe_tol(
sqrt(dnrm),1.0e-20_real64))
1428 if (ll /= ps%llocal)
then
1429 ps%h(ll, 1, 1) = kbcos
1430 kbprojector = kbprojector*kbnorm
1432 ps%h(ll, 1, 1) = m_zero
1435 call spline_fit(ps%g%nrval, ps%g%rofi, kbprojector, ps%kb(ll, 1), ps%projectors_sphere_threshold)
1438 call lalg_copy(ps_xml%grid_size, ps_xml%wavefunction(:, ll), wavefunction)
1439 wavefunction(ps_xml%grid_size+1:ps%g%nrval) = m_zero
1442 call spline_fit(ps%g%nrval, ps%g%rofi, wavefunction, ps%ur(ll + 1, is), ps%projectors_sphere_threshold)
1446 if (abs(sum(ps%conf%occ) - ps%z_val) < m_epsilon)
then
1448 do ip = 1, ps_xml%grid_size
1449 dens(ip, is) = dens(ip, is) + ps%conf%occ(ll+1, is)*wavefunction(ip)**2/(m_four*m_pi)
1456 if (abs(sum(ps%conf%occ) - ps%z_val) < m_epsilon)
then
1458 call spline_fit(ps%g%nrval, ps%g%rofi, dens(:,is), ps%density(is), ps%projectors_sphere_threshold)
1460 safe_deallocate_a(dens)
1461 density_is_known = .
true.
1462 ps%has_density = .
true.
1469 safe_allocate(dens(1:ps%g%nrval, 1))
1471 dens(1:ps_xml%grid_size, 1) = ps_xml%density(1:ps_xml%grid_size)/ps%ispin
1472 dens(ps_xml%grid_size + 1:ps%g%nrval, 1) = m_zero
1475 call spline_fit(ps%g%nrval, ps%g%rofi, dens(:, 1), ps%density(is), ps%projectors_sphere_threshold)
1478 safe_deallocate_a(dens)
1483 if (ps_xml%nlcc)
then
1485 safe_allocate(nlcc_density(1:ps%g%nrval))
1487 call lalg_copy(ps_xml%grid_size, ps_xml%nlcc_density, nlcc_density)
1490 do ir = ps_xml%grid_size - 1, 1, -1
1491 if (nlcc_density(ir) >
eps)
then
1497 nlcc_density(nrc:ps%g%nrval) = m_zero
1499 call spline_fit(ps%g%nrval, ps%g%rofi, nlcc_density, ps%core, ps%projectors_sphere_threshold)
1501 safe_deallocate_a(nlcc_density)
1507 ps%rc_max = ps%rc_max*1.05_real64
1509 safe_deallocate_a(kbprojector)
1510 safe_deallocate_a(wavefunction)
1519 type(
ps_t),
intent(in) :: ps
1534 type(
ps_t),
intent(in) :: ps
1541 if (any(.not. ps%bound(i,:))) cycle
1550 type(
ps_t),
intent(in) :: ps
1552 has_density = ps%has_density
1558 pure logical function ps_has_nlcc(ps)
result(has_nlcc)
1559 type(
ps_t),
intent(in) :: ps
1566 real(real64) function ps_density_volume(ps, namespace) result(volume)
1567 type(
ps_t),
intent(in) :: ps
1568 type(namespace_t),
intent(in) :: namespace
1570 integer :: ip, ispin
1572 real(real64),
allocatable ::vol(:)
1573 type(spline_t) :: volspl
1578 message(1) =
"The pseudopotential does not contain an atomic density"
1579 call messages_fatal(1, namespace=namespace)
1582 safe_allocate(vol(1:ps%g%nrval))
1584 do ip = 1, ps%g%nrval
1587 do ispin = 1, ps%ispin
1588 vol(ip) = vol(ip) + spline_eval(ps%density(ispin), rr)*m_four*m_pi*rr**5
1592 call spline_init(volspl)
1593 call spline_fit(ps%g%nrval, ps%g%rofi, vol, volspl, ps%projectors_sphere_threshold)
1594 volume = spline_integral(volspl)
1595 call spline_end(volspl)
1597 safe_deallocate_a(vol)
1606 type(namespace_t),
intent(in) :: namespace
1607 real(real64),
intent(in) :: zz
1608 real(real64),
intent(in) :: valcharge
1609 integer,
intent(in) :: ispin
1610 type(valconf_t),
intent(inout) :: conf
1622 write(message(1),
'(a,a,a)')
'Debug: Guessing the atomic occupations for ', trim(conf%symbol),
"."
1623 call messages_info(1, namespace=namespace, debug_only=.
true.)
1625 assert(valcharge <= zz)
1629 if(int(zz) > 2 .and. val > zz - 2)
then
1633 if(int(zz) > 4 .and. val > zz - 4)
then
1638 if(int(zz) > 18 .and. val > zz - 10)
then
1642 if(int(zz) > 12 .and. val > zz - 12)
then
1646 if(int(zz) > 18 .and. val > zz - 18)
then
1650 if(int(zz) > 28 .and. val > zz - 28)
then
1654 if(int(zz) > 30 .and. val > zz - 30)
then
1658 if(int(zz) > 36 .and. val > zz - 36)
then
1662 if(int(zz) > 46 .and. val > zz - 46)
then
1667 if((int(zz) > 48 .and. val > zz - 48) .or. &
1668 (int(zz) > 70 .and. int(zz) <= 81 .and. val > zz - 62))
then
1673 if((int(zz) > 54 .and. val > zz - 54) .or. &
1674 (int(zz) > 70 .and. int(zz) <= 81 .and. val > zz - 68) )
then
1679 if(int(zz) > 80 .and. val > zz - 68)
then
1685 select case (int(zz))
2002 if (val < m_epsilon)
then
2004 if (ispin == 2)
then
2005 call valconf_unpolarized_to_polarized(conf)
2009 message(1) =
"Error in attributing atomic occupations"
2010 call messages_warning(1, namespace=namespace)
2017 real(real64),
intent(inout) :: val
2018 integer,
intent(in) :: max_occ, nn
2021 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2022 val = val - conf%occ(conf%p,1)
2028 real(real64),
intent(inout) :: val
2029 integer,
intent(in) :: max_occ, nn
2032 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2033 val = val - conf%occ(conf%p,1)
2039 real(real64),
intent(inout) :: val
2040 integer,
intent(in) :: max_occ, nn
2043 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2044 val = val - conf%occ(conf%p,1)
2050 real(real64),
intent(inout) :: val
2051 integer,
intent(in) :: max_occ, nn
2054 conf%occ(conf%p,1) = min(val, real(max_occ, real64) )
2055 val = val - conf%occ(conf%p,1)
2062#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
This module is intended to contain "only mathematical" functions and procedures.
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.