LCOV - code coverage report
Current view: top level - src - qs_gamma2kp.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:2fce0f8) Lines: 37 42 88.1 %
Date: 2024-12-21 06:28:57 Functions: 1 1 100.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief Initialize a qs_env for kpoint calculations starting from a gamma point qs_env
      10             : !> \par History
      11             : !>      11.2016 created [JGH]
      12             : !> \author JGH
      13             : ! **************************************************************************************************
      14             : MODULE qs_gamma2kp
      15             :    USE cp_dbcsr_api,                    ONLY: dbcsr_add,&
      16             :                                               dbcsr_p_type
      17             :    USE cp_subsys_types,                 ONLY: cp_subsys_type
      18             :    USE input_constants,                 ONLY: atomic_guess,&
      19             :                                               xc_none
      20             :    USE input_section_types,             ONLY: section_vals_get_subs_vals,&
      21             :                                               section_vals_type,&
      22             :                                               section_vals_val_get,&
      23             :                                               section_vals_val_set
      24             :    USE kinds,                           ONLY: dp
      25             :    USE kpoint_types,                    ONLY: kpoint_create,&
      26             :                                               kpoint_type
      27             :    USE message_passing,                 ONLY: mp_para_env_type
      28             :    USE pw_methods,                      ONLY: pw_copy
      29             :    USE pw_types,                        ONLY: pw_c1d_gs_type,&
      30             :                                               pw_r3d_rs_type
      31             :    USE qs_energy_init,                  ONLY: qs_energies_init
      32             :    USE qs_environment,                  ONLY: qs_init
      33             :    USE qs_environment_types,            ONLY: get_qs_env,&
      34             :                                               qs_env_create,&
      35             :                                               qs_environment_type,&
      36             :                                               set_qs_env
      37             :    USE qs_ks_methods,                   ONLY: qs_ks_update_qs_env
      38             :    USE qs_rho_types,                    ONLY: qs_rho_get,&
      39             :                                               qs_rho_type
      40             :    USE qs_scf_initialization,           ONLY: qs_scf_env_init_basic
      41             :    USE qs_scf_types,                    ONLY: qs_scf_env_type
      42             :    USE scf_control_types,               ONLY: scf_control_type
      43             : #include "./base/base_uses.f90"
      44             : 
      45             :    IMPLICIT NONE
      46             :    PRIVATE
      47             : 
      48             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_gamma2kp'
      49             : 
      50             :    PUBLIC :: create_kp_from_gamma
      51             : 
      52             : ! **************************************************************************************************
      53             : 
      54             : CONTAINS
      55             : 
      56             : ! **************************************************************************************************
      57             : !> \brief ...
      58             : !> \param qs_env ...
      59             : !> \param qs_env_kp ...
      60             : !> \param with_xc_terms ...
      61             : ! **************************************************************************************************
      62           4 :    SUBROUTINE create_kp_from_gamma(qs_env, qs_env_kp, with_xc_terms)
      63             :       TYPE(qs_environment_type), POINTER                 :: qs_env, qs_env_kp
      64             :       LOGICAL, OPTIONAL                                  :: with_xc_terms
      65             : 
      66             :       INTEGER                                            :: ispin, xc_func
      67             :       LOGICAL                                            :: without_xc_terms
      68             :       TYPE(cp_subsys_type), POINTER                      :: cp_subsys
      69           2 :       TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER       :: rho_ao_kp, rho_ao_kp_gamma
      70             :       TYPE(kpoint_type), POINTER                         :: kpoint
      71             :       TYPE(mp_para_env_type), POINTER                    :: para_env
      72           2 :       TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER        :: rho_g_gamma, rho_g_kp
      73           2 :       TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER        :: rho_r_gamma, rho_r_kp
      74             :       TYPE(qs_rho_type), POINTER                         :: rho, rho_gamma
      75             :       TYPE(qs_scf_env_type), POINTER                     :: scf_env
      76             :       TYPE(scf_control_type), POINTER                    :: scf_control
      77             :       TYPE(section_vals_type), POINTER                   :: force_env_section, subsys_section, &
      78             :                                                             xc_fun_section
      79             : 
      80             :       CALL get_qs_env(qs_env, &
      81             :                       para_env=para_env, &
      82             :                       input=force_env_section, &
      83           2 :                       cp_subsys=cp_subsys)
      84             : 
      85           2 :       NULLIFY (subsys_section)
      86             : 
      87           2 :       NULLIFY (kpoint)
      88           2 :       CALL kpoint_create(kpoint)
      89           2 :       kpoint%kp_scheme = "GAMMA"
      90           2 :       kpoint%symmetry = .FALSE.
      91           2 :       kpoint%verbose = .FALSE.
      92           2 :       kpoint%full_grid = .TRUE.
      93           2 :       kpoint%eps_geo = 1.0e-6_dp
      94           2 :       kpoint%use_real_wfn = .TRUE.
      95           2 :       kpoint%parallel_group_size = 0
      96             : 
      97           2 :       without_xc_terms = .FALSE.
      98           2 :       IF (PRESENT(with_xc_terms)) without_xc_terms = .NOT. with_xc_terms
      99             : 
     100           0 :       IF (without_xc_terms) THEN
     101           0 :          xc_fun_section => section_vals_get_subs_vals(force_env_section, "DFT%XC%XC_FUNCTIONAL")
     102           0 :          CALL section_vals_val_get(xc_fun_section, "_SECTION_PARAMETERS_", i_val=xc_func)
     103           0 :          CALL section_vals_val_set(xc_fun_section, "_SECTION_PARAMETERS_", i_val=xc_none)
     104             :       END IF
     105             : 
     106           2 :       ALLOCATE (qs_env_kp)
     107           2 :       CALL qs_env_create(qs_env_kp)
     108             :       CALL qs_init(qs_env_kp, para_env, cp_subsys=cp_subsys, kpoint_env=kpoint, &
     109             :                    force_env_section=force_env_section, subsys_section=subsys_section, &
     110           2 :                    use_motion_section=.FALSE., silent=.TRUE.)
     111             : 
     112           2 :       CALL get_qs_env(qs_env_kp, scf_control=scf_control)
     113           2 :       scf_control%density_guess = atomic_guess
     114           2 :       CALL qs_energies_init(qs_env_kp, calc_forces=.FALSE.)
     115             : 
     116           2 :       NULLIFY (scf_env)
     117           2 :       CALL qs_scf_env_init_basic(qs_env_kp, scf_env)
     118             : 
     119           2 :       CALL set_qs_env(qs_env_kp, scf_env=scf_env)
     120             : 
     121             :       ! copy density matrix, n(r) and n(G) from Gamma-only to kpoint calculation
     122           2 :       CALL get_qs_env(qs_env, rho=rho_gamma)
     123           2 :       CALL qs_rho_get(rho_gamma, rho_ao_kp=rho_ao_kp_gamma, rho_r=rho_r_gamma, rho_g=rho_g_gamma)
     124           2 :       CALL get_qs_env(qs_env_kp, rho=rho)
     125           2 :       CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp, rho_r=rho_r_kp, rho_g=rho_g_kp)
     126             : 
     127           4 :       DO ispin = 1, SIZE(rho_r_gamma)
     128           2 :          CALL pw_copy(rho_r_gamma(ispin), rho_r_kp(ispin))
     129           2 :          CALL pw_copy(rho_g_gamma(ispin), rho_g_kp(ispin))
     130             :          CALL dbcsr_add(matrix_a=rho_ao_kp(ispin, 1)%matrix, alpha_scalar=0.0_dp, &
     131           4 :                         matrix_b=rho_ao_kp_gamma(ispin, 1)%matrix, beta_scalar=1.0_dp)
     132             :       END DO
     133             : 
     134           2 :       CALL qs_ks_update_qs_env(qs_env_kp, print_active=.FALSE.)
     135             : 
     136           2 :       IF (without_xc_terms) THEN
     137             :          ! set back the functional
     138           0 :          CALL section_vals_val_set(xc_fun_section, "_SECTION_PARAMETERS_", i_val=xc_func)
     139             :       END IF
     140             : 
     141           2 :    END SUBROUTINE create_kp_from_gamma
     142             : 
     143             : END MODULE qs_gamma2kp

Generated by: LCOV version 1.15