54#include "./base/base_uses.f90"
60 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_efield_local'
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
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)
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
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')
139 CALL timestop(handle)
141 END SUBROUTINE qs_efield_integrals
150 SUBROUTINE qs_efield_mo_derivatives(qs_env, rpoint, just_energy, calculate_forces)
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 :: handle, ia, iatom, idir, ikind, ispin, &
159 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: atom_of_kind
160 REAL(
dp) :: charge, ci(3), ener_field, fieldpol(3), &
162 REAL(
dp),
ALLOCATABLE,
DIMENSION(:, :) :: fdip
163 REAL(
dp),
DIMENSION(3) :: ria
166 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: dipmat, matrix_ks, matrix_p
173 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
176 CALL timeset(routinen, handle)
178 CALL get_qs_env(qs_env, dft_control=dft_control, cell=cell, particle_set=particle_set)
179 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, &
180 efield=efield, energy=energy, para_env=para_env)
182 fieldpol = dft_control%efield_fields(1)%efield%polarisation* &
183 dft_control%efield_fields(1)%efield%strength
186 natom =
SIZE(particle_set)
187 IF (calculate_forces)
THEN
188 CALL get_qs_env(qs_env=qs_env, atomic_kind_set=atomic_kind_set, force=force)
194 CALL get_qs_kind(qs_kind_set(ikind), core_charge=charge)
195 ria = particle_set(ia)%r - rpoint
197 ci(:) = ci(:) + charge*ria(:)
198 IF (calculate_forces)
THEN
199 IF (para_env%mepos == 0)
THEN
200 iatom = atom_of_kind(ia)
202 force(ikind)%efield(idir, iatom) = force(ikind)%efield(idir, iatom) - fieldpol(idir)*charge
207 ener_field = -sum(ci(:)*fieldpol(:))
210 dipmat => efield%dipmat
211 NULLIFY (rho, matrix_p)
214 DO ispin = 1,
SIZE(matrix_p)
216 CALL dbcsr_dot(matrix_p(ispin)%matrix, dipmat(idir)%matrix, tmp)
217 ener_field = ener_field + fieldpol(idir)*tmp
220 energy%efield = ener_field
222 IF (.NOT. just_energy)
THEN
226 CALL get_qs_env(qs_env=qs_env, matrix_ks=matrix_ks)
227 DO ispin = 1,
SIZE(matrix_ks)
229 CALL dbcsr_add(matrix_ks(ispin)%matrix, dipmat(idir)%matrix, &
230 alpha_scalar=1.0_dp, beta_scalar=fieldpol(idir))
235 IF (calculate_forces)
THEN
236 ALLOCATE (fdip(3, natom))
241 iatom = atom_of_kind(ia)
242 force(ikind)%efield(1:3, iatom) = force(ikind)%efield(1:3, iatom) + fdip(1:3, ia)
249 IF (calculate_forces)
THEN
250 DO ikind = 1,
SIZE(atomic_kind_set)
251 CALL para_env%sum(force(ikind)%efield)
255 CALL timestop(handle)
257 END SUBROUTINE qs_efield_mo_derivatives
271 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: field, rpoint
272 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: fdip
274 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_efield_dipole_force'
276 INTEGER :: handle, i, iatom, icol, idir, ikind, &
277 irow, iset, jatom, jkind, jset, ldab, &
278 ncoa, ncob, nkind, nseta, nsetb, sgfa, &
280 INTEGER,
DIMENSION(:),
POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
282 INTEGER,
DIMENSION(:, :),
POINTER :: first_sgfa, first_sgfb
283 LOGICAL :: found, trans
284 REAL(
dp) :: dab, fdir
285 REAL(
dp),
DIMENSION(3) :: ra, rab, rac, rbc
286 REAL(
dp),
DIMENSION(3, 3) :: forcea, forceb
287 REAL(
dp),
DIMENSION(:, :),
POINTER :: p_block_a, p_block_b, pblock, pmat, work
288 REAL(kind=
dp),
DIMENSION(:),
POINTER :: set_radius_a, set_radius_b
289 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: rpgfa, rpgfb, sphi_a, sphi_b, zeta, zetb
294 DIMENSION(:),
POINTER :: nl_iterator
298 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
301 CALL timeset(routinen, handle)
303 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set, qs_kind_set=qs_kind_set, &
306 nkind =
SIZE(qs_kind_set)
308 ALLOCATE (basis_set_list(nkind))
310 qs_kind => qs_kind_set(ikind)
311 CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set_a)
312 IF (
ASSOCIATED(basis_set_a))
THEN
313 basis_set_list(ikind)%gto_basis_set => basis_set_a
315 NULLIFY (basis_set_list(ikind)%gto_basis_set)
322 iatom=iatom, jatom=jatom, r=rab)
323 basis_set_a => basis_set_list(ikind)%gto_basis_set
324 IF (.NOT.
ASSOCIATED(basis_set_a)) cycle
325 basis_set_b => basis_set_list(jkind)%gto_basis_set
326 IF (.NOT.
ASSOCIATED(basis_set_b)) cycle
328 first_sgfa => basis_set_a%first_sgf
329 la_max => basis_set_a%lmax
330 la_min => basis_set_a%lmin
331 npgfa => basis_set_a%npgf
332 nseta = basis_set_a%nset
333 nsgfa => basis_set_a%nsgf_set
334 rpgfa => basis_set_a%pgf_radius
335 set_radius_a => basis_set_a%set_radius
336 sphi_a => basis_set_a%sphi
337 zeta => basis_set_a%zet
339 first_sgfb => basis_set_b%first_sgf
340 lb_max => basis_set_b%lmax
341 lb_min => basis_set_b%lmin
342 npgfb => basis_set_b%npgf
343 nsetb = basis_set_b%nset
344 nsgfb => basis_set_b%nsgf_set
345 rpgfb => basis_set_b%pgf_radius
346 set_radius_b => basis_set_b%set_radius
347 sphi_b => basis_set_b%sphi
348 zetb => basis_set_b%zet
350 ra(:) = particle_set(iatom)%r(:) - rpoint(:)
351 rac(:) =
pbc(ra(:), cell)
352 rbc(:) = rac(:) + rab(:)
353 dab = sqrt(rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3))
355 IF (iatom <= jatom)
THEN
366 IF (iatom == jatom .AND. dab < 1.e-10_dp) fdir = 1.0_dp
371 IF (.NOT. found) cycle
372 IF (
SIZE(matrix_p) > 1)
THEN
381 ncoa = npgfa(iset)*
ncoset(la_max(iset))
382 sgfa = first_sgfa(1, iset)
384 IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
385 ncob = npgfb(jset)*
ncoset(lb_max(jset))
386 sgfb = first_sgfb(1, jset)
388 ldab = max(ncoa, ncob)
389 ALLOCATE (work(ldab, ldab), pmat(ncoa, ncob))
392 DO i = 1,
SIZE(matrix_p)
399 CALL dgemm(
"N",
"T", ncoa, nsgfb(jset), nsgfa(iset), &
400 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
401 pblock(sgfb, sgfa),
SIZE(pblock, 1), &
402 0.0_dp, work(1, 1), ldab)
404 CALL dgemm(
"N",
"N", ncoa, nsgfb(jset), nsgfa(iset), &
405 1.0_dp, sphi_a(1, sgfa),
SIZE(sphi_a, 1), &
406 pblock(sgfa, sgfb),
SIZE(pblock, 1), &
407 0.0_dp, work(1, 1), ldab)
409 CALL dgemm(
"N",
"T", ncoa, ncob, nsgfb(jset), &
410 1.0_dp, work(1, 1), ldab, &
411 sphi_b(1, sgfb),
SIZE(sphi_b, 1), &
412 1.0_dp, pmat(1, 1), ncoa)
415 CALL dipole_force(la_max(iset), npgfa(iset), zeta(:, iset), rpgfa(:, iset), la_min(iset), &
416 lb_max(jset), npgfb(jset), zetb(:, jset), rpgfb(:, jset), lb_min(jset), &
417 1, rac, rbc, pmat, forcea, forceb)
419 DEALLOCATE (work, pmat)
424 fdip(1:3, iatom) = fdip(1:3, iatom) + fdir*field(idir)*forcea(idir, 1:3)
425 fdip(1:3, jatom) = fdip(1:3, jatom) + fdir*field(idir)*forceb(idir, 1:3)
430 DEALLOCATE (basis_set_list)
432 CALL timestop(handle)
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...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
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 qs_efield_dipole_force(qs_env, matrix_p, field, rpoint, fdip)
Electronic gradient from the nuclear derivative of the dipole integrals, dE/dR = sum_d field_d Tr(P d...
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.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, 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, rhoz_cneo_set, 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, harris_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, eeq, rhs, do_rixs, tb_tblite)
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, 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.
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, all_images, minimum_image, neighbor_image, first_component)
...
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...
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.