LCOV - code coverage report
Current view: top level - src - qs_environment_types.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:21ef868) Lines: 81.5 % 664 541
Test Date: 2026-08-14 07:04:57 Functions: 85.7 % 7 6

            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              : !> \par History
      10              : !>      - mo_set_p_type added to qs_env (23.04.02,MK)
      11              : !>      - qs_force_type added to qs_env (05.06.02,MK)
      12              : !> \author MK (23.01.2002)
      13              : ! **************************************************************************************************
      14              : MODULE qs_environment_types
      15              :    USE admm_types,                      ONLY: admm_env_release,&
      16              :                                               admm_type
      17              :    USE almo_scf_types,                  ONLY: almo_scf_env_release,&
      18              :                                               almo_scf_env_type
      19              :    USE atomic_kind_types,               ONLY: atomic_kind_type
      20              :    USE atprop_types,                    ONLY: atprop_type
      21              :    USE cell_types,                      ONLY: cell_release,&
      22              :                                               cell_retain,&
      23              :                                               cell_type
      24              :    USE cp_blacs_env,                    ONLY: cp_blacs_env_type
      25              :    USE cp_control_types,                ONLY: dft_control_type
      26              :    USE cp_dbcsr_api,                    ONLY: dbcsr_distribution_type,&
      27              :                                               dbcsr_p_type,&
      28              :                                               dbcsr_release_p
      29              :    USE cp_ddapc_types,                  ONLY: cp_ddapc_ewald_release,&
      30              :                                               cp_ddapc_ewald_type,&
      31              :                                               cp_ddapc_release,&
      32              :                                               cp_ddapc_type
      33              :    USE cp_fm_types,                     ONLY: cp_fm_release,&
      34              :                                               cp_fm_type
      35              :    USE cp_result_types,                 ONLY: cp_result_type
      36              :    USE cp_subsys_types,                 ONLY: cp_subsys_type
      37              :    USE distribution_1d_types,           ONLY: distribution_1d_type
      38              :    USE distribution_2d_types,           ONLY: distribution_2d_type
      39              :    USE dm_ls_scf_types,                 ONLY: ls_scf_env_type,&
      40              :                                               ls_scf_release
      41              :    USE ec_env_types,                    ONLY: ec_env_release,&
      42              :                                               energy_correction_type
      43              :    USE et_coupling_types,               ONLY: et_coupling_release,&
      44              :                                               et_coupling_type
      45              :    USE ewald_environment_types,         ONLY: ewald_env_release,&
      46              :                                               ewald_environment_type
      47              :    USE ewald_pw_types,                  ONLY: ewald_pw_release,&
      48              :                                               ewald_pw_type
      49              :    USE exstates_types,                  ONLY: excited_energy_type,&
      50              :                                               exstate_release
      51              :    USE fist_nonbond_env_types,          ONLY: fist_nonbond_env_release,&
      52              :                                               fist_nonbond_env_type
      53              :    USE global_types,                    ONLY: global_environment_type
      54              :    USE hartree_local_types,             ONLY: ecoul_1center_type,&
      55              :                                               get_hartree_local,&
      56              :                                               hartree_local_create,&
      57              :                                               hartree_local_release,&
      58              :                                               hartree_local_type,&
      59              :                                               set_hartree_local
      60              :    USE hfx_types,                       ONLY: hfx_release,&
      61              :                                               hfx_type
      62              :    USE input_constants,                 ONLY: energy_force_run,&
      63              :                                               energy_run
      64              :    USE input_section_types,             ONLY: section_vals_release,&
      65              :                                               section_vals_retain,&
      66              :                                               section_vals_type
      67              :    USE kg_environment_types,            ONLY: kg_env_release,&
      68              :                                               kg_environment_type
      69              :    USE kinds,                           ONLY: dp
      70              :    USE kpoint_types,                    ONLY: kpoint_type
      71              :    USE lri_environment_types,           ONLY: lri_density_release,&
      72              :                                               lri_density_type,&
      73              :                                               lri_env_release,&
      74              :                                               lri_environment_type
      75              :    USE message_passing,                 ONLY: mp_para_env_type
      76              :    USE molecule_kind_types,             ONLY: molecule_kind_type
      77              :    USE molecule_types,                  ONLY: molecule_type
      78              :    USE mp2_types,                       ONLY: mp2_env_release,&
      79              :                                               mp2_type
      80              :    USE mscfg_types,                     ONLY: molecular_scf_guess_env_destroy,&
      81              :                                               molecular_scf_guess_env_type
      82              :    USE particle_types,                  ONLY: particle_type
      83              :    USE post_scf_bandstructure_types,    ONLY: bs_env_release,&
      84              :                                               post_scf_bandstructure_type
      85              :    USE pw_env_types,                    ONLY: pw_env_type
      86              :    USE pw_types,                        ONLY: pw_c1d_gs_type,&
      87              :                                               pw_r3d_rs_type
      88              :    USE qmmm_types_low,                  ONLY: qmmm_env_qm_type
      89              :    USE qs_active_space_types,           ONLY: active_space_type,&
      90              :                                               release_active_space_type
      91              :    USE qs_charges_types,                ONLY: qs_charges_release,&
      92              :                                               qs_charges_type
      93              :    USE qs_cneo_types,                   ONLY: rhoz_cneo_type
      94              :    USE qs_dftb_types,                   ONLY: qs_dftb_pairpot_release,&
      95              :                                               qs_dftb_pairpot_type
      96              :    USE qs_dispersion_types,             ONLY: qs_dispersion_release,&
      97              :                                               qs_dispersion_type
      98              :    USE qs_energy_types,                 ONLY: qs_energy_type
      99              :    USE qs_force_types,                  ONLY: qs_force_type
     100              :    USE qs_gcp_types,                    ONLY: qs_gcp_release,&
     101              :                                               qs_gcp_type
     102              :    USE qs_harris_types,                 ONLY: harris_env_release,&
     103              :                                               harris_type
     104              :    USE qs_kind_types,                   ONLY: qs_kind_type
     105              :    USE qs_ks_qmmm_types,                ONLY: qs_ks_qmmm_env_type,&
     106              :                                               qs_ks_qmmm_release
     107              :    USE qs_ks_types,                     ONLY: get_ks_env,&
     108              :                                               qs_ks_env_type,&
     109              :                                               qs_ks_part_release,&
     110              :                                               qs_ks_release,&
     111              :                                               set_ks_env
     112              :    USE qs_linres_types,                 ONLY: linres_control_release,&
     113              :                                               linres_control_type,&
     114              :                                               polar_env_release,&
     115              :                                               polar_env_type
     116              :    USE qs_local_rho_types,              ONLY: get_local_rho,&
     117              :                                               local_rho_set_create,&
     118              :                                               local_rho_set_release,&
     119              :                                               local_rho_type,&
     120              :                                               rhoz_type,&
     121              :                                               set_local_rho
     122              :    USE qs_matrix_pools,                 ONLY: mpools_release,&
     123              :                                               mpools_retain,&
     124              :                                               qs_matrix_pools_type
     125              :    USE qs_mo_types,                     ONLY: deallocate_mo_set,&
     126              :                                               mo_set_type
     127              :    USE qs_neighbor_list_types,          ONLY: neighbor_list_set_p_type
     128              :    USE qs_oce_types,                    ONLY: deallocate_oce_set,&
     129              :                                               oce_matrix_type
     130              :    USE qs_period_efield_types,          ONLY: efield_berry_release,&
     131              :                                               efield_berry_type
     132              :    USE qs_rho0_types,                   ONLY: rho0_atom_type,&
     133              :                                               rho0_mpole_type
     134              :    USE qs_rho_atom_types,               ONLY: rho_atom_type
     135              :    USE qs_rho_types,                    ONLY: qs_rho_p_type,&
     136              :                                               qs_rho_release,&
     137              :                                               qs_rho_type
     138              :    USE qs_scf_types,                    ONLY: qs_scf_env_type,&
     139              :                                               scf_env_release
     140              :    USE qs_subsys_types,                 ONLY: qs_subsys_set,&
     141              :                                               qs_subsys_type
     142              :    USE qs_wf_history_types,             ONLY: qs_wf_history_type,&
     143              :                                               wfi_release,&
     144              :                                               wfi_retain
     145              :    USE rel_control_types,               ONLY: rel_c_release,&
     146              :                                               rel_control_type
     147              :    USE rt_propagation_types,            ONLY: rt_prop_release,&
     148              :                                               rt_prop_type
     149              :    USE scf_control_types,               ONLY: scf_c_release,&
     150              :                                               scf_control_type
     151              :    USE semi_empirical_mpole_types,      ONLY: nddo_mpole_release,&
     152              :                                               nddo_mpole_type
     153              :    USE semi_empirical_store_int_types,  ONLY: semi_empirical_si_release,&
     154              :                                               semi_empirical_si_type
     155              :    USE semi_empirical_types,            ONLY: se_taper_release,&
     156              :                                               se_taper_type
     157              :    USE task_list_types,                 ONLY: task_list_type
     158              :    USE tblite_types,                    ONLY: deallocate_tblite_type,&
     159              :                                               tblite_type
     160              :    USE transport_env_types,             ONLY: transport_env_release,&
     161              :                                               transport_env_type
     162              :    USE virial_types,                    ONLY: virial_type
     163              :    USE wannier_states_types,            ONLY: wannier_centres_type
     164              :    USE xas_env_types,                   ONLY: xas_env_release,&
     165              :                                               xas_environment_type
     166              :    USE xc_gauxc_cache,                  ONLY: cp_gauxc_cache_type,&
     167              :                                               gauxc_cache_release
     168              : #include "./base/base_uses.f90"
     169              : 
     170              :    IMPLICIT NONE
     171              : 
     172              :    PRIVATE
     173              : 
     174              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_environment_types'
     175              : 
     176              :    ! Public data types
     177              : 
     178              :    PUBLIC :: qs_environment_type
     179              : 
     180              :    ! Public subroutines
     181              : 
     182              :    PUBLIC :: get_qs_env, &
     183              :              qs_env_create, &
     184              :              qs_env_release, &
     185              :              qs_env_part_release, &
     186              :              set_qs_env
     187              : 
     188              : ! **************************************************************************************************
     189              : !> \param local_rho_set contains the atomic, compensations and core densities
     190              : !>                       and the local parts of the xc terms
     191              : !> \param hartree_local contains the 1, 2 and 3 centers coulomb terms
     192              : !> \param requires_mo_derivs logical, true if dE/dC is required (e.g. OT)
     193              : !> \param has_unit_metric logical, true if the S matrix is considered unity for the SCF
     194              : !> \param mo_derivs the actual derivatives of the total energy wrt to MO coeffs (divided by 2*f_i)
     195              : !> \param xas_env temporary information for xas calculation
     196              : !> \param dftb_potential pair potentials for use with DFTB
     197              : !> \param dispersion_env environment for use with QS dispersion
     198              : !>
     199              : !>      compatibility get (things that you should get from the subsys):
     200              : !> \param atomic_kind_set array with infos about the species (atomic_kinds)
     201              : !>        present in the system
     202              : !> \param particle_set info on the atoms you simulate, pos,...
     203              : !> \param local_particles which particles ar local to this processor
     204              : !>      new:
     205              : !> \param local_molecules which molecules are local to this processor
     206              : !> \param molecule_kind_set description of the molecule kinds
     207              : !> \param molecule_set all the molecule description
     208              : !> \param rtp all data needed for real time propagation
     209              : !> \param x contains data used in Hartree-Fock-Exchange calculations
     210              : !> \param task_list the list of tasks used in collocate and integrate
     211              : !> \param task_list_soft the list of tasks used in collocate and integrate in case of soft basis functions
     212              : !> \param mo_loc_history if a history of localized wfn is kept, they are stored here.
     213              : !> \param molecular_scf_guess_env contains inforamation about and results of claculations
     214              : !>          on separate molecules
     215              : !> \par History
     216              : !>      11.2002 added doc and attribute description [fawzi]
     217              : !>      08.2004 renamed some of the very short names (s,c,k,h) for easier grepping
     218              : !>      06.2018 polar_env added (MK)
     219              : !> \author Matthias Krack & fawzi
     220              : ! **************************************************************************************************
     221              : 
     222              :    TYPE qs_environment_type
     223              :       LOGICAL :: qmmm = .FALSE., qmmm_periodic = .FALSE.
     224              :       LOGICAL :: mimic = .FALSE.
     225              :       LOGICAL :: requires_mo_derivs = .FALSE.
     226              :       LOGICAL :: requires_matrix_vxc = .FALSE.
     227              :       LOGICAL :: has_unit_metric = .FALSE.
     228              :       LOGICAL :: run_rtp = .FALSE.
     229              :       LOGICAL :: linres_run = .FALSE.
     230              :       LOGICAL :: calc_image_preconditioner = .FALSE.
     231              :       LOGICAL :: do_transport = .FALSE.
     232              :       LOGICAL :: single_point_run = .FALSE.
     233              :       LOGICAL :: given_embed_pot = .FALSE.
     234              :       LOGICAL :: energy_correction = .FALSE.
     235              :       LOGICAL :: harris_method = .FALSE.
     236              :       LOGICAL :: do_rixs = .FALSE.
     237              :       REAL(KIND=dp)                                         :: sim_time = -1.0_dp
     238              :       REAL(KIND=dp) :: start_time = -1.0_dp, target_time = -1.0_dp
     239              :       REAL(KIND=dp), DIMENSION(:, :), POINTER               :: image_matrix => NULL()
     240              :       REAL(KIND=dp), DIMENSION(:), POINTER                  :: image_coeff => NULL()
     241              :       INTEGER, DIMENSION(:), POINTER                        :: ipiv => NULL()
     242              :       INTEGER                                               :: sim_step = -1
     243              :       TYPE(ls_scf_env_type), POINTER                        :: ls_scf_env => NULL()
     244              :       TYPE(almo_scf_env_type), POINTER                      :: almo_scf_env => NULL()
     245              :       TYPE(transport_env_type), POINTER                     :: transport_env => NULL()
     246              :       TYPE(cell_type), POINTER                              :: super_cell => NULL()
     247              :       TYPE(mo_set_type), DIMENSION(:), POINTER              :: mos => NULL()
     248              :       TYPE(cp_fm_type), DIMENSION(:), POINTER               :: mo_loc_history => NULL()
     249              :       TYPE(dbcsr_p_type), DIMENSION(:), POINTER             :: mo_derivs => NULL()
     250              :       TYPE(scf_control_type), POINTER                       :: scf_control => NULL()
     251              :       TYPE(rel_control_type), POINTER                       :: rel_control => NULL()
     252              :       ! ZMP adding variables
     253              :       TYPE(qs_rho_type), POINTER                            :: rho_external => NULL()
     254              :       TYPE(pw_r3d_rs_type), POINTER                         :: external_vxc => NULL()
     255              :       TYPE(pw_r3d_rs_type), POINTER                         :: mask => NULL()
     256              :       TYPE(qs_charges_type), POINTER                        :: qs_charges => NULL()
     257              :       TYPE(qs_ks_env_type), POINTER                         :: ks_env => NULL()
     258              :       TYPE(qs_ks_qmmm_env_type), POINTER                    :: ks_qmmm_env => NULL()
     259              :       TYPE(qmmm_env_qm_type), POINTER                       :: qmmm_env_qm => NULL()
     260              :       TYPE(qs_wf_history_type), POINTER                     :: wf_history => NULL()
     261              :       TYPE(qs_scf_env_type), POINTER                        :: scf_env => NULL()
     262              :       TYPE(qs_matrix_pools_type), POINTER                   :: mpools => NULL()
     263              :       TYPE(oce_matrix_type), POINTER                        :: oce => NULL()
     264              :       TYPE(local_rho_type), POINTER                         :: local_rho_set => NULL()
     265              :       TYPE(hartree_local_type), POINTER                     :: hartree_local => NULL()
     266              :       TYPE(section_vals_type), POINTER                      :: input => NULL()
     267              :       TYPE(linres_control_type), POINTER                    :: linres_control => NULL()
     268              :       TYPE(xas_environment_type), POINTER                   :: xas_env => NULL()
     269              :       TYPE(cp_ddapc_type), POINTER                          :: cp_ddapc_env => NULL()
     270              :       TYPE(cp_ddapc_ewald_type), POINTER                    :: cp_ddapc_ewald => NULL()
     271              :       REAL(KIND=dp), DIMENSION(:, :), POINTER               :: outer_scf_history => NULL()
     272              :       INTEGER                                               :: outer_scf_ihistory = -1
     273              :       REAL(KIND=dp), DIMENSION(:, :), POINTER               :: gradient_history => NULL(), &
     274              :                                                                variable_history => NULL()
     275              :       TYPE(hfx_type), DIMENSION(:, :), POINTER              :: x_data => NULL()
     276              :       TYPE(et_coupling_type), POINTER                       :: et_coupling => NULL()
     277              :       TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), POINTER  :: dftb_potential => NULL()
     278              :       TYPE(admm_type), POINTER                              :: admm_env => NULL()
     279              :       TYPE(active_space_type), POINTER                      :: active_space => NULL()
     280              :       ! LRI
     281              :       TYPE(lri_environment_type), POINTER                   :: lri_env => NULL()
     282              :       TYPE(lri_density_type), POINTER                       :: lri_density => NULL()
     283              :       ! Harris model
     284              :       TYPE(harris_type), POINTER                            :: harris_env => NULL()
     285              :       ! Energy correction
     286              :       TYPE(energy_correction_type), POINTER                 :: ec_env => NULL()
     287              :       ! Excited States
     288              :       LOGICAL                                               :: excited_state = .FALSE.
     289              :       TYPE(excited_energy_type), POINTER                    :: exstate_env => NULL()
     290              :       ! Empirical dispersion
     291              :       TYPE(qs_dispersion_type), POINTER                     :: dispersion_env => NULL()
     292              :       ! Empirical geometrical BSSE correction
     293              :       TYPE(qs_gcp_type), POINTER                            :: gcp_env => NULL()
     294              :       ! Semi-empirical and DFTB types
     295              :       TYPE(ewald_environment_type), POINTER                 :: ewald_env => NULL()
     296              :       TYPE(ewald_pw_type), POINTER                          :: ewald_pw => NULL()
     297              :       ! Semi-empirical types
     298              :       TYPE(se_taper_type), POINTER                          :: se_taper => NULL()
     299              :       TYPE(semi_empirical_si_type), POINTER                 :: se_store_int_env => NULL()
     300              :       TYPE(nddo_mpole_type), POINTER                        :: se_nddo_mpole => NULL()
     301              :       TYPE(fist_nonbond_env_type), POINTER                  :: se_nonbond_env => NULL()
     302              :       TYPE(rt_prop_type), POINTER                           :: rtp => NULL()
     303              :       TYPE(efield_berry_type), POINTER                      :: efield => NULL()
     304              :       ! a history for the broyden ot
     305              :       REAL(KIND=dp)                                         :: broyden_adaptive_sigma = -1.0_dp
     306              :       TYPE(mp2_type), POINTER                               :: mp2_env => NULL()
     307              :       TYPE(post_scf_bandstructure_type), POINTER                                :: bs_env => NULL()
     308              :       TYPE(kg_environment_type), POINTER                    :: kg_env => NULL()
     309              :       TYPE(wannier_centres_type), POINTER, DIMENSION(:)     :: WannierCentres => NULL()
     310              :       TYPE(molecular_scf_guess_env_type), POINTER           :: molecular_scf_guess_env => NULL()
     311              :       ! Subsystem densities
     312              :       TYPE(qs_rho_p_type), DIMENSION(:), POINTER            :: subsys_dens => NULL()
     313              :       ! Embedding potential
     314              :       TYPE(pw_r3d_rs_type), POINTER                         :: embed_pot => NULL()
     315              :       TYPE(pw_r3d_rs_type), POINTER                         :: spin_embed_pot => NULL()
     316              :       ! Polarizability tensor
     317              :       TYPE(polar_env_type), POINTER                         :: polar_env => NULL()
     318              :       ! EEQ charges
     319              :       REAL(KIND=dp), DIMENSION(:), POINTER                  :: eeq => NULL()
     320              :       ! Resp charges
     321              :       REAL(KIND=dp), DIMENSION(:), POINTER                  :: rhs => NULL()
     322              :       REAL(KIND=dp)                                         :: total_zeff_corr = -1.0_dp, surface_dipole_moment = -1.0_dp
     323              :       LOGICAL                                               :: surface_dipole_switch_off = .FALSE.
     324              :       TYPE(mo_set_type), DIMENSION(:), POINTER              :: mos_last_converged => NULL()
     325              :       ! tblite
     326              :       TYPE(tblite_type), POINTER                            :: tb_tblite => Null()
     327              :       TYPE(cp_gauxc_cache_type), POINTER                    :: gauxc_cache => NULL()
     328              :    END TYPE qs_environment_type
     329              : 
     330              : CONTAINS
     331              : 
     332              : ! **************************************************************************************************
     333              : !> \brief   Get the QUICKSTEP environment.
     334              : !> \param qs_env ...
     335              : !> \param atomic_kind_set ...
     336              : !> \param qs_kind_set ...
     337              : !> \param cell ...
     338              : !> \param super_cell ...
     339              : !> \param cell_ref ...
     340              : !> \param use_ref_cell ...
     341              : !> \param kpoints ...
     342              : !> \param dft_control ...
     343              : !> \param mos ...
     344              : !> \param sab_orb ...
     345              : !> \param sab_all ...
     346              : !> \param qmmm ...
     347              : !> \param qmmm_periodic ...
     348              : !> \param mimic ...
     349              : !> \param sac_ae ...
     350              : !> \param sac_ppl ...
     351              : !> \param sac_lri ...
     352              : !> \param sap_ppnl ...
     353              : !> \param sab_vdw ...
     354              : !> \param sab_scp ...
     355              : !> \param sap_oce ...
     356              : !> \param sab_lrc ...
     357              : !> \param sab_se ...
     358              : !> \param sab_xtbe ...
     359              : !> \param sab_tbe ...
     360              : !> \param sab_core ...
     361              : !> \param sab_xb ...
     362              : !> \param sab_xtb_pp ...
     363              : !> \param sab_xtb_nonbond ...
     364              : !> \param sab_almo ...
     365              : !> \param sab_kp ...
     366              : !> \param sab_kp_nosym ...
     367              : !> \param sab_cneo ...
     368              : !> \param particle_set ...
     369              : !> \param energy ...
     370              : !> \param force ...
     371              : !> \param matrix_h ...
     372              : !> \param matrix_h_im ...
     373              : !> \param matrix_ks ...
     374              : !> \param matrix_ks_im ...
     375              : !> \param matrix_vxc ...
     376              : !> \param run_rtp ...
     377              : !> \param rtp ...
     378              : !> \param matrix_h_kp ...
     379              : !> \param matrix_h_im_kp ...
     380              : !> \param matrix_ks_kp ...
     381              : !> \param matrix_ks_im_kp ...
     382              : !> \param matrix_vxc_kp ...
     383              : !> \param kinetic_kp ...
     384              : !> \param matrix_s_kp ...
     385              : !> \param matrix_w_kp ...
     386              : !> \param matrix_s_RI_aux_kp ...
     387              : !> \param matrix_s ...
     388              : !> \param matrix_s_RI_aux ...
     389              : !> \param matrix_w ...
     390              : !> \param matrix_p_mp2 ...
     391              : !> \param matrix_p_mp2_admm ...
     392              : !> \param matrix_vhxc ...
     393              : !> \param rho ...
     394              : !> \param rho_xc ...
     395              : !> \param pw_env ...
     396              : !> \param ewald_env ...
     397              : !> \param ewald_pw ...
     398              : !> \param active_space ...
     399              : !> \param mpools ...
     400              : !> \param input ...
     401              : !> \param para_env ...
     402              : !> \param blacs_env ...
     403              : !> \param scf_control ...
     404              : !> \param rel_control ...
     405              : !> \param kinetic ...
     406              : !> \param qs_charges ...
     407              : !> \param vppl ...
     408              : !> \param xcint_weights ...
     409              : !> \param rho_core ...
     410              : !> \param rho_nlcc ...
     411              : !> \param rho_nlcc_g ...
     412              : !> \param ks_env ...
     413              : !> \param ks_qmmm_env ...
     414              : !> \param wf_history ...
     415              : !> \param scf_env ...
     416              : !> \param local_particles ...
     417              : !> \param local_molecules ...
     418              : !> \param distribution_2d ...
     419              : !> \param dbcsr_dist ...
     420              : !> \param molecule_kind_set ...
     421              : !> \param molecule_set ...
     422              : !> \param subsys ...
     423              : !> \param cp_subsys ...
     424              : !> \param oce ...
     425              : !> \param local_rho_set ...
     426              : !> \param rho_atom_set ...
     427              : !> \param task_list ...
     428              : !> \param task_list_soft ...
     429              : !> \param rho0_atom_set ...
     430              : !> \param rho0_mpole ...
     431              : !> \param rhoz_set ...
     432              : !> \param rhoz_cneo_set ...
     433              : !> \param ecoul_1c ...
     434              : !> \param rho0_s_rs ...
     435              : !> \param rho0_s_gs ...
     436              : !> \param rhoz_cneo_s_rs ...
     437              : !> \param rhoz_cneo_s_gs ...
     438              : !> \param do_kpoints ...
     439              : !> \param has_unit_metric ...
     440              : !> \param requires_mo_derivs ...
     441              : !> \param mo_derivs ...
     442              : !> \param mo_loc_history ...
     443              : !> \param nkind ...
     444              : !> \param natom ...
     445              : !> \param nelectron_total ...
     446              : !> \param nelectron_spin ...
     447              : !> \param efield ...
     448              : !> \param neighbor_list_id ...
     449              : !> \param linres_control ...
     450              : !> \param xas_env ...
     451              : !> \param virial ...
     452              : !> \param cp_ddapc_env ...
     453              : !> \param cp_ddapc_ewald ...
     454              : !> \param outer_scf_history ...
     455              : !> \param outer_scf_ihistory ...
     456              : !> \param x_data ...
     457              : !> \param et_coupling ...
     458              : !> \param dftb_potential ...
     459              : !> \param results ...
     460              : !> \param se_taper ...
     461              : !> \param se_store_int_env ...
     462              : !> \param se_nddo_mpole ...
     463              : !> \param se_nonbond_env ...
     464              : !> \param admm_env ...
     465              : !> \param lri_env ...
     466              : !> \param lri_density ...
     467              : !> \param exstate_env ...
     468              : !> \param ec_env ...
     469              : !> \param harris_env ...
     470              : !> \param dispersion_env ...
     471              : !> \param gcp_env ...
     472              : !> \param vee ...
     473              : !> \param rho_external ...
     474              : !> \param external_vxc ...
     475              : !> \param mask ...
     476              : !> \param mp2_env ...
     477              : !> \param bs_env ...
     478              : !> \param kg_env ...
     479              : !> \param WannierCentres ...
     480              : !> \param atprop ...
     481              : !> \param ls_scf_env ...
     482              : !> \param do_transport ...
     483              : !> \param transport_env ...
     484              : !> \param v_hartree_rspace ...
     485              : !> \param s_mstruct_changed ...
     486              : !> \param rho_changed ...
     487              : !> \param potential_changed ...
     488              : !> \param forces_up_to_date ...
     489              : !> \param mscfg_env ...
     490              : !> \param almo_scf_env ...
     491              : !> \param gradient_history ...
     492              : !> \param variable_history ...
     493              : !> \param embed_pot ...
     494              : !> \param spin_embed_pot ...
     495              : !> \param polar_env ...
     496              : !> \param mos_last_converged ... [SGh]
     497              : !> \param eeq ...
     498              : !> \param rhs ...
     499              : !> \param do_rixs ...
     500              : !> \param tb_tblite ...
     501              : !> \date    23.01.2002
     502              : !> \author  MK
     503              : !> \version 1.0
     504              : ! **************************************************************************************************
     505     12669164 :    SUBROUTINE get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, &
     506              :                          dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, &
     507              :                          sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, &
     508              :                          sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, &
     509              :                          sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, &
     510              :                          matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, &
     511              :                          matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, &
     512              :                          matrix_w_kp, matrix_s_RI_aux_kp, matrix_s, matrix_s_RI_aux, matrix_w, &
     513              :                          matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, &
     514              :                          rho_xc, pw_env, ewald_env, ewald_pw, active_space, &
     515              :                          mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, &
     516              :                          vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, &
     517              :                          ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, &
     518              :                          local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, &
     519              :                          molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, &
     520              :                          task_list, task_list_soft, &
     521              :                          rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, &
     522              :                          rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, &
     523              :                          do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, &
     524              :                          mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, &
     525              :                          neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, &
     526              :                          outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, &
     527              :                          se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, &
     528              :                          lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, &
     529              :                          rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, &
     530              :                          WannierCentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, &
     531              :                          s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, &
     532              :                          gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, &
     533              :                          eeq, rhs, do_rixs, tb_tblite)
     534              : 
     535              :       TYPE(qs_environment_type), INTENT(IN)              :: qs_env
     536              :       TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
     537              :          POINTER                                         :: atomic_kind_set
     538              :       TYPE(qs_kind_type), DIMENSION(:), OPTIONAL, &
     539              :          POINTER                                         :: qs_kind_set
     540              :       TYPE(cell_type), OPTIONAL, POINTER                 :: cell, super_cell, cell_ref
     541              :       LOGICAL, OPTIONAL                                  :: use_ref_cell
     542              :       TYPE(kpoint_type), OPTIONAL, POINTER               :: kpoints
     543              :       TYPE(dft_control_type), OPTIONAL, POINTER          :: dft_control
     544              :       TYPE(mo_set_type), DIMENSION(:), OPTIONAL, POINTER :: mos
     545              :       TYPE(neighbor_list_set_p_type), DIMENSION(:), &
     546              :          OPTIONAL, POINTER                               :: sab_orb, sab_all
     547              :       LOGICAL, OPTIONAL                                  :: qmmm, qmmm_periodic, mimic
     548              :       TYPE(neighbor_list_set_p_type), DIMENSION(:), OPTIONAL, POINTER :: sac_ae, sac_ppl, sac_lri, &
     549              :          sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, &
     550              :          sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo
     551              :       TYPE(particle_type), DIMENSION(:), OPTIONAL, &
     552              :          POINTER                                         :: particle_set
     553              :       TYPE(qs_energy_type), OPTIONAL, POINTER            :: energy
     554              :       TYPE(qs_force_type), DIMENSION(:), OPTIONAL, &
     555              :          POINTER                                         :: force
     556              :       TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
     557              :          POINTER                                         :: matrix_h, matrix_h_im, matrix_ks, &
     558              :                                                             matrix_ks_im, matrix_vxc
     559              :       LOGICAL, OPTIONAL                                  :: run_rtp
     560              :       TYPE(rt_prop_type), OPTIONAL, POINTER              :: rtp
     561              :       TYPE(dbcsr_p_type), DIMENSION(:, :), OPTIONAL, POINTER :: matrix_h_kp, matrix_h_im_kp, &
     562              :          matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, &
     563              :          matrix_s_RI_aux_kp
     564              :       TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
     565              :          POINTER                                         :: matrix_s, matrix_s_RI_aux, matrix_w, &
     566              :                                                             matrix_p_mp2, matrix_p_mp2_admm, &
     567              :                                                             matrix_vhxc
     568              :       TYPE(qs_rho_type), OPTIONAL, POINTER               :: rho, rho_xc
     569              :       TYPE(pw_env_type), OPTIONAL, POINTER               :: pw_env
     570              :       TYPE(ewald_environment_type), OPTIONAL, POINTER    :: ewald_env
     571              :       TYPE(ewald_pw_type), OPTIONAL, POINTER             :: ewald_pw
     572              :       TYPE(active_space_type), OPTIONAL, POINTER         :: active_space
     573              :       TYPE(qs_matrix_pools_type), OPTIONAL, POINTER      :: mpools
     574              :       TYPE(section_vals_type), OPTIONAL, POINTER         :: input
     575              :       TYPE(mp_para_env_type), OPTIONAL, POINTER          :: para_env
     576              :       TYPE(cp_blacs_env_type), OPTIONAL, POINTER         :: blacs_env
     577              :       TYPE(scf_control_type), OPTIONAL, POINTER          :: scf_control
     578              :       TYPE(rel_control_type), OPTIONAL, POINTER          :: rel_control
     579              :       TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
     580              :          POINTER                                         :: kinetic
     581              :       TYPE(qs_charges_type), OPTIONAL, POINTER           :: qs_charges
     582              :       TYPE(pw_r3d_rs_type), OPTIONAL, POINTER            :: vppl, xcint_weights
     583              :       TYPE(pw_c1d_gs_type), OPTIONAL, POINTER            :: rho_core
     584              :       TYPE(pw_r3d_rs_type), OPTIONAL, POINTER            :: rho_nlcc
     585              :       TYPE(pw_c1d_gs_type), OPTIONAL, POINTER            :: rho_nlcc_g
     586              :       TYPE(qs_ks_env_type), OPTIONAL, POINTER            :: ks_env
     587              :       TYPE(qs_ks_qmmm_env_type), OPTIONAL, POINTER       :: ks_qmmm_env
     588              :       TYPE(qs_wf_history_type), OPTIONAL, POINTER        :: wf_history
     589              :       TYPE(qs_scf_env_type), OPTIONAL, POINTER           :: scf_env
     590              :       TYPE(distribution_1d_type), OPTIONAL, POINTER      :: local_particles, local_molecules
     591              :       TYPE(distribution_2d_type), OPTIONAL, POINTER      :: distribution_2d
     592              :       TYPE(dbcsr_distribution_type), OPTIONAL, POINTER   :: dbcsr_dist
     593              :       TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
     594              :          POINTER                                         :: molecule_kind_set
     595              :       TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
     596              :          POINTER                                         :: molecule_set
     597              :       TYPE(qs_subsys_type), OPTIONAL, POINTER            :: subsys
     598              :       TYPE(cp_subsys_type), OPTIONAL, POINTER            :: cp_subsys
     599              :       TYPE(oce_matrix_type), OPTIONAL, POINTER           :: oce
     600              :       TYPE(local_rho_type), OPTIONAL, POINTER            :: local_rho_set
     601              :       TYPE(rho_atom_type), DIMENSION(:), OPTIONAL, &
     602              :          POINTER                                         :: rho_atom_set
     603              :       TYPE(task_list_type), OPTIONAL, POINTER            :: task_list, task_list_soft
     604              :       TYPE(rho0_atom_type), DIMENSION(:), OPTIONAL, &
     605              :          POINTER                                         :: rho0_atom_set
     606              :       TYPE(rho0_mpole_type), OPTIONAL, POINTER           :: rho0_mpole
     607              :       TYPE(rhoz_type), DIMENSION(:), OPTIONAL, POINTER   :: rhoz_set
     608              :       TYPE(rhoz_cneo_type), DIMENSION(:), OPTIONAL, &
     609              :          POINTER                                         :: rhoz_cneo_set
     610              :       TYPE(ecoul_1center_type), DIMENSION(:), OPTIONAL, &
     611              :          POINTER                                         :: ecoul_1c
     612              :       TYPE(pw_r3d_rs_type), OPTIONAL, POINTER            :: rho0_s_rs
     613              :       TYPE(pw_c1d_gs_type), OPTIONAL, POINTER            :: rho0_s_gs
     614              :       TYPE(pw_r3d_rs_type), OPTIONAL, POINTER            :: rhoz_cneo_s_rs
     615              :       TYPE(pw_c1d_gs_type), OPTIONAL, POINTER            :: rhoz_cneo_s_gs
     616              :       LOGICAL, OPTIONAL                                  :: do_kpoints, has_unit_metric, &
     617              :                                                             requires_mo_derivs
     618              :       TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
     619              :          POINTER                                         :: mo_derivs
     620              :       TYPE(cp_fm_type), DIMENSION(:), OPTIONAL, POINTER  :: mo_loc_history
     621              :       INTEGER, OPTIONAL                                  :: nkind, natom, nelectron_total
     622              :       INTEGER, DIMENSION(2), OPTIONAL                    :: nelectron_spin
     623              :       TYPE(efield_berry_type), OPTIONAL, POINTER         :: efield
     624              :       INTEGER, OPTIONAL                                  :: neighbor_list_id
     625              :       TYPE(linres_control_type), OPTIONAL, POINTER       :: linres_control
     626              :       TYPE(xas_environment_type), OPTIONAL, POINTER      :: xas_env
     627              :       TYPE(virial_type), OPTIONAL, POINTER               :: virial
     628              :       TYPE(cp_ddapc_type), OPTIONAL, POINTER             :: cp_ddapc_env
     629              :       TYPE(cp_ddapc_ewald_type), OPTIONAL, POINTER       :: cp_ddapc_ewald
     630              :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: outer_scf_history
     631              :       INTEGER, INTENT(out), OPTIONAL                     :: outer_scf_ihistory
     632              :       TYPE(hfx_type), DIMENSION(:, :), OPTIONAL, POINTER :: x_data
     633              :       TYPE(et_coupling_type), OPTIONAL, POINTER          :: et_coupling
     634              :       TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), &
     635              :          OPTIONAL, POINTER                               :: dftb_potential
     636              :       TYPE(cp_result_type), OPTIONAL, POINTER            :: results
     637              :       TYPE(se_taper_type), OPTIONAL, POINTER             :: se_taper
     638              :       TYPE(semi_empirical_si_type), OPTIONAL, POINTER    :: se_store_int_env
     639              :       TYPE(nddo_mpole_type), OPTIONAL, POINTER           :: se_nddo_mpole
     640              :       TYPE(fist_nonbond_env_type), OPTIONAL, POINTER     :: se_nonbond_env
     641              :       TYPE(admm_type), OPTIONAL, POINTER                 :: admm_env
     642              :       TYPE(lri_environment_type), OPTIONAL, POINTER      :: lri_env
     643              :       TYPE(lri_density_type), OPTIONAL, POINTER          :: lri_density
     644              :       TYPE(excited_energy_type), OPTIONAL, POINTER       :: exstate_env
     645              :       TYPE(energy_correction_type), OPTIONAL, POINTER    :: ec_env
     646              :       TYPE(harris_type), OPTIONAL, POINTER               :: harris_env
     647              :       TYPE(qs_dispersion_type), OPTIONAL, POINTER        :: dispersion_env
     648              :       TYPE(qs_gcp_type), OPTIONAL, POINTER               :: gcp_env
     649              :       TYPE(pw_r3d_rs_type), OPTIONAL, POINTER            :: vee
     650              :       TYPE(qs_rho_type), OPTIONAL, POINTER               :: rho_external
     651              :       TYPE(pw_r3d_rs_type), OPTIONAL, POINTER            :: external_vxc, mask
     652              :       TYPE(mp2_type), OPTIONAL, POINTER                  :: mp2_env
     653              :       TYPE(post_scf_bandstructure_type), OPTIONAL, &
     654              :          POINTER                                         :: bs_env
     655              :       TYPE(kg_environment_type), OPTIONAL, POINTER       :: kg_env
     656              :       TYPE(wannier_centres_type), DIMENSION(:), &
     657              :          OPTIONAL, POINTER                               :: WannierCentres
     658              :       TYPE(atprop_type), OPTIONAL, POINTER               :: atprop
     659              :       TYPE(ls_scf_env_type), OPTIONAL, POINTER           :: ls_scf_env
     660              :       LOGICAL, OPTIONAL                                  :: do_transport
     661              :       TYPE(transport_env_type), OPTIONAL, POINTER        :: transport_env
     662              :       TYPE(pw_r3d_rs_type), OPTIONAL, POINTER            :: v_hartree_rspace
     663              :       LOGICAL, OPTIONAL                                  :: s_mstruct_changed, rho_changed, &
     664              :                                                             potential_changed, forces_up_to_date
     665              :       TYPE(molecular_scf_guess_env_type), OPTIONAL, &
     666              :          POINTER                                         :: mscfg_env
     667              :       TYPE(almo_scf_env_type), OPTIONAL, POINTER         :: almo_scf_env
     668              :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: gradient_history, variable_history
     669              :       TYPE(pw_r3d_rs_type), OPTIONAL, POINTER            :: embed_pot, spin_embed_pot
     670              :       TYPE(polar_env_type), OPTIONAL, POINTER            :: polar_env
     671              :       TYPE(mo_set_type), DIMENSION(:), OPTIONAL, POINTER :: mos_last_converged
     672              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: eeq, rhs
     673              :       LOGICAL, OPTIONAL                                  :: do_rixs
     674              :       TYPE(tblite_type), OPTIONAL, POINTER               :: tb_tblite
     675              : 
     676              :       TYPE(rho0_mpole_type), POINTER                     :: rho0_m
     677              : 
     678     12669164 :       NULLIFY (rho0_m)
     679     12669164 :       CPASSERT(ASSOCIATED(qs_env%ks_env))
     680              : 
     681     12669164 :       IF (PRESENT(outer_scf_history)) outer_scf_history => qs_env%outer_scf_history
     682     12669164 :       IF (PRESENT(outer_scf_ihistory)) outer_scf_ihistory = qs_env%outer_scf_ihistory
     683     12669164 :       IF (PRESENT(gradient_history)) gradient_history => qs_env%gradient_history
     684     12669164 :       IF (PRESENT(variable_history)) variable_history => qs_env%variable_history
     685     12669164 :       IF (PRESENT(mp2_env)) mp2_env => qs_env%mp2_env
     686     12669164 :       IF (PRESENT(bs_env)) bs_env => qs_env%bs_env
     687     12669164 :       IF (PRESENT(kg_env)) kg_env => qs_env%kg_env
     688     12669164 :       IF (PRESENT(super_cell)) super_cell => qs_env%super_cell
     689     12669164 :       IF (PRESENT(qmmm)) qmmm = qs_env%qmmm
     690     12669164 :       IF (PRESENT(qmmm_periodic)) qmmm_periodic = qs_env%qmmm_periodic
     691     12669164 :       IF (PRESENT(mimic)) mimic = qs_env%mimic
     692     12669164 :       IF (PRESENT(mos)) mos => qs_env%mos
     693     12669164 :       IF (PRESENT(mos_last_converged)) mos_last_converged => qs_env%mos_last_converged
     694     12669164 :       IF (PRESENT(ewald_env)) ewald_env => qs_env%ewald_env
     695     12669164 :       IF (PRESENT(ewald_pw)) ewald_pw => qs_env%ewald_pw
     696     12669164 :       IF (PRESENT(mpools)) mpools => qs_env%mpools
     697     12669164 :       IF (PRESENT(scf_control)) scf_control => qs_env%scf_control
     698     12669164 :       IF (PRESENT(rel_control)) rel_control => qs_env%rel_control
     699              :       ! ZMP pointing vectors
     700     12669164 :       IF (PRESENT(rho_external)) rho_external => qs_env%rho_external
     701     12669164 :       IF (PRESENT(external_vxc)) external_vxc => qs_env%external_vxc
     702     12669164 :       IF (PRESENT(mask)) mask => qs_env%mask
     703     12669164 :       IF (PRESENT(qs_charges)) qs_charges => qs_env%qs_charges
     704     12669164 :       IF (PRESENT(ks_env)) ks_env => qs_env%ks_env
     705     12669164 :       IF (PRESENT(ks_qmmm_env)) ks_qmmm_env => qs_env%ks_qmmm_env
     706     12669164 :       IF (PRESENT(wf_history)) wf_history => qs_env%wf_history
     707     12669164 :       IF (PRESENT(scf_env)) scf_env => qs_env%scf_env
     708     12669164 :       IF (PRESENT(oce)) oce => qs_env%oce
     709     12669164 :       IF (PRESENT(requires_mo_derivs)) requires_mo_derivs = qs_env%requires_mo_derivs
     710     12669164 :       IF (PRESENT(has_unit_metric)) has_unit_metric = qs_env%has_unit_metric
     711     12669164 :       IF (PRESENT(mo_derivs)) mo_derivs => qs_env%mo_derivs
     712     12669164 :       IF (PRESENT(mo_loc_history)) mo_loc_history => qs_env%mo_loc_history
     713     12669164 :       IF (PRESENT(linres_control)) linres_control => qs_env%linres_control
     714     12669164 :       IF (PRESENT(se_taper)) se_taper => qs_env%se_taper
     715     12669164 :       IF (PRESENT(se_store_int_env)) se_store_int_env => qs_env%se_store_int_env
     716     12669164 :       IF (PRESENT(se_nddo_mpole)) se_nddo_mpole => qs_env%se_nddo_mpole
     717     12669164 :       IF (PRESENT(se_nonbond_env)) se_nonbond_env => qs_env%se_nonbond_env
     718     12669164 :       IF (PRESENT(lri_env)) lri_env => qs_env%lri_env
     719     12669164 :       IF (PRESENT(lri_density)) lri_density => qs_env%lri_density
     720     12669164 :       IF (PRESENT(harris_env)) harris_env => qs_env%harris_env
     721     12669164 :       IF (PRESENT(ec_env)) ec_env => qs_env%ec_env
     722     12669164 :       IF (PRESENT(exstate_env)) exstate_env => qs_env%exstate_env
     723     12669164 :       IF (PRESENT(dispersion_env)) dispersion_env => qs_env%dispersion_env
     724     12669164 :       IF (PRESENT(gcp_env)) gcp_env => qs_env%gcp_env
     725     12669164 :       IF (PRESENT(run_rtp)) run_rtp = qs_env%run_rtp
     726     12669164 :       IF (PRESENT(rtp)) rtp => qs_env%rtp
     727     12669164 :       IF (PRESENT(ls_scf_env)) ls_scf_env => qs_env%ls_scf_env
     728     12669164 :       IF (PRESENT(almo_scf_env)) almo_scf_env => qs_env%almo_scf_env
     729     12669164 :       IF (PRESENT(do_transport)) do_transport = qs_env%do_transport
     730     12669164 :       IF (PRESENT(transport_env)) transport_env => qs_env%transport_env
     731     12669164 :       IF (PRESENT(mscfg_env)) mscfg_env => qs_env%molecular_scf_guess_env
     732     12669164 :       IF (PRESENT(active_space)) active_space => qs_env%active_space
     733     12669164 :       IF (PRESENT(admm_env)) admm_env => qs_env%admm_env
     734     12669164 :       IF (PRESENT(do_rixs)) do_rixs = qs_env%do_rixs
     735              : 
     736              :       ! Embedding potential
     737     12669164 :       IF (PRESENT(embed_pot)) embed_pot => qs_env%embed_pot
     738     12669164 :       IF (PRESENT(spin_embed_pot)) spin_embed_pot => qs_env%spin_embed_pot
     739              : 
     740              :       ! Polarisability tensor
     741     12669164 :       IF (PRESENT(polar_env)) polar_env => qs_env%polar_env
     742              : 
     743              :       ! EEQ charges
     744     12669164 :       IF (PRESENT(eeq)) eeq => qs_env%eeq
     745              : 
     746              :       ! Resp charges
     747     12669164 :       IF (PRESENT(rhs)) rhs => qs_env%rhs
     748              : 
     749     12669164 :       IF (PRESENT(local_rho_set)) THEN
     750        23638 :          local_rho_set => qs_env%local_rho_set
     751              :       END IF
     752     12669164 :       IF (PRESENT(rho_atom_set)) THEN
     753       180834 :          CALL get_local_rho(qs_env%local_rho_set, rho_atom_set=rho_atom_set)
     754              :       END IF
     755     12669164 :       IF (PRESENT(rho0_atom_set)) THEN
     756        42390 :          CALL get_local_rho(qs_env%local_rho_set, rho0_atom_set=rho0_atom_set)
     757              :       END IF
     758     12669164 :       IF (PRESENT(rho0_mpole)) THEN
     759        74416 :          CALL get_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_mpole)
     760              :       END IF
     761     12669164 :       IF (PRESENT(rhoz_set)) THEN
     762           14 :          CALL get_local_rho(qs_env%local_rho_set, rhoz_set=rhoz_set)
     763              :       END IF
     764     12669164 :       IF (PRESENT(rhoz_cneo_set)) THEN
     765        88337 :          CALL get_local_rho(qs_env%local_rho_set, rhoz_cneo_set=rhoz_cneo_set)
     766              :       END IF
     767     12669164 :       IF (PRESENT(ecoul_1c)) THEN
     768        22390 :          CALL get_hartree_local(qs_env%hartree_local, ecoul_1c=ecoul_1c)
     769              :       END IF
     770     12669164 :       IF (PRESENT(rho0_s_rs)) THEN
     771         1488 :          CALL get_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_m)
     772         1488 :          IF (ASSOCIATED(rho0_m)) THEN
     773         1488 :             rho0_s_rs => rho0_m%rho0_s_rs
     774              :          END IF
     775              :       END IF
     776     12669164 :       IF (PRESENT(rho0_s_gs)) THEN
     777        29208 :          CALL get_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_m)
     778        29208 :          IF (ASSOCIATED(rho0_m)) THEN
     779        23246 :             rho0_s_gs => rho0_m%rho0_s_gs
     780              :          END IF
     781              :       END IF
     782     12669164 :       IF (PRESENT(rhoz_cneo_s_rs)) THEN
     783         1488 :          CALL get_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_m)
     784         1488 :          IF (ASSOCIATED(rho0_m)) THEN
     785         1488 :             rhoz_cneo_s_rs => rho0_m%rhoz_cneo_s_rs
     786              :          END IF
     787              :       END IF
     788     12669164 :       IF (PRESENT(rhoz_cneo_s_gs)) THEN
     789        29208 :          CALL get_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_m)
     790        29208 :          IF (ASSOCIATED(rho0_m)) THEN
     791        23246 :             rhoz_cneo_s_gs => rho0_m%rhoz_cneo_s_gs
     792              :          END IF
     793              :       END IF
     794              : 
     795     12669164 :       IF (PRESENT(xas_env)) xas_env => qs_env%xas_env
     796     12669164 :       IF (PRESENT(input)) input => qs_env%input
     797     12669164 :       IF (PRESENT(cp_ddapc_env)) cp_ddapc_env => qs_env%cp_ddapc_env
     798     12669164 :       IF (PRESENT(cp_ddapc_ewald)) cp_ddapc_ewald => qs_env%cp_ddapc_ewald
     799     12669164 :       IF (PRESENT(x_data)) x_data => qs_env%x_data
     800     12669164 :       IF (PRESENT(et_coupling)) et_coupling => qs_env%et_coupling
     801     12669164 :       IF (PRESENT(dftb_potential)) dftb_potential => qs_env%dftb_potential
     802     12669164 :       IF (PRESENT(efield)) efield => qs_env%efield
     803     12669164 :       IF (PRESENT(WannierCentres)) WannierCentres => qs_env%WannierCentres
     804              : 
     805              :       CALL get_ks_env(qs_env%ks_env, &
     806              :                       v_hartree_rspace=v_hartree_rspace, &
     807              :                       s_mstruct_changed=s_mstruct_changed, &
     808              :                       rho_changed=rho_changed, &
     809              :                       potential_changed=potential_changed, &
     810              :                       forces_up_to_date=forces_up_to_date, &
     811              :                       matrix_h=matrix_h, &
     812              :                       matrix_h_im=matrix_h_im, &
     813              :                       matrix_ks=matrix_ks, &
     814              :                       matrix_ks_im=matrix_ks_im, &
     815              :                       matrix_vxc=matrix_vxc, &
     816              :                       kinetic=kinetic, &
     817              :                       matrix_s=matrix_s, &
     818              :                       matrix_s_RI_aux=matrix_s_RI_aux, &
     819              :                       matrix_ks_im_kp=matrix_ks_im_kp, &
     820              :                       matrix_w=matrix_w, &
     821              :                       matrix_p_mp2=matrix_p_mp2, &
     822              :                       matrix_p_mp2_admm=matrix_p_mp2_admm, &
     823              :                       matrix_vhxc=matrix_vhxc, &
     824              :                       matrix_h_kp=matrix_h_kp, &
     825              :                       matrix_h_im_kp=matrix_h_im_kp, &
     826              :                       matrix_ks_kp=matrix_ks_kp, &
     827              :                       matrix_vxc_kp=matrix_vxc_kp, &
     828              :                       kinetic_kp=kinetic_kp, &
     829              :                       matrix_s_kp=matrix_s_kp, &
     830              :                       matrix_w_kp=matrix_w_kp, &
     831              :                       matrix_s_RI_aux_kp=matrix_s_RI_aux_kp, &
     832              :                       rho=rho, &
     833              :                       rho_xc=rho_xc, &
     834              :                       xcint_weights=xcint_weights, &
     835              :                       rho_core=rho_core, &
     836              :                       rho_nlcc=rho_nlcc, &
     837              :                       rho_nlcc_g=rho_nlcc_g, &
     838              :                       vppl=vppl, &
     839              :                       vee=vee, &
     840              :                       neighbor_list_id=neighbor_list_id, &
     841              :                       sab_orb=sab_orb, &
     842              :                       sab_all=sab_all, &
     843              :                       sab_scp=sab_scp, &
     844              :                       sab_vdw=sab_vdw, &
     845              :                       sac_ae=sac_ae, &
     846              :                       sac_ppl=sac_ppl, &
     847              :                       sac_lri=sac_lri, &
     848              :                       sap_ppnl=sap_ppnl, &
     849              :                       sap_oce=sap_oce, &
     850              :                       sab_se=sab_se, &
     851              :                       sab_lrc=sab_lrc, &
     852              :                       sab_tbe=sab_tbe, &
     853              :                       sab_xtbe=sab_xtbe, &
     854              :                       sab_core=sab_core, &
     855              :                       sab_xb=sab_xb, &
     856              :                       sab_xtb_pp=sab_xtb_pp, &
     857              :                       sab_xtb_nonbond=sab_xtb_nonbond, &
     858              :                       sab_almo=sab_almo, &
     859              :                       sab_kp=sab_kp, &
     860              :                       sab_kp_nosym=sab_kp_nosym, &
     861              :                       sab_cneo=sab_cneo, &
     862              :                       task_list=task_list, &
     863              :                       task_list_soft=task_list_soft, &
     864              :                       kpoints=kpoints, &
     865              :                       do_kpoints=do_kpoints, &
     866              :                       local_molecules=local_molecules, &
     867              :                       local_particles=local_particles, &
     868              :                       atprop=atprop, &
     869              :                       virial=virial, &
     870              :                       results=results, &
     871              :                       cell=cell, &
     872              :                       cell_ref=cell_ref, &
     873              :                       use_ref_cell=use_ref_cell, &
     874              :                       energy=energy, &
     875              :                       force=force, &
     876              :                       qs_kind_set=qs_kind_set, &
     877              :                       subsys=subsys, &
     878              :                       cp_subsys=cp_subsys, &
     879              :                       atomic_kind_set=atomic_kind_set, &
     880              :                       particle_set=particle_set, &
     881              :                       molecule_kind_set=molecule_kind_set, &
     882              :                       molecule_set=molecule_set, &
     883              :                       natom=natom, &
     884              :                       nkind=nkind, &
     885              :                       dft_control=dft_control, &
     886              :                       dbcsr_dist=dbcsr_dist, &
     887              :                       distribution_2d=distribution_2d, &
     888              :                       pw_env=pw_env, &
     889              :                       para_env=para_env, &
     890              :                       blacs_env=blacs_env, &
     891              :                       nelectron_total=nelectron_total, &
     892     12669164 :                       nelectron_spin=nelectron_spin)
     893              : 
     894     12669164 :       IF (PRESENT(tb_tblite)) tb_tblite => qs_env%tb_tblite
     895              : 
     896     12669164 :    END SUBROUTINE get_qs_env
     897              : 
     898              : ! **************************************************************************************************
     899              : !> \brief  Initialise the QUICKSTEP environment.
     900              : !> \param qs_env ...
     901              : !> \param globenv ...
     902              : !> \date    25.01.2002
     903              : !> \author  MK
     904              : !> \version 1.0
     905              : ! **************************************************************************************************
     906         8800 :    SUBROUTINE init_qs_env(qs_env, globenv)
     907              : 
     908              :       TYPE(qs_environment_type), INTENT(INOUT)           :: qs_env
     909              :       TYPE(global_environment_type), OPTIONAL, POINTER   :: globenv
     910              : 
     911         8800 :       NULLIFY (qs_env%ls_scf_env)
     912         8800 :       NULLIFY (qs_env%almo_scf_env)
     913         8800 :       NULLIFY (qs_env%transport_env)
     914         8800 :       NULLIFY (qs_env%image_matrix)
     915         8800 :       NULLIFY (qs_env%ipiv)
     916         8800 :       NULLIFY (qs_env%image_coeff)
     917         8800 :       NULLIFY (qs_env%super_cell)
     918         8800 :       NULLIFY (qs_env%mos)
     919         8800 :       NULLIFY (qs_env%mos_last_converged)
     920         8800 :       NULLIFY (qs_env%mpools)
     921         8800 :       NULLIFY (qs_env%ewald_env)
     922         8800 :       NULLIFY (qs_env%ewald_pw)
     923         8800 :       NULLIFY (qs_env%scf_control)
     924         8800 :       NULLIFY (qs_env%rel_control)
     925         8800 :       NULLIFY (qs_env%qs_charges)
     926              :       ! ZMP initializing arrays
     927         8800 :       NULLIFY (qs_env%rho_external)
     928         8800 :       NULLIFY (qs_env%external_vxc)
     929         8800 :       NULLIFY (qs_env%mask)
     930              :       ! Embedding potential
     931         8800 :       NULLIFY (qs_env%embed_pot)
     932         8800 :       NULLIFY (qs_env%spin_embed_pot)
     933              : 
     934              :       ! Polarisability tensor
     935         8800 :       NULLIFY (qs_env%polar_env)
     936              : 
     937         8800 :       NULLIFY (qs_env%ks_env)
     938         8800 :       NULLIFY (qs_env%ks_qmmm_env)
     939         8800 :       NULLIFY (qs_env%wf_history)
     940         8800 :       NULLIFY (qs_env%scf_env)
     941         8800 :       NULLIFY (qs_env%oce)
     942         8800 :       NULLIFY (qs_env%local_rho_set)
     943         8800 :       NULLIFY (qs_env%hartree_local)
     944         8800 :       NULLIFY (qs_env%input)
     945         8800 :       NULLIFY (qs_env%linres_control)
     946         8800 :       NULLIFY (qs_env%xas_env)
     947         8800 :       NULLIFY (qs_env%cp_ddapc_env)
     948         8800 :       NULLIFY (qs_env%cp_ddapc_ewald)
     949         8800 :       NULLIFY (qs_env%outer_scf_history)
     950         8800 :       NULLIFY (qs_env%gradient_history)
     951         8800 :       NULLIFY (qs_env%variable_history)
     952         8800 :       NULLIFY (qs_env%x_data)
     953         8800 :       NULLIFY (qs_env%et_coupling)
     954         8800 :       NULLIFY (qs_env%dftb_potential)
     955         8800 :       NULLIFY (qs_env%active_space)
     956              : 
     957         8800 :       NULLIFY (qs_env%se_taper)
     958         8800 :       NULLIFY (qs_env%se_store_int_env)
     959         8800 :       NULLIFY (qs_env%se_nddo_mpole)
     960         8800 :       NULLIFY (qs_env%se_nonbond_env)
     961         8800 :       NULLIFY (qs_env%admm_env)
     962         8800 :       NULLIFY (qs_env%efield)
     963         8800 :       NULLIFY (qs_env%lri_env)
     964         8800 :       NULLIFY (qs_env%harris_env)
     965         8800 :       NULLIFY (qs_env%ec_env)
     966         8800 :       NULLIFY (qs_env%exstate_env)
     967         8800 :       NULLIFY (qs_env%lri_density)
     968         8800 :       NULLIFY (qs_env%gcp_env)
     969         8800 :       NULLIFY (qs_env%rtp)
     970         8800 :       NULLIFY (qs_env%mp2_env)
     971         8800 :       NULLIFY (qs_env%bs_env)
     972         8800 :       NULLIFY (qs_env%kg_env)
     973         8800 :       NULLIFY (qs_env%WannierCentres)
     974              : 
     975         8800 :       qs_env%outer_scf_ihistory = 0
     976         8800 :       qs_env%broyden_adaptive_sigma = -1.0_dp
     977              : 
     978         8800 :       CALL local_rho_set_create(qs_env%local_rho_set)
     979         8800 :       CALL hartree_local_create(qs_env%hartree_local)
     980         8800 :       qs_env%run_rtp = .FALSE.
     981         8800 :       qs_env%linres_run = .FALSE.
     982         8800 :       qs_env%single_point_run = .FALSE.
     983         8800 :       qs_env%qmmm = .FALSE.
     984         8800 :       qs_env%qmmm_periodic = .FALSE.
     985         8800 :       qs_env%mimic = .FALSE.
     986         8800 :       qs_env%requires_mo_derivs = .FALSE.
     987         8800 :       qs_env%requires_matrix_vxc = .FALSE.
     988         8800 :       qs_env%has_unit_metric = .FALSE.
     989         8800 :       qs_env%calc_image_preconditioner = .TRUE.
     990         8800 :       qs_env%do_transport = .FALSE.
     991         8800 :       qs_env%given_embed_pot = .FALSE.
     992         8800 :       qs_env%do_rixs = .FALSE.
     993         8800 :       IF (PRESENT(globenv)) THEN
     994         8794 :          qs_env%target_time = globenv%cp2k_target_time
     995         8794 :          qs_env%start_time = globenv%cp2k_start_time
     996              :          qs_env%single_point_run = (globenv%run_type_id == energy_run .OR. &
     997         8794 :                                     globenv%run_type_id == energy_force_run)
     998              :       ELSE
     999            6 :          qs_env%target_time = 0.0_dp
    1000            6 :          qs_env%start_time = 0.0_dp
    1001              :       END IF
    1002              : 
    1003         8800 :       qs_env%sim_time = 0._dp
    1004         8800 :       qs_env%sim_step = 0
    1005              : 
    1006         8800 :       qs_env%total_zeff_corr = 0.0_dp
    1007         8800 :       qs_env%surface_dipole_moment = 0.0_dp
    1008         8800 :       qs_env%surface_dipole_switch_off = .FALSE.
    1009              : 
    1010              :       ! Zero all variables containing results
    1011         8800 :       NULLIFY (qs_env%mo_derivs)
    1012         8800 :       NULLIFY (qs_env%mo_loc_history)
    1013              : 
    1014         8800 :       IF (.NOT. ASSOCIATED(qs_env%molecular_scf_guess_env)) ALLOCATE (qs_env%molecular_scf_guess_env)
    1015              : 
    1016         8800 :       NULLIFY (qs_env%tb_tblite)
    1017         8800 :       NULLIFY (qs_env%gauxc_cache)
    1018              : 
    1019         8800 :    END SUBROUTINE init_qs_env
    1020              : 
    1021              : ! **************************************************************************************************
    1022              : !> \brief   Set the QUICKSTEP environment.
    1023              : !> \param qs_env ...
    1024              : !> \param super_cell ...
    1025              : !> \param mos ...
    1026              : !> \param qmmm ...
    1027              : !> \param qmmm_periodic ...
    1028              : !> \param mimic ...
    1029              : !> \param ewald_env ...
    1030              : !> \param ewald_pw ...
    1031              : !> \param mpools ...
    1032              : !> \param rho_external ...
    1033              : !> \param external_vxc ...
    1034              : !> \param mask ...
    1035              : !> \param scf_control ...
    1036              : !> \param rel_control ...
    1037              : !> \param qs_charges ...
    1038              : !> \param ks_env ...
    1039              : !> \param ks_qmmm_env ...
    1040              : !> \param wf_history ...
    1041              : !> \param scf_env ...
    1042              : !> \param active_space ...
    1043              : !> \param input ...
    1044              : !> \param oce ...
    1045              : !> \param rho_atom_set ...
    1046              : !> \param rho0_atom_set ...
    1047              : !> \param rho0_mpole ...
    1048              : !> \param run_rtp ...
    1049              : !> \param rtp ...
    1050              : !> \param rhoz_set ...
    1051              : !> \param rhoz_tot ...
    1052              : !> \param ecoul_1c ...
    1053              : !> \param has_unit_metric ...
    1054              : !> \param requires_mo_derivs ...
    1055              : !> \param mo_derivs ...
    1056              : !> \param mo_loc_history ...
    1057              : !> \param efield ...
    1058              : !> \param rhoz_cneo_set ...
    1059              : !> \param linres_control ...
    1060              : !> \param xas_env ...
    1061              : !> \param cp_ddapc_env ...
    1062              : !> \param cp_ddapc_ewald ...
    1063              : !> \param outer_scf_history ...
    1064              : !> \param outer_scf_ihistory ...
    1065              : !> \param x_data ...
    1066              : !> \param et_coupling ...
    1067              : !> \param dftb_potential ...
    1068              : !> \param se_taper ...
    1069              : !> \param se_store_int_env ...
    1070              : !> \param se_nddo_mpole ...
    1071              : !> \param se_nonbond_env ...
    1072              : !> \param admm_env ...
    1073              : !> \param ls_scf_env ...
    1074              : !> \param do_transport ...
    1075              : !> \param transport_env ...
    1076              : !> \param lri_env ...
    1077              : !> \param lri_density ...
    1078              : !> \param exstate_env ...
    1079              : !> \param ec_env ...
    1080              : !> \param dispersion_env ...
    1081              : !> \param harris_env ...
    1082              : !> \param gcp_env ...
    1083              : !> \param mp2_env ...
    1084              : !> \param bs_env ...
    1085              : !> \param kg_env ...
    1086              : !> \param force ...
    1087              : !> \param kpoints ...
    1088              : !> \param WannierCentres ...
    1089              : !> \param almo_scf_env ...
    1090              : !> \param gradient_history ...
    1091              : !> \param variable_history ...
    1092              : !> \param embed_pot ...
    1093              : !> \param spin_embed_pot ...
    1094              : !> \param polar_env ...
    1095              : !> \param mos_last_converged ... [SGh]
    1096              : !> \param eeq ...
    1097              : !> \param rhs ...
    1098              : !> \param do_rixs ...
    1099              : !> \param tb_tblite ...
    1100              : !> \date    23.01.2002
    1101              : !> \author  MK
    1102              : !> \version 1.0
    1103              : ! **************************************************************************************************
    1104       181408 :    SUBROUTINE set_qs_env(qs_env, super_cell, &
    1105              :                          mos, qmmm, qmmm_periodic, mimic, &
    1106              :                          ewald_env, ewald_pw, mpools, &
    1107              :                          rho_external, external_vxc, mask, &
    1108              :                          scf_control, rel_control, qs_charges, ks_env, &
    1109              :                          ks_qmmm_env, wf_history, scf_env, active_space, &
    1110              :                          input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, &
    1111              :                          rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, &
    1112              :                          mo_loc_history, efield, rhoz_cneo_set, &
    1113              :                          linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, &
    1114              :                          outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, &
    1115              :                          se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, &
    1116              :                          do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, &
    1117              :                          harris_env, gcp_env, mp2_env, bs_env, kg_env, force, &
    1118              :                          kpoints, WannierCentres, almo_scf_env, gradient_history, variable_history, embed_pot, &
    1119              :                          spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
    1120              : 
    1121              :       TYPE(qs_environment_type), INTENT(INOUT)           :: qs_env
    1122              :       TYPE(cell_type), OPTIONAL, POINTER                 :: super_cell
    1123              :       TYPE(mo_set_type), DIMENSION(:), OPTIONAL, POINTER :: mos
    1124              :       LOGICAL, OPTIONAL                                  :: qmmm, qmmm_periodic, mimic
    1125              :       TYPE(ewald_environment_type), OPTIONAL, POINTER    :: ewald_env
    1126              :       TYPE(ewald_pw_type), OPTIONAL, POINTER             :: ewald_pw
    1127              :       TYPE(qs_matrix_pools_type), OPTIONAL, POINTER      :: mpools
    1128              :       TYPE(qs_rho_type), OPTIONAL, POINTER               :: rho_external
    1129              :       TYPE(pw_r3d_rs_type), OPTIONAL, POINTER            :: external_vxc, mask
    1130              :       TYPE(scf_control_type), OPTIONAL, POINTER          :: scf_control
    1131              :       TYPE(rel_control_type), OPTIONAL, POINTER          :: rel_control
    1132              :       TYPE(qs_charges_type), OPTIONAL, POINTER           :: qs_charges
    1133              :       TYPE(qs_ks_env_type), OPTIONAL, POINTER            :: ks_env
    1134              :       TYPE(qs_ks_qmmm_env_type), OPTIONAL, POINTER       :: ks_qmmm_env
    1135              :       TYPE(qs_wf_history_type), OPTIONAL, POINTER        :: wf_history
    1136              :       TYPE(qs_scf_env_type), OPTIONAL, POINTER           :: scf_env
    1137              :       TYPE(active_space_type), OPTIONAL, POINTER         :: active_space
    1138              :       TYPE(section_vals_type), OPTIONAL, POINTER         :: input
    1139              :       TYPE(oce_matrix_type), OPTIONAL, POINTER           :: oce
    1140              :       TYPE(rho_atom_type), DIMENSION(:), OPTIONAL, &
    1141              :          POINTER                                         :: rho_atom_set
    1142              :       TYPE(rho0_atom_type), DIMENSION(:), OPTIONAL, &
    1143              :          POINTER                                         :: rho0_atom_set
    1144              :       TYPE(rho0_mpole_type), OPTIONAL, POINTER           :: rho0_mpole
    1145              :       LOGICAL, OPTIONAL                                  :: run_rtp
    1146              :       TYPE(rt_prop_type), OPTIONAL, POINTER              :: rtp
    1147              :       TYPE(rhoz_type), DIMENSION(:), OPTIONAL, POINTER   :: rhoz_set
    1148              :       REAL(dp), OPTIONAL                                 :: rhoz_tot
    1149              :       TYPE(ecoul_1center_type), DIMENSION(:), OPTIONAL, &
    1150              :          POINTER                                         :: ecoul_1c
    1151              :       LOGICAL, OPTIONAL                                  :: has_unit_metric, requires_mo_derivs
    1152              :       TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
    1153              :          POINTER                                         :: mo_derivs
    1154              :       TYPE(cp_fm_type), DIMENSION(:), OPTIONAL, POINTER  :: mo_loc_history
    1155              :       TYPE(efield_berry_type), OPTIONAL, POINTER         :: efield
    1156              :       TYPE(rhoz_cneo_type), DIMENSION(:), OPTIONAL, &
    1157              :          POINTER                                         :: rhoz_cneo_set
    1158              :       TYPE(linres_control_type), OPTIONAL, POINTER       :: linres_control
    1159              :       TYPE(xas_environment_type), OPTIONAL, POINTER      :: xas_env
    1160              :       TYPE(cp_ddapc_type), OPTIONAL, POINTER             :: cp_ddapc_env
    1161              :       TYPE(cp_ddapc_ewald_type), OPTIONAL, POINTER       :: cp_ddapc_ewald
    1162              :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: outer_scf_history
    1163              :       INTEGER, INTENT(IN), OPTIONAL                      :: outer_scf_ihistory
    1164              :       TYPE(hfx_type), DIMENSION(:, :), OPTIONAL, POINTER :: x_data
    1165              :       TYPE(et_coupling_type), OPTIONAL, POINTER          :: et_coupling
    1166              :       TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), &
    1167              :          OPTIONAL, POINTER                               :: dftb_potential
    1168              :       TYPE(se_taper_type), OPTIONAL, POINTER             :: se_taper
    1169              :       TYPE(semi_empirical_si_type), OPTIONAL, POINTER    :: se_store_int_env
    1170              :       TYPE(nddo_mpole_type), OPTIONAL, POINTER           :: se_nddo_mpole
    1171              :       TYPE(fist_nonbond_env_type), OPTIONAL, POINTER     :: se_nonbond_env
    1172              :       TYPE(admm_type), OPTIONAL, POINTER                 :: admm_env
    1173              :       TYPE(ls_scf_env_type), OPTIONAL, POINTER           :: ls_scf_env
    1174              :       LOGICAL, OPTIONAL                                  :: do_transport
    1175              :       TYPE(transport_env_type), OPTIONAL, POINTER        :: transport_env
    1176              :       TYPE(lri_environment_type), OPTIONAL, POINTER      :: lri_env
    1177              :       TYPE(lri_density_type), OPTIONAL, POINTER          :: lri_density
    1178              :       TYPE(excited_energy_type), OPTIONAL, POINTER       :: exstate_env
    1179              :       TYPE(energy_correction_type), OPTIONAL, POINTER    :: ec_env
    1180              :       TYPE(qs_dispersion_type), OPTIONAL, POINTER        :: dispersion_env
    1181              :       TYPE(harris_type), OPTIONAL, POINTER               :: harris_env
    1182              :       TYPE(qs_gcp_type), OPTIONAL, POINTER               :: gcp_env
    1183              :       TYPE(mp2_type), OPTIONAL, POINTER                  :: mp2_env
    1184              :       TYPE(post_scf_bandstructure_type), OPTIONAL, &
    1185              :          POINTER                                         :: bs_env
    1186              :       TYPE(kg_environment_type), OPTIONAL, POINTER       :: kg_env
    1187              :       TYPE(qs_force_type), DIMENSION(:), OPTIONAL, &
    1188              :          POINTER                                         :: force
    1189              :       TYPE(kpoint_type), OPTIONAL, POINTER               :: kpoints
    1190              :       TYPE(wannier_centres_type), DIMENSION(:), &
    1191              :          OPTIONAL, POINTER                               :: WannierCentres
    1192              :       TYPE(almo_scf_env_type), OPTIONAL, POINTER         :: almo_scf_env
    1193              :       REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER  :: gradient_history, variable_history
    1194              :       TYPE(pw_r3d_rs_type), OPTIONAL, POINTER            :: embed_pot, spin_embed_pot
    1195              :       TYPE(polar_env_type), OPTIONAL, POINTER            :: polar_env
    1196              :       TYPE(mo_set_type), DIMENSION(:), OPTIONAL, POINTER :: mos_last_converged
    1197              :       REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER     :: eeq, rhs
    1198              :       LOGICAL, OPTIONAL                                  :: do_rixs
    1199              :       TYPE(tblite_type), OPTIONAL, POINTER               :: tb_tblite
    1200              : 
    1201              :       TYPE(qs_subsys_type), POINTER                      :: subsys
    1202              : 
    1203       181408 :       IF (PRESENT(mp2_env)) qs_env%mp2_env => mp2_env
    1204       181408 :       IF (PRESENT(bs_env)) qs_env%bs_env => bs_env
    1205       181408 :       IF (PRESENT(kg_env)) qs_env%kg_env => kg_env
    1206       181408 :       IF (PRESENT(super_cell)) THEN
    1207           48 :          CALL cell_retain(super_cell)
    1208           48 :          CALL cell_release(qs_env%super_cell)
    1209           48 :          qs_env%super_cell => super_cell
    1210              :       END IF
    1211              :       !
    1212       181408 :       IF (PRESENT(qmmm)) qs_env%qmmm = qmmm
    1213       181408 :       IF (PRESENT(qmmm_periodic)) qs_env%qmmm_periodic = qmmm_periodic
    1214       181408 :       IF (PRESENT(mimic)) qs_env%mimic = mimic
    1215       181408 :       IF (PRESENT(mos)) qs_env%mos => mos
    1216       181408 :       IF (PRESENT(mos_last_converged)) qs_env%mos_last_converged => mos_last_converged
    1217       181408 :       IF (PRESENT(ls_scf_env)) qs_env%ls_scf_env => ls_scf_env
    1218       181408 :       IF (PRESENT(almo_scf_env)) qs_env%almo_scf_env => almo_scf_env
    1219       181408 :       IF (PRESENT(do_transport)) qs_env%do_transport = do_transport
    1220       181408 :       IF (PRESENT(transport_env)) qs_env%transport_env => transport_env
    1221              :       ! if intels checking (-C) complains here, you have rediscovered a bug in the intel
    1222              :       ! compiler (present in at least 10.0.025). A testcase has been submitted to intel.
    1223       181408 :       IF (PRESENT(oce)) qs_env%oce => oce
    1224       181408 :       IF (PRESENT(outer_scf_history)) qs_env%outer_scf_history => outer_scf_history
    1225       181408 :       IF (PRESENT(gradient_history)) qs_env%gradient_history => gradient_history
    1226       181408 :       IF (PRESENT(variable_history)) qs_env%variable_history => variable_history
    1227       181408 :       IF (PRESENT(outer_scf_ihistory)) qs_env%outer_scf_ihistory = outer_scf_ihistory
    1228       181408 :       IF (PRESENT(requires_mo_derivs)) qs_env%requires_mo_derivs = requires_mo_derivs
    1229       181408 :       IF (PRESENT(has_unit_metric)) qs_env%has_unit_metric = has_unit_metric
    1230       181408 :       IF (PRESENT(mo_derivs)) qs_env%mo_derivs => mo_derivs
    1231       181408 :       IF (PRESENT(mo_loc_history)) qs_env%mo_loc_history => mo_loc_history
    1232       181408 :       IF (PRESENT(run_rtp)) qs_env%run_rtp = run_rtp
    1233       181408 :       IF (PRESENT(rtp)) qs_env%rtp => rtp
    1234       181408 :       IF (PRESENT(efield)) qs_env%efield => efield
    1235       181408 :       IF (PRESENT(active_space)) qs_env%active_space => active_space
    1236       181408 :       IF (PRESENT(do_rixs)) do_rixs = qs_env%do_rixs
    1237              : 
    1238       181408 :       IF (PRESENT(ewald_env)) THEN ! accept also null pointers?
    1239          412 :          IF (ASSOCIATED(qs_env%ewald_env)) THEN
    1240            0 :             IF (.NOT. ASSOCIATED(qs_env%ewald_env, ewald_env)) THEN
    1241            0 :                CALL ewald_env_release(qs_env%ewald_env)
    1242            0 :                DEALLOCATE (qs_env%ewald_env)
    1243              :             END IF
    1244              :          END IF
    1245          412 :          qs_env%ewald_env => ewald_env
    1246              :       END IF
    1247       181408 :       IF (PRESENT(ewald_pw)) THEN ! accept also null pointers?
    1248          412 :          IF (ASSOCIATED(qs_env%ewald_pw)) THEN
    1249            0 :             IF (.NOT. ASSOCIATED(ewald_pw, qs_env%ewald_pw)) THEN
    1250            0 :                CALL ewald_pw_release(qs_env%ewald_pw)
    1251            0 :                DEALLOCATE (qs_env%ewald_pw)
    1252              :             END IF
    1253              :          END IF
    1254          412 :          qs_env%ewald_pw => ewald_pw
    1255              :       END IF
    1256       181408 :       IF (PRESENT(scf_control)) THEN ! accept also null pointers?
    1257         8800 :          IF (ASSOCIATED(qs_env%scf_control)) THEN
    1258            0 :             IF (.NOT. ASSOCIATED(qs_env%scf_control, scf_control)) THEN
    1259            0 :                CALL scf_c_release(qs_env%scf_control)
    1260            0 :                DEALLOCATE (qs_env%scf_control)
    1261              :             END IF
    1262              :          END IF
    1263         8800 :          qs_env%scf_control => scf_control
    1264              :       END IF
    1265       181408 :       IF (PRESENT(rel_control)) THEN ! accept also null pointers?
    1266         8800 :          IF (ASSOCIATED(qs_env%rel_control)) THEN
    1267            0 :             IF (.NOT. ASSOCIATED(qs_env%rel_control, rel_control)) THEN
    1268            0 :                CALL rel_c_release(qs_env%rel_control)
    1269            0 :                DEALLOCATE (qs_env%rel_control)
    1270              :             END IF
    1271              :          END IF
    1272         8800 :          qs_env%rel_control => rel_control
    1273              :       END IF
    1274       181408 :       IF (PRESENT(linres_control)) THEN ! accept also null pointers?
    1275         1830 :          IF (ASSOCIATED(qs_env%linres_control)) THEN
    1276          634 :             IF (.NOT. ASSOCIATED(qs_env%linres_control, linres_control)) THEN
    1277          634 :                CALL linres_control_release(qs_env%linres_control)
    1278          634 :                DEALLOCATE (qs_env%linres_control)
    1279              :             END IF
    1280              :          END IF
    1281         1830 :          qs_env%linres_control => linres_control
    1282              :       END IF
    1283              :       ! ZMP associating variables
    1284       181408 :       IF (PRESENT(rho_external)) THEN
    1285            0 :          IF (ASSOCIATED(qs_env%rho_external)) THEN
    1286            0 :             IF (.NOT. ASSOCIATED(qs_env%rho_external, rho_external)) THEN
    1287            0 :                CALL qs_rho_release(qs_env%rho_external)
    1288            0 :                DEALLOCATE (qs_env%rho_external)
    1289              :             END IF
    1290              :          END IF
    1291            0 :          qs_env%rho_external => rho_external
    1292              :       END IF
    1293       181408 :       IF (PRESENT(external_vxc)) qs_env%external_vxc => external_vxc
    1294       181408 :       IF (PRESENT(mask)) qs_env%mask => mask
    1295              :       ! Embedding potential
    1296       181408 :       IF (PRESENT(embed_pot)) qs_env%embed_pot => embed_pot
    1297       181408 :       IF (PRESENT(spin_embed_pot)) qs_env%spin_embed_pot => spin_embed_pot
    1298              : 
    1299              :       ! Polarisability tensor
    1300       181408 :       IF (PRESENT(polar_env)) qs_env%polar_env => polar_env
    1301              : 
    1302       181408 :       IF (PRESENT(qs_charges)) THEN
    1303         8800 :          IF (ASSOCIATED(qs_env%qs_charges)) THEN
    1304            0 :             IF (.NOT. ASSOCIATED(qs_env%qs_charges, qs_charges)) THEN
    1305            0 :                CALL qs_charges_release(qs_env%qs_charges)
    1306            0 :                DEALLOCATE (qs_env%qs_charges)
    1307              :             END IF
    1308              :          END IF
    1309         8800 :          qs_env%qs_charges => qs_charges
    1310              :       END IF
    1311       181408 :       IF (PRESENT(ks_qmmm_env)) THEN
    1312          382 :          IF (ASSOCIATED(qs_env%ks_qmmm_env)) THEN
    1313            0 :             IF (.NOT. ASSOCIATED(qs_env%ks_qmmm_env, ks_qmmm_env)) THEN
    1314            0 :                CALL qs_ks_qmmm_release(qs_env%ks_qmmm_env)
    1315            0 :                DEALLOCATE (qs_env%ks_qmmm_env)
    1316              :             END IF
    1317              :          END IF
    1318          382 :          qs_env%ks_qmmm_env => ks_qmmm_env
    1319              :       END IF
    1320       181408 :       IF (PRESENT(ks_env)) THEN ! accept also null pointers?
    1321         8800 :          IF (ASSOCIATED(qs_env%ks_env)) THEN
    1322            0 :             IF (.NOT. ASSOCIATED(qs_env%ks_env, ks_env)) THEN
    1323            0 :                CALL qs_ks_release(qs_env%ks_env)
    1324            0 :                DEALLOCATE (qs_env%ks_env)
    1325              :             END IF
    1326              :          END IF
    1327         8800 :          qs_env%ks_env => ks_env
    1328              :       END IF
    1329       181408 :       IF (PRESENT(wf_history)) THEN ! accept also null pointers ?
    1330         9172 :          CALL wfi_retain(wf_history)
    1331         9172 :          CALL wfi_release(qs_env%wf_history)
    1332         9172 :          qs_env%wf_history => wf_history
    1333              :       END IF
    1334       181408 :       IF (PRESENT(scf_env)) THEN ! accept also null pointers ?
    1335         7709 :          IF (ASSOCIATED(qs_env%scf_env)) THEN
    1336           50 :             IF (.NOT. ASSOCIATED(qs_env%scf_env, scf_env)) THEN
    1337           50 :                CALL scf_env_release(qs_env%scf_env)
    1338           50 :                DEALLOCATE (qs_env%scf_env)
    1339              :             END IF
    1340              :          END IF
    1341         7709 :          qs_env%scf_env => scf_env
    1342              :       END IF
    1343       181408 :       IF (PRESENT(xas_env)) THEN ! accept also null pointers?
    1344           42 :          IF (ASSOCIATED(qs_env%xas_env)) THEN
    1345            0 :             IF (.NOT. ASSOCIATED(qs_env%xas_env, xas_env)) THEN
    1346            0 :                CALL xas_env_release(qs_env%xas_env)
    1347            0 :                DEALLOCATE (qs_env%xas_env)
    1348              :             END IF
    1349              :          END IF
    1350           42 :          qs_env%xas_env => xas_env
    1351              :       END IF
    1352       181408 :       IF (PRESENT(mpools)) THEN
    1353            0 :          CALL mpools_retain(mpools)
    1354            0 :          CALL mpools_release(qs_env%mpools)
    1355            0 :          qs_env%mpools => mpools
    1356              :       END IF
    1357       181408 :       IF (PRESENT(rho_atom_set)) THEN
    1358         1446 :          CALL set_local_rho(qs_env%local_rho_set, rho_atom_set=rho_atom_set)
    1359              :       END IF
    1360       181408 :       IF (PRESENT(rho0_atom_set)) THEN
    1361            0 :          CALL set_local_rho(qs_env%local_rho_set, rho0_atom_set=rho0_atom_set)
    1362              :       END IF
    1363       181408 :       IF (PRESENT(rho0_mpole)) THEN
    1364            0 :          CALL set_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_mpole)
    1365              :       END IF
    1366       181408 :       IF (PRESENT(rhoz_set)) THEN
    1367            0 :          CALL set_local_rho(qs_env%local_rho_set, rhoz_set=rhoz_set)
    1368              :       END IF
    1369       181408 :       IF (PRESENT(rhoz_cneo_set)) THEN
    1370            0 :          CALL set_local_rho(qs_env%local_rho_set, rhoz_cneo_set=rhoz_cneo_set)
    1371              :       END IF
    1372       181408 :       IF (PRESENT(rhoz_tot)) qs_env%local_rho_set%rhoz_tot = rhoz_tot
    1373       181408 :       IF (PRESENT(ecoul_1c)) THEN
    1374            0 :          CALL set_hartree_local(qs_env%hartree_local, ecoul_1c=ecoul_1c)
    1375              :       END IF
    1376       181408 :       IF (PRESENT(input)) THEN
    1377         8800 :          CALL section_vals_retain(input)
    1378         8800 :          CALL section_vals_release(qs_env%input)
    1379         8800 :          qs_env%input => input
    1380              :       END IF
    1381       181408 :       IF (PRESENT(cp_ddapc_env)) THEN
    1382            0 :          IF (ASSOCIATED(qs_env%cp_ddapc_env)) THEN
    1383            0 :             IF (.NOT. ASSOCIATED(qs_env%cp_ddapc_env, cp_ddapc_env)) THEN
    1384            0 :                CALL cp_ddapc_release(qs_env%cp_ddapc_env)
    1385            0 :                DEALLOCATE (qs_env%cp_ddapc_env)
    1386              :             END IF
    1387              :          END IF
    1388            0 :          qs_env%cp_ddapc_env => cp_ddapc_env
    1389              :       END IF
    1390       181408 :       IF (PRESENT(cp_ddapc_ewald)) THEN
    1391            0 :          qs_env%cp_ddapc_ewald => cp_ddapc_ewald
    1392              :       END IF
    1393       181408 :       IF (PRESENT(x_data)) qs_env%x_data => x_data
    1394       181408 :       IF (PRESENT(et_coupling)) qs_env%et_coupling => et_coupling
    1395       181408 :       IF (PRESENT(dftb_potential)) qs_env%dftb_potential => dftb_potential
    1396       181408 :       IF (PRESENT(se_taper)) THEN
    1397         1000 :          CALL se_taper_release(qs_env%se_taper)
    1398         1000 :          qs_env%se_taper => se_taper
    1399              :       END IF
    1400       181408 :       IF (PRESENT(se_store_int_env)) THEN
    1401         1000 :          CALL semi_empirical_si_release(qs_env%se_store_int_env)
    1402         1000 :          qs_env%se_store_int_env => se_store_int_env
    1403              :       END IF
    1404       181408 :       IF (PRESENT(se_nddo_mpole)) THEN
    1405           32 :          CALL nddo_mpole_release(qs_env%se_nddo_mpole)
    1406           32 :          qs_env%se_nddo_mpole => se_nddo_mpole
    1407              :       END IF
    1408       181408 :       IF (PRESENT(se_nonbond_env)) THEN
    1409           32 :          IF (ASSOCIATED(qs_env%se_nonbond_env)) THEN
    1410            0 :             IF (.NOT. ASSOCIATED(qs_env%se_nonbond_env, se_nonbond_env)) THEN
    1411            0 :                CALL fist_nonbond_env_release(qs_env%se_nonbond_env)
    1412            0 :                DEALLOCATE (qs_env%se_nonbond_env)
    1413              :             END IF
    1414              :          END IF
    1415           32 :          qs_env%se_nonbond_env => se_nonbond_env
    1416              :       END IF
    1417       181408 :       IF (PRESENT(admm_env)) qs_env%admm_env => admm_env
    1418       181408 :       IF (PRESENT(lri_env)) qs_env%lri_env => lri_env
    1419       181408 :       IF (PRESENT(lri_density)) qs_env%lri_density => lri_density
    1420       181408 :       IF (PRESENT(harris_env)) qs_env%harris_env => harris_env
    1421       181408 :       IF (PRESENT(ec_env)) qs_env%ec_env => ec_env
    1422       181408 :       IF (PRESENT(exstate_env)) qs_env%exstate_env => exstate_env
    1423       181408 :       IF (PRESENT(dispersion_env)) qs_env%dispersion_env => dispersion_env
    1424       181408 :       IF (PRESENT(gcp_env)) qs_env%gcp_env => gcp_env
    1425       181408 :       IF (PRESENT(WannierCentres)) qs_env%WannierCentres => WannierCentres
    1426       181408 :       IF (PRESENT(kpoints)) CALL set_ks_env(qs_env%ks_env, kpoints=kpoints)
    1427              : 
    1428              :       ! EEQ charges
    1429       181408 :       IF (PRESENT(eeq)) qs_env%eeq => eeq
    1430              : 
    1431              :       ! Resp charges
    1432       181408 :       IF (PRESENT(rhs)) qs_env%rhs => rhs
    1433              : 
    1434       181408 :       IF (PRESENT(force)) THEN
    1435         2660 :          CALL get_qs_env(qs_env, subsys=subsys)
    1436         2660 :          CALL qs_subsys_set(subsys, force=force)
    1437              :       END IF
    1438              : 
    1439       181408 :       IF (PRESENT(tb_tblite)) qs_env%tb_tblite => tb_tblite
    1440              : 
    1441       181408 :    END SUBROUTINE set_qs_env
    1442              : 
    1443              : ! **************************************************************************************************
    1444              : !> \brief allocates and intitializes a qs_env
    1445              : !> \param qs_env the object to create
    1446              : !> \param globenv ...
    1447              : !> \par History
    1448              : !>      12.2002 created [fawzi]
    1449              : !> \author Fawzi Mohamed
    1450              : ! **************************************************************************************************
    1451         8800 :    SUBROUTINE qs_env_create(qs_env, globenv)
    1452              :       TYPE(qs_environment_type), INTENT(OUT)             :: qs_env
    1453              :       TYPE(global_environment_type), OPTIONAL, POINTER   :: globenv
    1454              : 
    1455         8800 :       CALL init_qs_env(qs_env, globenv=globenv)
    1456         8800 :    END SUBROUTINE qs_env_create
    1457              : 
    1458              : ! **************************************************************************************************
    1459              : !> \brief releases the given qs_env (see doc/ReferenceCounting.html)
    1460              : !> \param qs_env the object to release
    1461              : !> \par History
    1462              : !>      12.2002 created [fawzi]
    1463              : !>      06.2018 polar_env added (MK)
    1464              : !> \author Fawzi Mohamed
    1465              : ! **************************************************************************************************
    1466         8800 :    SUBROUTINE qs_env_release(qs_env)
    1467              :       TYPE(qs_environment_type), INTENT(INOUT)           :: qs_env
    1468              : 
    1469              :       INTEGER                                            :: i
    1470              : 
    1471         8800 :       CALL cell_release(qs_env%super_cell)
    1472         8800 :       IF (ASSOCIATED(qs_env%mos)) THEN
    1473        18651 :          DO i = 1, SIZE(qs_env%mos)
    1474        18651 :             CALL deallocate_mo_set(qs_env%mos(i))
    1475              :          END DO
    1476         8412 :          DEALLOCATE (qs_env%mos)
    1477              :       END IF
    1478         8800 :       IF (ASSOCIATED(qs_env%mos_last_converged)) THEN
    1479            4 :          DO i = 1, SIZE(qs_env%mos_last_converged)
    1480            4 :             CALL deallocate_mo_set(qs_env%mos_last_converged(i))
    1481              :          END DO
    1482            2 :          DEALLOCATE (qs_env%mos_last_converged)
    1483              :       END IF
    1484              : 
    1485         8800 :       IF (ASSOCIATED(qs_env%mo_derivs)) THEN
    1486         5227 :          DO I = 1, SIZE(qs_env%mo_derivs)
    1487         5227 :             CALL dbcsr_release_p(qs_env%mo_derivs(I)%matrix)
    1488              :          END DO
    1489         2291 :          DEALLOCATE (qs_env%mo_derivs)
    1490              :       END IF
    1491              : 
    1492         8800 :       CALL cp_fm_release(qs_env%mo_loc_history)
    1493              : 
    1494         8800 :       IF (ASSOCIATED(qs_env%rtp)) THEN
    1495          204 :          CALL rt_prop_release(qs_env%rtp)
    1496          204 :          DEALLOCATE (qs_env%rtp)
    1497              :       END IF
    1498         8800 :       IF (ASSOCIATED(qs_env%outer_scf_history)) THEN
    1499         1565 :          DEALLOCATE (qs_env%outer_scf_history)
    1500         1565 :          qs_env%outer_scf_ihistory = 0
    1501              :       END IF
    1502         8800 :       IF (ASSOCIATED(qs_env%gradient_history)) THEN
    1503         1565 :          DEALLOCATE (qs_env%gradient_history)
    1504              :       END IF
    1505         8800 :       IF (ASSOCIATED(qs_env%variable_history)) THEN
    1506         1565 :          DEALLOCATE (qs_env%variable_history)
    1507              :       END IF
    1508         8800 :       IF (ASSOCIATED(qs_env%oce)) CALL deallocate_oce_set(qs_env%oce)
    1509         8800 :       IF (ASSOCIATED(qs_env%local_rho_set)) THEN
    1510         8791 :          CALL local_rho_set_release(qs_env%local_rho_set)
    1511              :       END IF
    1512         8800 :       IF (ASSOCIATED(qs_env%hartree_local)) THEN
    1513         8791 :          CALL hartree_local_release(qs_env%hartree_local)
    1514              :       END IF
    1515         8800 :       IF (ASSOCIATED(qs_env%scf_control)) THEN
    1516         8791 :          CALL scf_c_release(qs_env%scf_control)
    1517         8791 :          DEALLOCATE (qs_env%scf_control)
    1518              :       END IF
    1519         8800 :       IF (ASSOCIATED(qs_env%rel_control)) THEN
    1520         8791 :          CALL rel_c_release(qs_env%rel_control)
    1521         8791 :          DEALLOCATE (qs_env%rel_control)
    1522              :       END IF
    1523              : 
    1524         8800 :       IF (ASSOCIATED(qs_env%linres_control)) THEN
    1525         1196 :          CALL linres_control_release(qs_env%linres_control)
    1526         1196 :          DEALLOCATE (qs_env%linres_control)
    1527              :       END IF
    1528              : 
    1529         8800 :       IF (ASSOCIATED(qs_env%almo_scf_env)) THEN
    1530           72 :          CALL almo_scf_env_release(qs_env%almo_scf_env)
    1531              :       END IF
    1532              : 
    1533         8800 :       IF (ASSOCIATED(qs_env%ls_scf_env)) THEN
    1534          386 :          CALL ls_scf_release(qs_env%ls_scf_env)
    1535              :       END IF
    1536         8800 :       IF (ASSOCIATED(qs_env%molecular_scf_guess_env)) THEN
    1537         8791 :          CALL molecular_scf_guess_env_destroy(qs_env%molecular_scf_guess_env)
    1538         8791 :          DEALLOCATE (qs_env%molecular_scf_guess_env)
    1539              :       END IF
    1540              : 
    1541         8800 :       IF (ASSOCIATED(qs_env%transport_env)) THEN
    1542            0 :          CALL transport_env_release(qs_env%transport_env)
    1543              :       END IF
    1544              : 
    1545              :       !Only if do_xas_calculation
    1546         8800 :       IF (ASSOCIATED(qs_env%xas_env)) THEN
    1547            0 :          CALL xas_env_release(qs_env%xas_env)
    1548            0 :          DEALLOCATE (qs_env%xas_env)
    1549              :       END IF
    1550         8800 :       IF (ASSOCIATED(qs_env%ewald_env)) THEN
    1551          412 :          CALL ewald_env_release(qs_env%ewald_env)
    1552          412 :          DEALLOCATE (qs_env%ewald_env)
    1553              :       END IF
    1554         8800 :       IF (ASSOCIATED(qs_env%ewald_pw)) THEN
    1555          412 :          CALL ewald_pw_release(qs_env%ewald_pw)
    1556          412 :          DEALLOCATE (qs_env%ewald_pw)
    1557              :       END IF
    1558         8800 :       IF (ASSOCIATED(qs_env%image_matrix)) THEN
    1559           10 :          DEALLOCATE (qs_env%image_matrix)
    1560              :       END IF
    1561         8800 :       IF (ASSOCIATED(qs_env%ipiv)) THEN
    1562            8 :          DEALLOCATE (qs_env%ipiv)
    1563              :       END IF
    1564         8800 :       IF (ASSOCIATED(qs_env%image_coeff)) THEN
    1565           10 :          DEALLOCATE (qs_env%image_coeff)
    1566              :       END IF
    1567              :       ! ZMP
    1568         8800 :       IF (ASSOCIATED(qs_env%rho_external)) THEN
    1569            0 :          CALL qs_rho_release(qs_env%rho_external)
    1570            0 :          DEALLOCATE (qs_env%rho_external)
    1571              :       END IF
    1572         8800 :       IF (ASSOCIATED(qs_env%external_vxc)) THEN
    1573            0 :          CALL qs_env%external_vxc%release()
    1574            0 :          DEALLOCATE (qs_env%external_vxc)
    1575              :       END IF
    1576         8800 :       IF (ASSOCIATED(qs_env%mask)) THEN
    1577            0 :          CALL qs_env%mask%release()
    1578            0 :          DEALLOCATE (qs_env%mask)
    1579              :       END IF
    1580         8800 :       IF (ASSOCIATED(qs_env%active_space)) THEN
    1581           82 :          CALL release_active_space_type(qs_env%active_space)
    1582              :       END IF
    1583              :       ! Embedding potentials if provided as input
    1584         8800 :       IF (qs_env%given_embed_pot) THEN
    1585            2 :          CALL qs_env%embed_pot%release()
    1586            2 :          DEALLOCATE (qs_env%embed_pot)
    1587            2 :          IF (ASSOCIATED(qs_env%spin_embed_pot)) THEN
    1588            2 :             CALL qs_env%spin_embed_pot%release()
    1589            2 :             DEALLOCATE (qs_env%spin_embed_pot)
    1590              :          END IF
    1591              :       END IF
    1592              : 
    1593              :       ! Polarisability tensor
    1594         8800 :       CALL polar_env_release(qs_env%polar_env)
    1595              : 
    1596         8800 :       IF (ASSOCIATED(qs_env%qs_charges)) THEN
    1597         8791 :          CALL qs_charges_release(qs_env%qs_charges)
    1598         8791 :          DEALLOCATE (qs_env%qs_charges)
    1599              :       END IF
    1600         8800 :       IF (ASSOCIATED(qs_env%ks_env)) THEN
    1601         8800 :          CALL qs_ks_release(qs_env%ks_env)
    1602         8800 :          DEALLOCATE (qs_env%ks_env)
    1603              :       END IF
    1604         8800 :       IF (ASSOCIATED(qs_env%ks_qmmm_env)) THEN
    1605          382 :          CALL qs_ks_qmmm_release(qs_env%ks_qmmm_env)
    1606          382 :          DEALLOCATE (qs_env%ks_qmmm_env)
    1607              :       END IF
    1608         8800 :       CALL wfi_release(qs_env%wf_history)
    1609         8800 :       IF (ASSOCIATED(qs_env%scf_env)) THEN
    1610         7659 :          CALL scf_env_release(qs_env%scf_env)
    1611         7659 :          DEALLOCATE (qs_env%scf_env)
    1612              :       END IF
    1613         8800 :       CALL mpools_release(qs_env%mpools)
    1614         8800 :       CALL section_vals_release(qs_env%input)
    1615         8800 :       IF (ASSOCIATED(qs_env%cp_ddapc_env)) THEN
    1616          146 :          CALL cp_ddapc_release(qs_env%cp_ddapc_env)
    1617          146 :          DEALLOCATE (qs_env%cp_ddapc_env)
    1618              :       END IF
    1619         8800 :       CALL cp_ddapc_ewald_release(qs_env%cp_ddapc_ewald)
    1620         8800 :       CALL efield_berry_release(qs_env%efield)
    1621         8800 :       IF (ASSOCIATED(qs_env%x_data)) THEN
    1622         1384 :          CALL hfx_release(qs_env%x_data)
    1623              :       END IF
    1624         8800 :       IF (ASSOCIATED(qs_env%et_coupling)) THEN
    1625           10 :          CALL et_coupling_release(qs_env%et_coupling)
    1626              :       END IF
    1627         8800 :       IF (ASSOCIATED(qs_env%dftb_potential)) THEN
    1628          294 :          CALL qs_dftb_pairpot_release(qs_env%dftb_potential)
    1629              :       END IF
    1630         8800 :       IF (ASSOCIATED(qs_env%se_taper)) THEN
    1631         1000 :          CALL se_taper_release(qs_env%se_taper)
    1632              :       END IF
    1633         8800 :       IF (ASSOCIATED(qs_env%se_store_int_env)) THEN
    1634         1000 :          CALL semi_empirical_si_release(qs_env%se_store_int_env)
    1635              :       END IF
    1636         8800 :       IF (ASSOCIATED(qs_env%se_nddo_mpole)) THEN
    1637           32 :          CALL nddo_mpole_release(qs_env%se_nddo_mpole)
    1638              :       END IF
    1639         8800 :       IF (ASSOCIATED(qs_env%se_nonbond_env)) THEN
    1640           32 :          CALL fist_nonbond_env_release(qs_env%se_nonbond_env)
    1641           32 :          DEALLOCATE (qs_env%se_nonbond_env)
    1642              :       END IF
    1643         8800 :       IF (ASSOCIATED(qs_env%admm_env)) THEN
    1644          520 :          CALL admm_env_release(qs_env%admm_env)
    1645              :       END IF
    1646         8800 :       IF (ASSOCIATED(qs_env%lri_env)) THEN
    1647           50 :          CALL lri_env_release(qs_env%lri_env)
    1648           50 :          DEALLOCATE (qs_env%lri_env)
    1649              :       END IF
    1650         8800 :       IF (ASSOCIATED(qs_env%lri_density)) THEN
    1651           50 :          CALL lri_density_release(qs_env%lri_density)
    1652           50 :          DEALLOCATE (qs_env%lri_density)
    1653              :       END IF
    1654         8800 :       IF (ASSOCIATED(qs_env%harris_env)) THEN
    1655         8791 :          CALL harris_env_release(qs_env%harris_env)
    1656              :       END IF
    1657         8800 :       IF (ASSOCIATED(qs_env%ec_env)) THEN
    1658         8791 :          CALL ec_env_release(qs_env%ec_env)
    1659              :       END IF
    1660         8800 :       IF (ASSOCIATED(qs_env%exstate_env)) THEN
    1661         8791 :          CALL exstate_release(qs_env%exstate_env)
    1662              :       END IF
    1663         8800 :       IF (ASSOCIATED(qs_env%mp2_env)) THEN
    1664          484 :          CALL mp2_env_release(qs_env%mp2_env)
    1665         6292 :          DEALLOCATE (qs_env%mp2_env)
    1666              :          NULLIFY (qs_env%mp2_env)
    1667              :       END IF
    1668         8800 :       IF (ASSOCIATED(qs_env%bs_env)) THEN
    1669          106 :          CALL bs_env_release(qs_env%bs_env)
    1670              :       END IF
    1671         8800 :       IF (ASSOCIATED(qs_env%kg_env)) THEN
    1672           94 :          CALL kg_env_release(qs_env%kg_env)
    1673              :       END IF
    1674              : 
    1675              :       ! dispersion
    1676         8800 :       CALL qs_dispersion_release(qs_env%dispersion_env)
    1677              :       ! gCP
    1678         8800 :       IF (ASSOCIATED(qs_env%gcp_env)) THEN
    1679         6293 :          CALL qs_gcp_release(qs_env%gcp_env)
    1680              :       END IF
    1681              : 
    1682         8800 :       IF (ASSOCIATED(qs_env%WannierCentres)) THEN
    1683           20 :          DO i = 1, SIZE(qs_env%WannierCentres)
    1684           10 :             DEALLOCATE (qs_env%WannierCentres(i)%WannierHamDiag)
    1685           20 :             DEALLOCATE (qs_env%WannierCentres(i)%centres)
    1686              :          END DO
    1687           10 :          DEALLOCATE (qs_env%WannierCentres)
    1688              :       END IF
    1689              :       ! EEQ charges
    1690         8800 :       IF (ASSOCIATED(qs_env%eeq)) DEALLOCATE (qs_env%eeq)
    1691              :       ! Resp chargeqq
    1692         8800 :       IF (ASSOCIATED(qs_env%rhs)) DEALLOCATE (qs_env%rhs)
    1693              : 
    1694              :       ! tblite
    1695         8800 :       IF (ASSOCIATED(qs_env%tb_tblite)) THEN
    1696          174 :          CALL deallocate_tblite_type(qs_env%tb_tblite)
    1697              :       END IF
    1698              : 
    1699         8800 :       IF (ASSOCIATED(qs_env%gauxc_cache)) THEN
    1700           42 :          CALL gauxc_cache_release(qs_env%gauxc_cache)
    1701           42 :          DEALLOCATE (qs_env%gauxc_cache)
    1702              :       END IF
    1703              : 
    1704         8800 :    END SUBROUTINE qs_env_release
    1705              : 
    1706              : ! **************************************************************************************************
    1707              : !> \brief releases part of the given qs_env in order to save memory
    1708              : !> \param qs_env the object to release
    1709              : !> \par History
    1710              : !>      04.2022 created [JGH]
    1711              : ! **************************************************************************************************
    1712            9 :    SUBROUTINE qs_env_part_release(qs_env)
    1713              :       TYPE(qs_environment_type), INTENT(INOUT)           :: qs_env
    1714              : 
    1715              :       INTEGER                                            :: i
    1716              : 
    1717            9 :       IF (ASSOCIATED(qs_env%mos_last_converged)) THEN
    1718            0 :          DO i = 1, SIZE(qs_env%mos_last_converged)
    1719            0 :             CALL deallocate_mo_set(qs_env%mos_last_converged(i))
    1720              :          END DO
    1721            0 :          DEALLOCATE (qs_env%mos_last_converged)
    1722              :       END IF
    1723              : 
    1724            9 :       IF (ASSOCIATED(qs_env%mo_derivs)) THEN
    1725            0 :          DO I = 1, SIZE(qs_env%mo_derivs)
    1726            0 :             CALL dbcsr_release_p(qs_env%mo_derivs(I)%matrix)
    1727              :          END DO
    1728            0 :          DEALLOCATE (qs_env%mo_derivs)
    1729              :       END IF
    1730              : 
    1731            9 :       CALL cp_fm_release(qs_env%mo_loc_history)
    1732              : 
    1733            9 :       IF (ASSOCIATED(qs_env%rtp)) THEN
    1734            0 :          CALL rt_prop_release(qs_env%rtp)
    1735            0 :          DEALLOCATE (qs_env%rtp)
    1736              :       END IF
    1737            9 :       IF (ASSOCIATED(qs_env%outer_scf_history)) THEN
    1738            0 :          DEALLOCATE (qs_env%outer_scf_history)
    1739            0 :          qs_env%outer_scf_ihistory = 0
    1740              :       END IF
    1741            9 :       IF (ASSOCIATED(qs_env%gradient_history)) THEN
    1742            0 :          DEALLOCATE (qs_env%gradient_history)
    1743              :       END IF
    1744            9 :       IF (ASSOCIATED(qs_env%variable_history)) THEN
    1745            0 :          DEALLOCATE (qs_env%variable_history)
    1746              :       END IF
    1747            9 :       IF (ASSOCIATED(qs_env%oce)) CALL deallocate_oce_set(qs_env%oce)
    1748            9 :       IF (ASSOCIATED(qs_env%local_rho_set)) THEN
    1749            9 :          CALL local_rho_set_release(qs_env%local_rho_set)
    1750              :       END IF
    1751            9 :       IF (ASSOCIATED(qs_env%hartree_local)) THEN
    1752            9 :          CALL hartree_local_release(qs_env%hartree_local)
    1753              :       END IF
    1754            9 :       IF (ASSOCIATED(qs_env%scf_control)) THEN
    1755            9 :          CALL scf_c_release(qs_env%scf_control)
    1756            9 :          DEALLOCATE (qs_env%scf_control)
    1757              :       END IF
    1758            9 :       IF (ASSOCIATED(qs_env%rel_control)) THEN
    1759            9 :          CALL rel_c_release(qs_env%rel_control)
    1760            9 :          DEALLOCATE (qs_env%rel_control)
    1761              :       END IF
    1762              : 
    1763            9 :       IF (ASSOCIATED(qs_env%linres_control)) THEN
    1764            0 :          CALL linres_control_release(qs_env%linres_control)
    1765            0 :          DEALLOCATE (qs_env%linres_control)
    1766              :       END IF
    1767              : 
    1768            9 :       IF (ASSOCIATED(qs_env%almo_scf_env)) THEN
    1769            0 :          CALL almo_scf_env_release(qs_env%almo_scf_env)
    1770              :       END IF
    1771              : 
    1772            9 :       IF (ASSOCIATED(qs_env%ls_scf_env)) THEN
    1773            0 :          CALL ls_scf_release(qs_env%ls_scf_env)
    1774              :       END IF
    1775            9 :       IF (ASSOCIATED(qs_env%molecular_scf_guess_env)) THEN
    1776            9 :          CALL molecular_scf_guess_env_destroy(qs_env%molecular_scf_guess_env)
    1777            9 :          DEALLOCATE (qs_env%molecular_scf_guess_env)
    1778              :       END IF
    1779              : 
    1780            9 :       IF (ASSOCIATED(qs_env%transport_env)) THEN
    1781            0 :          CALL transport_env_release(qs_env%transport_env)
    1782              :       END IF
    1783              : 
    1784              :       !Only if do_xas_calculation
    1785            9 :       IF (ASSOCIATED(qs_env%xas_env)) THEN
    1786            0 :          CALL xas_env_release(qs_env%xas_env)
    1787            0 :          DEALLOCATE (qs_env%xas_env)
    1788              :       END IF
    1789            9 :       IF (ASSOCIATED(qs_env%ewald_env)) THEN
    1790            0 :          CALL ewald_env_release(qs_env%ewald_env)
    1791            0 :          DEALLOCATE (qs_env%ewald_env)
    1792              :       END IF
    1793            9 :       IF (ASSOCIATED(qs_env%ewald_pw)) THEN
    1794            0 :          CALL ewald_pw_release(qs_env%ewald_pw)
    1795            0 :          DEALLOCATE (qs_env%ewald_pw)
    1796              :       END IF
    1797            9 :       IF (ASSOCIATED(qs_env%image_matrix)) THEN
    1798            0 :          DEALLOCATE (qs_env%image_matrix)
    1799              :       END IF
    1800            9 :       IF (ASSOCIATED(qs_env%ipiv)) THEN
    1801            0 :          DEALLOCATE (qs_env%ipiv)
    1802              :       END IF
    1803            9 :       IF (ASSOCIATED(qs_env%image_coeff)) THEN
    1804            0 :          DEALLOCATE (qs_env%image_coeff)
    1805              :       END IF
    1806              :       ! ZMP
    1807            9 :       IF (ASSOCIATED(qs_env%rho_external)) THEN
    1808            0 :          CALL qs_rho_release(qs_env%rho_external)
    1809            0 :          DEALLOCATE (qs_env%rho_external)
    1810              :       END IF
    1811            9 :       IF (ASSOCIATED(qs_env%external_vxc)) THEN
    1812            0 :          CALL qs_env%external_vxc%release()
    1813            0 :          DEALLOCATE (qs_env%external_vxc)
    1814              :       END IF
    1815            9 :       IF (ASSOCIATED(qs_env%mask)) THEN
    1816            0 :          CALL qs_env%mask%release()
    1817            0 :          DEALLOCATE (qs_env%mask)
    1818              :       END IF
    1819            9 :       IF (ASSOCIATED(qs_env%active_space)) THEN
    1820            0 :          CALL release_active_space_type(qs_env%active_space)
    1821              :       END IF
    1822              :       ! Embedding potentials if provided as input
    1823            9 :       IF (qs_env%given_embed_pot) THEN
    1824            0 :          CALL qs_env%embed_pot%release()
    1825            0 :          DEALLOCATE (qs_env%embed_pot)
    1826            0 :          IF (ASSOCIATED(qs_env%spin_embed_pot)) THEN
    1827            0 :             CALL qs_env%spin_embed_pot%release()
    1828            0 :             DEALLOCATE (qs_env%spin_embed_pot)
    1829              :          END IF
    1830              :       END IF
    1831              : 
    1832              :       ! Polarisability tensor
    1833            9 :       CALL polar_env_release(qs_env%polar_env)
    1834              : 
    1835            9 :       IF (ASSOCIATED(qs_env%qs_charges)) THEN
    1836            9 :          CALL qs_charges_release(qs_env%qs_charges)
    1837            9 :          DEALLOCATE (qs_env%qs_charges)
    1838              :       END IF
    1839            9 :       CALL qs_ks_part_release(qs_env%ks_env)
    1840            9 :       IF (ASSOCIATED(qs_env%ks_qmmm_env)) THEN
    1841            0 :          CALL qs_ks_qmmm_release(qs_env%ks_qmmm_env)
    1842            0 :          DEALLOCATE (qs_env%ks_qmmm_env)
    1843              :       END IF
    1844            9 :       CALL wfi_release(qs_env%wf_history)
    1845            9 :       IF (ASSOCIATED(qs_env%scf_env)) THEN
    1846            0 :          CALL scf_env_release(qs_env%scf_env)
    1847            0 :          DEALLOCATE (qs_env%scf_env)
    1848              :       END IF
    1849            9 :       IF (ASSOCIATED(qs_env%cp_ddapc_env)) THEN
    1850            0 :          CALL cp_ddapc_release(qs_env%cp_ddapc_env)
    1851            0 :          DEALLOCATE (qs_env%cp_ddapc_env)
    1852              :       END IF
    1853            9 :       CALL cp_ddapc_ewald_release(qs_env%cp_ddapc_ewald)
    1854            9 :       CALL efield_berry_release(qs_env%efield)
    1855            9 :       IF (ASSOCIATED(qs_env%x_data)) THEN
    1856            0 :          CALL hfx_release(qs_env%x_data)
    1857              :       END IF
    1858            9 :       IF (ASSOCIATED(qs_env%et_coupling)) THEN
    1859            0 :          CALL et_coupling_release(qs_env%et_coupling)
    1860              :       END IF
    1861            9 :       IF (ASSOCIATED(qs_env%dftb_potential)) THEN
    1862            0 :          CALL qs_dftb_pairpot_release(qs_env%dftb_potential)
    1863              :       END IF
    1864            9 :       IF (ASSOCIATED(qs_env%se_taper)) THEN
    1865            0 :          CALL se_taper_release(qs_env%se_taper)
    1866              :       END IF
    1867            9 :       IF (ASSOCIATED(qs_env%se_store_int_env)) THEN
    1868            0 :          CALL semi_empirical_si_release(qs_env%se_store_int_env)
    1869              :       END IF
    1870            9 :       IF (ASSOCIATED(qs_env%se_nddo_mpole)) THEN
    1871            0 :          CALL nddo_mpole_release(qs_env%se_nddo_mpole)
    1872              :       END IF
    1873            9 :       IF (ASSOCIATED(qs_env%se_nonbond_env)) THEN
    1874            0 :          CALL fist_nonbond_env_release(qs_env%se_nonbond_env)
    1875            0 :          DEALLOCATE (qs_env%se_nonbond_env)
    1876              :       END IF
    1877            9 :       IF (ASSOCIATED(qs_env%admm_env)) THEN
    1878            0 :          CALL admm_env_release(qs_env%admm_env)
    1879              :       END IF
    1880            9 :       IF (ASSOCIATED(qs_env%lri_env)) THEN
    1881            0 :          CALL lri_env_release(qs_env%lri_env)
    1882            0 :          DEALLOCATE (qs_env%lri_env)
    1883              :       END IF
    1884            9 :       IF (ASSOCIATED(qs_env%lri_density)) THEN
    1885            0 :          CALL lri_density_release(qs_env%lri_density)
    1886            0 :          DEALLOCATE (qs_env%lri_density)
    1887              :       END IF
    1888            9 :       IF (ASSOCIATED(qs_env%harris_env)) THEN
    1889            9 :          CALL harris_env_release(qs_env%harris_env)
    1890              :       END IF
    1891            9 :       IF (ASSOCIATED(qs_env%ec_env)) THEN
    1892            9 :          CALL ec_env_release(qs_env%ec_env)
    1893              :       END IF
    1894            9 :       IF (ASSOCIATED(qs_env%exstate_env)) THEN
    1895            9 :          CALL exstate_release(qs_env%exstate_env)
    1896              :       END IF
    1897            9 :       IF (ASSOCIATED(qs_env%mp2_env)) THEN
    1898            0 :          CALL mp2_env_release(qs_env%mp2_env)
    1899            0 :          DEALLOCATE (qs_env%mp2_env)
    1900              :          NULLIFY (qs_env%mp2_env)
    1901              :       END IF
    1902            9 :       IF (ASSOCIATED(qs_env%kg_env)) THEN
    1903            0 :          CALL kg_env_release(qs_env%kg_env)
    1904              :       END IF
    1905              : 
    1906              :       ! dispersion
    1907            9 :       CALL qs_dispersion_release(qs_env%dispersion_env)
    1908              :       ! gCP
    1909            9 :       IF (ASSOCIATED(qs_env%gcp_env)) THEN
    1910            9 :          CALL qs_gcp_release(qs_env%gcp_env)
    1911              :       END IF
    1912              : 
    1913            9 :       IF (ASSOCIATED(qs_env%WannierCentres)) THEN
    1914            0 :          DO i = 1, SIZE(qs_env%WannierCentres)
    1915            0 :             DEALLOCATE (qs_env%WannierCentres(i)%WannierHamDiag)
    1916            0 :             DEALLOCATE (qs_env%WannierCentres(i)%centres)
    1917              :          END DO
    1918            0 :          DEALLOCATE (qs_env%WannierCentres)
    1919              :       END IF
    1920              :       ! EEQ charges
    1921            9 :       IF (ASSOCIATED(qs_env%eeq)) DEALLOCATE (qs_env%eeq)
    1922              :       ! Resp charges
    1923            9 :       IF (ASSOCIATED(qs_env%rhs)) DEALLOCATE (qs_env%rhs)
    1924              : 
    1925              :       ! tblite
    1926            9 :       IF (ASSOCIATED(qs_env%tb_tblite)) THEN
    1927            0 :          CALL deallocate_tblite_type(qs_env%tb_tblite)
    1928              :       END IF
    1929              : 
    1930            9 :       IF (ASSOCIATED(qs_env%gauxc_cache)) THEN
    1931            0 :          CALL gauxc_cache_release(qs_env%gauxc_cache)
    1932            0 :          DEALLOCATE (qs_env%gauxc_cache)
    1933              :       END IF
    1934              : 
    1935            9 :    END SUBROUTINE qs_env_part_release
    1936              : 
    1937            0 : END MODULE qs_environment_types
        

Generated by: LCOV version 2.0-1