(git:98357aa)
Loading...
Searching...
No Matches
qs_eht_guess.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 Generate an initial guess (dm and orb) from EHT calculation
10! **************************************************************************************************
15 USE cp_dbcsr_api, ONLY: dbcsr_create,&
21 dbcsr_type_no_symmetry
26 USE cp_fm_diag, ONLY: cp_fm_geeig
30 USE cp_fm_types, ONLY: cp_fm_create,&
41 USE kinds, ONLY: dp
45 USE qs_environment, ONLY: qs_init
55 USE qs_mo_types, ONLY: get_mo_set,&
61#include "./base/base_uses.f90"
62
63 IMPLICIT NONE
64
65 PRIVATE
66
67 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_eht_guess'
68
69 PUBLIC :: calculate_eht_guess
70
71! **************************************************************************************************
72
73CONTAINS
74
75! **************************************************************************************************
76!> \brief EHT MO guess calclulation
77!> \param qs_env ...
78!> \param mo_array ...
79! **************************************************************************************************
80 SUBROUTINE calculate_eht_guess(qs_env, mo_array)
81 TYPE(qs_environment_type), POINTER :: qs_env
82 TYPE(mo_set_type), DIMENSION(:), POINTER :: mo_array
83
84 CHARACTER(LEN=*), PARAMETER :: routinen = 'calculate_eht_guess'
85
86 INTEGER :: handle, ispin, nao, nbas, neeht, neorb, &
87 nkind, nmo, nspins, zero
88 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: eigenvalues
89 REAL(kind=dp), DIMENSION(:), POINTER :: eigval
90 TYPE(cp_blacs_env_type), POINTER :: blacs_env
91 TYPE(cp_fm_struct_type), POINTER :: mstruct_ee, mstruct_oe, mstruct_oo
92 TYPE(cp_fm_type) :: fmksmat, fmorb, fmscr, fmsmat, fmvec, &
93 fmwork, sfull, sinv
94 TYPE(cp_fm_type), POINTER :: mo_coeff
95 TYPE(cp_subsys_type), POINTER :: cp_subsys
96 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ksmat, matrix_s, matrix_t, smat
97 TYPE(dbcsr_type) :: tempmat, tmat
98 TYPE(dft_control_type), POINTER :: dft_control
99 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list_a, basis_set_list_b
100 TYPE(mp_para_env_type), POINTER :: para_env
101 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
102 POINTER :: sab_nl
103 TYPE(qs_environment_type), POINTER :: eht_env
104 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
105 TYPE(qs_ks_env_type), POINTER :: ks_env
106 TYPE(section_vals_type), POINTER :: dft_section, eht_force_env_section, &
107 force_env_section, qs_section, &
108 subsys_section, xtb_section
109
110 CALL timeset(routinen, handle)
111
112 NULLIFY (subsys_section)
113 CALL get_qs_env(qs_env, &
114 ks_env=ks_env, &
115 para_env=para_env, &
116 input=force_env_section, &
117 cp_subsys=cp_subsys, &
118 dft_control=dft_control)
119
120 NULLIFY (eht_force_env_section)
121 CALL section_vals_duplicate(force_env_section, eht_force_env_section)
122 dft_section => section_vals_get_subs_vals(eht_force_env_section, "DFT")
123 qs_section => section_vals_get_subs_vals(dft_section, "QS")
124 CALL section_vals_val_set(qs_section, "METHOD", i_val=do_method_xtb)
125 xtb_section => section_vals_get_subs_vals(qs_section, "xTB")
126 zero = 0
127 CALL section_vals_val_set(xtb_section, "GFN_TYPE", i_val=zero)
128 !
129 ALLOCATE (eht_env)
130 CALL qs_env_create(eht_env)
131 CALL qs_init(eht_env, para_env, cp_subsys=cp_subsys, &
132 force_env_section=eht_force_env_section, &
133 subsys_section=subsys_section, &
134 use_motion_section=.false., silent=.true.)
135 !
136 CALL get_qs_env(qs_env, nelectron_total=neorb)
137 CALL get_qs_env(eht_env, nelectron_total=neeht)
138 IF (neorb /= neeht) THEN
139 cpwarn("EHT has different number of electrons than calculation method.")
140 cpabort("EHT Initial Guess")
141 END IF
142 !
143 CALL qs_env_rebuild_pw_env(eht_env)
144 CALL qs_energies_init(eht_env, calc_forces=.false.)
145 ! the guess only builds H_KS to diagonalise — it never needs dE/dC
146 ! clear the requires_mo_derivs flag inherited from &OT block so the xTB/tblite
147 ! KS builder skips the mo_derivs path
148 eht_env%requires_mo_derivs = .false.
149 IF (dft_control%qs_control%xtb_control%do_tblite) THEN
150 CALL build_tblite_ks_matrix(eht_env, .false., .false.)
151 ELSE
152 CALL build_xtb_ks_matrix(eht_env, .false., .false.)
153 END IF
154 !
155 CALL get_qs_env(eht_env, &
156 matrix_s=smat, matrix_ks=ksmat)
157 nspins = SIZE(ksmat, 1)
158 CALL get_qs_env(eht_env, para_env=para_env, blacs_env=blacs_env)
159 CALL dbcsr_get_info(smat(1)%matrix, nfullrows_total=nao)
160 CALL cp_fm_struct_create(fmstruct=mstruct_ee, context=blacs_env, &
161 nrow_global=nao, ncol_global=nao)
162 CALL cp_fm_create(fmksmat, mstruct_ee)
163 CALL cp_fm_create(fmsmat, mstruct_ee)
164 CALL cp_fm_create(fmvec, mstruct_ee)
165 CALL cp_fm_create(fmwork, mstruct_ee)
166 ALLOCATE (eigenvalues(nao))
167
168 ! DBCSR matrix
169 CALL dbcsr_create(tempmat, template=smat(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
170
171 ! transfer to FM
172 CALL dbcsr_desymmetrize(smat(1)%matrix, tempmat)
173 CALL copy_dbcsr_to_fm(tempmat, fmsmat)
174
175 !SINV of origianl basis
176 CALL get_qs_env(qs_env, para_env=para_env, blacs_env=blacs_env)
177 CALL get_qs_env(qs_env, matrix_s=matrix_s)
178 CALL dbcsr_get_info(matrix_s(1)%matrix, nfullrows_total=nbas)
179 CALL dbcsr_create(tmat, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
180 CALL cp_fm_struct_create(fmstruct=mstruct_oo, context=blacs_env, &
181 nrow_global=nbas, ncol_global=nbas)
182 CALL cp_fm_create(sfull, mstruct_oo)
183 CALL cp_fm_create(sinv, mstruct_oo)
184 CALL dbcsr_desymmetrize(matrix_s(1)%matrix, tmat)
185 CALL copy_dbcsr_to_fm(tmat, sfull)
186 CALL cp_fm_invert(sfull, sinv)
187 CALL dbcsr_release(tmat)
188 CALL cp_fm_release(sfull)
189 !TMAT(bas1, bas2)
190 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, sab_all=sab_nl, nkind=nkind)
191 IF (.NOT. ASSOCIATED(sab_nl)) THEN
192 cpwarn("Full neighborlist not available for this method. EHT initial guess not possible.")
193 cpabort("EHT Initial Guess")
194 END IF
195 ALLOCATE (basis_set_list_a(nkind), basis_set_list_b(nkind))
196 CALL basis_set_list_setup(basis_set_list_a, "ORB", qs_kind_set)
197 CALL get_qs_env(eht_env, qs_kind_set=qs_kind_set)
198 CALL basis_set_list_setup(basis_set_list_b, "ORB", qs_kind_set)
199 !
200 NULLIFY (matrix_t)
201 CALL build_overlap_matrix_simple(ks_env, matrix_t, &
202 basis_set_list_a, basis_set_list_b, sab_nl)
203 DEALLOCATE (basis_set_list_a, basis_set_list_b)
204
205 ! KS matrix is not spin dependent!
206 CALL dbcsr_desymmetrize(ksmat(1)%matrix, tempmat)
207 CALL copy_dbcsr_to_fm(tempmat, fmksmat)
208 ! diagonalize
209 CALL cp_fm_geeig(fmksmat, fmsmat, fmvec, eigenvalues, fmwork)
210 ! Sinv*T*d
211 CALL cp_fm_struct_create(fmstruct=mstruct_oe, context=blacs_env, &
212 nrow_global=nbas, ncol_global=nao)
213 CALL cp_fm_create(fmscr, mstruct_oe)
214 CALL cp_fm_create(fmorb, mstruct_oe)
215 CALL cp_dbcsr_sm_fm_multiply(matrix_t(1)%matrix, fmvec, fmscr, ncol=nao)
216 CALL parallel_gemm('N', 'N', nbas, nao, nbas, 1.0_dp, sinv, fmscr, 0.0_dp, fmorb)
217 !
218 DO ispin = 1, nspins
219 CALL get_mo_set(mo_set=mo_array(ispin), mo_coeff=mo_coeff, nmo=nmo)
220 CALL cp_fm_to_fm(fmorb, mo_coeff, nmo, 1, 1)
221 NULLIFY (eigval)
222 CALL get_mo_set(mo_set=mo_array(ispin), eigenvalues=eigval)
223 IF (ASSOCIATED(eigval)) THEN
224 eigval(1:nmo) = eigenvalues(1:nmo)
225 END IF
226 END DO
227 CALL set_mo_occupation(mo_array, smear=qs_env%scf_control%smear)
228
229 DEALLOCATE (eigenvalues)
230 CALL dbcsr_release(tempmat)
231 CALL dbcsr_deallocate_matrix_set(matrix_t)
232 CALL cp_fm_release(fmksmat)
233 CALL cp_fm_release(fmsmat)
234 CALL cp_fm_release(fmvec)
235 CALL cp_fm_release(fmwork)
236 CALL cp_fm_release(fmscr)
237 CALL cp_fm_release(fmorb)
238 CALL cp_fm_release(sinv)
239 CALL cp_fm_struct_release(mstruct_ee)
240 CALL cp_fm_struct_release(mstruct_oe)
241 CALL cp_fm_struct_release(mstruct_oo)
242 !
243 CALL qs_env_release(eht_env)
244 DEALLOCATE (eht_env)
245 CALL section_vals_release(eht_force_env_section)
246
247 CALL timestop(handle)
248
249 END SUBROUTINE calculate_eht_guess
250
251END MODULE qs_eht_guess
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_release(matrix)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_invert(matrix_a, matrix_inverse, det_a, eps_svd, eigval)
Inverts a cp_fm_type matrix, optionally returning the determinant of the input matrix.
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
Definition cp_fm_diag.F:17
subroutine, public cp_fm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work)
General Eigenvalue Problem AX = BXE. Use cuSOLVERMp directly when requested and large enough; otherwi...
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
types that represent a subsys, i.e. a part of the system
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_method_xtb
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_set(section_vals, keyword_name, i_rep_section, i_rep_val, val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
sets the requested value
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_duplicate(section_vals_in, section_vals_out, i_rep_start, i_rep_end)
creates a deep copy from section_vals_in to section_vals_out
recursive subroutine, public section_vals_release(section_vals)
releases the given object
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
Generate an initial guess (dm and orb) from EHT calculation.
subroutine, public calculate_eht_guess(qs_env, mo_array)
EHT MO guess calclulation.
Utility subroutine for qs energy calculation.
subroutine, public qs_energies_init(qs_env, calc_forces)
Refactoring of qs_energies_scf. Driver routine for the initial setup and calculations for a qs energy...
qs_environment methods that use many other modules
subroutine, public qs_env_rebuild_pw_env(qs_env)
rebuilds the pw_env in the given qs_env, allocating it if necessary
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.
subroutine, public qs_env_release(qs_env)
releases the given qs_env (see doc/ReferenceCounting.html)
subroutine, public qs_env_create(qs_env, globenv)
allocates and intitializes a qs_env
subroutine, public qs_init(qs_env, para_env, root_section, globenv, cp_subsys, kpoint_env, qmmm, qmmm_env_qm, force_env_section, subsys_section, use_motion_section, silent, multip, charge)
Read the input and the database files for the setup of the QUICKSTEP environment.
Some utility functions for the calculation of integrals.
subroutine, public basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
Set up an easy accessible list of the basis sets for all kinds.
Define the quickstep kind type and their sub types.
Set occupation of molecular orbitals.
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.
Calculation of overlap matrix, its derivatives and forces.
Definition qs_overlap.F:19
subroutine, public build_overlap_matrix_simple(ks_env, matrix_s, basis_set_list_a, basis_set_list_b, sab_nl, lcart)
Calculation of the overlap matrix over Cartesian Gaussian functions.
Definition qs_overlap.F:575
tblite matrix build
subroutine, public build_tblite_ks_matrix(qs_env, calculate_forces, just_energy, ext_ks_matrix)
...
Calculation of KS matrix in xTB Reference: Stefan Grimme, Christoph Bannwarth, Philip Shushkov JCTC 1...
subroutine, public build_xtb_ks_matrix(qs_env, calculate_forces, just_energy, ext_ks_matrix)
...
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
represent a full matrix
represents a system: atoms, molecules, their pos,vel,...
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...