38 #include "./base/base_uses.f90"
44 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_external_density'
58 TYPE(qs_environment_type),
POINTER :: qs_env
60 CHARACTER(len=*),
PARAMETER :: routinen =
'external_read_density'
62 CHARACTER(LEN=default_string_length) :: filename
63 INTEGER :: extunit, handle, i, igrid_level, j, k, &
65 INTEGER,
DIMENSION(3) :: lbounds, lbounds_local, npoints, &
66 npoints_local, ubounds, ubounds_local
67 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: buffer
68 REAL(kind=
dp),
DIMENSION(3) :: dr, rdum
69 REAL(kind=
dp),
DIMENSION(:),
POINTER :: tot_rho_r_ext
70 TYPE(cell_type),
POINTER :: cell
71 TYPE(dft_control_type),
POINTER :: dft_control
72 TYPE(gridlevel_info_type),
POINTER :: gridlevel_info
73 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_ext_g
74 TYPE(pw_env_type),
POINTER :: pw_env
75 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_ext_r
76 TYPE(qs_rho_type),
POINTER :: rho_external
77 TYPE(realspace_grid_desc_p_type),
DIMENSION(:), &
79 TYPE(realspace_grid_type),
ALLOCATABLE, &
80 DIMENSION(:) :: rs_rho_ext
81 TYPE(section_vals_type),
POINTER :: ext_den_section, input
83 CALL timeset(routinen, handle)
84 NULLIFY (cell, input, ext_den_section, rs_descs, dft_control)
85 NULLIFY (rho_ext_r, rho_ext_g, tot_rho_r_ext)
89 rho_external=rho_external, &
92 dft_control=dft_control)
94 IF (dft_control%apply_external_density)
THEN
98 tot_rho_r=tot_rho_r_ext)
100 gridlevel_info => pw_env%gridlevel_info
104 ALLOCATE (rs_rho_ext(gridlevel_info%ngrid_levels))
106 DO igrid_level = 1, gridlevel_info%ngrid_levels
108 rs_descs(igrid_level)%rs_desc)
112 igrid_level = igrid_level - 1
118 associate(gid => rho_ext_r(1)%pw_grid%para%group, my_rank => rho_ext_r(1)%pw_grid%para%my_pos, &
119 num_pe => rho_ext_r(1)%pw_grid%para%group_size)
121 IF (dft_control%read_external_density)
THEN
124 dr(i) = rs_descs(igrid_level)%rs_desc%dh(i, i)
126 npoints = rs_descs(igrid_level)%rs_desc%npts
127 lbounds = rs_descs(igrid_level)%rs_desc%lb
128 ubounds = rs_descs(igrid_level)%rs_desc%ub
130 npoints_local = rho_ext_r(1)%pw_grid%npts_local
131 lbounds_local = rho_ext_r(1)%pw_grid%bounds_local(1, :)
132 ubounds_local = rho_ext_r(1)%pw_grid%bounds_local(2, :)
134 ALLOCATE (buffer(lbounds_local(3):ubounds_local(3)))
136 IF (my_rank == 0)
THEN
137 WRITE (*, fmt=
"(/,/,T2,A)")
"INITIALIZING ZMP CONSTRAINED DENSITY METHOD"
138 WRITE (*, fmt=
"(/,(T3,A,T51,A30))")
"ZMP| Reading the target density: ", filename
142 file_form=
"FORMATTED", &
143 file_action=
"READ", &
149 READ (extunit, *) nat, rdum
151 READ (extunit, *) ndum, rdum
152 IF (ndum /= npoints(i) .OR. (abs(rdum(i) - dr(i)) > 1e-4))
THEN
153 WRITE (*, *)
"ZMP | ERROR! | CUBE FILE NOT COINCIDENT WITH INTERNAL GRID ", i
154 WRITE (*, *)
"ZMP | ", ndum,
" DIFFERS FROM ", npoints(i)
155 WRITE (*, *)
"ZMP | ", rdum,
" DIFFERS FROM ", dr(i)
163 DO i = lbounds(1), ubounds(1)
164 DO j = lbounds(2), ubounds(2)
165 IF (my_rank .EQ. 0)
THEN
166 READ (extunit, *) (buffer(k), k=lbounds(3), ubounds(3))
168 CALL gid%bcast(buffer(lbounds(3):ubounds(3)), 0)
170 IF ((lbounds_local(1) .LE. i) .AND. (i .LE. ubounds_local(1)) .AND. (lbounds_local(2) .LE. j) &
171 .AND. (j .LE. ubounds_local(2)))
THEN
172 rs_rho_ext(igrid_level)%r(i, j, lbounds(3):ubounds(3)) = buffer(lbounds(3):ubounds(3))
177 IF (my_rank == 0)
CALL close_file(unit_number=extunit)
180 CALL density_rs2pw(pw_env, rs_rho_ext, rho=rho_ext_r(1), rho_gspace=rho_ext_g(1))
181 DO igrid_level = 1,
SIZE(rs_rho_ext)
184 tot_rho_r_ext(1) = pw_integrate_function(rho_ext_r(1), isign=1)
185 IF (my_rank == 0)
THEN
186 WRITE (*, fmt=
"(T3,A,T61,F20.10)")
"ZMP| Total external charge: ", &
189 DEALLOCATE (buffer, rs_rho_ext)
194 CALL timestop(handle)
Handles all functions related to the CELL.
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.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
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
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_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, 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, rhs)
Get the QUICKSTEP environment.
Routines to handle an external density The external density can be generic and is provided by user in...
subroutine, public external_read_density(qs_env)
Computes the external density on the grid.
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...
subroutine, public rs_grid_create(rs, desc)
...
subroutine, public rs_grid_release(rs_grid)
releases the given rs grid (see doc/ReferenceCounting.html)
subroutine, public rs_grid_zero(rs)
Initialize grid to zero.
Transfers densities from PW to RS grids and potentials from PW to RS.
subroutine, public density_rs2pw(pw_env, rs_rho, rho, rho_gspace)
given partial densities on the realspace multigrids, computes the full density on the plane wave grid...