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_scf, ONLY: scf
37 : #include "./base/base_uses.f90"
38 :
39 : IMPLICIT NONE
40 :
41 : PRIVATE
42 :
43 : ! *** Global parameters ***
44 :
45 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_energy'
46 :
47 : PUBLIC :: qs_energies
48 :
49 : CONTAINS
50 :
51 : ! **************************************************************************************************
52 : !> \brief Driver routine for QUICKSTEP single point wavefunction optimization.
53 : !> \param qs_env ...
54 : !> \param consistent_energies ...
55 : !> \param calc_forces ...
56 : !> \date 29.10.2002
57 : !> \par History
58 : !> - consistent_energies option added (25.08.2005, TdK)
59 : !> - introduced driver for energy in order to properly decide between
60 : !> SCF or RTP (fschiff 02.09)
61 : !> \author MK
62 : !> \version 1.0
63 : ! **************************************************************************************************
64 20065 : SUBROUTINE qs_energies(qs_env, consistent_energies, calc_forces)
65 : TYPE(qs_environment_type), POINTER :: qs_env
66 : LOGICAL, INTENT(IN), OPTIONAL :: consistent_energies, calc_forces
67 :
68 : CHARACTER(len=*), PARAMETER :: routineN = 'qs_energies'
69 :
70 : INTEGER :: handle
71 : LOGICAL :: do_consistent_energies, &
72 : do_excited_state, loverlap_deltat, &
73 : my_calc_forces, run_rtp
74 : TYPE(dft_control_type), POINTER :: dft_control
75 : TYPE(qs_energy_type), POINTER :: energy
76 : TYPE(section_vals_type), POINTER :: excited_state_section
77 :
78 20065 : CALL timeset(routineN, handle)
79 :
80 20065 : my_calc_forces = .FALSE.
81 20065 : IF (PRESENT(calc_forces)) my_calc_forces = calc_forces
82 :
83 20065 : do_consistent_energies = .FALSE.
84 20065 : IF (PRESENT(consistent_energies)) do_consistent_energies = consistent_energies
85 :
86 20065 : CALL qs_env_rebuild_pw_env(qs_env)
87 :
88 20065 : CALL get_qs_env(qs_env=qs_env, run_rtp=run_rtp)
89 20065 : IF (.NOT. run_rtp) THEN
90 :
91 18843 : NULLIFY (dft_control, energy)
92 18843 : CALL qs_energies_init(qs_env, my_calc_forces)
93 18843 : CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, energy=energy)
94 :
95 : ! *** check if only overlap matrix is needed for couplings
96 18843 : loverlap_deltat = .FALSE.
97 18843 : NULLIFY (excited_state_section)
98 18843 : excited_state_section => section_vals_get_subs_vals(qs_env%input, "DFT%EXCITED_STATES")
99 18843 : CALL section_vals_get(excited_state_section, explicit=do_excited_state)
100 18843 : IF (do_excited_state) THEN
101 : CALL section_vals_val_get(excited_state_section, "OVERLAP_DELTAT", &
102 916 : l_val=loverlap_deltat)
103 : END IF
104 :
105 : ! *** Perform a SCF run ***
106 18843 : IF (.NOT. loverlap_deltat) THEN
107 18843 : IF (dft_control%qs_control%do_ls_scf) THEN
108 596 : CALL ls_scf(qs_env=qs_env)
109 18247 : ELSE IF (dft_control%qs_control%do_almo_scf) THEN
110 116 : CALL almo_entry_scf(qs_env=qs_env, calc_forces=my_calc_forces)
111 : ELSE
112 18131 : CALL scf(qs_env=qs_env)
113 : END IF
114 : END IF
115 :
116 18843 : IF (do_consistent_energies) THEN
117 5208 : CALL qs_ks_update_qs_env(qs_env, calculate_forces=.FALSE., just_energy=.FALSE.)
118 : END IF
119 :
120 18843 : IF (.NOT. (dft_control%qs_control%do_ls_scf .OR. dft_control%qs_control%do_almo_scf)) THEN
121 : ! Compute MP2 energy
122 18131 : CALL qs_energies_mp2(qs_env, my_calc_forces)
123 :
124 18131 : IF (.NOT. ASSOCIATED(qs_env%mp2_env)) THEN
125 : ! if calculate forces, time to compute the w matrix
126 17501 : CALL qs_energies_compute_matrix_w(qs_env, my_calc_forces)
127 : END IF
128 :
129 : END IF
130 :
131 : ! Do active space calculation
132 18843 : CALL active_space_main(qs_env)
133 :
134 : ! Check for energy correction
135 18843 : IF (qs_env%energy_correction) THEN
136 522 : CALL energy_correction(qs_env, ec_init=.TRUE., calculate_forces=.FALSE.)
137 : END IF
138 :
139 18843 : IF (.NOT. loverlap_deltat) THEN
140 18843 : CALL qs_energies_properties(qs_env, calc_forces)
141 :
142 18843 : CALL excited_state_energy(qs_env, calculate_forces=.FALSE.)
143 : END IF
144 :
145 18843 : IF (dft_control%qs_control%lrigpw) THEN
146 58 : CALL lri_print_stat(qs_env)
147 : END IF
148 :
149 : END IF
150 :
151 20065 : CALL timestop(handle)
152 :
153 20065 : END SUBROUTINE qs_energies
154 :
155 : ! **************************************************************************************************
156 : !> \brief Enters the mp2 part of cp2k
157 : !> \param qs_env ...
158 : !> \param calc_forces ...
159 : ! **************************************************************************************************
160 :
161 18131 : SUBROUTINE qs_energies_mp2(qs_env, calc_forces)
162 : TYPE(qs_environment_type), POINTER :: qs_env
163 : LOGICAL, INTENT(IN) :: calc_forces
164 :
165 : LOGICAL :: should_stop
166 :
167 : ! Compute MP2 energy
168 :
169 18131 : IF (ASSOCIATED(qs_env%mp2_env)) THEN
170 :
171 : CALL external_control(should_stop, "MP2", target_time=qs_env%target_time, &
172 630 : start_time=qs_env%start_time)
173 :
174 630 : CALL mp2_main(qs_env=qs_env, calc_forces=calc_forces)
175 : END IF
176 :
177 18131 : END SUBROUTINE qs_energies_mp2
178 :
179 : END MODULE qs_energy
|