58#include "./base/base_uses.f90"
64 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_harris_utils'
85 cpassert(.NOT.
ASSOCIATED(harris_env))
87 CALL init_harris_env(qs_env, harris_env, harris_section)
100 SUBROUTINE init_harris_env(qs_env, harris_env, harris_section)
105 CHARACTER(LEN=*),
PARAMETER :: routinen =
'init_harris_env'
107 INTEGER :: handle, unit_nr
110 CALL timeset(routinen, handle)
112 IF (qs_env%harris_method)
THEN
114 cpassert(
PRESENT(harris_section))
117 IF (logger%para_env%is_source())
THEN
124 i_val=harris_env%energy_functional)
126 i_val=harris_env%density_source)
128 c_val=harris_env%density_filename)
130 i_val=harris_env%fit_max_iter)
132 i_val=harris_env%fit_method)
134 r_val=harris_env%fit_eps)
136 r_val=harris_env%fit_step_size)
138 i_val=harris_env%fit_max_backtrack)
140 r_val=harris_env%fit_temperature)
142 r_val=harris_env%fit_relative_entropy_weight)
144 l_val=harris_env%direct_density_matrix_energy)
146 i_val=harris_env%orbital_basis)
149 l_val=harris_env%debug_forces)
151 l_val=harris_env%debug_stress)
155 CALL timestop(handle)
157 END SUBROUTINE init_harris_env
170 CHARACTER(LEN=*),
PARAMETER :: routinen =
'harris_write_input'
172 INTEGER :: handle, unit_nr
175 CALL timeset(routinen, handle)
178 IF (logger%para_env%is_source())
THEN
184 IF (unit_nr > 0)
THEN
186 WRITE (unit_nr,
'(/,T2,A)') &
187 "!"//repeat(
"-", 29)//
" Harris Model "//repeat(
"-", 29)//
"!"
190 SELECT CASE (harris_env%energy_functional)
192 WRITE (unit_nr,
'(T2,A,T61,A20)')
"Energy Functional: ",
"Harris"
195 SELECT CASE (harris_env%density_source)
197 WRITE (unit_nr,
'(T2,A,T61,A20)')
"Harris model density: Type",
" Atomic kind density"
199 WRITE (unit_nr,
'(T2,A,T61,A20)')
"Harris model density: Type",
"Cube file"
200 WRITE (unit_nr,
'(T2,A,T31,A)')
"Harris model density: File", &
201 trim(harris_env%density_filename)
203 WRITE (unit_nr,
'(T2,A,T61,A20)')
"Harris model density: Type",
"Constrained cube fit"
204 WRITE (unit_nr,
'(T2,A,T31,A)')
"Harris model density: File", &
205 trim(harris_env%density_filename)
206 WRITE (unit_nr,
'(T2,A,T61,I20)')
"Harris density fit: Maximum iterations", &
207 harris_env%fit_max_iter
208 WRITE (unit_nr,
'(T2,A,T61,ES20.8)')
"Harris density fit: RMS target", &
210 WRITE (unit_nr,
'(T2,A,T61,ES20.8)')
"Harris density fit: Initial step size", &
211 harris_env%fit_step_size
212 SELECT CASE (harris_env%fit_method)
214 WRITE (unit_nr,
'(T2,A,T61,A20)')
"Harris density fit: Objective",
"Least squares"
216 WRITE (unit_nr,
'(T2,A,T61,A20)')
"Harris density fit: Objective",
"Relative entropy"
217 WRITE (unit_nr,
'(T2,A,T61,ES20.8)')
"Harris density fit: Temperature", &
218 harris_env%fit_temperature
219 WRITE (unit_nr,
'(T2,A,T61,ES20.8)')
"Harris density fit: Entropy weight", &
220 harris_env%fit_relative_entropy_weight
222 WRITE (unit_nr,
'(T2,A,T61,L20)')
"Direct fitted-DM energy evaluation", &
223 harris_env%direct_density_matrix_energy
226 WRITE (unit_nr,
'(T2,A,T71,A10)')
"Harris model density: Basis type", &
227 adjustr(trim(harris_env%rhoin%basis_type))
228 WRITE (unit_nr,
'(T2,A,T71,I10)')
"Harris model density: Number of basis functions", &
229 harris_env%rhoin%nbas
232 SELECT CASE (harris_env%orbital_basis)
234 WRITE (unit_nr,
'(T2,A,T61,A20)')
"Harris model basis: ",
"Atomic kind orbitals"
237 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
238 WRITE (unit_nr,
'()')
242 CALL timestop(handle)
255 CHARACTER(LEN=*),
PARAMETER :: routinen =
'harris_density_update'
257 INTEGER :: handle, i, ikind, ngto, nkind, nset, nsgf
258 INTEGER,
DIMENSION(:),
POINTER :: lmax, npgf
259 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: coef
260 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: density
261 REAL(kind=
dp),
DIMENSION(:),
POINTER :: norm
262 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: zet
263 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: gcc
267 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
270 CALL timeset(routinen, handle)
272 SELECT CASE (harris_env%density_source)
274 IF (.NOT. harris_env%rhoin%frozen)
THEN
275 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
278 atomic_kind => atomic_kind_set(ikind)
279 qs_kind => qs_kind_set(ikind)
280 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, &
281 basis_type=harris_env%rhoin%basis_type)
282 CALL get_gto_basis_set(gto_basis_set=basis_set, nset=nset, lmax=lmax, nsgf=nsgf, &
283 npgf=npgf, norm_cgf=norm, zet=zet, gcc=gcc)
284 IF (nset /= 1 .OR. lmax(1) /= 0 .OR. npgf(1) /= nsgf)
THEN
285 cpabort(
"RHOIN illegal basis type")
288 IF (sum(abs(gcc(1:npgf(1), i, 1))) /= maxval(abs(gcc(1:npgf(1), i, 1))))
THEN
289 cpabort(
"RHOIN illegal basis type")
294 ALLOCATE (density(ngto, 2))
295 density(1:ngto, 1) = zet(1:ngto, 1)
296 density(1:ngto, 2) = 0.0_dp
298 optbasis=.false., confine=.true.)
299 ALLOCATE (coef(ngto))
301 coef(i) = density(i, 2)/gcc(i, i, 1)/norm(i)
303 IF (harris_env%rhoin%nspin == 2)
THEN
304 DO i = 1,
SIZE(harris_env%rhoin%rhovec(ikind, 1)%rvecs, 2)
305 harris_env%rhoin%rhovec(ikind, 1)%rvecs(1:ngto, i) = coef(1:ngto)*0.5_dp
306 harris_env%rhoin%rhovec(ikind, 2)%rvecs(1:ngto, i) = coef(1:ngto)*0.5_dp
309 DO i = 1,
SIZE(harris_env%rhoin%rhovec(ikind, 1)%rvecs, 2)
310 harris_env%rhoin%rhovec(ikind, 1)%rvecs(1:ngto, i) = coef(1:ngto)
313 DEALLOCATE (density, coef)
315 harris_env%rhoin%frozen = .true.
318 IF (harris_env%rhoin%nspin /= 1)
THEN
319 cpabort(
"Harris cube densities currently require a spin-restricted calculation")
321 IF (len_trim(harris_env%density_filename) == 0)
THEN
322 cpabort(
"HARRIS_METHOD%FILE_DENSITY is required for cube density sources")
325 IF (harris_env%fit_max_iter < 1) cpabort(
"HARRIS_METHOD%FIT_MAX_ITER has to be positive")
326 IF (harris_env%fit_eps <= 0.0_dp) cpabort(
"HARRIS_METHOD%FIT_EPS has to be positive")
327 IF (harris_env%fit_step_size <= 0.0_dp)
THEN
328 cpabort(
"HARRIS_METHOD%FIT_STEP_SIZE has to be positive")
330 IF (harris_env%fit_max_backtrack < 0)
THEN
331 cpabort(
"HARRIS_METHOD%FIT_MAX_BACKTRACK cannot be negative")
334 IF (harris_env%fit_temperature <= 0.0_dp)
THEN
335 cpabort(
"HARRIS_METHOD%FIT_TEMPERATURE has to be positive for RELATIVE_ENTROPY")
337 IF (harris_env%fit_relative_entropy_weight < 0.0_dp)
THEN
338 cpabort(
"HARRIS_METHOD%FIT_RELATIVE_ENTROPY_WEIGHT cannot be negative")
343 cpabort(
"Illegal value of harris_env%density_source")
345 IF (harris_env%direct_density_matrix_energy .AND. &
347 cpabort(
"HARRIS_METHOD%DIRECT_DENSITY_MATRIX_ENERGY requires DENSITY_SOURCE CUBE_FIT")
350 CALL timestop(handle)
365 REAL(kind=
dp),
DIMENSION(:),
POINTER :: tot_rho_r
370 NULLIFY (pw_grid, rho_gspace, rho_rspace, tot_rho_r)
372 SELECT CASE (harris_env%density_source)
374 CALL calculate_harris_atomic_density(qs_env, harris_env%rhoin, rho_struct)
376 IF (harris_env%rhoin%nspin /= 1)
THEN
377 cpabort(
"Harris cube densities currently require a spin-restricted calculation")
379 IF (len_trim(harris_env%density_filename) == 0)
THEN
380 cpabort(
"HARRIS_METHOD%FILE_DENSITY is required for DENSITY_SOURCE CUBE")
383 total_density_sign=-1, source_label=
"HARRIS")
386 IF (.NOT. harris_env%density_target_ready)
THEN
388 total_density_sign=-1, source_label=
"HARRIS")
390 pw_grid => rho_rspace(1)%pw_grid
391 CALL harris_env%density_target_rspace%create(pw_grid)
392 CALL pw_copy(rho_rspace(1), harris_env%density_target_rspace)
393 harris_env%density_target_ready = .true.
395 CALL qs_rho_get(rho_struct, rho_r=rho_rspace, rho_g=rho_gspace, &
397 IF (harris_env%density_fit_ready)
THEN
398 CALL pw_copy(harris_env%density_fit_rspace, rho_rspace(1))
400 CALL pw_copy(harris_env%density_target_rspace, rho_rspace(1))
405 ELSE IF (.NOT. harris_env%density_fit_ready)
THEN
407 total_density_sign=-1, source_label=
"HARRIS")
408 IF (harris_env%direct_density_matrix_energy)
THEN
410 pw_grid => rho_rspace(1)%pw_grid
411 CALL harris_env%density_target_rspace%create(pw_grid)
412 CALL pw_copy(rho_rspace(1), harris_env%density_target_rspace)
415 harris_env%fit_eps, harris_env%fit_step_size, &
416 harris_env%fit_max_backtrack)
418 pw_grid => rho_rspace(1)%pw_grid
419 CALL harris_env%density_fit_rspace%create(pw_grid)
420 CALL pw_copy(rho_rspace(1), harris_env%density_fit_rspace)
421 harris_env%density_fit_ready = .true.
423 CALL qs_rho_get(rho_struct, rho_r=rho_rspace, rho_g=rho_gspace, &
425 CALL pw_copy(harris_env%density_fit_rspace, rho_rspace(1))
430 cpabort(
"Illegal value of harris_env%density_source")
441 SUBROUTINE calculate_harris_atomic_density(qs_env, rhoin, rho_struct)
446 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_harris_atomic_density'
448 INTEGER :: handle, i1, i2, iatom, ikind, ilocal, &
449 ispin, n, nkind, nlocal, nspin
450 REAL(kind=
dp) :: eps_rho_rspace
451 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: vector
452 REAL(kind=
dp),
DIMENSION(:),
POINTER :: total_rho
462 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
464 CALL timeset(routinen, handle)
466 CALL get_qs_env(qs_env, dft_control=dft_control, para_env=para_env)
467 eps_rho_rspace = dft_control%qs_control%eps_rho_rspace
469 atomic_kind_set=atomic_kind_set, particle_set=particle_set, &
470 local_particles=local_particles, &
471 qs_kind_set=qs_kind_set, cell=cell, pw_env=pw_env)
473 CALL qs_rho_get(rho_struct, rho_r=rho_rspace, rho_g=rho_gspace, &
476 ALLOCATE (vector(rhoin%nbas))
478 nkind =
SIZE(rhoin%rhovec, 1)
479 nspin =
SIZE(rhoin%rhovec, 2)
484 nlocal = local_particles%n_el(ikind)
485 DO ilocal = 1, nlocal
486 iatom = local_particles%list(ikind)%array(ilocal)
487 i1 = rhoin%basptr(iatom, 1)
488 i2 = rhoin%basptr(iatom, 2)
490 vector(i1:i2) = rhoin%rhovec(ikind, ispin)%rvecs(1:n, ilocal)
493 CALL para_env%sum(vector)
496 atomic_kind_set, qs_kind_set, cell, particle_set, pw_env, &
497 eps_rho_rspace, rhoin%basis_type)
503 CALL timestop(handle)
505 END SUBROUTINE calculate_harris_atomic_density
514 SUBROUTINE calculate_harris_integrals(qs_env, rhoin, v_rspace, calculate_forces)
518 LOGICAL,
INTENT(IN) :: calculate_forces
520 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_harris_integrals'
522 INTEGER :: handle, i1, i2, iatom, ikind, ilocal, &
523 ispin, n, nkind, nlocal, nspin
524 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: integral, vector
528 CALL timeset(routinen, handle)
530 CALL get_qs_env(qs_env, para_env=para_env, local_particles=local_particles)
532 ALLOCATE (vector(rhoin%nbas))
533 ALLOCATE (integral(rhoin%nbas))
535 nkind =
SIZE(rhoin%rhovec, 1)
536 nspin =
SIZE(rhoin%rhovec, 2)
542 nlocal = local_particles%n_el(ikind)
543 DO ilocal = 1, nlocal
544 iatom = local_particles%list(ikind)%array(ilocal)
545 i1 = rhoin%basptr(iatom, 1)
546 i2 = rhoin%basptr(iatom, 2)
548 vector(i1:i2) = rhoin%rhovec(ikind, ispin)%rvecs(1:n, ilocal)
551 CALL para_env%sum(vector)
553 CALL integrate_function(qs_env, v_rspace(ispin), vector, integral, &
554 calculate_forces, rhoin%basis_type)
556 nlocal = local_particles%n_el(ikind)
557 DO ilocal = 1, nlocal
558 iatom = local_particles%list(ikind)%array(ilocal)
559 i1 = rhoin%basptr(iatom, 1)
560 i2 = rhoin%basptr(iatom, 2)
562 rhoin%intvec(ikind, ispin)%rvecs(1:n, ilocal) = integral(i1:i2)
567 DEALLOCATE (vector, integral)
569 CALL timestop(handle)
571 END SUBROUTINE calculate_harris_integrals
584 INTEGER :: iab, ispin, nspins
588 IF (
ASSOCIATED(harris_env%vh_rspace%pw_grid))
THEN
589 CALL harris_env%vh_rspace%release()
591 IF (
ASSOCIATED(harris_env%vxc_rspace))
THEN
592 DO iab = 1,
SIZE(harris_env%vxc_rspace)
593 CALL harris_env%vxc_rspace(iab)%release()
595 DEALLOCATE (harris_env%vxc_rspace)
599 nspins = harris_env%rhoin%nspin
600 ALLOCATE (harris_env%vxc_rspace(nspins))
602 pw_grid => vh_rspace%pw_grid
603 CALL harris_env%vh_rspace%create(pw_grid)
605 CALL harris_env%vxc_rspace(ispin)%create(pw_grid)
610 IF (
ASSOCIATED(vxc_rspace))
THEN
612 CALL pw_transfer(vxc_rspace(ispin), harris_env%vxc_rspace(ispin))
613 CALL pw_scale(harris_env%vxc_rspace(ispin), vxc_rspace(ispin)%pw_grid%dvol)
617 CALL pw_zero(harris_env%vxc_rspace(ispin))
calculate the orbitals for a given atomic kind type
subroutine, public calculate_atomic_density(density, atomic_kind, qs_kind, ngto, iunit, optbasis, allelectron, confine)
...
Define the atomic kind types and their sub types.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius, npgf_seg_sum, ccon)
...
Handles all functions related to the CELL.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
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.
Define the data structure for the particle information.
container for various plainwaves related things
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public collocate_function(vector, rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, particle_set, pw_env, eps_rho_rspace, basis_type)
maps a given function on the grid
Constrained fitting of a real-space density by an AO density matrix. This is a dense reference implem...
subroutine, public fit_constrained_density(qs_env, rho_struct, max_iter, eps_rms, step_size, max_backtrack)
Fits the density currently stored in rho_struct with a spin-restricted AO density matrix....
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.
Routines to handle an external density The external density can be generic and is provided by user in...
subroutine, public read_cube_density(qs_env, rho_target, filename, total_density_sign, source_label)
Read an electron density from a Gaussian cube file into a QS density grid.
Types needed for a for a Harris model calculation.
Harris method environment setup and handling.
subroutine, public harris_write_input(harris_env)
Print out the Harris method input section.
subroutine, public harris_density_update(qs_env, harris_env)
...
subroutine, public harris_set_potentials(harris_env, vh_rspace, vxc_rspace)
...
subroutine, public harris_env_create(qs_env, harris_env, harris_section)
Allocates and intitializes harris_env.
subroutine, public calculate_harris_density(qs_env, harris_env, rho_struct)
...
Integrate single or product functions over a potential on a RS grid.
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.
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...
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
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
Contains information on the Harris method.
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.