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