25 USE dbcsr_api,
ONLY: dbcsr_add,&
46 neighbor_list_iterator_p_type,&
48 neighbor_list_set_p_type
54 #include "./base/base_uses.f90"
60 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_efield_local'
80 TYPE(qs_environment_type),
POINTER :: qs_env
81 LOGICAL,
INTENT(IN) :: just_energy, calculate_forces
83 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_efield_local_operator'
86 LOGICAL :: s_mstruct_changed
87 REAL(
dp),
DIMENSION(3) :: rpoint
88 TYPE(dft_control_type),
POINTER :: dft_control
90 CALL timeset(routinen, handle)
93 CALL get_qs_env(qs_env, s_mstruct_changed=s_mstruct_changed, &
94 dft_control=dft_control)
96 IF (dft_control%apply_efield)
THEN
98 IF (s_mstruct_changed)
CALL qs_efield_integrals(qs_env, rpoint)
99 CALL qs_efield_mo_derivatives(qs_env, rpoint, just_energy, calculate_forces)
102 CALL timestop(handle)
111 SUBROUTINE qs_efield_integrals(qs_env, rpoint)
113 TYPE(qs_environment_type),
POINTER :: qs_env
114 REAL(
dp),
DIMENSION(3),
INTENT(IN) :: rpoint
116 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_efield_integrals'
119 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: dipmat, matrix_s
120 TYPE(dft_control_type),
POINTER :: dft_control
121 TYPE(efield_berry_type),
POINTER :: efield
123 CALL timeset(routinen, handle)
124 cpassert(
ASSOCIATED(qs_env))
126 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
128 CALL get_qs_env(qs_env=qs_env, efield=efield, matrix_s=matrix_s)
132 ALLOCATE (dipmat(i)%matrix)
133 CALL dbcsr_copy(dipmat(i)%matrix, matrix_s(1)%matrix,
'DIP MAT')
134 CALL dbcsr_set(dipmat(i)%matrix, 0.0_dp)
139 CALL timestop(handle)
141 END SUBROUTINE qs_efield_integrals
150 SUBROUTINE qs_efield_mo_derivatives(qs_env, rpoint, just_energy, calculate_forces)
151 TYPE(qs_environment_type),
POINTER :: qs_env
152 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: rpoint
153 LOGICAL :: just_energy, calculate_forces
155 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_efield_mo_derivatives'
157 INTEGER :: atom_a, atom_b, handle, i, ia, iatom, icol, idir, ikind, irow, iset, ispin, &
158 jatom, jkind, jset, ldab, natom, ncoa, ncob, nkind, nseta, nsetb, sgfa, sgfb
159 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind
160 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
162 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
163 LOGICAL :: found, trans
164 REAL(
dp) :: charge, ci(3), dab, ener_field, fdir, &
166 REAL(
dp),
DIMENSION(3) :: ra, rab, rac, rbc, ria
167 REAL(
dp),
DIMENSION(3, 3) :: forcea, forceb
168 REAL(
dp),
DIMENSION(:, :),
POINTER :: p_block_a, p_block_b, pblock, pmat, work
169 REAL(kind=
dp),
DIMENSION(:),
POINTER :: set_radius_a, set_radius_b
170 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: rpgfa, rpgfb, sphi_a, sphi_b, zeta, zetb
171 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
172 TYPE(cell_type),
POINTER :: cell
173 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: dipmat, matrix_ks, matrix_p
174 TYPE(dft_control_type),
POINTER :: dft_control
175 TYPE(efield_berry_type),
POINTER :: efield
176 TYPE(gto_basis_set_p_type),
DIMENSION(:),
POINTER :: basis_set_list
177 TYPE(gto_basis_set_type),
POINTER :: basis_set_a, basis_set_b
178 TYPE(mp_para_env_type),
POINTER :: para_env
179 TYPE(neighbor_list_iterator_p_type), &
180 DIMENSION(:),
POINTER :: nl_iterator
181 TYPE(neighbor_list_set_p_type),
DIMENSION(:), &
183 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
184 TYPE(qs_energy_type),
POINTER :: energy
185 TYPE(qs_force_type),
DIMENSION(:),
POINTER :: force
186 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
187 TYPE(qs_kind_type),
POINTER :: qs_kind
188 TYPE(qs_rho_type),
POINTER :: rho
190 CALL timeset(routinen, handle)
192 CALL get_qs_env(qs_env, dft_control=dft_control, cell=cell, particle_set=particle_set)
193 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, &
194 efield=efield, energy=energy, para_env=para_env, sab_orb=sab_orb)
196 fieldpol = dft_control%efield_fields(1)%efield%polarisation* &
197 dft_control%efield_fields(1)%efield%strength
200 natom =
SIZE(particle_set)
201 IF (calculate_forces)
THEN
202 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, force=force)
208 CALL get_qs_kind(qs_kind_set(ikind), core_charge=charge)
209 ria = particle_set(ia)%r - rpoint
211 ci(:) = ci(:) + charge*ria(:)
212 IF (calculate_forces)
THEN
213 IF (para_env%mepos == 0)
THEN
214 iatom = atom_of_kind(ia)
216 force(ikind)%efield(idir, iatom) = force(ikind)%efield(idir, iatom) - fieldpol(idir)*charge
221 ener_field = -sum(ci(:)*fieldpol(:))
224 dipmat => efield%dipmat
225 NULLIFY (rho, matrix_p)
228 DO ispin = 1,
SIZE(matrix_p)
230 CALL dbcsr_dot(matrix_p(ispin)%matrix, dipmat(idir)%matrix, tmp)
231 ener_field = ener_field + fieldpol(idir)*tmp
234 energy%efield = ener_field
236 IF (.NOT. just_energy)
THEN
240 CALL get_qs_env(qs_env=qs_env, matrix_ks=matrix_ks)
241 DO ispin = 1,
SIZE(matrix_ks)
243 CALL dbcsr_add(matrix_ks(ispin)%matrix, dipmat(idir)%matrix, &
244 alpha_scalar=1.0_dp, beta_scalar=fieldpol(idir))
249 IF (calculate_forces)
THEN
250 nkind =
SIZE(qs_kind_set)
251 natom =
SIZE(particle_set)
253 ALLOCATE (basis_set_list(nkind))
255 qs_kind => qs_kind_set(ikind)
256 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set_a)
257 IF (
ASSOCIATED(basis_set_a))
THEN
258 basis_set_list(ikind)%gto_basis_set => basis_set_a
260 NULLIFY (basis_set_list(ikind)%gto_basis_set)
267 iatom=iatom, jatom=jatom, r=rab)
268 basis_set_a => basis_set_list(ikind)%gto_basis_set
269 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
270 basis_set_b => basis_set_list(jkind)%gto_basis_set
271 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
273 first_sgfa => basis_set_a%first_sgf
274 la_max => basis_set_a%lmax
275 la_min => basis_set_a%lmin
276 npgfa => basis_set_a%npgf
277 nseta = basis_set_a%nset
278 nsgfa => basis_set_a%nsgf_set
279 rpgfa => basis_set_a%pgf_radius
280 set_radius_a => basis_set_a%set_radius
281 sphi_a => basis_set_a%sphi
282 zeta => basis_set_a%zet
284 first_sgfb => basis_set_b%first_sgf
285 lb_max => basis_set_b%lmax
286 lb_min => basis_set_b%lmin
287 npgfb => basis_set_b%npgf
288 nsetb = basis_set_b%nset
289 nsgfb => basis_set_b%nsgf_set
290 rpgfb => basis_set_b%pgf_radius
291 set_radius_b => basis_set_b%set_radius
292 sphi_b => basis_set_b%sphi
293 zetb => basis_set_b%zet
295 atom_a = atom_of_kind(iatom)
296 atom_b = atom_of_kind(jatom)
298 ra(:) = particle_set(iatom)%r(:) - rpoint(:)
299 rac(:) =
pbc(ra(:), cell)
300 rbc(:) = rac(:) + rab(:)
301 dab = sqrt(rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3))
303 IF (iatom <= jatom)
THEN
314 IF (iatom == jatom .AND. dab < 1.e-10_dp) fdir = 1.0_dp
318 CALL dbcsr_get_block_p(matrix_p(1)%matrix, irow, icol, p_block_a, found)
319 IF (.NOT. found) cycle
320 IF (
SIZE(matrix_p) > 1)
THEN
322 CALL dbcsr_get_block_p(matrix_p(2)%matrix, irow, icol, p_block_b, found)
329 ncoa = npgfa(iset)*
ncoset(la_max(iset))
330 sgfa = first_sgfa(1, iset)
332 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
333 ncob = npgfb(jset)*
ncoset(lb_max(jset))
334 sgfb = first_sgfb(1, jset)
336 ldab = max(ncoa, ncob)
337 ALLOCATE (work(ldab, ldab), pmat(ncoa, ncob))
340 DO i = 1,
SIZE(matrix_p)
347 CALL dgemm(
"N",
"T", ncoa, nsgfb(jset), nsgfa(iset), &
348 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
349 pblock(sgfb, sgfa),
SIZE(pblock, 1), &
350 0.0_dp, work(1, 1), ldab)
352 CALL dgemm(
"N",
"N", ncoa, nsgfb(jset), nsgfa(iset), &
353 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
354 pblock(sgfa, sgfb),
SIZE(pblock, 1), &
355 0.0_dp, work(1, 1), ldab)
357 CALL dgemm(
"N",
"T", ncoa, ncob, nsgfb(jset), &
358 1.0_dp, work(1, 1), ldab, &
359 sphi_b(1, sgfb),
SIZE(sphi_b, 1), &
360 1.0_dp, pmat(1, 1), ncoa)
363 CALL dipole_force(la_max(iset), npgfa(iset), zeta(:, iset), rpgfa(:, iset), la_min(iset), &
364 lb_max(jset), npgfb(jset), zetb(:, jset), rpgfb(:, jset), lb_min(jset), &
365 1, rac, rbc, pmat, forcea, forceb)
367 DEALLOCATE (work, pmat)
372 force(ikind)%efield(1:3, atom_a) = force(ikind)%efield(1:3, atom_a) &
373 + fdir*fieldpol(idir)*forcea(idir, 1:3)
374 force(jkind)%efield(1:3, atom_b) = force(jkind)%efield(1:3, atom_b) &
375 + fdir*fieldpol(idir)*forceb(idir, 1:3)
380 DEALLOCATE (basis_set_list)
385 IF (calculate_forces)
THEN
386 DO ikind = 1,
SIZE(atomic_kind_set)
387 CALL para_env%sum(force(ikind)%efield)
391 CALL timestop(handle)
393 END SUBROUTINE qs_efield_mo_derivatives
subroutine pbc(r, r_pbc, s, s_pbc, a, b, c, alpha, beta, gamma, debug, info, pbc0, h, hinv)
...
static void dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Convenient wrapper to hide Fortran nature of dgemm_, swapping a and b.
Calculation of the moment integrals over Cartesian Gaussian-type functions.
subroutine, public dipole_force(la_max, npgfa, zeta, rpgfa, la_min, lb_max, npgfb, zetb, rpgfb, lb_min, order, rac, rbc, pab, forcea, forceb)
This returns the derivative of the dipole integrals [a|x|b], with respect to the position of the prim...
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Handles all functions related to the CELL.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public ncoset
Define the data structure for the particle information.
Calculates the energy contribution and the mo_derivative of a static electric field (nonperiodic)
subroutine, public qs_efield_local_operator(qs_env, just_energy, calculate_forces)
...
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.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, WannierCentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Set the QUICKSTEP environment.
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, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, 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_r3d_rs_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, 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, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
Calculates the moment integrals <a|r^m|b> and <a|r x d/dr|b>
subroutine, public build_local_moment_matrix(qs_env, moments, nmoments, ref_point, ref_points, basis_type)
...
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
type for berry phase efield matrices. At the moment only used for cosmat and sinmat
subroutine, public set_efield_matrices(efield, sinmat, cosmat, dipmat)
...
subroutine, public init_efield_matrices(efield)
...
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...