forked from grimme-lab/stda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stda-rw_dual.f
executable file
·1564 lines (1402 loc) · 47.3 KB
/
stda-rw_dual.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/>.
!
! adapted by Marc de Wegifosse 2018-2019
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 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 stda_rw_dual(ncent,nmo,nao,xyz,c,eps,occ,iaoat,thr,
. thrp,ax,alphak,betaj,fthr,nvec,ipat,ipao,nprims)
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,*)
logical ggavec,ex
c local varibles:
c l=dipole lengths, v=dipole velocity (d/dxyz), m=angular momentum
real*8 ::dipole(3),dipole_mo(3)
integer::iwrk,jwrk
real*8, allocatable ::xl(:),yl(:),zl(:)
real*8, allocatable ::xv(:),yv(:),zv(:)
real*8, allocatable ::xm(:),ym(:),zm(:)
real*8, allocatable ::help(:),scr(:),dum(:),x(:,:)
c MOs, orbital energies and CSF printout stuff
real*8, allocatable ::ca(:),epsi(:)
real*8, allocatable ::umerk(:,:),umrkx(:,:),umrky(:,:),umrkz(:,:)
real*8, allocatable ::rvp(:)
c stuff for diag of TDA matrix (or rpa)
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 (:)
c RPA stuff
real*4, allocatable ::apb(:)
real*4, allocatable ::ambsqr(:)
real*4, allocatable ::amb(:)
c Linear response
real*4 :: start_time, end_time, stda_time
integer :: STATUS
ccccccccccccc
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 ::clow(:)
real*4, allocatable ::gamj(:,:)
real*4, allocatable ::gamk(:,:)
real*4, allocatable ::qia(:,:),pia(:,:)
real*4, allocatable ::pij(:,:),qab(:,:),qij(:,:)
real*4, allocatable ::q1(:),q2(:),q3(:)
real*4 sdot, integral
!c the maximum size of the TDA expansion space
integer maxconf
real*8, allocatable ::ed(:),edpt(:)
integer, allocatable :: iconf(:,:),kconf(:,:)
! check for vector printout
integer, allocatable :: vecchk(:)
c intermediates
real*8 omax,vmin,pert,de,ek,ej,ak,xc,rabx,ef,fthr,aksqrt
real*8 beta1,alpha2,pp,hilf,uu,sss,rl,rv,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,betaj,alphak,beta2,alpha1,deps,loc,jii,jaa
real*8 alp_real(6),sumf,xms,yms,zms
integer moci,i,j,k,l,ii,ihomo,io,iv,ihilf,nex,new,jo,jv,m,jmem
integer nci,jj,idum1,idum2,kmem,imax,jmax,lmem,ij,nroot,lin,ierr
integer no,nv,n,nexpt,jhomo,nvec
integer*8 imem1,imem2,imem3
c atomic Hubbard parameters
real*8 eta(94)
c atomic masses
common /amass/ ams(107)
real*8 ams
character*79 dummy
c dual method extra parameters
real*8 thresh(2),sum_mo
integer num_atoms,nprims,ipat(nprims),ipao(nprims),n_MO(2)
integer,allocatable :: atom_list(:),mocc_1(:),mocc_2(:)
logical,allocatable :: mo_list(:)
call cpu_time(stda_time)
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 save
deps=deps*2.0
moci=0
omax=-1d+42
vmin= 1d+42
do i=1,nmo
if(occ(i).gt.1.990d0.and.eps(i).gt.omax) omax=eps(i)
if(occ(i).lt.0.010d0.and.eps(i).lt.vmin)vmin=eps(i)
enddo
! if eigenvectors are wanted in TM format,check now how many occupied there are in general
if(eigvec) then
jhomo=0
do i=1,nmo
if(occ(i).gt.1.990d0) jhomo=jhomo+1
enddo
endif
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
write(*,*)'triplet : ', triplet
do i=1,nmo
if(occ(i).gt.1.990d0.and.eps(i).gt.othr)moci=moci+1
if(occ(i).lt.0.010d0.and.eps(i).lt.vthr)moci=moci+1
enddo
allocate(
. xl(moci*(moci+1)/2),yl(moci*(moci+1)/2),
. zl(moci*(moci+1)/2),
. xv(moci*(moci+1)/2),yv(moci*(moci+1)/2),
. zv(moci*(moci+1)/2),
. xm(moci*(moci+1)/2),ym(moci*(moci+1)/2),
. zm(moci*(moci+1)/2),
. help(nao*(nao+1)/2),clow(nao*moci),
. scr(nao*nao),dum(nao*nao),x(nao,nao),
. gamj(ncent,ncent),
. gamk(ncent,ncent),
. ca(nao*moci),epsi(moci)
. )
write(*,*)'MOs in TDA : ', moci
! make two cases: 1st one) eigenvectors are needed, 2) eigenvectors are not needed
if(eigvec.or.nto) then ! we want eigenvectors to be printed out
allocate(vecchk(nmo), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for vecchk'
vecchk=0
moci=0
do i=1,nmo
if(occ(i).gt.1.990d0.and.eps(i).gt.othr)then
moci=moci+1
do j=1,nao
ca(j+(moci-1)*nao)=c(j+(i-1)*nao)
enddo
epsi(moci)=eps(i)
vecchk(i)=moci
endif
enddo
ihomo=moci
do i=1,nmo
if(occ(i).lt.0.010d0.and.eps(i).lt.vthr)then
moci=moci+1
do j=1,nao
ca(j+(moci-1)*nao)=c(j+(i-1)*nao)
enddo
epsi(moci)=eps(i)
vecchk(i)=moci
endif
enddo
else ! no eigenvectors needed
moci=0
do i=1,nmo
if(occ(i).gt.1.990d0.and.eps(i).gt.othr)then
moci=moci+1
do j=1,nao
ca(j+(moci-1)*nao)=c(j+(i-1)*nao)
enddo
epsi(moci)=eps(i)
endif
enddo
ihomo=moci
do i=1,nmo
if(occ(i).lt.0.010d0.and.eps(i).lt.vthr)then
moci=moci+1
do j=1,nao
ca(j+(moci-1)*nao)=c(j+(i-1)*nao)
enddo
epsi(moci)=eps(i)
endif
enddo
endif
no=ihomo
nv=moci-no
write(*,*)'oMOs in TDA: ', no
write(*,*)'vMOs in TDA: ', nv
if(no.eq.0.or.nv.eq.0) then
stop 'no CSF, increase energy threshold (-e option)'
endif
maxconf=no*nv
allocate(ed(maxconf),edpt(maxconf), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for ed and edpt'
allocate(iconf(maxconf,2), kconf(maxconf,2), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for iconf and kconf'
ed=0.0d0
edpt=0.0d0
iconf=0
kconf=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(moci,nao,c,epsi)
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,ca,nao,moci)
call shrink(moci,dum,xl)
close(31,status='delete')
open(unit=32,file='ylint',form='unformatted',status='old')
read(32) help
call onetri(1,help,dum,scr,ca,nao,moci)
call shrink(moci,dum,yl)
close(32,status='delete')
open(unit=33,file='zlint',form='unformatted',status='old')
read(33) help
call onetri(1,help,dum,scr,ca,nao,moci)
call shrink(moci,dum,zl)
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,ca,nao,moci)
call shrink(moci,dum,xm)
close(34,status='delete')
open(unit=35,file='ymint',form='unformatted',status='old')
read(35) help
call onetri(-1,help,dum,scr,ca,nao,moci)
call shrink(moci,dum,ym)
close(35,status='delete')
open(unit=36,file='zmint',form='unformatted',status='old')
read(36) help
call onetri(-1,help,dum,scr,ca,nao,moci)
call shrink(moci,dum,zm)
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,ca,nao,moci)
call shrink(moci,dum,xv)
close(37,status='delete')
open(unit=38,file='yvint',form='unformatted',status='old')
read(38) help
call onetri(-1,help,dum,scr,ca,nao,moci)
call shrink(moci,dum,yv)
close(38,status='delete')
open(unit=39,file='zvint',form='unformatted',status='old')
read(39) help
call onetri(-1,help,dum,scr,ca,nao,moci)
call shrink(moci,dum,zv)
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,moci,nao,1.d0,X,nao,CA,nao,0.d0,SCR,nao)
write(*,*) 'S^1/2 orthogonalized MO coefficients done.'
c check and copy to real*4 array
do i=1,moci
sss=0.0d0
do j=1,nao
sss=sss+scr(j+(i-1)*nao)**2
clow(j+(i-1)*nao)=scr(j+(i-1)*nao)
enddo
if(abs(sss-1.0d0).gt.1.d-2)then
write(*,*) 'MO norm ',i,sss
stop 'internal MO norm error'
endif
enddo
deallocate(scr,dum,help,x)
! call cpu_time(time)
c these are standard (CIS) factors for singlet
ak=2.0d0
if(triplet) ak=0.0d0
c open(unit=1,file='~/.param')
c read(1,*)beta1,beta2,alpha1,alpha2,fk
c close(1)
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 gamma's
call setrep(eta)
write(*,*) 'hardness table read.'
write(*,*) 'setting up gammas ...'
c distances for gamma calc
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=sqrt((xyz(1,i)-xyz(1,j))**2
. +(xyz(2,i)-xyz(2,j))**2
. +(xyz(3,i)-xyz(3,j))**2)
gamj(j,i)=1./(rabx**betaj+1./xj**betaj)**(1.0d0/betaj)
gamk(j,i)=1./(rabx**alphak+1./xk**alphak)**(1.0d0/alphak)
gamj(i,j)=gamj(j,i)
gamk(i,j)=gamk(j,i)
enddo
enddo
!
! write transition charges on disc
!
write(*,*)'write transition charges on disc'
open(unit=70,file='qii',form='unformatted',status='replace')
! open(unit=71,file='qij',form='unformatted',status='replace')
open(unit=710,file='pij',form='unformatted',status='replace')
allocate(q1(ncent),q2(ncent),qij(ncent,no*(no+1)/2))
q1=0.0
q2=0.0
Do i=1, no
Do j=1, i-1
call lo12pop(i,j,ncent,nao,iaoat,clow,q1)
! write(71)q1
qij(1:ncent,lin(i,j))=q1(1:ncent)
enddo
call lo12pop(i,i,ncent,nao,iaoat,clow,q1)
write(70)q1
qij(1:ncent,lin(i,i))=q1(1:ncent)
q2(1:ncent)=q2(1:ncent)+q1(1:ncent)
enddo
close(70)
! close(71)
allocate(pij(ncent,no*(no+1)/2))
call ssymm('l','l',ncent,no*(no+1)/2,1.0,gamj,ncent,qij,ncent,0.0
. ,pij,ncent)
deallocate(qij)
Do i=1, no*(no+1)/2
write(710)pij(1:ncent,i)
enddo
deallocate(pij)
close(710)
open(unit=72,file='qaa',form='unformatted',status='replace')
open(unit=73,file='qab',form='unformatted',status='replace')
Do i=no+1, moci
Do j=no+1, i-1
call lo12pop(i,j,ncent,nao,iaoat,clow,q1)
write(73)q1
enddo
call lo12pop(i,i,ncent,nao,iaoat,clow,q1)
write(72)q1
enddo
close(72)
close(73)
open(unit=74,file='qia',form='unformatted',status='replace')
open(unit=740,file='pia',form='unformatted',status='replace')
allocate(qia(ncent,no*nv))
Do i=1, no
Do j=no+1, moci
call lo12pop(i,j,ncent,nao,iaoat,clow,q1)
write(74)q1
ij=(i-1)*nv+j-no
qia(1:ncent,ij)=q1(1:ncent)
enddo
enddo
close(74)
allocate(pia(ncent,no*nv))
pia=0.0
call ssymm('l','l',ncent,no*nv,1.0,gamk,ncent,qia,ncent,0.0
. ,pia,ncent)
Do i=1, no*nv
write(740)pia(1:ncent,i)
enddo
close(740)
write(*,'(/'' SCF atom population (using active MOs):'')')
write(*,'(10F7.3)')q2(1:ncent)*2.0
write(*,*)
write(*,'('' # electrons in TDA:'',F8.3)') 2.0*sum(q2(1:ncent))
write(*,*)
open(unit=70,file='qii',form='unformatted',status='old')
open(unit=72,file='qaa',form='unformatted',status='old')
allocate(qij(ncent,no),qab(ncent,nv))
Do i=1, no
read(70)qij(1:ncent,i)
enddo
Do i=1, nv
read(72)qab(1:ncent,i)
enddo
close(70)
close(72)
allocate(pij(ncent,no), stat=ierr)
if(ierr.ne.0)stop 'allocation failed for (ii| intermediate'
pij=0.0
call ssymm('l','l',ncent,no,1.0,gamj,ncent,qij,ncent,0.0,pij
. ,ncent)
allocate(uci(nv,no), 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',nv,no,ncent,1.0,qab,ncent,pij,ncent,0.0,
. uci,nv)
deallocate(pij)
allocate(q3(1:ncent))
c DUAL parameter selection threshold
write(*,*)'***Dual thresholds Method***'
write(*,*)
open(unit=15,file='dual',form='formatted',status='old')
thresh(1)=thr*27.211385050d0
read(15,*)thresh(2)
read(15,*)num_atoms
allocate(atom_list(1:num_atoms))
Do i=1,num_atoms
read(15,*)atom_list(i)
enddo
write(*,'(a,f6.2,a)') 'Atoms in the chromophore considered with
.a threshold of ',thresh(1),' eV'
write(*,*) atom_list(:)
write(*,'(a,f6.2,a)') 'The rest uses a threshold of ',
. thresh(2),' eV'
c Identify important occupied MOs for the atom list
allocate(mo_list(no))
n_MO=0
Do i=1,no
sum_mo=0.0
Do k=1,nprims
Do j=1,num_atoms
if(ipat(k)==atom_list(j))then
if(k==1.or.ipao(k)/=ipao(k-1))then
sum_mo=sum_mo+clow(ipao(k)+(i-1)*nao)**2.0
endif
endif
enddo
enddo
!write(*,*)i,sum_mo
if(sum_mo>0.1)then
mo_list(i)=.true.
n_MO(1)=n_MO(1)+1
else
mo_list(i)=.false.
n_MO(2)=n_MO(2)+1
endif
!write(*,*)mo_list(i)
enddo
deallocate(clow)
allocate(mocc_1(n_MO(1)),mocc_2(n_MO(2)))
j=1
k=1
Do i=1,no
if(mo_list(i)==.true.)then
mocc_1(j)=i
j=j+1
else
mocc_2(k)=i
k=k+1
endif
enddo
!write(*,*)mocc_1
!write(*,*)mocc_2
write(*,'(a,f6.2,a,i)')' num. of occ. MOs with a
. threshold of',thresh(1),' eV :',n_MO(1)
write(*,'(a,f6.2,a,i)')' num. of occ. MOs with a
. threshold of',thresh(2),' eV :',n_MO(2)
thresh=thresh/27.211385050d0
c determine singles which are lower than thr
k=0
j=0
!First threshold
write(*,*)' First threshold '
do io=1,n_MO(1) ! occ loop
q1(1:ncent)=qij(1:ncent,mocc_1(io)) !qii
do iv=no+1,moci ! virt loop
de=epsi(iv)-epsi(mocc_1(io))
q2(1:ncent)=qab(1:ncent,iv-no) !qaa
ej=dble(uci(iv-no,mocc_1(io)))
de=de-ej
i=nv*(mocc_1(io)-1)+iv-no
q2(1:ncent)=pia(1:ncent,i)
q3(1:ncent)=qia(1:ncent,i) !qia
ek=sdot(ncent,q2,1,q3,1)
de=de+ak*ek
! optional: perform K(ia,ia) dependent shift
if(dokshift) then
call kshift_to_ediag(de,ek)
endif
c the primary ones
if(de.le.thresh(1))then
k=k+1
iconf(k,1)=mocc_1(io)
iconf(k,2)=iv
ed(k)=de
endif
c for PT
if(de.gt.thresh(1).and.de.lt.fthr)then ! needs to be on if fthr is specified
j=j+1
kconf(j,1)=mocc_1(io)
kconf(j,2)=iv
edpt(j)=de
endif
enddo ! virt loop
enddo ! occ loop
nci=nex
nex=k
nexpt=j
write(*,*)
write(*,*)nex,'CSF included by energy with 1st threshold'
write(*,*)nexpt,'considered in PT2.'
!Second threshold
write(*,*)
write(*,*)' Second threshold '
write(*,*)
! Because MOs were included by the first threshold below vthr, we need to restrain this range
! for the lower threshold. Thus, fthr is limited now to a resonable value:
fthr=((1.+0.8*ax)*thresh(2))*2.0 ! The orbital energy window with the second threshold.
write(*,'(2x,a,f6.2,a)')'Limiting the range for PT2 to ',
.fthr*27.211385050d0,' eV'
do io=1,n_MO(2) ! occ loop
q1(1:ncent)=qij(1:ncent,mocc_2(io)) !qii
do iv=no+1,moci ! virt loop
de=epsi(iv)-epsi(mocc_2(io))
q2(1:ncent)=qab(1:ncent,iv-no) !qaa
ej=dble(uci(iv-no,mocc_2(io)))
de=de-ej
i=nv*(mocc_2(io)-1)+iv-no
q2(1:ncent)=pia(1:ncent,i)
q3(1:ncent)=qia(1:ncent,i) !qia
ek=sdot(ncent,q2,1,q3,1)
de=de+ak*ek
! optional: perform K(ia,ia) dependent shift
if(dokshift) then
call kshift_to_ediag(de,ek)
endif
c the primary ones
if(de.le.thresh(2))then
k=k+1
iconf(k,1)=mocc_2(io)
iconf(k,2)=iv
ed(k)=de
endif
c for PT
if(de.gt.thresh(2).and.de.lt.fthr)then ! needs to be on if fthr is specified
j=j+1
kconf(j,1)=mocc_2(io)
kconf(j,2)=iv
edpt(j)=de
endif
enddo ! virt loop
enddo ! occ loop
deallocate(qij,qab,qia,pia,uci)
nci=nex
nex=k
nexpt=j
write(*,*)
write(*,*)nex,'CSF included by energy with both thresholds.'
write(*,*)
write(*,*)nexpt,'considered in PT2.'
c errors and warning
if(nex.lt.1) stop 'no CSF, increase energy threshold (-e option)'
! if(nex.eq.maxconf)
! . stop 'primary CSF space exceeded. use -e option!'
! if(nexpt.eq.maxconf)
! . write(*,*)'CSF PT2 space exceeded. try -p option!'
c sort for E diag
do 141 ii = 2,nex
i = ii - 1
k = i
pp= ed(i)
do 121 j = ii, nex
if (ed(j) .ge. pp) go to 121
k = j
pp=ed(j)
121 continue
if (k .eq. i) go to 141
ed(k) = ed(i)
ed(i) = pp
do m=1,2
ihilf=iconf(i,m)
iconf(i,m)=iconf(k,m)
iconf(k,m)=ihilf
enddo
141 continue
c just printout
write(*,*)'ordered frontier orbitals'
write(*,*)' eV'
j=max(1,no-10)
do i=j,no
write(*,'(i4,F10.3,F8.1)') i,epsi(i)*27.21139
enddo
write(*,*)
j=min(moci,no+11)
do i=no+1,j
write(*,'(i4,F10.3,F8.1)') i,epsi(i)*27.21139
enddo
open(unit=70,file='qii',form='unformatted',status='old')
open(unit=72,file='qaa',form='unformatted',status='old')
open(unit=74,file='qia',form='unformatted',status='old')
allocate(qij(ncent,no),qab(ncent,nv),qia(ncent,no*nv))
Do i=1, no
read(70)qij(1:ncent,i)
enddo
Do i=1, nv
read(72)qab(1:ncent,i)
enddo
Do i=1, no
Do j=no+1, moci
ij=(i-1)*nv+j-no
read(74)qia(1:ncent,ij)
enddo
enddo
close(70,status='delete')
close(72)
close(74)
write(*,*)
write(*,*)' lowest CSF states'
write(*,*)' eV nm excitation i->a eV'
do i=1,min(nex,25)
io=iconf(i,1)
iv=iconf(i,2)
q1(1:ncent)=qij(1:ncent,io)
jii=integral(q1,q1,gamj,ncent)
k=iv-no
q2(1:ncent)=qab(1:ncent,k)
ej=integral(q1,q2,gamj,ncent)
jaa=integral(q2,q2,gamj,ncent)
l=nv*(io-1)+k
q1(1:ncent)=qia(1:ncent,l)
ek=integral(q1,q1,gamk,ncent)
! de is now the Kia shift
de=0
loc=ej/sqrt(jii*jaa) ! locality
if(dokshift) call kshift_to_ediag(de,ek)
write(*,14) i,27.211*ed(i),
. 1.d+7/(ed(i)*2.19474625d+5),iconf(i,1:2),
. 27.211*(epsi(iv)-epsi(io)),27.211*ej,27.211*ek,27.211*de,loc
enddo
deallocate(q1,q2,q3,qij,qab,qia)
14 format(i5,f6.2,f8.1, 5x,i4,' ->',i4,5x,'gap,J,K:',3f8.3,
. 3x,'Kshft:',f8.3,2x,'locality:',f6.3,E12.5)
! call cpu_time(hilf)
! write(*,*) 'time elapsed:',hilf-time
write(*,*)
write(*,*)'selecting CSF ...'
if(pt_off)then
deallocate(edpt,kconf)
nroot=nex
nci=nex
write(*,*)nci,'CSF in total.'
else
call ptselect_rw(nex,ncent,no,nv,nexpt,maxconf,iconf,kconf,
. ak,ax,ed,edpt,gamj,gamk,thrp,new,moci)
deallocate(edpt,kconf)
c nroot at this point is the number of primary CSF. The
c number of roots in the range 0-thr (as desired) is not
c known but will be determined by the diag routine.
nroot=nex
write(*,*)new,'CSF included by PT.'
nci=nex+new
write(*,*)nci,'CSF in total.'
endif
! call cpu_time(hilf)
! write(*,*) 'time elapsed:',hilf-time
if(rpachk) then
**************************
c Obtional RPA procedure *
**************************
write(*,*) 'sTD-DFT procedure...'
write(*,*) 'setting up A+B and A-B matrices'
c allocate A+B and A-B in packed form
allocate( apb(nci*(nci+1)/2),ambsqr(nci*(nci+1)/2),
. stat=ierr )
if(ierr.ne.0)stop 'allocation failed for A+B or A-B'
call rrpamat_rw(nci,ncent,no,nv,maxconf,iconf,ak,ax,ed,gamj
. ,gamk,apb,ambsqr,moci)
*****************************
c Linear Response functions *
*****************************
if(optrota)then
call cpu_time(start_time)
allocate( amb(nci*(nci+1)/2), stat=ierr )
if(ierr.ne.0)stop 'allocation failed for A-B'
open(unit=53,file='amb',form='unformatted',status='old')
read(53) amb
close(53,status='delete')
if(velo_OR==.false.)call optrot(nci,apb,amb,iconf,maxconf,
.xl,yl,zl,moci,no,nv,xm,ym,zm,xmolw)
if(velo_OR==.true.)call optrot_velo(nci,apb,amb,iconf,maxconf,
.xv,yv,zv,moci,no,nv,xm,ym,zm,xmolw)
call cpu_time(end_time)
print '("Opt. Rot. Time = ",f12.2," minutes.")'
. ,(end_time-start_time)/60.0
if(nto)then
nnto=num_freq
allocate(uci(nci,nnto))
write(*,*)
write(*,*)'====================================================
.=================='
write(*,*)' Welcome in print NROs
. program'
write(*,*)'====================================================
.=================='
write(*,*)
Do i=1,3
if(i==1)write(*,*)'X axis'
if(i==2)write(*,*)'Y axis'
if(i==3)write(*,*)'Z axis'
Do ii=1,nnto
write(dummy,'(i1,a,i0)')i,'-',ii
open(unit=14,file=dummy)
read(14,*)uci(:,ii)
close(14,status='delete')
enddo
call print_nto_resp_new(uci,ca,moci,nci,nnto,nao,iconf,maxconf,
.no,nv,i,xm,ym,zm,.true.)
enddo
endif
print '("sTD-DFT_dual Time = ",f12.2," minutes.")'
. ,(end_time-stda_time)/60.0
CALL EXIT(STATUS)
endif
if(resp) then
if(triplet) stop 'not available'
call cpu_time(start_time)
allocate( amb(nci*(nci+1)/2), stat=ierr )
if(ierr.ne.0)stop 'allocation failed for A-B'
open(unit=53,file='amb',form='unformatted',status='old')
read(53) amb
close(53,status='delete')
call lresp1(nci,apb,amb,iconf,maxconf,xl,yl,zl,moci,
. no,nv)
call cpu_time(end_time)
print '("Lresp Time = ",f12.2," minutes.")'
. ,(end_time-start_time)/60.0
! call lresp1_noinv(nci,apb,amb,iconf,maxconf,xl,yl,zl,moci,
! . no,nv)
!
! call cpu_time(end_time)
! print '("Lresp Time = ",f12.2," minutes.")'
! . ,(end_time-start_time)/60.0
print '("sTD-DFT-rw_dual Time = ",f12.2," minutes.")'
. ,(end_time-stda_time)/60.0
CALL EXIT(STATUS)
endif
if(aresp) then
if(triplet) stop 'not available'
call cpu_time(start_time)
allocate( amb(nci*(nci+1)/2), stat=ierr )
if(ierr.ne.0)stop 'allocation failed for A-B'
open(unit=53,file='amb',form='unformatted',status='old')
read(53) amb
close(53,status='delete')
call lresp(nci,apb,amb,iconf,maxconf,xl,yl,zl,moci,
. no,nv)
call cpu_time(end_time)
print '("Lresp Time = ",f12.2," minutes.")'
. ,(end_time-start_time)/60.0
if(nto)then
nnto=num_freq+1
allocate(uci(nci,nnto))
write(*,*)
write(*,*)'====================================================
.=================='
write(*,*)' Welcome in print NROs
. program'
write(*,*)'====================================================
.=================='
write(*,*)
Do i=1,3
if(i==1)write(*,*)'X axis'
if(i==2)write(*,*)'Y axis'
if(i==3)write(*,*)'Z axis'
Do ii=1,nnto
write(dummy,'(i1,a,i0)')i,'-',ii
open(unit=14,file=dummy)
read(14,*)uci(:,ii)
close(14,status='delete')
enddo
call print_nto_resp(uci,ca,moci,nci,nnto,nao,iconf,maxconf,no,nv,i
.,xl,yl,zl,.false.)
enddo
endif
! call lresp_noinv(nci,apb,amb,iconf,maxconf,xl,yl,zl,moci,
! . no,nv)
! call lresp_noinv1(nci,apb,amb,iconf,maxconf,xl,yl,zl,moci,
! . no,nv)
!
! call cpu_time(end_time)
! print '("Lresp Time = ",f12.2," minutes.")'
! . ,(end_time-start_time)/60.0
print '("sTD-DFT-rw_dual Time = ",f12.2," minutes.")'
. ,(end_time-stda_time)/60.0
CALL EXIT(STATUS)
endif
c big arrays not needed anymore
deallocate(ed)
! call prmat4(6,ambsqr,nci,0,'A-B^0.5')
************************************************************************************
! if eigenvectors in TM format wanted for GGAs, this is done here (not so nice)
************************************************************************************
ggavec=.false.
if (ax.eq.0.0d0.and.eigvec) then
open(unit=39,file='TmPvEcInFo',status='replace')
! print to temporary file
if(triplet) then
write(39,*) 1
else
write(39,*) 0
endif
write(39,*) nvec,nmo,jhomo
do i=1,nmo
write(39,*) vecchk(i)
enddo
do i=1,nci
write(39,*) iconf(i,1),iconf(i,2)
enddo
close(39)
ggavec=.true.
eigvec=.false.
endif
************************************************************************************
allocate( eci(nci) ,stat=ierr)
if(ierr.ne.0)stop 'allocation failed for eigenvalue vector'
allocate(hci(nci,nci),uci(nci,nci),stat=ierr)
if(ierr.ne.0)stop 'allocation failed for eigenvector matrix'
c call sRPA routine (solve RPA problem)
c uci is now X, hci is Y