LCOV - code coverage report
Current view: top level - src - localization_tb.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:4dc10b3) Lines: 72 79 91.1 %
Date: 2024-11-21 06:45:46 Functions: 1 1 100.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2024 CP2K developers group <https://cp2k.org>                                   !
       4             : !                                                                                                  !
       5             : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6             : !--------------------------------------------------------------------------------------------------!
       7             : 
       8             : ! **************************************************************************************************
       9             : !> \brief Localization/Wannier functions for TB
      10             : !> \par History
      11             : !> \author JHU (03.2019)
      12             : ! **************************************************************************************************
      13             : MODULE localization_tb
      14             :    USE atomic_kind_types,               ONLY: atomic_kind_type
      15             :    USE cp_array_utils,                  ONLY: cp_1d_r_p_type
      16             :    USE cp_control_types,                ONLY: dft_control_type
      17             :    USE cp_fm_types,                     ONLY: cp_fm_create,&
      18             :                                               cp_fm_release,&
      19             :                                               cp_fm_to_fm,&
      20             :                                               cp_fm_type
      21             :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      22             :                                               cp_logger_get_default_io_unit,&
      23             :                                               cp_logger_type
      24             :    USE input_section_types,             ONLY: section_vals_get,&
      25             :                                               section_vals_get_subs_vals,&
      26             :                                               section_vals_type,&
      27             :                                               section_vals_val_get
      28             :    USE kinds,                           ONLY: dp
      29             :    USE particle_list_types,             ONLY: particle_list_type
      30             :    USE particle_types,                  ONLY: particle_type
      31             :    USE pw_env_types,                    ONLY: pw_env_get,&
      32             :                                               pw_env_type
      33             :    USE pw_pool_types,                   ONLY: pw_pool_p_type,&
      34             :                                               pw_pool_type
      35             :    USE pw_types,                        ONLY: pw_c1d_gs_type,&
      36             :                                               pw_r3d_rs_type
      37             :    USE qs_environment_types,            ONLY: get_qs_env,&
      38             :                                               qs_environment_type,&
      39             :                                               set_qs_env
      40             :    USE qs_kind_types,                   ONLY: qs_kind_type
      41             :    USE qs_loc_dipole,                   ONLY: loc_dipole
      42             :    USE qs_loc_states,                   ONLY: get_localization_info
      43             :    USE qs_loc_types,                    ONLY: qs_loc_env_create,&
      44             :                                               qs_loc_env_release,&
      45             :                                               qs_loc_env_type
      46             :    USE qs_loc_utils,                    ONLY: loc_write_restart,&
      47             :                                               qs_loc_control_init,&
      48             :                                               qs_loc_init,&
      49             :                                               retain_history
      50             :    USE qs_mo_types,                     ONLY: get_mo_set,&
      51             :                                               mo_set_type
      52             :    USE qs_subsys_types,                 ONLY: qs_subsys_get,&
      53             :                                               qs_subsys_type
      54             : #include "./base/base_uses.f90"
      55             : 
      56             :    IMPLICIT NONE
      57             :    PRIVATE
      58             : 
      59             :    ! Global parameters
      60             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'localization_tb'
      61             :    PUBLIC :: wfn_localization_tb
      62             : 
      63             : CONTAINS
      64             : 
      65             : ! **************************************************************************************************
      66             : !> \brief wfn localization
      67             : !> \param qs_env ...
      68             : !> \param tb_type ...
      69             : !> \par History
      70             : !>      03.2019 initial version
      71             : !> \author JHU
      72             : !> \note
      73             : ! **************************************************************************************************
      74        5328 :    SUBROUTINE wfn_localization_tb(qs_env, tb_type)
      75             : 
      76             :       TYPE(qs_environment_type), POINTER                 :: qs_env
      77             :       CHARACTER(LEN=*)                                   :: tb_type
      78             : 
      79             :       CHARACTER(len=*), PARAMETER :: routineN = 'wfn_localization_tb'
      80             : 
      81             :       INTEGER                                            :: handle, iounit, ispin, nspins
      82        5328 :       INTEGER, DIMENSION(:, :, :), POINTER               :: marked_states
      83             :       LOGICAL                                            :: do_homo, do_kpoints, explicit, &
      84             :                                                             loc_explicit
      85        5328 :       REAL(KIND=dp), DIMENSION(:), POINTER               :: mo_eigenvalues
      86        5328 :       TYPE(atomic_kind_type), DIMENSION(:), POINTER      :: atomic_kind_set
      87        5328 :       TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER        :: occupied_evals
      88        5328 :       TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:)        :: homo_localized, occupied_orbs
      89        5328 :       TYPE(cp_fm_type), DIMENSION(:), POINTER            :: mo_loc_history
      90             :       TYPE(cp_fm_type), POINTER                          :: mo_coeff
      91             :       TYPE(cp_logger_type), POINTER                      :: logger
      92             :       TYPE(dft_control_type), POINTER                    :: dft_control
      93        5328 :       TYPE(mo_set_type), DIMENSION(:), POINTER           :: mos
      94             :       TYPE(particle_list_type), POINTER                  :: particles
      95        5328 :       TYPE(particle_type), DIMENSION(:), POINTER         :: particle_set
      96             :       TYPE(pw_c1d_gs_type)                               :: wf_g
      97             :       TYPE(pw_env_type), POINTER                         :: pw_env
      98        5328 :       TYPE(pw_pool_p_type), DIMENSION(:), POINTER        :: pw_pools
      99             :       TYPE(pw_pool_type), POINTER                        :: auxbas_pw_pool
     100             :       TYPE(pw_r3d_rs_type)                               :: wf_r
     101        5328 :       TYPE(qs_kind_type), DIMENSION(:), POINTER          :: qs_kind_set
     102             :       TYPE(qs_loc_env_type), POINTER                     :: qs_loc_env_homo
     103             :       TYPE(qs_subsys_type), POINTER                      :: subsys
     104             :       TYPE(section_vals_type), POINTER                   :: dft_section, loc_print_section, &
     105             :                                                             localize_section
     106             : 
     107        5328 :       CALL timeset(routineN, handle)
     108             : 
     109        5328 :       logger => cp_get_default_logger()
     110        5328 :       iounit = cp_logger_get_default_io_unit(logger)
     111             : 
     112        5328 :       CPASSERT(ASSOCIATED(qs_env))
     113        5328 :       dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
     114        5328 :       localize_section => section_vals_get_subs_vals(dft_section, "LOCALIZE")
     115        5328 :       loc_print_section => section_vals_get_subs_vals(localize_section, "PRINT")
     116        5328 :       CALL section_vals_get(localize_section, explicit=loc_explicit)
     117             :       !
     118        5328 :       IF (TRIM(tb_type) == "xTB") THEN
     119             :          ! okay
     120             :       ELSE
     121        1934 :          IF (loc_explicit) THEN
     122           0 :             CPWARN("Wfn localization for this TB type not implemented")
     123           0 :             loc_explicit = .FALSE.
     124             :          END IF
     125             :       END IF
     126             : 
     127        5328 :       IF (loc_explicit) THEN
     128           6 :          CALL section_vals_val_get(localize_section, "LIST", explicit=explicit)
     129           6 :          CPWARN_IF(explicit, "Localization using LIST of states not implemented for TB methods")
     130           6 :          CALL section_vals_val_get(localize_section, "ENERGY_RANGE", explicit=explicit)
     131           6 :          CPWARN_IF(explicit, "Localization using energy range not implemented for TB methods")
     132           6 :          CALL section_vals_val_get(localize_section, "LIST_UNOCCUPIED", explicit=explicit)
     133           6 :          CPWARN_IF(explicit, "Localization of unoccupied states not implemented for TB methods")
     134             :          ! localize all occupied states
     135           6 :          IF (iounit > 0) THEN
     136           3 :             WRITE (iounit, "(/,T11,A)") " +++++++++++++ Start Localization of Orbitals +++++++++++++"
     137             :          END IF
     138             :          !
     139             :          CALL get_qs_env(qs_env, &
     140             :                          dft_control=dft_control, &
     141             :                          do_kpoints=do_kpoints, &
     142             :                          subsys=subsys, &
     143             :                          particle_set=particle_set, &
     144             :                          atomic_kind_set=atomic_kind_set, &
     145           6 :                          qs_kind_set=qs_kind_set)
     146           6 :          CALL qs_subsys_get(subsys, particles=particles)
     147             : 
     148           6 :          IF (do_kpoints) THEN
     149           0 :             CPWARN("Localization not implemented for k-point calculations!")
     150           6 :          ELSEIF (dft_control%restricted) THEN
     151           0 :             IF (iounit > 0) WRITE (iounit, *) &
     152           0 :                " Unclear how we define MOs / localization in the restricted case ... skipping"
     153             :          ELSE
     154           6 :             CALL get_qs_env(qs_env, mos=mos)
     155           6 :             nspins = dft_control%nspins
     156          26 :             ALLOCATE (occupied_orbs(nspins))
     157          26 :             ALLOCATE (occupied_evals(nspins))
     158          20 :             ALLOCATE (homo_localized(nspins))
     159          14 :             DO ispin = 1, nspins
     160             :                CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
     161           8 :                                eigenvalues=mo_eigenvalues)
     162           8 :                occupied_orbs(ispin) = mo_coeff
     163           8 :                occupied_evals(ispin)%array => mo_eigenvalues
     164           8 :                CALL cp_fm_create(homo_localized(ispin), occupied_orbs(ispin)%matrix_struct)
     165          14 :                CALL cp_fm_to_fm(occupied_orbs(ispin), homo_localized(ispin))
     166             :             END DO
     167             : 
     168           6 :             CALL get_qs_env(qs_env, mo_loc_history=mo_loc_history)
     169           6 :             do_homo = .TRUE.
     170             : 
     171           6 :             CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
     172           6 :             CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, pw_pools=pw_pools)
     173           6 :             CALL auxbas_pw_pool%create_pw(wf_r)
     174           6 :             CALL auxbas_pw_pool%create_pw(wf_g)
     175             : 
     176           6 :             NULLIFY (marked_states, qs_loc_env_homo)
     177          42 :             ALLOCATE (qs_loc_env_homo)
     178           6 :             CALL qs_loc_env_create(qs_loc_env_homo)
     179           6 :             CALL qs_loc_control_init(qs_loc_env_homo, localize_section, do_homo=do_homo)
     180             :             CALL qs_loc_init(qs_env, qs_loc_env_homo, localize_section, homo_localized, do_homo, &
     181           6 :                              .FALSE., mo_loc_history=mo_loc_history)
     182             :             CALL get_localization_info(qs_env, qs_loc_env_homo, localize_section, homo_localized, &
     183           6 :                                        wf_r, wf_g, particles, occupied_orbs, occupied_evals, marked_states)
     184             : 
     185             :             !retain the homo_localized for future use
     186           6 :             IF (qs_loc_env_homo%localized_wfn_control%use_history) THEN
     187           0 :                CALL retain_history(mo_loc_history, homo_localized)
     188           0 :                CALL set_qs_env(qs_env, mo_loc_history=mo_loc_history)
     189             :             END IF
     190             : 
     191             :             !write restart for localization of occupied orbitals
     192             :             CALL loc_write_restart(qs_loc_env_homo, loc_print_section, mos, &
     193           6 :                                    homo_localized, do_homo)
     194           6 :             CALL cp_fm_release(homo_localized)
     195           6 :             DEALLOCATE (occupied_orbs)
     196           6 :             DEALLOCATE (occupied_evals)
     197             :             ! Print Total Dipole if the localization has been performed
     198           6 :             IF (qs_loc_env_homo%do_localize) THEN
     199           6 :                CALL loc_dipole(qs_env%input, dft_control, qs_loc_env_homo, logger, qs_env)
     200             :             END IF
     201           6 :             CALL auxbas_pw_pool%give_back_pw(wf_g)
     202           6 :             CALL auxbas_pw_pool%give_back_pw(wf_r)
     203           6 :             CALL qs_loc_env_release(qs_loc_env_homo)
     204           6 :             DEALLOCATE (qs_loc_env_homo)
     205          12 :             IF (ASSOCIATED(marked_states)) THEN
     206           2 :                DEALLOCATE (marked_states)
     207             :             END IF
     208             :          END IF
     209             : 
     210             :       END IF
     211             : 
     212        5328 :       CALL timestop(handle)
     213             : 
     214       10656 :    END SUBROUTINE wfn_localization_tb
     215             : 
     216             : ! **************************************************************************************************
     217             : 
     218             : END MODULE localization_tb

Generated by: LCOV version 1.15