(git:33f85d8)
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-2025 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
25 USE kinds, ONLY: dp
26 USE kpoint_types, ONLY: kpoint_type
27 USE machine, ONLY: m_walltime
35 USE qs_ks_types, ONLY: qs_ks_did_change,&
37 USE qs_mo_types, ONLY: mo_set_type
39 USE qs_rho_types, ONLY: qs_rho_get,&
41 USE qs_scf, ONLY: init_scf_loop
51#include "./base/base_uses.f90"
52
53 IMPLICIT NONE
54
55 PRIVATE
56
57 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_nonscf'
58
59 PUBLIC :: nonscf
60
61CONTAINS
62
63! **************************************************************************************************
64!> \brief Find solution to HC=SCE
65!> \param qs_env the qs_environment where to perform the scf procedure
66!> \par History
67!> none
68!> \author JGH
69!> \note
70! **************************************************************************************************
71 SUBROUTINE nonscf(qs_env)
72 TYPE(qs_environment_type), POINTER :: qs_env
73
74 TYPE(dft_control_type), POINTER :: dft_control
75 TYPE(qs_scf_env_type), POINTER :: scf_env
76 TYPE(scf_control_type), POINTER :: scf_control
77
78 CALL get_qs_env(qs_env, dft_control=dft_control)
79
80 IF (dft_control%qs_control%do_ls_scf) THEN
81 ! Density matrix based solver
82
83 CALL ls_scf(qs_env, nonscf=.true.)
84
85 ELSE
86 ! Wavefunction based solver
87
88 CALL get_qs_env(qs_env, scf_env=scf_env, scf_control=scf_control)
89 IF (.NOT. ASSOCIATED(scf_env)) THEN
90 CALL qs_scf_env_initialize(qs_env, scf_env)
91 CALL set_qs_env(qs_env, scf_env=scf_env)
92 ELSE
93 CALL qs_scf_env_initialize(qs_env, scf_env)
94 END IF
95
96 CALL do_nonscf(qs_env, scf_env, scf_control)
97
98 ! add the converged wavefunction to the wavefunction history
99 IF (ASSOCIATED(qs_env%wf_history)) THEN
100 CALL wfi_update(qs_env%wf_history, qs_env=qs_env, dt=1.0_dp)
101 END IF
102
103 ! compute properties that depend on the wavefunction
104 CALL qs_scf_compute_properties(qs_env)
105
106 END IF
107
108 END SUBROUTINE nonscf
109
110! **************************************************************************************************
111!> \brief Solve KS equation for fixed potential
112!> \param qs_env ...
113!> \param scf_env the scf_env where to perform the scf procedure
114!> \param scf_control ...
115!> \par History
116!> none
117!> \author JGH
118!> \note
119! **************************************************************************************************
120 SUBROUTINE do_nonscf(qs_env, scf_env, scf_control)
121
122 TYPE(qs_environment_type), POINTER :: qs_env
123 TYPE(qs_scf_env_type), POINTER :: scf_env
124 TYPE(scf_control_type), POINTER :: scf_control
125
126 CHARACTER(LEN=*), PARAMETER :: routinen = 'do_nonscf'
127
128 INTEGER :: handle, img, iounit, ispin
129 LOGICAL :: diis_step, do_kpoints
130 REAL(kind=dp) :: pc_ener, qmmm_el, t1, t2, tdiag
131 TYPE(cp_logger_type), POINTER :: logger
132 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrixkp_ks, rho_ao_kp
133 TYPE(dft_control_type), POINTER :: dft_control
134 TYPE(kpoint_type), POINTER :: kpoints
135 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
136 TYPE(mp_para_env_type), POINTER :: para_env
137 TYPE(qs_energy_type), POINTER :: energy
138 TYPE(qs_ks_env_type), POINTER :: ks_env
139 TYPE(qs_rho_type), POINTER :: rho
140 TYPE(section_vals_type), POINTER :: dft_section, input, scf_section
141
142 CALL timeset(routinen, handle)
143
144 t1 = m_walltime()
145
146 logger => cp_get_default_logger()
147 iounit = cp_logger_get_default_io_unit(logger)
148
149 CALL get_qs_env(qs_env=qs_env, &
150 energy=energy, &
151 ks_env=ks_env, &
152 rho=rho, &
153 mos=mos, &
154 input=input, &
155 dft_control=dft_control, &
156 do_kpoints=do_kpoints, &
157 kpoints=kpoints, &
158 para_env=para_env)
159
160 DO ispin = 1, dft_control%nspins
161 cpassert(.NOT. mos(ispin)%use_mo_coeff_b)
162 END DO
163
164 dft_section => section_vals_get_subs_vals(input, "DFT")
165 scf_section => section_vals_get_subs_vals(dft_section, "SCF")
166 CALL init_scf_loop(scf_env=scf_env, qs_env=qs_env, scf_section=scf_section)
167
168 ! Calculate KS matrix
169 CALL qs_ks_update_qs_env(qs_env, just_energy=.false., calculate_forces=.false.)
170
171 ! print 'heavy weight' or relatively expensive quantities
172 CALL qs_scf_loop_print(qs_env, scf_env, para_env)
173
174 ! Diagonalization
175 IF (do_kpoints) THEN
176 ! kpoints
177 CALL qs_scf_new_mos_kp(qs_env, scf_env, scf_control, diis_step)
178 ELSE
179 ! Gamma points only
180 CALL qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, .false.)
181 END IF
182
183 ! Print requested MO information (can be computationally expensive with OT)
184 CALL qs_scf_write_mos(qs_env, scf_env, final_mos=.true.)
185
186 ! copy density matrix
187 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
188 DO ispin = 1, dft_control%nspins
189 DO img = 1, SIZE(rho_ao_kp, 2)
190 CALL dbcsr_copy(rho_ao_kp(ispin, img)%matrix, scf_env%p_mix_new(ispin, img)%matrix)
191 END DO
192 END DO
193
194 CALL qs_ks_did_change(ks_env, rho_changed=.true., potential_changed=.true.)
195
196 ! band energy : Tr(PH)
197 CALL get_qs_env(qs_env, matrix_ks_kp=matrixkp_ks)
198 CALL calculate_ptrace(matrixkp_ks, rho_ao_kp, energy%band, dft_control%nspins)
199 ! core energy : Tr(Ph)
200 energy%total = energy%total - energy%core
201 CALL get_qs_env(qs_env, matrix_h_kp=matrix_h)
202 CALL calculate_ptrace(matrix_h, rho_ao_kp, energy%core, dft_control%nspins)
203
204 IF (qs_env%qmmm) THEN
205 ! Compute QM/MM Energy
206 cpassert(SIZE(matrixkp_ks, 2) == 1)
207 DO ispin = 1, dft_control%nspins
208 CALL dbcsr_dot(qs_env%ks_qmmm_env%matrix_h(1)%matrix, &
209 matrixkp_ks(ispin, 1)%matrix, qmmm_el)
210 energy%qmmm_el = energy%qmmm_el + qmmm_el
211 END DO
212 pc_ener = qs_env%ks_qmmm_env%pc_ener
213 energy%qmmm_el = energy%qmmm_el + pc_ener
214 ELSE
215 energy%qmmm_el = 0.0_dp
216 END IF
217
218 t2 = m_walltime()
219 tdiag = t2 - t1
220
221 CALL qs_nonscf_print_summary(qs_env, tdiag, scf_env%nelectron, iounit)
222
223 CALL timestop(handle)
224
225 END SUBROUTINE do_nonscf
226
227END 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
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:147
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, 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, 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, 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, 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, ecoul_1c, rho0_s_rs, rho0_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)
Get the QUICKSTEP environment.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, 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, 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)
Set the QUICKSTEP environment.
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:72
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(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only)
takes known energy and derivatives and produces new wfns and or density matrix
subroutine, public qs_scf_new_mos_kp(qs_env, scf_env, scf_control, diis_step)
Updates MOs and density matrix using diagonalization Kpoint code.
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)
inits those objects needed if you want to restart the scf with, say only a new initial guess,...
Definition qs_scf.F:650
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
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.