(git:0de0cc2)
qs_spin_orbit.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 Distribution of the spin orbit integral matrix.
10 !> \par History
11 !> \author VW (27.02.2009)
12 ! **************************************************************************************************
14  USE ai_spin_orbit, ONLY: pso
15  USE basis_set_types, ONLY: gto_basis_set_p_type,&
16  gto_basis_set_type
17  USE block_p_types, ONLY: block_p_type
18  USE cell_types, ONLY: cell_type,&
19  pbc
22  cp_logger_type
23  USE cp_output_handling, ONLY: cp_p_file,&
27  USE dbcsr_api, ONLY: dbcsr_get_block_p,&
28  dbcsr_p_type
30  USE kinds, ONLY: dp
31  USE message_passing, ONLY: mp_para_env_type
33  ncoset
34  USE particle_types, ONLY: particle_type
35  USE qs_environment_types, ONLY: get_qs_env,&
36  qs_environment_type
37  USE qs_kind_types, ONLY: get_qs_kind,&
39  qs_kind_type
43  neighbor_list_iterator_p_type,&
45  neighbor_list_set_p_type
46 #include "./base/base_uses.f90"
47 
48  IMPLICIT NONE
49 
50  PRIVATE
51 
52 ! *** Global parameters ***
53 
54  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_spin_orbit'
55 
56 ! *** Public subroutines ***
57 
58  PUBLIC :: build_pso_matrix
59 
60 CONTAINS
61 
62 ! **************************************************************************************************
63 !> \brief Calculation of the paramagnetic spin orbit matrix over
64 !> Cartesian Gaussian functions.
65 !> \param qs_env ...
66 !> \param matrix_so ...
67 !> \param rc ...
68 !> \date 27.02.2009
69 !> \author VW
70 !> \version 1.0
71 ! **************************************************************************************************
72 
73  SUBROUTINE build_pso_matrix(qs_env, matrix_so, rc)
74 
75  TYPE(qs_environment_type), POINTER :: qs_env
76  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_so
77  REAL(dp), DIMENSION(3), INTENT(IN) :: rc
78 
79  CHARACTER(len=*), PARAMETER :: routinen = 'build_pso_matrix'
80 
81  INTEGER :: after, handle, i, iatom, icol, ikind, inode, irow, iset, iw, jatom, jkind, jset, &
82  last_jatom, ldai, maxco, maxlgto, maxsgf, natom, ncoa, ncob, neighbor_list_id, nkind, &
83  nseta, nsetb, sgfa, sgfb
84  INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
85  npgfb, nsgfa, nsgfb
86  INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
87  LOGICAL :: found, new_atom_b, omit_headers
88  REAL(kind=dp) :: dab, rab2
89  REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: work
90  REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :, :) :: rr_work, soab
91  REAL(kind=dp), DIMENSION(3) :: ra, rab, rac, rb, rbc
92  REAL(kind=dp), DIMENSION(:), POINTER :: set_radius_a, set_radius_b
93  REAL(kind=dp), DIMENSION(:, :), POINTER :: rpgfa, rpgfb, sphi_a, sphi_b, zeta, zetb
94  TYPE(block_p_type), ALLOCATABLE, DIMENSION(:) :: soint
95  TYPE(cell_type), POINTER :: cell
96  TYPE(cp_logger_type), POINTER :: logger
97  TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
98  TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
99  TYPE(mp_para_env_type), POINTER :: para_env
100  TYPE(neighbor_list_iterator_p_type), &
101  DIMENSION(:), POINTER :: nl_iterator
102  TYPE(neighbor_list_set_p_type), DIMENSION(:), &
103  POINTER :: sab_orb
104  TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
105  TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
106  TYPE(qs_kind_type), POINTER :: qs_kind
107 
108  CALL timeset(routinen, handle)
109 
110  NULLIFY (cell, sab_orb, qs_kind_set, particle_set, para_env)
111  NULLIFY (logger)
112 
113  logger => cp_get_default_logger()
114 
115  CALL get_qs_env(qs_env=qs_env, &
116  qs_kind_set=qs_kind_set, &
117  particle_set=particle_set, &
118  neighbor_list_id=neighbor_list_id, &
119  para_env=para_env, &
120  sab_orb=sab_orb, &
121  cell=cell)
122 
123  nkind = SIZE(qs_kind_set)
124  natom = SIZE(particle_set)
125 
126 ! *** Allocate work storage ***
127 
128  CALL get_qs_kind_set(qs_kind_set=qs_kind_set, &
129  maxco=maxco, &
130  maxlgto=maxlgto, &
131  maxsgf=maxsgf)
132 
133  ldai = ncoset(maxlgto + 1)
134  CALL init_orbital_pointers(ldai)
135 
136  ALLOCATE (rr_work(0:2*maxlgto + 2, ldai, ldai))
137  ALLOCATE (soab(maxco, maxco, 3))
138  ALLOCATE (work(maxco, maxsgf))
139  ALLOCATE (soint(3))
140 
141  rr_work(:, :, :) = 0.0_dp
142  soab(:, :, :) = 0.0_dp
143  work(:, :) = 0.0_dp
144 
145  ALLOCATE (basis_set_list(nkind))
146  DO ikind = 1, nkind
147  qs_kind => qs_kind_set(ikind)
148  CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set_a)
149  IF (ASSOCIATED(basis_set_a)) THEN
150  basis_set_list(ikind)%gto_basis_set => basis_set_a
151  ELSE
152  NULLIFY (basis_set_list(ikind)%gto_basis_set)
153  END IF
154  END DO
155  CALL neighbor_list_iterator_create(nl_iterator, sab_orb)
156  DO WHILE (neighbor_list_iterate(nl_iterator) == 0)
157  CALL get_iterator_info(nl_iterator, ikind=ikind, jkind=jkind, inode=inode, &
158  iatom=iatom, jatom=jatom, r=rab)
159  basis_set_a => basis_set_list(ikind)%gto_basis_set
160  IF (.NOT. ASSOCIATED(basis_set_a)) cycle
161  basis_set_b => basis_set_list(jkind)%gto_basis_set
162  IF (.NOT. ASSOCIATED(basis_set_b)) cycle
163  ra = pbc(particle_set(iatom)%r, cell)
164  ! basis ikind
165  first_sgfa => basis_set_a%first_sgf
166  la_max => basis_set_a%lmax
167  la_min => basis_set_a%lmin
168  npgfa => basis_set_a%npgf
169  nseta = basis_set_a%nset
170  nsgfa => basis_set_a%nsgf_set
171  rpgfa => basis_set_a%pgf_radius
172  set_radius_a => basis_set_a%set_radius
173  sphi_a => basis_set_a%sphi
174  zeta => basis_set_a%zet
175  ! basis jkind
176  first_sgfb => basis_set_b%first_sgf
177  lb_max => basis_set_b%lmax
178  lb_min => basis_set_b%lmin
179  npgfb => basis_set_b%npgf
180  nsetb = basis_set_b%nset
181  nsgfb => basis_set_b%nsgf_set
182  rpgfb => basis_set_b%pgf_radius
183  set_radius_b => basis_set_b%set_radius
184  sphi_b => basis_set_b%sphi
185  zetb => basis_set_b%zet
186 
187  IF (inode == 1) last_jatom = 0
188 
189  rb = rab + ra
190  rab2 = rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3)
191  dab = sqrt(rab2)
192  rac = pbc(ra, rc, cell)
193  rbc = rac - rab
194 
195  IF (jatom /= last_jatom) THEN
196  new_atom_b = .true.
197  last_jatom = jatom
198  ELSE
199  new_atom_b = .false.
200  END IF
201 
202  IF (new_atom_b) THEN
203  IF (iatom <= jatom) THEN
204  irow = iatom
205  icol = jatom
206  ELSE
207  irow = jatom
208  icol = iatom
209  END IF
210 
211  DO i = 1, 3
212  NULLIFY (soint(i)%block)
213  CALL dbcsr_get_block_p(matrix=matrix_so(i)%matrix, &
214  row=irow, col=icol, block=soint(i)%block, found=found)
215  END DO
216  END IF
217 
218  DO iset = 1, nseta
219 
220  ncoa = npgfa(iset)*ncoset(la_max(iset))
221  sgfa = first_sgfa(1, iset)
222 
223  DO jset = 1, nsetb
224 
225  IF (set_radius_a(iset) + set_radius_b(jset) < dab) cycle
226 
227  ncob = npgfb(jset)*ncoset(lb_max(jset))
228  sgfb = first_sgfb(1, jset)
229 
230  ! *** Calculate the primitive fermi contact integrals ***
231 
232  CALL pso(la_max(iset), la_min(iset), npgfa(iset), &
233  rpgfa(:, iset), zeta(:, iset), &
234  lb_max(jset), lb_min(jset), npgfb(jset), &
235  rpgfb(:, jset), zetb(:, jset), &
236  rac, rbc, rab, soab, SIZE(rr_work, 1), SIZE(rr_work, 2), rr_work)
237 
238  ! *** Contraction step ***
239 
240  DO i = 1, 3
241 
242  CALL dgemm("N", "N", ncoa, nsgfb(jset), ncob, &
243  1.0_dp, soab(1, 1, i), SIZE(soab, 1), &
244  sphi_b(1, sgfb), SIZE(sphi_b, 1), &
245  0.0_dp, work(1, 1), SIZE(work, 1))
246 
247  IF (iatom <= jatom) THEN
248 
249  CALL dgemm("T", "N", nsgfa(iset), nsgfb(jset), ncoa, &
250  1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
251  work(1, 1), SIZE(work, 1), &
252  1.0_dp, soint(i)%block(sgfa, sgfb), &
253  SIZE(soint(i)%block, 1))
254 
255  ELSE
256 
257  CALL dgemm("T", "N", nsgfb(jset), nsgfa(iset), ncoa, &
258  -1.0_dp, work(1, 1), SIZE(work, 1), &
259  sphi_a(1, sgfa), SIZE(sphi_a, 1), &
260  1.0_dp, soint(i)%block(sgfb, sgfa), &
261  SIZE(soint(i)%block, 1))
262  END IF
263 
264  END DO
265 
266  END DO
267 
268  END DO
269 
270  END DO
271  CALL neighbor_list_iterator_release(nl_iterator)
272 
273  ! *** Release work storage ***
274 
275  DEALLOCATE (basis_set_list)
276 
277  DEALLOCATE (soab)
278 
279  DEALLOCATE (work)
280 
281  DEALLOCATE (soint)
282 
283 ! *** Print the spin orbit matrix, if requested ***
284 
285  IF (btest(cp_print_key_should_output(logger%iter_info, &
286  qs_env%input, "DFT%PRINT%AO_MATRICES/PSO"), cp_p_file)) THEN
287  iw = cp_print_key_unit_nr(logger, qs_env%input, "DFT%PRINT%AO_MATRICES/PSO", &
288  extension=".Log")
289  CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
290  after = min(max(after, 1), 16)
291  CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%OMIT_HEADERS", l_val=omit_headers)
292  CALL cp_dbcsr_write_sparse_matrix(matrix_so(1)%matrix, 4, after, qs_env, &
293  para_env, output_unit=iw, omit_headers=omit_headers)
294  CALL cp_dbcsr_write_sparse_matrix(matrix_so(2)%matrix, 4, after, qs_env, &
295  para_env, output_unit=iw, omit_headers=omit_headers)
296  CALL cp_dbcsr_write_sparse_matrix(matrix_so(3)%matrix, 4, after, qs_env, &
297  para_env, output_unit=iw, omit_headers=omit_headers)
298  CALL cp_print_key_finished_output(iw, logger, qs_env%input, &
299  "DFT%PRINT%AO_MATRICES/PSO")
300  END IF
301 
302  CALL timestop(handle)
303 
304  END SUBROUTINE build_pso_matrix
305 
306 ! **************************************************************************************************
307 
308 END MODULE qs_spin_orbit
309 
subroutine pbc(r, r_pbc, s, s_pbc, a, b, c, alpha, beta, gamma, debug, info, pbc0, h, hinv)
...
Definition: dumpdcd.F:1203
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 spin orbit integrals over Cartesian Gaussian-type functions.
Definition: ai_spin_orbit.F:37
subroutine, public pso(la_max, la_min, npgfa, rpgfa, zeta, lb_max, lb_min, npgfb, rpgfb, zetb, rac, rbc, rab, vab, ldrr1, ldrr2, rr)
Calculation of the primitive paramagnetic spin orbit integrals over Cartesian Gaussian-type functions...
Definition: ai_spin_orbit.F:81
collect pointers to a block of reals
Definition: block_p_types.F:14
Handles all functions related to the CELL.
Definition: cell_types.F:15
DBCSR output in CP2K.
subroutine, public cp_dbcsr_write_sparse_matrix(sparse_matrix, before, after, qs_env, para_env, first_row, last_row, first_col, last_col, scale, output_unit, omit_headers)
...
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,...
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...
objects that represent the structure of input sections and the data contained in an input section
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
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Interface to the message passing library MPI.
Provides Cartesian and spherical orbital pointers and indices.
subroutine, public init_orbital_pointers(maxl)
Initialize or update the orbital pointers.
integer, dimension(:), allocatable, public ncoset
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.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, basis_type, total_zeff_corr)
Get attributes of an atomic kind set.
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)
...
Distribution of the spin orbit integral matrix.
Definition: qs_spin_orbit.F:13
subroutine, public build_pso_matrix(qs_env, matrix_so, rc)
Calculation of the paramagnetic spin orbit matrix over Cartesian Gaussian functions.
Definition: qs_spin_orbit.F:74