LCOV - code coverage report
Current view: top level - src/xc - xc_derivatives.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:1be8651) Lines: 82.6 % 276 228
Test Date: 2026-11-24 01:22:08 Functions: 87.5 % 8 7

            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              : MODULE xc_derivatives
      10              : 
      11              :    USE input_section_types,             ONLY: section_vals_get_subs_vals2,&
      12              :                                               section_vals_type,&
      13              :                                               section_vals_val_get
      14              :    USE kinds,                           ONLY: default_string_length,&
      15              :                                               dp
      16              :    USE string_utilities,                ONLY: uppercase
      17              :    USE xc_b97,                          ONLY: b97_lda_eval,&
      18              :                                               b97_lda_info,&
      19              :                                               b97_lsd_eval,&
      20              :                                               b97_lsd_info
      21              :    USE xc_cs1,                          ONLY: cs1_lda_eval,&
      22              :                                               cs1_lda_info,&
      23              :                                               cs1_lsd_eval,&
      24              :                                               cs1_lsd_info
      25              :    USE xc_derivative_set_types,         ONLY: xc_derivative_set_type
      26              :    USE xc_exchange_gga,                 ONLY: xgga_eval,&
      27              :                                               xgga_info
      28              :    USE xc_gauxc_functional,             ONLY: skala_info
      29              :    USE xc_hcth,                         ONLY: hcth_lda_eval,&
      30              :                                               hcth_lda_info
      31              :    USE xc_ke_gga,                       ONLY: ke_gga_info,&
      32              :                                               ke_gga_lda_eval,&
      33              :                                               ke_gga_lsd_eval
      34              :    USE xc_libxc,                        ONLY: libxc_spin_polarized_eval,&
      35              :                                               libxc_spin_polarized_info,&
      36              :                                               libxc_spin_unpolarized_eval,&
      37              :                                               libxc_spin_unpolarized_info
      38              :    USE xc_lyp,                          ONLY: lyp_lda_eval,&
      39              :                                               lyp_lda_info,&
      40              :                                               lyp_lsd_eval,&
      41              :                                               lyp_lsd_info
      42              :    USE xc_lyp_adiabatic,                ONLY: lyp_adiabatic_lda_eval,&
      43              :                                               lyp_adiabatic_lda_info,&
      44              :                                               lyp_adiabatic_lsd_eval,&
      45              :                                               lyp_adiabatic_lsd_info
      46              :    USE xc_optx,                         ONLY: optx_lda_eval,&
      47              :                                               optx_lda_info,&
      48              :                                               optx_lsd_eval,&
      49              :                                               optx_lsd_info
      50              :    USE xc_pade,                         ONLY: pade_info,&
      51              :                                               pade_init,&
      52              :                                               pade_lda_pw_eval,&
      53              :                                               pade_lsd_pw_eval
      54              :    USE xc_pbe,                          ONLY: pbe_lda_eval,&
      55              :                                               pbe_lda_info,&
      56              :                                               pbe_lsd_eval,&
      57              :                                               pbe_lsd_info
      58              :    USE xc_perdew86,                     ONLY: p86_lda_eval,&
      59              :                                               p86_lda_info
      60              :    USE xc_perdew_wang,                  ONLY: perdew_wang_info,&
      61              :                                               perdew_wang_lda_eval,&
      62              :                                               perdew_wang_lsd_eval
      63              :    USE xc_perdew_zunger,                ONLY: pz_info,&
      64              :                                               pz_lda_eval,&
      65              :                                               pz_lsd_eval
      66              :    USE xc_rho_cflags_types,             ONLY: xc_rho_cflags_setall,&
      67              :                                               xc_rho_cflags_type
      68              :    USE xc_rho_set_types,                ONLY: xc_rho_set_get,&
      69              :                                               xc_rho_set_type
      70              :    USE xc_tfw,                          ONLY: tfw_lda_eval,&
      71              :                                               tfw_lda_info,&
      72              :                                               tfw_lsd_eval,&
      73              :                                               tfw_lsd_info
      74              :    USE xc_thomas_fermi,                 ONLY: thomas_fermi_info,&
      75              :                                               thomas_fermi_lda_eval,&
      76              :                                               thomas_fermi_lsd_eval
      77              :    USE xc_tpss,                         ONLY: tpss_lda_eval,&
      78              :                                               tpss_lda_info
      79              :    USE xc_vwn,                          ONLY: vwn_lda_eval,&
      80              :                                               vwn_lda_info,&
      81              :                                               vwn_lsd_eval,&
      82              :                                               vwn_lsd_info
      83              :    USE xc_xalpha,                       ONLY: xalpha_info,&
      84              :                                               xalpha_lda_eval,&
      85              :                                               xalpha_lsd_eval
      86              :    USE xc_xbecke88,                     ONLY: xb88_lda_eval,&
      87              :                                               xb88_lda_info,&
      88              :                                               xb88_lsd_eval,&
      89              :                                               xb88_lsd_info
      90              :    USE xc_xbecke88_long_range,          ONLY: xb88_lr_lda_eval,&
      91              :                                               xb88_lr_lda_info,&
      92              :                                               xb88_lr_lsd_eval,&
      93              :                                               xb88_lr_lsd_info
      94              :    USE xc_xbecke88_lr_adiabatic,        ONLY: xb88_lr_adiabatic_lda_eval,&
      95              :                                               xb88_lr_adiabatic_lda_info,&
      96              :                                               xb88_lr_adiabatic_lsd_eval,&
      97              :                                               xb88_lr_adiabatic_lsd_info
      98              :    USE xc_xbecke_roussel,               ONLY: xbecke_roussel_lda_eval,&
      99              :                                               xbecke_roussel_lda_info,&
     100              :                                               xbecke_roussel_lsd_eval,&
     101              :                                               xbecke_roussel_lsd_info
     102              :    USE xc_xbeef,                        ONLY: xbeef_lda_eval,&
     103              :                                               xbeef_lda_info,&
     104              :                                               xbeef_lsd_eval,&
     105              :                                               xbeef_lsd_info
     106              :    USE xc_xbr_pbe_lda_hole_t_c_lr,      ONLY: xbr_pbe_lda_hole_tc_lr_lda_eval,&
     107              :                                               xbr_pbe_lda_hole_tc_lr_lda_info,&
     108              :                                               xbr_pbe_lda_hole_tc_lr_lsd_eval,&
     109              :                                               xbr_pbe_lda_hole_tc_lr_lsd_info
     110              :    USE xc_xlda_hole_t_c_lr,             ONLY: xlda_hole_t_c_lr_lda_eval,&
     111              :                                               xlda_hole_t_c_lr_lda_info,&
     112              :                                               xlda_hole_t_c_lr_lsd_eval,&
     113              :                                               xlda_hole_t_c_lr_lsd_info
     114              :    USE xc_xpbe_hole_t_c_lr,             ONLY: xpbe_hole_t_c_lr_lda_eval,&
     115              :                                               xpbe_hole_t_c_lr_lda_info,&
     116              :                                               xpbe_hole_t_c_lr_lsd_eval,&
     117              :                                               xpbe_hole_t_c_lr_lsd_info
     118              :    USE xc_xwpbe,                        ONLY: xwpbe_lda_eval,&
     119              :                                               xwpbe_lda_info,&
     120              :                                               xwpbe_lsd_eval,&
     121              :                                               xwpbe_lsd_info
     122              : #include "../base/base_uses.f90"
     123              : 
     124              :    IMPLICIT NONE
     125              : 
     126              :    PRIVATE
     127              : 
     128              :    LOGICAL, PARAMETER          :: debug_this_module = .FALSE.
     129              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'xc_derivatives'
     130              : 
     131              :    PUBLIC :: xc_functional_get_info, xc_functionals_eval, xc_functionals_get_needs
     132              : 
     133              : CONTAINS
     134              : 
     135              : ! **************************************************************************************************
     136              : !> \brief get the information about the given functional
     137              : !> \param functional the functional you want info about
     138              : !> \param lsd if you are using lsd or lda
     139              : !> \param reference the reference to the acticle where the functional is
     140              : !>        explained
     141              : !> \param shortform the short definition of the functional
     142              : !> \param needs the flags corresponding to the inputs needed by this
     143              : !>        functional are set to true (the flags not needed aren't touched)
     144              : !> \param max_deriv the maximal derivative available
     145              : !> \param print_warn whether to print warnings (mainly relevant for libxc)
     146              : !> \author fawzi
     147              : ! **************************************************************************************************
     148       302243 :    SUBROUTINE xc_functional_get_info(functional, lsd, reference, shortform, &
     149              :                                      needs, max_deriv, print_warn)
     150              :       TYPE(section_vals_type), POINTER                   :: functional
     151              :       LOGICAL, INTENT(in)                                :: lsd
     152              :       CHARACTER(LEN=*), INTENT(OUT), OPTIONAL            :: reference, shortform
     153              :       TYPE(xc_rho_cflags_type), INTENT(inout), OPTIONAL  :: needs
     154              :       INTEGER, INTENT(out), OPTIONAL                     :: max_deriv
     155              :       LOGICAL, INTENT(IN), OPTIONAL                      :: print_warn
     156              : 
     157              :       INTEGER                                            :: i_param
     158              :       REAL(kind=dp)                                      :: r_param
     159              : 
     160       302243 :       CPASSERT(ASSOCIATED(functional))
     161       302910 :       SELECT CASE (functional%section%name)
     162              :       CASE ("BECKE97")
     163          667 :          IF (lsd) THEN
     164              :             CALL b97_lsd_info(reference=reference, shortform=shortform, &
     165            0 :                               needs=needs, max_deriv=max_deriv, b97_params=functional)
     166              :          ELSE
     167              :             CALL b97_lda_info(reference=reference, shortform=shortform, &
     168         1993 :                               needs=needs, max_deriv=max_deriv, b97_params=functional)
     169              :          END IF
     170              :       CASE ("BECKE88_LR_ADIABATIC")
     171          186 :          IF (lsd) THEN
     172              :             CALL xb88_lr_adiabatic_lsd_info(reference=reference, shortform=shortform, &
     173          325 :                                             needs=needs, max_deriv=max_deriv)
     174              :          ELSE
     175              :             CALL xb88_lr_adiabatic_lda_info(reference=reference, shortform=shortform, &
     176          229 :                                             needs=needs, max_deriv=max_deriv)
     177              :          END IF
     178              :       CASE ("LYP_ADIABATIC")
     179          186 :          IF (lsd) THEN
     180              :             CALL lyp_adiabatic_lsd_info(reference=reference, shortform=shortform, &
     181          325 :                                         needs=needs, max_deriv=max_deriv)
     182              :          ELSE
     183              :             CALL lyp_adiabatic_lda_info(reference=reference, shortform=shortform, &
     184          229 :                                         needs=needs, max_deriv=max_deriv)
     185              :          END IF
     186              :       CASE ("BEEF")
     187           23 :          IF (lsd) THEN
     188              :             CALL xbeef_lsd_info(reference=reference, shortform=shortform, &
     189            0 :                                 needs=needs, max_deriv=max_deriv)
     190              :          ELSE
     191              :             CALL xbeef_lda_info(reference=reference, shortform=shortform, &
     192           67 :                                 needs=needs, max_deriv=max_deriv)
     193              :          END IF
     194              :       CASE ("BECKE88")
     195        13769 :          IF (lsd) THEN
     196              :             CALL xb88_lsd_info(reference=reference, shortform=shortform, &
     197         8769 :                                needs=needs, max_deriv=max_deriv)
     198              :          ELSE
     199              :             CALL xb88_lda_info(reference=reference, shortform=shortform, &
     200        32230 :                                needs=needs, max_deriv=max_deriv)
     201              :          END IF
     202              :       CASE ("BECKE88_LR")
     203         1633 :          IF (lsd) THEN
     204              :             CALL xb88_lr_lsd_info(reference=reference, shortform=shortform, &
     205          169 :                                   needs=needs, max_deriv=max_deriv)
     206              :          ELSE
     207              :             CALL xb88_lr_lda_info(reference=reference, shortform=shortform, &
     208         4712 :                                   needs=needs, max_deriv=max_deriv)
     209              :          END IF
     210              :       CASE ("LYP")
     211        11704 :          IF (lsd) THEN
     212              :             CALL lyp_lsd_info(reference=reference, shortform=shortform, &
     213         8566 :                               needs=needs, max_deriv=max_deriv)
     214              :          ELSE
     215              :             CALL lyp_lda_info(reference=reference, shortform=shortform, &
     216        26256 :                               needs=needs, max_deriv=max_deriv)
     217              :          END IF
     218              :       CASE ("PADE")
     219       270935 :          CALL pade_info(reference, shortform, lsd=lsd, needs=needs)
     220              :       CASE ("HCTH")
     221          589 :          CALL section_vals_val_get(functional, "PARAMETER_SET", i_val=i_param)
     222          589 :          CPASSERT(.NOT. lsd)
     223         1763 :          CALL hcth_lda_info(i_param, reference, shortform, needs, max_deriv)
     224              :       CASE ("OPTX")
     225          916 :          IF (lsd) THEN
     226         1441 :             CALL optx_lsd_info(reference, shortform, needs, max_deriv)
     227              :          ELSE
     228         1299 :             CALL optx_lda_info(reference, shortform, needs, max_deriv)
     229              :          END IF
     230              :       CASE ("CS1")
     231           33 :          IF (lsd) THEN
     232            0 :             CALL cs1_lsd_info(reference, shortform, needs, max_deriv)
     233              :          ELSE
     234           97 :             CALL cs1_lda_info(reference, shortform, needs=needs, max_deriv=max_deriv)
     235              :          END IF
     236              :       CASE ("XGGA")
     237           14 :          CALL section_vals_val_get(functional, "FUNCTIONAL", i_val=i_param)
     238           38 :          CALL xgga_info(i_param, lsd, reference, shortform, needs, max_deriv)
     239              :       CASE ("KE_GGA")
     240         2042 :          CALL section_vals_val_get(functional, "FUNCTIONAL", i_val=i_param)
     241         6126 :          CALL ke_gga_info(i_param, lsd, reference, shortform, needs, max_deriv)
     242              :       CASE ("P86C")
     243          215 :          IF (lsd) THEN
     244            0 :             CPABORT("BP functional not implemented with LSD")
     245              :          END IF
     246          631 :          CALL p86_lda_info(reference, shortform, needs, max_deriv)
     247              :       CASE ("PW92")
     248          337 :          CALL section_vals_val_get(functional, "PARAMETRIZATION", i_val=i_param)
     249          337 :          CALL section_vals_val_get(functional, "SCALE", r_val=r_param)
     250              :          CALL perdew_wang_info(i_param, lsd, reference, shortform, needs, max_deriv, &
     251          989 :                                r_param)
     252              :       CASE ("PZ81")
     253           39 :          CALL section_vals_val_get(functional, "PARAMETRIZATION", i_val=i_param)
     254          115 :          CALL pz_info(i_param, lsd, reference, shortform, needs, max_deriv)
     255              :       CASE ("TFW")
     256            0 :          IF (lsd) THEN
     257            0 :             CALL tfw_lsd_info(reference, shortform, needs, max_deriv)
     258              :          ELSE
     259            0 :             CALL tfw_lda_info(reference, shortform, needs, max_deriv)
     260              :          END IF
     261              :       CASE ("TF")
     262          672 :          CALL thomas_fermi_info(lsd, reference, shortform, needs, max_deriv)
     263              :       CASE ("VWN")
     264          966 :          IF (lsd) THEN
     265           56 :             CALL vwn_lsd_info(reference, shortform, needs, max_deriv)
     266              :          ELSE
     267         2792 :             CALL vwn_lda_info(reference, shortform, needs, max_deriv)
     268              :          END IF
     269              :       CASE ("XALPHA")
     270         3047 :          CALL section_vals_val_get(functional, "XA", r_val=r_param)
     271              :          CALL xalpha_info(lsd, reference, shortform, needs, max_deriv, &
     272         9065 :                           xa_parameter=r_param)
     273              :       CASE ("TPSS")
     274         2611 :          IF (lsd) THEN
     275            0 :             CPABORT("TPSS functional not implemented with LSD. Use the LIBXC version instead.")
     276              :          ELSE
     277         7787 :             CALL tpss_lda_info(functional, reference, shortform, needs, max_deriv)
     278              :          END IF
     279              :       CASE ("PBE")
     280       143699 :          IF (lsd) THEN
     281        83157 :             CALL pbe_lsd_info(functional, reference, shortform, needs, max_deriv)
     282              :          ELSE
     283       345674 :             CALL pbe_lda_info(functional, reference, shortform, needs, max_deriv)
     284              :          END IF
     285              :       CASE ("GAUXC")
     286          118 :          IF (gauxc_model_none_selected(functional)) THEN
     287              :             CALL gauxc_model_none_xc_info(functional, lsd, reference, shortform, &
     288          160 :                                           needs, max_deriv, print_warn)
     289              :          ELSE
     290          178 :             CALL skala_info(functional, lsd, reference, shortform, needs, max_deriv)
     291              :             ! Note: SKALA functional routes through apply_gauxc in qs_ks_methods.F
     292              :             ! when USE_GAUXC = .TRUE. (requires dft_control%use_gauxc to be set)
     293              :          END IF
     294              :       CASE ("SKALA_NATIVE")
     295         1387 :          CALL skala_info(functional, lsd, reference, shortform, needs, max_deriv)
     296              :       CASE ("XWPBE")
     297         4119 :          IF (lsd) THEN
     298         3488 :             CALL xwpbe_lsd_info(reference, shortform, needs, max_deriv)
     299              :          ELSE
     300         8847 :             CALL xwpbe_lda_info(reference, shortform, needs, max_deriv)
     301              :          END IF
     302              :       CASE ("BECKE_ROUSSEL")
     303          191 :          IF (lsd) THEN
     304          272 :             CALL xbecke_roussel_lsd_info(reference, shortform, needs, max_deriv)
     305              :          ELSE
     306          291 :             CALL xbecke_roussel_lda_info(reference, shortform, needs, max_deriv)
     307              :          END IF
     308              :       CASE ("LDA_HOLE_T_C_LR")
     309           90 :          IF (lsd) THEN
     310          187 :             CALL xlda_hole_t_c_lr_lsd_info(reference, shortform, needs, max_deriv)
     311              :          ELSE
     312           79 :             CALL xlda_hole_t_c_lr_lda_info(reference, shortform, needs, max_deriv)
     313              :          END IF
     314              :       CASE ("PBE_HOLE_T_C_LR")
     315         3606 :          IF (lsd) THEN
     316         3158 :             CALL xpbe_hole_t_c_lr_lsd_info(reference, shortform, needs, max_deriv)
     317              :          ELSE
     318         7652 :             CALL xpbe_hole_t_c_lr_lda_info(reference, shortform, needs, max_deriv)
     319              :          END IF
     320              :       CASE ("GV09")
     321          268 :          IF (lsd) THEN
     322          187 :             CALL xbr_pbe_lda_hole_tc_lr_lsd_info(reference, shortform, needs, max_deriv)
     323              :          ELSE
     324          613 :             CALL xbr_pbe_lda_hole_tc_lr_lda_info(reference, shortform, needs, max_deriv)
     325              :          END IF
     326              :       CASE default
     327              :          ! If the functional has not been implemented internally, it's from LibXC
     328       302243 :          IF (lsd) THEN
     329        12219 :             CALL libxc_spin_polarized_info(functional, reference, shortform, needs, max_deriv, print_warn)
     330              :          ELSE
     331        46954 :             CALL libxc_spin_unpolarized_info(functional, reference, shortform, needs, max_deriv, print_warn)
     332              :          END IF
     333              :       END SELECT
     334       302243 :    END SUBROUTINE xc_functional_get_info
     335              : 
     336              : ! **************************************************************************************************
     337              : !> \brief evaluate a functional (and its derivatives)
     338              : !> \param functional a section that describes the functional to be added
     339              : !> \param lsd if a local spin desnity is performed
     340              : !> \param rho_set a rho set where all the arguments needed by this functional
     341              : !>        should be valid (which argument are needed can be found with
     342              : !>        xc_functional_get_info)
     343              : !> \param deriv_set place where to store the functional derivatives (they are
     344              : !>        added to the derivatives)
     345              : !> \param deriv_order degree of the derivative that should be evaluated,
     346              : !>        if positive all the derivatives up to the given degree are evaluated,
     347              : !>        if negative only the given degree is requested (but to simplify
     348              : !>        the code all the derivatives might be calculated, you should ignore
     349              : !>        them when adding derivatives of various functionals they might contain
     350              : !>        the derivative of just one functional)
     351              : !> \par History
     352              : !>      11.2003 created [fawzi]
     353              : !> \author fawzi
     354              : ! **************************************************************************************************
     355       989130 :    SUBROUTINE xc_functional_eval(functional, lsd, rho_set, deriv_set, deriv_order)
     356              : 
     357              :       TYPE(section_vals_type), POINTER                   :: functional
     358              :       LOGICAL, INTENT(in)                                :: lsd
     359              :       TYPE(xc_rho_set_type), INTENT(IN)                  :: rho_set
     360              :       TYPE(xc_derivative_set_type), INTENT(IN)           :: deriv_set
     361              :       INTEGER, INTENT(IN)                                :: deriv_order
     362              : 
     363              :       CHARACTER(len=*), PARAMETER :: abort_message_skala = &
     364              :          "GauXC functionals are evaluated only through the QS GauXC path. "// &
     365              :          "Higher XC derivatives for response and kernel properties are not implemented.", &
     366              :          routineN = 'xc_functional_eval'
     367              : 
     368              :       INTEGER                                            :: handle, i_param
     369              :       LOGICAL                                            :: fun_active
     370              :       REAL(KIND=dp)                                      :: density_cut, gradient_cut, r_param
     371              : 
     372       329710 :       CALL timeset(routineN, handle)
     373              : 
     374              :       CALL xc_rho_set_get(rho_set, rho_cutoff=density_cut, &
     375       329710 :                           drho_cutoff=gradient_cut)
     376              :       CALL section_vals_val_get(functional, "_SECTION_PARAMETERS_", &
     377       329710 :                                 l_val=fun_active)
     378       329710 :       IF (.NOT. fun_active) THEN
     379          122 :          CALL timestop(handle)
     380          122 :          RETURN
     381              :       END IF
     382              : 
     383       329588 :       IF (deriv_order < 0) THEN
     384            0 :          CPABORT("Negative orders of derivative not allowed!")
     385              :       END IF
     386              : 
     387       330231 :       SELECT CASE (functional%section%name)
     388              :       CASE ("BECKE97")
     389          643 :          IF (lsd) THEN
     390            0 :             CALL b97_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     391              :          ELSE
     392          643 :             CALL b97_lda_eval(rho_set, deriv_set, deriv_order, functional)
     393              :          END IF
     394              :       CASE ("BECKE88_LR_ADIABATIC")
     395          176 :          IF (lsd) THEN
     396          104 :             CALL xb88_lr_adiabatic_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     397              :          ELSE
     398           72 :             CALL xb88_lr_adiabatic_lda_eval(rho_set, deriv_set, deriv_order, functional)
     399              :          END IF
     400              :       CASE ("LYP_ADIABATIC")
     401          176 :          IF (lsd) THEN
     402          104 :             CALL lyp_adiabatic_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     403              :          ELSE
     404           72 :             CALL lyp_adiabatic_lda_eval(rho_set, deriv_set, deriv_order, functional)
     405              :          END IF
     406              :       CASE ("BECKE88")
     407        12919 :          IF (lsd) THEN
     408         3146 :             CALL xb88_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     409              :          ELSE
     410         9773 :             CALL xb88_lda_eval(rho_set, deriv_set, deriv_order, functional)
     411              :          END IF
     412              :       CASE ("BEEF")
     413           18 :          IF (lsd) THEN
     414            0 :             CALL xbeef_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     415              :          ELSE
     416           18 :             CALL xbeef_lda_eval(rho_set, deriv_set, deriv_order, functional)
     417              :          END IF
     418              :       CASE ("BECKE88_LR")
     419         1190 :          IF (lsd) THEN
     420           52 :             CALL xb88_lr_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     421              :          ELSE
     422         1138 :             CALL xb88_lr_lda_eval(rho_set, deriv_set, deriv_order, functional)
     423              :          END IF
     424              :       CASE ("LYP")
     425        11555 :          IF (lsd) THEN
     426         3092 :             CALL lyp_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     427              :          ELSE
     428         8463 :             CALL lyp_lda_eval(rho_set, deriv_set, deriv_order, functional)
     429              :          END IF
     430              :       CASE ("PADE")
     431        98034 :          CALL pade_init(density_cut)
     432        98034 :          IF (lsd) THEN
     433        16783 :             CALL pade_lsd_pw_eval(deriv_set, rho_set, deriv_order)
     434              :          ELSE
     435        81251 :             CALL pade_lda_pw_eval(deriv_set, rho_set, deriv_order)
     436              :          END IF
     437              :       CASE ("HCTH")
     438          565 :          CPASSERT(.NOT. lsd)
     439          565 :          CALL section_vals_val_get(functional, "PARAMETER_SET", i_val=i_param)
     440          565 :          CALL hcth_lda_eval(i_param, rho_set, deriv_set, deriv_order)
     441              :       CASE ("OPTX")
     442         1040 :          IF (lsd) THEN
     443          476 :             CALL optx_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     444              :          ELSE
     445          564 :             CALL optx_lda_eval(rho_set, deriv_set, deriv_order, functional)
     446              :          END IF
     447              :       CASE ("CS1")
     448           32 :          IF (lsd) THEN
     449            0 :             CALL cs1_lsd_eval(rho_set, deriv_set, deriv_order)
     450              :          ELSE
     451           32 :             CALL cs1_lda_eval(rho_set, deriv_set, deriv_order)
     452              :          END IF
     453              :       CASE ("XGGA")
     454            4 :          CALL section_vals_val_get(functional, "FUNCTIONAL", i_val=i_param)
     455            4 :          CALL xgga_eval(i_param, lsd, rho_set, deriv_set, deriv_order)
     456              :       CASE ("KE_GGA")
     457         1780 :          CALL section_vals_val_get(functional, "FUNCTIONAL", i_val=i_param)
     458         1780 :          IF (lsd) THEN
     459            0 :             CALL ke_gga_lsd_eval(i_param, rho_set, deriv_set, deriv_order)
     460              :          ELSE
     461         1780 :             CALL ke_gga_lda_eval(i_param, rho_set, deriv_set, deriv_order)
     462              :          END IF
     463              :       CASE ("P86C")
     464          180 :          CPASSERT(.NOT. lsd)
     465          180 :          CALL p86_lda_eval(rho_set, deriv_set, deriv_order, functional)
     466              :       CASE ("PW92")
     467          240 :          CALL section_vals_val_get(functional, "PARAMETRIZATION", i_val=i_param)
     468          240 :          CALL section_vals_val_get(functional, "SCALE", r_val=r_param)
     469          240 :          IF (lsd) THEN
     470              :             CALL perdew_wang_lsd_eval(i_param, rho_set, deriv_set, deriv_order, &
     471           20 :                                       r_param)
     472              :          ELSE
     473              :             CALL perdew_wang_lda_eval(i_param, rho_set, deriv_set, deriv_order, &
     474          220 :                                       r_param)
     475              :          END IF
     476              :       CASE ("PZ81")
     477           50 :          CALL section_vals_val_get(functional, "PARAMETRIZATION", i_val=i_param)
     478           50 :          IF (lsd) THEN
     479           12 :             CALL pz_lsd_eval(i_param, rho_set, deriv_set, deriv_order, functional)
     480              :          ELSE
     481           38 :             CALL pz_lda_eval(i_param, rho_set, deriv_set, deriv_order, functional)
     482              :          END IF
     483              :       CASE ("TFW")
     484            0 :          IF (lsd) THEN
     485            0 :             CALL tfw_lsd_eval(rho_set, deriv_set, deriv_order)
     486              :          ELSE
     487            0 :             CALL tfw_lda_eval(rho_set, deriv_set, deriv_order)
     488              :          END IF
     489              :       CASE ("TF")
     490          216 :          IF (lsd) THEN
     491            0 :             CALL thomas_fermi_lsd_eval(rho_set, deriv_set, deriv_order)
     492              :          ELSE
     493          216 :             CALL thomas_fermi_lda_eval(rho_set, deriv_set, deriv_order)
     494              :          END IF
     495              :       CASE ("VWN")
     496         1163 :          IF (lsd) THEN
     497           32 :             CALL vwn_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     498              :          ELSE
     499         1131 :             CALL vwn_lda_eval(rho_set, deriv_set, deriv_order, functional)
     500              :          END IF
     501              :       CASE ("XALPHA")
     502         2727 :          CALL section_vals_val_get(functional, "XA", r_val=r_param)
     503         2727 :          IF (lsd) THEN
     504              :             CALL xalpha_lsd_eval(rho_set, deriv_set, deriv_order, &
     505          166 :                                  xa_parameter=r_param, xa_params=functional)
     506              :          ELSE
     507              :             CALL xalpha_lda_eval(rho_set, deriv_set, deriv_order, &
     508         2561 :                                  xa_parameter=r_param, xa_params=functional)
     509              :          END IF
     510              :       CASE ("TPSS")
     511         3386 :          IF (lsd) THEN
     512            0 :             CPABORT("TPSS functional not implemented with LSD. Use the LIBXC version instead.")
     513              :          ELSE
     514         3386 :             CALL tpss_lda_eval(rho_set, deriv_set, deriv_order, functional)
     515              :          END IF
     516              :       CASE ("PBE")
     517       160000 :          IF (lsd) THEN
     518        27847 :             CALL pbe_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     519              :          ELSE
     520       132153 :             CALL pbe_lda_eval(rho_set, deriv_set, deriv_order, functional)
     521              :          END IF
     522              :       CASE ("GAUXC")
     523            0 :          IF (gauxc_model_none_selected(functional)) THEN
     524            0 :             CALL gauxc_model_none_xc_eval(functional, lsd, rho_set, deriv_set, deriv_order)
     525              :          ELSE
     526            0 :             CPABORT(abort_message_skala)
     527              :          END IF
     528              :       CASE ("SKALA_NATIVE")
     529            0 :          CPABORT(abort_message_skala)
     530              :       CASE ("XWPBE")
     531         5064 :          IF (lsd) THEN
     532         1324 :             CALL xwpbe_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     533              :          ELSE
     534         3740 :             CALL xwpbe_lda_eval(rho_set, deriv_set, deriv_order, functional)
     535              :          END IF
     536              :       CASE ("BECKE_ROUSSEL")
     537          166 :          IF (lsd) THEN
     538           82 :             CALL xbecke_roussel_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     539              :          ELSE
     540           84 :             CALL xbecke_roussel_lda_eval(rho_set, deriv_set, deriv_order, functional)
     541              :          END IF
     542              :       CASE ("LDA_HOLE_T_C_LR")
     543           80 :          IF (lsd) THEN
     544           58 :             CALL xlda_hole_t_c_lr_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     545              :          ELSE
     546           22 :             CALL xlda_hole_t_c_lr_lda_eval(rho_set, deriv_set, deriv_order, functional)
     547              :          END IF
     548              :       CASE ("PBE_HOLE_T_C_LR")
     549         4318 :          IF (lsd) THEN
     550         1196 :             CALL xpbe_hole_t_c_lr_lsd_eval(rho_set, deriv_set, deriv_order, functional)
     551              :          ELSE
     552         3122 :             CALL xpbe_hole_t_c_lr_lda_eval(rho_set, deriv_set, deriv_order, functional)
     553              :          END IF
     554              :       CASE ("GV09")
     555          258 :          IF (lsd) THEN
     556              :             CALL xbr_pbe_lda_hole_tc_lr_lsd_eval(rho_set, deriv_set, deriv_order, &
     557           58 :                                                  functional)
     558              :          ELSE
     559              :             CALL xbr_pbe_lda_hole_tc_lr_lda_eval(rho_set, deriv_set, deriv_order, &
     560          200 :                                                  functional)
     561              :          END IF
     562              :       CASE default
     563              :          ! If functional not natively supported, ask LibXC
     564       330153 :          IF (lsd) THEN
     565         3904 :             CALL libxc_spin_polarized_eval(rho_set, deriv_set, deriv_order, functional)
     566              :          ELSE
     567        19704 :             CALL libxc_spin_unpolarized_eval(rho_set, deriv_set, deriv_order, functional)
     568              :          END IF
     569              :       END SELECT
     570              : 
     571       329588 :       CALL timestop(handle)
     572              :    END SUBROUTINE xc_functional_eval
     573              : 
     574              : ! **************************************************************************************************
     575              : !> \brief true for GAUXC sections that wrap a conventional LibXC functional
     576              : !> \param functional the GAUXC section
     577              : !> \return whether MODEL NONE is active
     578              : ! **************************************************************************************************
     579          118 :    FUNCTION gauxc_model_none_selected(functional)
     580              :       TYPE(section_vals_type), POINTER                   :: functional
     581              :       LOGICAL                                            :: gauxc_model_none_selected
     582              : 
     583              :       CHARACTER(LEN=default_string_length)               :: model_key, model_name, xc_fun_name, &
     584              :                                                             xc_key
     585              : 
     586          118 :       CALL section_vals_val_get(functional, "MODEL", c_val=model_name)
     587          118 :       CALL section_vals_val_get(functional, "FUNCTIONAL", c_val=xc_fun_name)
     588          118 :       model_key = ADJUSTL(model_name)
     589          118 :       xc_key = ADJUSTL(xc_fun_name)
     590          118 :       CALL uppercase(model_key)
     591          118 :       CALL uppercase(xc_key)
     592              :       gauxc_model_none_selected = (TRIM(model_key) == "" .OR. TRIM(model_key) == "NONE" .OR. &
     593          118 :                                    TRIM(model_key) == TRIM(xc_key))
     594          118 :    END FUNCTION gauxc_model_none_selected
     595              : 
     596              : ! **************************************************************************************************
     597              : !> \brief map GAUXC MODEL NONE shorthand names to LibXC exchange/correlation components
     598              : !> \param functional the GAUXC section
     599              : !> \param xc_fun_name the GAUXC FUNCTIONAL value
     600              : !> \param libxc_names LibXC section names to evaluate and add
     601              : !> \param nfunc number of LibXC components
     602              : ! **************************************************************************************************
     603          112 :    SUBROUTINE gauxc_model_none_libxc_names(functional, xc_fun_name, libxc_names, nfunc)
     604              :       TYPE(section_vals_type), POINTER                   :: functional
     605              :       CHARACTER(LEN=*), INTENT(OUT)                      :: xc_fun_name
     606              :       CHARACTER(LEN=*), DIMENSION(:), INTENT(OUT)        :: libxc_names
     607              :       INTEGER, INTENT(OUT)                               :: nfunc
     608              : 
     609              :       CHARACTER(LEN=default_string_length)               :: xc_key
     610              : 
     611           56 :       CALL section_vals_val_get(functional, "FUNCTIONAL", c_val=xc_fun_name)
     612           56 :       xc_key = ADJUSTL(xc_fun_name)
     613           56 :       CALL uppercase(xc_key)
     614          168 :       libxc_names(:) = ""
     615           56 :       SELECT CASE (TRIM(xc_key))
     616              :       CASE ("LDA", "PADE")
     617            0 :          nfunc = 2
     618            0 :          libxc_names(1) = "LDA_X"
     619            0 :          libxc_names(2) = "LDA_C_PW"
     620              :       CASE ("VWN")
     621            0 :          nfunc = 2
     622            0 :          libxc_names(1) = "LDA_X"
     623            0 :          libxc_names(2) = "LDA_C_VWN"
     624              :       CASE ("PBE")
     625           56 :          nfunc = 2
     626           56 :          libxc_names(1) = "GGA_X_PBE"
     627           56 :          libxc_names(2) = "GGA_C_PBE"
     628              :       CASE ("BLYP")
     629            0 :          nfunc = 2
     630            0 :          libxc_names(1) = "GGA_X_B88"
     631            0 :          libxc_names(2) = "GGA_C_LYP"
     632              :       CASE ("BP")
     633            0 :          nfunc = 2
     634            0 :          libxc_names(1) = "GGA_X_B88"
     635            0 :          libxc_names(2) = "GGA_C_P86"
     636              :       CASE ("TPSS")
     637            0 :          nfunc = 2
     638            0 :          libxc_names(1) = "MGGA_X_TPSS"
     639            0 :          libxc_names(2) = "MGGA_C_TPSS"
     640              :       CASE ("R2SCAN")
     641            0 :          nfunc = 2
     642            0 :          libxc_names(1) = "MGGA_X_R2SCAN"
     643            0 :          libxc_names(2) = "MGGA_C_R2SCAN"
     644              :       CASE DEFAULT
     645            0 :          nfunc = 1
     646           56 :          libxc_names(1) = TRIM(xc_key)
     647              :       END SELECT
     648           56 :    END SUBROUTINE gauxc_model_none_libxc_names
     649              : 
     650              : ! **************************************************************************************************
     651              : !> \brief needs information for GAUXC MODEL NONE one-center GAPW corrections
     652              : !> \param functional the GAUXC section
     653              : !> \param lsd whether spin-polarized derivatives are needed
     654              : !> \param reference reference string for the wrapped functional
     655              : !> \param shortform short name for printout
     656              : !> \param needs density ingredients needed by the wrapped functional
     657              : !> \param max_deriv maximum implemented derivative order
     658              : !> \param print_warn whether LibXC should print development warnings
     659              : ! **************************************************************************************************
     660           56 :    SUBROUTINE gauxc_model_none_xc_info(functional, lsd, reference, shortform, &
     661              :                                        needs, max_deriv, print_warn)
     662              :       TYPE(section_vals_type), POINTER                   :: functional
     663              :       LOGICAL, INTENT(in)                                :: lsd
     664              :       CHARACTER(LEN=*), INTENT(OUT), OPTIONAL            :: reference, shortform
     665              :       TYPE(xc_rho_cflags_type), INTENT(inout), OPTIONAL  :: needs
     666              :       INTEGER, INTENT(out), OPTIONAL                     :: max_deriv
     667              :       LOGICAL, INTENT(IN), OPTIONAL                      :: print_warn
     668              : 
     669              :       CHARACTER(LEN=default_string_length)               :: libxc_names(2), xc_fun_name
     670              :       INTEGER                                            :: ifunc, max_deriv_i, max_deriv_min, nfunc
     671              : 
     672           56 :       CALL gauxc_model_none_libxc_names(functional, xc_fun_name, libxc_names, nfunc)
     673           56 :       max_deriv_min = HUGE(max_deriv_min)
     674          168 :       DO ifunc = 1, nfunc
     675          112 :          IF (lsd) THEN
     676              :             CALL libxc_spin_polarized_info(functional, needs=needs, max_deriv=max_deriv_i, &
     677              :                                            print_warn=print_warn, &
     678           24 :                                            func_name_override=TRIM(libxc_names(ifunc)))
     679              :          ELSE
     680              :             CALL libxc_spin_unpolarized_info(functional, needs=needs, max_deriv=max_deriv_i, &
     681              :                                              print_warn=print_warn, &
     682           88 :                                              func_name_override=TRIM(libxc_names(ifunc)))
     683              :          END IF
     684          168 :          max_deriv_min = MIN(max_deriv_min, max_deriv_i)
     685              :       END DO
     686           56 :       IF (PRESENT(max_deriv)) max_deriv = max_deriv_min
     687           56 :       IF (PRESENT(reference)) THEN
     688            4 :          reference = "Functional computed by GauXC (underlying: "//TRIM(xc_fun_name)//")"
     689              :       END IF
     690           56 :       IF (PRESENT(shortform)) shortform = "GAUXC ("//TRIM(xc_fun_name)//")"
     691           56 :    END SUBROUTINE gauxc_model_none_xc_info
     692              : 
     693              : ! **************************************************************************************************
     694              : !> \brief one-center GAPW correction evaluation for GAUXC MODEL NONE
     695              : !> \param functional the GAUXC section
     696              : !> \param lsd whether spin-polarized derivatives are evaluated
     697              : !> \param rho_set density ingredients
     698              : !> \param deriv_set derivative accumulator
     699              : !> \param deriv_order derivative order to evaluate
     700              : ! **************************************************************************************************
     701            0 :    SUBROUTINE gauxc_model_none_xc_eval(functional, lsd, rho_set, deriv_set, deriv_order)
     702              :       TYPE(section_vals_type), POINTER                   :: functional
     703              :       LOGICAL, INTENT(in)                                :: lsd
     704              :       TYPE(xc_rho_set_type), INTENT(IN)                  :: rho_set
     705              :       TYPE(xc_derivative_set_type), INTENT(IN)           :: deriv_set
     706              :       INTEGER, INTENT(IN)                                :: deriv_order
     707              : 
     708              :       CHARACTER(LEN=default_string_length)               :: libxc_names(2), xc_fun_name
     709              :       INTEGER                                            :: ifunc, nfunc
     710              : 
     711            0 :       CALL gauxc_model_none_libxc_names(functional, xc_fun_name, libxc_names, nfunc)
     712            0 :       DO ifunc = 1, nfunc
     713            0 :          IF (lsd) THEN
     714              :             CALL libxc_spin_polarized_eval(rho_set, deriv_set, deriv_order, functional, &
     715            0 :                                            func_name_override=TRIM(libxc_names(ifunc)))
     716              :          ELSE
     717              :             CALL libxc_spin_unpolarized_eval(rho_set, deriv_set, deriv_order, functional, &
     718            0 :                                              func_name_override=TRIM(libxc_names(ifunc)))
     719              :          END IF
     720              :       END DO
     721            0 :    END SUBROUTINE gauxc_model_none_xc_eval
     722              : 
     723              : ! **************************************************************************************************
     724              : !> \brief ...
     725              : !> \param functionals a section containing the functional combination to be
     726              : !>        applied
     727              : !> \param lsd if a local spin desnity is performed
     728              : !> \param rho_set a rho set where all the arguments needed by this functional
     729              : !>        should be valid (which argument are needed can be found with
     730              : !>        xc_functional_get_info)
     731              : !> \param deriv_set place where to store the functional derivatives (they are
     732              : !>        added to the derivatives)
     733              : !> \param deriv_order degree of the derivative that should be evaluated,
     734              : !>        if positive all the derivatives up to the given degree are evaluated,
     735              : !>        if negative only the given degree is requested (but to simplify
     736              : !>        the code all the derivatives might be calculated, you should ignore
     737              : !>        them when adding derivatives of various functionals they might contain
     738              : !>        the derivative of just one functional)
     739              : !> \author fawzi
     740              : ! **************************************************************************************************
     741       296101 :    SUBROUTINE xc_functionals_eval(functionals, lsd, rho_set, deriv_set, &
     742              :                                   deriv_order)
     743              :       TYPE(section_vals_type), POINTER                   :: functionals
     744              :       LOGICAL, INTENT(in)                                :: lsd
     745              :       TYPE(xc_rho_set_type), INTENT(IN)                  :: rho_set
     746              :       TYPE(xc_derivative_set_type), INTENT(IN)           :: deriv_set
     747              :       INTEGER, INTENT(in)                                :: deriv_order
     748              : 
     749              :       INTEGER                                            :: ifun
     750              :       TYPE(section_vals_type), POINTER                   :: xc_fun
     751              : 
     752       296101 :       CPASSERT(ASSOCIATED(functionals))
     753       296101 :       ifun = 0
     754       329710 :       DO
     755       625811 :          ifun = ifun + 1
     756       625811 :          xc_fun => section_vals_get_subs_vals2(functionals, i_section=ifun)
     757       625811 :          IF (.NOT. ASSOCIATED(xc_fun)) EXIT
     758              :          CALL xc_functional_eval(xc_fun, &
     759              :                                  lsd=lsd, &
     760              :                                  rho_set=rho_set, &
     761              :                                  deriv_set=deriv_set, &
     762       329710 :                                  deriv_order=deriv_order)
     763              :       END DO
     764       296101 :    END SUBROUTINE xc_functionals_eval
     765              : 
     766              : ! **************************************************************************************************
     767              : !> \brief ...
     768              : !> \param functionals a section containing the functional combination to be
     769              : !>        applied
     770              : !> \param lsd if a local spin desnity is performed
     771              : !> \param calc_potential set, if potential calculation will be carried out later.
     772              : !>        helps to save memory and flops. defaults to false.
     773              : !> \return ...
     774              : !> \author fawzi
     775              : ! **************************************************************************************************
     776       280189 :    FUNCTION xc_functionals_get_needs(functionals, lsd, calc_potential) &
     777              :       RESULT(needs)
     778              :       TYPE(section_vals_type), POINTER                   :: functionals
     779              :       LOGICAL, INTENT(in)                                :: lsd
     780              :       LOGICAL, INTENT(in), OPTIONAL                      :: calc_potential
     781              :       TYPE(xc_rho_cflags_type)                           :: needs
     782              : 
     783              :       INTEGER                                            :: ifun
     784              :       LOGICAL                                            :: my_calc_potential
     785              :       TYPE(section_vals_type), POINTER                   :: xc_fun
     786              : 
     787       280189 :       my_calc_potential = .FALSE.
     788       280189 :       IF (PRESENT(calc_potential)) my_calc_potential = calc_potential
     789              : 
     790       280189 :       CPASSERT(ASSOCIATED(functionals))
     791       280189 :       CALL xc_rho_cflags_setall(needs, .FALSE.)
     792              : 
     793       280189 :       ifun = 0
     794       299968 :       DO
     795       580157 :          ifun = ifun + 1
     796       580157 :          xc_fun => section_vals_get_subs_vals2(functionals, i_section=ifun)
     797       580157 :          IF (.NOT. ASSOCIATED(xc_fun)) EXIT
     798       299968 :          CALL xc_functional_get_info(xc_fun, lsd=lsd, needs=needs)
     799              :       END DO
     800              : 
     801       280189 :       IF (my_calc_potential) THEN
     802       224671 :          IF (lsd) THEN
     803        43969 :             needs%rho_spin = .TRUE.
     804        86562 :             needs%tau_spin = needs%tau_spin .OR. needs%tau
     805              :          ELSE
     806       180702 :             needs%rho = .TRUE.
     807              :          END IF
     808       224671 :          IF (needs%norm_drho .OR. needs%norm_drho_spin) THEN
     809       135867 :             IF (lsd) THEN
     810        27510 :                needs%drho_spin = .TRUE.
     811              :             ELSE
     812       108357 :                needs%drho = .TRUE.
     813              :             END IF
     814              :          END IF
     815              :       END IF
     816       280189 :    END FUNCTION xc_functionals_get_needs
     817              : 
     818              : END MODULE xc_derivatives
        

Generated by: LCOV version 2.0-1