-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathQCModel_Huckel.f
349 lines (251 loc) · 8.88 KB
/
QCModel_Huckel.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#include "GPU.h"
module QCModel_Huckel
use MPI
use omp_lib
use f95_precision
use blas95
use lapack95
use type_m
use constants_m
use Matrix_Math
use MPI_definitions_m , only : ForceCrew , KernelCrew
use parameters_m , only : EnvField_ , Induced_ , driver , verbose , restart
use Overlap_Builder , only : Overlap_Matrix
use Hamiltonians , only : X_ij , even_more_extended_Huckel
use decoherence_m , only : Bcast_Matrices
public :: EigenSystem , S_root_inv
private
interface EigenSystem
module procedure EigenSystem
module procedure EigenSystem_just_erg
end interface
! module variables ...
real*8 , allocatable :: S_root_inv(:,:)
contains
!
!
!
!==================================================
subroutine EigenSystem( system , basis , QM , it )
!==================================================
implicit none
type(structure) , intent(in) :: system
type(STO_basis) , intent(in) :: basis(:)
type(R_eigen) , intent(inout) :: QM
integer , optional , intent(in) :: it
! local variables ...
real*8 , ALLOCATABLE :: Lv(:,:) , Rv(:,:)
real*8 , ALLOCATABLE :: h(:,:) , S_matrix(:,:) , S_root(:,:)
real*8 , ALLOCATABLE :: dumb_S(:,:) , tool(:,:) , S_eigen(:)
integer :: i , N , info
logical , save :: first_call_ = .true.
!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
CALL Overlap_Matrix( system , basis , S_matrix )
! After instantiating Overlap_matrix, processes wait outside ...
If( ForceCrew .OR. KernelCrew ) return
N = size(basis)
If( .NOT. allocated(QM%erg) ) ALLOCATE(QM%erg(N))
Allocate( h(N,N) )
Allocate( dumb_S(N,N) )
! clone S_matrix because SYGVD will destroy it ...
dumb_s = S_matrix
If( EnvField_ .OR. Induced_ ) then
h(:,:) = even_more_extended_Huckel( system , basis , S_matrix , it )
else
h(:,:) = Build_Huckel( basis , S_matrix )
end If
CALL SYGVD( h , dumb_S , QM%erg , 1 , 'V' , 'L' , info )
If ( info /= 0 ) write(*,*) 'info = ',info,' in SYGVD in EigenSystem '
select case ( driver )
case default
!---------------------------------------------------
! ROTATES THE HAMILTONIAN: H --> H*S_inv
!
! RIGHT EIGENVECTOR ALSO CHANGE: |C> --> S.|C>
!
! normalizes the L&R eigenvectors as < L(i) | R(i) > = 1
!---------------------------------------------------
Allocate( Lv(N,N) )
Allocate( Rv(N,N) )
Lv = h
Deallocate( h , dumb_S )
If( .NOT. allocated(QM%L) ) ALLOCATE(QM%L(N,N))
! eigenvectors in the rows of QM%L
QM%L = transpose(Lv)
! Rv = S * Lv ...
CALL symm( S_matrix , Lv , Rv )
if( driver == "slice_CSDM" ) CALL Bcast_Matrices( Rv , QM%L , S_matrix , N )
DEALLOCATE( S_matrix )
If( .NOT. ALLOCATED(QM%R) ) ALLOCATE(QM%R(N,N))
! eigenvectors in the columns of QM%R
QM%R = Rv
Deallocate( Lv , Rv )
case ("slice_FSSH")
!--------------------------------------------------------
! Overlap Matrix Factorization: S^(1/2) ...
dumb_s = S_matrix
Allocate( S_eigen(N) )
CALL SYEVD(dumb_S , S_eigen , 'V' , 'L' , info)
Allocate( tool(N,N) , source = transpose(dumb_S) )
forall( i=1:N ) tool(:,i) = sqrt(S_eigen) * tool(:,i)
allocate( S_root(N,N) )
CALL gemm(dumb_S , tool , S_root , 'N' , 'N')
!now S_root = S^(1/2) Lowdin Orthogonalization matrix ...
!now S_matrix = S ...
DEALLOCATE( S_eigen , dumb_S , tool )
!---------------------------------------------------
!RIGHT EIGENVECTOR ALSO CHANGE: |C> --> S^(1/2).|C>
!
!normalizes the L&R eigenvectors as < L(i) | R(i) > = 1
!---------------------------------------------------
Allocate( Lv(N,N) )
Allocate( Rv(N,N) )
Lv = h
Deallocate( h )
If( .NOT. allocated(QM%L) ) ALLOCATE(QM%L(N,N))
! eigenvectors in the rows of QM%L
! keeping the nonorthogonal representation of %L for future use ...
QM%L = transpose(Lv)
If( first_call_ .AND. (.NOT. restart) ) then
! Rv = S * Lv ...
call symm( S_matrix, Lv, Rv )
call invert( S_root )
first_call_ = .false.
else
! Rv = S^(1/2) * Lv ...
! Lowding representation ...
CALL symm( S_root , Lv , Rv )
end If
If( .NOT. ALLOCATED(QM%R) ) ALLOCATE(QM%R(N,N))
! eigenvectors in the columns of QM%R
QM%R = Rv
Deallocate( Lv , Rv , S_matrix , S_root )
case ("diagnostic")
deallocate(dumb_S)
call Lowdin( h , S_matrix , QM , N )
end select
!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
! save energies of the TOTAL system ...
OPEN(unit=9,file='ancillary.trunk/system-ergs.dat',status='unknown')
do i = 1 , N
write(9,*) i , QM%erg(i)
end do
CLOSE(9)
If( verbose ) Print*, '>> EigenSystem done <<'
end subroutine EigenSystem
!
!
!
!===================================================
function Build_Huckel( basis , S_matrix ) result(h)
!===================================================
implicit none
type(STO_basis) , intent(in) :: basis(:)
real*8 , intent(in) :: S_matrix(:,:)
! local variables ...
integer :: i , j , N
real*8 , allocatable :: h(:,:)
!----------------------------------------------------------
! building the HUCKEL HAMILTONIAN
N = size(basis)
ALLOCATE( h(N,N) , source = D_zero )
do j = 1 , N
do i = j , N
h(i,j) = X_ij( i , j , basis ) * S_matrix(i,j)
end do
end do
end function Build_Huckel
!
!
!
!=======================================================
subroutine EigenSystem_just_erg( system , basis , erg )
!=======================================================
implicit none
type(structure) , intent(in) :: system
type(STO_basis) , intent(in) :: basis(:)
real*8 , intent(out) :: erg( size(basis) )
! local variables ...
real*8 , ALLOCATABLE :: h(:,:) , S_matrix(:,:)
integer :: i , j , N , info
N = size(basis)
CALL Overlap_Matrix(system,basis,S_matrix)
ALLOCATE( h(N,N) )
If( EnvField_ ) then
h(:,:) = even_more_extended_Huckel( system , basis , S_matrix )
else
do j = 1 , N
do i = 1 , j
h(i,j) = X_ij( i , j , basis ) * S_matrix(i,j)
end do
end do
end If
CALL SYGVD(h,S_matrix,erg,1,'N','U',info)
If ( info /= 0 ) write(*,*) 'info = ',info,' in SYGVD in EigenSystem '
DEALLOCATE( h , S_matrix )
end subroutine EigenSystem_just_erg
!
!
!
!===========================
subroutine invert( matrix )
!===========================
implicit none
real*8 , intent(inout) :: matrix(:,:)
!local variables ...
integer :: N
N = size(matrix(:,1))
CALL syInvert( matrix, return_full ) ! <== matrix content is destroyed and matrix_inv is returned
#define matrix_inv matrix
allocate( S_root_inv(N,N) , source = matrix_inv )
#undef matrix_inv
end subroutine invert
!
!
!
!
!==========================================
subroutine Lowdin( h , S_matrix , QM , N )
!==========================================
implicit none
real*8 , allocatable , intent(inout) :: h(:,:)
real*8 , allocatable , intent(inout) :: S_matrix(:,:)
type(R_eigen) , intent(inout) :: QM
integer , intent(in) :: N
! local variables ...
real*8 , ALLOCATABLE :: Lv(:,:) , Rv(:,:)
real*8 , ALLOCATABLE :: dumb_S(:,:), tool(:,:), S_eigen(:)
integer :: i , info
!--------------------------------------------------------
! Overlap Matrix Factorization: S^(1/2) ...
Allocate( dumb_S , source = S_matrix )
Allocate( S_eigen(N) )
CALL SYEVD(dumb_S , S_eigen , 'V' , 'L' , info)
Allocate( tool(N,N) , source = transpose(dumb_S) )
forall( i=1:N ) tool(:,i) = sqrt(S_eigen) * tool(:,i)
CALL gemm(dumb_S , tool , S_matrix , 'N' , 'N')
!now S_matrix = S^(1/2), Lowdin Orthogonalization matrix ...
DEALLOCATE( S_eigen , dumb_S , tool )
!---------------------------------------------------
!RIGHT EIGENVECTOR ALSO CHANGE: |C> --> S^(1/2).|C>
!
!normalizes the L&R eigenvectors as < L(i) | R(i) > = 1
!---------------------------------------------------
Allocate( Lv(N,N) )
Allocate( Rv(N,N) )
Lv = h
! Rv = S^(1/2) * Lv ...
CALL symm( S_matrix , Lv , Rv )
ALLOCATE(QM%R(N,N))
ALLOCATE(QM%L(N,N))
! eigenvectors in the columns of QM%R
QM%R = Rv
! eigenvectors in the rows of QM%L
QM%L = transpose(Rv)
Deallocate( h , Lv , Rv , S_matrix )
end subroutine Lowdin
!
!
!
!
end module QCModel_Huckel