(git:744416f)
Loading...
Searching...
No Matches
qs_matrix_w.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 Utility subroutine for qs energy calculation
10!> \par History
11!> none
12!> \author MK (29.10.2002)
13! **************************************************************************************************
16 USE cp_dbcsr_api, ONLY: dbcsr_p_type,&
21 USE cp_fm_types, ONLY: cp_fm_create,&
24 USE kinds, ONLY: dp
28 USE kpoint_types, ONLY: kpoint_type
33 USE qs_mo_types, ONLY: get_mo_set,&
36 USE qs_rho_types, ONLY: qs_rho_get,&
39#include "./base/base_uses.f90"
40
41 IMPLICIT NONE
42
43 PRIVATE
44
45! *** Global parameters ***
46
47 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_matrix_w'
48
49 PUBLIC :: compute_matrix_w
50
51CONTAINS
52
53! **************************************************************************************************
54!> \brief Refactoring of qs_energies_scf. Moves computation of matrix_w
55!> into separate subroutine
56!> \param qs_env ...
57!> \param calc_forces ...
58!> \par History
59!> 05.2013 created [Florian Schiffmann]
60! **************************************************************************************************
61
62 SUBROUTINE compute_matrix_w(qs_env, calc_forces)
63 TYPE(qs_environment_type), POINTER :: qs_env
64 LOGICAL, INTENT(IN) :: calc_forces
65
66 CHARACTER(len=*), PARAMETER :: routinen = 'compute_matrix_w'
67
68 INTEGER :: handle, is, ispin, nao, nspin
69 LOGICAL :: do_kpoints, has_unit_metric
70 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s, matrix_w, &
71 mo_derivs, rho_ao
72 TYPE(dft_control_type), POINTER :: dft_control
73 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
74 TYPE(mo_set_type), POINTER :: mo_set
75 TYPE(qs_rho_type), POINTER :: rho
76 TYPE(scf_control_type), POINTER :: scf_control
77
78 CALL timeset(routinen, handle)
79
80 ! if calculate forces, time to compute the w matrix
81 CALL get_qs_env(qs_env, has_unit_metric=has_unit_metric)
82
83 IF (calc_forces .AND. .NOT. has_unit_metric) THEN
84 CALL get_qs_env(qs_env, do_kpoints=do_kpoints)
85
86 IF (do_kpoints) THEN
87 block
88 TYPE(cp_fm_type), DIMENSION(2) :: fmwork
89 TYPE(cp_fm_struct_type), POINTER :: ao_ao_fmstruct
90 TYPE(cp_fm_type), POINTER :: mo_coeff
91 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks_kp, matrix_s_kp, &
92 matrix_w_kp
93 TYPE(kpoint_type), POINTER :: kpoints
94 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
95 POINTER :: sab_nl
96
97 CALL get_qs_env(qs_env, &
98 matrix_w_kp=matrix_w_kp, &
99 matrix_ks_kp=matrix_ks_kp, &
100 matrix_s_kp=matrix_s_kp, &
101 sab_orb=sab_nl, &
102 mos=mos, &
103 kpoints=kpoints, &
104 scf_control=scf_control)
105
106 CALL get_mo_set(mos(1), mo_coeff=mo_coeff, nao=nao)
107 CALL cp_fm_struct_create(fmstruct=ao_ao_fmstruct, nrow_global=nao, ncol_global=nao, &
108 template_fmstruct=mo_coeff%matrix_struct)
109
110 DO is = 1, SIZE(fmwork)
111 CALL cp_fm_create(fmwork(is), matrix_struct=ao_ao_fmstruct)
112 END DO
113 CALL cp_fm_struct_release(ao_ao_fmstruct)
114
115 ! energy weighted density matrices in k-space
116 IF (scf_control%use_ot) THEN
117 CALL kpoint_ot_energy_weighted_matrices(kpoints, matrix_ks_kp)
118 ELSE
119 CALL kpoint_density_matrices(kpoints, energy_weighted=.true.)
120 END IF
121 ! energy weighted density matrices in real space
122 CALL kpoint_density_transform(kpoints, matrix_w_kp, .true., &
123 matrix_s_kp(1, 1)%matrix, sab_nl, fmwork)
124
125 DO is = 1, SIZE(fmwork)
126 CALL cp_fm_release(fmwork(is))
127 END DO
128
129 END block
130 ELSE
131
132 NULLIFY (dft_control, rho_ao)
133 CALL get_qs_env(qs_env, &
134 matrix_w=matrix_w, &
135 matrix_ks=matrix_ks, &
136 matrix_s=matrix_s, &
137 mo_derivs=mo_derivs, &
138 scf_control=scf_control, &
139 mos=mos, &
140 rho=rho, &
141 dft_control=dft_control)
142
143 CALL qs_rho_get(rho, rho_ao=rho_ao)
144
145 nspin = SIZE(mos)
146 DO ispin = 1, nspin
147 mo_set => mos(ispin)
148 IF (dft_control%roks) THEN
149 IF (scf_control%use_ot) THEN
150 IF (ispin > 1) THEN
151 ! not very elegant, indeed ...
152 CALL dbcsr_set(matrix_w(ispin)%matrix, 0.0_dp)
153 ELSE
154 CALL calculate_w_matrix_ot(mo_set, mo_derivs(ispin)%matrix, &
155 matrix_w(ispin)%matrix, matrix_s(1)%matrix)
156 END IF
157 ELSE
158 CALL calculate_w_matrix(mo_set=mo_set, &
159 matrix_ks=matrix_ks(ispin)%matrix, &
160 matrix_p=rho_ao(ispin)%matrix, &
161 matrix_w=matrix_w(ispin)%matrix)
162 END IF
163 ELSE
164 IF (scf_control%use_ot) THEN
165 CALL calculate_w_matrix_ot(mo_set, mo_derivs(ispin)%matrix, &
166 matrix_w(ispin)%matrix, matrix_s(1)%matrix)
167 ELSE
168 CALL calculate_w_matrix(mo_set, matrix_w(ispin)%matrix)
169 END IF
170 END IF
171 END DO
172
173 END IF
174
175 END IF
176
177 CALL timestop(handle)
178
179 END SUBROUTINE compute_matrix_w
180
181END MODULE qs_matrix_w
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_set(matrix, alpha)
...
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Routines needed for kpoint calculation.
subroutine, public kpoint_ot_energy_weighted_matrices(kpoint, matrix_ks)
Build energy-weighted density matrices for complex K-point OT. H(k) is transformed only while W(k) is...
subroutine, public kpoint_density_transform(kpoint, denmat, wtype, tempmat, sab_nl, fmwork, for_aux_fit, pmat_ext, overlap_rs)
generate real space density matrices in DBCSR format
subroutine, public kpoint_density_matrices(kpoint, energy_weighted, for_aux_fit)
Calculate kpoint density matrices (rho(k), owned by kpoint groups).
Types and basic routines needed for a kpoint calculation.
collects routines that calculate density matrices
subroutine, public calculate_w_matrix_ot(mo_set, mo_deriv, w_matrix, s_matrix)
Calculate the W matrix from the MO coefs, MO derivs could overwrite the mo_derivs for increased memor...
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.
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
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.
Define the neighbor list data types and the corresponding functionality.
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...
parameters that control an scf iteration
keeps the information about the structure of a full matrix
represent a full matrix
Contains information about kpoints.
keeps the density in various representations, keeping track of which ones are valid.