(git:374b731)
Loading...
Searching...
No Matches
ex_property_calculation.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 Routines for property calculations of excited states
10!> \par History
11!> 02.2020 Adapted from ec_properties
12!> \author JGH
13! **************************************************************************************************
17 USE cell_types, ONLY: cell_type,&
18 pbc
25 USE cp_output_handling, ONLY: cp_p_file,&
32 USE dbcsr_api, ONLY: dbcsr_add,&
33 dbcsr_copy,&
34 dbcsr_create,&
35 dbcsr_dot,&
36 dbcsr_p_type,&
37 dbcsr_release,&
38 dbcsr_set,&
39 dbcsr_type
46 USE kinds, ONLY: default_path_length,&
48 dp
51 USE mulliken, ONLY: mulliken_charges
53 USE physcon, ONLY: debye
56 USE qs_kind_types, ONLY: get_qs_kind,&
60 USE qs_rho_types, ONLY: qs_rho_get,&
62#include "./base/base_uses.f90"
63
64 IMPLICIT NONE
65
66 PRIVATE
67
68 ! Global parameters
69
70 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ex_property_calculation'
71
72 PUBLIC :: ex_properties
73
74CONTAINS
75
76! **************************************************************************************************
77!> \brief ...
78!> \param qs_env ...
79!> \param matrix_pe ...
80!> \param p_env ...
81! **************************************************************************************************
82 SUBROUTINE ex_properties(qs_env, matrix_pe, p_env)
83 TYPE(qs_environment_type), POINTER :: qs_env
84 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_pe
85 TYPE(qs_p_env_type) :: p_env
86
87 CHARACTER(LEN=*), PARAMETER :: routinen = 'ex_properties'
88
89 CHARACTER(LEN=8), DIMENSION(3) :: rlab
90 CHARACTER(LEN=default_path_length) :: filename
91 CHARACTER(LEN=default_string_length) :: description
92 INTEGER :: akind, handle, i, ia, iatom, idir, &
93 ikind, iounit, ispin, maxmom, natom, &
94 nspins, reference, unit_nr
95 LOGICAL :: magnetic, periodic, tb
96 REAL(kind=dp) :: charge, dd, q, tmp
97 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: mcharge
98 REAL(kind=dp), DIMENSION(3) :: cdip, pdip, pedip, rcc, rdip, ria, tdip
99 REAL(kind=dp), DIMENSION(:), POINTER :: ref_point
100 TYPE(atomic_kind_type), POINTER :: atomic_kind
101 TYPE(cell_type), POINTER :: cell
102 TYPE(cp_logger_type), POINTER :: logger
103 TYPE(cp_result_type), POINTER :: results
104 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_p, matrix_s, moments
105 TYPE(dbcsr_type), POINTER :: matrix_pall
106 TYPE(dft_control_type), POINTER :: dft_control
107 TYPE(distribution_1d_type), POINTER :: local_particles
108 TYPE(mp_para_env_type), POINTER :: para_env
109 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
110 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
111 TYPE(qs_rho_type), POINTER :: rho
112 TYPE(section_vals_type), POINTER :: print_key
113
114 CALL timeset(routinen, handle)
115
116 rlab(1) = "X"
117 rlab(2) = "Y"
118 rlab(3) = "Z"
119
120 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
121 tb = (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb)
122
123 logger => cp_get_default_logger()
124 IF (logger%para_env%is_source()) THEN
125 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
126 ELSE
127 iounit = -1
128 END IF
129
130 print_key => section_vals_get_subs_vals(section_vals=qs_env%input, &
131 subsection_name="DFT%PRINT%MOMENTS")
132
133 IF (btest(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
134
135 maxmom = section_get_ival(section_vals=qs_env%input, &
136 keyword_name="DFT%PRINT%MOMENTS%MAX_MOMENT")
137 periodic = section_get_lval(section_vals=qs_env%input, &
138 keyword_name="DFT%PRINT%MOMENTS%PERIODIC")
139 reference = section_get_ival(section_vals=qs_env%input, &
140 keyword_name="DFT%PRINT%MOMENTS%REFERENCE")
141 magnetic = section_get_lval(section_vals=qs_env%input, &
142 keyword_name="DFT%PRINT%MOMENTS%MAGNETIC")
143 NULLIFY (ref_point)
144 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%MOMENTS%REF_POINT", r_vals=ref_point)
145 unit_nr = cp_print_key_unit_nr(logger=logger, basis_section=qs_env%input, &
146 print_key_path="DFT%PRINT%MOMENTS", extension=".dat", &
147 middle_name="moments", log_filename=.false.)
148
149 IF (iounit > 0) THEN
150 IF (unit_nr /= iounit .AND. unit_nr > 0) THEN
151 INQUIRE (unit=unit_nr, name=filename)
152 WRITE (unit=iounit, fmt="(/,T2,A,2(/,T3,A),/)") &
153 "MOMENTS", "The electric/magnetic moments are written to file:", &
154 trim(filename)
155 ELSE
156 WRITE (unit=iounit, fmt="(/,T2,A)") "ELECTRIC/MAGNETIC MOMENTS"
157 END IF
158 END IF
159
160 IF (periodic) THEN
161 cpabort("Periodic moments not implemented with TDDFT")
162 ELSE
163 cpassert(maxmom < 2)
164 cpassert(.NOT. magnetic)
165 IF (maxmom == 1) THEN
166 CALL get_qs_env(qs_env=qs_env, cell=cell, para_env=para_env)
167 ! reference point
168 CALL get_reference_point(rcc, qs_env=qs_env, reference=reference, ref_point=ref_point)
169 ! nuclear contribution
170 cdip = 0.0_dp
171 CALL get_qs_env(qs_env=qs_env, particle_set=particle_set, &
172 qs_kind_set=qs_kind_set, local_particles=local_particles)
173 DO ikind = 1, SIZE(local_particles%n_el)
174 DO ia = 1, local_particles%n_el(ikind)
175 iatom = local_particles%list(ikind)%array(ia)
176 ! fold atomic positions back into unit cell
177 ria = pbc(particle_set(iatom)%r - rcc, cell) + rcc
178 ria = ria - rcc
179 atomic_kind => particle_set(iatom)%atomic_kind
180 CALL get_atomic_kind(atomic_kind, kind_number=akind)
181 CALL get_qs_kind(qs_kind_set(akind), core_charge=charge)
182 cdip(1:3) = cdip(1:3) - charge*ria(1:3)
183 END DO
184 END DO
185 CALL para_env%sum(cdip)
186 !
187 ! electronic contribution
188 CALL get_qs_env(qs_env=qs_env, rho=rho, matrix_s=matrix_s)
189 CALL qs_rho_get(rho, rho_ao=matrix_p)
190 nspins = SIZE(matrix_p, 1)
191 IF (tb) THEN
192 ALLOCATE (matrix_pall)
193 CALL dbcsr_create(matrix_pall, template=matrix_s(1)%matrix)
194 CALL dbcsr_copy(matrix_pall, matrix_s(1)%matrix, "Moments")
195 CALL dbcsr_set(matrix_pall, 0.0_dp)
196 DO ispin = 1, nspins
197 CALL dbcsr_add(matrix_pall, matrix_p(ispin)%matrix, 1.0_dp, 1.0_dp)
198 CALL dbcsr_add(matrix_pall, matrix_pe(ispin)%matrix, 1.0_dp, 1.0_dp)
199 CALL dbcsr_add(matrix_pall, p_env%p1(ispin)%matrix, 1.0_dp, 1.0_dp)
200 END DO
201 CALL get_qs_env(qs_env=qs_env, natom=natom)
202 ! Mulliken charges
203 ALLOCATE (mcharge(natom))
204 !
205 CALL mulliken_charges(matrix_pall, matrix_s(1)%matrix, para_env, mcharge)
206 !
207 rdip = 0.0_dp
208 pdip = 0.0_dp
209 pedip = 0.0_dp
210 DO i = 1, SIZE(particle_set)
211 ria = pbc(particle_set(i)%r - rcc, cell) + rcc
212 ria = ria - rcc
213 q = mcharge(i)
214 rdip = rdip + q*ria
215 END DO
216 CALL dbcsr_release(matrix_pall)
217 DEALLOCATE (matrix_pall)
218 DEALLOCATE (mcharge)
219 ELSE
220 ! KS-DFT
221 NULLIFY (moments)
222 CALL dbcsr_allocate_matrix_set(moments, 4)
223 DO i = 1, 4
224 ALLOCATE (moments(i)%matrix)
225 CALL dbcsr_copy(moments(i)%matrix, matrix_s(1)%matrix, "Moments")
226 CALL dbcsr_set(moments(i)%matrix, 0.0_dp)
227 END DO
228 CALL build_local_moment_matrix(qs_env, moments, 1, ref_point=rcc)
229 !
230 rdip = 0.0_dp
231 pdip = 0.0_dp
232 pedip = 0.0_dp
233 DO ispin = 1, nspins
234 DO idir = 1, 3
235 CALL dbcsr_dot(matrix_pe(ispin)%matrix, moments(idir)%matrix, tmp)
236 pedip(idir) = pedip(idir) + tmp
237 CALL dbcsr_dot(matrix_p(ispin)%matrix, moments(idir)%matrix, tmp)
238 pdip(idir) = pdip(idir) + tmp
239 CALL dbcsr_dot(p_env%p1(ispin)%matrix, moments(idir)%matrix, tmp)
240 rdip(idir) = rdip(idir) + tmp
241 END DO
242 END DO
243 CALL dbcsr_deallocate_matrix_set(moments)
244 END IF
245
246 tdip = -(rdip + pedip + pdip + cdip)
247
248 IF (unit_nr > 0) THEN
249 WRITE (unit_nr, "(T3,A)") "Dipoles are based on the traditional operator."
250 dd = sqrt(sum(tdip(1:3)**2))*debye
251 WRITE (unit_nr, "(T3,A)") "Dipole moment [Debye]"
252 WRITE (unit_nr, "(T5,3(A,A,F14.8,1X),T60,A,T67,F14.8)") &
253 (trim(rlab(i)), "=", tdip(i)*debye, i=1, 3), "Total=", dd
254 WRITE (unit_nr, fmt="(T2,A,T61,E20.12)") ' DIPOLE : CheckSum =', sum(abs(tdip))
255 END IF
256 END IF
257 END IF
258
259 CALL get_qs_env(qs_env=qs_env, results=results)
260 description = "[DIPOLE]"
261 CALL cp_results_erase(results=results, description=description)
262 CALL put_results(results=results, description=description, values=tdip(1:3))
263
264 CALL cp_print_key_finished_output(unit_nr=unit_nr, logger=logger, &
265 basis_section=qs_env%input, print_key_path="DFT%PRINT%MOMENTS")
266 END IF
267
268 CALL timestop(handle)
269
270 END SUBROUTINE ex_properties
271
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
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
set of type/routines to handle the storage of results in force_envs
subroutine, public cp_results_erase(results, description, nval)
erase a part of result_list
set of type/routines to handle the storage of results in force_envs
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
Routines for property calculations of excited states.
subroutine, public ex_properties(qs_env, matrix_pe, p_env)
...
objects that represent the structure of input sections and the data contained in an input section
integer function, public section_get_ival(section_vals, keyword_name)
...
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
logical function, public section_get_lval(section_vals, keyword_name)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Interface to the message passing library MPI.
Calculates the moment integrals <a|r^m|b>
subroutine, public get_reference_point(rpoint, drpoint, qs_env, fist_env, reference, ref_point, ifirst, ilast)
...
compute mulliken charges we (currently) define them as c_i = 1/2 [ (PS)_{ii} + (SP)_{ii} ]
Definition mulliken.F:13
Define the data structure for the particle information.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public debye
Definition physcon.F:201
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.
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>
Definition qs_moments.F:14
subroutine, public build_local_moment_matrix(qs_env, moments, nmoments, ref_point, ref_points, basis_type)
...
Definition qs_moments.F:558
basis types for the calculation of the perturbation of density theory.
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.
Definition cell_types.F:55
type of a logger, at the moment it contains just a print level starting at which level it should be l...
contains arbitrary information which need to be stored
structure to store local (to a processor) ordered lists of integers.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
Represent a qs system that is perturbed. Can calculate the linear operator and the rhs of the system ...
keeps the density in various representations, keeping track of which ones are valid.