Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Calculation of commutator [H,r] matrices
10 : !> \par History
11 : !> JGH: [7.2016]
12 : !> \author Juerg Hutter
13 : ! **************************************************************************************************
14 : MODULE qs_commutators
15 : USE cell_types, ONLY: cell_type
16 : USE commutator_rpnl, ONLY: build_com_mom_nl
17 : USE cp_control_types, ONLY: dft_control_type
18 : USE cp_dbcsr_api, ONLY: dbcsr_add,&
19 : dbcsr_create,&
20 : dbcsr_p_type,&
21 : dbcsr_scale,&
22 : dbcsr_set,&
23 : dbcsr_type_antisymmetric
24 : USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_alloc_block_from_nbl
25 : USE cp_dbcsr_operations, ONLY: dbcsr_allocate_matrix_set,&
26 : dbcsr_deallocate_matrix_set
27 : USE kinds, ONLY: dp
28 : USE particle_types, ONLY: particle_type
29 : USE qs_environment_types, ONLY: get_qs_env,&
30 : qs_environment_type
31 : USE qs_kind_types, ONLY: qs_kind_type
32 : USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
33 : USE qs_operators_ao, ONLY: build_lin_mom_matrix
34 :
35 : !$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num
36 : #include "./base/base_uses.f90"
37 :
38 : IMPLICIT NONE
39 :
40 : PRIVATE
41 :
42 : ! *** Global parameters ***
43 :
44 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_commutators'
45 :
46 : ! *** Public subroutines ***
47 :
48 : PUBLIC :: build_com_hr_matrix
49 :
50 : CONTAINS
51 :
52 : ! **************************************************************************************************
53 : !> \brief Calculation of the [H,r] commutators matrices over Cartesian Gaussian functions.
54 : !> \param qs_env ...
55 : !> \param matrix_hr ...
56 : !> \date 26.07.2016
57 : !> \par History
58 : !> \author JGH
59 : !> \version 1.0
60 : ! **************************************************************************************************
61 2 : SUBROUTINE build_com_hr_matrix(qs_env, matrix_hr)
62 :
63 : TYPE(qs_environment_type), POINTER :: qs_env
64 : TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
65 : POINTER :: matrix_hr
66 :
67 : CHARACTER(len=*), PARAMETER :: routineN = 'build_com_hr_matrix'
68 :
69 : INTEGER :: handle, ir
70 : REAL(KIND=dp) :: eps_ppnl
71 : TYPE(cell_type), POINTER :: cell
72 2 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_nl
73 2 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s
74 : TYPE(dft_control_type), POINTER :: dft_control
75 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
76 2 : POINTER :: sab_orb, sap_ppnl
77 2 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
78 2 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
79 :
80 2 : CALL timeset(routineN, handle)
81 :
82 2 : NULLIFY (cell, matrix_nl, particle_set, sab_orb, sap_ppnl)
83 : CALL get_qs_env(qs_env=qs_env, sab_orb=sab_orb, sap_ppnl=sap_ppnl, cell=cell, &
84 2 : particle_set=particle_set)
85 : !
86 2 : CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, dft_control=dft_control)
87 2 : eps_ppnl = dft_control%qs_control%eps_ppnl
88 : !
89 2 : CALL get_qs_env(qs_env=qs_env, matrix_s_kp=matrix_s)
90 2 : CPASSERT(.NOT. ASSOCIATED(matrix_hr))
91 2 : CALL dbcsr_allocate_matrix_set(matrix_hr, 3)
92 8 : DO ir = 1, 3
93 6 : ALLOCATE (matrix_hr(ir)%matrix)
94 : CALL dbcsr_create(matrix_hr(ir)%matrix, template=matrix_s(1, 1)%matrix, &
95 6 : name="COMMUTATOR", matrix_type=dbcsr_type_antisymmetric)
96 6 : CALL cp_dbcsr_alloc_block_from_nbl(matrix_hr(ir)%matrix, sab_orb)
97 8 : CALL dbcsr_set(matrix_hr(ir)%matrix, 0.0_dp)
98 : END DO
99 :
100 : ! The kinetic-position commutator is the negative of the derivative matrix.
101 2 : CALL build_lin_mom_matrix(qs_env, matrix_hr)
102 8 : DO ir = 1, 3
103 8 : CALL dbcsr_scale(matrix_hr(ir)%matrix, alpha_scalar=-1.0_dp)
104 : END DO
105 2 : IF (ASSOCIATED(sap_ppnl)) THEN
106 0 : CALL dbcsr_allocate_matrix_set(matrix_nl, 3)
107 0 : DO ir = 1, 3
108 0 : ALLOCATE (matrix_nl(ir)%matrix)
109 : CALL dbcsr_create(matrix_nl(ir)%matrix, template=matrix_s(1, 1)%matrix, &
110 0 : name="NONLOCAL COMMUTATOR", matrix_type=dbcsr_type_antisymmetric)
111 0 : CALL cp_dbcsr_alloc_block_from_nbl(matrix_nl(ir)%matrix, sab_orb)
112 0 : CALL dbcsr_set(matrix_nl(ir)%matrix, 0.0_dp)
113 : END DO
114 :
115 : CALL build_com_mom_nl(qs_kind_set, sab_orb, sap_ppnl, eps_ppnl, particle_set, cell, &
116 0 : matrix_rv=matrix_nl)
117 : ! build_com_mom_nl returns [r,Vnl]; [H,r] requires [Vnl,r].
118 0 : DO ir = 1, 3
119 0 : CALL dbcsr_scale(matrix_nl(ir)%matrix, alpha_scalar=-1.0_dp)
120 0 : CALL dbcsr_add(matrix_hr(ir)%matrix, matrix_nl(ir)%matrix, alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
121 : END DO
122 0 : CALL dbcsr_deallocate_matrix_set(matrix_nl)
123 : END IF
124 :
125 2 : CALL timestop(handle)
126 :
127 2 : END SUBROUTINE build_com_hr_matrix
128 :
129 : END MODULE qs_commutators
|