38#include "./base/base_uses.f90"
43 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'fde_methods'
72 NULLIFY (pw_env, poisson_env, auxbas_pw_pool, rho)
73 CALL get_qs_env(qs_env, pw_env=pw_env, rho=rho)
74 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, poisson_env=poisson_env)
76 CALL auxbas_pw_pool%create_pw(rho_tot_g)
80 CALL auxbas_pw_pool%create_pw(v_es_g)
83 CALL auxbas_pw_pool%create_pw(v_es)
86 CALL auxbas_pw_pool%give_back_pw(rho_tot_g)
87 CALL auxbas_pw_pool%give_back_pw(v_es_g)
100 INTEGER :: ispin, nspins
107 NULLIFY (dft_control, pw_env, auxbas_pw_pool, rho_r, rho_qs)
108 CALL get_qs_env(qs_env, dft_control=dft_control, pw_env=pw_env, rho=rho_qs)
109 nspins = dft_control%nspins
111 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
112 CALL auxbas_pw_pool%create_pw(rho)
117 CALL pw_axpy(rho_r(ispin), rho, 1.0_dp)
131 SUBROUTINE fde_vxc_on_grid(ks_env, pw_env, xc_section, rho, v_xc, e_xc)
137 REAL(kind=
dp),
INTENT(OUT) :: e_xc
139 REAL(kind=
dp),
DIMENSION(3, 3) :: virial_xc
142 TYPE(
pw_pool_type),
POINTER :: auxbas_pw_pool, xc_pw_pool
143 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r, tau, vxc_rho, vxc_tau
146 NULLIFY (auxbas_pw_pool, xc_pw_pool, rho_r, rho_g, tau, vxc_rho, vxc_tau, weights)
147 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, xc_pw_pool=xc_pw_pool)
148 CALL get_ks_env(ks_env, xcint_weights=weights)
150 ALLOCATE (rho_r(1), rho_g(1))
152 CALL auxbas_pw_pool%create_pw(rho_g_single)
154 rho_g(1) = rho_g_single
162 xc_section=xc_section, &
164 pw_pool=xc_pw_pool, &
165 compute_virial=.false., &
168 CALL auxbas_pw_pool%create_pw(v_xc)
171 CALL xc_pw_pool%give_back_pw(vxc_rho(1))
173 IF (
ASSOCIATED(vxc_tau))
THEN
174 CALL xc_pw_pool%give_back_pw(vxc_tau(1))
177 CALL auxbas_pw_pool%give_back_pw(rho_g_single)
178 DEALLOCATE (rho_r, rho_g)
180 END SUBROUTINE fde_vxc_on_grid
194 REAL(kind=
dp),
INTENT(OUT) :: e_xc_na, e_kin_na
196 REAL(kind=
dp) :: exc_a, exc_ab, exc_b
204 NULLIFY (dft_control, pw_env, auxbas_pw_pool, ks_env, input, xc_section, kg_xc_section)
205 CALL get_qs_env(qs_env, dft_control=dft_control, pw_env=pw_env, ks_env=ks_env, input=input)
206 cpassert(dft_control%nspins == 1)
207 cpassert(.NOT. dft_control%qs_control%gapw)
209 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
212 CALL auxbas_pw_pool%create_pw(rho_ab)
214 CALL pw_axpy(rho, rho_ab, 1.0_dp)
221 CALL fde_vxc_on_grid(ks_env, pw_env, xc_section, rho_ab, v_ab, exc_ab)
222 CALL fde_vxc_on_grid(ks_env, pw_env, xc_section, rho, v_a, exc_a)
223 CALL fde_vxc_on_grid(ks_env, pw_env, xc_section, rho_b_r, v_tmp, exc_b)
224 CALL auxbas_pw_pool%give_back_pw(v_tmp)
225 CALL pw_axpy(v_ab, v_emb, 1.0_dp)
226 CALL pw_axpy(v_a, v_emb, -1.0_dp)
227 CALL auxbas_pw_pool%give_back_pw(v_ab)
228 CALL auxbas_pw_pool%give_back_pw(v_a)
229 e_xc_na = exc_ab - exc_a - exc_b
231 CALL fde_vxc_on_grid(ks_env, pw_env, kg_xc_section, rho_ab, v_ab, exc_ab)
232 CALL fde_vxc_on_grid(ks_env, pw_env, kg_xc_section, rho, v_a, exc_a)
233 CALL fde_vxc_on_grid(ks_env, pw_env, kg_xc_section, rho_b_r, v_tmp, exc_b)
234 CALL auxbas_pw_pool%give_back_pw(v_tmp)
235 CALL pw_axpy(v_ab, v_emb, 1.0_dp)
236 CALL pw_axpy(v_a, v_emb, -1.0_dp)
237 CALL auxbas_pw_pool%give_back_pw(v_ab)
238 CALL auxbas_pw_pool%give_back_pw(v_a)
239 e_kin_na = exc_ab - exc_a - exc_b
241 CALL auxbas_pw_pool%give_back_pw(rho_ab)
242 CALL auxbas_pw_pool%give_back_pw(rho_b_r)
255 CHARACTER(len=*),
INTENT(IN) :: input_file
258 CHARACTER(len=:),
ALLOCATABLE :: command
259 INTEGER :: cmdstat, exitstat
261 IF (len_trim(fde_control%workdir) > 0)
THEN
262 command =
"cd "//trim(fde_control%workdir)//
" && "// &
263 trim(fde_control%command)//
" "//trim(input_file)
265 command = trim(fde_control%command)//
" "//trim(input_file)
270 IF (para_env%is_source())
THEN
271 CALL execute_command_line(command, wait=.true., exitstat=exitstat, cmdstat=cmdstat)
274 CALL para_env%bcast(cmdstat)
275 CALL para_env%bcast(exitstat)
277 IF (cmdstat /= 0)
THEN
278 cpabort(
"FDE: failed to launch command: "//command)
280 IF (exitstat /= 0)
THEN
281 cpabort(
"FDE: command returned a non-zero exit status: "//trim(
cp_to_string(exitstat)))
296 CHARACTER(len=*),
INTENT(IN) :: filename
297 LOGICAL,
INTENT(IN) :: write_value
299 CHARACTER(len=*),
PARAMETER :: routinen =
'fde_write_pw'
301 INTEGER :: dest, handle, i1, i2, i3, ip, l1, l2, &
302 l3, mepos, num_pe, source, tag, u1, &
304 REAL(kind=
dp) :: dvol, x, y, z
305 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: buf
308 CALL timeset(routinen, handle)
310 l1 = pw%pw_grid%bounds(1, 1)
311 u1 = pw%pw_grid%bounds(2, 1)
312 l2 = pw%pw_grid%bounds(1, 2)
313 u2 = pw%pw_grid%bounds(2, 2)
314 l3 = pw%pw_grid%bounds(1, 3)
315 u3 = pw%pw_grid%bounds(2, 3)
316 dvol = pw%pw_grid%dvol
318 group = pw%pw_grid%para%group
319 mepos = pw%pw_grid%para%group%mepos
320 num_pe = pw%pw_grid%para%group%num_pe
325 IF (mepos == dest)
THEN
326 CALL open_file(file_name=trim(filename), file_status=
"REPLACE", file_form=
"FORMATTED", &
327 file_action=
"WRITE", unit_number=unit_nr)
328 WRITE (unit_nr,
'(I10)') pw%pw_grid%ngpts
331 ALLOCATE (buf(l3:u3))
337 DO ip = 0, num_pe - 1
338 IF (pw%pw_grid%para%bo(1, 1, ip, 1) <= i1 - l1 + 1 &
339 .AND. pw%pw_grid%para%bo(2, 1, ip, 1) >= i1 - l1 + 1 &
340 .AND. pw%pw_grid%para%bo(1, 2, ip, 1) <= i2 - l2 + 1 &
341 .AND. pw%pw_grid%para%bo(2, 2, ip, 1) >= i2 - l2 + 1)
THEN
349 IF (source == dest)
THEN
350 IF (mepos == source) buf(:) = pw%array(i1, i2, :)
352 IF (mepos == source)
THEN
353 buf(:) = pw%array(i1, i2, :)
354 CALL group%send(buf, dest, tag)
356 IF (mepos == dest)
CALL group%recv(buf, source, tag)
359 IF (mepos == dest)
THEN
361 x = pw%pw_grid%dh(1, 1)*(i1 - l1) &
362 + pw%pw_grid%dh(2, 1)*(i2 - l2) &
363 + pw%pw_grid%dh(3, 1)*(i3 - l3)
364 y = pw%pw_grid%dh(1, 2)*(i1 - l1) &
365 + pw%pw_grid%dh(2, 2)*(i2 - l2) &
366 + pw%pw_grid%dh(3, 2)*(i3 - l3)
367 z = pw%pw_grid%dh(1, 3)*(i1 - l1) &
368 + pw%pw_grid%dh(2, 3)*(i2 - l2) &
369 + pw%pw_grid%dh(3, 3)*(i3 - l3)
370 IF (write_value)
THEN
371 WRITE (unit_nr,
'(3F16.8,2ES20.10E3)') x, y, z, dvol, buf(i3)
373 WRITE (unit_nr,
'(3F16.8)') x, y, z
384 IF (mepos == dest)
CALL close_file(unit_number=unit_nr)
386 CALL timestop(handle)
397 CHARACTER(len=*),
INTENT(IN) :: filename
399 CHARACTER(len=*),
PARAMETER :: routinen =
'fde_read_pw'
401 INTEGER :: dest, handle, i1, i2, i3, ip, l1, l2, &
402 l3, mepos, npoints, num_pe, source, &
403 tag, u1, u2, u3, unit_nr
404 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: buf
407 CALL timeset(routinen, handle)
409 l1 = pw%pw_grid%bounds(1, 1)
410 u1 = pw%pw_grid%bounds(2, 1)
411 l2 = pw%pw_grid%bounds(1, 2)
412 u2 = pw%pw_grid%bounds(2, 2)
413 l3 = pw%pw_grid%bounds(1, 3)
414 u3 = pw%pw_grid%bounds(2, 3)
416 group = pw%pw_grid%para%group
417 mepos = pw%pw_grid%para%group%mepos
418 num_pe = pw%pw_grid%para%group%num_pe
423 IF (mepos == dest)
THEN
424 CALL open_file(file_name=trim(filename), file_status=
"OLD", file_form=
"FORMATTED", &
425 file_action=
"READ", unit_number=unit_nr)
426 READ (unit_nr, *) npoints
427 IF (npoints /= pw%pw_grid%ngpts)
THEN
428 cpabort(
"Number of grid points in file does not match the pw grid")
432 ALLOCATE (buf(l3:u3))
438 DO ip = 0, num_pe - 1
439 IF (pw%pw_grid%para%bo(1, 1, ip, 1) <= i1 - l1 + 1 &
440 .AND. pw%pw_grid%para%bo(2, 1, ip, 1) >= i1 - l1 + 1 &
441 .AND. pw%pw_grid%para%bo(1, 2, ip, 1) <= i2 - l2 + 1 &
442 .AND. pw%pw_grid%para%bo(2, 2, ip, 1) >= i2 - l2 + 1)
THEN
450 IF (mepos == dest)
THEN
452 READ (unit_nr, *) buf(i3)
456 IF (source == dest)
THEN
457 IF (mepos == source) pw%array(i1, i2, :) = buf(:)
459 IF (mepos == dest)
CALL group%send(buf, source, tag)
460 IF (mepos == source)
THEN
461 CALL group%recv(buf, dest, tag)
462 pw%array(i1, i2, :) = buf(:)
472 IF (mepos == dest)
CALL close_file(unit_number=unit_nr)
474 CALL timestop(handle)
498 CHARACTER(len=*),
INTENT(IN) :: filename
500 REAL(kind=
dp),
INTENT(OUT) :: e_sub, e_emb, e_nuc, n_e
501 INTEGER,
INTENT(OUT) :: n_a
502 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
504 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :), &
507 INTEGER :: iatom, unit_nr
508 REAL(kind=
dp),
DIMENSION(4) :: vals
512 IF (para_env%is_source())
THEN
513 CALL open_file(file_name=trim(filename), file_status=
"OLD", file_form=
"FORMATTED", &
514 file_action=
"READ", unit_number=unit_nr)
515 READ (unit_nr, *) vals(1)
516 READ (unit_nr, *) vals(2)
517 READ (unit_nr, *) vals(3)
518 READ (unit_nr, *) vals(4)
519 READ (unit_nr, *) n_a
521 CALL para_env%bcast(vals)
522 CALL para_env%bcast(n_a)
524 ALLOCATE (z_a(n_a), r_a(3, n_a))
527 IF (para_env%is_source())
THEN
529 READ (unit_nr, *) z_a(iatom), r_a(1, iatom), r_a(2, iatom), r_a(3, iatom)
533 CALL para_env%bcast(z_a)
534 CALL para_env%bcast(r_a)
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Utility routines to open and close files. Tracking of preconnections.
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
various routines to log and control the output. The idea is that decisions about where to log should ...
subroutine, public fde_read_results(filename, para_env, e_sub, e_emb, e_nuc, n_e, n_a, z_a, r_a)
Read scalar results returned by the subsystem solver, one value per line, in this order: E_sub : embe...
subroutine, public fde_read_pw(pw, filename)
Read the density in x y z weight value format.
subroutine, public fde_write_pw(pw, filename, write_value)
Write grid points to disk in the Molcas format, optionally with weights and values....
subroutine, public fde_build_v_emb(qs_env, rho, v_emb, e_xc_na, e_kin_na)
Build the embedding potential and evaluate nonadditive terms of a QS calculation.
subroutine, public fde_v_es(qs_env, v_es)
Build the electrostatic potential of a QS calculation.
subroutine, public fde_spawn(fde_control, input_file, para_env)
Spawns the subsystem solver. Only the source rank launches the process; the other ranks wait for it o...
subroutine, public fde_get_env_density(qs_env, rho)
Copy the electron density from a QS calculation into a new grid.
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
integer, parameter, public pw_mode_local
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 ...
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 that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho, skip_nuclear_density)
...
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
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...
Exchange and Correlation functional calculations.
subroutine, public xc_vxc_pw_create(vxc_rho, vxc_tau, exc, rho_r, rho_g, tau, xc_section, weights, pw_pool, compute_virial, virial_xc, exc_r)
Exchange and Correlation functional calculations.
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 ...
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.