61#include "./base/base_uses.f90"
67 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_energy_window'
83 CHARACTER(len=*),
PARAMETER :: routinen =
'energy_windows'
84 LOGICAL,
PARAMETER :: debug = .false.
85 REAL(kind=
dp),
PARAMETER :: one = 1.0_dp, zero = 0.0_dp
87 CHARACTER(len=40) :: ext, title
88 INTEGER :: handle, i, lanzcos_max_iter, last, nao, &
89 nelectron_total, newton_schulz_order, &
90 next, nwindows, print_unit, unit_nr
91 INTEGER,
DIMENSION(:),
POINTER :: stride(:)
92 LOGICAL :: mpi_io, print_cube, restrict_range
93 REAL(kind=
dp) :: bin_width, density_ewindow_total, density_total, energy_range, fermi_level, &
94 filter_eps, frob_norm, lanzcos_threshold, lower_bound, occupation, upper_bound
95 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues, p_eigenvalues, &
99 TYPE(
cp_fm_type) :: eigenvectors, eigenvectors_nonorth, matrix_ks_fm, p_eigenvectors, &
100 p_window_fm, rho_ao_ortho_fm, s_minus_half_fm, tmp_fm, window_eigenvectors, window_fm
102 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s, rho_ao
103 TYPE(
dbcsr_type) :: matrix_ks_nosym, s_half, s_minus_half, &
105 TYPE(
dbcsr_type),
POINTER :: rho_ao_ortho, window
116 CALL timeset(routinen, handle)
120 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env, matrix_ks=matrix_ks, pw_env=pw_env, rho=rho, &
121 input=input, nelectron_total=nelectron_total, subsys=subsys, ks_env=ks_env, matrix_s=matrix_s)
123 CALL qs_rho_get(rho_struct=rho, rho_ao=rho_ao)
124 IF (
SIZE(rho_ao) > 1)
CALL cp_warn(__location__, &
125 "The printing of energy windows is currently only implemented for clsoe shell systems")
126 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
133 CALL section_vals_val_get(dft_section,
"PRINT%ENERGY_WINDOWS%RESTRICT_RANGE", l_val=restrict_range)
144 ALLOCATE (window, rho_ao_ortho)
145 CALL dbcsr_get_info(matrix=matrix_ks(1)%matrix, nfullrows_total=nao)
146 ALLOCATE (eigenvalues(nao))
147 CALL dbcsr_create(tmp, template=matrix_s(1)%matrix, matrix_type=
"N")
148 CALL dbcsr_create(s_minus_half, template=matrix_s(1)%matrix, matrix_type=
"N")
149 CALL dbcsr_create(s_half, template=matrix_s(1)%matrix, matrix_type=
"N")
150 CALL dbcsr_create(window, template=matrix_s(1)%matrix, matrix_type=
"N")
151 CALL dbcsr_create(rho_ao_ortho, template=matrix_s(1)%matrix, matrix_type=
"N")
152 CALL cp_fm_struct_create(fmstruct=ao_ao_fmstruct, context=blacs_env, nrow_global=nao, ncol_global=nao)
159 CALL auxbas_pw_pool%create_pw(rho_r)
160 CALL auxbas_pw_pool%create_pw(rho_g)
164 newton_schulz_order, lanzcos_threshold, lanzcos_max_iter)
170 CALL dbcsr_multiply(
"N",
"N", one, s_minus_half, matrix_ks_nosym, zero, tmp, filter_eps=filter_eps)
171 CALL dbcsr_multiply(
"N",
"N", one, tmp, s_minus_half, zero, matrix_ks_nosym, filter_eps=filter_eps)
173 CALL dbcsr_multiply(
"N",
"N", one, s_half, rho_ao(1)%matrix, zero, tmp, filter_eps=filter_eps)
174 CALL dbcsr_multiply(
"N",
"N", one, tmp, s_half, zero, rho_ao_ortho, filter_eps=filter_eps)
179 fermi_level = eigenvalues((nelectron_total + mod(nelectron_total, 2))/2)
180 IF (restrict_range)
THEN
181 lower_bound = max(fermi_level - energy_range, eigenvalues(1))
182 upper_bound = min(fermi_level + energy_range, eigenvalues(
SIZE(eigenvalues)))
184 lower_bound = eigenvalues(1)
185 upper_bound = eigenvalues(
SIZE(eigenvalues))
187 IF (unit_nr > 0)
THEN
188 WRITE (unit_nr, *)
" Creating energy windows. Fermi level: ", fermi_level
189 WRITE (unit_nr, *)
" Printing Energy Levels from ", lower_bound,
" to ", upper_bound
194 CALL parallel_gemm(
"N",
"N", nao, nao, nao, one, s_minus_half_fm, eigenvectors, zero, eigenvectors_nonorth)
199 ncol_global=nelectron_total/2)
201 CALL cp_fm_to_fm(eigenvectors_nonorth, window_fm, nelectron_total/2, 1, 1)
202 CALL parallel_gemm(
"N",
"T", nao, nao, nelectron_total/2, 2*one, window_fm, window_fm, zero, p_window_fm)
206 CALL dbcsr_copy(window, tmp, keep_sparsity=.true.)
212 IF (unit_nr > 0)
WRITE (unit_nr, *)
" Ground-state density: ", density_total
214 IF (unit_nr > 0)
WRITE (unit_nr, *)
" Frob norm of calculated ground-state density matrix: ", frob_norm
215 CALL dbcsr_add(window, rho_ao(1)%matrix, one, -one)
217 IF (unit_nr > 0)
WRITE (unit_nr, *)
" Frob norm of current density matrix: ", frob_norm
219 IF (unit_nr > 0)
WRITE (unit_nr, *)
" Difference between calculated ground-state density and current density: ", frob_norm
224 ALLOCATE (p_eigenvalues(nao))
227 ALLOCATE (window_eigenvalues(nao))
228 CALL cp_fm_to_fm(eigenvectors, window_fm, nelectron_total/2, 1, 1)
229 CALL parallel_gemm(
"N",
"T", nao, nao, nelectron_total/2, 2*one, window_fm, window_fm, zero, p_window_fm)
232 IF (unit_nr > 0)
THEN
233 WRITE (unit_nr, *) i,
"H:", eigenvalues(i),
"P:", p_eigenvalues(nao - i + 1),
"Pnew:", window_eigenvalues(nao - i + 1)
236 DEALLOCATE (p_eigenvalues)
239 DEALLOCATE (window_eigenvalues)
245 bin_width = (upper_bound - lower_bound)/nwindows
249 DO WHILE (eigenvalues(next + 1) < lower_bound)
253 DO WHILE (eigenvalues(next + 1) < lower_bound + i*bin_width)
255 IF (next ==
SIZE(eigenvalues))
EXIT
259 CALL cp_fm_struct_create(fmstruct=window_fm_struct, context=blacs_env, nrow_global=nao, ncol_global=next - last)
262 CALL cp_fm_to_fm(eigenvectors, window_fm, next - last, last + 1, 1)
263 CALL parallel_gemm(
"N",
"T", nao, nao, next - last, one, window_fm, window_fm, zero, p_window_fm)
264 CALL cp_fm_trace(p_window_fm, rho_ao_ortho_fm, occupation)
266 CALL cp_fm_to_fm(eigenvectors_nonorth, window_fm, next - last, last + 1, 1)
269 CALL parallel_gemm(
"N",
"T", nao, nao, next - last, one, window_fm, window_fm, zero, p_window_fm)
273 CALL dbcsr_copy(window, tmp, keep_sparsity=.true.)
278 WRITE (ext,
"(A14,I5.5,A)")
"-ENERGY-WINDOW", i, trim(
cp_iter_string(logger%iter_info))//
".cube"
281 extension=ext, file_status=
"REPLACE", file_action=
"WRITE", &
282 log_filename=.false., mpi_io=mpi_io)
283 WRITE (title,
"(A14,I5)")
"ENERGY WINDOW ", i
284 CALL cp_pw_to_cube(rho_r, print_unit, title, particles=particles, stride=stride, mpi_io=mpi_io)
286 "PRINT%ENERGY_WINDOWS", mpi_io=mpi_io)
288 IF (unit_nr > 0)
WRITE (unit_nr,
"(A,F16.10,A,I5,A,F20.14,A,F20.14)")
" Energy Level: ", &
289 lower_bound + (i - 0.5_dp)*bin_width,
" Number of states: ", next - last,
" Occupation: ", &
290 occupation,
" Grid Density ", density_ewindow_total
292 IF (unit_nr > 0)
THEN
293 WRITE (unit_nr,
"(A,F16.10,A,I5,A,F20.14)")
" Energy Level: ", lower_bound + (i - 0.5_dp)*bin_width, &
294 " Number of states: ", next - last,
" Occupation: ", occupation
308 DEALLOCATE (window, rho_ao_ortho)
316 CALL auxbas_pw_pool%give_back_pw(rho_r)
317 CALL auxbas_pw_pool%give_back_pw(rho_g)
318 DEALLOCATE (eigenvalues)
321 CALL timestop(handle)
methods related to the blacs parallel environment
subroutine, public dbcsr_desymmetrize(matrix_a, matrix_b)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
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)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
real(dp) function, public dbcsr_frobenius_norm(matrix)
Compute the frobenius norm of a dbcsr matrix.
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
basic linear algebra operations for full matrices
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
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_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
character(len=default_string_length) function, public cp_iter_string(iter_info, print_key, for_file)
returns the iteration string, a string that is useful to create unique filenames (once you trim it)
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,...
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_pw_to_cube(pw, unit_nr, title, particles, stride, zero_tails, silent, mpi_io)
...
Routines useful for iterative matrix calculations.
subroutine, public matrix_sqrt_newton_schulz(matrix_sqrt, matrix_sqrt_inv, matrix, threshold, order, eps_lanczos, max_iter_lanczos, symmetrize, converged, iounit)
compute the sqrt of a matrix via the sign function and the corresponding Newton-Schulz iterations the...
Defines the basic variable types.
integer, parameter, public dp
basic linear algebra operations for full matrixes
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
Does all kind of post scf calculations for GPW/GAPW.
subroutine, public energy_windows(qs_env)
...
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, 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, 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, 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, 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, ecoul_1c, rho0_s_rs, rho0_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)
Get the QUICKSTEP environment.
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)
...
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represent a list of objects
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 ...
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.