56 integrate_v_core_rspace,&
66#include "./base/base_uses.f90"
72 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_harris_methods'
86 LOGICAL,
INTENT(IN) :: calculate_forces
88 CHARACTER(LEN=*),
PARAMETER :: routinen =
'harris_energy_correction'
90 INTEGER :: handle, iounit, ispin, nspins
91 REAL(kind=
dp) :: dvol, ec, eh, exc, vxc
103 mark_used(calculate_forces)
105 CALL timeset(routinen, handle)
107 CALL get_qs_env(qs_env, harris_env=harris_env, energy=ks_energy)
108 energy => harris_env%energy
109 IF (harris_env%direct_density_matrix_energy)
THEN
110 IF (calculate_forces)
THEN
111 cpabort(
"Forces are not available for the direct fitted-density-matrix energy")
113 ks_energy%nonscf_correction = energy%direct_harris - ks_energy%total
114 ks_energy%total = energy%direct_harris
115 CALL timestop(handle)
118 IF (calculate_forces .AND. (harris_env%density_source ==
hden_cube .OR. &
120 cpabort(
"Forces are not available for a Harris energy based on an external cube density")
122 energy%eband = ks_energy%band
123 energy%ewald_correction = ks_energy%core_overlap + ks_energy%core_self
124 energy%dispersion = ks_energy%dispersion
126 nspins = harris_env%rhoin%nspin
128 CALL get_qs_env(qs_env, rho=rho, rho_core=rho_core)
132 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
133 CALL auxbas_pw_pool%create_pw(core_rspace)
136 dvol = harris_env%vh_rspace%pw_grid%dvol
142 eh = 0.5_dp*(eh + ec)
143 energy%eh_correction = ec - eh
147 IF (
ASSOCIATED(harris_env%vxc_rspace))
THEN
149 vxc = vxc +
pw_integral_ab(rho_r(ispin), harris_env%vxc_rspace(ispin))/ &
150 harris_env%vxc_rspace(ispin)%pw_grid%dvol
153 energy%exc_correction = exc - vxc
156 energy%eharris = energy%eband + energy%eh_correction + energy%exc_correction + &
157 energy%ewald_correction + energy%dispersion
159 CALL auxbas_pw_pool%give_back_pw(core_rspace)
161 ks_energy%total = ks_energy%total + ks_energy%core
162 ks_energy%nonscf_correction = energy%eharris - ks_energy%total
163 ks_energy%total = energy%eharris
170 IF (calculate_forces)
THEN
171 CALL harris_forces(qs_env, iounit)
174 CALL timestop(handle)
190 CHARACTER(LEN=*),
PARAMETER :: routinen =
'harris_direct_density_matrix_energy'
192 INTEGER :: handle, iounit
193 REAL(kind=
dp) :: target_density_energy, &
195 REAL(kind=
dp),
DIMENSION(:),
POINTER :: tot_rho_r
204 CALL timeset(routinen, handle)
205 NULLIFY (harris_env, ks_energy, rho, rho_g, rho_r, tot_rho_r)
207 CALL get_qs_env(qs_env, harris_env=harris_env, energy=ks_energy, rho=rho)
209 cpassert(harris_env%density_fit_ready)
210 cpassert(
ASSOCIATED(harris_env%density_target_rspace%pw_grid))
212 energy => harris_env%energy
216 print_active=.false.)
217 energy%trial_dm = ks_energy%total
218 trial_density_energy = ks_energy%hartree + ks_energy%hartree_1c + &
219 ks_energy%exc + ks_energy%exc1 + &
220 ks_energy%exc_aux_fit + ks_energy%exc1_aux_fit
223 CALL qs_rho_get(rho, rho_r=rho_r, rho_g=rho_g, tot_rho_r=tot_rho_r)
224 cpassert(
SIZE(rho_r) == 1 .AND.
SIZE(rho_g) == 1)
225 CALL pw_copy(harris_env%density_target_rspace, rho_r(1))
228 CALL qs_rho_set(rho, rho_r_valid=.true., rho_g_valid=.true.)
229 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true., potential_changed=.true.)
231 print_active=.false.)
232 target_density_energy = ks_energy%hartree + ks_energy%hartree_1c + &
233 ks_energy%exc + ks_energy%exc1 + &
234 ks_energy%exc_aux_fit + ks_energy%exc1_aux_fit
236 energy%direct_harris = energy%trial_dm + target_density_energy - trial_density_energy
237 energy%direct_difference = energy%trial_dm - energy%direct_harris
238 energy%eharris = energy%direct_harris
239 ks_energy%nonscf_correction = energy%direct_harris - ks_energy%total
240 ks_energy%total = energy%direct_harris
246 CALL timestop(handle)
258 CHARACTER(LEN=*),
PARAMETER :: routinen =
'harris_relative_entropy_reconstruction'
261 REAL(kind=
dp),
DIMENSION(:),
POINTER :: tot_rho_r
268 CALL timeset(routinen, handle)
269 NULLIFY (harris_env, matrix_ks, rho, rho_g, rho_r, tot_rho_r)
271 CALL get_qs_env(qs_env, harris_env=harris_env, rho=rho)
273 cpassert(harris_env%density_target_ready)
274 cpassert(.NOT. harris_env%density_fit_ready)
278 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true., potential_changed=.true.)
280 print_active=.false.)
282 cpassert(
ASSOCIATED(matrix_ks) .AND.
SIZE(matrix_ks) == 1)
285 harris_env%fit_temperature, &
286 harris_env%fit_relative_entropy_weight, &
287 harris_env%fit_max_iter, harris_env%fit_eps, &
288 harris_env%fit_step_size, harris_env%fit_max_backtrack)
290 CALL qs_rho_get(rho, rho_r=rho_r, rho_g=rho_g, tot_rho_r=tot_rho_r)
291 cpassert(
SIZE(rho_r) == 1 .AND.
SIZE(rho_g) == 1)
292 CALL harris_env%density_fit_rspace%create(rho_r(1)%pw_grid)
293 CALL pw_copy(rho_r(1), harris_env%density_fit_rspace)
294 harris_env%density_fit_ready = .true.
295 CALL qs_rho_set(rho, rho_r_valid=.true., rho_g_valid=.true.)
296 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true., potential_changed=.true.)
298 CALL timestop(handle)
307 SUBROUTINE harris_forces(qs_env, iounit)
309 INTEGER,
INTENT(IN) :: iounit
311 CHARACTER(LEN=*),
PARAMETER :: routinen =
'harris_forces'
312 LOGICAL,
PARAMETER :: debug_forces = .true.
314 INTEGER :: handle, ispin, nspins
315 REAL(kind=
dp) :: ehartree
316 REAL(kind=
dp),
DIMENSION(3) :: fodeb
318 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: rhoh_ao, smat
328 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: fhxc_rspace, ftau, fxc, rho_r, rhoh_r, &
333 TYPE(
rho_atom_type),
DIMENSION(:),
POINTER :: rho0_atom_set, rho1_atom_set
336 CALL timeset(routinen, handle)
338 IF (debug_forces)
THEN
339 IF (iounit > 0)
WRITE (iounit,
"(/,T3,A)") &
340 "DEBUG:: Harris Method Forces (density dependent)"
343 CALL get_qs_env(qs_env, harris_env=harris_env, force=force, para_env=para_env)
344 nspins = harris_env%rhoin%nspin
346 CALL get_qs_env(qs_env, rho=rho, rho_core=rho_core, matrix_s=smat)
348 CALL qs_rho_get(rho, rho_ao=rhoh_ao, rho_r=rho_r, rho_g=rho_g)
349 ALLOCATE (scrm%matrix)
350 CALL dbcsr_create(scrm%matrix, template=rhoh_ao(1)%matrix)
354 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, ks_env=ks_env)
355 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
356 CALL auxbas_pw_pool%create_pw(vhxc_rspace)
358 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
360 CALL pw_copy(harris_env%vh_rspace, vhxc_rspace)
361 CALL pw_axpy(harris_env%vxc_rspace(ispin), vhxc_rspace)
362 CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
363 hmat=scrm, pmat=rhoh_ao(ispin), &
364 qs_env=qs_env, calculate_forces=.true.)
366 IF (debug_forces)
THEN
367 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
368 CALL para_env%sum(fodeb)
369 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: P*(Vh[in]+Vxc)", fodeb
373 DEALLOCATE (scrm%matrix)
374 CALL auxbas_pw_pool%give_back_pw(vhxc_rspace)
376 ALLOCATE (rhoh_r(nspins), rhoh_g(nspins))
378 CALL auxbas_pw_pool%create_pw(rhoh_r(ispin))
379 CALL auxbas_pw_pool%create_pw(rhoh_g(ispin))
381 CALL auxbas_pw_pool%create_pw(rhoh_tot_gspace)
382 CALL pw_copy(rho_core, rhoh_tot_gspace)
385 rho=rhoh_r(ispin), rho_gspace=rhoh_g(ispin))
386 CALL pw_axpy(rhoh_g(ispin), rhoh_tot_gspace)
391 CALL auxbas_pw_pool%create_pw(vhout_rspace)
392 CALL auxbas_pw_pool%create_pw(vhout_gspace)
393 CALL pw_env_get(pw_env, poisson_env=poisson_env)
398 CALL pw_scale(vhout_rspace, vhout_rspace%pw_grid%dvol)
400 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
401 CALL integrate_v_core_rspace(vhout_rspace, qs_env)
402 IF (debug_forces)
THEN
403 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
404 CALL para_env%sum(fodeb)
405 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: Vh[out]*dncore ", fodeb
408 ALLOCATE (fhxc_rspace(nspins))
410 CALL auxbas_pw_pool%create_pw(fhxc_rspace(ispin))
413 CALL pw_axpy(harris_env%vh_rspace, vhout_rspace, alpha=-1._dp, beta=1.0_dp)
417 CALL pw_axpy(rho_r(ispin), rhoh_r(ispin), alpha=-1._dp, beta=1.0_dp)
418 CALL pw_axpy(rho_g(ispin), rhoh_g(ispin), alpha=-1._dp, beta=1.0_dp)
422 NULLIFY (rho0_atom_set, rho1_atom_set)
425 IF (
ASSOCIATED(rhoh_r))
THEN
426 CALL qs_rho_set(rhoh, rho_r=rhoh_r, rho_r_valid=.true.)
428 IF (
ASSOCIATED(rhoh_g))
THEN
429 CALL qs_rho_set(rhoh, rho_g=rhoh_g, rho_g_valid=.true.)
431 IF (
ASSOCIATED(tauh_r))
THEN
432 CALL qs_rho_set(rhoh, tau_r=tauh_r, tau_r_valid=.true.)
435 CALL qs_fxc_create(qs_env, rho, rhoh, rho0_atom_set, xc_section, .false., &
436 fxc, ftau, rho1_atom_set)
439 cpassert(.NOT.
ASSOCIATED(ftau))
442 CALL pw_copy(vhout_rspace, fhxc_rspace(ispin))
443 IF (
ASSOCIATED(fxc))
THEN
444 CALL pw_scale(fxc(ispin), fxc(ispin)%pw_grid%dvol)
445 CALL pw_axpy(fxc(ispin), fhxc_rspace(ispin))
449 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
450 CALL calculate_harris_integrals(qs_env, harris_env%rhoin, fhxc_rspace, .true.)
451 IF (debug_forces)
THEN
452 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
453 CALL para_env%sum(fodeb)
454 IF (iounit > 0)
WRITE (iounit,
"(T3,A,T33,3F16.8)")
"DEBUG:: (dVh+fxc)*dn[in] ", fodeb
457 IF (
ASSOCIATED(fxc))
THEN
459 CALL auxbas_pw_pool%give_back_pw(fxc(ispin))
463 IF (
ASSOCIATED(ftau))
THEN
465 CALL auxbas_pw_pool%give_back_pw(ftau(ispin))
470 CALL auxbas_pw_pool%give_back_pw(rhoh_tot_gspace)
471 CALL auxbas_pw_pool%give_back_pw(vhout_rspace)
472 CALL auxbas_pw_pool%give_back_pw(vhout_gspace)
475 CALL auxbas_pw_pool%give_back_pw(rhoh_r(ispin))
476 CALL auxbas_pw_pool%give_back_pw(rhoh_g(ispin))
477 CALL auxbas_pw_pool%give_back_pw(fhxc_rspace(ispin))
479 DEALLOCATE (rhoh_r, rhoh_g, fhxc_rspace)
481 CALL timestop(handle)
483 END SUBROUTINE harris_forces
492 SUBROUTINE calculate_harris_integrals(qs_env, rhoin, v_rspace, calculate_forces)
496 LOGICAL,
INTENT(IN) :: calculate_forces
498 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_harris_integrals'
500 INTEGER :: handle, i1, i2, iatom, ikind, ilocal, &
501 ispin, n, nkind, nlocal, nspin
502 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: integral, vector
506 CALL timeset(routinen, handle)
508 CALL get_qs_env(qs_env, para_env=para_env, local_particles=local_particles)
510 ALLOCATE (vector(rhoin%nbas))
511 ALLOCATE (integral(rhoin%nbas))
513 nkind =
SIZE(rhoin%rhovec, 1)
514 nspin =
SIZE(rhoin%rhovec, 2)
520 nlocal = local_particles%n_el(ikind)
521 DO ilocal = 1, nlocal
522 iatom = local_particles%list(ikind)%array(ilocal)
523 i1 = rhoin%basptr(iatom, 1)
524 i2 = rhoin%basptr(iatom, 2)
526 vector(i1:i2) = rhoin%rhovec(ikind, ispin)%rvecs(1:n, ilocal)
529 CALL para_env%sum(vector)
531 CALL integrate_function(qs_env, v_rspace(ispin), vector, integral, &
532 calculate_forces, rhoin%basis_type)
534 nlocal = local_particles%n_el(ikind)
535 DO ilocal = 1, nlocal
536 iatom = local_particles%list(ikind)%array(ilocal)
537 i1 = rhoin%basptr(iatom, 1)
538 i2 = rhoin%basptr(iatom, 2)
540 rhoin%intvec(ikind, ispin)%rvecs(1:n, ilocal) = integral(i1:i2)
545 DEALLOCATE (vector, integral)
547 CALL timestop(handle)
549 END SUBROUTINE calculate_harris_integrals
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
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
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
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
functions related to the poisson solver on regular grids
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
Constrained fitting of a real-space density by an AO density matrix. This is a dense reference implem...
subroutine, public fit_relative_entropy_density(qs_env, rho_struct, prior_hamiltonian, temperature, entropy_weight, max_iter, eps_rms, step_size, max_backtrack)
Reconstructs an AO density matrix using the Fermi matrix of H[n_cube] as a fermionic relative-entropy...
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.
Setup Routine for Fxc Potentials.
subroutine, public qs_fxc_create(qs_env, rho0_struct, rho1_struct, rho0_atom_set, xc_section, do_onecenter, fxc_rho, fxc_tau, rho1_atom_set, do_scale, is_triplet, spinflip, no_weights, uf_grid_results, pw_env_ext, kind_set_external, para_env_external, compute_virial, virial_xc)
...
Harris method calculations.
subroutine, public harris_relative_entropy_reconstruction(qs_env)
Builds H[n_cube] once and reconstructs the AO density matrix by minimizing a density residual regular...
subroutine, public harris_direct_density_matrix_energy(qs_env)
Evaluates the fitted AO density matrix without solving a NONSCF eigenproblem.
subroutine, public harris_energy_correction(qs_env, calculate_forces)
...
Types needed for a for a Harris model calculation.
subroutine, public harris_print_direct_energy(iounit, energy)
Prints the two direct fitted-density-matrix energy evaluations.
subroutine, public harris_print_energy(iounit, energy)
...
Integrate single or product functions over a potential on a RS grid.
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)
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...
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...
subroutine, public qs_rho_create(rho)
Allocates a new instance of rho.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
structure to store local (to a processor) ordered lists of integers.
stores all the informations relevant to an mpi environment
contained for different pw related things
environment for the poisson solver
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Contains information on the Harris method.
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.