-
Notifications
You must be signed in to change notification settings - Fork 13
/
sutda.f
executable file
·2403 lines (2199 loc) · 74.8 KB
/
sutda.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
! This file is part of stda.
!
! Copyright (C) 2013-2019 Stefan Grimme
!
! stda is free software: you can redistribute it and/or modify it under
! the terms of the GNU Lesser General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! stda is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU Lesser General Public License for more details.
!
! You should have received a copy of the GNU Lesser General Public License
! along with stda. If not, see <https://www.gnu.org/licenses/>.
!
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C ncent: number of atoms
C nmo : number of MOs
C nao : number of contracted AOs
C xyz : array with atomic coordinates (1:3) and nuclear charge (4) in
C Bohr
C c : MO coefficients (nao*nmo)
C eps : MO energies (au)
C occ : occupation numbers
C csp : molecular orbital spin (alpha - 1, beta - 2)
C iaoat: index array (1:nao) indicating on which atom the AO is centered
C thr : energy threshold in eV up to which energy the excited states
C are computed = spectral range (input in eV)
C thrp : threshold for perturbation selection of CSF (input)
C ax : Fock exchange mixing parameter in DF used
C othr and vthr NOT used (computed)
C othr : occ. orbitals with up to <othr> lower than Fermi level are
C included (input in eV)
C vthr : virt. orbitals with up to <vthr> above Fermi level are
C included (input in eV)
C fthr : threshold for CSF consideration in PT2
C nvec : integer, # roots for which eigenvectors are wanted
!
!!! used logicals from commonlogicals !!!
C triplet: logical=.true. if triplet states are to be calculated
C rpachk : logical=.true. if sTD-DFT is performed
C eigvec : logical=.true. print eigenvectors, ggavec is needed if eigvec and GGAs are used together
C nvec : integer, # roots for which eigenvectors are wanted
C screen : prescreen in pt selection and for CSFs with small transition strengths
C dokshift : shift A(ia,ia) elements if K(ia,ia) is small
C
C writes file <tda.dat> for spectrum plotting
C
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
SUBROUTINE sutda(ncent,nmo,nao,xyz,c,eps,occ,csp,iaoat,thr,thrp,
. ax,alphak,betaj,fthr,nvec)
use commonlogicals
use commonresp
use omp_lib
IMPLICIT NONE
c input:
integer ncent,nmo,nao
integer iaoat(*)
real*8 thr,thrp,ax,othr,vthr
real*8 c(*),eps(*),occ(*),xyz(4,*)
integer csp(*)
logical ggavec,ex
c local varibles:
c l=dipole lengths, v=dipole velocity (d/dxyz), m=angular momentum
real*8, allocatable ::xla(:),yla(:),zla(:)
real*8, allocatable ::xva(:),yva(:),zva(:)
real*8, allocatable ::xma(:),yma(:),zma(:)
real*8, allocatable ::xlb(:),ylb(:),zlb(:)
real*8, allocatable ::xvb(:),yvb(:),zvb(:)
real*8, allocatable ::xmb(:),ymb(:),zmb(:)
real*8, allocatable ::help(:),scr(:),dum(:),x(:,:)
c MOs, orbital energies and CSF printout stuff
real*8, allocatable ::cca(:),epsia(:)
real*8, allocatable ::ccb(:),epsib(:)
real*8, allocatable ::umerk(:,:)
real*8, allocatable ::umrkx(:,:),umrky(:,:),umrkz(:,:)
real*8, allocatable ::rvp(:)
c stuff for diag of TDA matrix
c critical regarding memory
integer info,lwork,liwork,il,iu,nfound
real*4, allocatable ::uci (:,:)
real*4, allocatable ::eci (:)
real*4, allocatable ::hci (:,:)
real*4, allocatable ::work (:)
real*4 vu,vl
integer,allocatable ::iwork(:)
integer,allocatable::isuppz(:)
c Löwdin MOs, repulsion terms, charges and half-transformed stuff
c critical regarding memory
real*8, allocatable ::clowa(:)
real*8, allocatable ::clowb(:)
real*4, allocatable ::gamj(:,:)
real*4, allocatable ::gamk(:,:)
real*4, allocatable ::qiaa(:,:),qiab(:,:),piaa(:,:),piab(:,:)
real*4, allocatable ::pija(:,:),qaba(:,:),qija(:,:)
real*4, allocatable ::pijb(:,:),qabb(:,:),qijb(:,:)
real*4, allocatable ::q1a(:),q1b(:),q2(:)
! real*4 q1a(ncent),q1b(ncent),q2(ncent)
! prescreening vectors K_ia,ia
real*4 sdot
c the maximum size of the TDA expansion space
! integer maxconf1,maxconf2
! parameter (maxconf1=500000)
!c the maximum size of the TDA pt2 space
! parameter (maxconf2=maxconf1*10)
! integer kconfa(maxconf2,2)
! integer kconfb(maxconf2,2)
! real*8 edpta(maxconf2)
! real*8 edptb(maxconf2)
! maximum sizes of P-CSF and S-CSF expansion space
integer maxconfa,maxconfb
real*8, allocatable ::eda(:),edb(:)
real*8, allocatable ::edpta(:),edptb(:)
integer, allocatable :: iconfa(:,:),iconfb(:,:)
integer, allocatable :: kconfa(:,:),kconfb(:,:)
c RPA stuff
real*4, allocatable ::apb(:)
real*4, allocatable ::ambsqr(:)
c intermediates
real*8 omax,vmin,pert,de,ek,ej,ak,xc,rabx,ef
real*8 pp,hilf,uu,sss,rl,rv,rm,time,coc(3)
real*8 fl,fv,ec,p23,xp,umax,xvu,yvu,zvu,xmu,ymu,zmu,xlu,ylu,zlu
real*8 xj,amat,xmolw,xk,loc,jii,jaa,xms,yms,zms
real*8 betaj,alphak,beta1,beta2,alpha1,alpha2,deps,fthr
integer moci,i,j,k,ii,io,iv,ihilf,jo,jv,m,l,idum1,idum2
integer*8 imem1,imem2,imem3
integer jj,kmem,imax,jmax,lmem,jmem,ij,lin,ierr
! state/orbital indices and dimensions
integer n,no,nv,noa,nob,nva,nvb,nuhf,nsomoa,nsomob
integer nexpt,nexpta,nexptb
integer nex,nexa,nexb
integer new,newa,newb
integer mocia,mocib
integer ispin,nci,nroot
! SOS polarizability and sum rule check
real*8 alp_real(6),sumf
! variables for vector printout
integer, allocatable :: vecchka(:),vecchkb(:)
integer nvec,jhomo,jhomoa,jhomob
c atomic Hubbard parameters
real*8 eta(94)
c atomic masses
common /amass/ ams(107)
real*8 ams
character*79 dummy
c Linear response
real*4 :: start_time, end_time, stda_time
integer :: STATUS
c just a printout
call header('s T D A',0)
thr =thr /27.211385050d0
c estimate the orbital energy window which corresponds to the desired
c spectra range thr
deps=(1.+0.8*ax)*thr
c make it safe
deps=deps*2.0
omax=-1d+42
vmin= 1d+42
do i=1,nmo
if(occ(i).gt.0.99.and.eps(i).gt.omax) omax=eps(i)
if(occ(i).lt.0.01.and.eps(i).lt.vmin) vmin=eps(i)
enddo
! optional: if eigenvectors are wanted in TM format, check now how many occupied there are in general
! this is needed to get the CSF sorting of TM
jhomo=0
jhomoa=0
jhomob=0
do i=1,nmo
if(occ(i).gt.0.990d0) then
jhomo=jhomo+1
if(csp(i).eq.1) jhomoa = jhomoa + 1
if(csp(i).eq.2) jhomob = jhomob + 1
endif
enddo
nuhf=jhomoa-jhomob
othr=vmin-deps
vthr=deps+omax
write(*,*)'spectral range up to (eV) : ', thr*27.211385050d0
write(*,*)'occ MO cut-off (eV) : ', othr*27.211385050d0
write(*,*)'virtMO cut-off (eV) : ', vthr*27.211385050d0
write(*,*)'perturbation thr : ', thrp
if(fthr.lt.1.79d308) then
write(*,*)'max. CSF selection range (eV) : ', fthr
fthr = fthr /27.211385050d0
endif
mocia = 0
mocib = 0
do i = 1,nmo
if(eps(i).gt.othr.and.eps(i).lt.vthr) then
if(csp(i).eq.1) mocia = mocia + 1
if(csp(i).eq.2) mocib = mocib + 1
endif
enddo
moci = mocia + mocib
allocate(
. xla(mocia*(mocia+1)/2),yla(mocia*(mocia+1)/2),
. zla(mocia*(mocia+1)/2),
. xlb(mocib*(mocib+1)/2),ylb(mocib*(mocib+1)/2),
. zlb(mocib*(mocib+1)/2),
. xva(mocia*(mocia+1)/2),yva(mocia*(mocia+1)/2),
. zva(mocia*(mocia+1)/2),
. xvb(mocib*(mocib+1)/2),yvb(mocib*(mocib+1)/2),
. zvb(mocib*(mocib+1)/2),
. xma(mocia*(mocia+1)/2),yma(mocia*(mocia+1)/2),
. zma(mocia*(mocia+1)/2),
. xmb(mocib*(mocib+1)/2),ymb(mocib*(mocib+1)/2),
. zmb(mocib*(mocib+1)/2),
. help(nao*(nao+1)/2),
. clowa(nao*mocia),clowb(nao*mocib),
. scr(nao*nao),dum(nao*nao),x(nao,nao),
. gamj(ncent,ncent),gamk(ncent,ncent),
. cca(nao*mocia),epsia(mocia),
. ccb(nao*mocib),epsib(mocib)
. )
write(*,*) 'Active space MOs in TDA : ',moci,mocia,mocib
mocia=0
mocib=0
moci =0
! optional: if eigenvectors are wanted, make set a checking variable (vecchk) that maps the
! TM orbital space onto the sTDA orbital space (which is reduced due to thresholds)
if(eigvec.or.nto) then
allocate (vecchka(nmo/2),vecchkb(nmo/2))
vecchka=0 ! for vector printout
vecchkb=0
l=0
k=0
do i = 1,nmo
if(occ(i).gt.0.99) then
if(csp(i).eq.1) then
l=l+1 ! increase alpha counter
if(eps(i).gt.othr)then
mocia = mocia + 1
moci = moci +1
do j=1,nao
cca(j+(mocia-1)*nao)=c(j+(i-1)*nao)
enddo
epsia(mocia)=eps(i)
vecchka(l)=mocia
endif
endif
if(csp(i).eq.2) then
k = k+1 ! increase beta counter
if(eps(i).gt.othr)then
mocib = mocib + 1
moci = moci + 1
do j=1,nao
ccb(j+(mocib-1)*nao)=c(j+(i-1)*nao)
enddo
epsib(mocib)=eps(i)
vecchkb(k)=mocib
endif
endif
endif
enddo
no = moci
noa = mocia
nob = mocib
do i = 1,nmo
if(occ(i).lt.0.01) then
if(csp(i).eq.1) then
l=l+1 ! increase alpha counter
if(eps(i).lt.vthr)then
mocia = mocia + 1
moci = moci +1
do j=1,nao
cca(j+(mocia-1)*nao)=c(j+(i-1)*nao)
enddo
epsia(mocia)=eps(i)
vecchka(l)=mocia
endif
endif
if(csp(i).eq.2) then
k = k+1 ! increase beta counter
if(eps(i).lt.vthr)then
mocib = mocib + 1
moci = moci + 1
do j=1,nao
ccb(j+(mocib-1)*nao)=c(j+(i-1)*nao)
enddo
epsib(mocib)=eps(i)
vecchkb(k)=mocib
endif
endif
endif
enddo
else
! do not print eigenvectors case
do i = 1,nmo
if(occ(i).gt.0.99.and.eps(i).gt.othr)then
moci = moci + 1
if(csp(i).eq.1) then
mocia = mocia + 1
do j=1,nao
cca(j+(mocia-1)*nao)=c(j+(i-1)*nao)
enddo
epsia(mocia)=eps(i)
endif
if(csp(i).eq.2) then
mocib = mocib + 1
do j=1,nao
ccb(j+(mocib-1)*nao)=c(j+(i-1)*nao)
enddo
epsib(mocib)=eps(i)
endif
endif
enddo
no = moci
noa = mocia
nob = mocib
do i = 1,nmo
if(occ(i).lt.0.01.and.eps(i).lt.vthr)then
moci=moci+1
if(csp(i).eq.1) then
mocia = mocia + 1
do j=1,nao
cca(j+(mocia-1)*nao)=c(j+(i-1)*nao)
enddo
epsia(mocia)=eps(i)
endif
if(csp(i).eq.2) then
mocib = mocib + 1
do j=1,nao
ccb(j+(mocib-1)*nao)=c(j+(i-1)*nao)
enddo
epsib(mocib)=eps(i)
endif
endif
enddo
endif
nv = moci - no
nva = mocia - noa
nvb = mocib - nob
write(*,*) 'Occupied active MOs in TDA: ', no,noa,nob
write(*,*) 'Virtual active MOs in TDA: ', nv,nva,nvb
if((noa.eq.0.or.nva.eq.0).and.(nob.eq.0.or.nvb.eq.0)) then
stop 'no CSF, increase energy threshold (-e option)'
endif
maxconfa=noa*nva
maxconfb=nob*nvb
allocate(eda(maxconfa),edpta(maxconfa),
. edb(maxconfb),edptb(maxconfb), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for ed and edpt'
allocate(iconfa(maxconfa,2),kconfa(maxconfa,2),
. iconfb(maxconfb,2),kconfb(maxconfb,2), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for iconf and kconf'
eda=0.0d0
edpta=0.0d0
iconfa=0
kconfa=0
edb=0.0d0
edptb=0.0d0
iconfb=0
kconfb=0
c we arrange MOS according to energy from 1:HOMO to LUMO:MOCI
c (in TM they come in irreps)
write(*,*) 'Sorting MOs ...'
c sort for E diag
call sort_vec(mocia,nao,cca,epsia)
call sort_vec(mocib,nao,ccb,epsib)
write(*,*) 'Reading and transforming R..V..L AO ints ...'
c read L,V,M with xyz components each and transform
c to MO basis (original but sorted MOs in array ca)
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
c
c dipole lengths
c
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
open(unit=31,file='xlint',form='unformatted',status='old')
read(31) help
call onetri(1,help,dum,scr,cca,nao,mocia)
call shrink(mocia,dum,xla)
call onetri(1,help,dum,scr,ccb,nao,mocib)
call shrink(mocib,dum,xlb)
close(31,status='delete')
open(unit=32,file='ylint',form='unformatted',status='old')
read(32) help
call onetri(1,help,dum,scr,cca,nao,mocia)
call shrink(mocia,dum,yla)
call onetri(1,help,dum,scr,ccb,nao,mocib)
call shrink(mocib,dum,ylb)
close(32,status='delete')
open(unit=33,file='zlint',form='unformatted',status='old')
read(33) help
call onetri(1,help,dum,scr,cca,nao,mocia)
call shrink(mocia,dum,zla)
call onetri(1,help,dum,scr,ccb,nao,mocib)
call shrink(mocib,dum,zlb)
close(33,status='delete')
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
c
c magnetic dipole
c
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
open(unit=34,file='xmint',form='unformatted',status='old')
read(34) help
call onetri(-1,help,dum,scr,cca,nao,mocia)
call shrink(mocia,dum,xma)
call onetri(-1,help,dum,scr,ccb,nao,mocib)
call shrink(mocib,dum,xmb)
close(34,status='delete')
open(unit=35,file='ymint',form='unformatted',status='old')
read(35) help
call onetri(-1,help,dum,scr,cca,nao,mocia)
call shrink(mocia,dum,yma)
call onetri(-1,help,dum,scr,ccb,nao,mocib)
call shrink(mocib,dum,ymb)
close(35,status='delete')
open(unit=36,file='zmint',form='unformatted',status='old')
read(36) help
call onetri(-1,help,dum,scr,cca,nao,mocia)
call shrink(mocia,dum,zma)
call onetri(-1,help,dum,scr,ccb,nao,mocib)
call shrink(mocib,dum,zmb)
close(36,status='delete')
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
c
c velocity dipole
c
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
open(unit=37,file='xvint',form='unformatted',status='old')
read(37) help
call onetri(-1,help,dum,scr,cca,nao,mocia)
call shrink(mocia,dum,xva)
call onetri(-1,help,dum,scr,ccb,nao,mocib)
call shrink(mocib,dum,xvb)
close(37,status='delete')
open(unit=38,file='yvint',form='unformatted',status='old')
read(38) help
call onetri(-1,help,dum,scr,cca,nao,mocia)
call shrink(mocia,dum,yva)
call onetri(-1,help,dum,scr,ccb,nao,mocib)
call shrink(mocib,dum,yvb)
close(38,status='delete')
open(unit=39,file='zvint',form='unformatted',status='old')
read(39) help
call onetri(-1,help,dum,scr,cca,nao,mocia)
call shrink(mocia,dum,zva)
call onetri(-1,help,dum,scr,ccb,nao,mocib)
call shrink(mocib,dum,zvb)
close(39,status='delete')
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
c calc S^1/2 and q(GS)
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
open(unit=40,file='sint',form='unformatted',status='old')
read(40) help
write(*,*) 'ints done.'
close(40,status='delete')
write(*,*) 'S^1/2 ...'
call makel(nao,help,x)
call dgemm('n','n',nao,mocia,nao,1.d0,x,nao,cca,nao,0.d0,scr,nao)
do i=1,mocia
sss=0
do j=1,nao
sss = sss+scr(j+(i-1)*nao)**2
clowa(j+(i-1)*nao) = scr(j+(i-1)*nao)
enddo
if(abs(sss-1.).gt.1.d-2)then
write(*,*) 'alpha MO norm ',i,sss
stop 'internal MO norm error'
endif
enddo
call dgemm('n','n',nao,mocib,nao,1.d0,x,nao,ccb,nao,0.d0,scr,nao)
do i=1,mocib
sss=0
do j=1,nao
sss = sss+scr(j+(i-1)*nao)**2
clowb(j+(i-1)*nao) = scr(j+(i-1)*nao)
enddo
if(abs(sss-1.0d0).gt.1.d-2)then
write(*,*) 'beta MO norm ',i,sss
stop 'internal MO norm error'
endif
enddo
write(*,*) 'S^1/2 orthogonalized MO coefficients done.'
deallocate(scr,dum,help,x)
! q1a = 0
! do i=1,noa
! call lo12pop(i,i,ncent,nao,iaoat,clowa,q2)
! q1a(1:ncent)=q1a(1:ncent)+q2(1:ncent)
! enddo
! q1b = 0
! do i=1,nob
! call lo12pop(i,i,ncent,nao,iaoat,clowb,q2)
! q1b(1:ncent)=q1b(1:ncent)+q2(1:ncent)
! enddo
call cpu_time(time)
allocate(q1a(ncent),q1b(ncent),q2(ncent))
q1a=0.0
q1b=0.0
q2=0.0
allocate(qija(ncent,noa),qaba(ncent,nva),
. qijb(ncent,nob),qabb(ncent,nvb),stat=ierr)
if(ierr.ne.0) stop 'error in diag. J charges allocation'
qija=0.0
qaba=0.0
qijb=0.0
qabb=0.0
do i=1,noa
call lo12pop(i,i,ncent,nao,iaoat,clowa,q2)
q1a(1:ncent)=q1a(1:ncent)+q2(1:ncent)
qija(1:ncent,i)=q2(1:ncent)
enddo
do i=1,nob
call lo12pop(i,i,ncent,nao,iaoat,clowb,q2)
q1b(1:ncent)=q1b(1:ncent)+q2(1:ncent)
qijb(1:ncent,i)=q2(1:ncent)
enddo
write(*,'(/'' SCF atom population (using active MOs):'')')
write(*,'(10F7.3)') q1a(1:ncent)
write(*,'(10F7.3)') q1b(1:ncent)
write(*,'(10F7.3)') (q1a(1:ncent)+q1b(1:ncent))
write(*,*)
write(*,'('' # of alpha and beta electrons in TDA:'',2F8.3)')
.sum(q1a(1:ncent)),sum(q1b(1:ncent))
write(*,*)
do i=noa+1,mocia
j=i-noa
call lo12pop(i,i,ncent,nao,iaoat,clowa,q2)
qaba(1:ncent,j)=q2(1:ncent)
enddo
do i=nob+1,mocib
j=i-nob
call lo12pop(i,i,ncent,nao,iaoat,clowb,q2)
qabb(1:ncent,j)=q2(1:ncent)
enddo
c UCIS scaling factor for K(ia|jb):
ak = 1.0d0
c the global parameters of the method:
beta1 = 0.20d0
beta2 = 1.830d0
alpha1 = 1.420d0
alpha2 = 0.480d0
if(betaj.lt.-99.0d0) then ! if no beta parameter was read in
betaj=beta1+beta2*ax
endif
if(alphak.lt.-99.0d0) then ! if no alpha parameter was read in
alphak=alpha1+alpha2*ax
endif
write(*,*)
write(*,*) 'ax(DF) : ',ax
write(*,*) 's^K : ',ak
write(*,*) 'beta (J): ',betaj
write(*,*) 'alpha (K): ',alphak
write(*,*)
c set the hardness table
call setrep(eta)
write(*,*) 'hardness table read.'
write(*,*) 'setting up gammas ...'
c compute gamma(j/k)
xmolw=0
do i = 1,ncent
ii = idint(xyz(4,i))
c ams is the atomic mass (mol weight for output file)
xmolw = xmolw+ams(ii)
do j=1,i
jj = idint(xyz(4,j))
xj = 0.50d0*(eta(ii)+eta(jj)) * ax
xk = 0.50d0*(eta(ii)+eta(jj))
rabx = dsqrt((xyz(1,i)-xyz(1,j))**2
. +(xyz(2,i)-xyz(2,j))**2
. +(xyz(3,i)-xyz(3,j))**2)
gamj(j,i)=real(1./(rabx**betaj+1./xj**betaj)**(1.0d0/betaj))
gamk(j,i)=real(1./(rabx**alphak+1./xk**alphak)
. **(1.0d0/alphak))
gamj(i,j) = gamj(j,i)
gamk(i,j) = gamk(j,i)
enddo
enddo
! compute intermediates q's refer to charges, p's to gam*q (i.e., contracted)
imem1=noa
imem2=nva
imem3=(noa*nva+nob*nvb)*2
imem1=noa*(noa+1)/2+nob*(nob+1)/2
imem2=nva*(nva+1)/2+nvb*(nvb+1)/2
imem3=imem3+imem1+imem2
hilf=dble(imem3)/1024.0**2
hilf=dble(4*ncent)*hilf
imem1=idint(hilf)
write(*,*)'memory needed for qa and qb data (Mb) ',imem1
write(*,*)'computing q(ij,n) ...'
! first alpha part
! Coulomb type terms: calc qij*gam^J
allocate(pija(ncent,noa), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for (ii| intermediate'
pija=0.0
call ssymm('l','l',ncent,noa,1.0,gamj,ncent,qija,ncent,0.0,pija
. ,ncent)
allocate(uci(nva,noa), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for (ii|aa) matrix'
uci=0.0
! now calc (ii|aa)^J
call sgemm('t','n',nva,noa,ncent,1.0,qaba,ncent,pija,ncent,0.0,
. uci,nva)
deallocate(pija)
nex=noa*nva
allocate(piaa(ncent,nex),qiaa(ncent,nex), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for intermediates'
qiaa=0.0
piaa=0.0
! K-type terms
k=0
!$omp parallel private(i,j,k,q2)
!$omp do
do i=1,noa
do j=noa+1,mocia
! k=k+1
k=(i-1)*nva+j-noa
call lo12pop(i,j,ncent,nao,iaoat,clowa,q2)
qiaa(1:ncent,k)=q2(1:ncent)
enddo
enddo
!$omp end do
!$omp end parallel
piaa=0.0
call ssymm('l','l',ncent,nex,1.0,gamk,ncent,qiaa,ncent,0.0
. ,piaa,ncent)
c determine singles which are lower than thr using A(ia,ia)
c alpha excitations first:
k=0
j=0
l=0
nsomoa=noa-nuhf
do io=1,noa
do iv=noa+1,mocia
c compute A(ia,ia) = eps(a)-eps(i) + (ia|ia) - (ii|aa)
de=epsia(iv)-epsia(io)
l=iv-noa
ej=0.0d0
ej=dble(uci(l,io))
de=de-ej
ek=0.0d0
i=nva*(io-1)+l
q1a(1:ncent)=piaa(1:ncent,i)
ek=sdot(ncent,q1a,1,qiaa(1,i),1)
de=de+ak*ek
if(dokshift) then
! perform K(ia,ia) dependent shift
call kshift_to_ediag(de,ek)
call somo_shift(nsomoa,io,iv,de,ek)
endif
c the primary ones
if(de.le.thr)then
k=k+1
iconfa(k,1)=io
iconfa(k,2)=iv
eda(k)=de
endif
c for PT
if(de.gt.thr.and.de.lt.fthr)then ! needs to be on if fthr is specified
j=j+1
kconfa(j,1)=io
kconfa(j,2)=iv
edpta(j)=de
endif
enddo
enddo
nexa=k
nexpta=j
deallocate(uci)
! now beta part
! Coulomb type terms: calc qij*gam^J
allocate(pijb(ncent,nob), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for (ii| intermediate'
pijb=0.0
call ssymm('l','l',ncent,nob,1.0,gamj,ncent,qijb,ncent,0.0,pijb
. ,ncent)
allocate(uci(nvb,nob), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for (ii|aa) matrix'
uci=0.0
! now calc (ii|aa)^J
call sgemm('t','n',nvb,nob,ncent,1.0,qabb,ncent,pijb,ncent,0.0,
. uci,nvb)
deallocate(pijb)
nex=nob*nvb
allocate(piab(ncent,nex),qiab(ncent,nex), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for intermediates'
qiab=0.0
piab=0.0
! K-type terms
k=0
!$omp parallel private(i,j,k,q2)
!$omp do
do i=1,nob
do j=nob+1,mocib
! k=k+1
k=(i-1)*nvb+j-nob
call lo12pop(i,j,ncent,nao,iaoat,clowb,q2)
qiab(1:ncent,k)=q2(1:ncent)
enddo
enddo
!$omp end do
!$omp end parallel
piab=0.0
call ssymm('l','l',ncent,nex,1.0,gamk,ncent,qiab,ncent,0.0
. ,piab,ncent)
deallocate(gamk)
k=0
j=0
l=0
nsomob=nob+nuhf
do io=1,nob
do iv=nob+1,mocib
c compute A(ia,ia) = eps(a)-eps(i) + (ia|ia) - (ii|aa)
de=epsib(iv)-epsib(io)
l=iv-nob
ej=0.0d0
ej=dble(uci(l,io))
de=de-ej
ek=0.0d0
i=nvb*(io-1)+l
q1b(1:ncent)=piab(1:ncent,i)
ek=sdot(ncent,q1b,1,qiab(1,i),1)
de=de+ak*ek
if(dokshift) then
! perform K(ia,ia) dependent shift
call kshift_to_ediag(de,ek)
call somo_shift(nsomob,io,iv,de,ek)
endif
c the primary ones
if(de.le.thr)then
k=k+1
iconfb(k,1)=io
iconfb(k,2)=iv
edb(k)=de
endif
c for PT
if(de.gt.thr.and.de.lt.fthr)then ! needs to be on if fthr is specified
j=j+1
kconfb(j,1)=io
kconfb(j,2)=iv
edptb(j)=de
endif
enddo
enddo
nexb=k
nexptb=j
deallocate(uci)
nex = nexa + nexb
nexpt = nexpta + nexptb
write(*,*)
write(*,*) '# CSF included by energy:',nexa,nexb,nex
write(*,*)
write(*,*) '# CSF considered in PT2:',nexpta,nexptb,nexpt
c errors and warning
if(nex.lt.1) stop 'No CSF, increase energy threshold (-e option)'
if(nexa.lt.1.or.nexb.lt.1)
. write(*,*) 'WARNING: No alpha or beta excitations included!'
! if(nexa.eq.maxconf1.or.nexb.eq.maxconf1)
! . stop 'Primary CSF space exceeded. use -e option!'
! if(nexpta.eq.maxconf2.or.nexptb.eq.maxconf2)
! . write(*,*)'CSF PT2 space exceeded. try -p option!'
c sort for E diag in each spin manifold
do 141 ii = 2,nexa
i = ii - 1
k = i
pp= eda(i)
do 121 j = ii, nexa
if (eda(j) .ge. pp) go to 121
k = j
pp=eda(j)
121 continue
if (k .eq. i) go to 141
eda(k) = eda(i)
eda(i) = pp
do m=1,2
ihilf=iconfa(i,m)
iconfa(i,m)=iconfa(k,m)
iconfa(k,m)=ihilf
enddo
141 continue
do 142 ii = 2,nexb
i = ii - 1
k = i
pp= edb(i)
do 122 j = ii, nexb
if (edb(j) .ge. pp) go to 122
k = j
pp=edb(j)
122 continue
if (k .eq. i) go to 142
edb(k) = edb(i)
edb(i) = pp
do m=1,2
ihilf=iconfb(i,m)
iconfb(i,m)=iconfb(k,m)
iconfb(k,m)=ihilf
enddo
142 continue
c just printout
write(*,*) ' '
write(*,*)'Ordered frontier alpha orbitals:'
write(*,*)' eV # centers'
j=max(1,noa-10)
do i=j,noa
xc=0
do k=1,ncent
xc=xc+qija(k,i)**2
enddo
write(*,'(i4,F10.3,F8.1)') i,epsia(i)*27.21139,1./(xc+1.d-8)
enddo
! write(*,*)'Unoccupied:'
write(*,*) ' '
j=min(mocia,noa+11)
do i=noa+1,j
xc=0
do k=1,ncent
xc=xc+qaba(k,i-noa)**2
enddo
write(*,'(i4,F10.3,F8.1)') i,epsia(i)*27.21139,1./(xc+1.d-8)
enddo
write(*,*) ' '
write(*,*)'Ordered frontier beta orbitals:'
write(*,*)' eV # centers'
j=max(1,nob-10)
do i=j,nob
xc=0
do k=1,ncent
xc=xc+qijb(k,i)**2
enddo
write(*,'(i4,F10.3,F8.1)') i,epsib(i)*27.21139,1./(xc+1.d-8)
enddo
! write(*,*)'Unoccupied:'
write(*,*) ' '
j=min(mocib,nob+11)
do i=nob+1,j
xc=0
do k=1,ncent
xc=xc+qabb(k,i-nob)**2
enddo
write(*,'(i4,F10.3,F8.1)') i,epsib(i)*27.21139,1./(xc+1.d-8)
enddo
write(*,*)
write(*,*)' Lowest CSF states:'
write(*,*)' Alpha Excitations:'
write(*,*)' eV nm excitation i->a eV'
do i=1,min(nexa,25)
io=iconfa(i,1)
iv=iconfa(i,2)
q1a(1:ncent)=qija(1:ncent,io)
call ssymv('l',ncent,1.0e0,gamj,ncent,q1a,1,0.0,q2,1)
jii=sdot(ncent,q1a,1,q2,1)
k=iv-noa
q1a(1:ncent)=qaba(1:ncent,k)
ej=sdot(ncent,q1a,1,q2,1)
call ssymv('l',ncent,1.0e0,gamj,ncent,q1a,1,0.0,q2,1)
jaa=sdot(ncent,q1a,1,q2,1)
l=nva*(io-1)+k
q1a(1:ncent)=piaa(1:ncent,l)
q2(1:ncent)=qiaa(1:ncent,l)
ek=sdot(ncent,q1a,1,q2,1)
! de is now the Kia shift
de=0
loc=ej/sqrt(jii*jaa) ! locality
if(dokshift) call kshift_to_ediag(de,ek)
if(dokshift) call somo_shift(nsomoa,io,iv,de,ek)
write(*,16) i,27.211*eda(i),
. 1.d+7/(eda(i)*2.19474625d+5),iconfa(i,1:2),
. 27.211*(epsia(iv)-epsia(io)),27.211*ej,27.211*ek,27.211*de,loc
enddo
16 format(i5,f6.2,f8.1, 5x,i4,' ->',i4,5x,'gap,J,K:',3f8.3,
. 3x,'Kshft:',f8.3,2x,'locality:',f6.3)
write(*,*)
write(*,*)' Beta Excitations:'
write(*,*)' eV nm excitation i->a eV'
do i=1,min(nexb,25)
io=iconfb(i,1)
iv=iconfb(i,2)
q1b(1:ncent)=qijb(1:ncent,io)
call ssymv('l',ncent,1.0e0,gamj,ncent,q1b,1,0.0,q2,1)
jii=sdot(ncent,q1b,1,q2,1)
k=iv-nob
q1b(1:ncent)=qabb(1:ncent,k)
ej=sdot(ncent,q1b,1,q2,1)
call ssymv('l',ncent,1.0e0,gamj,ncent,q1b,1,0.0,q2,1)
jaa=sdot(ncent,q1b,1,q2,1)
l=nvb*(io-1)+k
q1b(1:ncent)=piab(1:ncent,l)
q2(1:ncent)=qiab(1:ncent,l)
ek=sdot(ncent,q1b,1,q2,1)
! de is now the Kia shift
de=0
loc=ej/sqrt(jii*jaa) ! locality
if(dokshift) call kshift_to_ediag(de,ek)
if(dokshift) call somo_shift(nsomob,io,iv,de,ek)
write(*,16) i,27.211*edb(i),
. 1.d+7/(edb(i)*2.19474625d+5),iconfb(i,1:2),
. 27.211*(epsib(iv)-epsib(io)),27.211*ej,27.211*ek,27.211*de,loc
enddo
deallocate(qija,qaba,qijb,qabb)
!!! now set up pij an qab -alpha first
ihilf=noa*(noa+1)/2
allocate(qija(ncent,ihilf),stat=ierr)
if(ierr.ne.0) stop 'error in qij allocation'
qija=0.0
ij=0
!$omp parallel private(i,j,ij,q2)
!$omp do
do i=1,noa
do j=1,i
ij=lin(i,j)
call lo12pop(i,j,ncent,nao,iaoat,clowa,q2)
qija(1:ncent,ij)=q2(1:ncent)
enddo
enddo
!$omp end do