(git:08825b9)
Loading...
Searching...
No Matches
qs_gamma2kp.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 Initialize a qs_env for kpoint calculations starting from a gamma point qs_env
10!> \par History
11!> 11.2016 created [JGH]
12!> \author JGH
13! **************************************************************************************************
16 USE cp_dbcsr_api, ONLY: dbcsr_add,&
19 USE input_constants, ONLY: atomic_guess,&
25 USE kinds, ONLY: dp
26 USE kpoint_types, ONLY: kpoint_create,&
29 USE pw_methods, ONLY: pw_copy
30 USE pw_types, ONLY: pw_c1d_gs_type,&
33 USE qs_environment, ONLY: qs_init
40 USE qs_rho_types, ONLY: qs_rho_get,&
46#include "./base/base_uses.f90"
47
48 IMPLICIT NONE
49 PRIVATE
50
51 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_gamma2kp'
52
53 PUBLIC :: create_kp_from_gamma
54
55! **************************************************************************************************
56
57CONTAINS
58
59! **************************************************************************************************
60!> \brief ...
61!> \param qs_env ...
62!> \param qs_env_kp ...
63!> \param with_xc_terms ...
64! **************************************************************************************************
65 SUBROUTINE create_kp_from_gamma(qs_env, qs_env_kp, with_xc_terms)
66 TYPE(qs_environment_type), POINTER :: qs_env, qs_env_kp
67 LOGICAL, OPTIONAL :: with_xc_terms
68
69 INTEGER :: iatom, ispin, xc_func
70 LOGICAL :: without_xc_terms
71 TYPE(cp_subsys_type), POINTER :: cp_subsys
72 TYPE(dft_control_type), POINTER :: dft_control
73 TYPE(kpoint_type), POINTER :: kpoint
74 TYPE(mp_para_env_type), POINTER :: para_env
75 TYPE(qs_rho_type), POINTER :: rho, rho_gamma
76 TYPE(qs_scf_env_type), POINTER :: scf_env
77 TYPE(rho_atom_type), POINTER :: atoms(:), atoms_gamma(:)
78 TYPE(scf_control_type), POINTER :: scf_control
79 TYPE(section_vals_type), POINTER :: force_env_section, subsys_section, &
80 xc_fun_section
81
82 CALL get_qs_env(qs_env, &
83 para_env=para_env, &
84 input=force_env_section, &
85 cp_subsys=cp_subsys)
86
87 NULLIFY (subsys_section)
88
89 NULLIFY (kpoint)
90 CALL kpoint_create(kpoint)
91 kpoint%kp_scheme = "GAMMA"
92 kpoint%symmetry = .false.
93 kpoint%verbose = .false.
94 kpoint%full_grid = .true.
95 kpoint%eps_geo = 1.0e-6_dp
96 kpoint%use_real_wfn = .true.
97 kpoint%parallel_group_size = 0
98
99 without_xc_terms = .false.
100 IF (PRESENT(with_xc_terms)) without_xc_terms = .NOT. with_xc_terms
101
102 IF (without_xc_terms) THEN
103 xc_fun_section => section_vals_get_subs_vals(force_env_section, "DFT%XC%XC_FUNCTIONAL")
104 CALL section_vals_val_get(xc_fun_section, "_SECTION_PARAMETERS_", i_val=xc_func)
105 CALL section_vals_val_set(xc_fun_section, "_SECTION_PARAMETERS_", i_val=xc_none)
106 END IF
107
108 ALLOCATE (qs_env_kp)
109 CALL qs_env_create(qs_env_kp)
110 CALL qs_init(qs_env_kp, para_env, cp_subsys=cp_subsys, kpoint_env=kpoint, &
111 force_env_section=force_env_section, subsys_section=subsys_section, &
112 use_motion_section=.false., silent=.true.)
113
114 CALL get_qs_env(qs_env_kp, scf_control=scf_control)
115 scf_control%density_guess = atomic_guess
116 CALL qs_energies_init(qs_env_kp, calc_forces=.false.)
117
118 NULLIFY (scf_env)
119 CALL qs_scf_env_init_basic(qs_env_kp, scf_env)
120
121 CALL set_qs_env(qs_env_kp, scf_env=scf_env)
122
123 ! Preserve the converged density fields, not the new environment's atomic guess.
124 CALL get_qs_env(qs_env, rho=rho_gamma)
125 CALL get_qs_env(qs_env_kp, rho=rho)
126 CALL copy_frozen_density(rho_gamma, rho)
127
128 CALL get_qs_env(qs_env, dft_control=dft_control)
129 IF (dft_control%qs_control%gapw_xc) THEN
130 CALL get_qs_env(qs_env, rho_xc=rho_gamma)
131 CALL get_qs_env(qs_env_kp, rho_xc=rho)
132 CALL copy_frozen_density(rho_gamma, rho)
133 END IF
134 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc) THEN
135 ! The frozen GAPW potential also depends on these hard/soft onsite densities.
136 CALL get_qs_env(qs_env, rho_atom_set=atoms_gamma)
137 CALL get_qs_env(qs_env_kp, rho_atom_set=atoms)
138 cpassert(SIZE(atoms) == SIZE(atoms_gamma))
139 DO iatom = 1, SIZE(atoms_gamma)
140 IF (.NOT. ASSOCIATED(atoms_gamma(iatom)%cpc_h)) cycle
141 cpassert(ASSOCIATED(atoms(iatom)%cpc_h))
142 DO ispin = 1, SIZE(atoms_gamma(iatom)%cpc_h)
143 IF (.NOT. ASSOCIATED(atoms_gamma(iatom)%cpc_h(ispin)%r_coef)) cycle
144 cpassert(ASSOCIATED(atoms(iatom)%cpc_h(ispin)%r_coef))
145 cpassert(ASSOCIATED(atoms(iatom)%cpc_s(ispin)%r_coef))
146 atoms(iatom)%cpc_h(ispin)%r_coef = atoms_gamma(iatom)%cpc_h(ispin)%r_coef
147 atoms(iatom)%cpc_s(ispin)%r_coef = atoms_gamma(iatom)%cpc_s(ispin)%r_coef
148 END DO
149 END DO
150 END IF
151
152 CALL qs_ks_update_qs_env(qs_env_kp, print_active=.false.)
153
154 IF (without_xc_terms) THEN
155 ! set back the functional
156 CALL section_vals_val_set(xc_fun_section, "_SECTION_PARAMETERS_", i_val=xc_func)
157 END IF
158
159 END SUBROUTINE create_kp_from_gamma
160
161! **************************************************************************************************
162!> \brief Copy converged Gamma density fields into the initialized k-point environment.
163!> \param source Converged Gamma density
164!> \param destination Initialized density with the same real/reciprocal grids
165!> \author Thomas D. Kuehne (tkuehne@cp2k.org)
166! **************************************************************************************************
167 SUBROUTINE copy_frozen_density(source, destination)
168 TYPE(qs_rho_type), INTENT(IN) :: source
169 TYPE(qs_rho_type), INTENT(INOUT) :: destination
170
171 INTEGER :: idir, ispin
172 LOGICAL :: drho_g_valid, drho_r_valid, rho_g_valid, &
173 rho_r_valid, soft_valid, tau_g_valid, &
174 tau_r_valid
175 REAL(dp), DIMENSION(:), POINTER :: total_g_in, total_g_out, total_r_in, &
176 total_r_out
177 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ao_in, ao_out
178 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g_in, rho_g_out, tau_g_in, tau_g_out
179 TYPE(pw_c1d_gs_type), DIMENSION(:, :), POINTER :: drho_g_in, drho_g_out
180 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r_in, rho_r_out, tau_r_in, tau_r_out
181 TYPE(pw_r3d_rs_type), DIMENSION(:, :), POINTER :: drho_r_in, drho_r_out
182
183 CALL qs_rho_get(source, rho_ao_kp=ao_in, rho_r=rho_r_in, rho_g=rho_g_in, &
184 tau_r=tau_r_in, tau_g=tau_g_in, drho_r=drho_r_in, drho_g=drho_g_in, &
185 tot_rho_r=total_r_in, tot_rho_g=total_g_in, &
186 rho_r_valid=rho_r_valid, rho_g_valid=rho_g_valid, &
187 tau_r_valid=tau_r_valid, tau_g_valid=tau_g_valid, &
188 drho_r_valid=drho_r_valid, drho_g_valid=drho_g_valid, soft_valid=soft_valid)
189 CALL qs_rho_get(destination, rho_ao_kp=ao_out, rho_r=rho_r_out, rho_g=rho_g_out, &
190 tau_r=tau_r_out, tau_g=tau_g_out, drho_r=drho_r_out, drho_g=drho_g_out, &
191 tot_rho_r=total_r_out, tot_rho_g=total_g_out)
192
193 cpassert(SIZE(rho_r_in) == SIZE(rho_r_out))
194 DO ispin = 1, SIZE(rho_r_in)
195 CALL pw_copy(rho_r_in(ispin), rho_r_out(ispin))
196 CALL pw_copy(rho_g_in(ispin), rho_g_out(ispin))
197 CALL dbcsr_add(matrix_a=ao_out(ispin, 1)%matrix, alpha_scalar=0.0_dp, &
198 matrix_b=ao_in(ispin, 1)%matrix, beta_scalar=1.0_dp)
199 ! XC fields need not be allocated when with_xc_terms is false.
200 IF (ASSOCIATED(tau_r_out) .AND. tau_r_valid) THEN
201 cpassert(ASSOCIATED(tau_r_in))
202 CALL pw_copy(tau_r_in(ispin), tau_r_out(ispin))
203 END IF
204 IF (ASSOCIATED(tau_g_out) .AND. tau_g_valid) THEN
205 cpassert(ASSOCIATED(tau_g_in))
206 CALL pw_copy(tau_g_in(ispin), tau_g_out(ispin))
207 END IF
208 IF (ASSOCIATED(drho_r_out) .AND. drho_r_valid) THEN
209 cpassert(ASSOCIATED(drho_r_in))
210 DO idir = 1, SIZE(drho_r_out, 1)
211 CALL pw_copy(drho_r_in(idir, ispin), drho_r_out(idir, ispin))
212 END DO
213 END IF
214 IF (ASSOCIATED(drho_g_out) .AND. drho_g_valid) THEN
215 cpassert(ASSOCIATED(drho_g_in))
216 DO idir = 1, SIZE(drho_g_out, 1)
217 CALL pw_copy(drho_g_in(idir, ispin), drho_g_out(idir, ispin))
218 END DO
219 END IF
220 END DO
221 IF (ASSOCIATED(total_r_in) .AND. ASSOCIATED(total_r_out)) total_r_out = total_r_in
222 IF (ASSOCIATED(total_g_in) .AND. ASSOCIATED(total_g_out)) total_g_out = total_g_in
223 CALL qs_rho_set(destination, rho_r_valid=rho_r_valid, rho_g_valid=rho_g_valid, &
224 tau_r_valid=tau_r_valid .AND. ASSOCIATED(tau_r_out), &
225 tau_g_valid=tau_g_valid .AND. ASSOCIATED(tau_g_out), &
226 drho_r_valid=drho_r_valid .AND. ASSOCIATED(drho_r_out), &
227 drho_g_valid=drho_g_valid .AND. ASSOCIATED(drho_g_out), soft_valid=soft_valid)
228
229 END SUBROUTINE copy_frozen_density
230
231END MODULE qs_gamma2kp
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
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 atomic_guess
integer, parameter, public xc_none
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_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Types and basic routines needed for a kpoint calculation.
subroutine, public kpoint_create(kpoint)
Create a kpoint environment.
Interface to the message passing library MPI.
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...
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_create(qs_env, globenv)
allocates and intitializes a qs_env
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.
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.
Initialize a qs_env for kpoint calculations starting from a gamma point qs_env.
Definition qs_gamma2kp.F:14
subroutine, public create_kp_from_gamma(qs_env, qs_env_kp, with_xc_terms)
...
Definition qs_gamma2kp.F:66
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, print_active)
updates the Kohn Sham matrix of the given qs_env (facility method)
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_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...
Utility routines for qs_scf.
subroutine, public qs_scf_env_init_basic(qs_env, scf_env)
initializes input parameters if needed for non-scf calclulations using diagonalization
module that contains the definitions of the scf types
parameters that control an scf iteration
represents a system: atoms, molecules, their pos,vel,...
Contains information about kpoints.
stores all the informations relevant to an mpi environment
keeps the density in various representations, keeping track of which ones are valid.