LCOV - code coverage report
Current view: top level - src - post_scf_bandstructure_types.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4c33f95) Lines: 154 155 99.4 %
Date: 2025-01-30 06:53:08 Functions: 12 17 70.6 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2025 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief
      10             : !> \author Jan Wilhelm
      11             : !> \date 07.2023
      12             : ! **************************************************************************************************
      13             : MODULE post_scf_bandstructure_types
      14             :    USE basis_set_types,                 ONLY: gto_basis_set_p_type
      15             :    USE cp_cfm_types,                    ONLY: cp_cfm_release,&
      16             :                                               cp_cfm_type
      17             :    USE cp_dbcsr_api,                    ONLY: dbcsr_p_type,&
      18             :                                               dbcsr_release
      19             :    USE cp_dbcsr_operations,             ONLY: dbcsr_deallocate_matrix_set
      20             :    USE cp_fm_types,                     ONLY: cp_fm_release,&
      21             :                                               cp_fm_type
      22             :    USE dbt_api,                         ONLY: dbt_destroy,&
      23             :                                               dbt_type
      24             :    USE input_constants,                 ONLY: rtp_method_bse,&
      25             :                                               small_cell_full_kp
      26             :    USE kinds,                           ONLY: default_string_length,&
      27             :                                               dp
      28             :    USE kpoint_types,                    ONLY: kpoint_release,&
      29             :                                               kpoint_type
      30             :    USE libint_2c_3c,                    ONLY: libint_potential_type
      31             :    USE message_passing,                 ONLY: mp_para_env_release,&
      32             :                                               mp_para_env_type
      33             :    USE qs_tensors_types,                ONLY: neighbor_list_3c_type
      34             : #include "./base/base_uses.f90"
      35             : 
      36             :    IMPLICIT NONE
      37             : 
      38             :    PRIVATE
      39             : 
      40             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'post_scf_bandstructure_types'
      41             : 
      42             :    PUBLIC :: post_scf_bandstructure_type, band_edges_type, data_3_type, bs_env_release
      43             : 
      44             :    ! valence band maximum (VBM), conduction band minimum (CBM), direct band gap (DBG),
      45             :    ! indirect band gap (IDBG)
      46             :    TYPE band_edges_type
      47             :       REAL(KIND=dp)                                   :: VBM = -1.0_dp, &
      48             :                                                          CBM = -1.0_dp, &
      49             :                                                          DBG = -1.0_dp, &
      50             :                                                          IDBG = -1.0_dp
      51             :    END TYPE band_edges_type
      52             : 
      53             :    ! data type for storing 3-index quantities for small-cell, full-k-points GW code
      54             :    TYPE data_3_type
      55             :       REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE :: data_3
      56             :    END TYPE data_3_type
      57             : 
      58             :    TYPE post_scf_bandstructure_type
      59             : 
      60             :       ! decide which calculations will be done
      61             :       LOGICAL                                         :: do_gw = .FALSE., &
      62             :                                                          do_soc = .FALSE., &
      63             :                                                          do_ldos = .FALSE.
      64             : 
      65             :       ! various eigenvalues computed in GW code, some depend on k-points
      66             :       ! and have therefore three dimensions (band index, k-point, spin)
      67             :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE     :: eigenval_scf_Gamma
      68             :       REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE  :: eigenval_scf, &
      69             :                                                          eigenval_G0W0, &
      70             :                                                          eigenval_HF, &
      71             :                                                          eigenval_scGW0
      72             :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE     :: eigenval_scf_soc, &
      73             :                                                          eigenval_G0W0_soc
      74             :       TYPE(band_edges_type), DIMENSION(2)             :: band_edges_scf_Gamma = band_edges_type()
      75             :       TYPE(band_edges_type)                           :: band_edges_scf = band_edges_type(), &
      76             :                                                          band_edges_G0W0 = band_edges_type(), &
      77             :                                                          band_edges_HF = band_edges_type()
      78             : 
      79             :       ! parameters that influence the GW flavor
      80             :       LOGICAL                                         :: do_hedin_shift = .FALSE.
      81             : 
      82             :       ! general parameters on molecular orbitals and basis sets
      83             :       INTEGER                                      :: n_ao = -1, &
      84             :                                                       n_RI = -1, &
      85             :                                                       n_spin = -1, &
      86             :                                                       n_atom = -1, &
      87             :                                                       max_AO_bf_per_atom = -1
      88             :       INTEGER, DIMENSION(:), ALLOCATABLE           :: i_ao_start_from_atom, &
      89             :                                                       i_ao_end_from_atom, &
      90             :                                                       i_RI_start_from_atom, &
      91             :                                                       i_RI_end_from_atom
      92             :       INTEGER, DIMENSION(2)                        :: n_occ = -1, &
      93             :                                                       n_vir = -1
      94             :       REAL(KIND=dp)                                :: spin_degeneracy = -1.0_dp
      95             :       REAL(KIND=dp), DIMENSION(2)                  :: e_fermi = -1.0_dp
      96             : 
      97             :       ! kpoint mesh for chi, eps, W
      98             :       INTEGER, DIMENSION(:), POINTER               :: nkp_grid_DOS_input => NULL(), &
      99             :                                                       nkp_grid_chi_eps_W_input => NULL()
     100             :       INTEGER, DIMENSION(3)                        :: nkp_grid_chi_eps_W_orig = -1, &
     101             :                                                       nkp_grid_chi_eps_W_extra = -1
     102             :       INTEGER                                      :: nkp_chi_eps_W_orig = -1, &
     103             :                                                       nkp_chi_eps_W_extra = -1, &
     104             :                                                       nkp_chi_eps_W_orig_plus_extra = -1, &
     105             :                                                       nkp_chi_eps_W_batch = -1, &
     106             :                                                       num_chi_eps_W_batches = -1, &
     107             :                                                       size_lattice_sum_V = -1
     108             :       TYPE(kpoint_type), POINTER                   :: kpoints_chi_eps_W => NULL(), &
     109             :                                                       kpoints_DOS => NULL()
     110             :       LOGICAL                                      :: approx_kp_extrapol = .FALSE.
     111             : 
     112             :       REAL(KIND=dp)                                :: wkp_orig = -1.0_dp
     113             :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE     :: wkp_s_p, &
     114             :                                                       wkp_no_extra
     115             :       INTEGER, DIMENSION(:), ALLOCATABLE           :: l_RI
     116             :       INTEGER                                      :: input_kp_bs_npoints = -1, &
     117             :                                                       input_kp_bs_n_sp_pts = -1, &
     118             :                                                       nkp_bs_and_DOS = -1, &
     119             :                                                       nkp_only_bs = -1, &
     120             :                                                       nkp_only_DOS = -1
     121             :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE  :: xkp_special
     122             : 
     123             :       ! parameters for GW band structure calculation of small unit cell (with multiple unit cell)
     124             :       INTEGER                                      :: small_cell_full_kp_or_large_cell_Gamma = -1, &
     125             :                                                       nimages_scf = -1
     126             :       INTEGER, DIMENSION(3)                        :: periodic = -1
     127             :       REAL(KIND=dp), DIMENSION(3, 3)               :: hmat = -1.0_dp
     128             : 
     129             :       ! imaginary time and frequency grids
     130             :       INTEGER                                         :: num_time_freq_points = -1, &
     131             :                                                          num_freq_points_fit = -1
     132             :       REAL(KIND=dp), DIMENSION(:), ALLOCATABLE        :: imag_time_points, &
     133             :                                                          imag_time_weights_freq_zero, &
     134             :                                                          imag_freq_points, &
     135             :                                                          imag_freq_points_fit
     136             :       REAL(KIND=dp), DIMENSION(:, :), ALLOCATABLE     :: weights_cos_t_to_w, &
     137             :                                                          weights_cos_w_to_t, &
     138             :                                                          weights_sin_t_to_w
     139             :       INTEGER                                         :: nparam_pade = -1, &
     140             :                                                          num_points_per_magnitude = -1
     141             :       REAL(KIND=dp)                                   :: freq_max_fit = -1.0_dp, &
     142             :                                                          regularization_minimax = -1.0_dp, &
     143             :                                                          stabilize_exp = -1.0_dp
     144             : 
     145             :       ! filter threshold for matrix-tensor operations
     146             :       REAL(KIND=dp)                                :: eps_filter = -1.0_dp, &
     147             :                                                       eps_atom_grid_2d_mat = -1.0_dp
     148             : 
     149             :       ! threshold for inverting ao overlap matrix, RI cfm_1d
     150             :       REAL(KIND=dp)                                :: eps_eigval_mat_s = -1.0_dp, &
     151             :                                                       eps_eigval_mat_RI = -1.0_dp, &
     152             :                                                       input_regularization_RI = -1.0_dp, &
     153             :                                                       regularization_RI = -1.0_dp
     154             : 
     155             :       ! global full cfm_1d used in GW
     156             :       TYPE(cp_fm_type)                             :: fm_s_Gamma = cp_fm_type(), &
     157             :                                                       fm_Gocc = cp_fm_type(), &
     158             :                                                       fm_Gvir = cp_fm_type()
     159             :       TYPE(cp_fm_type), DIMENSION(2)               :: fm_ks_Gamma = cp_fm_type(), &
     160             :                                                       fm_V_xc_Gamma = cp_fm_type(), &
     161             :                                                       fm_mo_coeff_Gamma = cp_fm_type()
     162             :       TYPE(cp_fm_type), DIMENSION(4)               :: fm_work_mo = cp_fm_type()
     163             :       TYPE(cp_fm_type)                             :: fm_RI_RI = cp_fm_type(), &
     164             :                                                       fm_chi_Gamma_freq = cp_fm_type(), &
     165             :                                                       fm_W_MIC_freq = cp_fm_type(), &
     166             :                                                       fm_W_MIC_freq_1_extra = cp_fm_type(), &
     167             :                                                       fm_W_MIC_freq_1_no_extra = cp_fm_type(), &
     168             :                                                       fm_W_MIC_freq_zero = cp_fm_type(), &
     169             :                                                       fm_h_G0W0_Gamma = cp_fm_type()
     170             :       TYPE(cp_cfm_type)                            :: cfm_work_mo = cp_cfm_type(), &
     171             :                                                       cfm_work_mo_2 = cp_cfm_type()
     172             : 
     173             :       ! global dbcsr cfm_1d used in GW
     174             :       TYPE(dbcsr_p_type)                           :: mat_ao_ao = dbcsr_p_type(), &
     175             :                                                       mat_RI_RI = dbcsr_p_type()
     176             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER    :: mat_chi_Gamma_tau => NULL()
     177             : 
     178             :       ! local dbcsr cfm_1d used in GW (local in tensor group)
     179             :       TYPE(dbcsr_p_type)                           :: mat_ao_ao_tensor = dbcsr_p_type(), &
     180             :                                                       mat_RI_RI_tensor = dbcsr_p_type()
     181             : 
     182             :       ! tensors for sparse matrix-tensor operations
     183             : #if defined(FTN_NO_DEFAULT_INIT)
     184             :       TYPE(dbt_type)                               :: t_G, &
     185             :                                                       t_chi, &
     186             :                                                       t_W, &
     187             :                                                       t_RI_AO__AO, &
     188             :                                                       t_RI__AO_AO
     189             : #else
     190             :       TYPE(dbt_type)                               :: t_G = dbt_type(), &
     191             :                                                       t_chi = dbt_type(), &
     192             :                                                       t_W = dbt_type(), &
     193             :                                                       t_RI_AO__AO = dbt_type(), &
     194             :                                                       t_RI__AO_AO = dbt_type()
     195             : #endif
     196             : 
     197             :       ! parameters and data for parallelization
     198             :       INTEGER                                      :: group_size_tensor = -1, &
     199             :                                                       tensor_group_color = -1, &
     200             :                                                       num_tensor_groups = -1
     201             :       REAL(KIND=dp)                                :: input_memory_per_proc_GB = -1.0_dp
     202             :       TYPE(mp_para_env_type), POINTER              :: para_env => NULL(), &
     203             :                                                       para_env_tensor => NULL()
     204             :       REAL(KIND=dp)                                :: occupation_3c_int = -1.0_dp, &
     205             :                                                       max_dist_AO_atoms = -1.0_dp, &
     206             :                                                       safety_factor_memory = -1.0_dp
     207             : 
     208             :       ! parallelization: atom range i and atom range j for tensor group
     209             :       INTEGER, DIMENSION(2)                        :: atoms_i = -1, &
     210             :                                                       atoms_j = -1
     211             :       INTEGER                                      :: n_atom_i = -1, &
     212             :                                                       n_intervals_i = -1, &
     213             :                                                       n_atom_j = -1, &
     214             :                                                       n_intervals_j = -1, &
     215             :                                                       n_atom_per_interval_ij = -1, &
     216             :                                                       n_intervals_inner_loop_atoms = -1, &
     217             :                                                       n_atom_per_IL_interval = -1
     218             :       INTEGER, DIMENSION(:, :), ALLOCATABLE        :: i_atom_intervals, &
     219             :                                                       j_atom_intervals, &
     220             :                                                       inner_loop_atom_intervals, &
     221             :                                                       atoms_i_t_group, &
     222             :                                                       atoms_j_t_group
     223             :       LOGICAL, DIMENSION(:, :), ALLOCATABLE        :: skip_Sigma_occ, &
     224             :                                                       skip_Sigma_vir
     225             :       ! Marek : rtp_method
     226             :       INTEGER                                      :: rtp_method = rtp_method_bse
     227             : 
     228             :       ! check-arrays and names for restarting
     229             :       LOGICAL, DIMENSION(:), ALLOCATABLE           :: read_chi, &
     230             :                                                       calc_chi
     231             :       LOGICAL, DIMENSION(:, :), ALLOCATABLE        :: Sigma_c_exists
     232             :       LOGICAL                                      :: all_W_exist = .FALSE., &
     233             :                                                       Sigma_x_exists = .FALSE.
     234             :       CHARACTER(LEN=3)                             :: chi_name = "chi"
     235             :       CHARACTER(LEN=6)                             :: W_time_name = "W_time"
     236             :       CHARACTER(LEN=7)                             :: Sigma_x_name = "Sigma_x"
     237             :       CHARACTER(LEN=13)                            :: Sigma_p_name = "Sigma_pos_tau", &
     238             :                                                       Sigma_n_name = "Sigma_neg_tau"
     239             :       CHARACTER(LEN=default_string_length)         :: prefix = ""
     240             :       INTEGER                                      :: unit_nr = -1
     241             : 
     242             :       ! parameters and data for basis sets
     243             :       TYPE(gto_basis_set_p_type), &
     244             :          DIMENSION(:), ALLOCATABLE                 :: basis_set_AO, &
     245             :                                                       basis_set_RI
     246             :       INTEGER, DIMENSION(:), ALLOCATABLE           :: sizes_AO, &
     247             :                                                       sizes_RI
     248             :       TYPE(neighbor_list_3c_type)                  :: nl_3c = neighbor_list_3c_type()
     249             :       TYPE(libint_potential_type)                  :: ri_metric = libint_potential_type(), &
     250             :                                                       trunc_coulomb = libint_potential_type()
     251             : 
     252             :       ! parameters for SOC calculation
     253             :       REAL(KIND=dp)                                :: energy_window_soc = -1.0_dp
     254             :       ! sizes: mat_V_SOC_xyz: xyz, img
     255             :       TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_V_SOC_xyz => NULL()
     256             :       TYPE(cp_fm_type), DIMENSION(3)               :: fm_V_SOC_xyz_mo = cp_fm_type()
     257             :       ! small-cell GW: dimension = number of kpoints; large-cell GW: Gamma-point, dimension = 1
     258             :       TYPE(cp_cfm_type), DIMENSION(:), ALLOCATABLE :: cfm_SOC_spinor_ao
     259             :       TYPE(band_edges_type)                        :: band_edges_scf_SOC = band_edges_type(), &
     260             :                                                       band_edges_G0W0_SOC = band_edges_type()
     261             : 
     262             :       ! parameters for DOS and PDOS calculation
     263             :       REAL(KIND=dp)                                :: energy_window_DOS = -1.0_dp, &
     264             :                                                       energy_step_DOS = -1.0_dp, &
     265             :                                                       broadening_DOS = -1.0_dp
     266             : 
     267             :       ! parameters for LDOS calculation (LDOS: local density of states)
     268             :       INTEGER                                      :: int_ldos_xyz = -1
     269             :       INTEGER, DIMENSION(:), POINTER               :: bin_mesh => NULL()
     270             :       INTEGER                                      :: n_bins_max_for_printing = -1
     271             :       REAL(KIND=dp)                                :: unit_ldos_int_z_inv_Ang2_eV = -1.0_dp
     272             : 
     273             :       ! quantities only needed for small cells and k-point sampling in DFT (small_cell_full_kp)
     274             :       INTEGER                                      :: nkp_scf_desymm = -1, &
     275             :                                                       nimages_3c = -1, &
     276             :                                                       nimages_scf_desymm = -1, &
     277             :                                                       nimages_Delta_R = -1
     278             :       TYPE(kpoint_type), POINTER                   :: kpoints_scf_desymm => NULL(), &
     279             :                                                       kpoints_scf_desymm_2 => NULL()
     280             :       INTEGER, DIMENSION(3)                        :: cell_grid_scf_desymm = -1
     281             :       INTEGER, DIMENSION(:, :), ALLOCATABLE        :: index_to_cell_3c, &
     282             :                                                       index_to_cell_Delta_R
     283             :       INTEGER, DIMENSION(:, :, :), POINTER         :: cell_to_index_3c => NULL(), &
     284             :                                                       cell_to_index_Delta_R => NULL()
     285             :       REAL(KIND=dp)                                :: heuristic_filter_factor = -1.0_dp
     286             : 
     287             :       ! small_cell_full_kp parallelization
     288             :       INTEGER                                      :: n_tasks_Delta_R_local = -1
     289             :       INTEGER, DIMENSION(:), ALLOCATABLE           :: task_Delta_R
     290             :       INTEGER, DIMENSION(:, :), ALLOCATABLE        :: nblocks_3c
     291             : 
     292             :       ! cfm for k-dep overl mat S_µν(k), KS mat h_µν(k,spin) and mo coeff C_μn(k,spin) from SCF
     293             :       TYPE(cp_cfm_type), DIMENSION(:), ALLOCATABLE      :: cfm_s_kp
     294             :       TYPE(cp_cfm_type), DIMENSION(:, :), ALLOCATABLE   :: cfm_mo_coeff_kp, &
     295             :                                                            cfm_ks_kp
     296             :       TYPE(cp_fm_type), DIMENSION(:), ALLOCATABLE       :: fm_G_S, &
     297             :                                                            fm_Sigma_x_R
     298             :       TYPE(cp_fm_type), DIMENSION(:, :), ALLOCATABLE    :: fm_V_xc_R, &
     299             :                                                            fm_chi_R_t, &
     300             :                                                            fm_MWM_R_t
     301             :       TYPE(cp_fm_type), DIMENSION(:, :, :), ALLOCATABLE :: fm_Sigma_c_R_neg_tau, &
     302             :                                                            fm_Sigma_c_R_pos_tau
     303             :       REAL(KIND=dp), DIMENSION(:, :, :), ALLOCATABLE    :: v_xc_n
     304             :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)      :: t_3c_int
     305             : 
     306             :    END TYPE post_scf_bandstructure_type
     307             : 
     308             : CONTAINS
     309             : 
     310             : ! **************************************************************************************************
     311             : !> \brief ...
     312             : !> \param bs_env ...
     313             : ! **************************************************************************************************
     314          34 :    SUBROUTINE bs_env_release(bs_env)
     315             :       TYPE(post_scf_bandstructure_type), POINTER         :: bs_env
     316             : 
     317             :       CHARACTER(LEN=*), PARAMETER                        :: routineN = 'bs_env_release'
     318             : 
     319             :       INTEGER                                            :: handle
     320             : 
     321          34 :       CALL timeset(routineN, handle)
     322             : 
     323          34 :       CPASSERT(ASSOCIATED(bs_env))
     324             : 
     325          34 :       CALL safe_kpoints_release(bs_env%kpoints_chi_eps_W)
     326          34 :       CALL safe_kpoints_release(bs_env%kpoints_DOS)
     327          34 :       CALL safe_kpoints_release(bs_env%kpoints_scf_desymm)
     328          34 :       CALL safe_kpoints_release(bs_env%kpoints_scf_desymm_2)
     329             : 
     330          34 :       IF (ALLOCATED(bs_env%wkp_s_p)) DEALLOCATE (bs_env%wkp_s_p)
     331          34 :       IF (ALLOCATED(bs_env%wkp_no_extra)) DEALLOCATE (bs_env%wkp_no_extra)
     332          34 :       IF (ALLOCATED(bs_env%l_RI)) DEALLOCATE (bs_env%l_RI)
     333          34 :       IF (ALLOCATED(bs_env%xkp_special)) DEALLOCATE (bs_env%xkp_special)
     334          34 :       IF (ALLOCATED(bs_env%imag_time_points)) DEALLOCATE (bs_env%imag_time_points)
     335          34 :       IF (ALLOCATED(bs_env%imag_time_weights_freq_zero)) DEALLOCATE (bs_env%imag_time_weights_freq_zero)
     336          34 :       IF (ALLOCATED(bs_env%imag_freq_points)) DEALLOCATE (bs_env%imag_freq_points)
     337          34 :       IF (ALLOCATED(bs_env%eigenval_scf_Gamma)) DEALLOCATE (bs_env%eigenval_scf_Gamma)
     338          34 :       IF (ALLOCATED(bs_env%eigenval_scf)) DEALLOCATE (bs_env%eigenval_scf)
     339          34 :       IF (ALLOCATED(bs_env%eigenval_G0W0)) DEALLOCATE (bs_env%eigenval_G0W0)
     340          34 :       IF (ALLOCATED(bs_env%eigenval_HF)) DEALLOCATE (bs_env%eigenval_HF)
     341          34 :       IF (ALLOCATED(bs_env%eigenval_scGW0)) DEALLOCATE (bs_env%eigenval_scGW0)
     342          34 :       IF (ALLOCATED(bs_env%eigenval_scf_soc)) DEALLOCATE (bs_env%eigenval_scf_soc)
     343          34 :       IF (ALLOCATED(bs_env%eigenval_G0W0_soc)) DEALLOCATE (bs_env%eigenval_G0W0_soc)
     344          34 :       IF (ALLOCATED(bs_env%i_ao_start_from_atom)) DEALLOCATE (bs_env%i_ao_start_from_atom)
     345          34 :       IF (ALLOCATED(bs_env%i_ao_end_from_atom)) DEALLOCATE (bs_env%i_ao_end_from_atom)
     346          34 :       IF (ALLOCATED(bs_env%i_RI_start_from_atom)) DEALLOCATE (bs_env%i_RI_start_from_atom)
     347          34 :       IF (ALLOCATED(bs_env%i_RI_end_from_atom)) DEALLOCATE (bs_env%i_RI_end_from_atom)
     348          34 :       IF (ALLOCATED(bs_env%i_atom_intervals)) DEALLOCATE (bs_env%i_atom_intervals)
     349          34 :       IF (ALLOCATED(bs_env%j_atom_intervals)) DEALLOCATE (bs_env%j_atom_intervals)
     350          34 :       IF (ALLOCATED(bs_env%atoms_i_t_group)) DEALLOCATE (bs_env%atoms_i_t_group)
     351          34 :       IF (ALLOCATED(bs_env%atoms_j_t_group)) DEALLOCATE (bs_env%atoms_j_t_group)
     352          34 :       IF (ALLOCATED(bs_env%skip_Sigma_occ)) DEALLOCATE (bs_env%skip_Sigma_occ)
     353          34 :       IF (ALLOCATED(bs_env%skip_Sigma_vir)) DEALLOCATE (bs_env%skip_Sigma_vir)
     354          34 :       IF (ALLOCATED(bs_env%read_chi)) DEALLOCATE (bs_env%read_chi)
     355          34 :       IF (ALLOCATED(bs_env%calc_chi)) DEALLOCATE (bs_env%calc_chi)
     356          34 :       IF (ALLOCATED(bs_env%Sigma_c_exists)) DEALLOCATE (bs_env%Sigma_c_exists)
     357          34 :       IF (ALLOCATED(bs_env%sizes_AO)) DEALLOCATE (bs_env%sizes_AO)
     358          34 :       IF (ALLOCATED(bs_env%sizes_RI)) DEALLOCATE (bs_env%sizes_RI)
     359          34 :       IF (ALLOCATED(bs_env%index_to_cell_3c)) DEALLOCATE (bs_env%index_to_cell_3c)
     360          34 :       IF (ALLOCATED(bs_env%index_to_cell_Delta_R)) DEALLOCATE (bs_env%index_to_cell_Delta_R)
     361          34 :       IF (ASSOCIATED(bs_env%cell_to_index_3c)) DEALLOCATE (bs_env%cell_to_index_3c)
     362          34 :       IF (ASSOCIATED(bs_env%cell_to_index_Delta_R)) DEALLOCATE (bs_env%cell_to_index_Delta_R)
     363          34 :       IF (ALLOCATED(bs_env%task_Delta_R)) DEALLOCATE (bs_env%task_Delta_R)
     364          34 :       IF (ALLOCATED(bs_env%nblocks_3c)) DEALLOCATE (bs_env%nblocks_3c)
     365             : 
     366          34 :       CALL cp_fm_release(bs_env%fm_s_Gamma)
     367          34 :       CALL cp_fm_release(bs_env%fm_ks_Gamma(1))
     368          34 :       CALL cp_fm_release(bs_env%fm_ks_Gamma(2))
     369          34 :       CALL cp_fm_release(bs_env%fm_V_xc_Gamma(1))
     370          34 :       CALL cp_fm_release(bs_env%fm_V_xc_Gamma(2))
     371          34 :       CALL cp_fm_release(bs_env%fm_mo_coeff_Gamma(1))
     372          34 :       CALL cp_fm_release(bs_env%fm_mo_coeff_Gamma(2))
     373          34 :       CALL cp_fm_release(bs_env%fm_Gocc)
     374          34 :       CALL cp_fm_release(bs_env%fm_Gvir)
     375          34 :       CALL cp_fm_release(bs_env%fm_work_mo(1))
     376          34 :       CALL cp_fm_release(bs_env%fm_work_mo(2))
     377          34 :       CALL cp_fm_release(bs_env%fm_work_mo(3))
     378          34 :       CALL cp_fm_release(bs_env%fm_work_mo(4))
     379          34 :       CALL cp_fm_release(bs_env%fm_RI_RI)
     380          34 :       CALL cp_fm_release(bs_env%fm_chi_Gamma_freq)
     381          34 :       CALL cp_fm_release(bs_env%fm_W_MIC_freq)
     382             :       ! TODO : Test whether IF (rtp_method == rtp_method_gw) is needed
     383          34 :       CALL cp_fm_release(bs_env%fm_W_MIC_freq_zero)
     384          34 :       CALL cp_fm_release(bs_env%fm_W_MIC_freq_1_extra)
     385          34 :       CALL cp_fm_release(bs_env%fm_W_MIC_freq_1_no_extra)
     386          34 :       CALL cp_cfm_release(bs_env%cfm_work_mo)
     387          34 :       CALL cp_cfm_release(bs_env%cfm_work_mo_2)
     388             : 
     389          34 :       CALL safe_fm_destroy_1d(bs_env%fm_G_S)
     390          34 :       CALL safe_fm_destroy_1d(bs_env%fm_Sigma_x_R)
     391          34 :       CALL safe_fm_destroy_2d(bs_env%fm_V_xc_R)
     392          34 :       CALL safe_fm_destroy_2d(bs_env%fm_chi_R_t)
     393          34 :       CALL safe_fm_destroy_2d(bs_env%fm_MWM_R_t)
     394          34 :       CALL safe_fm_destroy_3d(bs_env%fm_Sigma_c_R_neg_tau)
     395          34 :       CALL safe_fm_destroy_3d(bs_env%fm_Sigma_c_R_pos_tau)
     396             : 
     397          34 :       CALL t_destroy_2d(bs_env%t_3c_int)
     398             : 
     399          34 :       CALL release_dbcsr_p_type(bs_env%mat_ao_ao)
     400          34 :       CALL release_dbcsr_p_type(bs_env%mat_RI_RI)
     401          34 :       CALL safe_dbcsr_deallocate_matrix_set_1d(bs_env%mat_chi_Gamma_tau)
     402             : 
     403          34 :       CALL release_dbcsr_p_type(bs_env%mat_ao_ao_tensor)
     404          34 :       CALL release_dbcsr_p_type(bs_env%mat_RI_RI_tensor)
     405             : 
     406          34 :       CALL safe_cfm_destroy_1d(bs_env%cfm_s_kp)
     407          34 :       CALL safe_cfm_destroy_2d(bs_env%cfm_ks_kp)
     408          34 :       CALL safe_cfm_destroy_2d(bs_env%cfm_mo_coeff_kp)
     409             : 
     410          34 :       CALL mp_para_env_release(bs_env%para_env)
     411          34 :       IF (ASSOCIATED(bs_env%para_env_tensor)) CALL mp_para_env_release(bs_env%para_env_tensor)
     412             : 
     413          34 :       CALL safe_dbt_destroy(bs_env%t_G)
     414          34 :       CALL safe_dbt_destroy(bs_env%t_chi)
     415          34 :       CALL safe_dbt_destroy(bs_env%t_W)
     416          34 :       CALL safe_dbt_destroy(bs_env%t_RI_AO__AO)
     417          34 :       CALL safe_dbt_destroy(bs_env%t_RI__AO_AO)
     418             : 
     419          34 :       IF (ALLOCATED(bs_env%basis_set_AO)) DEALLOCATE (bs_env%basis_set_AO)
     420          34 :       IF (ALLOCATED(bs_env%basis_set_RI)) DEALLOCATE (bs_env%basis_set_RI)
     421             : 
     422             :       ! SOC cfm_1d and arrays
     423          34 :       CALL safe_dbcsr_deallocate_matrix_set_2d(bs_env%mat_V_SOC_xyz)
     424          34 :       CALL cp_fm_release(bs_env%fm_V_SOC_xyz_mo(1))
     425          34 :       CALL cp_fm_release(bs_env%fm_V_SOC_xyz_mo(2))
     426          34 :       CALL cp_fm_release(bs_env%fm_V_SOC_xyz_mo(3))
     427          34 :       CALL safe_cfm_destroy_1d(bs_env%cfm_SOC_spinor_ao)
     428             : 
     429          34 :       DEALLOCATE (bs_env)
     430             : 
     431          34 :       CALL timestop(handle)
     432             : 
     433          34 :    END SUBROUTINE bs_env_release
     434             : 
     435             : ! **************************************************************************************************
     436             : !> \brief ...
     437             : !> \param kpoints ...
     438             : ! **************************************************************************************************
     439         136 :    SUBROUTINE safe_kpoints_release(kpoints)
     440             :       TYPE(kpoint_type), POINTER                         :: kpoints
     441             : 
     442         136 :       IF (ASSOCIATED(kpoints)) CALL kpoint_release(kpoints)
     443             : 
     444         136 :    END SUBROUTINE safe_kpoints_release
     445             : 
     446             : ! **************************************************************************************************
     447             : !> \brief ...
     448             : !> \param dbcsr_p_type_matrix ...
     449             : ! **************************************************************************************************
     450         136 :    SUBROUTINE release_dbcsr_p_type(dbcsr_p_type_matrix)
     451             :       TYPE(dbcsr_p_type)                                 :: dbcsr_p_type_matrix
     452             : 
     453         136 :       IF (ASSOCIATED(dbcsr_p_type_matrix%matrix)) THEN
     454         136 :          CALL dbcsr_release(dbcsr_p_type_matrix%matrix)
     455         136 :          DEALLOCATE (dbcsr_p_type_matrix%matrix)
     456             :       END IF
     457             : 
     458         136 :    END SUBROUTINE release_dbcsr_p_type
     459             : 
     460             : ! **************************************************************************************************
     461             : !> \brief ...
     462             : !> \param t ...
     463             : ! **************************************************************************************************
     464         170 :    SUBROUTINE safe_dbt_destroy(t)
     465             :       TYPE(dbt_type)                                     :: t
     466             : 
     467         170 :       IF (ASSOCIATED(t%matrix_rep)) CALL dbt_destroy(t)
     468             : 
     469         170 :    END SUBROUTINE safe_dbt_destroy
     470             : 
     471             : ! **************************************************************************************************
     472             : !> \brief ...
     473             : !> \param dbcsr_array ...
     474             : ! **************************************************************************************************
     475          34 :    SUBROUTINE safe_dbcsr_deallocate_matrix_set_1d(dbcsr_array)
     476             :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER          :: dbcsr_array
     477             : 
     478          34 :       IF (ASSOCIATED(dbcsr_array)) CALL dbcsr_deallocate_matrix_set(dbcsr_array)
     479             : 
     480          34 :    END SUBROUTINE safe_dbcsr_deallocate_matrix_set_1d
     481             : 
     482             : ! **************************************************************************************************
     483             : !> \brief ...
     484             : !> \param dbcsr_array ...
     485             : ! **************************************************************************************************
     486          34 :    SUBROUTINE safe_dbcsr_deallocate_matrix_set_2d(dbcsr_array)
     487             :       TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER       :: dbcsr_array
     488             : 
     489          34 :       IF (ASSOCIATED(dbcsr_array)) CALL dbcsr_deallocate_matrix_set(dbcsr_array)
     490             : 
     491          34 :    END SUBROUTINE safe_dbcsr_deallocate_matrix_set_2d
     492             : 
     493             : ! **************************************************************************************************
     494             : !> \brief ...
     495             : !> \param fm_1d ...
     496             : ! **************************************************************************************************
     497          68 :    SUBROUTINE safe_fm_destroy_1d(fm_1d)
     498             :       TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:)        :: fm_1d
     499             : 
     500             :       INTEGER                                            :: i
     501             : 
     502          68 :       IF (ALLOCATED(fm_1d)) THEN
     503         120 :          DO i = 1, SIZE(fm_1d, 1)
     504         120 :             CALL cp_fm_release(fm_1d(i))
     505             :          END DO
     506          12 :          DEALLOCATE (fm_1d)
     507             :       END IF
     508             : 
     509          68 :    END SUBROUTINE safe_fm_destroy_1d
     510             : 
     511             : ! **************************************************************************************************
     512             : !> \brief ...
     513             : !> \param fm_2d ...
     514             : ! **************************************************************************************************
     515         102 :    SUBROUTINE safe_fm_destroy_2d(fm_2d)
     516             :       TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :)     :: fm_2d
     517             : 
     518             :       INTEGER                                            :: i, j
     519             : 
     520         102 :       IF (ALLOCATED(fm_2d)) THEN
     521         272 :          DO i = 1, SIZE(fm_2d, 1)
     522        1354 :          DO j = 1, SIZE(fm_2d, 2)
     523        1336 :             CALL cp_fm_release(fm_2d(i, j))
     524             :          END DO
     525             :          END DO
     526          18 :          DEALLOCATE (fm_2d)
     527             :       END IF
     528             : 
     529         102 :    END SUBROUTINE safe_fm_destroy_2d
     530             : 
     531             : ! **************************************************************************************************
     532             : !> \brief ...
     533             : !> \param fm_3d ...
     534             : ! **************************************************************************************************
     535          68 :    SUBROUTINE safe_fm_destroy_3d(fm_3d)
     536             :       TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :, :)  :: fm_3d
     537             : 
     538             :       INTEGER                                            :: i, j, k
     539             : 
     540          68 :       IF (ALLOCATED(fm_3d)) THEN
     541         120 :          DO i = 1, SIZE(fm_3d, 1)
     542        1056 :          DO j = 1, SIZE(fm_3d, 2)
     543        1980 :          DO k = 1, SIZE(fm_3d, 3)
     544        1872 :             CALL cp_fm_release(fm_3d(i, j, k))
     545             :          END DO
     546             :          END DO
     547             :          END DO
     548          12 :          DEALLOCATE (fm_3d)
     549             :       END IF
     550             : 
     551          68 :    END SUBROUTINE safe_fm_destroy_3d
     552             : 
     553             : ! **************************************************************************************************
     554             : !> \brief ...
     555             : !> \param cfm_1d ...
     556             : ! **************************************************************************************************
     557          68 :    SUBROUTINE safe_cfm_destroy_1d(cfm_1d)
     558             :       TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:)       :: cfm_1d
     559             : 
     560             :       INTEGER                                            :: i
     561             : 
     562          68 :       IF (ALLOCATED(cfm_1d)) THEN
     563         476 :          DO i = 1, SIZE(cfm_1d, 1)
     564         476 :             CALL cp_cfm_release(cfm_1d(i))
     565             :          END DO
     566          24 :          DEALLOCATE (cfm_1d)
     567             :       END IF
     568             : 
     569          68 :    END SUBROUTINE safe_cfm_destroy_1d
     570             : 
     571             : ! **************************************************************************************************
     572             : !> \brief ...
     573             : !> \param cfm_2d ...
     574             : ! **************************************************************************************************
     575          68 :    SUBROUTINE safe_cfm_destroy_2d(cfm_2d)
     576             :       TYPE(cp_cfm_type), ALLOCATABLE, DIMENSION(:, :)    :: cfm_2d
     577             : 
     578             :       INTEGER                                            :: i, j
     579             : 
     580          68 :       IF (ALLOCATED(cfm_2d)) THEN
     581         452 :          DO i = 1, SIZE(cfm_2d, 1)
     582         892 :          DO j = 1, SIZE(cfm_2d, 2)
     583         880 :             CALL cp_cfm_release(cfm_2d(i, j))
     584             :          END DO
     585             :          END DO
     586          12 :          DEALLOCATE (cfm_2d)
     587             :       END IF
     588             : 
     589          68 :    END SUBROUTINE safe_cfm_destroy_2d
     590             : 
     591             : ! **************************************************************************************************
     592             : !> \brief ...
     593             : !> \param t_2d ...
     594             : ! **************************************************************************************************
     595          34 :    SUBROUTINE t_destroy_2d(t_2d)
     596             :       TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :)       :: t_2d
     597             : 
     598             :       INTEGER                                            :: i, j
     599             : 
     600          34 :       IF (ALLOCATED(t_2d)) THEN
     601          50 :          DO i = 1, SIZE(t_2d, 1)
     602         438 :             DO j = 1, SIZE(t_2d, 2)
     603         432 :                CALL dbt_destroy(t_2d(i, j))
     604             :             END DO
     605             :          END DO
     606         394 :          DEALLOCATE (t_2d)
     607             :       END IF
     608             : 
     609          34 :    END SUBROUTINE t_destroy_2d
     610             : 
     611           0 : END MODULE post_scf_bandstructure_types

Generated by: LCOV version 1.15