(git:b195825)
qs_energy_matrix_w.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 Utility subroutine for qs energy calculation
10 !> \par History
11 !> none
12 !> \author MK (29.10.2002)
13 ! *****************************************************************************
15  USE cp_control_types, ONLY: dft_control_type
18  cp_fm_struct_type
19  USE cp_fm_types, ONLY: cp_fm_create,&
20  cp_fm_release,&
21  cp_fm_type
22  USE dbcsr_api, ONLY: dbcsr_p_type,&
23  dbcsr_set
24  USE kinds, ONLY: dp
27  USE kpoint_types, ONLY: kpoint_type
28  USE qs_density_matrices, ONLY: calculate_w_matrix,&
30  USE qs_environment_types, ONLY: get_qs_env,&
31  qs_environment_type
32  USE qs_mo_types, ONLY: get_mo_set,&
33  mo_set_type
34  USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
35  USE qs_rho_types, ONLY: qs_rho_get,&
36  qs_rho_type
37  USE scf_control_types, ONLY: scf_control_type
38 #include "./base/base_uses.f90"
39 
40  IMPLICIT NONE
41 
42  PRIVATE
43 
44 ! *** Global parameters ***
45 
46  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_energy_matrix_w'
47 
48  PUBLIC :: qs_energies_compute_w
49 
50 CONTAINS
51 
52 ! *****************************************************************************
53 !> \brief Refactoring of qs_energies_scf. Moves computation of matrix_w
54 !> into separate subroutine
55 !> \param qs_env ...
56 !> \param calc_forces ...
57 !> \par History
58 !> 05.2013 created [Florian Schiffmann]
59 ! **************************************************************************************************
60 
61  SUBROUTINE qs_energies_compute_w(qs_env, calc_forces)
62  TYPE(qs_environment_type), POINTER :: qs_env
63  LOGICAL, INTENT(IN) :: calc_forces
64 
65  CHARACTER(len=*), PARAMETER :: routinen = 'qs_energies_compute_w'
66 
67  INTEGER :: handle, is, ispin, nao, nspin
68  LOGICAL :: do_kpoints, has_unit_metric
69  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s, matrix_w, &
70  mo_derivs, rho_ao
71  TYPE(dft_control_type), POINTER :: dft_control
72  TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
73  TYPE(mo_set_type), POINTER :: mo_set
74  TYPE(qs_rho_type), POINTER :: rho
75  TYPE(scf_control_type), POINTER :: scf_control
76 
77  CALL timeset(routinen, handle)
78 
79  ! if calculate forces, time to compute the w matrix
80  CALL get_qs_env(qs_env, has_unit_metric=has_unit_metric)
81 
82  IF (calc_forces .AND. .NOT. has_unit_metric) THEN
83  CALL get_qs_env(qs_env, do_kpoints=do_kpoints)
84 
85  IF (do_kpoints) THEN
86  block
87  TYPE(cp_fm_struct_type), POINTER :: ao_ao_fmstruct
88  TYPE(cp_fm_type), POINTER :: mo_coeff
89  TYPE(cp_fm_type), DIMENSION(2) :: fmwork
90  TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s_kp, matrix_w_kp
91  TYPE(kpoint_type), POINTER :: kpoints
92  TYPE(neighbor_list_set_p_type), DIMENSION(:), &
93  POINTER :: sab_nl
94 
95  CALL get_qs_env(qs_env, &
96  matrix_w_kp=matrix_w_kp, &
97  matrix_s_kp=matrix_s_kp, &
98  sab_orb=sab_nl, &
99  mos=mos, &
100  kpoints=kpoints)
101 
102  CALL get_mo_set(mos(1), mo_coeff=mo_coeff, nao=nao)
103  CALL cp_fm_struct_create(fmstruct=ao_ao_fmstruct, nrow_global=nao, ncol_global=nao, &
104  template_fmstruct=mo_coeff%matrix_struct)
105 
106  DO is = 1, SIZE(fmwork)
107  CALL cp_fm_create(fmwork(is), matrix_struct=ao_ao_fmstruct)
108  END DO
109  CALL cp_fm_struct_release(ao_ao_fmstruct)
110 
111  ! energy weighted density matrices in k-space
112  CALL kpoint_density_matrices(kpoints, energy_weighted=.true.)
113  ! energy weighted density matrices in real space
114  CALL kpoint_density_transform(kpoints, matrix_w_kp, .true., &
115  matrix_s_kp(1, 1)%matrix, sab_nl, fmwork)
116 
117  DO is = 1, SIZE(fmwork)
118  CALL cp_fm_release(fmwork(is))
119  END DO
120 
121  END block
122  ELSE
123 
124  NULLIFY (dft_control, rho_ao)
125  CALL get_qs_env(qs_env, &
126  matrix_w=matrix_w, &
127  matrix_ks=matrix_ks, &
128  matrix_s=matrix_s, &
129  mo_derivs=mo_derivs, &
130  scf_control=scf_control, &
131  mos=mos, &
132  rho=rho, &
133  dft_control=dft_control)
134 
135  CALL qs_rho_get(rho, rho_ao=rho_ao)
136 
137  nspin = SIZE(mos)
138  DO ispin = 1, nspin
139  mo_set => mos(ispin)
140  IF (dft_control%roks) THEN
141  IF (scf_control%use_ot) THEN
142  IF (ispin > 1) THEN
143  ! not very elegant, indeed ...
144  CALL dbcsr_set(matrix_w(ispin)%matrix, 0.0_dp)
145  ELSE
146  CALL calculate_w_matrix_ot(mo_set, mo_derivs(ispin)%matrix, &
147  matrix_w(ispin)%matrix, matrix_s(1)%matrix)
148  END IF
149  ELSE
150  CALL calculate_w_matrix(mo_set=mo_set, &
151  matrix_ks=matrix_ks(ispin)%matrix, &
152  matrix_p=rho_ao(ispin)%matrix, &
153  matrix_w=matrix_w(ispin)%matrix)
154  END IF
155  ELSE
156  IF (scf_control%use_ot) THEN
157  CALL calculate_w_matrix_ot(mo_set, mo_derivs(ispin)%matrix, &
158  matrix_w(ispin)%matrix, matrix_s(1)%matrix)
159  ELSE
160  CALL calculate_w_matrix(mo_set, matrix_w(ispin)%matrix)
161  END IF
162  END IF
163  END DO
164 
165  END IF
166 
167  END IF
168  CALL timestop(handle)
169 
170  END SUBROUTINE qs_energies_compute_w
171 
172 END MODULE qs_energy_matrix_w
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
represent the structure of a full matrix
Definition: cp_fm_struct.F:14
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
Definition: cp_fm_struct.F:125
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
Definition: cp_fm_struct.F:320
represent a full matrix distributed on many processors
Definition: cp_fm_types.F:15
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
Definition: cp_fm_types.F:167
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_density_transform(kpoint, denmat, wtype, tempmat, sab_nl, fmwork, for_aux_fit, pmat_ext)
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.
Definition: kpoint_types.F:15
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...
Utility subroutine for qs energy calculation.
subroutine, public qs_energies_compute_w(qs_env, calc_forces)
Refactoring of qs_energies_scf. Moves computation of matrix_w into separate subroutine.
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
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...
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
parameters that control an scf iteration