(git:ccc2433)
qs_linres_epr_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 g tensor calculation by dfpt
10 !> Initialization of the epr_env, creation of the special neighbor lists
11 !> Perturbation Hamiltonians by application of the p and rxp oprtators to psi0
12 !> Write output
13 !> Deallocate everything
14 !> \note
15 !> The psi0 should be localized
16 !> the Sebastiani method works within the assumption that the orbitals are
17 !> completely contained in the simulation box
18 !> \par History
19 !> created 07-2005 [MI]
20 !> \author MI
21 ! **************************************************************************************************
23  USE atomic_kind_types, ONLY: atomic_kind_type
24  USE cell_types, ONLY: cell_type
25  USE cp_control_types, ONLY: dft_control_type
27  cp_logger_type
31  section_vals_type
32  USE kinds, ONLY: dp
33  USE mathconstants, ONLY: fourpi,&
34  twopi
35  USE particle_types, ONLY: particle_type
36  USE physcon, ONLY: a_fine,&
37  e_gfactor
38  USE pw_env_types, ONLY: pw_env_get,&
39  pw_env_type
40  USE pw_pool_types, ONLY: pw_pool_type
41  USE pw_types, ONLY: pw_c1d_gs_type,&
42  pw_r3d_rs_type
43  USE qs_environment_types, ONLY: get_qs_env,&
44  qs_environment_type
45  USE qs_kind_types, ONLY: qs_kind_type
47  epr_env_type,&
49  linres_control_type,&
50  nablavks_atom_type,&
52  USE qs_matrix_pools, ONLY: qs_matrix_pools_type
53  USE qs_mo_types, ONLY: mo_set_type
55  USE qs_rho_types, ONLY: qs_rho_clear,&
58  USE scf_control_types, ONLY: scf_control_type
59 #include "./base/base_uses.f90"
60 
61  IMPLICIT NONE
62 
63  PRIVATE
64 
65  PUBLIC :: epr_env_cleanup, epr_env_init
66 
67  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_linres_epr_utils'
68 
69 CONTAINS
70 
71 ! **************************************************************************************************
72 !> \brief Initialize the epr environment
73 !> \param epr_env ...
74 !> \param qs_env ...
75 !> \par History
76 !> 07.2006 created [MI]
77 !> \author MI
78 ! **************************************************************************************************
79  SUBROUTINE epr_env_init(epr_env, qs_env)
80  !
81  TYPE(epr_env_type) :: epr_env
82  TYPE(qs_environment_type), POINTER :: qs_env
83 
84  CHARACTER(LEN=*), PARAMETER :: routinen = 'epr_env_init'
85 
86  INTEGER :: handle, i_b, idir, ispin, n_mo(2), nao, &
87  natom, nmoloc, nspins, output_unit
88  LOGICAL :: gapw
89  TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
90  TYPE(cell_type), POINTER :: cell
91  TYPE(cp_logger_type), POINTER :: logger
92  TYPE(dft_control_type), POINTER :: dft_control
93  TYPE(linres_control_type), POINTER :: linres_control
94  TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
95  TYPE(nablavks_atom_type), DIMENSION(:), POINTER :: nablavks_atom_set
96  TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
97  TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
98  TYPE(pw_env_type), POINTER :: pw_env
99  TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
100  TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
101  TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
102  TYPE(qs_matrix_pools_type), POINTER :: mpools
103  TYPE(scf_control_type), POINTER :: scf_control
104  TYPE(section_vals_type), POINTER :: lr_section
105 
106  CALL timeset(routinen, handle)
107 
108  NULLIFY (atomic_kind_set, qs_kind_set, cell, dft_control, linres_control, scf_control)
109  NULLIFY (logger, mos, mpools, particle_set)
110  NULLIFY (auxbas_pw_pool, pw_env)
111  NULLIFY (nablavks_atom_set)
112 
113  n_mo(1:2) = 0
114  nao = 0
115  nmoloc = 0
116 
117  logger => cp_get_default_logger()
118  lr_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%LINRES")
119 
120  output_unit = cp_print_key_unit_nr(logger, lr_section, "PRINT%PROGRAM_RUN_INFO", &
121  extension=".linresLog")
122 
123  CALL epr_env_cleanup(epr_env)
124 
125  IF (output_unit > 0) THEN
126  WRITE (output_unit, "(/,T20,A,/)") "*** Start EPR g tensor calculation ***"
127  WRITE (output_unit, "(T10,A,/)") "Initialization of the EPR environment"
128  END IF
129 
130  CALL get_qs_env(qs_env=qs_env, &
131  atomic_kind_set=atomic_kind_set, &
132  qs_kind_set=qs_kind_set, &
133  cell=cell, &
134  dft_control=dft_control, &
135  linres_control=linres_control, &
136  mos=mos, &
137  mpools=mpools, &
138  particle_set=particle_set, &
139  pw_env=pw_env, &
140  scf_control=scf_control)
141  !
142  ! Check if restat also psi0 should be restarted
143  !IF(epr_env%restart_epr .AND. scf_control%density_guess/=restart_guess)THEN
144  ! CPABORT("restart_epr requires density_guess=restart")
145  !ENDIF
146  !
147  ! check that the psi0 are localized and you have all the centers
148  cpassert(linres_control%localized_psi0)
149  IF (output_unit > 0) THEN
150  WRITE (output_unit, '(A)') &
151  ' To get EPR parameters within PBC you need localized zero order orbitals '
152  END IF
153  gapw = dft_control%qs_control%gapw
154  nspins = dft_control%nspins
155  natom = SIZE(particle_set, 1)
156  !
157  ! Conversion factors
158  ! Magical constant twopi/cell%deth just like in NMR shift (basically undo scale_fac in qs_linres_nmr_current.F)
159  epr_env%g_free_factor = -1.0_dp*e_gfactor
160  epr_env%g_zke_factor = e_gfactor*(a_fine)**2
161  epr_env%g_so_factor = (a_fine)**2*(-1.0_dp*e_gfactor - 1.0_dp)/2.0_dp*twopi/cell%deth
162  epr_env%g_so_factor_gapw = (a_fine)**2*(-1.0_dp*e_gfactor - 1.0_dp)/2.0_dp
163  ! * 2 because B_ind = 2 * B_beta
164  epr_env%g_soo_factor = 2.0_dp*fourpi*(a_fine)**2*twopi/cell%deth
165  ! 2 * 2 * 1/4 * e^2 / m * a_0^2 * 2/3 * mu_0 / (omega * 1e-30 )
166  epr_env%g_soo_chicorr_factor = 2.0/3.0_dp*fourpi*(a_fine)**2/cell%deth
167  !
168  ! If the current density on the grid needs to be stored
169  CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
170  !
171  ! Initialize local current density if GAPW calculation
172  IF (gapw) THEN
173  CALL init_nablavks_atom_set(nablavks_atom_set, atomic_kind_set, qs_kind_set, nspins)
174  CALL set_epr_env(epr_env=epr_env, &
175  nablavks_atom_set=nablavks_atom_set)
176  END IF
177  !
178  ! Bind
179  ALLOCATE (epr_env%bind_set(3, 3))
180  DO i_b = 1, 3
181  DO idir = 1, 3
182  NULLIFY (epr_env%bind_set(idir, i_b)%rho, rho_r, rho_g)
183  ALLOCATE (epr_env%bind_set(idir, i_b)%rho)
184  CALL qs_rho_create(epr_env%bind_set(idir, i_b)%rho)
185  ALLOCATE (rho_r(1), rho_g(1))
186  CALL auxbas_pw_pool%create_pw(rho_r(1))
187  CALL auxbas_pw_pool%create_pw(rho_g(1))
188  CALL qs_rho_set(epr_env%bind_set(idir, i_b)%rho, rho_r=rho_r, rho_g=rho_g)
189  END DO
190  END DO
191 
192  ! Nabla_V_ks
193  ALLOCATE (epr_env%nablavks_set(3, dft_control%nspins))
194  DO idir = 1, 3
195  DO ispin = 1, nspins
196  NULLIFY (epr_env%nablavks_set(idir, ispin)%rho, rho_r, rho_g)
197  ALLOCATE (epr_env%nablavks_set(idir, ispin)%rho)
198  CALL qs_rho_create(epr_env%nablavks_set(idir, ispin)%rho)
199  ALLOCATE (rho_r(1), rho_g(1))
200  CALL auxbas_pw_pool%create_pw(rho_r(1))
201  CALL auxbas_pw_pool%create_pw(rho_g(1))
202  CALL qs_rho_set(epr_env%nablavks_set(idir, ispin)%rho, &
203  rho_r=rho_r, rho_g=rho_g)
204  END DO
205  END DO
206 
207  ! Initialize the g tensor components
208  ALLOCATE (epr_env%g_total(3, 3))
209  ALLOCATE (epr_env%g_so(3, 3))
210  ALLOCATE (epr_env%g_soo(3, 3))
211  epr_env%g_total = 0.0_dp
212  epr_env%g_zke = 0.0_dp
213  epr_env%g_so = 0.0_dp
214  epr_env%g_soo = 0.0_dp
215 
216  CALL cp_print_key_finished_output(output_unit, logger, lr_section,&
217  & "PRINT%PROGRAM_RUN_INFO")
218 
219  CALL timestop(handle)
220 
221  END SUBROUTINE epr_env_init
222 
223 ! **************************************************************************************************
224 !> \brief Deallocate the epr environment
225 !> \param epr_env ...
226 !> \par History
227 !> 07.2005 created [MI]
228 !> \author MI
229 ! **************************************************************************************************
230  SUBROUTINE epr_env_cleanup(epr_env)
231 
232  TYPE(epr_env_type) :: epr_env
233 
234  INTEGER :: i_b, idir, ispin
235 
236  ! nablavks_set
237  IF (ASSOCIATED(epr_env%nablavks_set)) THEN
238  DO ispin = 1, SIZE(epr_env%nablavks_set, 2)
239  DO idir = 1, SIZE(epr_env%nablavks_set, 1)
240  CALL qs_rho_clear(epr_env%nablavks_set(idir, ispin)%rho)
241  DEALLOCATE (epr_env%nablavks_set(idir, ispin)%rho)
242  END DO
243  END DO
244  DEALLOCATE (epr_env%nablavks_set)
245  END IF
246  ! nablavks_atom_set
247  IF (ASSOCIATED(epr_env%nablavks_atom_set)) THEN
248  CALL deallocate_nablavks_atom_set(epr_env%nablavks_atom_set)
249  END IF
250  ! vks_atom_set
251  IF (ASSOCIATED(epr_env%vks_atom_set)) THEN
252  CALL deallocate_rho_atom_set(epr_env%vks_atom_set)
253  END IF
254  ! bind_set
255  IF (ASSOCIATED(epr_env%bind_set)) THEN
256  DO i_b = 1, SIZE(epr_env%bind_set, 2)
257  DO idir = 1, SIZE(epr_env%bind_set, 1)
258  CALL qs_rho_clear(epr_env%bind_set(idir, i_b)%rho)
259  DEALLOCATE (epr_env%bind_set(idir, i_b)%rho)
260  END DO
261  END DO
262  DEALLOCATE (epr_env%bind_set)
263  END IF
264  ! bind_atom_set
265  IF (ASSOCIATED(epr_env%bind_atom_set)) THEN
266  DEALLOCATE (epr_env%bind_atom_set)
267  END IF
268  ! g_total
269  IF (ASSOCIATED(epr_env%g_total)) THEN
270  DEALLOCATE (epr_env%g_total)
271  END IF
272  ! g_so
273  IF (ASSOCIATED(epr_env%g_so)) THEN
274  DEALLOCATE (epr_env%g_so)
275  END IF
276  ! g_soo
277  IF (ASSOCIATED(epr_env%g_soo)) THEN
278  DEALLOCATE (epr_env%g_soo)
279  END IF
280 
281  END SUBROUTINE epr_env_cleanup
282 
283 END MODULE qs_linres_epr_utils
Define the atomic kind types and their sub types.
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...
various routines to log and control the output. The idea is that decisions about where to log should ...
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,...
objects that represent the structure of input sections and the data contained in an input section
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
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Definition of mathematical constants and functions.
Definition: mathconstants.F:16
real(kind=dp), parameter, public fourpi
real(kind=dp), parameter, public twopi
Define the data structure for the particle information.
Definition of physical constants:
Definition: physcon.F:68
real(kind=dp), parameter, public a_fine
Definition: physcon.F:119
real(kind=dp), parameter, public e_gfactor
Definition: physcon.F:115
container for various plainwaves related things
Definition: pw_env_types.F:14
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Definition: pw_env_types.F:113
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Definition: pw_pool_types.F:24
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
g tensor calculation by dfpt Initialization of the epr_env, creation of the special neighbor lists Pe...
subroutine, public epr_env_cleanup(epr_env)
Deallocate the epr environment.
subroutine, public epr_env_init(epr_env, qs_env)
Initialize the epr environment.
Type definitiona for linear response calculations.
subroutine, public deallocate_nablavks_atom_set(nablavks_atom_set)
...
subroutine, public set_epr_env(epr_env, g_free_factor, g_soo_chicorr_factor, g_soo_factor, g_so_factor, g_so_factor_gapw, g_zke_factor, nablavks_set, nablavks_atom_set)
...
subroutine, public init_nablavks_atom_set(nablavks_atom_set, atomic_kind_set, qs_kind_set, nspins)
...
wrapper for the pools of matrixes
Definition and initialisation of the mo data type.
Definition: qs_mo_types.F:22
subroutine, public deallocate_rho_atom_set(rho_atom_set)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
Definition: qs_rho_types.F:18
subroutine, public qs_rho_set(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)
...
Definition: qs_rho_types.F:308
subroutine, public qs_rho_create(rho)
Allocates a new instance of rho.
Definition: qs_rho_types.F:99
subroutine, public qs_rho_clear(rho_struct)
Deallocates all components, without deallocating rho_struct itself.
Definition: qs_rho_types.F:125
parameters that control an scf iteration