(git:97501a3)
Loading...
Searching...
No Matches
tblite_ks_matrix.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 tblite matrix build
10!> \author JVP
11!> \history creation 09.2024
12! **************************************************************************************************
13
15
17 USE cp_dbcsr_api, ONLY: dbcsr_add,&
23 USE kinds, ONLY: dp
29 USE qs_mo_types, ONLY: get_mo_set,&
31 USE qs_rho_types, ONLY: qs_rho_get,&
37#include "./base/base_uses.f90"
38
39 IMPLICIT NONE
40
41 PRIVATE
42
43 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tblite_ks_matrix'
44
46
47CONTAINS
48
49! **************************************************************************************************
50!> \brief ...
51!> \param qs_env ...
52!> \param calculate_forces ...
53!> \param just_energy ...
54!> \param ext_ks_matrix ...
55! **************************************************************************************************
56 SUBROUTINE build_tblite_ks_matrix(qs_env, calculate_forces, just_energy, ext_ks_matrix)
57 TYPE(qs_environment_type), POINTER :: qs_env
58 LOGICAL, INTENT(in) :: calculate_forces, just_energy
59 TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
60 POINTER :: ext_ks_matrix
61
62 CHARACTER(len=*), PARAMETER :: routinen = 'build_tblite_ks_matrix'
63
64 INTEGER :: handle, img, ispin, nimg, ns, nspins
65 LOGICAL :: do_efield
66 REAL(kind=dp) :: pc_ener, qmmm_el
67 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_p1, mo_derivs
68 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix, matrix_h
69 TYPE(dbcsr_type), POINTER :: mo_coeff
70 TYPE(dft_control_type), POINTER :: dft_control
71 TYPE(mp_para_env_type), POINTER :: para_env
72 TYPE(qs_energy_type), POINTER :: energy
73 TYPE(qs_ks_env_type), POINTER :: ks_env
74 TYPE(qs_rho_type), POINTER :: rho
75
76 CALL timeset(routinen, handle)
77
78 NULLIFY (dft_control, ks_env, ks_matrix, rho, energy)
79 cpassert(ASSOCIATED(qs_env))
80
81 CALL get_qs_env(qs_env, &
82 dft_control=dft_control, &
83 matrix_h_kp=matrix_h, &
84 para_env=para_env, &
85 ks_env=ks_env, &
86 matrix_ks_kp=ks_matrix, &
87 rho=rho, &
88 energy=energy)
89
90 IF (PRESENT(ext_ks_matrix)) THEN
91 ! remap pointer to allow for non-kpoint external ks matrix
92 ! ext_ks_matrix is used in linear response code
93 ns = SIZE(ext_ks_matrix)
94 ks_matrix(1:ns, 1:1) => ext_ks_matrix(1:ns)
95 END IF
96
97 energy%qmmm_el = 0.0_dp
98
99 nspins = dft_control%nspins
100 nimg = dft_control%nimages
101 cpassert(ASSOCIATED(matrix_h))
102 cpassert(ASSOCIATED(rho))
103 cpassert(SIZE(ks_matrix) > 0)
104
105 DO ispin = 1, nspins
106 DO img = 1, nimg
107 ! copy the core matrix into the fock matrix
108 CALL dbcsr_copy(ks_matrix(ispin, img)%matrix, matrix_h(1, img)%matrix)
109 END DO
110 END DO
111
112 IF (dft_control%apply_period_efield .OR. dft_control%apply_efield .OR. &
113 dft_control%apply_efield_field) THEN
114 do_efield = .true.
115 cpabort("Not implemented yet. Use CP2K routines for GFN1")
116 ELSE
117 do_efield = .false.
118 END IF
119
120 CALL tb_update_charges(qs_env, dft_control, qs_env%tb_tblite, calculate_forces, .true.)
121
122 CALL tb_ham_add_coulomb(qs_env, qs_env%tb_tblite, dft_control)
123
124 IF (qs_env%qmmm) THEN
125 cpassert(SIZE(ks_matrix, 2) == 1)
126 DO ispin = 1, nspins
127 ! If QM/MM sumup the 1el Hamiltonian
128 CALL dbcsr_add(ks_matrix(ispin, 1)%matrix, qs_env%ks_qmmm_env%matrix_h(1)%matrix, &
129 1.0_dp, 1.0_dp)
130 CALL qs_rho_get(rho, rho_ao=matrix_p1)
131 ! Compute QM/MM Energy
132 CALL dbcsr_dot(qs_env%ks_qmmm_env%matrix_h(1)%matrix, &
133 matrix_p1(ispin)%matrix, qmmm_el)
134 energy%qmmm_el = energy%qmmm_el + qmmm_el
135 END DO
136 pc_ener = qs_env%ks_qmmm_env%pc_ener
137 energy%qmmm_el = energy%qmmm_el + pc_ener
138 END IF
139
140 IF (calculate_forces) THEN
141 CALL tb_derive_dh_diag(qs_env, .true., nimg)
142 CALL tb_derive_dh_off(qs_env, .true., nimg)
143 END IF
144
145 ! here we compute dE/dC if needed. Assumes dE/dC is H_{ks}C
146 IF (qs_env%requires_mo_derivs .AND. .NOT. just_energy) THEN
147 cpassert(SIZE(ks_matrix, 2) == 1)
148 block
149 TYPE(mo_set_type), DIMENSION(:), POINTER :: mo_array
150 CALL get_qs_env(qs_env, mo_derivs=mo_derivs, mos=mo_array)
151 DO ispin = 1, SIZE(mo_derivs)
152 CALL get_mo_set(mo_set=mo_array(ispin), mo_coeff_b=mo_coeff)
153 IF (.NOT. mo_array(ispin)%use_mo_coeff_b) THEN
154 cpabort("")
155 END IF
156 CALL dbcsr_multiply('n', 'n', 1.0_dp, ks_matrix(ispin, 1)%matrix, mo_coeff, &
157 0.0_dp, mo_derivs(ispin)%matrix)
158 END DO
159 END block
160 END IF
161
162 CALL timestop(handle)
163
164 END SUBROUTINE build_tblite_ks_matrix
165
166END MODULE tblite_ks_matrix
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_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
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.
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
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, do_rixs, tb_tblite)
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.
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...
interface to tblite
subroutine, public tb_ham_add_coulomb(qs_env, tb, dft_control)
...
subroutine, public tb_derive_dh_diag(qs_env, use_rho, nimg)
compute the derivative of the energy
subroutine, public tb_update_charges(qs_env, dft_control, tb, calculate_forces, use_rho)
...
subroutine, public tb_derive_dh_off(qs_env, use_rho, nimg)
compute the derivative of the energy
tblite matrix build
subroutine, public build_tblite_ks_matrix(qs_env, calculate_forces, just_energy, ext_ks_matrix)
...
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.