(git:98357aa)
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-2026 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,&
36#include "./base/base_uses.f90"
37
38 IMPLICIT NONE
39
40 PRIVATE
41
42 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'tblite_ks_matrix'
43
45
46CONTAINS
47
48! **************************************************************************************************
49!> \brief ...
50!> \param qs_env ...
51!> \param calculate_forces ...
52!> \param just_energy ...
53!> \param ext_ks_matrix ...
54! **************************************************************************************************
55 SUBROUTINE build_tblite_ks_matrix(qs_env, calculate_forces, just_energy, ext_ks_matrix)
56 TYPE(qs_environment_type), POINTER :: qs_env
57 LOGICAL, INTENT(in) :: calculate_forces, just_energy
58 TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
59 POINTER :: ext_ks_matrix
60
61 CHARACTER(len=*), PARAMETER :: routinen = 'build_tblite_ks_matrix'
62
63 INTEGER :: handle, img, ispin, nimg, ns, nspins
64 LOGICAL :: do_efield, force_use_rho
65 REAL(kind=dp) :: pc_ener, qmmm_el
66 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_p1, mo_derivs
67 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix, matrix_h
68 TYPE(dbcsr_type), POINTER :: mo_coeff
69 TYPE(dft_control_type), POINTER :: dft_control
70 TYPE(mp_para_env_type), POINTER :: para_env
71 TYPE(qs_energy_type), POINTER :: energy
72 TYPE(qs_ks_env_type), POINTER :: ks_env
73 TYPE(qs_rho_type), POINTER :: rho
74
75 CALL timeset(routinen, handle)
76
77 NULLIFY (dft_control, ks_env, ks_matrix, rho, energy)
78 cpassert(ASSOCIATED(qs_env))
79
80 CALL get_qs_env(qs_env, &
81 dft_control=dft_control, &
82 matrix_h_kp=matrix_h, &
83 para_env=para_env, &
84 ks_env=ks_env, &
85 matrix_ks_kp=ks_matrix, &
86 rho=rho, &
87 energy=energy)
88
89 IF (PRESENT(ext_ks_matrix)) THEN
90 ! remap pointer to allow for non-kpoint external ks matrix
91 ! ext_ks_matrix is used in linear response code
92 ns = SIZE(ext_ks_matrix)
93 ks_matrix(1:ns, 1:1) => ext_ks_matrix(1:ns)
94 END IF
95
96 energy%qmmm_el = 0.0_dp
97
98 nspins = dft_control%nspins
99 nimg = dft_control%nimages
100 cpassert(ASSOCIATED(matrix_h))
101 cpassert(ASSOCIATED(rho))
102 cpassert(SIZE(ks_matrix) > 0)
103
104 DO ispin = 1, nspins
105 DO img = 1, nimg
106 ! copy the core matrix into the fock matrix
107 CALL dbcsr_copy(ks_matrix(ispin, img)%matrix, matrix_h(1, img)%matrix)
108 END DO
109 END DO
110
111 IF (dft_control%apply_period_efield .OR. dft_control%apply_efield .OR. &
112 dft_control%apply_efield_field) THEN
113 do_efield = .true.
114 cpabort("Not implemented yet. Use CP2K routines for GFN1")
115 ELSE
116 do_efield = .false.
117 END IF
118
119 force_use_rho = .NOT. (calculate_forces .AND. nspins > 1)
120 CALL tb_update_charges(qs_env, dft_control, qs_env%tb_tblite, calculate_forces, force_use_rho)
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_off(qs_env, force_use_rho, nimg)
142 END IF
143
144 ! here we compute dE/dC if needed. Assumes dE/dC is H_{ks}C
145 IF (qs_env%requires_mo_derivs .AND. .NOT. just_energy) THEN
146 cpassert(SIZE(ks_matrix, 2) == 1)
147 block
148 TYPE(mo_set_type), DIMENSION(:), POINTER :: mo_array
149 CALL get_qs_env(qs_env, mo_derivs=mo_derivs, mos=mo_array)
150 DO ispin = 1, SIZE(mo_derivs)
151 CALL get_mo_set(mo_set=mo_array(ispin), mo_coeff_b=mo_coeff)
152 cpassert(mo_array(ispin)%use_mo_coeff_b)
153 CALL dbcsr_multiply('n', 'n', 1.0_dp, ks_matrix(ispin, 1)%matrix, mo_coeff, &
154 0.0_dp, mo_derivs(ispin)%matrix)
155 END DO
156 END block
157 END IF
158
159 CALL timestop(handle)
160
161 END SUBROUTINE build_tblite_ks_matrix
162
163END 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, 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.
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_update_charges(qs_env, dft_control, tb, calculate_forces, use_rho)
...
subroutine, public tb_derive_dh_off(qs_env, use_rho, nimg)
Add SCC-overlap and direct multipole Hamiltonian derivatives.
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.