150 CHARACTER(LEN=*),
INTENT(IN) :: filename
151 INTEGER,
INTENT(IN) :: total_density_sign
152 CHARACTER(LEN=*),
INTENT(IN) :: source_label
154 CHARACTER(len=*),
PARAMETER :: routinen =
'read_cube_density'
156 INTEGER :: extunit, handle, i, igrid_level, j, k, &
157 nat, ndum, output_unit
158 INTEGER,
DIMENSION(3) :: lbounds, lbounds_local, npoints, &
159 ubounds, ubounds_local
160 LOGICAL :: grid_mismatch
161 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: buffer
162 REAL(kind=
dp),
DIMENSION(3) :: cube_origin, voxel
163 REAL(kind=
dp),
DIMENSION(:),
POINTER :: tot_rho_r
171 DIMENSION(:) :: rs_rho
173 CALL timeset(routinen, handle)
174 NULLIFY (pw_env, rho_r, rho_g, tot_rho_r, rs_descs)
177 IF (total_density_sign /= -1 .AND. total_density_sign /= 1)
THEN
178 cpabort(
"total_density_sign has to be -1 or 1")
182 CALL qs_rho_get(rho_target, rho_r=rho_r, rho_g=rho_g, tot_rho_r=tot_rho_r)
183 gridlevel_info => pw_env%gridlevel_info
186 ALLOCATE (rs_rho(gridlevel_info%ngrid_levels))
187 DO igrid_level = 1, gridlevel_info%ngrid_levels
188 CALL rs_grid_create(rs_rho(igrid_level), rs_descs(igrid_level)%rs_desc)
191 igrid_level = gridlevel_info%ngrid_levels
193 npoints = rs_descs(igrid_level)%rs_desc%npts
194 lbounds = rs_descs(igrid_level)%rs_desc%lb
195 ubounds = rs_descs(igrid_level)%rs_desc%ub
196 lbounds_local = rho_r(1)%pw_grid%bounds_local(1, :)
197 ubounds_local = rho_r(1)%pw_grid%bounds_local(2, :)
198 ALLOCATE (buffer(lbounds(3):ubounds(3)))
200 associate(gid => rho_r(1)%pw_grid%para%group, &
201 my_rank => rho_r(1)%pw_grid%para%group%mepos)
202 grid_mismatch = .false.
203 IF (my_rank == 0)
THEN
204 WRITE (output_unit, fmt=
"(/,T3,A,A)") &
205 trim(source_label)//
"| Reading electron density: ", trim(filename)
206 CALL open_file(file_name=filename, file_status=
"OLD", file_form=
"FORMATTED", &
207 file_action=
"READ", unit_number=extunit)
211 READ (extunit, *) nat, cube_origin
212 IF (maxval(abs(cube_origin)) > 1.0e-4_dp)
THEN
213 grid_mismatch = .true.
214 WRITE (output_unit, fmt=
"(T3,A,3ES16.8)") trim(source_label)// &
215 "| Cube origin is not the CP2K grid origin: ", cube_origin
218 grid_mismatch = .true.
219 WRITE (output_unit, fmt=
"(T3,A)") trim(source_label)// &
220 "| Multi-orbital cube files are not supported"
223 READ (extunit, *) ndum, voxel
224 IF (ndum /= npoints(i) .OR. &
225 maxval(abs(voxel - rs_descs(igrid_level)%rs_desc%dh(:, i))) > 1.0e-4_dp)
THEN
226 grid_mismatch = .true.
227 WRITE (output_unit, fmt=
"(T3,A,I0)") trim(source_label)// &
228 "| Cube grid does not coincide with CP2K grid along axis ", i
229 WRITE (output_unit, fmt=
"(T3,A,I0,A,I0)") trim(source_label)//
"| Grid points: ", &
230 ndum,
" instead of ", npoints(i)
231 WRITE (output_unit, fmt=
"(T3,A,3ES16.8)") trim(source_label)//
"| Cube vector: ", voxel
232 WRITE (output_unit, fmt=
"(T3,A,3ES16.8)") trim(source_label)//
"| CP2K vector: ", &
233 rs_descs(igrid_level)%rs_desc%dh(:, i)
241 CALL gid%bcast(grid_mismatch, 0)
242 IF (grid_mismatch)
THEN
243 IF (my_rank == 0)
CALL close_file(unit_number=extunit)
244 cpabort(
"Cube density grid is incompatible with the CP2K real-space grid")
247 DO i = lbounds(1), ubounds(1)
248 DO j = lbounds(2), ubounds(2)
249 IF (my_rank == 0)
THEN
250 READ (extunit, *) (buffer(k), k=lbounds(3), ubounds(3))
252 CALL gid%bcast(buffer, 0)
253 IF ((lbounds_local(1) <= i) .AND. (i <= ubounds_local(1)) .AND. &
254 (lbounds_local(2) <= j) .AND. (j <= ubounds_local(2)))
THEN
255 rs_rho(igrid_level)%r(i, j, lbounds(3):ubounds(3)) = buffer
259 IF (my_rank == 0)
CALL close_file(unit_number=extunit)
261 CALL density_rs2pw(pw_env, rs_rho, rho=rho_r(1), rho_gspace=rho_g(1))
263 IF (my_rank == 0)
THEN
264 WRITE (output_unit, fmt=
"(T3,A,T61,F20.10)") trim(source_label)// &
265 "| Integrated electron density:", real(total_density_sign,
dp)*tot_rho_r(1)
270 DO igrid_level = 1,
SIZE(rs_rho)
273 DEALLOCATE (buffer, rs_rho)
275 CALL timestop(handle)
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.