Repository navigation
Expand file tree
/
Copy pathfunction.f90
More file actions
7648 lines (6962 loc) · 266 KB
/
Copy pathfunction.f90
File metadata and controls
7648 lines (6962 loc) · 266 KB
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 function ==========
! ======================================
module functions
use defvar
use libreta
implicit real*8 (a-h,o-z)
contains
!!-------- Calculate any supported real space function at a given point
real*8 function calcfuncall(ifunc,x,y,z)
integer ifunc
real*8 x,y,z
if (ifunc==1) then
if (allocated(b)) then
calcfuncall=fdens(x,y,z)
else
calcfuncall=calcprodens(x,y,z,0) !Use promolecular density
end if
else if (ifunc==2) then
calcfuncall=fgrad(x,y,z,'t')
else if (ifunc==3) then
calcfuncall=flapl(x,y,z,'t')
else if (ifunc==4) then
calcfuncall=fmo(x,y,z,iorbsel)
else if (ifunc==5) then
calcfuncall=fspindens(x,y,z,'s')
else if (ifunc==6) then
calcfuncall=Hamkin(x,y,z,0)
else if (ifunc==7) then
calcfuncall=lagkin(x,y,z,0)
else if (ifunc==8) then
calcfuncall=nucesp(x,y,z)
else if (ifunc==9) then
calcfuncall=ELF_LOL(x,y,z,"ELF")
else if (ifunc==10) then
calcfuncall=ELF_LOL(x,y,z,"LOL")
else if (ifunc==11) then
calcfuncall=infoentro(1,x,y,z)
else if (ifunc==12) then
calcfuncall=totesp(x,y,z)
else if (ifunc==13) then
calcfuncall=fgrad(x,y,z,'r')
else if (ifunc==14) then
calcfuncall=RDGprodens(x,y,z)
else if (ifunc==15) then
calcfuncall=signlambda2rho(x,y,z)
else if (ifunc==16) then
calcfuncall=signlambda2rho_prodens(x,y,z)
else if (ifunc==17) then
calcfuncall=pairfunc(refx,refy,refz,x,y,z)
else if (ifunc==18) then
calcfuncall=avglocion(x,y,z)
else if (ifunc==19) then
calcfuncall=srcfunc(x,y,z,srcfuncmode)
else if (ifunc==20) then
calcfuncall=edr(x,y,z)
else if (ifunc==21) then
calcfuncall=edrdmax(x,y,z)
else if (ifunc==22) then
calcfuncall=delta_g_promol(x,y,z)
else if (ifunc==23) then
calcfuncall=delta_g_Hirsh(x,y,z)
else if (ifunc==24) then
calcfuncall=IRIfunc(x,y,z)
else if (ifunc==25) then
calcfuncall=vdwpotfunc(x,y,z,1)
else if (ifunc==44) then
calcfuncall=forbdens(x,y,z,iorbsel)
else if (ifunc==100) then
calcfuncall=userfunc(x,y,z)
end if
end function
!!--------- User-defined function, the content is needed to be filled by users or selected by "iuserfunc" in settings.ini
real*8 function userfunc(x,y,z)
real*8 x,y,z,vec(3),mat(3,3)
userfunc=1D0 !Default value
select case(iuserfunc)
case (-10) !For test purpose
userfunc=fmo(x,y,z,13)*fmo(x,y,z,20)
case (-3) !The function value evaluated by cubic spline interpolation from cubmat
userfunc=splineintp3d(x,y,z,1)
case (-2) !Promolecular density
userfunc=calcprodens(x,y,z,0)
case (-1) !The function value evaluated by trilinear interpolation from cubmat
userfunc=linintp3d(x,y,z,1)
case (1) !Alpha density
userfunc=fspindens(x,y,z,'a')
case (2) !Beta density
userfunc=fspindens(x,y,z,'b')
case (3) !Integrand of electronic spatial extent <r^2>
userfunc=(x*x+y*y+z*z)*fdens(x,y,z)
case (4) !Weizsacker potential
userfunc=weizpot(x,y,z)
case (5) !Integrand of Weizsacker functional
userfunc=KED(x,y,z,4) !Equivalent to weizsacker(x,y,z)
case (6) !Radial distribution function (assume that density is sphericalized)
userfunc=4*pi*fdens(x,y,z)*(x*x+y*y+z*z)
case (7) !Local Temperature (Kelvin), PNAS,81,8028
tmp=fdens(x,y,z)
if (tmp>uservar) then
userfunc=2D0/3D0*lagkin(x,y,z,0)/tmp
else
userfunc=0
end if
case (8) !Average local electrostatic potential, useful in exhibiting atomic shell structure
userfunc=totesp(x,y,z)/fdens(x,y,z)
case (9) !Shape function
userfunc=fdens(x,y,z)/nelec
case (10) !Potential energy density, also known as virial field
userfunc=-Hamkin(x,y,z,0)-lagkin(x,y,z,0)
case (11) !Energy density
userfunc=-Hamkin(x,y,z,0)
case (-11) !Scaled energy density
userfunc=-Hamkin(x,y,z,0)*(virialratio-1)
case (12) !Local nuclear attraction potential energy
userfunc=-nucesp(x,y,z)*fdens(x,y,z)
case (13) !This quantity at bond critical point is useful to discriminate covalent bonding and closed-shell interaction
userfunc=lagkin(x,y,z,0)/fdens(x,y,z)
case (14) !Electrostatic potential from electrons
userfunc=eleesp(x,y,z)
case (15) !Bond metallicity
userfunc=fdens(x,y,z)/flapl(x,y,z,'t')
case (16) !Dimensionless bond metallicity
userfunc=36*(3*pi*pi)**(2D0/3D0)/5D0*fdens(x,y,z)**(5D0/3D0)/flapl(x,y,z,'t')
case (17) !Energy density per electron
userfunc=-Hamkin(x,y,z,0)/fdens(x,y,z)
case (18) !Region of Slow Electrons (RoSE), defined in Chem. Phys. Lett., 582, 144 (2013)
rho=fdens(x,y,z)
if (wfntype==0.or.wfntype==3) then !Closed-shell cases
Dh=2.871234000D0*rho**(5D0/3D0)
else if (wfntype==1.or.wfntype==2.or.wfntype==4) then !Open shell cases
rhospin=fspindens(x,y,z,'s') !rhospin=rhoa-rhob, rho=rhoa+rhob
rhoa=(rhospin+rho)/2D0
rhob=(rho-rhospin)/2D0
Dh=4.557799872D0*(rhoa**(5D0/3D0)+rhob**(5D0/3D0)) !kinetic energy of HEG
end if
G=Lagkin(x,y,z,0)
userfunc=(Dh-G)/(Dh+G)
case (19) !SEDD
userfunc=SEDD(x,y,z)
case (20) !DORI
userfunc=DORI(x,y,z)
case (21) !Integrand of X component of electric dipole moment
userfunc=-x*fdens(x,y,z)
case (22) !Integrand of Y component of electric dipole moment
userfunc=-y*fdens(x,y,z)
case (23) !Integrand of Z component of electric dipole moment
userfunc=-z*fdens(x,y,z)
case (24) !Approximate form of DFT linear response kernel for closed-shell
userfunc=linrespkernel(x,y,z)
case (25) !Magnitude of fluctuation of the electronic momentum
userfunc=fgrad(x,y,z,'t')/fdens(x,y,z)/2D0
case (26) !Thomas-Fermi kinetic energy density
userfunc=KED(x,y,z,3)
case (27) !Local electron affinity
userfunc=loceleaff(x,y,z)
case (-27) !Local electron attachment energy
userfunc=loceleatt(x,y,z)
case (28) !Local Mulliken electronegativity
userfunc=(avglocion(x,y,z)+loceleaff(x,y,z))/2
case (29) !Local hardness
userfunc=(avglocion(x,y,z)-loceleaff(x,y,z))/2
case (30) !Ellipticity of electron density
userfunc=densellip(x,y,z,1)
case (31) !eta index, Angew. Chem. Int. Ed., 53, 2766-2770 (2014)
userfunc=densellip(x,y,z,2)
case (32) !Modified eta index
userfunc=densellip(x,y,z,2)-1
case (33) !PAEM, potential acting on one electron in a molecule, defined by Zhongzhi Yang
userfunc=PAEM(x,y,z,1)
case (34) !The same as 33, but using DFT XC potential directly rather than evaluating the XC potential based on pair density
userfunc=PAEM(x,y,z,2)
case (35) !|V(r)|/G(r)
tmpval=lagkin(x,y,z,0)
userfunc=abs(-Hamkin(x,y,z,0)-tmpval)/tmpval
case (36) !On-top pair density, i.e. r1=r2 case of pair density. paircorrtype affects result
pairfunctypeold=pairfunctype
pairfunctype=12
userfunc=pairfunc(x,y,z,x,y,z)
pairfunctype=pairfunctypeold
case (37) !SCI
userfunc=ELF_LOL(x,y,z,"SCI")
case (38) !The angle between the second eigenvector of rho and the plane defined by option 4 of main function 1000
userfunc=Ang_rhoeigvec_ple(x,y,z,2)
case (39) !ESP without contribution of nuclues "iskipnuc"
userfunc=totespskip(x,y,z,iskipnuc)
case (40) !Steric energy density
userfunc=weizsacker(x,y,z)
case (41) !Steric potential
userfunc=stericpot(x,y,z)
case (42) !Steric charge
userfunc=stericcharge(x,y,z)
case (43) !The magnitude of steric force
userfunc=stericforce(x,y,z)
case (44) !Steric potential with damping function to a given constant value
userfunc=stericpot_damp(x,y,z)
case (45) !Steric force based on damped potential
userfunc=stericforce_damp(x,y,z)
case (46) !Steric force directly damped to zero
userfunc=stericforce_directdamp(x,y,z)
case (47) !Steric charge directly damped to zero
userfunc=stericcharge_directdamp(x,y,z)
case (49) !Relative Shannon entropy, also called information gain
userfunc=relShannon(x,y,z)
case (50) !Shannon entropy density, see JCP,126,191107 for example
userfunc=infoentro(2,x,y,z)
case (51) !Fisher information density, see JCP,126,191107 for example
userfunc=Fisherinfo(1,x,y,z)
case (52) !Second Fisher information density, see JCP,126,191107 for derivation
userfunc=Fisherinfo(2,x,y,z)
case (53) !Ghosh entropy density with G(r) as kinetic energy density, PNAS,81,8028
userfunc=Ghoshentro(x,y,z,1)
case (54) !Ghosh entropy density with G(r)-der2rho/8 as kinetic energy density, exactly corresponds to Eq.22 in PNAS,81,8028
userfunc=Ghoshentro(x,y,z,2)
case (55) !Integrand of quadratic form of Renyi entropy
userfunc=fdens(x,y,z)**2
case (56) !Integrand of cubic form of Renyi entropy
userfunc=fdens(x,y,z)**3
case (60) !Pauli potential, Comp. Theor. Chem., 1006, 92-99
userfunc=paulipot(x,y,z)
case (61) !Magnitude of Pauli force
userfunc=pauliforce(x,y,z)
case (62) !Pauli charge
userfunc=paulicharge(x,y,z)
case (63) !Quantum potential
userfunc=quantumpot(x,y,z)
case (64) !The magnitude of quantum force
userfunc=quantumforce(x,y,z)
case (65) !Quantum charge
userfunc=quantumcharge(x,y,z)
case (66) !The magnitude of electrostatic force
userfunc=elestatforce(x,y,z)
case (67) !Electrostatic charge
userfunc=elestatcharge(x,y,z)
case (68) !Energy density of electronic part of electrostatic term (Ee) of SBL's energy decomposition
userfunc=-fdens(x,y,z)*totesp(x,y,z)
case (69) !Energy density of quantum term (Eq) of SBL's energy decomposition using Hamiltonian kinetic energy
userfunc=Hamkin(x,y,z,0)-weizsacker(x,y,z)+DFTxcfunc(x,y,z)
case (-69) !Energy density of quantum term (Eq) of SBL's energy decomposition using Lagrangian kinetic energy
userfunc=Lagkin(x,y,z,0)-weizsacker(x,y,z)+DFTxcfunc(x,y,z)
case (70) !Phase-space-defined Fisher information density
userfunc=4.5D0*fdens(x,y,z)**2/lagkin(x,y,z,0)
case (71) !X component of electron linear momentum density in 3D representation
userfunc=elemomdens(x,y,z,1)
case (72) !Y component of electron linear momentum density in 3D representation
userfunc=elemomdens(x,y,z,2)
case (73) !Z component of electron linear momentum density in 3D representation
userfunc=elemomdens(x,y,z,3)
case (74) !Magnitude of electron linear momentum density in 3D representation
userfunc=elemomdens(x,y,z,0)
case (75) !X component of magnetic dipole moment density
userfunc=magmomdens(x,y,z,1)
case (76) !Y component of magnetic dipole moment density
userfunc=magmomdens(x,y,z,2)
case (77) !Z component of magnetic dipole moment density
userfunc=magmomdens(x,y,z,3)
case (78) !Magnitude of magnetic dipole moment density
userfunc=magmomdens(x,y,z,0)
case (79) !Gradient norm of energy density
userfunc=energydens_grdn(x,y,z)
case (80) !Laplacian of energy density
userfunc=energydens_lapl(x,y,z)
case (81) !X component of Hamiltonian kinetic energy density
userfunc=hamkin(x,y,z,1)
case (82) !Y component of Hamiltonian kinetic energy density
userfunc=hamkin(x,y,z,2)
case (83) !Z component of Hamiltonian kinetic energy density
userfunc=hamkin(x,y,z,3)
case (84) !X component of Lagrangian kinetic energy density
userfunc=Lagkin(x,y,z,1)
case (85) !Y component of Lagrangian kinetic energy density
userfunc=Lagkin(x,y,z,2)
case (86) !Z component of Lagrangian kinetic energy density
userfunc=Lagkin(x,y,z,3)
case (87) !Local total electron correlation function
userfunc=localcorr(x,y,z,1)
case (88) !Local dynamic electron correlation function
userfunc=localcorr(x,y,z,2)
case (89) !Local nondynamic electron correlation function
userfunc=localcorr(x,y,z,3)
case (90) !Fractional occupation number weighted electron density (FOD)
userfunc=FODfunc(x,y,z)
case (91) !Delta-g_inter(Hirsh) defined in IGMH model
userfunc=delta_g_inter_Hirsh(x,y,z)
case (92) !vdW potential
userfunc=vdwpotfunc(x,y,z,1)
case (93) !Repulsion potential
userfunc=vdwpotfunc(x,y,z,2)
case (94) !Disperison potential
userfunc=vdwpotfunc(x,y,z,3)
case (95) !Orbital-weighted f+ Fukui function
userfunc=orbwei_Fukui(1,x,y,z)
case (96) !Orbital-weighted f- Fukui function
userfunc=orbwei_Fukui(2,x,y,z)
case (97) !Orbital-weighted f0 Fukui function
userfunc=orbwei_Fukui(3,x,y,z)
case (98) !Orbital-weighted dual descriptor
userfunc=orbwei_Fukui(4,x,y,z)
case (99) !Interaction region indicator (IRI)
userfunc=IRIfunc(x,y,z)
case (100) !Disequilibrium (also known as semi-similarity)
userfunc=fdens(x,y,z)**2
case (101) !Positive part of ESP
userfunc=totesp(x,y,z)
if (userfunc<0D0) userfunc=0D0
case (102) !Negative part of ESP
userfunc=totesp(x,y,z)
if (userfunc>0D0) userfunc=0D0
case (103) !Magnitude of electric field
call gencalchessmat(1,12,x,y,z,value,vec,mat) !Get gradient of ESP
userfunc=dsqrt(sum(vec**2))
case (110) !Total energy density of the energy components defined by SBL (steric + electrostatic + quantum)
!That is, userfunc(40) + userfunc(68) + userfunc(69)
!userfunc = weizsacker(x,y,z) - fdens(x,y,z)*totesp(x,y,z) + (Hamkin(x,y,z,0)-weizsacker(x,y,z)+DFTxcfunc(x,y,z)) !Original expression
userfunc = -fdens(x,y,z)*totesp(x,y,z) + Hamkin(x,y,z,0) + DFTxcfunc(x,y,z)
case (111) !Total potential of the energy components defined by SBL (steric + electrostatic + quantum)
userfunc = stericpot(x,y,z) - totesp(x,y,z) + quantumpot(x,y,z)
case (112) !Magnitude of total force of the energy components defined by SBL (steric + electrostatic + quantum)
!That is, vector sum of userfunc(43), userfunc(66), userfunc(64)
!userfunc= stericforce(x,y,z) + elestatforce(x,y,z) + quantumforce(x,y,z) !This is sum of magnitude, not what we want
userfunc = SBLallforce(x,y,z)
case (113) !Total charge of the energy components defined by SBL (steric + electrostatic + quantum)
!That is, userfunc(42) + userfunc(67) + userfunc(65)
userfunc = stericcharge(x,y,z) + elestatcharge(x,y,z) + quantumcharge(x,y,z)
case (114) !Pauli kinetic energy density
userfunc = KED(x,y,z,iKEDsel) - weizsacker(x,y,z)
case (115) !Stiffness
userfunc = densellip(x,y,z,3)
case (116) !Stress tensor stiffness
userfunc = stress_stiffness(x,y,z)
case (117) !Stress tensor polarizability
userfunc = 1D0/stress_stiffness(x,y,z)
case (118) !Stress tensor ellipticity
userfunc = stress_ellipticity(x,y,z)
case (200) !Random number of [0,1£©
call RANDOM_NUMBER(userfunc)
case (802:807)
userfunc=funcvalLSB(iuserfunc-800,x,y,z)
case (812:817)
userfunc=1/funcvalLSB(iuserfunc-810,x,y,z)
case (819) !Ultrastrong interaction (USI)
userfunc=flapl(x,y,z,'t')/fdens(x,y,z)**(5D0/3D0)
case (820) !Bonding and noncovalent interaction (BNI): (tau-t_w)/t_w
tmp=weizsacker(x,y,z)
userfunc=(lagkin(x,y,z,0)-tmp)/tmp
case (821) !rho^(4/3)/|der_rho|, for shubin
userfunc=fdens(x,y,z)**(4D0/3D0) / fgrad(x,y,z,'t')
case (900) !X coordinate
userfunc=x
case (901) !Y coordinate
userfunc=y
case (902) !Z coordinate
userfunc=z
case (910) !Hirshfeld atomic weighting function
call Hirshatmwei(nint(uservar),x,y,z,userfunc)
case (911) !Becke atomic weighting function using covr_tianlu
call Beckeatmwei(nint(uservar),x,y,z,userfunc,covr_tianlu,3)
case (912) !Becke atomic weighting function using CSD covalent radii
call Beckeatmwei(nint(uservar),x,y,z,userfunc,covr,3)
case (913) !LT1 atomic weighting function
call TLatmwei(nint(uservar),x,y,z,userfunc,1)
case (914) !LT1 atomic weighting function
call TLatmwei(nint(uservar),x,y,z,userfunc,2)
case (999) !Local Hartree-Fock exchange energy
userfunc=locHFexc(x,y,z)
case (1000) !Various kinds of DFT exchange-correlation functions
userfunc=DFTxcfunc(x,y,z)
case (1100) !Various kinds of DFT exchange-correlation potentials for closed-shell
userfunc=DFTxcpot(x,y,z,0)
case (1101) !Various kinds of DFT exchange-correlation potentials of alpha electrons for open-shell
userfunc=DFTxcpot(x,y,z,1)
case (1102) !Various kinds of DFT exchange-correlation potentials of beta electrons for open-shell
userfunc=DFTxcpot(x,y,z,2)
case (1200) !Various kinds of electronic kinetic energy density (KED)
userfunc=KED(x,y,z,iKEDsel)
case (1201) !Get difference between KED selected by iKEDsel and Weizsacker KED
userfunc=KEDdiff(x,y,z,iKEDsel,1)
case (1202) !Get difference between KED selected by iKEDsel and Lagrangian KED
userfunc=KEDdiff(x,y,z,iKEDsel,2)
case (1203) !Get absolute difference between KED selected by iKEDsel and Lagrangian KED
userfunc=KEDdiff(x,y,z,iKEDsel,3)
case (1204) !Local Temperature(Kelvin), PNAS,81,8028, but using user-defined KED by "iKEDsel"
tmp=fdens(x,y,z)
if (tmp>uservar) then
userfunc=2D0/3D0*KED(x,y,z,iKEDsel)/tmp
else
userfunc=0
end if
case (1210) !Potential of KED
userfunc=KEDpot(x,y,z)
case (1303) !\xi^\alpha Fractional integrals/derivatives, close to Lagkin, fdens routines
userfunc=fracderiv(x,y,z)
end select
if (iuserfunc>10000) then
userfunc=calcfuncall(iuserfunc-10000,x,y,z)
end if
!Below are other examples
! userfunc=hamkin(x,y,z,3)-0.5D0*(hamkin(x,y,z,1)+hamkin(x,y,z,2)) !Anisotropy of Hamiltonian kinetic energy in Z, namely K_Z-0.5*(K_X+K_Y)
! userfunc=-x*y*fdens(x,y,z) !Integrand of XY component of electric quadrupole moment
! userfunc=-x*y*z*fdens(x,y,z)*au2debye*b2a**2 !Integrand of XYZ component of electric octapole moment in Debye-Ang**2
end function
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! Calculate wavefunction value of a range of orbitals and their derivatives at a given point, up to third-order
!! istart and iend is the range of the orbitals will be calculated, to calculate all orbitals, use 1,nmo
!! runtype=1: value =2: value+dx/y/z =3: value+dxx/yy/zz (diagonal of hess) =4: value+dx/y/z+Hessian
!! =5: value+dx/y/z+hess+3-order derivative tensor
subroutine orbderv(runtype,istart,iend,x,y,z,wfnval,grad,hess,tens3)
real*8 x,y,z,wfnval(nmo)
real*8,optional :: grad(3,nmo),hess(3,3,nmo),tens3(3,3,3,nmo)
integer runtype,istart,iend
if (ifPBC>0) then !Consider PBC
call orbderv_PBC(runtype,istart,iend,x,y,z,wfnval,grad,hess,tens3)
return
end if
wfnval=0D0
if (present(grad)) grad=0D0
if (present(hess)) hess=0D0
if (present(tens3)) tens3=0D0
lastcen=-1 !Arbitrary value
!If the center/exp of current GTF is the same as previous, then we do not need to recalculate them
if (nprims_uniq==0) then !Unique GTF information is not available
do j=1,nprims
jcen=b(j)%center
if (jcen/=lastcen) then
sftx=x-a(jcen)%x
sfty=y-a(jcen)%y
sftz=z-a(jcen)%z
sftx2=sftx*sftx
sfty2=sfty*sfty
sftz2=sftz*sftz
rr=sftx2+sfty2+sftz2
end if
ep=b(j)%exp
tmpval=-ep*rr
lastcen=jcen
if (tmpval>expcutoff.or.expcutoff>0) then
expterm=exp(tmpval)
else
cycle
end if
!Calculate value for current GTF
jtype=b(j)%type
ix=type2ix(jtype)
iy=type2iy(jtype)
iz=type2iz(jtype)
if (jtype==1) then !Some functype use manually optimized formula for cutting down computational time
GTFval=expterm
else if (jtype==2) then
GTFval=sftx*expterm
else if (jtype==3) then
GTFval=sfty*expterm
else if (jtype==4) then
GTFval=sftz*expterm
else if (jtype==5) then
GTFval=sftx2*expterm
else if (jtype==6) then
GTFval=sfty2*expterm
else if (jtype==7) then
GTFval=sftz2*expterm
else if (jtype==8) then
GTFval=sftx*sfty*expterm
else if (jtype==9) then
GTFval=sftx*sftz*expterm
else if (jtype==10) then
GTFval=sfty*sftz*expterm
else !If above conditions are not satisfied (angular moment higher than f), the function will be calculated explicitly
GTFval=sftx**ix *sfty**iy *sftz**iz *expterm
end if
!Calculate orbital wavefunction value. This is bottle neck of cost of this function
do imo=istart,iend
wfnval(imo)=wfnval(imo)+CO(imo,j)*GTFval
end do
if (runtype>=2) then
!Calculate 1-order derivative for current GTF
tx=0D0
ty=0D0
tz=0D0
if (ix/=0) tx=ix*sftx**(ix-1)
if (iy/=0) ty=iy*sfty**(iy-1)
if (iz/=0) tz=iz*sftz**(iz-1)
GTFdx=sfty**iy *sftz**iz *expterm*(tx-2*ep*sftx**(ix+1))
GTFdy=sftx**ix *sftz**iz *expterm*(ty-2*ep*sfty**(iy+1))
GTFdz=sftx**ix *sfty**iy *expterm*(tz-2*ep*sftz**(iz+1))
!Calculate 1-order derivative for orbitals
do imo=istart,iend
grad(1,imo)=grad(1,imo)+CO(imo,j)*GTFdx
grad(2,imo)=grad(2,imo)+CO(imo,j)*GTFdy
grad(3,imo)=grad(3,imo)+CO(imo,j)*GTFdz
end do
if (runtype>=3) then
!Calculate 2-order derivative for current GTF
txx=0D0
tyy=0D0
tzz=0D0
if (ix>=2) txx=ix*(ix-1)*sftx**(ix-2)
if (iy>=2) tyy=iy*(iy-1)*sfty**(iy-2)
if (iz>=2) tzz=iz*(iz-1)*sftz**(iz-2)
GTFdxx=sfty**iy *sftz**iz *expterm*( txx + 2*ep*sftx**ix*(-2*ix+2*ep*sftx2-1) )
GTFdyy=sftx**ix *sftz**iz *expterm*( tyy + 2*ep*sfty**iy*(-2*iy+2*ep*sfty2-1) )
GTFdzz=sftx**ix *sfty**iy *expterm*( tzz + 2*ep*sftz**iz*(-2*iz+2*ep*sftz2-1) )
ttx=tx-2*ep*sftx**(ix+1)
tty=ty-2*ep*sfty**(iy+1)
ttz=tz-2*ep*sftz**(iz+1)
GTFdxy=sftz**iz *expterm*ttx*tty
GTFdyz=sftx**ix *expterm*tty*ttz
GTFdxz=sfty**iy *expterm*ttx*ttz
!Calculate diagonal Hessian elements for orbitals
do imo=istart,iend
hess(1,1,imo)=hess(1,1,imo)+CO(imo,j)*GTFdxx !dxx
hess(2,2,imo)=hess(2,2,imo)+CO(imo,j)*GTFdyy !dyy
hess(3,3,imo)=hess(3,3,imo)+CO(imo,j)*GTFdzz !dzz
end do
if (runtype>=4) then !Also process nondiagonal elements
do imo=istart,iend
hess(1,2,imo)=hess(1,2,imo)+CO(imo,j)*GTFdxy !dxy
hess(2,3,imo)=hess(2,3,imo)+CO(imo,j)*GTFdyz !dyz
hess(1,3,imo)=hess(1,3,imo)+CO(imo,j)*GTFdxz !dxz
end do
hess(2,1,:)=hess(1,2,:)
hess(3,2,:)=hess(2,3,:)
hess(3,1,:)=hess(1,3,:)
end if
if (runtype>=5) then
!Calculate 3-order derivative for current GTF
ep2=ep*2D0
ep4=ep*4D0
epep4=ep2*ep2
epep8=epep4*2D0
!dxyz
a1=0D0
b1=0D0
c1=0D0
if (ix>=1) a1=ix*sftx**(ix-1)
if (iy>=1) b1=iy*sfty**(iy-1)
if (iz>=1) c1=iz*sftz**(iz-1)
a2=-ep2*sftx**(ix+1)
b2=-ep2*sfty**(iy+1)
c2=-ep2*sftz**(iz+1)
GTFdxyz=(a1+a2)*(b1+b2)*(c1+c2)*expterm
!dxyy,dxxy,dxxz,dxzz,dyzz,dyyz
atmp=0D0
btmp=0D0
ctmp=0D0
if (ix>=2) atmp=ix*(ix-1)*sftx**(ix-2)
if (iy>=2) btmp=iy*(iy-1)*sfty**(iy-2)
if (iz>=2) ctmp=iz*(iz-1)*sftz**(iz-2)
GTFdxyy=(a1+a2)*sftz**iz *expterm*(-ep4*iy*sfty**iy+epep4*sfty**(iy+2)+btmp-ep2*sfty**iy)
GTFdxxy=(b1+b2)*sftz**iz *expterm*(-ep4*ix*sftx**ix+epep4*sftx**(ix+2)+atmp-ep2*sftx**ix) !=dyxx
GTFdxxz=(c1+c2)*sfty**iy *expterm*(-ep4*ix*sftx**ix+epep4*sftx**(ix+2)+atmp-ep2*sftx**ix) !=dzxx
GTFdxzz=(a1+a2)*sfty**iy *expterm*(-ep4*iz*sftz**iz+epep4*sftz**(iz+2)+ctmp-ep2*sftz**iz)
GTFdyzz=(b1+b2)*sftx**ix *expterm*(-ep4*iz*sftz**iz+epep4*sftz**(iz+2)+ctmp-ep2*sftz**iz)
GTFdyyz=(c1+c2)*sftx**ix *expterm*(-ep4*iy*sfty**iy+epep4*sfty**(iy+2)+btmp-ep2*sfty**iy) !=dzyy
!dxxx,dyyy,dzzz
aatmp1=0D0
bbtmp1=0D0
cctmp1=0D0
if (ix>=1) aatmp1=ep2*ix*sftx**(ix-1)
if (iy>=1) bbtmp1=ep2*iy*sfty**(iy-1)
if (iz>=1) cctmp1=ep2*iz*sftz**(iz-1)
aatmp2=0D0
bbtmp2=0D0
cctmp2=0D0
if (ix>=2) aatmp2=ep2*ix*(ix-1)*sftx**(ix-1)
if (iy>=2) bbtmp2=ep2*iy*(iy-1)*sfty**(iy-1)
if (iz>=2) cctmp2=ep2*iz*(iz-1)*sftz**(iz-1)
aatmp3=0D0
bbtmp3=0D0
cctmp3=0D0
if (ix>=3) aatmp3=ix*(ix-1)*(ix-2)*sftx**(ix-3)
if (iy>=3) bbtmp3=iy*(iy-1)*(iy-2)*sfty**(iy-3)
if (iz>=3) cctmp3=iz*(iz-1)*(iz-2)*sftz**(iz-3)
GTFdxxx=sfty**iy*sftz**iz*expterm*( (-2*ix+ep2*sftx2-1)*(-epep4*sftx**(ix+1) + aatmp1) - aatmp2 + epep8*sftx**(ix+1) + aatmp3 )
GTFdyyy=sftx**ix*sftz**iz*expterm*( (-2*iy+ep2*sfty2-1)*(-epep4*sfty**(iy+1) + bbtmp1) - bbtmp2 + epep8*sfty**(iy+1) + bbtmp3 )
GTFdzzz=sfty**iy*sftx**ix*expterm*( (-2*iz+ep2*sftz2-1)*(-epep4*sftz**(iz+1) + cctmp1) - cctmp2 + epep8*sftz**(iz+1) + cctmp3 )
!Calculate 3-order derivative tensor for orbital wavefunction
do imo=istart,iend
tens3(1,1,1,imo)=tens3(1,1,1,imo)+CO(imo,j)*GTFdxxx !dxxx
tens3(2,2,2,imo)=tens3(2,2,2,imo)+CO(imo,j)*GTFdyyy !dyyy
tens3(3,3,3,imo)=tens3(3,3,3,imo)+CO(imo,j)*GTFdzzz !dzzz
tens3(1,2,2,imo)=tens3(1,2,2,imo)+CO(imo,j)*GTFdxyy !dxyy
tens3(1,1,2,imo)=tens3(1,1,2,imo)+CO(imo,j)*GTFdxxy !dxxy
tens3(1,1,3,imo)=tens3(1,1,3,imo)+CO(imo,j)*GTFdxxz !dxxz
tens3(1,3,3,imo)=tens3(1,3,3,imo)+CO(imo,j)*GTFdxzz !dxzz
tens3(2,3,3,imo)=tens3(2,3,3,imo)+CO(imo,j)*GTFdyzz !dyzz
tens3(2,2,3,imo)=tens3(2,2,3,imo)+CO(imo,j)*GTFdyyz !dyyz
tens3(1,2,3,imo)=tens3(1,2,3,imo)+CO(imo,j)*GTFdxyz !dxyz
end do
tens3(1,2,1,:)=tens3(1,1,2,:) !dxyx=dxxy
tens3(1,3,1,:)=tens3(1,1,3,:) !dxzx=dxxz
tens3(1,3,2,:)=tens3(1,2,3,:) !dxzy=dxyz
tens3(2,1,1,:)=tens3(1,1,2,:) !dyxx=dxxy
tens3(2,1,2,:)=tens3(1,2,2,:) !dyxy=dxyy
tens3(2,1,3,:)=tens3(1,2,3,:) !dyxz=dxyz
tens3(2,2,1,:)=tens3(1,2,2,:) !dyyx=dxyy
tens3(2,3,1,:)=tens3(1,2,3,:) !dyzx=dxyz
tens3(2,3,2,:)=tens3(2,2,3,:) !dyzy=dyyz
tens3(3,1,1,:)=tens3(1,1,3,:) !dzxx=dxxz
tens3(3,1,2,:)=tens3(1,2,3,:) !dzxy=dxyz
tens3(3,1,3,:)=tens3(1,3,3,:) !dzxz=dxzz
tens3(3,2,1,:)=tens3(1,2,3,:) !dzyx=dxyz
tens3(3,2,2,:)=tens3(2,2,3,:) !dzyy=dyyz
tens3(3,2,3,:)=tens3(2,3,3,:) !dzyz=dyzz
tens3(3,3,1,:)=tens3(1,3,3,:) !dzzx=dxzz
tens3(3,3,2,:)=tens3(2,3,3,:) !dzzy=dyzz
end if !end runtype>=5
end if !end runtype>=3
end if !end runtype>=2
end do
else !Unique GTF information has been constructed by gen_GTFuniq
do j=1,nprims_uniq
jcen=b_uniq(j)%center
if (jcen/=lastcen) then
sftx=x-a(jcen)%x
sfty=y-a(jcen)%y
sftz=z-a(jcen)%z
sftx2=sftx*sftx
sfty2=sfty*sfty
sftz2=sftz*sftz
rr=sftx2+sfty2+sftz2
end if
ep=b_uniq(j)%exp
tmpval=-ep*rr
lastcen=jcen
if (tmpval>expcutoff.or.expcutoff>0) then
expterm=exp(tmpval)
else
cycle
end if
!Calculate value for current GTF
jtype=b_uniq(j)%type
ix=type2ix(jtype)
iy=type2iy(jtype)
iz=type2iz(jtype)
if (jtype==1) then !Some functype use manually optimized formula for cutting down computational time
GTFval=expterm
else if (jtype==2) then
GTFval=sftx*expterm
else if (jtype==3) then
GTFval=sfty*expterm
else if (jtype==4) then
GTFval=sftz*expterm
else if (jtype==5) then
GTFval=sftx2*expterm
else if (jtype==6) then
GTFval=sfty2*expterm
else if (jtype==7) then
GTFval=sftz2*expterm
else if (jtype==8) then
GTFval=sftx*sfty*expterm
else if (jtype==9) then
GTFval=sftx*sftz*expterm
else if (jtype==10) then
GTFval=sfty*sftz*expterm
else !If above conditions are not satisfied (angular moment higher than f), the function will be calculated explicitly
GTFval=sftx**ix *sfty**iy *sftz**iz *expterm
end if
!Calculate orbital wavefunction value. This is bottle neck of cost of this function
do imo=istart,iend
wfnval(imo)=wfnval(imo)+CO_uniq(imo,j)*GTFval
end do
if (runtype>=2) then
!Calculate 1-order derivative for current GTF
tx=0D0
ty=0D0
tz=0D0
if (ix/=0) tx=ix*sftx**(ix-1)
if (iy/=0) ty=iy*sfty**(iy-1)
if (iz/=0) tz=iz*sftz**(iz-1)
GTFdx=sfty**iy *sftz**iz *expterm*(tx-2*ep*sftx**(ix+1))
GTFdy=sftx**ix *sftz**iz *expterm*(ty-2*ep*sfty**(iy+1))
GTFdz=sftx**ix *sfty**iy *expterm*(tz-2*ep*sftz**(iz+1))
!Calculate 1-order derivative for orbitals
do imo=istart,iend
grad(1,imo)=grad(1,imo)+CO_uniq(imo,j)*GTFdx
grad(2,imo)=grad(2,imo)+CO_uniq(imo,j)*GTFdy
grad(3,imo)=grad(3,imo)+CO_uniq(imo,j)*GTFdz
end do
if (runtype>=3) then
!Calculate 2-order derivative for current GTF
txx=0D0
tyy=0D0
tzz=0D0
if (ix>=2) txx=ix*(ix-1)*sftx**(ix-2)
if (iy>=2) tyy=iy*(iy-1)*sfty**(iy-2)
if (iz>=2) tzz=iz*(iz-1)*sftz**(iz-2)
GTFdxx=sfty**iy *sftz**iz *expterm*( txx + 2*ep*sftx**ix*(-2*ix+2*ep*sftx2-1) )
GTFdyy=sftx**ix *sftz**iz *expterm*( tyy + 2*ep*sfty**iy*(-2*iy+2*ep*sfty2-1) )
GTFdzz=sftx**ix *sfty**iy *expterm*( tzz + 2*ep*sftz**iz*(-2*iz+2*ep*sftz2-1) )
ttx=tx-2*ep*sftx**(ix+1)
tty=ty-2*ep*sfty**(iy+1)
ttz=tz-2*ep*sftz**(iz+1)
GTFdxy=sftz**iz *expterm*ttx*tty
GTFdyz=sftx**ix *expterm*tty*ttz
GTFdxz=sfty**iy *expterm*ttx*ttz
!Calculate diagonal Hessian elements for orbitals
do imo=istart,iend
hess(1,1,imo)=hess(1,1,imo)+CO_uniq(imo,j)*GTFdxx !dxx
hess(2,2,imo)=hess(2,2,imo)+CO_uniq(imo,j)*GTFdyy !dyy
hess(3,3,imo)=hess(3,3,imo)+CO_uniq(imo,j)*GTFdzz !dzz
end do
if (runtype>=4) then !Also process nondiagonal elements
do imo=istart,iend
hess(1,2,imo)=hess(1,2,imo)+CO_uniq(imo,j)*GTFdxy !dxy
hess(2,3,imo)=hess(2,3,imo)+CO_uniq(imo,j)*GTFdyz !dyz
hess(1,3,imo)=hess(1,3,imo)+CO_uniq(imo,j)*GTFdxz !dxz
end do
hess(2,1,:)=hess(1,2,:)
hess(3,2,:)=hess(2,3,:)
hess(3,1,:)=hess(1,3,:)
end if
if (runtype>=5) then
!Calculate 3-order derivative for current GTF
ep2=ep*2D0
ep4=ep*4D0
epep4=ep2*ep2
epep8=epep4*2D0
!dxyz
a1=0D0
b1=0D0
c1=0D0
if (ix>=1) a1=ix*sftx**(ix-1)
if (iy>=1) b1=iy*sfty**(iy-1)
if (iz>=1) c1=iz*sftz**(iz-1)
a2=-ep2*sftx**(ix+1)
b2=-ep2*sfty**(iy+1)
c2=-ep2*sftz**(iz+1)
GTFdxyz=(a1+a2)*(b1+b2)*(c1+c2)*expterm
!dxyy,dxxy,dxxz,dxzz,dyzz,dyyz
atmp=0D0
btmp=0D0
ctmp=0D0
if (ix>=2) atmp=ix*(ix-1)*sftx**(ix-2)
if (iy>=2) btmp=iy*(iy-1)*sfty**(iy-2)
if (iz>=2) ctmp=iz*(iz-1)*sftz**(iz-2)
GTFdxyy=(a1+a2)*sftz**iz *expterm*(-ep4*iy*sfty**iy+epep4*sfty**(iy+2)+btmp-ep2*sfty**iy)
GTFdxxy=(b1+b2)*sftz**iz *expterm*(-ep4*ix*sftx**ix+epep4*sftx**(ix+2)+atmp-ep2*sftx**ix) !=dyxx
GTFdxxz=(c1+c2)*sfty**iy *expterm*(-ep4*ix*sftx**ix+epep4*sftx**(ix+2)+atmp-ep2*sftx**ix) !=dzxx
GTFdxzz=(a1+a2)*sfty**iy *expterm*(-ep4*iz*sftz**iz+epep4*sftz**(iz+2)+ctmp-ep2*sftz**iz)
GTFdyzz=(b1+b2)*sftx**ix *expterm*(-ep4*iz*sftz**iz+epep4*sftz**(iz+2)+ctmp-ep2*sftz**iz)
GTFdyyz=(c1+c2)*sftx**ix *expterm*(-ep4*iy*sfty**iy+epep4*sfty**(iy+2)+btmp-ep2*sfty**iy) !=dzyy
!dxxx,dyyy,dzzz
aatmp1=0D0
bbtmp1=0D0
cctmp1=0D0
if (ix>=1) aatmp1=ep2*ix*sftx**(ix-1)
if (iy>=1) bbtmp1=ep2*iy*sfty**(iy-1)
if (iz>=1) cctmp1=ep2*iz*sftz**(iz-1)
aatmp2=0D0
bbtmp2=0D0
cctmp2=0D0
if (ix>=2) aatmp2=ep2*ix*(ix-1)*sftx**(ix-1)
if (iy>=2) bbtmp2=ep2*iy*(iy-1)*sfty**(iy-1)
if (iz>=2) cctmp2=ep2*iz*(iz-1)*sftz**(iz-1)
aatmp3=0D0
bbtmp3=0D0
cctmp3=0D0
if (ix>=3) aatmp3=ix*(ix-1)*(ix-2)*sftx**(ix-3)
if (iy>=3) bbtmp3=iy*(iy-1)*(iy-2)*sfty**(iy-3)
if (iz>=3) cctmp3=iz*(iz-1)*(iz-2)*sftz**(iz-3)
GTFdxxx=sfty**iy*sftz**iz*expterm*( (-2*ix+ep2*sftx2-1)*(-epep4*sftx**(ix+1) + aatmp1) - aatmp2 + epep8*sftx**(ix+1) + aatmp3 )
GTFdyyy=sftx**ix*sftz**iz*expterm*( (-2*iy+ep2*sfty2-1)*(-epep4*sfty**(iy+1) + bbtmp1) - bbtmp2 + epep8*sfty**(iy+1) + bbtmp3 )
GTFdzzz=sfty**iy*sftx**ix*expterm*( (-2*iz+ep2*sftz2-1)*(-epep4*sftz**(iz+1) + cctmp1) - cctmp2 + epep8*sftz**(iz+1) + cctmp3 )
!Calculate 3-order derivative tensor for orbital wavefunction
do imo=istart,iend
tens3(1,1,1,imo)=tens3(1,1,1,imo)+CO_uniq(imo,j)*GTFdxxx !dxxx
tens3(2,2,2,imo)=tens3(2,2,2,imo)+CO_uniq(imo,j)*GTFdyyy !dyyy
tens3(3,3,3,imo)=tens3(3,3,3,imo)+CO_uniq(imo,j)*GTFdzzz !dzzz
tens3(1,2,2,imo)=tens3(1,2,2,imo)+CO_uniq(imo,j)*GTFdxyy !dxyy
tens3(1,1,2,imo)=tens3(1,1,2,imo)+CO_uniq(imo,j)*GTFdxxy !dxxy
tens3(1,1,3,imo)=tens3(1,1,3,imo)+CO_uniq(imo,j)*GTFdxxz !dxxz
tens3(1,3,3,imo)=tens3(1,3,3,imo)+CO_uniq(imo,j)*GTFdxzz !dxzz
tens3(2,3,3,imo)=tens3(2,3,3,imo)+CO_uniq(imo,j)*GTFdyzz !dyzz
tens3(2,2,3,imo)=tens3(2,2,3,imo)+CO_uniq(imo,j)*GTFdyyz !dyyz
tens3(1,2,3,imo)=tens3(1,2,3,imo)+CO_uniq(imo,j)*GTFdxyz !dxyz
end do
tens3(1,2,1,:)=tens3(1,1,2,:) !dxyx=dxxy
tens3(1,3,1,:)=tens3(1,1,3,:) !dxzx=dxxz
tens3(1,3,2,:)=tens3(1,2,3,:) !dxzy=dxyz
tens3(2,1,1,:)=tens3(1,1,2,:) !dyxx=dxxy
tens3(2,1,2,:)=tens3(1,2,2,:) !dyxy=dxyy
tens3(2,1,3,:)=tens3(1,2,3,:) !dyxz=dxyz
tens3(2,2,1,:)=tens3(1,2,2,:) !dyyx=dxyy
tens3(2,3,1,:)=tens3(1,2,3,:) !dyzx=dxyz
tens3(2,3,2,:)=tens3(2,2,3,:) !dyzy=dyyz
tens3(3,1,1,:)=tens3(1,1,3,:) !dzxx=dxxz
tens3(3,1,2,:)=tens3(1,2,3,:) !dzxy=dxyz
tens3(3,1,3,:)=tens3(1,3,3,:) !dzxz=dxzz
tens3(3,2,1,:)=tens3(1,2,3,:) !dzyx=dxyz
tens3(3,2,2,:)=tens3(2,2,3,:) !dzyy=dyyz
tens3(3,2,3,:)=tens3(2,3,3,:) !dzyz=dyzz
tens3(3,3,1,:)=tens3(1,3,3,:) !dzzx=dxzz
tens3(3,3,2,:)=tens3(2,3,3,:) !dzzy=dyzz
end if !end runtype>=5
end if !end runtype>=3
end if !end runtype>=2
end do
end if
end subroutine
!!--------- The same as orbderv, but explicitly consider PBC
!! Calculate wavefunction value of a range of orbitals and their derivatives at a given point, up to third-order
!! istart and iend is the range of the orbitals will be calculated, to calculate all orbitals, use 1,nmo
!! runtype=1: value =2: value+dx/y/z =3: value+dxx/yy/zz(diagonal of hess) =4: value+dx/y/z+Hessian
!! =5: value+dx/y/z+hess+3-order derivative tensor
!! k-point is taken into account if kp1crd,kp2crd,kp3crd has been properly defined (default to 0,0,0), in this case, &
!! itype_in=1: Returns real part =2: Returns imaginary part (e.g. 4.3i returns 4.3). If not explicitly defined, it is decided by global variable "iorbcomplex"
subroutine orbderv_PBC(runtype,istart,iend,x,y,z,wfnval,grad,hess,tens3,itype_in)
real*8 x,y,z,wfnval(nmo),tvec(3)
real*8,optional :: grad(3,nmo),hess(3,3,nmo),tens3(3,3,3,nmo)
integer runtype,istart,iend
integer,optional :: itype_in
wfnval=0D0
if (present(grad)) grad=0D0
if (present(hess)) hess=0D0
if (present(tens3)) tens3=0D0
if (present(itype_in)) then
itype=itype_in
else
itype=iorbcomplex
end if
iquick=0 !Check for this position if quick code can be used. If this position is out of region covered by reduced grid, the slow conventional code must be used
if (allocated(neighGTF)) then
ix_red=floor((x-orgx_neigh)/spcred)
iy_red=floor((y-orgy_neigh)/spcred)
iz_red=floor((z-orgz_neigh)/spcred)
if (ix_red>=0.and.ix_red<=size(neighnGTF,1)-1 .and. iy_red>=0.and.iy_red<=size(neighnGTF,2)-1 .and. iz_red>=0.and.iz_red<=size(neighnGTF,3)-1) iquick=1
end if
if (iquick==1) then !Utilizing neighbouring GTF list at reduced grids to significantly reduce number of candidate GTFs. Unique GTF cannot be utilized in this case
nloopGTF=neighnGTF(ix_red,iy_red,iz_red)
do iloopGTF=1,nloopGTF !Only loop the neighbouring GTFs corresponding to the reduced grid that the current position belongs to
j=neighGTF(iloopGTF,ix_red,iy_red,iz_red)
icell=neighGTFcell(1,iloopGTF,ix_red,iy_red,iz_red) !Obtaining the cell index that the neighbouring GTF attributed to
jcell=neighGTFcell(2,iloopGTF,ix_red,iy_red,iz_red)
kcell=neighGTFcell(3,iloopGTF,ix_red,iy_red,iz_red)
call tvec_PBC(icell,jcell,kcell,tvec)
if (itype==1) then !Real part of exponent term of wavefunction
fac=cos(2*pi*(icell*kp1crd+jcell*kp2crd+kcell*kp3crd))
else !Imaginary part of exponent term of wavefunction
fac=sin(2*pi*(icell*kp1crd+jcell*kp2crd+kcell*kp3crd))
end if
jcen=b(j)%center
sftx=x-(a(jcen)%x+tvec(1))
sfty=y-(a(jcen)%y+tvec(2))
sftz=z-(a(jcen)%z+tvec(3))
sftx2=sftx*sftx
sfty2=sfty*sfty
sftz2=sftz*sftz
rr=sftx2 + sfty2 + sftz2
ep=b(j)%exp
tmpval=-ep*rr
if (tmpval>expcutoff_PBC.or.expcutoff_PBC>0) then
expterm=exp(tmpval)*fac !!!! Exponent term of orbital wavefunction is merged into GTF exponent term to make it take effect properly without modifying any other codes
else
cycle
end if
!Calculate value for current GTF
jtype=b(j)%type
ix=type2ix(jtype)
iy=type2iy(jtype)
iz=type2iz(jtype)
if (jtype==1) then
GTFval=expterm
else if (jtype==2) then
GTFval=sftx*expterm
else if (jtype==3) then
GTFval=sfty*expterm
else if (jtype==4) then
GTFval=sftz*expterm
else if (jtype==5) then
GTFval=sftx2*expterm
else if (jtype==6) then
GTFval=sfty2*expterm
else if (jtype==7) then
GTFval=sftz2*expterm
else if (jtype==8) then
GTFval=sftx*sfty*expterm
else if (jtype==9) then
GTFval=sftx*sftz*expterm
else if (jtype==10) then
GTFval=sfty*sftz*expterm
else
GTFval=sftx**ix *sfty**iy *sftz**iz *expterm
end if
!Calculate orbital wavefunction value
do imo=istart,iend
wfnval(imo)=wfnval(imo)+CO(imo,j)*GTFval
end do
if (runtype>=2) then
!Calculate 1-order derivative for current GTF
tx=0D0
ty=0D0
tz=0D0
if (ix/=0) tx=ix*sftx**(ix-1)
if (iy/=0) ty=iy*sfty**(iy-1)
if (iz/=0) tz=iz*sftz**(iz-1)
GTFdx=sfty**iy *sftz**iz *expterm*(tx-2*ep*sftx**(ix+1))
GTFdy=sftx**ix *sftz**iz *expterm*(ty-2*ep*sfty**(iy+1))
GTFdz=sftx**ix *sfty**iy *expterm*(tz-2*ep*sftz**(iz+1))
!Calculate 1-order derivative for orbitals
do imo=istart,iend
grad(1,imo)=grad(1,imo)+CO(imo,j)*GTFdx
grad(2,imo)=grad(2,imo)+CO(imo,j)*GTFdy
grad(3,imo)=grad(3,imo)+CO(imo,j)*GTFdz
end do
if (runtype>=3) then
!Calculate 2-order derivative for current GTF
txx=0D0
tyy=0D0
tzz=0D0
if (ix>=2) txx=ix*(ix-1)*sftx**(ix-2)
if (iy>=2) tyy=iy*(iy-1)*sfty**(iy-2)
if (iz>=2) tzz=iz*(iz-1)*sftz**(iz-2)
GTFdxx=sfty**iy *sftz**iz *expterm*( txx + 2*ep*sftx**ix*(-2*ix+2*ep*sftx2-1) )
GTFdyy=sftx**ix *sftz**iz *expterm*( tyy + 2*ep*sfty**iy*(-2*iy+2*ep*sfty2-1) )
GTFdzz=sftx**ix *sfty**iy *expterm*( tzz + 2*ep*sftz**iz*(-2*iz+2*ep*sftz2-1) )
ttx=tx-2*ep*sftx**(ix+1)
tty=ty-2*ep*sfty**(iy+1)
ttz=tz-2*ep*sftz**(iz+1)
GTFdxy=sftz**iz *expterm*ttx*tty
GTFdyz=sftx**ix *expterm*tty*ttz
GTFdxz=sfty**iy *expterm*ttx*ttz
!Calculate diagonal Hessian elements for orbitals
do imo=istart,iend
hess(1,1,imo)=hess(1,1,imo)+CO(imo,j)*GTFdxx !dxx
hess(2,2,imo)=hess(2,2,imo)+CO(imo,j)*GTFdyy !dyy
hess(3,3,imo)=hess(3,3,imo)+CO(imo,j)*GTFdzz !dzz
end do
if (runtype>=4) then !Also process nondiagonal elements
do imo=istart,iend
hess(1,2,imo)=hess(1,2,imo)+CO(imo,j)*GTFdxy !dxy
hess(2,3,imo)=hess(2,3,imo)+CO(imo,j)*GTFdyz !dyz
hess(1,3,imo)=hess(1,3,imo)+CO(imo,j)*GTFdxz !dxz
end do
hess(2,1,:)=hess(1,2,:)
hess(3,2,:)=hess(2,3,:)
hess(3,1,:)=hess(1,3,:)
end if
if (runtype>=5) then
!Calculate 3-order derivative for current GTF
ep2=ep*2D0
ep4=ep*4D0
epep4=ep2*ep2
epep8=epep4*2D0
!dxyz
a1=0D0
b1=0D0
c1=0D0
if (ix>=1) a1=ix*sftx**(ix-1)
if (iy>=1) b1=iy*sfty**(iy-1)
if (iz>=1) c1=iz*sftz**(iz-1)
a2=-ep2*sftx**(ix+1)
b2=-ep2*sfty**(iy+1)
c2=-ep2*sftz**(iz+1)
GTFdxyz=(a1+a2)*(b1+b2)*(c1+c2)*expterm
!dxyy,dxxy,dxxz,dxzz,dyzz,dyyz
atmp=0D0