LCOV - code coverage report
Current view: top level - src - qs_energy.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:b8e0b09) Lines: 47 47 100.0 %
Date: 2024-08-31 06:31:37 Functions: 2 2 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 Perform a QUICKSTEP wavefunction optimization (single point)
      10             : !> \par History
      11             : !>      none
      12             : !> \author MK (29.10.2002)
      13             : ! **************************************************************************************************
      14             : MODULE qs_energy
      15             :    USE almo_scf,                        ONLY: almo_entry_scf
      16             :    USE cp_control_types,                ONLY: dft_control_type
      17             :    USE cp_external_control,             ONLY: external_control
      18             :    USE dm_ls_scf,                       ONLY: ls_scf
      19             :    USE energy_corrections,              ONLY: energy_correction
      20             :    USE excited_states,                  ONLY: excited_state_energy
      21             :    USE input_section_types,             ONLY: section_vals_get,&
      22             :                                               section_vals_get_subs_vals,&
      23             :                                               section_vals_type,&
      24             :                                               section_vals_val_get
      25             :    USE lri_environment_methods,         ONLY: lri_print_stat
      26             :    USE mp2,                             ONLY: mp2_main
      27             :    USE qs_active_space_methods,         ONLY: active_space_main
      28             :    USE qs_energy_init,                  ONLY: qs_energies_init
      29             :    USE qs_energy_types,                 ONLY: qs_energy_type
      30             :    USE qs_energy_utils,                 ONLY: qs_energies_properties
      31             :    USE qs_environment_methods,          ONLY: qs_env_rebuild_pw_env
      32             :    USE qs_environment_types,            ONLY: get_qs_env,&
      33             :                                               qs_environment_type
      34             :    USE qs_ks_methods,                   ONLY: qs_ks_update_qs_env
      35             :    USE qs_matrix_w,                     ONLY: qs_energies_compute_matrix_w
      36             :    USE qs_nonscf,                       ONLY: nonscf
      37             :    USE qs_scf,                          ONLY: scf
      38             :    USE scf_control_types,               ONLY: scf_control_type
      39             : #include "./base/base_uses.f90"
      40             : 
      41             :    IMPLICIT NONE
      42             : 
      43             :    PRIVATE
      44             : 
      45             : ! *** Global parameters ***
      46             : 
      47             :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_energy'
      48             : 
      49             :    PUBLIC :: qs_energies
      50             : 
      51             : CONTAINS
      52             : 
      53             : ! **************************************************************************************************
      54             : !> \brief   Driver routine for QUICKSTEP single point wavefunction optimization.
      55             : !> \param qs_env ...
      56             : !> \param consistent_energies ...
      57             : !> \param calc_forces ...
      58             : !> \date    29.10.2002
      59             : !> \par History
      60             : !>          - consistent_energies option added (25.08.2005, TdK)
      61             : !>          - introduced driver for energy in order to properly decide between
      62             : !>            SCF or RTP (fschiff 02.09)
      63             : !> \author  MK
      64             : !> \version 1.0
      65             : ! **************************************************************************************************
      66       20101 :    SUBROUTINE qs_energies(qs_env, consistent_energies, calc_forces)
      67             :       TYPE(qs_environment_type), POINTER                 :: qs_env
      68             :       LOGICAL, INTENT(IN), OPTIONAL                      :: consistent_energies, calc_forces
      69             : 
      70             :       CHARACTER(len=*), PARAMETER                        :: routineN = 'qs_energies'
      71             : 
      72             :       INTEGER                                            :: handle
      73             :       LOGICAL                                            :: do_consistent_energies, &
      74             :                                                             do_excited_state, loverlap_deltat, &
      75             :                                                             my_calc_forces, run_rtp
      76             :       TYPE(dft_control_type), POINTER                    :: dft_control
      77             :       TYPE(qs_energy_type), POINTER                      :: energy
      78             :       TYPE(scf_control_type), POINTER                    :: scf_control
      79             :       TYPE(section_vals_type), POINTER                   :: excited_state_section
      80             : 
      81       20101 :       CALL timeset(routineN, handle)
      82             : 
      83       20101 :       my_calc_forces = .FALSE.
      84       20101 :       IF (PRESENT(calc_forces)) my_calc_forces = calc_forces
      85             : 
      86       20101 :       do_consistent_energies = .FALSE.
      87       20101 :       IF (PRESENT(consistent_energies)) do_consistent_energies = consistent_energies
      88             : 
      89       20101 :       CALL qs_env_rebuild_pw_env(qs_env)
      90             : 
      91       20101 :       CALL get_qs_env(qs_env=qs_env, run_rtp=run_rtp)
      92       20101 :       IF (.NOT. run_rtp) THEN
      93             : 
      94       18879 :          NULLIFY (dft_control, energy)
      95       18879 :          CALL qs_energies_init(qs_env, my_calc_forces)
      96       18879 :          CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, scf_control=scf_control, energy=energy)
      97             : 
      98             :          ! *** check if only overlap matrix is needed for couplings
      99       18879 :          loverlap_deltat = .FALSE.
     100       18879 :          NULLIFY (excited_state_section)
     101       18879 :          excited_state_section => section_vals_get_subs_vals(qs_env%input, "DFT%EXCITED_STATES")
     102       18879 :          CALL section_vals_get(excited_state_section, explicit=do_excited_state)
     103       18879 :          IF (do_excited_state) THEN
     104             :             CALL section_vals_val_get(excited_state_section, "OVERLAP_DELTAT", &
     105         916 :                                       l_val=loverlap_deltat)
     106             :          END IF
     107             : 
     108             :          ! *** Perform a SCF run ***
     109       18879 :          IF (.NOT. loverlap_deltat) THEN
     110       18879 :             IF (scf_control%non_selfconsistent) THEN
     111         576 :                CALL nonscf(qs_env)
     112       18303 :             ELSE IF (dft_control%qs_control%do_ls_scf) THEN
     113         596 :                CALL ls_scf(qs_env)
     114       17707 :             ELSE IF (dft_control%qs_control%do_almo_scf) THEN
     115         116 :                CALL almo_entry_scf(qs_env, calc_forces=my_calc_forces)
     116             :             ELSE
     117       17591 :                CALL scf(qs_env)
     118             :             END IF
     119             :          END IF
     120             : 
     121       18879 :          IF (do_consistent_energies) THEN
     122        5208 :             CALL qs_ks_update_qs_env(qs_env, calculate_forces=.FALSE., just_energy=.FALSE.)
     123             :          END IF
     124             : 
     125       18879 :          IF (.NOT. (dft_control%qs_control%do_ls_scf .OR. dft_control%qs_control%do_almo_scf)) THEN
     126             :             ! Compute MP2 energy
     127       18167 :             CALL qs_energies_mp2(qs_env, my_calc_forces)
     128             : 
     129       18167 :             IF (.NOT. ASSOCIATED(qs_env%mp2_env)) THEN
     130             :                ! if calculate forces, time to compute the w matrix
     131       17511 :                CALL qs_energies_compute_matrix_w(qs_env, my_calc_forces)
     132             :             END IF
     133             : 
     134             :          END IF
     135             : 
     136             :          ! Do active space calculation
     137       18879 :          CALL active_space_main(qs_env)
     138             : 
     139             :          ! Check for energy correction
     140       18879 :          IF (qs_env%energy_correction) THEN
     141         522 :             CALL energy_correction(qs_env, ec_init=.TRUE., calculate_forces=.FALSE.)
     142             :          END IF
     143             : 
     144       18879 :          IF (.NOT. loverlap_deltat) THEN
     145       18879 :             CALL qs_energies_properties(qs_env, calc_forces)
     146             : 
     147       18879 :             CALL excited_state_energy(qs_env, calculate_forces=.FALSE.)
     148             :          END IF
     149             : 
     150       18879 :          IF (dft_control%qs_control%lrigpw) THEN
     151          58 :             CALL lri_print_stat(qs_env)
     152             :          END IF
     153             : 
     154             :       END IF
     155             : 
     156       20101 :       CALL timestop(handle)
     157             : 
     158       20101 :    END SUBROUTINE qs_energies
     159             : 
     160             : ! **************************************************************************************************
     161             : !> \brief Enters the mp2 part of cp2k
     162             : !> \param qs_env ...
     163             : !> \param calc_forces ...
     164             : ! **************************************************************************************************
     165             : 
     166       18167 :    SUBROUTINE qs_energies_mp2(qs_env, calc_forces)
     167             :       TYPE(qs_environment_type), POINTER                 :: qs_env
     168             :       LOGICAL, INTENT(IN)                                :: calc_forces
     169             : 
     170             :       LOGICAL                                            :: should_stop
     171             : 
     172             :       ! Compute MP2 energy
     173             : 
     174       18167 :       IF (ASSOCIATED(qs_env%mp2_env)) THEN
     175             : 
     176             :          CALL external_control(should_stop, "MP2", target_time=qs_env%target_time, &
     177         656 :                                start_time=qs_env%start_time)
     178             : 
     179         656 :          CALL mp2_main(qs_env=qs_env, calc_forces=calc_forces)
     180             :       END IF
     181             : 
     182       18167 :    END SUBROUTINE qs_energies_mp2
     183             : 
     184             : END MODULE qs_energy

Generated by: LCOV version 1.15