-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctionals.f90
2584 lines (2121 loc) · 74.8 KB
/
functionals.f90
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
!----------------------------------------------------------
! THIS IS A FILE THAT THE FUNCTIONALS ARE DEFINED
! Entropy functionals are also included at the end
! created by N. N. Lathiotakis and I.Theophilou
!----------------------------------------------------------
subroutine calc_occ_factors(occ, fac_h, fac_c, fac_e)
! Just a wrapper calling the appropriate functional routine
!..Global
use global; use functional_m
implicit none
!..Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
select case (functional)
case("RHF")
call RHF(occ, fac_h, fac_c, fac_e) ! Restricted Hartree-Fock
case("RHA")
call RHA(occ, fac_h, fac_c, fac_e) ! Restricted Hartree-Fock
case("GUM")
call GUM(occ, fac_h, fac_c, fac_e) ! Goedecker Umrigar
case("BB0")
call BB0(occ, fac_h, fac_c, fac_e) ! Mueller, Buijse Baerends
case("BB1")
call BB1(occ, fac_h, fac_c, fac_e) ! BBC1
case("BB2")
call BB2(occ, fac_h, fac_c, fac_e) ! BBC2
case("BB3")
call BB3(occ, fac_h, fac_c, fac_e) ! BBC3
case("BBp")
call BB1(occ, fac_h, fac_c, fac_e) ! BBC++
case("CHF")
call CHF(occ, fac_h, fac_c, fac_e) ! Corected Hartree Fock (Csanyi-Arias)
case("CGA")
call CGA(occ, fac_h, fac_c, fac_e) ! Csanyi-Goedecker-Arias
case("POW")
call POW(occ, fac_h, fac_c, fac_e) ! Power functional
case("PNO")
call PNO(occ, fac_h, fac_c, fac_e) ! Piris NO functional
case("PNP")
call PNP(occ, fac_h, fac_c, fac_e) ! Piris NO functional with pinning
case("MPF")
call MPF(occ, fac_h, fac_c, fac_e) ! Mueller general-p functional
case("MLP")
call MLP(occ, fac_h, fac_c, fac_e) ! Marques Lathiotakis Pade
case("SA1")
call SA1(occ, fac_h, fac_c, fac_e) ! New Sangeeta idea
case("AC3")
call AC3(occ, fac_h, fac_c, fac_e) ! JCP129, 164105 (2009)
case("TST")
call TST(occ, fac_h, fac_c, fac_e)
case("OSM")
call OSM(occ, fac_h, fac_c, fac_e)
case("DFT") ! For DFT calculation
call DFT(occ, fac_h, fac_c, fac_e)
case("SLR") ! Slater version of Power functional
call DFT(occ, fac_h, fac_c, fac_e)
case("HDR")
call HDR(occ, fac_h, fac_c, fac_e)
case("DBF")
call DBF(occ, fac_h, fac_c, fac_e)
case("NEK")
call NEK(occ, fac_h, fac_c, fac_e)
case("LSH")
call LSH(occ, fac_h, fac_c, fac_e)
case("PN5") ! PNOF-5
call PN5(occ, fac_h, fac_c, fac_e)
case("BBN")
call BBN(occ, fac_h, fac_c, fac_e) ! Mueller modified
case("LSM")
call LSM(occ, fac_h, fac_c, fac_e) !Modified LSH
case("LST")
call LST(occ, fac_h, fac_c, fac_e) !Modified LSH for triplet
case("GPC")
call GPC(occ, fac_h, fac_c, fac_e) !Functional for three electrons based on the expansion of a 3 determinental wavefunction
case default
print*,'Functional:',functional
stop 'calc_occ_factors: not implemented functional'
end select
end subroutine calc_occ_factors
!----------------------------------------------------------------
subroutine calc_der_occ_factors(ia, ispin, occ, fac_c_d, fac_e_d)
! Just a wrapper calling the appropriate functional routine
!..Global
use global; use functional_m
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb)
real(dp), intent(out) :: fac_e_d(lnnatorb)
select case (functional)
case ("RHF") !Restricted Hartree Fock
call RHF_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("RHA") !Restricted Hartree Fock
call RHA_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("GUM") !Goedecker Umrigar
call GUM_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("BB0") !Mueller functional
call BB0_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("BB1") !BBC1
call BB1_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("BB2") !BBC2
call BB2_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("BB3") !BBC3
call BB3_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("BBp")
call BB1_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("CHF")
call CHF_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("CGA")
call CGA_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("POW")
call POW_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("PNO")
call PNO_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("PNP")
call PNP_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("MPF")
call MPF_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("MLP")
call MLP_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("SA1")
call SA1_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("AC3")
call AC3_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("TST")
call BB0_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("OSM")
call OSM_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("DFT")
call DFT_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("SLR")
call DFT_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("HDR")
call HDR_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("DBF")
call DBF_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("NEK")
call NEK_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("LSH")
call LSH_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("PN5")
call PN5_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("BBN") !Mueller modified
call BBN_d(ia, ispin, occ, fac_c_d, fac_e_d)
case ("LSM")
call LSM_d(ia, ispin, occ, fac_c_d, fac_e_d)!LSH modified
case ("LST")
call LST_d(ia, ispin, occ, fac_c_d, fac_e_d)!LSH modified for triplets
case ("GPC")
call GPC_d(ia, ispin, occ, fac_c_d, fac_e_d)
case default
stop 'calc_der_occ_factors: not implemented functional'
end select
end subroutine calc_der_occ_factors
!-------------------------------------------------------------------
! RESTRICTED (OPEN-SHELL) HARTREE FOCK (RHF)
subroutine RHF(occ, fac_h, fac_c, fac_e)
use global
implicit none
!.....Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!.....Local variables
integer :: ia, ib
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
do ib=1,ia
fac_c(ia,ib) = (occ(ia,1)+occ(ia,2))*(occ(ib,1)+occ(ib,2))
fac_e(ia,ib) = -occ(ia,1)*occ(ib,1)-occ(ia,2)*occ(ib,2)
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
fac_e(ia,ib) = 0.5_dp*fac_e(ia,ib)
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine RHF
!---------------AND THE DERIVATIVE----------------------------
subroutine RHF_d(ia, ispin, occ, fac_c_d, fac_e_d)
use global
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
ispin_op=2
if(ispin==2) ispin_op=1
ocia = occ(ia, ispin)
do ib = 1, nnatorb
ocib= occ(ib,ispin)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op + ocib
fac_e_d(ib) = -ocib
enddo
end subroutine RHF_d
!-------------------------------------------------------------------
! RESTRICTED (OPEN-SHELL) HARTREE (NO FOCK!!!!!)
subroutine RHA(occ, fac_h, fac_c, fac_e)
use global
implicit none
!.....Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!.....Local variables
integer :: ia, ib
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
do ib=1,ia
fac_c(ia,ib) = (occ(ia,1)+occ(ia,2))*(occ(ib,1)+occ(ib,2))
fac_e(ia,ib) = 0._dp
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
fac_e(ia,ib) = 0._dp
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine RHA
!---------------AND THE DERIVATIVE----------------------------
subroutine RHA_d(ia, ispin, occ, fac_c_d, fac_e_d)
use global
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
ispin_op=2
if(ispin==2) ispin_op=1
ocia = occ(ia, ispin)
do ib = 1, nnatorb
ocib= occ(ib,ispin)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op + ocib
fac_e_d(ib) = 0._dp
enddo
end subroutine RHA_d
!--------------------------------------------------------------------
! THE MUELLER FUNCTIONAL (or Buisze-Baerents) Phys Lett. 105A, 446 (1984),
! Mol Phys 100, 401 (2002)
subroutine BB0(occ, fac_h, fac_c, fac_e)!
use global
implicit none
!..Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!..Local variables
integer :: ia, ib
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
do ib=1,ia
fac_c(ia,ib) = (occ(ia,1)+occ(ia,2))*(occ(ib,1)+occ(ib,2))
fac_e(ia,ib) = -sqrt(occ(ia,1)*occ(ib,1)) &
-sqrt(occ(ia,2)*occ(ib,2))
!........The double counting 1/2 factor
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
fac_e(ia,ib) = 0.5_dp*fac_e(ia,ib)
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine BB0
!---------------AND THE DERIVATIVE----------------------------
subroutine BB0_d(ia, ispin, occ, fac_c_d, fac_e_d)
use global
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
ispin_op=2
if(ispin==2) ispin_op=1
ocia = occ(ia, ispin)
do ib = 1, nnatorb
ocib= occ(ib,ispin)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op + ocib
fac_e_d(ib) = - 0.5_dp*sqrt(ocib)/sqrt(ocia)
enddo
end subroutine BB0_d
!--------------------------------------------------------------
! The Goedecker Umrigar functional (PRL81 866, 1998)
! see also PRA 72, 030501(R) (2005) for open shells
subroutine GUM(occ, fac_h, fac_c, fac_e)
use global
implicit none
!..Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!..Local
integer :: ia,ib
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
do ib=1,ia
fac_c(ia,ib) = occ(ia,1)*occ(ib,2) &
+ occ(ia,2)*occ(ib,1)
fac_e(ia,ib) = 0.0_dp
if(ia/=ib) then
fac_c(ia,ib) = fac_c(ia,ib) + occ(ia,1)*occ(ib,1) &
+ occ(ia,2)*occ(ib,2)
fac_e(ia,ib) = - sqrt(occ(ia,1)*occ(ib,1)) &
- sqrt(occ(ia,2)*occ(ib,2))
fac_e(ia,ib) = 0.5_dp*fac_e(ia,ib)
endif
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
! if(abs(fac_c(ia,ib))<1d-8) fac_c(ia,ib)=0.d0
! if(abs(fac_e(ia,ib))<1d-8) fac_e(ia,ib)=0.d0
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine GUM
!---------------AND THE DERIVATIVE----------------------------
subroutine GUM_d(ia, ispin, occ, fac_c_d, fac_e_d)
use global
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
ispin_op=2
if(ispin==2) ispin_op=1
ocia = occ(ia, ispin)
do ib = 1, nnatorb
ocib= occ(ib,ispin)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op
fac_e_d(ib) = 0._dp
if(ib/=ia) then
fac_c_d(ib) = fac_c_d(ib) + ocib
fac_e_d(ib) = - 0.5_dp*sqrt(ocib)/sqrt(ocia)
endif
enddo
end subroutine GUM_d
!-------------------------------------------------------------
! BBC1, Journal of Chem Phys, 122, 204102-1 (2005).
subroutine BB1(occ, fac_h, fac_c, fac_e)
use global; use functional_m
implicit none
!..Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!..Local variables
integer :: ia, ib
real(dp) :: exch1, exch2
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
do ib=1,ia
fac_c(ia,ib) = (occ(ia,1)+occ(ia,2))*(occ(ib,1)+occ(ib,2))
exch1 = -sqrt(max(occ(ia,1)*occ(ib,1),small))
exch2 = -sqrt(max(occ(ia,2)*occ(ib,2),small))
!........BBC1 correction (strength: PRB 75, 195120, (2007))
if(ia/=ib) then
if(ia>ibond(1).and.ib>ibond(1)) exch1 = -strength*exch1
if(ia>ibond(2).and.ib>ibond(2)) exch2 = -strength*exch2
endif
!........The double counting 1/2 factor
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
fac_e(ia,ib) = 0.5_dp*(exch1+exch2)
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine BB1
!---------------AND THE DERIVATIVE----------------------------
subroutine BB1_d(ia, ispin, occ, fac_c_d, fac_e_d)
use global; use functional_m
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
ispin_op=2
if(ispin==2) ispin_op=1
ocia = max(occ(ia, ispin),small)
do ib = 1, nnatorb
ocib= max(occ(ib,ispin),small)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op + ocib
fac_e_d(ib) = - 0.5_dp*sqrt(ocib)/sqrt(ocia)
!.....BBC1 correction
if(ia/=ib) then
if(ia>ibond(ispin).and.ib>ibond(ispin)) fac_e_d(ib)=-strength*fac_e_d(ib)
endif
enddo
end subroutine BB1_d
!--------------------------------------------------------------------
! BBC2, Journal of Chem Phys, 122, 204102-1 (2005).
subroutine BB2(occ, fac_h, fac_c, fac_e)
use global
implicit none
!..Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!..Local variables
integer :: ia, ib
real(dp) :: exch1, exch2
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
do ib=1,ia
fac_c(ia,ib) = (occ(ia,1)+occ(ia,2))*(occ(ib,1)+occ(ib,2))
exch1 = -sqrt(occ(ia,1)*occ(ib,1))
exch2 = -sqrt(occ(ia,2)*occ(ib,2))
if(ia/=ib) then !Here go the BBC1, BBC2 corrections
if(ia>ibond(1).and.ib>ibond(1)) exch1 = -exch1
if(ia>ibond(2).and.ib>ibond(2)) exch2 = -exch2
if(ia<=ibond(1).and.ib<=ibond(1)) exch1 = -occ(ia,1)*occ(ib,1)
if(ia<=ibond(2).and.ib<=ibond(2)) exch2 = -occ(ia,2)*occ(ib,2)
endif
!........And the factor of a half for the double counting
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
fac_e(ia,ib) = 0.5_dp*(exch1+exch2)
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine BB2
!---------------AND THE DERIVATIVE----------------------------
subroutine BB2_d(ia, ispin, occ, fac_c_d, fac_e_d)
use global
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
ispin_op=2
if(ispin==2) ispin_op=1
ocia = occ(ia, ispin)
do ib = 1, nnatorb
ocib= occ(ib,ispin)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op + ocib
fac_e_d(ib) = - 0.5_dp*sqrt(ocib)/sqrt(ocia)
if(ia/=ib) then !BBC1, BBC2 corrections
if(ia>ibond(ispin).and.ib>ibond(ispin)) fac_e_d(ib)=-fac_e_d(ib)
if(ia<=ibond(ispin).and.ib<=ibond(ispin)) fac_e_d(ib)=-ocib
endif
enddo
end subroutine BB2_d
!-------------------------------------------------------------
! BBC3_old (Journal of Chem Phys, 122, 204102-1 (2005).
! BBC3_old uses one bonding and one anti-bonding orbital
! An improved version respecting degeneracies of bonding
! and antibonding is given below
subroutine BB3_old(occ, fac_h, fac_c, fac_e) !spin dependent
use global
use functional_m
implicit none
!..Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!..Local variables
integer :: ia, ib
integer :: ilim1, ilim2
real(dp) :: exch1, exch2
ilim1=xnele(1); if(xnele(1)-ilim1 > 5*small) ilim1=ilim1+1
ilim2=xnele(2); if(xnele(2)-ilim2 > 5*small) ilim2=ilim2+1
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
do ib=1,ia !NOTE ia >= ib
!........The non SI part added for all:
fac_c(ia,ib) = occ(ia,1)*occ(ib,2) &
+ occ(ia,2)*occ(ib,1)
exch1=0.0_dp
exch2=0.0_dp
!........Add SI terms for bonding antibonding (spin resolved):
if(((ia==ianti(1)).or.(ia==ibond(1))).and.(ib==ia)) then
fac_c(ia,ib)= fac_c(ia,ib) + occ(ia,1)*occ(ib,1)
exch1 = -sqrt(occ(ia,1)*occ(ib,1))
endif
if(((ia==ianti(2)).or.(ia==ibond(2))).and.(ib==ia)) then
fac_c(ia,ib)= fac_c(ia,ib) + occ(ia,2)*occ(ib,2)
exch2 = -sqrt(occ(ia,2)*occ(ib,2))
endif
if(ia/=ib) then
fac_c(ia,ib)= fac_c(ia,ib) + occ(ia,1)*occ(ib,1) &
+ occ(ia,2)*occ(ib,2)
exch1 = -sqrt(occ(ia,1)*occ(ib,1))
exch2 = -sqrt(occ(ia,2)*occ(ib,2))
!...........BBC1 correction:
if(ia>ilim1.and.ib>ilim1) exch1 = -exch1
if(ia>ilim2.and.ib>ilim2) exch2 = -exch2
!...........BBC2 correction:
if(ia<=ilim1.and.ib<=ilim1) exch1 = -occ(ia,1)*occ(ib,1)
if(ia<=ilim2.and.ib<=ilim2) exch2 = -occ(ia,2)*occ(ib,2)
!...........Include antibonding in BBC2 correction
if(ia == ianti(1) .and. ib <= ilim1) then
if(ib /= ibond(1)) exch1 = -occ(ia,1)*occ(ib,1)
endif
if(ia == ianti(2) .and. ib <= ilim2) then
if(ib /= ibond(2)) exch2 = -occ(ia,2)*occ(ib,2)
endif
endif
!........And the factor of a half for the double counting
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
fac_e(ia,ib) = 0.5_dp*(exch1+exch2)
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine BB3_old
!---------------AND THE DERIVATIVE----------------------------
subroutine BB3_d_old(ia, ispin, occ, fac_c_d, fac_e_d)
use global
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
integer :: ilim
ilim=xnele(ispin); if(xnele(ispin)-ilim > 5*small) ilim=ilim+1
ispin_op=2
if(ispin==2) ispin_op=1
ocia = occ(ia, ispin)
do ib = 1, nnatorb
ocib= occ(ib,ispin)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op
fac_e_d(ib) = 0._dp
!.....Add SI terms for bonding-antibonding
if(((ia==ianti(ispin)).or.(ia==ibond(ispin))).and.(ib==ia)) then
fac_c_d(ib) = fac_c_d(ib) + ocib
fac_e_d(ib) = - 0.5_dp*sqrt(ocib)/sqrt(ocia)
endif
if(ia/=ib) then
fac_c_d(ib) = fac_c_d(ib) + ocib
fac_e_d(ib) = - 0.5_dp*sqrt(ocib)/sqrt(ocia)
!........BBC1 correction
if(ia > ilim.and.ib > ilim) fac_e_d(ib)=-fac_e_d(ib)
!........BBC2 correction
if(ia <= ilim .and. ib <= ilim) fac_e_d(ib)=-ocib
!........Add BBC2 for the antibonding
if(ia == ianti(ispin) .and. ib <= ilim) then
if(ib /= ibond(ispin)) fac_e_d(ib)=-ocib
endif
if(ib == ianti(ispin) .and. ia <= ilim) then
if(ia /= ibond(ispin)) fac_e_d(ib)=-ocib
endif
endif
enddo
end subroutine BB3_d_old
!-------------------------------------------------------------------
!-------------------------------------------------------------
! BBC3 (Journal of Chem Phys, 122, 204102-1 (2005).
! Degeneracies of bonding/antibonding are taken into account
! as in JCP 128, 184103 (2008)
subroutine BB3(occ, fac_h, fac_c, fac_e) !spin dependent
use global
use functional_m
implicit none
!..Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!..Local variables
integer :: ia, ib
real(dp) :: exch1, exch2
! See auxil.f90 subroutine BB_orb_kinds.
! kind_BBC3(ia,ispin) = 1 : orbital 'ia' is strongly occupied for ispin
! kind_BBC3(ia,ispin) = 2 : orbital 'ia' is bonding for ispin
! kind_BBC3(ia,ispin) = 3 : orbital 'ia' is anti-bonding for ispin
! kind_BBC3(ia,ispin) = 4 : orbital 'ia' is weakly occupied for ispin
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
do ib=1,ia !NOTE ia >= ib
!........The non SI part added for all:
fac_c(ia,ib) = occ(ia,1)*occ(ib,2) &
+ occ(ia,2)*occ(ib,1)
exch1=0.0_dp
exch2=0.0_dp
!........Add SI terms for bonding antibonding (spin resolved):
if((kind_BBC3(ia,1)==2.or.kind_BBC3(ia,1)==3).and.(ib==ia)) then
fac_c(ia,ib)= fac_c(ia,ib) + occ(ia,1)*occ(ib,1)
exch1 = -sqrt(occ(ia,1)*occ(ib,1))
endif
if((kind_BBC3(ia,2)==2.or.kind_BBC3(ia,2)==3).and.(ib==ia)) then
fac_c(ia,ib)= fac_c(ia,ib) + occ(ia,2)*occ(ib,2)
exch2 = -sqrt(occ(ia,2)*occ(ib,2))
endif
if(ia/=ib) then
fac_c(ia,ib)= fac_c(ia,ib) + occ(ia,1)*occ(ib,1) &
+ occ(ia,2)*occ(ib,2)
exch1 = -sqrt(occ(ia,1)*occ(ib,1))
exch2 = -sqrt(occ(ia,2)*occ(ib,2))
!...........BBC1 correction:
if(kind_BBC3(ia,1) >= 3 .and. kind_BBC3(ib,1) >= 3) exch1 = -exch1
if(kind_BBC3(ia,2) >= 3 .and. kind_BBC3(ib,2) >= 3) exch2 = -exch2
!...........BBC2 correction:
if(kind_BBC3(ia,1) <= 2 .and. kind_BBC3(ib,1) <= 2) exch1 = -occ(ia,1)*occ(ib,1)
if(kind_BBC3(ia,2) <= 2 .and. kind_BBC3(ib,2) <= 2) exch2 = -occ(ia,2)*occ(ib,2)
!...........Include antibonding in BBC2 correction
if(kind_BBC3(ia,1)==3 .and. kind_BBC3(ib,1)==1) exch1 = -occ(ia,1)*occ(ib,1)
if(kind_BBC3(ia,2)==3 .and. kind_BBC3(ib,2)==1) exch2 = -occ(ia,2)*occ(ib,2)
endif
!........And the factor of a half for the double counting
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
fac_e(ia,ib) = 0.5_dp*(exch1+exch2)
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine BB3
!---------------AND THE DERIVATIVE----------------------------
subroutine BB3_d(ia, ispin, occ, fac_c_d, fac_e_d)
use global
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
ispin_op=2
if(ispin==2) ispin_op=1
ocia = occ(ia, ispin)
do ib = 1, nnatorb
ocib= occ(ib,ispin)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op
fac_e_d(ib) = 0._dp
!.....Add SI terms for bonding-antibonding
! if(((ia==ianti(ispin)).or.(ia==ibond(ispin))).and.(ib==ia)) then
if((kind_BBC3(ia,ispin)==2 .or. kind_BBC3(ia,ispin)==3) &
.and. ia==ib) then
fac_c_d(ib) = fac_c_d(ib) + ocib
fac_e_d(ib) = - 0.5_dp*sqrt(ocib)/sqrt(ocia)
endif
if(ia/=ib) then
fac_c_d(ib) = fac_c_d(ib) + ocib
fac_e_d(ib) = - 0.5_dp*sqrt(ocib)/sqrt(ocia)
!........BBC1 correction
if(kind_BBC3(ia,ispin)>=3 .and. kind_BBC3(ib,ispin)>=3) &
fac_e_d(ib)=-fac_e_d(ib)
!........BBC2 correction
if(kind_BBC3(ia,ispin)<=2 .and. kind_BBC3(ib,ispin)<=2) &
fac_e_d(ib)=-ocib
!........Add BBC2 for the antibonding
if(kind_BBC3(ia,ispin)==3 .and. kind_BBC3(ib,ispin)==1) &
fac_e_d(ib)=-ocib
if(kind_BBC3(ib,ispin)==3 .and. kind_BBC3(ia,ispin)==1) &
fac_e_d(ib)=-ocib
endif
enddo
end subroutine BB3_d
!-------------------------------------------------------------------
!--------------------------------------------------------------------
! THE CHF FUNCTIONAL (Corrected-Hartree-Fock Csanyi-Arias, PRB 61, 7348 (2000))
subroutine CHF(occ, fac_h, fac_c, fac_e)
use global
implicit none
!..Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!..Local variables
integer :: ia, ib
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
if(occ(ia,1) < 0._dp) stop 'CHF:1 negative occ'
if(occ(ia,2) < 0._dp) stop 'CHF:2 negative occ'
if(occ(ia,1) > 1._dp) stop 'CHF:3 occ >1 '
if(occ(ia,2) > 1._dp) stop 'CHF:4 occ >1 '
do ib=1,ia
if(occ(ib,1) < 0._dp) stop 'CHF:5 negative occ'
if(occ(ib,2) < 0._dp) stop 'CHF:6 negative occ'
if(occ(ib,1) > 1._dp) stop 'CHF:7 occ >1 '
if(occ(ib,2) > 1._dp) stop 'CHF:8 occ >1 '
fac_c(ia,ib) = (occ(ia,1)+occ(ia,2))*(occ(ib,1)+occ(ib,2))
fac_e(ia,ib) = -occ(ia,1)*occ(ib,1) &
-occ(ia,2)*occ(ib,2) &
-sqrt(occ(ia,1)*(1._dp-occ(ia,1))*occ(ib,1)*(1._dp-occ(ib,1)))&
-sqrt(occ(ia,2)*(1._dp-occ(ia,2))*occ(ib,2)*(1._dp-occ(ib,2)))
!........The double counting 1/2 factor
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
fac_e(ia,ib) = 0.5_dp*fac_e(ia,ib)
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine CHF
!---------------AND THE DERIVATIVE----------------------------
subroutine CHF_d(ia, ispin, occ, fac_c_d, fac_e_d)
use global
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
ispin_op=2
if(ispin==2) ispin_op=1
ocia = min(occ(ia, ispin),1.d0-small)
do ib = 1, nnatorb
ocib= occ(ib,ispin)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op + ocib
fac_e_d(ib) = -ocib - 0.5_dp*(1._dp-2._dp*ocia)* &
sqrt((ocib*(1._dp-ocib))/(ocia*(1._dp-ocia)))
enddo
end subroutine CHF_d
!--------------------------------------------------------------------
! THE CGA FUNCTIONAL (Csanyi-Goedecker-Arias, PRA 65, 032510 (2002))
subroutine CGA(occ, fac_h, fac_c, fac_e)
use global
implicit none
!..Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!..Local variables
integer :: ia, ib
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
do ib=1,ia
fac_c(ia,ib) = (occ(ia,1)+occ(ia,2))*(occ(ib,1)+occ(ib,2))
fac_e(ia,ib) = -0.5_dp*(occ(ia,1)*occ(ib,1) &
+occ(ia,2)*occ(ib,2) &
+sqrt(occ(ia,1)*(2._dp-occ(ia,1))*occ(ib,1)*(2._dp-occ(ib,1)))&
+sqrt(occ(ia,2)*(2._dp-occ(ia,2))*occ(ib,2)*(2._dp-occ(ib,2))))
!........The double counting 1/2 factor
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
fac_e(ia,ib) = 0.5_dp*fac_e(ia,ib)
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine CGA
!---------------AND THE DERIVATIVE----------------------------
subroutine CGA_d(ia, ispin, occ, fac_c_d, fac_e_d)
use global
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
ispin_op=2
if(ispin==2) ispin_op=1
ocia = occ(ia, ispin)
do ib = 1, nnatorb
ocib= occ(ib,ispin)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op + ocib
fac_e_d(ib) = -0.5_dp*(ocib + (1._dp-1._dp*ocia)* &
sqrt((ocib*(2._dp-ocib))/(ocia*(2._dp-ocia))))
enddo
end subroutine CGA_d
!--------------------------------------------------------------------
! POWER FUNCTIONAL, Phys. Rev. B, 78, 201103(R) (2008), Lathiotakis et al PRA, 79 (2009)
! (modification of the Mueller functional: alpha exponent instead of 1/2 )
subroutine POW(occ, fac_h, fac_c, fac_e)
use global; use functional_m
implicit none
!..Arguments
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_h(lnnatorb)
real(dp), intent(out) :: fac_c(lnnatorb,lnnatorb)
real(dp), intent(out) :: fac_e(lnnatorb,lnnatorb)
!..Local variables
integer :: ia, ib
do ia=1,nnatorb
fac_h(ia) = occ(ia,1) + occ(ia,2)
do ib=1,ia
fac_c(ia,ib) = (occ(ia,1)+occ(ia,2))*(occ(ib,1)+occ(ib,2))
fac_e(ia,ib) = -(occ(ia,1)*occ(ib,1))**alpha &
-(occ(ia,2)*occ(ib,2))**alpha
!........The double counting 1/2 factor
fac_c(ia,ib) = 0.5_dp*fac_c(ia,ib)
fac_e(ia,ib) = 0.5_dp*fac_e(ia,ib)
fac_c(ib,ia) = fac_c(ia,ib)
fac_e(ib,ia) = fac_e(ia,ib)
enddo
enddo
end subroutine POW
!---------------AND THE DERIVATIVE----------------------------
subroutine POW_d(ia, ispin, occ, fac_c_d, fac_e_d)
use global; use functional_m
implicit none
!..Arguments
integer, intent(in) :: ia, ispin
real(dp), intent(in) :: occ(lnnatorb,3)
real(dp), intent(out) :: fac_c_d(lnnatorb), fac_e_d(lnnatorb)
!..Local
integer :: ib, ispin_op
real(dp) :: ocia, ocib, ocib_op
ispin_op=2
if(ispin==2) ispin_op=1
ocia = occ(ia, ispin)
do ib = 1, nnatorb
ocib= occ(ib,ispin)
ocib_op=occ(ib, ispin_op)
fac_c_d(ib) = ocib_op + ocib
fac_e_d(ib) = - alpha*(ocib**alpha)*(ocia**(alpha-1._dp))
enddo