(git:ba1d7ca)
Loading...
Searching...
No Matches
qs_energy.F
Go to the documentation of this file.
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!> \brief Perform a QUICKSTEP wavefunction optimization (single point)
10!> \par History
11!> none
12!> \author MK (29.10.2002)
13! **************************************************************************************************
15 USE almo_scf, ONLY: almo_entry_scf
18 USE dm_ls_scf, ONLY: ls_scf
27 USE mp2, ONLY: mp2_main
39 USE qs_nonscf, ONLY: nonscf
40 USE qs_scf, ONLY: scf
43#include "./base/base_uses.f90"
44
45 IMPLICIT NONE
46
47 PRIVATE
48
49! *** Global parameters ***
50
51 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_energy'
52
53 PUBLIC :: qs_energies
54
55CONTAINS
56
57! **************************************************************************************************
58!> \brief Driver routine for QUICKSTEP single point wavefunction optimization.
59!> \param qs_env ...
60!> \param consistent_energies ...
61!> \param calc_forces ...
62!> \date 29.10.2002
63!> \par History
64!> - consistent_energies option added (25.08.2005, TdK)
65!> - introduced driver for energy in order to properly decide between
66!> SCF or RTP (fschiff 02.09)
67!> \author MK
68!> \version 1.0
69! **************************************************************************************************
70 SUBROUTINE qs_energies(qs_env, consistent_energies, calc_forces)
71 TYPE(qs_environment_type), POINTER :: qs_env
72 LOGICAL, INTENT(IN), OPTIONAL :: consistent_energies, calc_forces
73
74 CHARACTER(len=*), PARAMETER :: routinen = 'qs_energies'
75
76 INTEGER :: handle
77 LOGICAL :: do_consistent_energies, &
78 do_excited_state, loverlap_deltat, &
79 my_calc_forces, run_rtp
80 TYPE(dft_control_type), POINTER :: dft_control
81 TYPE(harris_type), POINTER :: harris_env
82 TYPE(qs_energy_type), POINTER :: energy
83 TYPE(scf_control_type), POINTER :: scf_control
84 TYPE(section_vals_type), POINTER :: excited_state_section
85
86 CALL timeset(routinen, handle)
87
88 my_calc_forces = .false.
89 IF (PRESENT(calc_forces)) my_calc_forces = calc_forces
90
91 do_consistent_energies = .false.
92 IF (PRESENT(consistent_energies)) do_consistent_energies = consistent_energies
93
94 CALL qs_env_rebuild_pw_env(qs_env)
95
96 CALL get_qs_env(qs_env=qs_env, run_rtp=run_rtp)
97 IF (.NOT. run_rtp) THEN
98
99 NULLIFY (dft_control, energy, harris_env)
100 CALL qs_energies_init(qs_env, my_calc_forces)
101 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, scf_control=scf_control, energy=energy, &
102 harris_env=harris_env)
103 IF (ASSOCIATED(harris_env)) THEN
104 IF (harris_env%direct_density_matrix_energy .AND. my_calc_forces) THEN
105 cpabort("Forces are not available for the direct fitted-density-matrix energy")
106 END IF
107 END IF
108
109 ! *** check if only overlap matrix is needed for couplings
110 loverlap_deltat = .false.
111 NULLIFY (excited_state_section)
112 excited_state_section => section_vals_get_subs_vals(qs_env%input, "DFT%EXCITED_STATES")
113 CALL section_vals_get(excited_state_section, explicit=do_excited_state)
114 IF (do_excited_state) THEN
115 CALL section_vals_val_get(excited_state_section, "OVERLAP_DELTAT", &
116 l_val=loverlap_deltat)
117 END IF
118
119 ! *** Perform a SCF run ***
120 IF (.NOT. loverlap_deltat) THEN
121 IF (scf_control%non_selfconsistent .AND. .NOT. scf_control%force_scf_calculation) THEN
122 CALL nonscf(qs_env)
123 ELSE IF (dft_control%qs_control%do_ls_scf) THEN
124 CALL ls_scf(qs_env)
125 ELSE IF (dft_control%qs_control%do_almo_scf) THEN
126 CALL almo_entry_scf(qs_env, calc_forces=my_calc_forces)
127 ELSE
128 ! current-induced forces
129 IF (dft_control%smeagol_control%smeagol_enabled .AND. &
130 dft_control%smeagol_control%run_type == smeagol_runtype_emtransport) THEN
131 dft_control%smeagol_control%emforces = my_calc_forces
132 END IF
133
134 CALL scf(qs_env)
135 END IF
136 END IF
137
138 IF (do_consistent_energies) THEN
139 CALL qs_ks_update_qs_env(qs_env, calculate_forces=.false., just_energy=.false.)
140 END IF
141
142 IF (.NOT. (dft_control%qs_control%do_ls_scf .OR. dft_control%qs_control%do_almo_scf)) THEN
143 ! Compute MP2 energy
144 CALL qs_energies_mp2(qs_env, my_calc_forces)
145
146 IF (.NOT. ASSOCIATED(qs_env%mp2_env)) THEN
147 ! do not overwrite w matrix computed by SMEAGOL (current-induced forces)
148 IF (.NOT. (dft_control%smeagol_control%smeagol_enabled .AND. &
149 dft_control%smeagol_control%run_type == smeagol_runtype_emtransport)) THEN
150 ! if calculate forces, time to compute the w matrix
151 CALL compute_matrix_w(qs_env, my_calc_forces)
152 END IF
153 END IF
154 END IF
155
156 ! Check for energy correction
157 IF (qs_env%harris_method) THEN
158 CALL harris_energy_correction(qs_env, my_calc_forces)
159 END IF
160
161 ! Do active space calculation
162 CALL active_space_main(qs_env)
163
164 ! Check for energy correction
165 IF (qs_env%energy_correction) THEN
166 CALL energy_correction(qs_env, ec_init=.true., calculate_forces=.false.)
167 END IF
168
169 IF (.NOT. loverlap_deltat) THEN
170 ! Calculate energy, response vector and some contributions to the force
171 CALL qs_energies_properties(qs_env, calc_forces)
172
173 ! Update total energy of the selected excited state
174 CALL excited_state_energy(qs_env, calculate_forces=.false.)
175 END IF
176
177 IF (dft_control%tddfpt2_control%do_smearing) THEN
178 IF (.NOT. ASSOCIATED(dft_control%tddfpt2_control%smeared_occup)) THEN
179 cpabort("Smearing occupation not associated.")
180 END IF
181 CALL deallocate_fermi_params(dft_control%tddfpt2_control%smeared_occup)
182 END IF
183 IF (dft_control%qs_control%lrigpw) THEN
184 CALL lri_print_stat(qs_env)
185 END IF
186
187 END IF
188
189 CALL timestop(handle)
190
191 END SUBROUTINE qs_energies
192
193! **************************************************************************************************
194!> \brief Enters the mp2 part of cp2k
195!> \param qs_env ...
196!> \param calc_forces ...
197! **************************************************************************************************
198
199 SUBROUTINE qs_energies_mp2(qs_env, calc_forces)
200 TYPE(qs_environment_type), POINTER :: qs_env
201 LOGICAL, INTENT(IN) :: calc_forces
202
203 LOGICAL :: should_stop
204
205 ! Compute MP2 energy
206
207 IF (ASSOCIATED(qs_env%mp2_env)) THEN
208
209 CALL external_control(should_stop, "MP2", target_time=qs_env%target_time, &
210 start_time=qs_env%start_time)
211
212 CALL mp2_main(qs_env=qs_env, calc_forces=calc_forces)
213 END IF
214
215 END SUBROUTINE qs_energies_mp2
216
217END MODULE qs_energy
Routines for all ALMO-based SCF methods 'RZK-warning' marks unresolved issues.
Definition almo_scf.F:15
subroutine, public almo_entry_scf(qs_env, calc_forces)
The entry point into ALMO SCF routines.
Definition almo_scf.F:126
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
Routines for a linear scaling quickstep SCF run based on the density matrix.
Definition dm_ls_scf.F:15
subroutine, public ls_scf(qs_env, nonscf)
perform an linear scaling scf procedure: entry point
Definition dm_ls_scf.F:108
Routines for an energy correction on top of a Kohn-Sham calculation.
subroutine, public energy_correction(qs_env, ec_init, calculate_forces)
Energy Correction to a Kohn-Sham simulation Available energy corrections: (1) Harris energy functiona...
Routines for total energy and forces of excited states.
subroutine, public excited_state_energy(qs_env, calculate_forces)
Excited state energy and forces.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public smeagol_runtype_emtransport
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Calculates integral matrices for LRIGPW method lri : local resolution of the identity.
subroutine, public lri_print_stat(qs_env, ltddfpt, tddfpt_lri_env)
...
Routines to calculate MP2 energy.
Definition mp2.F:14
subroutine, public mp2_main(qs_env, calc_forces)
the main entry point for MP2 calculations
Definition mp2.F:128
Determine active space Hamiltonian.
subroutine, public active_space_main(qs_env)
Main method for determining the active space Hamiltonian.
Utility subroutine for qs energy calculation.
subroutine, public qs_energies_init(qs_env, calc_forces)
Refactoring of qs_energies_scf. Driver routine for the initial setup and calculations for a qs energy...
Utility subroutine for qs energy calculation.
subroutine, public qs_energies_properties(qs_env, calc_forces)
Refactoring of qs_energies_scf. Moves computation of properties into separate subroutine....
Perform a QUICKSTEP wavefunction optimization (single point)
Definition qs_energy.F:14
subroutine, public qs_energies(qs_env, consistent_energies, calc_forces)
Driver routine for QUICKSTEP single point wavefunction optimization.
Definition qs_energy.F:71
qs_environment methods that use many other modules
subroutine, public qs_env_rebuild_pw_env(qs_env)
rebuilds the pw_env in the given qs_env, allocating it if necessary
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Harris method calculations.
subroutine, public harris_energy_correction(qs_env, calculate_forces)
...
Types needed for a for a Harris model calculation.
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, print_active)
updates the Kohn Sham matrix of the given qs_env (facility method)
Utility subroutine for qs energy calculation.
Definition qs_matrix_w.F:14
subroutine, public compute_matrix_w(qs_env, calc_forces)
Refactoring of qs_energies_scf. Moves computation of matrix_w into separate subroutine.
Definition qs_matrix_w.F:63
Routines for Quickstep NON-SCF run.
Definition qs_nonscf.F:14
subroutine, public nonscf(qs_env)
Find solution to HC=SCE.
Definition qs_nonscf.F:78
Routines for the Quickstep SCF run.
Definition qs_scf.F:47
subroutine, public scf(qs_env, has_converged, total_scf_steps)
perform an scf procedure in the given qs_env
Definition qs_scf.F:265
subroutine, public deallocate_fermi_params(smeared_occup)
...
parameters that control an scf iteration
Contains information on the Harris method.