-
Notifications
You must be signed in to change notification settings - Fork 5
/
ga_QCModel.f
1364 lines (987 loc) · 36.9 KB
/
ga_QCModel.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
module GA_QCModel_m
use type_m
use constants_m
use f95_precision
use blas95
use lapack95
use parameters_m , only : Alpha_Tensor , EnvField_ , Induced_
use Semi_Empirical_Parms , only : element => atom
use Allocation_m , only : Allocate_Structures
use Structure_Builder , only : Extended_Cell
use Overlap_Builder , only : Overlap_Matrix
use Hamiltonians , only : X_ij , even_more_extended_Huckel
use Multipole_Routines_m , only : rotationmultipoles , &
multipole_messages , &
multipoles1c , &
multipoles2c
public :: MO_erg, MO_erg_diff, GA_eigen, GA_DP_Analysis, Mulliken, AlphaPolar, Bond_Type, MO_character, Localize, Exclude
public :: eval_CG_cost , Adaptive_GA, i_
private
interface Mulliken
module procedure R_Mulliken
module procedure C_Mulliken
end interface
! module variables ...
Real*8 , allocatable :: DP_matrix_AO(:,:,:)
Real*8 , allocatable :: H0(:,:) , S(:,:) ! <== to be used by AlphaPolar ...
type(structure) :: sys_DPF ! <== to be used by GA_DP_Analysis ...
integer , allocatable :: occupancy(:)
integer :: i_= 0
type(on_the_fly) :: Adaptive_GA
logical :: eval_CG_cost = .false.
logical :: done = .false.
! module parameters ...
real*8 :: big = 1.d2
real*8 :: penalty = 1.d1
contains
!
!
!
!=====================================================================
function MO_erg( GA , MO , ref , weight ) result(cost)
!=====================================================================
implicit none
type(R_eigen) , intent(in) :: GA
integer , intent(in) :: MO
real*8 , intent(in) :: ref
real , optional , intent(in) :: weight
!local variables ...
real :: w
real*8 :: cost , delta_E
delta_E = dabs(GA%erg(MO) - ref)
if( present(weight) ) &
then
w = weight
else
w = 1.0
endif
cost = delta_E * w
i_ = i_ + 1
end function MO_erg
!
!
!
!=====================================================================
function MO_erg_diff( GA , up , down , dE_ref , weight ) result(cost)
!=====================================================================
implicit none
type(R_eigen) , intent(in) :: GA
integer , intent(in) :: up
integer , intent(in) :: down
real*8 , intent(in) :: dE_ref
real , optional , intent(in) :: weight
!local variables ...
real :: w
real*8 :: cost , delta_E
delta_E = GA%erg(up) - GA%erg(down)
if( present(weight) ) &
then
w = weight
else
w = 1.0
endif
cost = (delta_E - dE_ref) * w
i_ = i_ + 1
end function MO_erg_diff
!
!
!
!=====================================================================================================
function Exclude( GA , basis , MO , atom , AO , EHSymbol , residue , reference , from_to , adaptive )
!=====================================================================================================
implicit none
type(R_eigen) , intent(in) :: GA
type(STO_basis) , intent(in) :: basis(:)
integer , intent(in) :: MO
integer , optional , intent(in) :: atom(:)
character(len=*) , optional , intent(in) :: AO
character(len=*) , optional , intent(in) :: EHSymbol
character(len=*) , optional , intent(in) :: residue
real , optional , intent(in) :: reference
type(real_interval), optional , intent(in) :: from_to
logical , optional , intent(in) :: adaptive
! local variables ...
integer :: i , l , m
real*8 :: x , Exclude , population , LinearFill
logical , allocatable :: mask(:) , mask_1(:) , mask_2(:) , mask_3(:) , mask_4(:)
allocate( mask (size(basis)) , source=.false. )
allocate( mask_1(size(basis)) , source=.false. )
allocate( mask_2(size(basis)) , source=.false. )
allocate( mask_3(size(basis)) , source=.false. )
allocate( mask_4(size(basis)) , source=.false. )
!====================================================
IF( .NOT. present(atom) ) then
mask_1 = .true.
else
do i = 1 , size(atom)
where( basis%atom == atom(i) ) mask_1 = .true.
end do
end IF
!====================================================
IF( .NOT. present(residue) ) then
mask_2 = .true.
else
where( basis%residue == residue ) mask_2 = .true.
end IF
!====================================================
IF( .NOT. present(EHSymbol) ) then
mask_3 = .true.
else
where( basis%EHSymbol == EHSymbol ) mask_3 = .true.
end IF
!====================================================
IF( .NOT. present(AO) ) then
mask_4 = .true.
else
select case( AO )
case( 's', 'S' )
l = 0 ; m = 0
case( 'py', 'Py' , 'PY' )
l = 1 ; m = -1
case( 'pz', 'Pz' , 'PZ' )
l = 1 ; m = 0
case( 'px', 'Px' , 'PX' )
l = 1 ; m = +1
case( 'dxy', 'Dxy' , 'DXY' )
l = 2 ; m = -2
case( 'dyz', 'Dyz' , 'DYZ' )
l = 2 ; m = -1
case( 'dz2', 'Dz2' , 'DZ2' )
l = 2 ; m = 0
case( 'dxz', 'Dxz' , 'DXZ' )
l = 2 ; m = +1
case( 'dx2y2', 'Dx2y2' , 'DX2Y2' )
l = 2 ; m = +2
case default
stop " >> error in [Exclude] subroutine check input arguments <<"
end select
where( (basis%l == l) .AND. (basis%m == m) ) mask_4 = .true.
end IF
!====================================================
! the total mask ...
mask = ( mask_1 .AND. mask_2 .AND. mask_3 .AND. mask_4 )
!population = sqrt( sum( GA%L(MO,:) * GA%R(:,MO) , mask ) )
population = sum( GA%L(MO,:) * GA%R(:,MO) , mask )
If( .NOT. present(from_to) ) then
If( present(reference) ) then
x = population - reference
else
! default value is assumed, 0.001 of localization ...
x = population - 1.d-3
end if
ElseIf( adaptive == .true. ) then
LinearFill = (from_to%fim - from_to%inicio) * Adaptive_GA% gen / Adaptive_GA% Ngen + from_to%inicio
x = population - LinearFill
ElseIf( adaptive == .false. ) then
x = population - from_to%fim
EndIf
! (population < reference) ==> no penalty for Exclude function ...
If( eval_CG_cost ) then
Exclude = big * max( D_zero , x) ! <== Conjugate Gradient uses continuous RectifiedLinearUnit (ReLU)
else
Exclude = merge( D_zero , penalty , x < D_zero ) ! <== Genetic Algorithm uses step function
EndIf
deallocate( mask )
i_ = i_ + 1
end function exclude
!
!
!
!
!======================================================================================================
function Localize( GA , basis , MO , atom , AO , EHSymbol , residue , reference , from_to , adaptive )
!======================================================================================================
implicit none
type(R_eigen) , intent(in) :: GA
type(STO_basis) , intent(in) :: basis(:)
integer , intent(in) :: MO
integer , optional , intent(in) :: atom(:)
character(len=*) , optional , intent(in) :: AO
character(len=*) , optional , intent(in) :: EHSymbol
character(len=*) , optional , intent(in) :: residue
real , optional , intent(in) :: reference
type(real_interval), optional , intent(in) :: from_to
logical , optional , intent(in) :: adaptive
! local variables ...
integer :: i , l , m
real*8 :: x , Localize , population , LinearFill
logical , allocatable :: mask(:) , mask_1(:) , mask_2(:) , mask_3(:) , mask_4(:)
allocate( mask (size(basis)) , source=.false. )
allocate( mask_1(size(basis)) , source=.false. )
allocate( mask_2(size(basis)) , source=.false. )
allocate( mask_3(size(basis)) , source=.false. )
allocate( mask_4(size(basis)) , source=.false. )
!====================================================
IF( .NOT. present(atom) ) then
mask_1 = .true.
else
do i = 1 , size(atom)
where( basis%atom == atom(i) ) mask_1 = .true.
end do
end IF
!====================================================
IF( .NOT. present(residue) ) then
mask_2 = .true.
else
where( basis%residue == residue ) mask_2 = .true.
end IF
!====================================================
IF( .NOT. present(EHSymbol) ) then
mask_3 = .true.
else
where( basis%EHSymbol == EHSymbol ) mask_3 = .true.
end IF
!====================================================
IF( .NOT. present(AO) ) then
mask_4 = .true.
else
select case( AO )
case( 's', 'S' )
l = 0 ; m = 0
case( 'py', 'Py' , 'PY' )
l = 1 ; m = -1
case( 'pz', 'Pz' , 'PZ' )
l = 1 ; m = 0
case( 'px', 'Px' , 'PX' )
l = 1 ; m = +1
case( 'dxy', 'Dxy' , 'DXY' )
l = 2 ; m = -2
case( 'dyz', 'Dyz' , 'DYZ' )
l = 2 ; m = -1
case( 'dz2', 'Dz2' , 'DZ2' )
l = 2 ; m = 0
case( 'dxz', 'Dxz' , 'DXZ' )
l = 2 ; m = +1
case( 'dx2y2', 'Dx2y2' , 'DX2Y2' )
l = 2 ; m = +2
case default
stop " >> error in [Exclude] subroutine check input arguments <<"
end select
where( (basis%l == l) .AND. (basis%m == m) ) mask_4 = .true.
end IF
!====================================================
! the total mask ...
mask = ( mask_1 .AND. mask_2 .AND. mask_3 .AND. mask_4 )
!population = sqrt( sum( GA%L(MO,:) * GA%R(:,MO) , mask ) )
population = sum( GA%L(MO,:) * GA%R(:,MO) , mask )
If( .NOT. present(from_to) ) then
If( present(reference) ) then
x = reference - population
else
! default value is assumed, 85% of localization ...
x = 0.85 - population
end if
ElseIf( adaptive == .true. ) then
LinearFill = (from_to%fim - from_to%inicio) * Adaptive_GA% gen / Adaptive_GA% Ngen + from_to%inicio
x = LinearFill - population
ElseIf( adaptive == .false. ) then
x = from_to%fim - population
EndIf
! (population > reference) ==> no penalty for localize function ...
If( eval_CG_cost ) then
Localize = big * max( D_zero , x) ! <== Conjugate Gradient uses continuous RectifiedLinearUnit (ReLU)
else
Localize = merge( D_zero , penalty , x < D_zero ) ! <== Genetic Algorithm uses step function
EndIf
deallocate( mask )
i_ = i_ + 1
end function Localize
!
!
!
!======================================================
function MO_character( GA , basis , MO , AO , y_or_n )
!======================================================
implicit none
type(R_eigen) , intent(in) :: GA
type(STO_basis) , intent(in) :: basis(:)
integer , intent(in) :: MO
character(len=*), optional , intent(in) :: AO
character(len=1), optional , intent(in) :: y_or_n
! local variables ...
integer :: l , m
real*8 :: MO_character , population
logical , allocatable :: mask(:)
allocate( mask (size(basis)) , source=.false. )
select case( AO )
case( 's', 'S' )
l = 0 ; m = 0
case( 'py', 'Py' , 'PY' )
l = 1 ; m = -1
case( 'pz', 'Pz' , 'PZ' )
l = 1 ; m = 0
case( 'px', 'Px' , 'PX' )
l = 1 ; m = +1
case( 'dxy', 'Dxy' , 'DXY' )
l = 2 ; m = -2
case( 'dyz', 'Dyz' , 'DYZ' )
l = 2 ; m = -1
case( 'dz2', 'Dz2' , 'DZ2' )
l = 2 ; m = 0
case( 'dxz', 'Dxz' , 'DXZ' )
l = 2 ; m = +1
case( 'dx2y2', 'Dx2y2' , 'DX2Y2' )
l = 2 ; m = +2
case default
stop " >> error in [MO_character] subroutine check input arguments <<"
end select
where( (basis%l == l) .AND. (basis%m == m) ) mask = .true.
population = sqrt( sum( GA%L(MO,:) * GA%R(:,MO) , mask ) )
if( .not. present(y_or_n) ) then
MO_character = merge( D_zero , penalty , population > HALF )
elseif( y_or_n == "y" ) then
MO_character = merge( D_zero , penalty , population > HALF )
elseif( y_or_n == "n" ) then
MO_character = merge( D_zero , penalty , population < HALF )
endif
deallocate( mask )
i_ = i_ + 1
end function MO_character
!
!
!
!=============================================================================
function Bond_Type( system , GA , MO , atom1 , AO1 , atom2 , AO2 , instance )
!=============================================================================
implicit none
type(structure) , intent(in) :: system
type(R_eigen) , intent(in) :: GA
integer , intent(in) :: MO
integer , intent(in) :: atom1
character(*) , intent(in) :: AO1
integer , intent(in) :: atom2
character(*) , intent(in) :: AO2
character(len=1) , intent(in) :: instance
real*8 :: bond_type
! local variables ...
integer :: indx1 , indx2
real*8 :: bond_signal
select case( AO1 )
case( 's', 'S' )
indx1 = system% BasisPointer(atom1) + 1
case( 'py', 'Py' , 'PY' )
indx1 = system% BasisPointer(atom1) + 2
case( 'pz', 'Pz' , 'PZ' )
indx1 = system% BasisPointer(atom1) + 3
case( 'px', 'Px' , 'PX' )
indx1 = system% BasisPointer(atom1) + 4
case( 'dxy', 'Dxy' , 'DXY' )
indx1 = system% BasisPointer(atom1) + 5
case( 'dyz', 'Dyz' , 'DYZ' )
indx1 = system% BasisPointer(atom1) + 6
case( 'dz2', 'Dz2' , 'DZ2' )
indx1 = system% BasisPointer(atom1) + 7
case( 'dxz', 'Dxz' , 'DXZ' )
indx1 = system% BasisPointer(atom1) + 8
case( 'dx2y2', 'Dx2y2' , 'DX2Y2' )
indx1 = system% BasisPointer(atom1) + 9
case default
stop " >> error in [bond] subroutine check input arguments <<"
end select
select case( AO2 )
case( 's', 'S' )
indx2 = system% BasisPointer(atom2) + 1
case( 'py', 'Py' , 'PY' )
indx2 = system% BasisPointer(atom2) + 2
case( 'pz', 'Pz' , 'PZ' )
indx2 = system% BasisPointer(atom2) + 3
case( 'px', 'Px' , 'PX' )
indx2 = system% BasisPointer(atom2) + 4
case( 'dxy', 'Dxy' , 'DXY' )
indx2 = system% BasisPointer(atom2) + 5
case( 'dyz', 'Dyz' , 'DYZ' )
indx2 = system% BasisPointer(atom2) + 6
case( 'dz2', 'Dz2' , 'DZ2' )
indx2 = system% BasisPointer(atom2) + 7
case( 'dxz', 'Dxz' , 'DXZ' )
indx2 = system% BasisPointer(atom2) + 8
case( 'dx2y2', 'Dx2y2' , 'DX2Y2' )
indx2 = system% BasisPointer(atom2) + 9
case default
stop " >> error in [bond] subroutine check input arguments <<"
end select
! pre-processing ...
bond_type = D_zero
If( dabs(GA%R(indx1,MO)) < mid_prec .OR. dabs(GA%R(indx2,MO)) < mid_prec ) then
i_ = i_ + 1
return
end If
! actual calculations start here ...
bond_signal = sign( 1.d0 , GA%R(indx1,MO) * GA%R(indx2,MO) )
select case ( instance )
case( '+' ) ! <== Bonding ...
bond_type = merge( D_zero , penalty , bond_signal > D_zero )
case( '-' ) ! <== Anti-Bonding ...
bond_type = merge( D_zero , penalty , bond_signal < D_zero )
case default
stop " >> error in [Bond_Type] subroutine check input arguments <<"
end select
i_ = i_ + 1
end function
!
!
!
!=========================================================================================
function R_Mulliken( GA , basis , MO , atom , AO , EHSymbol , residue , weight , Symbol )
!=========================================================================================
implicit none
type(R_eigen) , intent(in) :: GA
type(STO_basis) , intent(in) :: basis(:)
integer , intent(in) :: MO
integer , optional , intent(in) :: atom(:)
character(len=*), optional , intent(in) :: AO
character(len=*), optional , intent(in) :: EHSymbol
character(len=*), optional , intent(in) :: residue
real , optional , intent(in) :: weight
character(len=*), optional , intent(in) :: Symbol
! local variables ...
integer :: i , l , m
real*8 :: R_Mulliken
logical , allocatable :: mask(:) , mask_1(:) , mask_2(:) , mask_3(:) , mask_4(:) , mask_5(:)
allocate( mask (size(basis)) , source=.false. )
allocate( mask_1(size(basis)) , source=.false. )
allocate( mask_2(size(basis)) , source=.false. )
allocate( mask_3(size(basis)) , source=.false. )
allocate( mask_4(size(basis)) , source=.false. )
allocate( mask_5(size(basis)) , source=.false. )
!====================================================
IF( .NOT. present(atom) ) then
mask_1 = .true.
else
do i = 1 , size(atom)
where( basis%atom == atom(i) ) mask_1 = .true.
end do
end IF
!====================================================
IF( .NOT. present(AO) ) then
mask_2 = .true.
else
select case( AO )
case( 's', 'S' )
l = 0 ; m = 0
case( 'py', 'Py' , 'PY' )
l = 1 ; m = -1
case( 'pz', 'Pz' , 'PZ' )
l = 1 ; m = 0
case( 'px', 'Px' , 'PX' )
l = 1 ; m = +1
case( 'dxy', 'Dxy' , 'DXY' )
l = 2 ; m = -2
case( 'dyz', 'Dyz' , 'DYZ' )
l = 2 ; m = -1
case( 'dz2', 'Dz2' , 'DZ2' )
l = 2 ; m = 0
case( 'dxz', 'Dxz' , 'DXZ' )
l = 2 ; m = +1
case( 'dx2y2', 'Dx2y2' , 'DX2Y2' )
l = 2 ; m = +2
case default
stop " >> error in [Mulliken] subroutine check input arguments <<"
end select
where( (basis%l == l) .AND. (basis%m == m) ) mask_2 = .true.
end IF
!====================================================
IF( .NOT. present(EHSymbol) ) then
mask_3 = .true.
else
where( basis%EHSymbol == EHSymbol ) mask_3 = .true.
end IF
!====================================================
IF( .NOT. present(residue) ) then
mask_4 = .true.
else
where( basis%residue == residue ) mask_4 = .true.
end IF
!====================================================
IF( .NOT. present(Symbol) ) then
mask_5 = .true.
else
where( basis%Symbol == Symbol ) mask_5 = .true.
end IF
!====================================================
! the total mask ...
mask = ( mask_1 .AND. mask_2 .AND. mask_3 .AND. mask_4 .AND. mask_5 )
! perform the population analysis ...
R_Mulliken = real( sum( GA%L(MO,:) * GA%R(:,MO) , mask ) )
If( .not. present(weight)) then
i_ = i_ + 1 ! <= updat me
else If( weight > 0 ) then
! apply weight ...
R_Mulliken = R_Mulliken * weight
i_ = i_ + 1 ! <= also updat me
end If ! <= otherwise, dont update me and dont apply weight
deallocate( mask , mask_1 , mask_2 , mask_3 , mask_4 , mask_5)
end function R_Mulliken
!
!
!
!===========================================================================
function C_Mulliken( GA , basis , MO , atom , AO_ang , EHSymbol , residue )
!===========================================================================
implicit none
type(C_eigen) , intent(in) :: GA
type(STO_basis) , intent(in) :: basis(:)
integer , intent(in) :: MO
integer , optional , intent(in) :: atom
integer , optional , intent(in) :: AO_ang
character(len=*), optional , intent(in) :: EHSymbol
character(len=*), optional , intent(in) :: residue
! local variables ...
complex*16 :: C_Mulliken
logical , allocatable :: mask(:) , mask_1(:) , mask_2(:) , mask_3(:) , mask_4(:)
allocate( mask (size(basis)) , source=.false. )
allocate( mask_1(size(basis)) , source=.false. )
allocate( mask_2(size(basis)) , source=.false. )
allocate( mask_3(size(basis)) , source=.false. )
allocate( mask_4(size(basis)) , source=.false. )
!====================================================
IF( .NOT. present(atom) ) then
mask_1 = .true.
else
where( basis%atom == atom ) mask_1 = .true.
end IF
!====================================================
IF( .NOT. present(AO_ang) ) then
mask_2 = .true.
else
where( basis%l == AO_ang ) mask_2 = .true.
end IF
!====================================================
IF( .NOT. present(EHSymbol) ) then
mask_3 = .true.
else
where( basis%EHSymbol == EHSymbol ) mask_3 = .true.
end IF
!====================================================
IF( .NOT. present(residue) ) then
mask_4 = .true.
else
where( basis%residue == residue ) mask_4 = .true.
end IF
!====================================================
mask = ( mask_1 .AND. mask_2 .AND. mask_3 .AND. mask_4)
! perform the population analysis ...
C_Mulliken = sum( GA%L(MO,:) * GA%R(:,MO) , mask )
deallocate( mask , mask_1 , mask_2 , mask_3 , mask_4 )
i_ = i_ + 1
end function C_Mulliken
!
!
!
!===================================================
subroutine GA_eigen( system , basis , FMO , flag )
!===================================================
implicit none
type(structure) , intent(in) :: system
type(STO_basis) , intent(in) :: basis(:)
type(R_eigen) , intent(out) :: FMO
integer , optional , intent(in) :: flag
! local variables ...
integer :: i , N , info
real*8 , ALLOCATABLE :: Lv(:,:) , Rv(:,:) , s_FMO(:,:) , h_FMO(:,:) , dumb_S(:,:)
real*8 , ALLOCATABLE :: S_eigen(:) , tool(:,:)
! local parameters ...
real*8 , parameter :: one = 1.d0 , zero = 0.d0
N = size(basis)
ALLOCATE( s_FMO (size(basis),size(basis)) )
ALLOCATE( h_FMO (size(basis),size(basis)) )
ALLOCATE( dumb_S (size(basis),size(basis)) )
ALLOCATE( FMO%erg (size(basis) ) )
!-----------------------------------------------------------------------
CALL Overlap_Matrix( system, basis, S_FMO, "GA-CG" )
! clone S_matrix because SYGVD will destroy it ...
dumb_S = S_FMO
If( EnvField_ .OR. Induced_ ) then
h_FMO = even_more_extended_Huckel( system , basis , S_FMO )
else
h_FMO = Build_Huckel( basis , S_FMO )
end If
!-------- solve generalized eH eigenvalue problem H*Q = E*S*Q
CALL SYGVD( h_FMO , dumb_S , FMO%erg , 1 , 'V' , 'U' , info )
If ( present(flag) .AND. info/=0 ) write(*,*) 'info = ',info,' in GA_Eigen '
If ( present(flag) ) &
then
If ( flag==2 ) &
then
OPEN(unit=9,file='ancillary.trunk/system-GA-ergs.dat',status='unknown')
do i = 1 , N
write(9,*) i , FMO%erg(i)
end do
CLOSE(9)
end if
end if
!--------------------------------------------------------
! Overlap Matrix Factorization: S^(1/2) ...
Allocate( S_eigen(N) )
dumb_s = S_FMO
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)
!now S_FMO = S^(1/2) Lowdin Orthogonalization matrix ...
CALL gemm(dumb_S , tool , S_FMO , 'N' , 'N')
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_FMO
Deallocate( h_FMO )
! Rv = S^(1/2) * Lv ...
CALL symm( S_FMO , Lv , Rv )
ALLOCATE(FMO%R(N,N))
! eigenvectors in the columns of QM%R
FMO%R = Rv
ALLOCATE(FMO%L(N,N))
! eigenvectors in the rows of QM%L
FMO%L = transpose(FMO%R)
Deallocate( Lv , Rv , S_FMO )
end subroutine GA_eigen
!
!
!
!===================================================
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 = 1 , j
h(i,j) = X_ij( i , j , basis ) * S_matrix(i,j)
h(j,i) = h(i,j)
end do
end do
end function Build_Huckel
!
!
!
!======================================================
subroutine GA_DP_Analysis( system , basis , L_vec , R_vec , Total_DP )
!======================================================
implicit none
type(structure) , intent(in) :: system
type(STO_basis) , intent(in) :: basis(:)
real*8 , intent(in) :: L_vec(:,:) , R_vec(:,:)
real*8 , intent(out) :: Total_DP(3)
!local variables ...
type(STO_basis) , allocatable :: basis_DPF(:)
type(R_eigen) :: DPF
CALL preprocess( system , basis , basis_DPF)
CALL GA_eigen( sys_DPF , basis_DPF , DPF )
CALL Build_Dipole_Matrix( sys_DPF , basis_DPF )
CALL Dipole_Moment( sys_DPF , basis_DPF , DPF%L , DPF%R , Total_DP )
end subroutine GA_DP_Analysis
!
!
!
!==================================================
subroutine AlphaPolar( system , basis , Alpha_ii )
!==================================================
implicit none
type(structure) , intent(inout) :: system
type(STO_basis) , intent(in) :: basis(:)
real*8 , intent(out) :: Alpha_ii(3)
! local variables ...
integer :: mm , i , j , xyz
real*8 , ALLOCATABLE :: H(:,:) , DP_AO(:,:)
type(R_eigen) :: UNI
type(R3_vector) :: Induced(-2:2)
! local parameters ...
real*8 , parameter :: conversion_factor = 20.23100999d0 ! <== see AlphaTensor.f
real*8 , parameter :: base_Field = 5.0d-4
mm = size(basis)
! build the field independent H and S matrices ...
CALL Build_H0_and_S( system , basis )
ALLOCATE( H(mm,mm) , source=D_zero )
! field dependent hamiltonian and Induced DP moments (DP is calculated in Debyes) ...
ALLOCATE( DP_AO(mm,mm) , source=D_zero )
! for each molecular axis F_xyz ...
do xyz = 1 , 3
select case ( xyz )
case (1)
forall( i=1:mm , j=1:mm ) DP_AO(i,j) = DP_matrix_AO(i,j,xyz) + basis(i)%x*S(i,j)
case (2)
forall( i=1:mm , j=1:mm ) DP_AO(i,j) = DP_matrix_AO(i,j,xyz) + basis(i)%y*S(i,j)
case (3)
forall( i=1:mm , j=1:mm ) DP_AO(i,j) = DP_matrix_AO(i,j,xyz) + basis(i)%z*S(i,j)