(git:691081d)
Loading...
Searching...
No Matches
qs_nonscf.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 Routines for Quickstep NON-SCF run.
10!> \par History
11!> - initial setup [JGH, 2024]
12!> \author JGH (13.05.2024)
13! **************************************************************************************************
16 USE cp_dbcsr_api, ONLY: dbcsr_copy,&
22 USE dm_ls_scf, ONLY: ls_scf
26 USE kinds, ONLY: dp
27 USE kpoint_types, ONLY: kpoint_type
28 USE machine, ONLY: m_walltime
40 USE qs_ks_types, ONLY: qs_ks_did_change,&
42 USE qs_mo_types, ONLY: mo_set_type
45 USE qs_rho_types, ONLY: qs_rho_get,&
47 USE qs_scf, ONLY: init_scf_loop
57#include "./base/base_uses.f90"
58
59 IMPLICIT NONE
60
61 PRIVATE
62
63 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_nonscf'
64
65 PUBLIC :: nonscf
66
67CONTAINS
68
69! **************************************************************************************************
70!> \brief Find solution to HC=SCE
71!> \param qs_env the qs_environment where to perform the scf procedure
72!> \par History
73!> none
74!> \author JGH
75!> \note
76! **************************************************************************************************
77 SUBROUTINE nonscf(qs_env)
78 TYPE(qs_environment_type), POINTER :: qs_env
79
80 TYPE(dft_control_type), POINTER :: dft_control
81 TYPE(harris_type), POINTER :: harris_env
82 TYPE(qs_rho_type), POINTER :: rho
83 TYPE(qs_scf_env_type), POINTER :: scf_env
84 TYPE(scf_control_type), POINTER :: scf_control
85
86 NULLIFY (harris_env, rho)
87 CALL get_qs_env(qs_env, dft_control=dft_control, harris_env=harris_env, rho=rho)
88
89 IF (ASSOCIATED(harris_env)) THEN
90 IF (harris_env%fit_method == hfit_relative_entropy .AND. &
91 .NOT. harris_env%density_fit_ready) THEN
92 CALL harris_density_update(qs_env, harris_env)
93 CALL qs_rho_update_rho(rho, qs_env=qs_env)
95 END IF
96 IF (harris_env%direct_density_matrix_energy) THEN
97 CALL harris_density_update(qs_env, harris_env)
98 CALL qs_rho_update_rho(rho, qs_env=qs_env)
99 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true., potential_changed=.true.)
101 RETURN
102 END IF
103 END IF
104
105 IF (dft_control%qs_control%do_ls_scf) THEN
106 ! Density matrix based solver
107
108 CALL ls_scf(qs_env, nonscf=.true.)
109
110 ELSE
111 ! Wavefunction based solver
112
113 CALL get_qs_env(qs_env, scf_env=scf_env, scf_control=scf_control)
114 IF (.NOT. ASSOCIATED(scf_env)) THEN
115 CALL qs_scf_env_initialize(qs_env, scf_env)
116 CALL set_qs_env(qs_env, scf_env=scf_env)
117 ELSE
118 CALL qs_scf_env_initialize(qs_env, scf_env)
119 END IF
120
121 CALL do_nonscf(qs_env, scf_env, scf_control)
122
123 ! add the converged wavefunction to the wavefunction history
124 IF (ASSOCIATED(qs_env%wf_history)) THEN
125 CALL wfi_update(qs_env%wf_history, qs_env=qs_env, dt=1.0_dp)
126 END IF
127
128 ! compute properties that depend on the wavefunction
129 CALL qs_scf_compute_properties(qs_env)
130
131 END IF
132
133 END SUBROUTINE nonscf
134
135! **************************************************************************************************
136!> \brief Solve KS equation for fixed potential
137!> \param qs_env ...
138!> \param scf_env the scf_env where to perform the scf procedure
139!> \param scf_control ...
140!> \par History
141!> none
142!> \author JGH
143!> \note
144! **************************************************************************************************
145 SUBROUTINE do_nonscf(qs_env, scf_env, scf_control)
146
147 TYPE(qs_environment_type), POINTER :: qs_env
148 TYPE(qs_scf_env_type), POINTER :: scf_env
149 TYPE(scf_control_type), POINTER :: scf_control
150
151 CHARACTER(LEN=*), PARAMETER :: routinen = 'do_nonscf'
152
153 INTEGER :: handle, img, iounit, ispin
154 LOGICAL :: diis_step, do_kpoints
155 REAL(kind=dp) :: pc_ener, qmmm_el, t1, t2, tdiag
156 TYPE(cp_logger_type), POINTER :: logger
157 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrixkp_ks, rho_ao_kp
158 TYPE(dft_control_type), POINTER :: dft_control
159 TYPE(kpoint_type), POINTER :: kpoints
160 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
161 TYPE(mp_para_env_type), POINTER :: para_env
162 TYPE(qs_energy_type), POINTER :: energy
163 TYPE(qs_ks_env_type), POINTER :: ks_env
164 TYPE(qs_rho_type), POINTER :: rho
165 TYPE(section_vals_type), POINTER :: dft_section, input, scf_section
166
167 CALL timeset(routinen, handle)
168
169 t1 = m_walltime()
170
171 logger => cp_get_default_logger()
172 iounit = cp_logger_get_default_io_unit(logger)
173
174 CALL get_qs_env(qs_env=qs_env, &
175 energy=energy, &
176 ks_env=ks_env, &
177 rho=rho, &
178 mos=mos, &
179 input=input, &
180 dft_control=dft_control, &
181 do_kpoints=do_kpoints, &
182 kpoints=kpoints, &
183 para_env=para_env)
184
185 DO ispin = 1, dft_control%nspins
186 cpassert(.NOT. mos(ispin)%use_mo_coeff_b)
187 END DO
188
189 dft_section => section_vals_get_subs_vals(input, "DFT")
190 scf_section => section_vals_get_subs_vals(dft_section, "SCF")
191 CALL init_scf_loop(scf_env=scf_env, qs_env=qs_env, scf_section=scf_section)
192
193 ! Calculate KS matrix
194 CALL qs_ks_update_qs_env(qs_env, just_energy=.false., calculate_forces=.false.)
195
196 ! print 'heavy weight' or relatively expensive quantities
197 CALL qs_scf_loop_print(qs_env, scf_env, para_env)
198
199 ! Diagonalization
200 IF (do_kpoints) THEN
201 ! kpoints
202 CALL qs_scf_new_mos_kp(qs_env, scf_env, scf_control, diis_step)
203 ELSE
204 ! Gamma points only
205 CALL qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, .false.)
206 END IF
207
208 ! Print requested MO information (can be computationally expensive with OT)
209 CALL qs_scf_write_mos(qs_env, scf_env, final_mos=.true.)
210
211 ! copy density matrix
212 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
213 DO ispin = 1, dft_control%nspins
214 DO img = 1, SIZE(rho_ao_kp, 2)
215 CALL dbcsr_copy(rho_ao_kp(ispin, img)%matrix, scf_env%p_mix_new(ispin, img)%matrix)
216 END DO
217 END DO
218
219 CALL qs_ks_did_change(ks_env, rho_changed=.true., potential_changed=.true.)
220
221 ! band energy : Tr(PH)
222 CALL get_qs_env(qs_env, matrix_ks_kp=matrixkp_ks)
223 CALL calculate_ptrace(matrixkp_ks, rho_ao_kp, energy%band, dft_control%nspins, .true.)
224 ! core energy : Tr(Ph)
225 energy%total = energy%total - energy%core
226 CALL get_qs_env(qs_env, matrix_h_kp=matrix_h)
227 CALL calculate_ptrace(matrix_h, rho_ao_kp, energy%core, dft_control%nspins)
228
229 IF (qs_env%qmmm) THEN
230 ! Compute QM/MM Energy
231 cpassert(SIZE(matrixkp_ks, 2) == 1)
232 DO ispin = 1, dft_control%nspins
233 CALL dbcsr_dot(qs_env%ks_qmmm_env%matrix_h(1)%matrix, &
234 matrixkp_ks(ispin, 1)%matrix, qmmm_el)
235 energy%qmmm_el = energy%qmmm_el + qmmm_el
236 END DO
237 pc_ener = qs_env%ks_qmmm_env%pc_ener
238 energy%qmmm_el = energy%qmmm_el + pc_ener
239 ELSE
240 energy%qmmm_el = 0.0_dp
241 END IF
242
243 t2 = m_walltime()
244 tdiag = t2 - t1
245
246 CALL qs_nonscf_print_summary(qs_env, tdiag, scf_env%nelectron, iounit)
247
248 CALL timestop(handle)
249
250 END SUBROUTINE do_nonscf
251
252END MODULE qs_nonscf
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
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
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public hfit_relative_entropy
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
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Types and basic routines needed for a kpoint calculation.
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:141
Interface to the message passing library MPI.
Calculation of the energies concerning the core charge distribution.
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.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, rhoz_cneo_set, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Set the QUICKSTEP environment.
Harris method calculations.
subroutine, public harris_relative_entropy_reconstruction(qs_env)
Builds H[n_cube] once and reconstructs the AO density matrix by minimizing a density residual regular...
subroutine, public harris_direct_density_matrix_energy(qs_env)
Evaluates the fitted AO density matrix without solving a NONSCF eigenproblem.
Types needed for a for a Harris model calculation.
Harris method environment setup and handling.
subroutine, public harris_density_update(qs_env, harris_env)
...
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)
subroutine, public qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, potential_changed, full_reset)
tells that some of the things relevant to the ks calculation did change. has to be called when change...
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
Routines for Quickstep NON-SCF run.
subroutine, public qs_nonscf_print_summary(qs_env, tdiag, nelectron_total, iounit)
writes a summary of information after diagonalization
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
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_update_rho(rho_struct, qs_env, rho_xc_external, local_rho_set, task_list_external, task_list_external_soft, pw_env_external, para_env_external)
updates rho_r and rho_g to the rhorho_ao. if use_kinetic_energy_density also computes tau_r and tau_g...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
Utility routines for qs_scf.
subroutine, public qs_scf_env_initialize(qs_env, scf_env, scf_control, scf_section)
initializes input parameters if needed or restores values from previous runs to fill scf_env with the...
Utility routines for qs_scf.
subroutine, public qs_scf_new_mos_kp(qs_env, scf_env, scf_control, diis_step, probe, ot_kp_subspace_refresh, allow_ot_kp_subspace_refresh, allow_ot_kp_exit_refresh, accepted_ot_kp_searches, added_mos_auto_grow, energy_only)
Updates MOs and density matrix using diagonalization Kpoint code.
subroutine, public qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only, probe)
takes known energy and derivatives and produces new wfns and or density matrix
subroutine, public qs_scf_loop_print(qs_env, scf_env, para_env)
collects the 'heavy duty' printing tasks out of the SCF loop
subroutine, public qs_scf_write_mos(qs_env, scf_env, final_mos)
Write the MO eigenvector, eigenvalues, and occupation numbers to the output unit.
Utility routines for qs_scf.
subroutine, public qs_scf_compute_properties(qs_env, wf_type, do_mp2)
computes properties for a given hamilonian using the current wfn
module that contains the definitions of the scf types
Routines for the Quickstep SCF run.
Definition qs_scf.F:47
subroutine, public init_scf_loop(scf_env, qs_env, scf_section, kp_ot_entry_reason)
inits those objects needed if you want to restart the scf with, say only a new initial guess,...
Definition qs_scf.F:1242
Storage of past states of the qs_env. Methods to interpolate (or actually normally extrapolate) the n...
subroutine, public wfi_update(wf_history, qs_env, dt)
updates the snapshot buffer, taking a new snapshot
parameters that control an scf iteration
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Contains information on the Harris method.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.