(git:691081d)
Loading...
Searching...
No Matches
qs_fod.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 Fractional occupation number weighted density (Grimme and Hansen).
10!> \author Falk William Seidel (initial implementation)
11! **************************************************************************************************
12MODULE qs_fod
13 USE bibliography, ONLY: grimme2015fod,&
14 cite_reference
16 USE cp_dbcsr_api, ONLY: dbcsr_copy,&
21 USE cp_output_handling, ONLY: cp_p_file,&
31 USE kinds, ONLY: dp
33 USE pw_env_types, ONLY: pw_env_get,&
36 USE pw_types, ONLY: pw_c1d_gs_type,&
42 USE qs_kind_types, ONLY: get_qs_kind,&
48 USE qs_rho_types, ONLY: qs_rho_get,&
53#include "./base/base_uses.f90"
54
55 IMPLICIT NONE
56 PRIVATE
57 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_fod'
59
60CONTAINS
61
62! **************************************************************************************************
63!> \brief Hole weights below the chemical potential, particle weights above it.
64!> \param occupation Fermi-Dirac occupations (0 to maxocc).
65!> \param eigenvalues Orbital energies in the same units as mu.
66!> \param mu Chemical potential for this spin channel.
67!> \param maxocc Maximum occupation, two for RKS and one for UKS.
68!> \return Nonnegative FOD weights; both branches agree at half occupation.
69! **************************************************************************************************
70 PURE FUNCTION fod_weights(occupation, eigenvalues, mu, maxocc) RESULT(weights)
71 REAL(dp), DIMENSION(:), INTENT(IN) :: occupation, eigenvalues
72 REAL(dp), INTENT(IN) :: mu, maxocc
73 REAL(dp), DIMENSION(SIZE(occupation)) :: weights
74
75 WHERE (eigenvalues <= mu)
76 weights = maxocc - occupation
77 ELSE WHERE
78 weights = occupation
79 END WHERE
80 END FUNCTION fod_weights
81
82! **************************************************************************************************
83!> \brief Reject unsupported FOD settings before starting an expensive SCF calculation.
84!> \param input FORCE_EVAL input section.
85!> \param logger Output logger.
86!> \param qs_env Quickstep environment.
87! **************************************************************************************************
88 SUBROUTINE qs_fod_validate(input, logger, qs_env)
89 TYPE(section_vals_type), POINTER :: input
90 TYPE(cp_logger_type), POINTER :: logger
91 TYPE(qs_environment_type), POINTER :: qs_env
92
93 LOGICAL :: do_kpoints
94 TYPE(dft_control_type), POINTER :: dft_control
95 TYPE(scf_control_type), POINTER :: scf_control
96 TYPE(section_vals_type), POINTER :: fod_section
97
98 fod_section => section_vals_get_subs_vals(input, "DFT%PRINT%FOD")
99 IF (.NOT. btest(cp_print_key_should_output(logger%iter_info, fod_section, ""), cp_p_file)) RETURN
100 CALL get_qs_env(qs_env, dft_control=dft_control, scf_control=scf_control, do_kpoints=do_kpoints)
101 IF (do_kpoints) cpabort("FOD currently supports Gamma-point calculations only.")
102 IF (.NOT. dft_control%qs_control%gpw) cpabort("FOD currently requires the GPW method.")
103 IF (qs_env%run_rtp) cpabort("FOD is not supported for real-time propagation.")
104 IF (.NOT. scf_control%smear%do_smear .OR. scf_control%smear%method /= smear_fermi_dirac) THEN
105 cpabort("FOD requires SCF%SMEAR with METHOD FERMI_DIRAC.")
106 END IF
107 IF (scf_control%smear%electronic_temperature <= 0.0_dp) THEN
108 cpabort("FOD requires a positive electronic temperature.")
109 END IF
110 END SUBROUTINE qs_fod_validate
111
112! **************************************************************************************************
113!> \brief Print the orbital FOD sum and, optionally, its real-space density.
114!> \param input FORCE_EVAL input section.
115!> \param logger Output logger.
116!> \param qs_env Quickstep environment; the SCF orbitals and density are not modified.
117!> \param output_unit Main output unit, nonpositive on non-writing ranks.
118! **************************************************************************************************
119 SUBROUTINE qs_scf_post_fod(input, logger, qs_env, output_unit)
120 TYPE(section_vals_type), POINTER :: input
121 TYPE(cp_logger_type), POINTER :: logger
122 TYPE(qs_environment_type), POINTER :: qs_env
123 INTEGER, INTENT(IN) :: output_unit
124
125 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_post_fod'
126
127 INTEGER :: handle, iatom, ikind, ispin, unit_nr
128 LOGICAL :: write_cube
129 REAL(dp) :: grid_integral, nfod, spin_integral
130 REAL(dp), ALLOCATABLE, DIMENSION(:) :: weights, zcharge
131 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao
132 TYPE(dbcsr_type), POINTER :: matrix_fod
133 TYPE(mo_set_type) :: mo_fod
134 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
135 TYPE(particle_list_type), POINTER :: particles
136 TYPE(pw_c1d_gs_type) :: tmp_g
137 TYPE(pw_env_type), POINTER :: pw_env
138 TYPE(pw_pool_type), POINTER :: pool
139 TYPE(pw_r3d_rs_type) :: fod_r, tmp_r
140 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
141 TYPE(qs_ks_env_type), POINTER :: ks_env
142 TYPE(qs_rho_type), POINTER :: rho
143 TYPE(qs_subsys_type), POINTER :: subsys
144 TYPE(scf_control_type), POINTER :: scf_control
145 TYPE(section_vals_type), POINTER :: fod_section
146
147 fod_section => section_vals_get_subs_vals(input, "DFT%PRINT%FOD")
148 IF (.NOT. btest(cp_print_key_should_output(logger%iter_info, fod_section, ""), cp_p_file)) RETURN
149 CALL timeset(routinen, handle)
150 CALL qs_fod_validate(input, logger, qs_env)
151 CALL get_qs_env(qs_env, mos=mos, scf_control=scf_control)
152 cpassert(ASSOCIATED(mos))
153 CALL cite_reference(grimme2015fod)
154 CALL section_vals_val_get(fod_section, "CUBE", l_val=write_cube)
155
156 NULLIFY (rho, rho_ao, ks_env, pw_env, pool, subsys, particles, matrix_fod)
157 IF (write_cube) THEN
158 CALL get_qs_env(qs_env, rho=rho, ks_env=ks_env, pw_env=pw_env, subsys=subsys, qs_kind_set=qs_kind_set)
159 CALL qs_rho_get(rho, rho_ao=rho_ao)
160 CALL qs_subsys_get(subsys, particles=particles)
161 ALLOCATE (zcharge(particles%n_els))
162 DO iatom = 1, particles%n_els
163 ikind = particles%els(iatom)%atomic_kind%kind_number
164 CALL get_qs_kind(qs_kind_set(ikind), zeff=zcharge(iatom))
165 END DO
166 CALL pw_env_get(pw_env, auxbas_pw_pool=pool)
167 CALL pool%create_pw(fod_r)
168 CALL pool%create_pw(tmp_r)
169 CALL pool%create_pw(tmp_g)
170 fod_r%array = 0.0_dp
171 END IF
172
173 nfod = 0.0_dp
174 grid_integral = 0.0_dp
175 DO ispin = 1, SIZE(mos)
176 cpassert(mos(ispin)%nmo > 0)
177 IF (mos(ispin)%occupation_numbers(mos(ispin)%nmo) > &
178 mos(ispin)%maxocc*scf_control%smear%eps_fermi_dirac) THEN
179 cpwarn("FOD: the highest available orbital is occupied; increase ADDED_MOS and check convergence.")
180 END IF
181 ALLOCATE (weights(mos(ispin)%nmo))
182 weights(:) = fod_weights(mos(ispin)%occupation_numbers, mos(ispin)%eigenvalues, &
183 mos(ispin)%mu, mos(ispin)%maxocc)
184 nfod = nfod + sum(weights)
185 IF (write_cube) THEN
186 CALL duplicate_mo_set(mo_fod, mos(ispin))
187 mo_fod%occupation_numbers = weights
188 mo_fod%uniform_occupation = .false.
189 ! Include every supplied orbital, including the fractional virtual tail.
190 mo_fod%homo = mo_fod%nmo
191 ALLOCATE (matrix_fod)
192 CALL dbcsr_copy(matrix_fod, rho_ao(ispin)%matrix)
193 CALL calculate_density_matrix(mo_fod, matrix_fod)
194 CALL calculate_rho_elec(matrix_p=matrix_fod, rho=tmp_r, rho_gspace=tmp_g, &
195 total_rho=spin_integral, ks_env=ks_env)
196 fod_r%array = fod_r%array + tmp_r%array
197 ! calculate_rho_elec returns electronic charge, not electron count.
198 grid_integral = grid_integral - spin_integral
199 CALL dbcsr_release(matrix_fod)
200 DEALLOCATE (matrix_fod)
201 CALL deallocate_mo_set(mo_fod)
202 END IF
203 DEALLOCATE (weights)
204 END DO
205
206 IF (output_unit > 0) THEN
207 WRITE (output_unit, '(T2,A,T61,F20.10)') "FOD| N_FOD (orbital sum)", nfod
208 IF (write_cube) WRITE (output_unit, '(T2,A,T61,F20.10)') "FOD| Grid integral", grid_integral
209 END IF
210 IF (write_cube) THEN
211 unit_nr = cp_print_key_unit_nr(logger, fod_section, "", extension=".cube", &
212 middle_name="FOD", file_position="REWIND", log_filename=.false.)
213 ! Collective call: non-writing ranks must participate even with unit_nr=-1.
214 CALL cp_pw_to_cube(fod_r, unit_nr, "FRACTIONAL OCCUPATION DENSITY [e/bohr^3]", &
215 particles=particles, zeff=zcharge, stride=section_get_ivals(fod_section, "STRIDE"))
216 CALL cp_print_key_finished_output(unit_nr, logger, fod_section, "")
217 CALL pool%give_back_pw(fod_r)
218 CALL pool%give_back_pw(tmp_r)
219 CALL pool%give_back_pw(tmp_g)
220 DEALLOCATE (zcharge)
221 END IF
222 CALL timestop(handle)
223 END SUBROUTINE qs_scf_post_fod
224END MODULE qs_fod
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public grimme2015fod
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_release(matrix)
...
various routines to log and control the output. The idea is that decisions about where to log should ...
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_pw_to_cube(pw, unit_nr, title, particles, zeff, stride, max_file_size_mb, zero_tails, silent, mpi_io)
...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public smear_fermi_dirac
objects that represent the structure of input sections and the data contained in an input section
integer function, dimension(:), pointer, public section_get_ivals(section_vals, keyword_name)
...
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
represent a simple array based list of the given type
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_rho_elec(matrix_p, matrix_p_kp, rho, rho_gspace, total_rho, ks_env, soft_valid, compute_tau, compute_grad, basis_type, der_type, idir, task_list_external, pw_env_external)
computes the density corresponding to a given density matrix on the grid
collects routines that calculate density matrices
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.
Fractional occupation number weighted density (Grimme and Hansen).
Definition qs_fod.F:12
subroutine, public qs_fod_validate(input, logger, qs_env)
Reject unsupported FOD settings before starting an expensive SCF calculation.
Definition qs_fod.F:89
pure real(dp) function, dimension(size(occupation)), public fod_weights(occupation, eigenvalues, mu, maxocc)
Hole weights below the chemical potential, particle weights above it.
Definition qs_fod.F:71
subroutine, public qs_scf_post_fod(input, logger, qs_env, output_unit)
Print the orbital FOD sum and, optionally, its real-space density.
Definition qs_fod.F:120
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
subroutine, public duplicate_mo_set(mo_set_new, mo_set_old)
allocate a new mo_set, and copy the old data
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction 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...
types that represent a quickstep subsys
subroutine, public qs_subsys_get(subsys, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...
parameters that control an scf iteration
type of a logger, at the moment it contains just a print level starting at which level it should be l...
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
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.