(git:fd7f302)
Loading...
Searching...
No Matches
ec_methods.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 Routines used for Harris functional
10!> Kohn-Sham calculation
11!> \par History
12!> 10.2020 created
13!> \author Fabian Belleflamme
14! **************************************************************************************************
18 USE cp_dbcsr_api, ONLY: dbcsr_init_p,&
20 dbcsr_type_no_symmetry
25 USE cp_fm_types, ONLY: cp_fm_get_info,&
29 USE kinds, ONLY: dp
31 USE pw_types, ONLY: pw_c1d_gs_type,&
36 USE qs_fxc, ONLY: qs_fxc_create
41 USE qs_mo_types, ONLY: allocate_mo_set,&
45 USE qs_rho_types, ONLY: qs_rho_create,&
48#include "./base/base_uses.f90"
49
50 IMPLICIT NONE
51
52 PRIVATE
53
54! *** Global parameters ***
55
56 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ec_methods'
57
58 PUBLIC :: create_kernel
59 PUBLIC :: ec_mos_init
60
61CONTAINS
62
63! **************************************************************************************************
64!> \brief Creation of second derivative xc-potential
65!> \param qs_env ...
66!> \param vxc will contain the partially integrated second derivative
67!> taken with respect to rho, evaluated in rho and folded with rho1
68!> vxc is allocated here and needs to be deallocated by the caller.
69!> \param vxc_tau ...
70!> \param rho density at which derivatives were calculated
71!> \param rho1_r density in r-space with which to fold
72!> \param rho1_g density in g-space with which to fold
73!> \param tau1_r ...
74!> \param xc_section XC parameters of this potential
75!> \param compute_virial Enable stress-tensor calculation
76!> \param virial_xc Will contain GGA contribution of XC-kernel to stress-tensor
77!> \date 11.2019
78!> \author fbelle
79! **************************************************************************************************
80 SUBROUTINE create_kernel(qs_env, vxc, vxc_tau, rho, rho1_r, rho1_g, tau1_r, xc_section, &
81 compute_virial, virial_xc)
82
83 TYPE(qs_environment_type), POINTER :: qs_env
84 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: vxc, vxc_tau
85 TYPE(qs_rho_type), INTENT(IN), POINTER :: rho
86 TYPE(pw_r3d_rs_type), DIMENSION(:), INTENT(IN), &
87 POINTER :: rho1_r
88 TYPE(pw_c1d_gs_type), DIMENSION(:), INTENT(IN), &
89 POINTER :: rho1_g
90 TYPE(pw_r3d_rs_type), DIMENSION(:), INTENT(IN), &
91 POINTER :: tau1_r
92 TYPE(section_vals_type), INTENT(IN), POINTER :: xc_section
93 LOGICAL, INTENT(IN), OPTIONAL :: compute_virial
94 REAL(kind=dp), DIMENSION(3, 3), INTENT(INOUT), &
95 OPTIONAL :: virial_xc
96
97 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_kernel'
98
99 INTEGER :: handle
100 TYPE(qs_rho_type), POINTER :: rho1
101
102 CALL timeset(routinen, handle)
103
104 cpassert(.NOT. ASSOCIATED(vxc))
105 cpassert(.NOT. ASSOCIATED(vxc_tau))
106
107 ALLOCATE (rho1)
108 CALL qs_rho_create(rho1)
109 IF (ASSOCIATED(rho1_r)) THEN
110 CALL qs_rho_set(rho1, rho_r=rho1_r, rho_r_valid=.true.)
111 END IF
112 IF (ASSOCIATED(rho1_g)) THEN
113 CALL qs_rho_set(rho1, rho_g=rho1_g, rho_g_valid=.true.)
114 END IF
115 IF (ASSOCIATED(tau1_r)) THEN
116 CALL qs_rho_set(rho1, tau_r=tau1_r, tau_r_valid=.true.)
117 END IF
118 !
119 CALL qs_fxc_create(qs_env, rho, rho1, xc_section, vxc, vxc_tau, &
120 compute_virial=compute_virial, virial_xc=virial_xc)
121 !
122 DEALLOCATE (rho1)
123
124 CALL timestop(handle)
125
126 END SUBROUTINE create_kernel
127
128! **************************************************************************************************
129!> \brief Allocate and initiate molecular orbitals environment
130!>
131!> \param qs_env ...
132!> \param matrix_s Used as template
133!> \param
134!>
135!> \par History
136!> 2020.10 created [Fabian Belleflamme]
137!> \author Fabian Belleflamme
138! **************************************************************************************************
139 SUBROUTINE ec_mos_init(qs_env, matrix_s)
140 TYPE(qs_environment_type), POINTER :: qs_env
141 TYPE(dbcsr_type) :: matrix_s
142
143 CHARACTER(len=*), PARAMETER :: routinen = 'ec_mos_init'
144
145 INTEGER :: handle, ispin, multiplicity, n_ao, &
146 nelectron, nmo, nspins
147 INTEGER, DIMENSION(2) :: n_mo, nelectron_spin
148 REAL(dp) :: maxocc
149 TYPE(cp_blacs_env_type), POINTER :: blacs_env
150 TYPE(cp_fm_struct_type), POINTER :: fm_struct
151 TYPE(cp_fm_type), POINTER :: mo_coeff
152 TYPE(dbcsr_type), POINTER :: mo_coeff_b
153 TYPE(dft_control_type), POINTER :: dft_control
154 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
155 TYPE(mp_para_env_type), POINTER :: para_env
156 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
157 TYPE(qs_matrix_pools_type), POINTER :: my_mpools
158
159 CALL timeset(routinen, handle)
160
161 NULLIFY (blacs_env, dft_control, mo_coeff, mo_coeff_b, mos, my_mpools, qs_kind_set)
162
163 CALL get_qs_env(qs_env=qs_env, &
164 dft_control=dft_control, &
165 blacs_env=blacs_env, &
166 qs_kind_set=qs_kind_set, &
167 nelectron_spin=nelectron_spin, &
168 para_env=para_env)
169 nspins = dft_control%nspins
170
171 ! Start setup
172 CALL get_qs_kind_set(qs_kind_set, nsgf=n_ao, nelectron=nelectron)
173
174 ! the total number of electrons
175 nelectron = nelectron - dft_control%charge
176 multiplicity = dft_control%multiplicity
177
178 ! setting maxocc and n_mo
179 IF (dft_control%nspins == 1) THEN
180 maxocc = 2.0_dp
181 nelectron_spin(1) = nelectron
182 nelectron_spin(2) = 0
183 IF (modulo(nelectron, 2) == 0) THEN
184 n_mo(1) = nelectron/2
185 ELSE
186 n_mo(1) = int(nelectron/2._dp) + 1
187 END IF
188 n_mo(2) = 0
189 ELSE
190 maxocc = 1.0_dp
191
192 ! The simplist spin distribution is written here. Special cases will
193 ! need additional user input
194 IF (modulo(nelectron + multiplicity - 1, 2) /= 0) THEN
195 cpabort("LSD: try to use a different multiplicity")
196 END IF
197
198 nelectron_spin(1) = (nelectron + multiplicity - 1)/2
199 nelectron_spin(2) = (nelectron - multiplicity + 1)/2
200
201 IF (nelectron_spin(2) < 0) THEN
202 cpabort("LSD: too few electrons for this multiplicity")
203 END IF
204
205 n_mo(1) = nelectron_spin(1)
206 n_mo(2) = nelectron_spin(2)
207
208 END IF
209
210 ! Allocate MO set
211 ALLOCATE (mos(nspins))
212 DO ispin = 1, nspins
213 CALL allocate_mo_set(mo_set=mos(ispin), &
214 nao=n_ao, &
215 nmo=n_mo(ispin), &
216 nelectron=nelectron_spin(ispin), &
217 n_el_f=real(nelectron_spin(ispin), dp), &
218 maxocc=maxocc, &
219 flexible_electron_count=dft_control%relax_multiplicity)
220 END DO
221
222 CALL set_qs_env(qs_env, mos=mos)
223
224 ! finish initialization of the MOs
225 NULLIFY (mo_coeff, mo_coeff_b)
226 DO ispin = 1, SIZE(mos)
227 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, mo_coeff_b=mo_coeff_b, &
228 nmo=nmo, nao=n_ao)
229
230 IF (.NOT. ASSOCIATED(mo_coeff)) THEN
231 CALL cp_fm_struct_create(fm_struct, nrow_global=n_ao, &
232 ncol_global=nmo, para_env=para_env, &
233 context=blacs_env)
234
235 CALL init_mo_set(mos(ispin), &
236 fm_struct=fm_struct, &
237 name="qs_env%mo"//trim(adjustl(cp_to_string(ispin))))
238 CALL cp_fm_struct_release(fm_struct)
239 END IF
240
241 IF (.NOT. ASSOCIATED(mo_coeff_b)) THEN
242 CALL cp_fm_get_info(mos(ispin)%mo_coeff, ncol_global=nmo)
243 CALL dbcsr_init_p(mos(ispin)%mo_coeff_b)
244 CALL cp_dbcsr_m_by_n_from_row_template(mos(ispin)%mo_coeff_b, &
245 template=matrix_s, &
246 n=nmo, &
247 sym=dbcsr_type_no_symmetry)
248 END IF
249 END DO
250
251 CALL mpools_release(mpools=my_mpools)
252
253 CALL timestop(handle)
254
255 END SUBROUTINE ec_mos_init
256
257END MODULE ec_methods
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
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_init_p(matrix)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_m_by_n_from_row_template(matrix, template, n, sym)
Utility function to create dbcsr matrix, m x n matrix (n arbitrary) with the same processor grid and ...
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_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
various routines to log and control the output. The idea is that decisions about where to log should ...
Routines used for Harris functional Kohn-Sham calculation.
Definition ec_methods.F:15
subroutine, public ec_mos_init(qs_env, matrix_s)
Allocate and initiate molecular orbitals environment.
Definition ec_methods.F:140
subroutine, public create_kernel(qs_env, vxc, vxc_tau, rho, rho1_r, rho1_g, tau1_r, xc_section, compute_virial, virial_xc)
Creation of second derivative xc-potential.
Definition ec_methods.F:82
objects that represent the structure of input sections and the data contained in an input section
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.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, rhoz_cneo_set, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Set the QUICKSTEP environment.
Setup Routine for Fxc Potentials.
Definition qs_fxc.F:29
subroutine, public qs_fxc_create(qs_env, rho0_struct, rho1_struct, xc_section, fxc_rho, fxc_tau, is_triplet, spinflip, no_weights, uf_grid_results, pw_env_ext, compute_virial, virial_xc)
...
Definition qs_fxc.F:105
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
wrapper for the pools of matrixes
subroutine, public mpools_release(mpools)
releases the given mpools
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
subroutine, public init_mo_set(mo_set, fm_pool, fm_ref, fm_struct, name, counter)
initializes an allocated mo_set. eigenvalues, mo_coeff, occupation_numbers are valid only after this ...
subroutine, public allocate_mo_set(mo_set, nao, nmo, nelectron, n_el_f, maxocc, flexible_electron_count)
Allocates a mo set and partially initializes it (nao,nmo,nelectron, and flexible_electron_count are v...
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_set(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)
...
subroutine, public qs_rho_create(rho)
Allocates a new instance of rho.
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
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
container for the pools of matrixes used by qs
keeps the density in various representations, keeping track of which ones are valid.