LCOV - code coverage report
Current view: top level - src - wannier_states.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:e7e05ae) Lines: 47 47 100.0 %
Date: 2024-04-18 06:59:28 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 Routines for the calculation of wannier states
      10             : !> \author Alin M Elena
      11             : ! **************************************************************************************************
      12             : MODULE wannier_states
      13             :    USE cp_dbcsr_operations,             ONLY: cp_dbcsr_sm_fm_multiply
      14             :    USE cp_fm_struct,                    ONLY: cp_fm_struct_create,&
      15             :                                               cp_fm_struct_release,&
      16             :                                               cp_fm_struct_type
      17             :    USE cp_fm_types,                     ONLY: cp_fm_create,&
      18             :                                               cp_fm_get_element,&
      19             :                                               cp_fm_get_info,&
      20             :                                               cp_fm_release,&
      21             :                                               cp_fm_to_fm,&
      22             :                                               cp_fm_type
      23             :    USE cp_log_handling,                 ONLY: cp_get_default_logger,&
      24             :                                               cp_logger_get_default_io_unit,&
      25             :                                               cp_logger_type
      26             :    USE cp_output_handling,              ONLY: cp_print_key_finished_output,&
      27             :                                               cp_print_key_unit_nr
      28             :    USE cp_units,                        ONLY: cp_unit_from_cp2k
      29             :    USE dbcsr_api,                       ONLY: dbcsr_type
      30             :    USE input_section_types,             ONLY: section_vals_get_subs_vals,&
      31             :                                               section_vals_type,&
      32             :                                               section_vals_val_get
      33             :    USE kinds,                           ONLY: default_string_length,&
      34             :                                               dp
      35             :    USE message_passing,                 ONLY: mp_para_env_type
      36             :    USE parallel_gemm_api,               ONLY: parallel_gemm
      37             :    USE qs_environment_types,            ONLY: get_qs_env,&
      38             :                                               qs_environment_type
      39             :    USE wannier_states_types,            ONLY: wannier_centres_type
      40             : !!!! this ones are needed to mapping
      41             : #include "./base/base_uses.f90"
      42             : 
      43             :    IMPLICIT NONE
      44             : 
      45             :    PRIVATE
      46             : 
      47             : ! *** Global parameters ***
      48             : 
      49             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'wannier_states'
      50             : 
      51             :    LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .TRUE.
      52             : 
      53             : ! *** Public subroutines ***
      54             : 
      55             :    PUBLIC :: construct_wannier_states
      56             : 
      57             : CONTAINS
      58             : 
      59             : ! **************************************************************************************************
      60             : !> \brief constructs wannier states. mo_localized should not be overwritten!
      61             : !> \param mo_localized ...
      62             : !> \param Hks ...
      63             : !> \param qs_env ...
      64             : !> \param loc_print_section ...
      65             : !> \param WannierCentres ...
      66             : !> \param ns ...
      67             : !> \param states ...
      68             : ! **************************************************************************************************
      69          32 :    SUBROUTINE construct_wannier_states(mo_localized, &
      70             :                                        Hks, qs_env, loc_print_section, WannierCentres, ns, states)
      71             : 
      72             :       TYPE(cp_fm_type), INTENT(in)                       :: mo_localized
      73             :       TYPE(dbcsr_type), POINTER                          :: Hks
      74             :       TYPE(qs_environment_type), POINTER                 :: qs_env
      75             :       TYPE(section_vals_type), POINTER                   :: loc_print_section
      76             :       TYPE(wannier_centres_type), INTENT(INOUT)          :: WannierCentres
      77             :       INTEGER, INTENT(IN)                                :: ns
      78             :       INTEGER, INTENT(IN), POINTER                       :: states(:)
      79             : 
      80             :       CHARACTER(len=*), PARAMETER :: routineN = 'construct_wannier_states'
      81             : 
      82             :       CHARACTER(default_string_length)                   :: unit_str
      83             :       INTEGER                                            :: handle, i, iproc, ncol_global, nproc, &
      84             :                                                             nrow_global, nstates(2), output_unit, &
      85             :                                                             unit_mat
      86             :       REAL(KIND=dp)                                      :: unit_conv
      87             :       TYPE(cp_fm_struct_type), POINTER                   :: fm_struct_tmp
      88             :       TYPE(cp_fm_type)                                   :: b, c, d
      89             :       TYPE(cp_logger_type), POINTER                      :: logger
      90             :       TYPE(mp_para_env_type), POINTER                    :: para_env
      91             :       TYPE(section_vals_type), POINTER                   :: print_key
      92             : 
      93             : !-----------------------------------------------------------------------
      94             : !-----------------------------------------------------------------------
      95             : 
      96          16 :       CALL timeset(routineN, handle)
      97          16 :       NULLIFY (logger, para_env)
      98             : 
      99          16 :       CALL get_qs_env(qs_env, para_env=para_env)
     100          16 :       nproc = para_env%num_pe
     101             : 
     102          16 :       logger => cp_get_default_logger()
     103          16 :       output_unit = cp_logger_get_default_io_unit(logger)
     104             :       CALL cp_fm_get_info(mo_localized, &
     105             :                           ncol_global=ncol_global, &
     106          16 :                           nrow_global=nrow_global)
     107             : 
     108          16 :       nstates(1) = ns
     109          16 :       nstates(2) = para_env%mepos
     110          16 :       iproc = nstates(2)
     111          16 :       NULLIFY (fm_struct_tmp, print_key)
     112             : 
     113          16 :       print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_CENTERS")
     114          16 :       CALL section_vals_val_get(print_key, "UNIT", c_val=unit_str)
     115          16 :       unit_conv = cp_unit_from_cp2k(1.0_dp, TRIM(unit_str))
     116             : 
     117             :       CALL cp_fm_struct_create(fm_struct_tmp, nrow_global=nrow_global, &
     118             :                                ncol_global=1, &
     119             :                                para_env=mo_localized%matrix_struct%para_env, &
     120          16 :                                context=mo_localized%matrix_struct%context)
     121             : 
     122          16 :       CALL cp_fm_create(b, fm_struct_tmp, name="b")
     123          16 :       CALL cp_fm_create(c, fm_struct_tmp, name="c")
     124             : 
     125          16 :       CALL cp_fm_struct_release(fm_struct_tmp)
     126             : 
     127             :       CALL cp_fm_struct_create(fm_struct_tmp, nrow_global=1, ncol_global=1, &
     128             :                                para_env=mo_localized%matrix_struct%para_env, &
     129          16 :                                context=mo_localized%matrix_struct%context)
     130             : 
     131          16 :       CALL cp_fm_create(d, fm_struct_tmp, name="d")
     132          16 :       CALL cp_fm_struct_release(fm_struct_tmp)
     133             : 
     134         132 :       WannierCentres%WannierHamDiag = 0.0_dp
     135             :       ! try to print the matrix
     136             : 
     137             :       unit_mat = cp_print_key_unit_nr(logger, loc_print_section, &
     138             :                                       "WANNIER_STATES", extension=".whks", &
     139          16 :                                       ignore_should_output=.FALSE.)
     140          16 :       IF (unit_mat > 0) THEN
     141           8 :          WRITE (unit_mat, '(a16,1(i0,1x))') "Wannier states: ", ns
     142           8 :          WRITE (unit_mat, '(a16)') "#No x y z energy "
     143             :       END IF
     144         132 :       DO i = 1, ns
     145         116 :          CALL cp_fm_to_fm(mo_localized, b, 1, states(i), 1)
     146         116 :          CALL cp_dbcsr_sm_fm_multiply(Hks, b, c, 1)
     147             :          CALL parallel_gemm('T', 'N', 1, 1, nrow_global, 1.0_dp, &
     148         116 :                             b, c, 0.0_dp, d)
     149         116 :          CALL cp_fm_get_element(d, 1, 1, WannierCentres%WannierHamDiag(i))
     150             :          !               if (iproc==para_env%mepos) WRITE(unit_mat,'(f16.8,2x)', advance='no')WannierCentres%WannierHamDiag(i)
     151         174 :          IF (unit_mat > 0) WRITE (unit_mat, '(i0,1x,4(f16.8,2x))') states(i), &
     152         306 :             WannierCentres%centres(1:3, states(i))*unit_conv, WannierCentres%WannierHamDiag(states(i))
     153             :       END DO
     154             : 
     155          16 :       IF (unit_mat > 0) WRITE (unit_mat, *)
     156             :       CALL cp_print_key_finished_output(unit_mat, logger, loc_print_section, &
     157          16 :                                         "WANNIER_STATES")
     158          16 :       IF (output_unit > 0) THEN
     159           8 :          WRITE (output_unit, *) ""
     160           8 :          WRITE (output_unit, *) "NUMBER OF Wannier STATES  ", ns
     161           8 :          WRITE (output_unit, *) "ENERGY      original MO-index"
     162          66 :          DO i = 1, ns
     163          66 :             WRITE (output_unit, '(f16.8,2x,i0)') WannierCentres%WannierHamDiag(i), states(i)
     164             :          END DO
     165             :       END IF
     166          16 :       CALL cp_fm_release(b)
     167          16 :       CALL cp_fm_release(c)
     168          16 :       CALL cp_fm_release(d)
     169          16 :       CALL timestop(handle)
     170          16 :    END SUBROUTINE construct_wannier_states
     171             : 
     172             : END MODULE wannier_states
     173             : 

Generated by: LCOV version 1.15