(git:ccc2433)
moments_utils.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief Calculates the moment integrals <a|r^m|b>
10 !> \par History
11 !> 12.2007 [tlaino] - Splitting common routines to QS and FIST
12 !> 06.2009 [tlaino] - Extending to molecular dipoles (interval of atoms)
13 !> \author JGH (20.07.2006)
14 ! **************************************************************************************************
16  USE atomic_kind_types, ONLY: atomic_kind_type,&
18  USE cell_types, ONLY: cell_type,&
19  pbc
20  USE distribution_1d_types, ONLY: distribution_1d_type
22  fist_environment_type
27  USE kinds, ONLY: dp
28  USE message_passing, ONLY: mp_para_env_type
29  USE particle_types, ONLY: particle_type
30  USE qs_environment_types, ONLY: get_qs_env,&
31  qs_environment_type
32  USE qs_kind_types, ONLY: get_qs_kind,&
33  qs_kind_type
34 #include "./base/base_uses.f90"
35 
36  IMPLICIT NONE
37 
38  PRIVATE
39 
40  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'moments_utils'
41 
42 ! *** Public subroutines ***
43 
44  PUBLIC :: get_reference_point
45 
46 CONTAINS
47 
48 ! **************************************************************************************************
49 !> \brief ...
50 !> \param rpoint ...
51 !> \param drpoint ...
52 !> \param qs_env ...
53 !> \param fist_env ...
54 !> \param reference ...
55 !> \param ref_point ...
56 !> \param ifirst ...
57 !> \param ilast ...
58 ! **************************************************************************************************
59  SUBROUTINE get_reference_point(rpoint, drpoint, qs_env, fist_env, reference, ref_point, &
60  ifirst, ilast)
61  REAL(dp), DIMENSION(3), INTENT(OUT) :: rpoint
62  REAL(dp), DIMENSION(3), INTENT(OUT), OPTIONAL :: drpoint
63  TYPE(qs_environment_type), OPTIONAL, POINTER :: qs_env
64  TYPE(fist_environment_type), OPTIONAL, POINTER :: fist_env
65  INTEGER, INTENT(IN) :: reference
66  REAL(kind=dp), DIMENSION(:), POINTER :: ref_point
67  INTEGER, INTENT(IN), OPTIONAL :: ifirst, ilast
68 
69  INTEGER :: akind, ia, iatom, ikind
70  LOGICAL :: do_molecule
71  REAL(dp) :: charge, mass, mass_low, mtot, ztot
72  REAL(dp), DIMENSION(3) :: center, ria
73  TYPE(atomic_kind_type), POINTER :: atomic_kind
74  TYPE(cell_type), POINTER :: cell
75  TYPE(distribution_1d_type), POINTER :: local_particles
76  TYPE(mp_para_env_type), POINTER :: para_env
77  TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
78  TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
79 
80  cpassert(PRESENT(ifirst) .EQV. PRESENT(ilast))
81  NULLIFY (cell, particle_set, qs_kind_set, local_particles, para_env)
82  IF (PRESENT(qs_env)) THEN
83  CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set, &
84  qs_kind_set=qs_kind_set, &
85  local_particles=local_particles, para_env=para_env)
86  END IF
87  IF (PRESENT(fist_env)) THEN
88  CALL fist_env_get(fist_env, cell=cell, particle_set=particle_set, &
89  local_particles=local_particles, para_env=para_env)
90  END IF
91  do_molecule = .false.
92  IF (PRESENT(ifirst) .AND. PRESENT(ilast)) do_molecule = .true.
93  IF (PRESENT(drpoint)) drpoint = 0.0_dp
94  SELECT CASE (reference)
95  CASE DEFAULT
96  cpabort("Type of reference point not implemented")
97  CASE (use_mom_ref_com)
98  rpoint = 0._dp
99  mtot = 0._dp
100  center(:) = 0._dp
101  IF (do_molecule) THEN
102  mass_low = -huge(mass_low)
103  ! fold the molecule around the heaviest atom in the molecule
104  DO iatom = ifirst, ilast
105  atomic_kind => particle_set(iatom)%atomic_kind
106  CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
107  IF (mass > mass_low) THEN
108  mass_low = mass
109  center = particle_set(iatom)%r
110  END IF
111  END DO
112  DO iatom = ifirst, ilast
113  ria = particle_set(iatom)%r
114  ria = pbc(ria - center, cell) + center
115  atomic_kind => particle_set(iatom)%atomic_kind
116  CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
117  rpoint(:) = rpoint(:) + mass*ria(:)
118  IF (PRESENT(drpoint)) drpoint = drpoint + mass*particle_set(iatom)%v
119  mtot = mtot + mass
120  END DO
121  ELSE
122  DO ikind = 1, SIZE(local_particles%n_el)
123  DO ia = 1, local_particles%n_el(ikind)
124  iatom = local_particles%list(ikind)%array(ia)
125  ria = particle_set(iatom)%r
126  ria = pbc(ria, cell)
127  atomic_kind => particle_set(iatom)%atomic_kind
128  CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
129  rpoint(:) = rpoint(:) + mass*ria(:)
130  IF (PRESENT(drpoint)) drpoint = drpoint + mass*particle_set(iatom)%v
131  mtot = mtot + mass
132  END DO
133  END DO
134  CALL para_env%sum(rpoint)
135  CALL para_env%sum(mtot)
136  END IF
137  IF (abs(mtot) > 0._dp) THEN
138  rpoint(:) = rpoint(:)/mtot
139  IF (PRESENT(drpoint)) drpoint = drpoint/mtot
140  END IF
141  CASE (use_mom_ref_coac)
142  rpoint = 0._dp
143  ztot = 0._dp
144  center(:) = 0._dp
145  IF (do_molecule) THEN
146  mass_low = -huge(mass_low)
147  ! fold the molecule around the heaviest atom in the molecule
148  DO iatom = ifirst, ilast
149  atomic_kind => particle_set(iatom)%atomic_kind
150  CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
151  IF (mass > mass_low) THEN
152  mass_low = mass
153  center = particle_set(iatom)%r
154  END IF
155  END DO
156  DO iatom = ifirst, ilast
157  ria = particle_set(iatom)%r
158  ria = pbc(ria - center, cell) + center
159  atomic_kind => particle_set(iatom)%atomic_kind
160  CALL get_atomic_kind(atomic_kind, kind_number=akind)
161  CALL get_qs_kind(qs_kind_set(akind), core_charge=charge)
162  rpoint(:) = rpoint(:) + charge*ria(:)
163  IF (PRESENT(drpoint)) drpoint = drpoint + charge*particle_set(iatom)%v
164  ztot = ztot + charge
165  END DO
166  ELSE
167  DO ikind = 1, SIZE(local_particles%n_el)
168  DO ia = 1, local_particles%n_el(ikind)
169  iatom = local_particles%list(ikind)%array(ia)
170  ria = particle_set(iatom)%r
171  ria = pbc(ria, cell)
172  atomic_kind => particle_set(iatom)%atomic_kind
173  CALL get_atomic_kind(atomic_kind, kind_number=akind)
174  CALL get_qs_kind(qs_kind_set(akind), core_charge=charge)
175  rpoint(:) = rpoint(:) + charge*ria(:)
176  IF (PRESENT(drpoint)) drpoint = drpoint + charge*particle_set(iatom)%v
177  ztot = ztot + charge
178  END DO
179  END DO
180  CALL para_env%sum(rpoint)
181  CALL para_env%sum(ztot)
182  END IF
183  IF (abs(ztot) > 0._dp) THEN
184  rpoint(:) = rpoint(:)/ztot
185  IF (PRESENT(drpoint)) drpoint = drpoint/ztot
186  END IF
187  CASE (use_mom_ref_user)
188  rpoint = ref_point
189  CASE (use_mom_ref_zero)
190  rpoint = 0._dp
191  END SELECT
192 
193  END SUBROUTINE get_reference_point
194 
195 END MODULE moments_utils
196 
subroutine pbc(r, r_pbc, s, s_pbc, a, b, c, alpha, beta, gamma, debug, info, pbc0, h, hinv)
...
Definition: dumpdcd.F:1203
Define the atomic kind types and their sub types.
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.
Definition: cell_types.F:15
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
subroutine, public fist_env_get(fist_env, atomic_kind_set, particle_set, ewald_pw, local_particles, local_molecules, molecule_kind_set, molecule_set, cell, cell_ref, ewald_env, fist_nonbond_env, thermo, para_env, subsys, qmmm, qmmm_env, input, shell_model, shell_model_ad, shell_particle_set, core_particle_set, multipoles, results, exclusions, efield)
Purpose: Get the FIST environment.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public use_mom_ref_coac
integer, parameter, public use_mom_ref_user
integer, parameter, public use_mom_ref_com
integer, parameter, public use_mom_ref_zero
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Interface to the message passing library MPI.
Calculates the moment integrals <a|r^m|b>
Definition: moments_utils.F:15
subroutine, public get_reference_point(rpoint, drpoint, qs_env, fist_env, reference, ref_point, ifirst, ilast)
...
Definition: moments_utils.F:61
Define the data structure for the particle information.
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.
Define the quickstep kind type and their sub types.
Definition: qs_kind_types.F:23
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.