55#include "./base/base_uses.f90"
60 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_kpoint_state'
78 INTEGER :: ikpoint_local, ispin, nao, nmo, nocc
79 LOGICAL :: use_real_wfn
80 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: density_eigenvalues
81 TYPE(
cp_cfm_type) :: density_metric, density_work, matrix_p, &
82 matrix_s, matrix_s_work, projected
85 TYPE(
cp_fm_type),
POINTER :: mo_coeff_im, mo_coeff_re
88 NULLIFY (active_struct, kp, mo_coeff_im, mo_coeff_re, square_struct)
90 cpassert(
ASSOCIATED(kpoints))
91 cpassert(
ASSOCIATED(kpoints%kp_env))
93 IF (use_real_wfn)
THEN
94 cpabort(
"Fixed-density k-point OT initialization requires complex wavefunctions.")
97 DO ikpoint_local = 1,
SIZE(kpoints%kp_env)
98 kp => kpoints%kp_env(ikpoint_local)%kpoint_env
99 cpassert(
ASSOCIATED(kp))
100 cpassert(
ASSOCIATED(kp%mos))
101 cpassert(
ASSOCIATED(kp%ot_hmat))
102 cpassert(
ASSOCIATED(kp%ot_smat))
103 cpassert(
SIZE(kp%ot_hmat, 1) >= 2)
104 cpassert(
SIZE(kp%ot_hmat, 2) >=
SIZE(kp%mos, 2))
105 cpassert(
SIZE(kp%ot_smat) >= 2)
107 CALL cp_fm_get_info(kp%ot_hmat(1, 1), matrix_struct=square_struct, nrow_global=nao)
108 CALL cp_cfm_create(matrix_p, square_struct, name=
"natural-orbital density P(k)")
109 CALL cp_cfm_create(matrix_s, square_struct, name=
"natural-orbital overlap S(k)")
110 CALL cp_fm_to_cfm(kp%ot_smat(1), kp%ot_smat(2), matrix_s)
112 DO ispin = 1,
SIZE(kp%mos, 2)
113 CALL get_mo_set(kp%mos(1, ispin), homo=nocc, mo_coeff=mo_coeff_re, nmo=nmo)
114 CALL get_mo_set(kp%mos(2, ispin), mo_coeff=mo_coeff_im)
115 cpassert(
ASSOCIATED(mo_coeff_re))
116 cpassert(
ASSOCIATED(mo_coeff_im))
117 cpassert(nocc >= 1 .AND. nocc <= nmo)
121 CALL cp_fm_to_cfm(kp%ot_hmat(1, ispin), kp%ot_hmat(2, ispin), matrix_p)
122 CALL cp_cfm_create(projected, active_struct, name=
"fixed-density natural orbitals")
123 CALL cp_cfm_create(density_metric, square_struct, name=
"natural-orbital metric")
124 CALL cp_cfm_create(density_work, square_struct, name=
"natural-orbital work")
125 CALL cp_cfm_create(matrix_s_work, square_struct, name=
"natural-orbital overlap work")
136 ALLOCATE (density_eigenvalues(nocc))
137 CALL cp_cfm_geeig(density_metric, matrix_s_work, projected, &
138 density_eigenvalues, density_work, lowest_subset=.true.)
139 DEALLOCATE (density_eigenvalues)
141 CALL cp_fm_create(active_re, active_struct, name=
"fixed-density orbitals real")
142 CALL cp_fm_create(active_im, active_struct, name=
"fixed-density orbitals imaginary")
174 INTEGER :: ikpoint_local, ispin, nao, nmo, nocc
175 LOGICAL :: use_real_wfn
176 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: ritz_values
177 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues_im, eigenvalues_re
178 TYPE(
cp_cfm_type) :: coeff, eigenvectors, hblock, hc, &
182 TYPE(
cp_fm_type),
POINTER :: mo_coeff_im, mo_coeff_re
185 NULLIFY (active_struct, eigenvalues_im, eigenvalues_re, kp, mo_coeff_im, mo_coeff_re, &
188 cpassert(
ASSOCIATED(kpoints))
189 cpassert(
ASSOCIATED(kpoints%kp_env))
191 IF (use_real_wfn)
THEN
192 cpabort(
"Fixed-density k-point OT canonicalization requires complex wavefunctions.")
195 DO ikpoint_local = 1,
SIZE(kpoints%kp_env)
196 kp => kpoints%kp_env(ikpoint_local)%kpoint_env
197 cpassert(
ASSOCIATED(kp))
198 cpassert(
ASSOCIATED(kp%mos))
199 cpassert(
ASSOCIATED(kp%ot_hmat))
200 cpassert(
SIZE(kp%ot_hmat, 1) >= 2)
201 cpassert(
SIZE(kp%ot_hmat, 2) >=
SIZE(kp%mos, 2))
203 CALL cp_fm_get_info(kp%ot_hmat(1, 1), matrix_struct=square_struct, nrow_global=nao)
204 CALL cp_cfm_create(matrix_h, square_struct, name=
"fixed-density Ritz Hamiltonian")
206 DO ispin = 1,
SIZE(kp%mos, 2)
207 CALL get_mo_set(kp%mos(1, ispin), homo=nocc, mo_coeff=mo_coeff_re, nmo=nmo, &
208 eigenvalues=eigenvalues_re)
209 CALL get_mo_set(kp%mos(2, ispin), mo_coeff=mo_coeff_im, &
210 eigenvalues=eigenvalues_im)
211 cpassert(
ASSOCIATED(mo_coeff_re))
212 cpassert(
ASSOCIATED(mo_coeff_im))
213 cpassert(
ASSOCIATED(eigenvalues_re))
214 cpassert(
ASSOCIATED(eigenvalues_im))
215 cpassert(nocc >= 1 .AND. nocc <= nmo)
216 cpassert(
SIZE(eigenvalues_re) >= nocc)
217 cpassert(
SIZE(eigenvalues_im) >= nocc)
221 CALL cp_fm_create(active_re, active_struct, name=
"fixed-density Ritz orbitals real")
222 CALL cp_fm_create(active_im, active_struct, name=
"fixed-density Ritz orbitals imaginary")
226 CALL cp_cfm_create(coeff, active_struct, name=
"fixed-density Ritz orbitals")
227 CALL cp_cfm_create(hc, active_struct, name=
"fixed-density Ritz HC")
228 CALL cp_cfm_create(rotated, active_struct, name=
"fixed-density Ritz rotated orbitals")
229 CALL cp_cfm_create(hblock, active_struct, nrow=nocc, ncol=nocc, &
230 name=
"fixed-density projected Hamiltonian")
231 CALL cp_cfm_create(eigenvectors, active_struct, nrow=nocc, ncol=nocc, &
232 name=
"fixed-density Ritz eigenvectors")
233 CALL cp_fm_to_cfm(kp%ot_hmat(1, ispin), kp%ot_hmat(2, ispin), matrix_h)
238 ALLOCATE (ritz_values(nocc))
245 eigenvalues_re(1:nocc) = ritz_values
246 eigenvalues_im(1:nocc) = ritz_values
247 DEALLOCATE (ritz_values)
272 separate_spin_occupations, fixed_occupations)
274 LOGICAL,
INTENT(IN) :: update_occupations
275 LOGICAL,
INTENT(IN),
OPTIONAL :: separate_spin_occupations, &
279 LOGICAL :: fixed, separate_spins
280 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s_kp, rho_ao_kp
290 NULLIFY (energy, kpoints, matrix_s_kp, mos, rho_ao_kp, sab_nl, rho, scf_env, scf_control)
293 separate_spins = .false.
294 IF (
PRESENT(fixed_occupations)) fixed = fixed_occupations
295 IF (
PRESENT(separate_spin_occupations)) separate_spins = separate_spin_occupations
296 IF (fixed .AND. .NOT. update_occupations)
THEN
297 cpabort(
"Fixed occupations can only be requested while updating occupations.")
300 CALL get_qs_env(qs_env, kpoints=kpoints, matrix_s_kp=matrix_s_kp, &
301 energy=energy, rho=rho, scf_env=scf_env, scf_control=scf_control)
304 IF (update_occupations)
THEN
306 kpoints, scf_control%smear, separate_spin_occupations=separate_spins)
307 IF (fixed)
CALL qs_kpoint_set_fixed_occupations(kpoints)
312 matrix_s_kp(1, 1)%matrix, sab_nl, scf_env%scf_work1, &
313 overlap_rs=matrix_s_kp)
318 energy%efermi = 0.0_dp
319 mos => kpoints%kp_env(1)%kpoint_env%mos
320 cpassert(
ASSOCIATED(mos))
321 DO ispin = 1,
SIZE(mos, 2)
322 energy%kTS = energy%kTS + mos(1, ispin)%kTS
323 energy%efermi = energy%efermi + mos(1, ispin)%mu
325 energy%efermi = energy%efermi/real(
SIZE(mos, 2), kind=
dp)
337 LOGICAL,
INTENT(IN),
OPTIONAL :: require_full_space
338 LOGICAL :: initialized
340 INTEGER :: icomponent, ikpoint_local, ispin, &
342 LOGICAL :: full_space
343 REAL(kind=
dp) :: coefficient_norm
344 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: column_norm, component_norm
349 NULLIFY (kp, mo_coeff, para_env)
350 cpassert(
ASSOCIATED(kpoints))
351 cpassert(
ASSOCIATED(kpoints%kp_env))
354 IF (
PRESENT(require_full_space)) full_space = require_full_space
355 coefficient_norm = huge(1.0_dp)
356 DO ikpoint_local = 1,
SIZE(kpoints%kp_env)
357 kp => kpoints%kp_env(ikpoint_local)%kpoint_env
358 cpassert(
ASSOCIATED(kp))
359 cpassert(
ASSOCIATED(kp%mos))
360 DO ispin = 1,
SIZE(kp%mos, 2)
361 CALL get_mo_set(kp%mos(1, ispin), homo=nocc, mo_coeff=mo_coeff, nmo=nmo)
362 cpassert(
ASSOCIATED(mo_coeff))
363 nactive = merge(nmo, nocc, full_space)
364 IF (nactive < 1 .OR. nactive > nmo)
THEN
365 coefficient_norm = 0.0_dp
368 ALLOCATE (column_norm(nmo), component_norm(nmo))
369 column_norm(:) = 0.0_dp
370 DO icomponent = 1,
SIZE(kp%mos, 1)
371 CALL get_mo_set(kp%mos(icomponent, ispin), mo_coeff=mo_coeff)
372 cpassert(
ASSOCIATED(mo_coeff))
374 column_norm(:) = column_norm(:) + component_norm(:)**2
376 coefficient_norm = min(coefficient_norm, sqrt(minval(column_norm(1:nactive))))
377 DEALLOCATE (column_norm, component_norm)
382 cpassert(
ASSOCIATED(para_env))
383 CALL para_env%min(coefficient_norm)
384 initialized = coefficient_norm > 100.0_dp*epsilon(1.0_dp)
395 INTEGER,
INTENT(IN) :: nspin
397 INTEGER :: icomponent, ikpoint_local, ispin
398 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues_source, eigenvalues_target
399 TYPE(
cp_fm_type),
POINTER :: mo_coeff_source, mo_coeff_target
402 NULLIFY (eigenvalues_source, eigenvalues_target, kp, mo_coeff_source, mo_coeff_target)
403 cpassert(
ASSOCIATED(kpoints))
404 cpassert(
ASSOCIATED(kpoints%kp_env))
407 DO ikpoint_local = 1,
SIZE(kpoints%kp_env)
408 kp => kpoints%kp_env(ikpoint_local)%kpoint_env
409 cpassert(
ASSOCIATED(kp))
410 cpassert(
ASSOCIATED(kp%mos))
411 cpassert(
SIZE(kp%mos, 2) >= nspin)
412 DO icomponent = 1,
SIZE(kp%mos, 1)
413 CALL get_mo_set(kp%mos(icomponent, 1), mo_coeff=mo_coeff_source, &
414 eigenvalues=eigenvalues_source)
415 cpassert(
ASSOCIATED(mo_coeff_source))
416 cpassert(
ASSOCIATED(eigenvalues_source))
418 CALL get_mo_set(kp%mos(icomponent, ispin), mo_coeff=mo_coeff_target, &
419 eigenvalues=eigenvalues_target)
420 cpassert(
ASSOCIATED(mo_coeff_target))
421 cpassert(
ASSOCIATED(eigenvalues_target))
423 eigenvalues_target(:) = eigenvalues_source(:)
434 SUBROUTINE qs_kpoint_set_fixed_occupations(kpoints)
437 INTEGER :: icomponent, ikpoint_local, ispin, &
439 REAL(kind=
dp) :: maxocc
440 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occupation_numbers
443 NULLIFY (kp, occupation_numbers)
444 cpassert(
ASSOCIATED(kpoints))
445 cpassert(
ASSOCIATED(kpoints%kp_env))
447 DO ikpoint_local = 1,
SIZE(kpoints%kp_env)
448 kp => kpoints%kp_env(ikpoint_local)%kpoint_env
449 cpassert(
ASSOCIATED(kp))
450 cpassert(
ASSOCIATED(kp%mos))
451 DO ispin = 1,
SIZE(kp%mos, 2)
452 DO icomponent = 1,
SIZE(kp%mos, 1)
453 CALL get_mo_set(kp%mos(icomponent, ispin), homo=nocc, maxocc=maxocc, &
454 nelectron=nelectron, nmo=nmo, occupation_numbers=occupation_numbers)
455 cpassert(
ASSOCIATED(occupation_numbers))
456 IF (nocc < 1 .OR. nocc > nmo)
THEN
457 cpabort(
"Fixed-occupation k-point OT requires a nonempty occupied subspace.")
459 IF (abs(maxocc*real(nocc, kind=
dp) - real(nelectron, kind=
dp)) > &
460 100.0_dp*epsilon(1.0_dp))
THEN
461 cpabort(
"Fixed-occupation k-point OT requires uniform integer occupations.")
463 occupation_numbers(:) = 0.0_dp
464 occupation_numbers(1:nocc) = maxocc
465 kp%mos(icomponent, ispin)%kTS = 0.0_dp
470 END SUBROUTINE qs_kpoint_set_fixed_occupations
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_gemm(transa, transb, m, n, k, alpha, matrix_a, matrix_b, beta, matrix_c, a_first_col, a_first_row, b_first_col, b_first_row, c_first_col, c_first_row)
Performs one of the matrix-matrix operations: matrix_c = alpha * op1( matrix_a ) * op2( matrix_b ) + ...
used for collecting diagonalization schemes available for cp_cfm_type
subroutine, public cp_cfm_heevd(matrix, eigenvectors, eigenvalues)
Perform a diagonalisation of a complex matrix.
subroutine, public cp_cfm_geeig(amatrix, bmatrix, eigenvectors, eigenvalues, work, lowest_subset)
General Eigenvalue Problem AX = BXE Single option version: Cholesky decomposition of B.
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_fm_to_cfm(msourcer, msourcei, mtarget)
Construct a complex full matrix by taking its real and imaginary parts from two separate real-value f...
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
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
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
subroutine, public cp_fm_vectorsnorm(matrix, norm_array)
find the inorm of each column norm_{j}= sqrt( \sum_{i} A_{ij}*A_{ij} )
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
Defines the basic variable types.
integer, parameter, public dp
Routines needed for kpoint calculation.
subroutine, public kpoint_density_transform(kpoint, denmat, wtype, tempmat, sab_nl, fmwork, for_aux_fit, pmat_ext, overlap_rs)
generate real space density matrices in DBCSR format
subroutine, public kpoint_set_mo_occupation(kpoint, smear, probe, added_mos_auto, added_mos_auto_grow, separate_spin_occupations)
Given the eigenvalues of all kpoints, calculates the occupation numbers.
subroutine, public kpoint_density_matrices(kpoint, energy_weighted, for_aux_fit)
Calculate kpoint density matrices (rho(k), owned by kpoint groups).
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered, lattice_fft)
Retrieve information from a kpoint environment.
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public z_zero
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.
Methods for preparing and committing k-point orbital states to the QS environment.
subroutine, public qs_kpoint_state_commit(qs_env, update_occupations, separate_spin_occupations, fixed_occupations)
Rebuilds the physical density from the current k-point orbitals and occupations.
subroutine, public qs_kpoint_state_prepare_fixed_density(kpoints)
Reconstructs fixed-rank complex k-point orbitals from a density kernel. The density and overlap must ...
logical function, public qs_kpoint_mos_initialized(kpoints, require_full_space)
Checks whether every local k-point channel contains nonzero occupied orbitals.
subroutine, public qs_kpoint_copy_spin_mos(kpoints, nspin)
Copies the first k-point spin channel into the remaining channels.
subroutine, public qs_kpoint_state_canonicalize_fixed(kpoints)
Rotates a uniformly occupied k-point subspace into Ritz states of the current Hamiltonian and stores ...
subroutine, public qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, potential_changed, full_reset)
tells that some of the things relevant to the ks calculation did change. has to be called when change...
Definition and initialisation of the mo data type.
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.
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_update_rho(rho_struct, qs_env, rho_xc_external, local_rho_set, task_list_external, task_list_external_soft, pw_env_external, para_env_external)
updates rho_r and rho_g to the rhorho_ao. if use_kinetic_energy_density also computes tau_r and tau_g...
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...
module that contains the definitions of the scf types
parameters that control an scf iteration
Represent a complex full matrix.
keeps the information about the structure of a full matrix
Keeps information about a specific k-point.
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.