LCOV - code coverage report
Current view: top level - src/pseudopotentials - upf_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 71.0 % 69 49
Test Date: 2026-11-24 01:22:08 Functions: 28.6 % 14 4

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief Owned UPF dataset and radial conventions shared by ATOM and Quickstep.
      10              : !>        Dataset availability does not select an orbital representation or calculation method.
      11              : ! **************************************************************************************************
      12              : MODULE upf_types
      13              :    USE ieee_arithmetic,                 ONLY: ieee_is_finite
      14              :    USE kinds,                           ONLY: default_path_length,&
      15              :                                               default_string_length,&
      16              :                                               dp
      17              : #include "../base/base_uses.f90"
      18              : 
      19              :    IMPLICIT NONE
      20              :    PRIVATE
      21              : 
      22              :    ! use same value as in atom_types!
      23              :    INTEGER, PARAMETER                                :: lmat = 3
      24              : 
      25              :    TYPE upf_partial_waves_type
      26              :       ! Original r*phi(r), one AE/PS pair per beta projector; not the atomic guesses.
      27              :       REAL(dp), ALLOCATABLE :: ae_wfc(:, :), ps_wfc(:, :)
      28              :       INTEGER, ALLOCATABLE :: angular_momenta(:)
      29              :    END TYPE upf_partial_waves_type
      30              : 
      31              :    TYPE upf_gipaw_orbitals_type
      32              :       ! Signed u=r*R(r), without a frozen-core assignment or assumed occupations.
      33              :       INTEGER :: data_format = -1
      34              :       REAL(dp), ALLOCATABLE :: wfc(:, :)
      35              :       INTEGER, ALLOCATABLE :: indices(:), principal_quantum_numbers(:), angular_momenta(:)
      36              :    END TYPE upf_gipaw_orbitals_type
      37              : 
      38              :    TYPE, EXTENDS(upf_partial_waves_type) :: upf_paw_type
      39              :       INTEGER :: data_format = -1, cutoff_index = -1, lmax_aug = -1
      40              :       CHARACTER(LEN=default_string_length) :: augmentation_shape = ""
      41              :       REAL(dp) :: cutoff_radius = -1.0_dp, augmentation_epsilon = 1.e-12_dp
      42              :       REAL(dp) :: core_energy = 0.0_dp
      43              :       LOGICAL :: has_core_energy = .FALSE.
      44              :       REAL(dp), ALLOCATABLE :: occupations(:), multipoles(:, :, :)
      45              :       ! AE core density per volume; AE local potential and core energy in Hartree.
      46              :       REAL(dp), ALLOCATABLE :: rho_core(:), vlocal(:)
      47              :       TYPE(upf_gipaw_orbitals_type), ALLOCATABLE :: gipaw_core_orbitals
      48              :    END TYPE upf_paw_type
      49              : 
      50              :    TYPE atom_upfpot_type
      51              :       CHARACTER(LEN=2)                               :: symbol = ""
      52              :       CHARACTER(LEN=default_string_length)           :: pname = ""
      53              :       INTEGER, DIMENSION(0:lmat)                     :: econf = 0
      54              :       REAL(dp)                                       :: zion = 0.0_dp
      55              :       CHARACTER(LEN=default_string_length)           :: version = ""
      56              :       CHARACTER(LEN=default_path_length)             :: filename = ""
      57              :       ! <INFO>
      58              :       INTEGER                                        :: maxinfo = 100
      59              :       CHARACTER(LEN=default_string_length), DIMENSION(100) &
      60              :          :: info = ""
      61              :       ! <HEADER>
      62              :       CHARACTER(LEN=default_string_length)           :: generated = ""
      63              :       CHARACTER(LEN=default_string_length)           :: author = ""
      64              :       CHARACTER(LEN=default_string_length)           :: date = ""
      65              :       CHARACTER(LEN=default_string_length)           :: comment = ""
      66              :       CHARACTER(LEN=4)                               :: pseudo_type = ""
      67              :       CHARACTER(LEN=15)                              :: relativistic = ""
      68              :       CHARACTER(LEN=default_string_length)           :: functional = ""
      69              :       LOGICAL                                        :: is_ultrasoft = .FALSE.
      70              :       LOGICAL                                        :: is_paw = .FALSE.
      71              :       LOGICAL                                        :: is_coulomb = .FALSE.
      72              :       LOGICAL                                        :: has_so = .FALSE.
      73              :       LOGICAL                                        :: has_wfc = .FALSE.
      74              :       LOGICAL                                        :: has_gipaw = .FALSE.
      75              :       LOGICAL                                        :: paw_as_gipaw = .FALSE.
      76              :       LOGICAL                                        :: core_correction = .FALSE.
      77              :       LOGICAL                                        :: with_metagga_info = .FALSE.
      78              :       REAL(dp)                                       :: total_psenergy = 0.0_dp
      79              :       REAL(dp)                                       :: wfc_cutoff = 0.0_dp
      80              :       REAL(dp)                                       :: rho_cutoff = 0.0_dp
      81              :       INTEGER                                        :: l_max = -100
      82              :       INTEGER                                        :: l_max_rho = -1
      83              :       INTEGER                                        :: l_local = -1
      84              :       INTEGER                                        :: mesh_size = -1
      85              :       INTEGER                                        :: number_of_wfc = -1
      86              :       INTEGER                                        :: number_of_proj = -1
      87              :       ! <MESH>
      88              :       REAL(dp)                                       :: dx = 0.0_dp
      89              :       REAL(dp)                                       :: xmin = 0.0_dp
      90              :       REAL(dp)                                       :: rmax = 0.0_dp
      91              :       REAL(dp)                                       :: zmesh = 0.0_dp
      92              :       REAL(dp), DIMENSION(:), ALLOCATABLE            :: r, rab
      93              :       ! <NLCC>
      94              :       REAL(dp), DIMENSION(:), ALLOCATABLE            :: rho_nlcc
      95              :       ! Preserve supplied samples. Only an explicit canonical convention permits XC use.
      96              :       REAL(dp), ALLOCATABLE :: tau_nlcc(:), tau_atom(:)
      97              :       CHARACTER(LEN=default_string_length) :: tau_nlcc_convention = "", tau_atom_convention = ""
      98              :       ! <LOCAL>
      99              :       REAL(dp), DIMENSION(:), ALLOCATABLE            :: vlocal
     100              :       ! <NONLOCAL>: keep the tabulated projector amplitude; D includes Ry -> Hartree.
     101              :       ! beta stores beta(r), with the radial prefactor in PP_BETA removed.
     102              :       REAL(dp), DIMENSION(:, :), ALLOCATABLE         :: dion
     103              :       REAL(dp), DIMENSION(:, :), ALLOCATABLE         :: beta
     104              :       INTEGER, DIMENSION(:), ALLOCATABLE             :: lbeta
     105              :       ! <AUGMENTATION>: PP_Q and r**2*Q_ij^L(r), in the original beta convention.
     106              :       ! The pair index is j*(j-1)/2+i for i<=j; the last dimension starts at L=0.
     107              :       REAL(dp), DIMENSION(:, :), ALLOCATABLE         :: qij
     108              :       REAL(dp), DIMENSION(:, :, :), ALLOCATABLE      :: qijl
     109              :       TYPE(upf_partial_waves_type), ALLOCATABLE :: partial_waves
     110              :       TYPE(upf_paw_type), ALLOCATABLE :: paw
     111              :       ! <SEMILOCAL>
     112              :       REAL(dp), DIMENSION(:, :), ALLOCATABLE         :: vsemi
     113              :    END TYPE atom_upfpot_type
     114              : 
     115              :    PUBLIC :: atom_upfpot_type, upf_partial_waves_type, upf_radial_weights
     116              :    PUBLIC :: upf_paw_type, upf_gipaw_orbitals_type
     117              :    PUBLIC :: upf_release, upf_has_complete_partial_waves
     118              :    PUBLIC :: upf_nlcc_kinetic, upf_uses_model_core_tau
     119              : CONTAINS
     120              : 
     121              : ! **************************************************************************************************
     122              : !> \brief Select model-core tau for USPP and for NC with an explicitly supplied table.
     123              : !> \param pot Original UPF metadata and optional model-core table.
     124              : !> \return Whether this dataset uses the model-core convention instead of PAW reconstruction.
     125              : ! **************************************************************************************************
     126            0 :    PURE FUNCTION upf_uses_model_core_tau(pot) RESULT(use_tau)
     127              :       TYPE(atom_upfpot_type), INTENT(IN)                 :: pot
     128              :       LOGICAL                                            :: use_tau
     129              : 
     130            0 :       use_tau = .NOT. pot%is_paw .AND. (pot%is_ultrasoft .OR. ALLOCATED(pot%tau_nlcc))
     131            0 :    END FUNCTION upf_uses_model_core_tau
     132              : 
     133              : ! **************************************************************************************************
     134              : !> \brief Obtain the independently supplied model-core kinetic density in Hartree per cubic bohr.
     135              : !>        Charge augmentation and NLCC charge do not determine this field. Unlabelled samples
     136              : !>        remain available as raw data, without an assumed generator normalization.
     137              : !> \param pot Original UPF dataset.
     138              : !> \param kinetic Spin-summed canonical core tau, zero for an absent partial core.
     139              : !> \param available Whether the canonical field is defined for this dataset.
     140              : !> \param reason Explanation when the field cannot be used.
     141              : ! **************************************************************************************************
     142           10 :    SUBROUTINE upf_nlcc_kinetic(pot, kinetic, available, reason)
     143              :       TYPE(atom_upfpot_type), INTENT(IN)                 :: pot
     144              :       REAL(dp), ALLOCATABLE, INTENT(OUT)                 :: kinetic(:)
     145              :       LOGICAL, INTENT(OUT)                               :: available
     146              :       CHARACTER(LEN=*), INTENT(OUT)                      :: reason
     147              : 
     148              :       LOGICAL                                            :: has_core
     149              : 
     150            0 :       CPASSERT(ALLOCATED(pot%r))
     151           30 :       ALLOCATE (kinetic(SIZE(pot%r)), SOURCE=0.0_dp)
     152           10 :       available = .FALSE.
     153           10 :       reason = "UPF model-core tau is missing. Supply canonical PP_TAUMOD or prepare an explicit model with add_upf_core_tau.py"
     154           10 :       has_core = .FALSE.
     155           22 :       IF (ALLOCATED(pot%rho_nlcc)) has_core = ANY(pot%rho_nlcc /= 0.0_dp)
     156           10 :       IF (.NOT. has_core) THEN
     157            4 :          IF (ALLOCATED(pot%tau_nlcc)) THEN
     158            2 :             IF (ANY(pot%tau_nlcc /= 0.0_dp)) THEN
     159            2 :                reason = "UPF has a nonzero model-core kinetic density without a nonzero NLCC density"
     160            2 :                RETURN
     161              :             END IF
     162              :          END IF
     163            2 :          available = .TRUE.
     164            2 :          reason = ""
     165            2 :          RETURN
     166              :       END IF
     167            6 :       IF (.NOT. pot%core_correction) THEN
     168            0 :          reason = "UPF has a nonzero NLCC density with core_correction disabled"
     169            0 :          RETURN
     170              :       END IF
     171            6 :       IF (.NOT. ALLOCATED(pot%tau_nlcc)) RETURN
     172            4 :       IF (TRIM(pot%tau_nlcc_convention) /= "HARTREE_PER_VOLUME") THEN
     173            2 :          reason = "UPF PP_TAUMOD requires an explicit hartree_per_volume convention before use in XC"
     174            2 :          RETURN
     175              :       END IF
     176            2 :       CPASSERT(SIZE(pot%tau_nlcc) == SIZE(pot%r))
     177            8 :       CPASSERT(ALL(ieee_is_finite(pot%tau_nlcc)))
     178            8 :       kinetic(:) = pot%tau_nlcc
     179            2 :       available = .TRUE.
     180            2 :       reason = ""
     181           10 :    END SUBROUTINE upf_nlcc_kinetic
     182              : 
     183              : ! **************************************************************************************************
     184              : !> \brief Composite Simpson weights for dr on the supplied UPF mesh index.
     185              : !> \param pot Original radial coordinates and dr/d(index).
     186              : !> \return Radial weights, with a last trapezoidal interval for an even mesh size.
     187              : ! **************************************************************************************************
     188            0 :    FUNCTION upf_radial_weights(pot) RESULT(weights)
     189              :       TYPE(atom_upfpot_type), INTENT(IN)                 :: pot
     190              :       REAL(dp)                                           :: weights(SIZE(pot%r))
     191              : 
     192              :       INTEGER                                            :: n, ns
     193              : 
     194            0 :       n = SIZE(pot%r)
     195            0 :       CPASSERT(n >= 3 .AND. SIZE(pot%rab) == n)
     196            0 :       CPASSERT(ALL(pot%r(2:) > pot%r(:n - 1)) .AND. ALL(pot%rab > 0.0_dp))
     197            0 :       ns = n - 1 + MODULO(n, 2)
     198            0 :       weights = 0.0_dp
     199            0 :       weights(1:ns:2) = 2.0_dp/3.0_dp
     200            0 :       weights(2:ns - 1:2) = 4.0_dp/3.0_dp
     201            0 :       weights(1) = 1.0_dp/3.0_dp
     202            0 :       weights(ns) = 1.0_dp/3.0_dp
     203            0 :       IF (ns < n) weights(n - 1:n) = weights(n - 1:n) + 0.5_dp
     204            0 :       weights(:) = weights*pot%rab
     205            0 :    END FUNCTION upf_radial_weights
     206              : 
     207              : ! **************************************************************************************************
     208              : !> \brief Check for a complete projector-indexed pair of original AE and PS waves.
     209              : !> \param pot Original UPF dataset; atomic guess waves do not satisfy this query.
     210              : !> \return Whether every beta projector has a compatible full-wave pair.
     211              : ! **************************************************************************************************
     212            8 :    PURE FUNCTION upf_has_complete_partial_waves(pot) RESULT(complete)
     213              :       TYPE(atom_upfpot_type), INTENT(IN)                 :: pot
     214              :       LOGICAL                                            :: complete
     215              : 
     216              :       INTEGER                                            :: n, nb
     217              : 
     218            8 :       complete = .FALSE.
     219            8 :       IF (.NOT. ALLOCATED(pot%lbeta)) RETURN
     220            8 :       IF (.NOT. ALLOCATED(pot%r) .OR. .NOT. ALLOCATED(pot%rab)) RETURN
     221            8 :       n = pot%mesh_size
     222            8 :       nb = pot%number_of_proj
     223            8 :       IF (n < 3 .OR. nb < 1 .OR. SIZE(pot%lbeta) /= nb) RETURN
     224            8 :       IF (SIZE(pot%r) /= n .OR. SIZE(pot%rab) /= n) RETURN
     225            8 :       IF (pot%is_paw) THEN
     226            2 :          IF (.NOT. ALLOCATED(pot%paw)) RETURN
     227            2 :          complete = compatible_waves(pot%paw)
     228              :       ELSE
     229            6 :          IF (.NOT. ALLOCATED(pot%partial_waves)) RETURN
     230            4 :          complete = compatible_waves(pot%partial_waves)
     231              :       END IF
     232              :    CONTAINS
     233              : ! **************************************************************************************************
     234              : !> \brief ...
     235              : !> \param waves ...
     236              : !> \return ...
     237              : ! **************************************************************************************************
     238            6 :       PURE FUNCTION compatible_waves(waves) RESULT(compatible)
     239              :          CLASS(upf_partial_waves_type), INTENT(IN) :: waves
     240              :          LOGICAL :: compatible
     241              : 
     242            6 :          compatible = .FALSE.
     243            6 :          IF (.NOT. ALLOCATED(waves%ae_wfc) .OR. .NOT. ALLOCATED(waves%ps_wfc)) RETURN
     244            4 :          IF (.NOT. ALLOCATED(waves%angular_momenta)) RETURN
     245           12 :          IF (ANY(SHAPE(waves%ae_wfc) /= [n, nb])) RETURN
     246           12 :          IF (ANY(SHAPE(waves%ps_wfc) /= [n, nb])) RETURN
     247            4 :          IF (SIZE(waves%angular_momenta) /= nb) RETURN
     248           10 :          compatible = ALL(waves%angular_momenta == pot%lbeta)
     249              :       END FUNCTION compatible_waves
     250              :    END FUNCTION upf_has_complete_partial_waves
     251              : 
     252              : ! **************************************************************************************************
     253              : !> \brief Release every owned field and reset metadata before reusing a dataset.
     254              : !> \param pot Owned UPF dataset.
     255              : ! **************************************************************************************************
     256        11972 :    PURE SUBROUTINE upf_release(pot)
     257              :       TYPE(atom_upfpot_type), INTENT(INOUT)              :: pot
     258              : 
     259      1257060 :       pot = atom_upfpot_type()
     260        11972 :    END SUBROUTINE upf_release
     261            0 : END MODULE upf_types
        

Generated by: LCOV version 2.0-1