(git:34ef472)
se_fock_matrix.F
Go to the documentation of this file.
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 Calculation of the Fock matrix for SE methods
10 !> \author JGH and TLAINO
11 !> \par History
12 !> Teodoro Laino (04.2008) [tlaino] - University of Zurich : d-orbitals
13 !> Teodoro Laino (09.2008) [tlaino] - University of Zurich : Speed-up
14 !> Teodoro Laino (09.2008) [tlaino] - University of Zurich : Periodic SE
15 !> Teodoro Laino (05.2009) [tlaino] - Split and module reorganization
16 ! **************************************************************************************************
18  USE atomic_kind_types, ONLY: atomic_kind_type
19  USE atprop_types, ONLY: atprop_array_init,&
20  atprop_type
21  USE cp_control_types, ONLY: dft_control_type,&
22  semi_empirical_control_type
24  cp_logger_type
27  USE dbcsr_api, ONLY: dbcsr_add,&
28  dbcsr_copy,&
29  dbcsr_dot,&
30  dbcsr_get_info,&
31  dbcsr_multiply,&
32  dbcsr_p_type,&
33  dbcsr_type
34  USE input_constants, ONLY: &
38  section_vals_type
39  USE kinds, ONLY: dp
40  USE message_passing, ONLY: mp_para_env_type
41  USE particle_types, ONLY: particle_type
42  USE qs_energy_types, ONLY: qs_energy_type
43  USE qs_environment_types, ONLY: get_qs_env,&
44  qs_environment_type
45  USE qs_ks_types, ONLY: qs_ks_env_type
46  USE qs_mo_types, ONLY: get_mo_set,&
47  mo_set_type
48  USE qs_rho_types, ONLY: qs_rho_get,&
49  qs_rho_type
57  semi_empirical_si_type
58 #include "./base/base_uses.f90"
59 
60  IMPLICIT NONE
61  PRIVATE
62 
63  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'se_fock_matrix'
64  LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .false.
65  LOGICAL, PARAMETER, PRIVATE :: debug_energy_coulomb_lr = .false.
66 
67  PUBLIC :: build_se_fock_matrix
68 
69 CONTAINS
70 
71 ! **************************************************************************************************
72 !> \brief Construction of the Fock matrix for NDDO methods
73 !> \param qs_env ...
74 !> \param calculate_forces ...
75 !> \param just_energy ...
76 !> \par History
77 !> - Teodoro Laino [tlaino] (05.2009) - Split and module reorganization
78 !> \author JGH
79 ! **************************************************************************************************
80  SUBROUTINE build_se_fock_matrix(qs_env, calculate_forces, just_energy)
81  TYPE(qs_environment_type), POINTER :: qs_env
82  LOGICAL, INTENT(in) :: calculate_forces, just_energy
83 
84  CHARACTER(len=*), PARAMETER :: routinen = 'build_se_fock_matrix'
85 
86  INTEGER :: handle, ispin, natom, ncol_global, &
87  nspins, output_unit
88  LOGICAL :: s_mstruct_changed
89  REAL(kind=dp) :: ecoul, qmmm_el
90  REAL(kind=dp), DIMENSION(:), POINTER :: occupation_numbers
91  TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
92  TYPE(atprop_type), POINTER :: atprop
93  TYPE(cp_logger_type), POINTER :: logger
94  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_matrix, matrix_h, matrix_p, mo_derivs
95  TYPE(dbcsr_type), POINTER :: mo_coeff
96  TYPE(dft_control_type), POINTER :: dft_control
97  TYPE(mo_set_type), DIMENSION(:), POINTER :: mo_array
98  TYPE(mp_para_env_type), POINTER :: para_env
99  TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
100  TYPE(qs_energy_type), POINTER :: energy
101  TYPE(qs_ks_env_type), POINTER :: ks_env
102  TYPE(qs_rho_type), POINTER :: rho
103  TYPE(section_vals_type), POINTER :: scf_section
104  TYPE(semi_empirical_control_type), POINTER :: se_control
105  TYPE(semi_empirical_si_type), POINTER :: store_int_env
106 
107  CALL timeset(routinen, handle)
108  NULLIFY (matrix_h, dft_control, logger, scf_section, store_int_env, se_control)
109  NULLIFY (atomic_kind_set, atprop)
110  NULLIFY (ks_env, ks_matrix, rho, energy)
111  logger => cp_get_default_logger()
112  cpassert(ASSOCIATED(qs_env))
113 
114  CALL get_qs_env(qs_env, &
115  dft_control=dft_control, &
116  matrix_h=matrix_h, &
117  para_env=para_env, &
118  se_store_int_env=store_int_env, &
119  atprop=atprop, &
120  atomic_kind_set=atomic_kind_set, &
121  s_mstruct_changed=s_mstruct_changed, &
122  ks_env=ks_env, &
123  matrix_ks=ks_matrix, &
124  rho=rho, &
125  energy=energy)
126 
127  SELECT CASE (dft_control%qs_control%method_id)
128  CASE DEFAULT
129  ! Abort if the parameterization is an unknown one..
130  cpabort("Fock Matrix not available for the chosen parameterization! ")
131 
134 
135  ! Check for properly allocation of Matrixes
136  nspins = dft_control%nspins
137  cpassert(((nspins >= 1) .AND. (nspins <= 2)))
138  cpassert(ASSOCIATED(matrix_h))
139  cpassert(ASSOCIATED(rho))
140  cpassert(SIZE(ks_matrix) > 0)
141 
142  se_control => dft_control%qs_control%se_control
143  scf_section => section_vals_get_subs_vals(qs_env%input, "DFT%SCF")
144  CALL qs_rho_get(rho, rho_ao=matrix_p)
145 
146  energy%qmmm_el = 0.0_dp
147  energy%total = 0.0_dp
148 
149  DO ispin = 1, nspins
150  ! Copy the core matrix into the fock matrix
151  CALL dbcsr_copy(ks_matrix(ispin)%matrix, matrix_h(1)%matrix)
152  END DO
153 
154 ! WRITE ( *, * ) 'KS_ENV%s_mstruct_changed', ks_env%s_mstruct_changed
155  IF (atprop%energy) THEN
156  CALL get_qs_env(qs_env=qs_env, particle_set=particle_set)
157  natom = SIZE(particle_set)
158  CALL atprop_array_init(atprop%atecoul, natom)
159  END IF
160 
161  ! Compute Exchange and Coulomb terms
162  CALL semi_empirical_si_initialize(store_int_env, s_mstruct_changed)
163  CALL build_fock_matrix_exchange(qs_env, ks_matrix, matrix_p, calculate_forces, &
164  store_int_env)
165  CALL build_fock_matrix_coulomb(qs_env, ks_matrix, matrix_p, energy, calculate_forces, &
166  store_int_env)
167 
168  ! Debug statements for Long-Range
169  IF (debug_energy_coulomb_lr .AND. se_control%do_ewald) THEN
170  CALL dbg_energy_coulomb_lr(energy, ks_matrix, nspins, qs_env, matrix_p, &
171  calculate_forces, store_int_env)
172  END IF
173 
174  ! Long Range Electrostatic
175  IF (se_control%do_ewald) THEN
176  ! Evaluate Coulomb Long-Range
177  CALL build_fock_matrix_coulomb_lr(qs_env, ks_matrix, matrix_p, energy, calculate_forces, &
178  store_int_env)
179 
180  ! Possibly handle the slowly convergent term 1/R^3
181  IF (se_control%do_ewald_r3) THEN
182  CALL build_fock_matrix_coul_lr_r3(qs_env, ks_matrix, matrix_p, energy, &
183  calculate_forces)
184  END IF
185  END IF
186  CALL semi_empirical_si_finalize(store_int_env, s_mstruct_changed)
187 
188  IF (atprop%energy) THEN
189  atprop%atecoul = 0.5_dp*atprop%atecoul
190  END IF
191 
192  ! Compute the Hartree energy
193  ! NOTE: If we are performing SCP-NDDO, ks_matrix contains coulomb piece from SCP.
194  DO ispin = 1, nspins
195  CALL dbcsr_dot(ks_matrix(ispin)%matrix, matrix_p(ispin)%matrix, ecoul)
196  energy%hartree = energy%hartree + ecoul
197  END DO
198 ! WRITE ( *, * ) 'AFTER Hartree', ecoul, energy%hartree
199 
200 ! CALL build_fock_matrix_ph(qs_env,ks_matrix)
201  ! QM/MM
202  IF (qs_env%qmmm) THEN
203  DO ispin = 1, nspins
204  ! If QM/MM sumup the 1el Hamiltonian
205  CALL dbcsr_add(ks_matrix(ispin)%matrix, qs_env%ks_qmmm_env%matrix_h(1)%matrix, &
206  1.0_dp, 1.0_dp)
207  ! Compute QM/MM Energy
208  CALL dbcsr_dot(qs_env%ks_qmmm_env%matrix_h(1)%matrix, &
209  matrix_p(ispin)%matrix, qmmm_el)
210  energy%qmmm_el = energy%qmmm_el + qmmm_el
211  END DO
212  END IF
213 
214 ! WRITE ( *, * ) ' before TOTAL', energy%total
215  ! Collect all the energy terms
216  energy%mulliken = 0.0_dp
217  energy%exc = 0.0_dp
218  energy%total = energy%total + energy%core + &
219  energy%core_overlap + &
220  0.5_dp*energy%hartree + &
221  energy%qmmm_el + &
222  energy%dispersion + &
223  energy%mulliken
224 ! WRITE ( *, * ) ' AFTER TOTAL', energy%total
225 
226  output_unit = cp_print_key_unit_nr(logger, scf_section, "PRINT%DETAILED_ENERGY", &
227  extension=".scfLog")
228 
229  IF (output_unit > 0) THEN
230  WRITE (unit=output_unit, fmt="(/,(T3,A,T60,F20.10))") &
231  "Core Hamiltonian energy: ", energy%core, &
232  "Two-electron integral energy: ", energy%hartree
233  IF (qs_env%qmmm) THEN
234  WRITE (unit=output_unit, fmt="(T3,A,T60,F20.10)") &
235  "QM/MM Electrostatic energy: ", energy%qmmm_el
236  END IF
237  END IF
238 
239  CALL cp_print_key_finished_output(output_unit, logger, scf_section, &
240  "PRINT%DETAILED_ENERGY")
241 
242  ! Here we compute dE/dC if needed. Assumes dE/dC is H_{ks}C (plus occupation numbers)
243  IF (qs_env%requires_mo_derivs .AND. .NOT. just_energy) THEN
244  CALL get_qs_env(qs_env, mo_derivs=mo_derivs, mos=mo_array)
245  DO ispin = 1, SIZE(mo_derivs)
246  CALL get_mo_set(mo_set=mo_array(ispin), &
247  mo_coeff_b=mo_coeff, occupation_numbers=occupation_numbers)
248  IF (.NOT. mo_array(ispin)%use_mo_coeff_b) THEN
249  cpabort("")
250  END IF
251  CALL dbcsr_get_info(mo_coeff, nfullcols_total=ncol_global)
252  CALL dbcsr_multiply('n', 'n', 1.0_dp, ks_matrix(ispin)%matrix, mo_coeff, &
253  0.0_dp, mo_derivs(ispin)%matrix)
254  END DO
255  END IF
256 
257  END SELECT
258 
259  CALL timestop(handle)
260 
261  END SUBROUTINE build_se_fock_matrix
262 
263 END MODULE se_fock_matrix
264 
Define the atomic kind types and their sub types.
Holds information on atomic properties.
Definition: atprop_types.F:14
subroutine, public atprop_array_init(atarray, natom)
...
Definition: atprop_types.F:98
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_method_pdg
integer, parameter, public do_method_pnnl
integer, parameter, public do_method_rm1
integer, parameter, public do_method_pm3
integer, parameter, public do_method_mndo
integer, parameter, public do_method_mndod
integer, parameter, public do_method_am1
integer, parameter, public do_method_pm6fm
integer, parameter, public do_method_pm6
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
Interface to the message passing library MPI.
Define the data structure for the particle information.
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_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, 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, rhs)
Get the QUICKSTEP environment.
Definition and initialisation of the mo data type.
Definition: qs_mo_types.F:22
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kTS, mu, flexible_electron_count)
Get the components of a MO set data structure.
Definition: qs_mo_types.F:397
superstucture that hold various representations of the density and keeps track of which ones are vali...
Definition: qs_rho_types.F:18
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...
Definition: qs_rho_types.F:229
Module that collects all Coulomb parts of the fock matrix construction.
subroutine, public build_fock_matrix_coulomb(qs_env, ks_matrix, matrix_p, energy, calculate_forces, store_int_env)
Construction of the Coulomb part of the Fock matrix.
subroutine, public build_fock_matrix_coul_lr_r3(qs_env, ks_matrix, matrix_p, energy, calculate_forces)
Construction of the residual part (1/R^3) of the Coulomb long-range term of the Fock matrix The 1/R^3...
subroutine, public build_fock_matrix_coulomb_lr(qs_env, ks_matrix, matrix_p, energy, calculate_forces, store_int_env)
Long-Range part for SE Coulomb interactions.
subroutine, public dbg_energy_coulomb_lr(energy, ks_matrix, nspins, qs_env, matrix_p, calculate_forces, store_int_env)
Debug routine for long-range energy (debug value of EWALD vs VALUE KS)
Construction of the Exchange part of the Fock Matrix.
subroutine, public build_fock_matrix_exchange(qs_env, ks_matrix, matrix_p, calculate_forces, store_int_env)
Construction of the Exchange part of the Fock matrix.
Calculation of the Fock matrix for SE methods.
subroutine, public build_se_fock_matrix(qs_env, calculate_forces, just_energy)
Construction of the Fock matrix for NDDO methods.
Type to store integrals for semi-empirical calculations.
subroutine, public semi_empirical_si_finalize(store_int_env, geometry_did_change)
Deallocate the semi-empirical store integrals type.
subroutine, public semi_empirical_si_initialize(store_int_env, geometry_did_change)
Deallocate the semi-empirical store integrals type.