forked from sanshar/Dice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSHCIgetdeterminants.cpp
1047 lines (913 loc) · 40.3 KB
/
SHCIgetdeterminants.cpp
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
/*
Developed by Sandeep Sharma with contributions from James E. T. Smith and Adam A. Holmes, 2017
Copyright (c) 2017, Sandeep Sharma
This file is part of DICE.
This program is free software: you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation,
either version 3 of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License along with this program.
If not, see <http://www.gnu.org/licenses/>.
*/
#include "Determinants.h"
#include "SHCIgetdeterminants.h"
#include "input.h"
#include "integral.h"
#include <vector>
#include "math.h"
#include "Hmult.h"
#include <tuple>
#include <map>
#include "Davidson.h"
#include "boost/format.hpp"
#include <fstream>
#include "OccRestrictions.h"
using namespace std;
using namespace Eigen;
using namespace boost;
//=============================================================================
void SHCIgetdeterminants::getDeterminantsDeterministicPT(
Determinant& d, double epsilon, CItype ci1, CItype ci2,
oneInt& int1, twoInt& int2, twoIntHeatBathSHM& I2hb,
vector<int>& irreps, double coreE, double E0,
std::vector<Determinant>& dets, std::vector<CItype>& numerator, std::vector<double>& energy,
schedule& schd, int Nmc, int nelec) {
//-----------------------------------------------------------------------------
/*!
BM_description
:Inputs:
Determinant& d:
The reference |D_i>
double epsilon:
The criterion for chosing new determinants (understood as epsilon/c_i)
CItype ci1:
The reference CI coefficient c_i
CItype ci2:
The reference CI coefficient c_i (unused)
oneInt& int1:
One-electron tensor of the Hamiltonian
twoInt& int2:
Two-electron tensor of the Hamiltonian
twoIntHeatBathSHM& I2hb:
The sorted two-electron integrals to choose the bi-excited determinants
vector<int>& irreps:
Irrep of the orbitals
double coreE:
The core energy
double E0:
The current variational energy
std::vector<Determinant>& dets:
The determinants' determinant
std::vector<CItype>& numerator:
The determinants' numerator
std::vector<double>& energy:
The determinants' energy
schedule& schd:
The schedule
int Nmc:
BM_description
int nelec:
Number of electrons
*/
//-----------------------------------------------------------------------------
// initialize variables
int norbs = d.norbs;
int nclosed = nelec;
int nopen = norbs-nclosed;
vector<int> closed(nelec,0);
vector<int> open(norbs-nelec,0);
d.getOpenClosed(open, closed);
//d.getRepArray(detArray);
double Energyd = d.Energy(int1, int2, coreE);
initiateRestrictions(schd.restrictionsPT, closed);
// mono-excited determinants
for (int ia=0; ia<nopen*nclosed; ia++){
int i=ia/nopen, a=ia%nopen;
if (! satisfiesRestrictions(schd.restrictionsPT, closed[i], open[a])) continue;
//CItype integral = d.Hij_1Excite(closed[i],open[a],int1,int2);
CItype integral = Hij_1Excite(open[a],closed[i],int1,int2, &closed[0], nclosed);
// sgn
if (closed[i]%2 != open[a]%2) {
double sgn = 1.0;
d.parity(min(open[a],closed[i]), max(open[a],closed[i]),sgn);
integral = int1(open[a], closed[i])*sgn;
}
// generate determinant if integral is above the criterion
if (fabs(integral) > epsilon ) {
dets.push_back(d);
Determinant& di = *dets.rbegin();
di.setocc(open[a], true); di.setocc(closed[i],false);
// numerator and energy
numerator.push_back(integral*ci1);
#ifndef Complex
double E = EnergyAfterExcitation(closed, nclosed, int1, int2, coreE, i, open[a], Energyd);
#else
double E = di.Energy(int1, int2, coreE);
#endif
energy.push_back(E);
}
} // ia
// bi-excitated determinants
//#pragma omp parallel for schedule(dynamic)
if (fabs(int2.maxEntry) < epsilon) return;
// for all pairs of closed
for (int ij=0; ij<nclosed*nclosed; ij++) {
int i=ij/nclosed, j = ij%nclosed;
if (i<=j) continue;
int I = closed[i]/2, J = closed[j]/2;
int X = max(I, J), Y = min(I, J);
int pairIndex = X*(X+1)/2+Y;
size_t start = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex] : I2hb.startingIndicesOppositeSpin[pairIndex];
size_t end = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex+1] : I2hb.startingIndicesOppositeSpin[pairIndex+1];
float* integrals = closed[i]%2==closed[j]%2 ? I2hb.sameSpinIntegrals : I2hb.oppositeSpinIntegrals;
short* orbIndices = closed[i]%2==closed[j]%2 ? I2hb.sameSpinPairs : I2hb.oppositeSpinPairs;
// for all HCI integrals
for (size_t index=start; index<end; index++) {
// if we are going below the criterion, break
if (fabs(integrals[index]) < epsilon) break;
// otherwise: generate the determinant corresponding to the current excitation
int a = 2* orbIndices[2*index] + closed[i]%2, b= 2*orbIndices[2*index+1]+closed[j]%2;
if (! satisfiesRestrictions(schd.restrictionsPT, closed[i], closed[j], a, b)) continue;
if (!(d.getocc(a) || d.getocc(b))) {
dets.push_back(d);
Determinant& di = *dets.rbegin();
di.setocc(a, true), di.setocc(b, true), di.setocc(closed[i],false), di.setocc(closed[j], false);
// sgn
double sgn = 1.0;
di.parity(a, b, closed[i], closed[j], sgn);
// numerator and energy
numerator.push_back(integrals[index]*sgn*ci1);
double E = EnergyAfterExcitation(closed, nclosed, int1, int2, coreE, i, a, j, b, Energyd);
energy.push_back(E);
}
} // heatbath integrals
} // ij
return;
} // end SHCIgetdeterminants::getDeterminantsDeterministicPT
//=============================================================================
void SHCIgetdeterminants::getDeterminantsDeterministicPTKeepRefDets(
Determinant det, int det_ind, double epsilon, CItype ci,
oneInt& int1, twoInt& int2, twoIntHeatBathSHM& I2hb,
vector<int>& irreps, double coreE, double E0,
std::vector<Determinant>& dets, std::vector<CItype>& numerator, std::vector<double>& energy,
std::vector<int>& var_indices, std::vector<size_t>& orbDifference, schedule& schd, int nelec) {
//-----------------------------------------------------------------------------
/*!
Similar to SHCIgetdeterminants::getDeterminantsDeterministicPT,
but also keeps track of the reference dets each connected det came from
:Inputs:
Determinant det:
The reference |D_i>
int det_ind:
BM_description
double epsilon:
The criterion for chosing new determinants (understood as epsilon/c_i)
CItype ci:
The reference CI coefficient c_i
oneInt& int1:
One-electron tensor of the Hamiltonian
twoInt& int2:
Two-electron tensor of the Hamiltonian
twoIntHeatBathSHM& I2hb:
The sorted two-electron integrals to choose the bi-excited determinants
vector<int>& irreps:
Irrep of the orbitals
double coreE:
The core energy
double E0:
The current variational energy
std::vector<Determinant>& dets:
The determinants' determinant
std::vector<CItype>& numerator:
The determinants' numerator
std::vector<double>& energy:
The determinants' energy
std::vector<int>& var_indices:
BM_description
std::vector<size_t>& orbDifference:
The determinants' orbital differences
schedule& schd:
The schedule
int nelec:
Number of electrons
*/
//-----------------------------------------------------------------------------
// initialize variables
int norbs = det.norbs;
int nclosed = nelec;
int nopen = norbs-nclosed;
vector<int> closed(nelec,0);
vector<int> open(norbs-nelec,0);
det.getOpenClosed(open, closed);
//d.getRepArray(detArray);
double Energyd = det.Energy(int1, int2, coreE);
size_t orbDiff;
std::vector<int> var_indices_vec;
std::vector<size_t> orbDiff_vec;
initiateRestrictions(schd.restrictionsPT, closed);
// mono-excited determinants
for (int ia=0; ia<nopen*nclosed; ia++){
int i=ia/nopen, a=ia%nopen;
if (! satisfiesRestrictions(schd.restrictionsPT, closed[i], open[a])) continue;
if (irreps[closed[i]/2] != irreps[open[a]/2]) continue;
CItype integral = Hij_1Excite(open[a],closed[i],int1,int2, &closed[0], nclosed);
// generate determinant if integral is above the criterion
if (fabs(integral) > epsilon ) {
dets.push_back(det);
Determinant& di = *dets.rbegin();
di.setocc(open[a], true); di.setocc(closed[i],false);
// numerator and energy
numerator.push_back(integral*ci);
double E = EnergyAfterExcitation(closed, nclosed, int1, int2, coreE, i, open[a], Energyd);
energy.push_back(E);
// ...
var_indices.push_back(det_ind);
size_t A = open[a], N= norbs, I = closed[i];
orbDiff = A*N+I; // a = creation, i = annihilation
orbDifference.push_back(orbDiff);
}
} // ia
// bi-excitated determinants
//#pragma omp parallel for schedule(dynamic)
if (fabs(int2.maxEntry) < epsilon) return;
// for all pairs of closed
for (int ij=0; ij<nclosed*nclosed; ij++) {
int i=ij/nclosed, j = ij%nclosed;
if (i<=j) continue;
int I = closed[i]/2, J = closed[j]/2;
int X = max(I, J), Y = min(I, J);
int pairIndex = X*(X+1)/2+Y;
size_t start = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex] : I2hb.startingIndicesOppositeSpin[pairIndex];
size_t end = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex+1] : I2hb.startingIndicesOppositeSpin[pairIndex+1];
float* integrals = closed[i]%2==closed[j]%2 ? I2hb.sameSpinIntegrals : I2hb.oppositeSpinIntegrals;
short* orbIndices = closed[i]%2==closed[j]%2 ? I2hb.sameSpinPairs : I2hb.oppositeSpinPairs;
// for all HCI integrals
for (size_t index=start; index<end; index++) {
// if we are going below the criterion, break
if (fabs(integrals[index]) < epsilon) break;
// otherwise: generate the determinant corresponding to the current excitation
int a = 2* orbIndices[2*index] + closed[i]%2, b= 2*orbIndices[2*index+1]+closed[j]%2;
if (! satisfiesRestrictions(schd.restrictionsPT, closed[i], closed[j], a, b)) continue;
if (!(det.getocc(a) || det.getocc(b))) {
dets.push_back(det);
Determinant& di = *dets.rbegin();
di.setocc(a, true), di.setocc(b, true), di.setocc(closed[i],false), di.setocc(closed[j], false);
// sgn
double sgn = 1.0;
di.parity(a, b, closed[i], closed[j], sgn);
// numerator and energy
numerator.push_back(integrals[index]*sgn*ci);
double E = EnergyAfterExcitation(closed, nclosed, int1, int2, coreE, i, a, j, b, Energyd);
energy.push_back(E);
// ...
var_indices.push_back(det_ind);
size_t A = a, B = b, N= norbs, I = closed[i], J = closed[j];
orbDiff = A*N*N*N+I*N*N+B*N+J; //i>j and a>b??
orbDifference.push_back(orbDiff);
}
} // heatbath integrals
} // ij
return;
} // end SHCIgetdeterminants::getDeterminantsDeterministicPTKeepRefDets
//=============================================================================
void SHCIgetdeterminants::getDeterminantsDeterministicPTWithSOC(
Determinant det, int det_ind, double epsilon1, CItype ci1, double epsilon2, CItype ci2,
oneInt& int1, twoInt& int2, twoIntHeatBathSHM& I2hb,
vector<int>& irreps, double coreE,
std::vector<Determinant>& dets, std::vector<CItype>& numerator1, std::vector<CItype>& numerator2, std::vector<double>& energy,
schedule& schd, int nelec) {
//-----------------------------------------------------------------------------
/*!
Similar to SHCIgetdeterminants::getDeterminantsDeterministicPT,
but with SOC modifications
:Inputs:
Determinant det:
The reference |D_i>
int det_ind:
BM_description
double epsilon1:
The criterion for chosing new determinants (understood as epsilon/c_i)
CItype ci1:
The reference CI coefficient c_i
double epsilon2:
The criterion for chosing new determinants (understood as epsilon/c_i)
CItype ci2:
The reference CI coefficient c_i
oneInt& int1:
One-electron tensor of the Hamiltonian
twoInt& int2:
Two-electron tensor of the Hamiltonian
twoIntHeatBathSHM& I2hb:
The sorted two-electron integrals to choose the bi-excited determinants
vector<int>& irreps:
Irrep of the orbitals
double coreE:
The core energy
std::vector<Determinant>& dets:
The determinants' determinant
std::vector<CItype>& numerator1:
The determinants' numerator
std::vector<CItype>& numerator2:
The determinants' numerator
std::vector<double>& energy:
The determinants' energy
schedule& schd:
The schedule
int nelec:
Number of electrons
*/
//-----------------------------------------------------------------------------
// initialize variables
int norbs = det.norbs;
int nclosed = nelec;
int nopen = norbs-nclosed;
vector<int> closed(nelec,0);
vector<int> open(norbs-nelec,0);
det.getOpenClosed(open, closed);
double Energyd = det.Energy(int1, int2, coreE);
size_t orbDiff;
std::vector<int> var_indices_vec;
std::vector<size_t> orbDiff_vec;
initiateRestrictions(schd.restrictionsPT, closed);
// mono-excited determinants
for (int ia=0; ia<nopen*nclosed; ia++){
int i=ia/nopen, a=ia%nopen;
if (! satisfiesRestrictions(schd.restrictionsPT, closed[i], open[a])) continue;
CItype integral = Hij_1Excite(open[a],closed[i],int1,int2, &closed[0], nclosed);
// sgn
if (closed[i]%2 != open[a]%2) {
double sgn = 1.0;
det.parity(min(open[a],closed[i]), max(open[a],closed[i]),sgn);
integral = int1(open[a], closed[i])*sgn;
}
// generate determinant if integral is above the criterion
if (fabs(integral) > epsilon1 || fabs(integral) > epsilon2 ) {
dets.push_back(det);
Determinant& di = *dets.rbegin();
di.setocc(open[a], true); di.setocc(closed[i],false);
// numerator and energy
if(fabs(integral) > epsilon1) numerator1.push_back(integral*ci1);
else numerator1.push_back(0.0);
if(fabs(integral) > epsilon2) numerator2.push_back(integral*ci2);
else numerator2.push_back(0.0);
double E = EnergyAfterExcitation(closed, nclosed, int1, int2, coreE, i, open[a], Energyd);
//double E = Energyd - int1(closed[i], closed[i]) + int1(open[a],open[a]);
if (closed[i]%2 != open[a]%2) E = di.Energy(int1, int2, coreE);
energy.push_back(E);
}
} // ia
// bi-excitated determinants
//#pragma omp parallel for schedule(dynamic)
if (fabs(int2.maxEntry) < epsilon1 && fabs(int2.maxEntry) < epsilon2) return;
// for all pairs of closed
for (int ij=0; ij<nclosed*nclosed; ij++) {
int i=ij/nclosed, j = ij%nclosed;
if (i<=j) continue;
int I = closed[i]/2, J = closed[j]/2;
int X = max(I, J), Y = min(I, J);
int pairIndex = X*(X+1)/2+Y;
size_t start = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex] : I2hb.startingIndicesOppositeSpin[pairIndex];
size_t end = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex+1] : I2hb.startingIndicesOppositeSpin[pairIndex+1];
float* integrals = closed[i]%2==closed[j]%2 ? I2hb.sameSpinIntegrals : I2hb.oppositeSpinIntegrals;
short* orbIndices = closed[i]%2==closed[j]%2 ? I2hb.sameSpinPairs : I2hb.oppositeSpinPairs;
// for all HCI integrals
for (size_t index=start; index<end; index++) {
// if we are going below the criterion, break
if (fabs(integrals[index]) < epsilon1 && fabs(integrals[index]) < epsilon2) break;
// otherwise: generate the determinant corresponding to the current excitation
int a = 2* orbIndices[2*index] + closed[i]%2, b= 2*orbIndices[2*index+1]+closed[j]%2;
if (! satisfiesRestrictions(schd.restrictionsPT, closed[i], closed[j], a, b)) continue;
if (!(det.getocc(a) || det.getocc(b))) {
dets.push_back(det);
Determinant& di = *dets.rbegin();
di.setocc(a, true), di.setocc(b, true), di.setocc(closed[i],false), di.setocc(closed[j], false);
// sgn
double sgn = 1.0;
di.parity(a, b, closed[i], closed[j], sgn);
// numerator and energy
if(fabs(integrals[index]) > epsilon1) numerator1.push_back(integrals[index]*sgn*ci1);
else numerator1.push_back(0.0);
if(fabs(integrals[index]) > epsilon2) numerator2.push_back(integrals[index]*sgn*ci2);
else numerator2.push_back(0.0);
double E = EnergyAfterExcitation(closed, nclosed, int1, int2, coreE, i, a, j, b, Energyd);
energy.push_back(E);
}
} // heatbath integrals
} // ij
return;
} // end SHCIgetdeterminants::getDeterminantsDeterministicPTWithSOC
//=============================================================================
void SHCIgetdeterminants::getDeterminantsVariational(
Determinant& d, double epsilon, CItype ci1, CItype ci2,
oneInt& int1, twoInt& int2, twoIntHeatBathSHM& I2hb,
vector<int>& irreps, double coreE, double E0,
std::vector<Determinant>& dets,
schedule& schd, int Nmc, int nelec) {
//-----------------------------------------------------------------------------
/*!
Make the int represenation of open and closed orbitals of determinant
this helps to speed up the energy calculation
:Inputs:
Determinant& d:
The reference |D_i>
double epsilon:
The criterion for chosing new determinants (understood as epsilon/c_i)
CItype ci1:
The reference CI coefficient c_i
CItype ci2:
The reference CI coefficient c_i
oneInt& int1:
One-electron tensor of the Hamiltonian
twoInt& int2:
Two-electron tensor of the Hamiltonian
twoIntHeatBathSHM& I2hb:
The sorted two-electron integrals to choose the bi-excited determinants
vector<int>& irreps:
Irrep of the orbitals
double coreE:
The core energy
double E0:
The current variational energy
std::vector<Determinant>& dets:
The determinants' determinant
schedule& schd:
The schedule
int Nmc:
BM_description
int nelec:
Number of electrons
*/
//-----------------------------------------------------------------------------
// initialize variables
int norbs = d.norbs;
int nclosed = nelec;
int nopen = norbs-nclosed;
vector<int> closed(nelec,0);
vector<int> open(norbs-nelec,0);
d.getOpenClosed(open, closed);
initiateRestrictions(schd.restrictionsV, closed);
// mono-excited determinants
for (int ia=0; ia<nopen*nclosed; ia++){
int i=ia/nopen, a=ia%nopen;
if (closed[i]/2 < schd.ncore || open[a]/2 >= schd.ncore+schd.nact) continue;
if (! satisfiesRestrictions(schd.restrictionsV, closed[i], open[a])) continue;
//if we are doing SOC calculation then breaking spin and point group symmetry is allowed
#ifndef Complex
if (closed[i]%2 != open[a]%2 || irreps[closed[i]/2] != irreps[open[a]/2]) continue;
#endif
CItype integral = Hij_1Excite(open[a],closed[i],int1,int2, &closed[0], nclosed);
if (closed[i]%2 != open[a]%2) {
integral = int1(open[a], closed[i])*schd.socmultiplier;
}
// generate determinant if integral is above the criterion
if (fabs(integral) > epsilon ) {
dets.push_back(d);
Determinant& di = *dets.rbegin();
di.setocc(open[a], true); di.setocc(closed[i],false);
//if (Determinant::Trev != 0) di.makeStandard();
}
} // ia
// bi-excitated determinants
if (fabs(int2.maxEntry) < epsilon) return;
// for all pairs of closed
for (int ij=0; ij<nclosed*nclosed; ij++) {
int i=ij/nclosed, j = ij%nclosed;
if (i<=j) continue;
int I = closed[i]/2, J = closed[j]/2;
int X = max(I, J), Y = min(I, J);
if (closed[i]/2 < schd.ncore || closed[j]/2 < schd.ncore) continue;
int pairIndex = X*(X+1)/2+Y;
size_t start = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex] : I2hb.startingIndicesOppositeSpin[pairIndex];
size_t end = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex+1] : I2hb.startingIndicesOppositeSpin[pairIndex+1];
float* integrals = closed[i]%2==closed[j]%2 ? I2hb.sameSpinIntegrals : I2hb.oppositeSpinIntegrals;
short* orbIndices = closed[i]%2==closed[j]%2 ? I2hb.sameSpinPairs : I2hb.oppositeSpinPairs;
// for all HCI integrals
for (size_t index=start; index<end; index++) {
// if we are going below the criterion, break
if (fabs(integrals[index]) < epsilon) break;
// otherwise: generate the determinant corresponding to the current excitation
int a = 2* orbIndices[2*index] + closed[i]%2, b= 2*orbIndices[2*index+1]+closed[j]%2;
if (a/2 >= schd.ncore+schd.nact || b/2 >= schd.ncore+schd.nact) continue;
if (! satisfiesRestrictions(schd.restrictionsV, closed[i], closed[j], a, b)) continue;
if (!(d.getocc(a) || d.getocc(b))) {
dets.push_back(d);
Determinant& di = *dets.rbegin();
di.setocc(a, true), di.setocc(b, true), di.setocc(closed[i],false), di.setocc(closed[j], false);
//if (Determinant::Trev != 0) di.makeStandard();
}
} // heatbath integrals
} // ij
return;
} // end SHCIgetdeterminants::getDeterminantsVariational
//=============================================================================
void SHCIgetdeterminants::getDeterminantsVariationalApprox(
Determinant& d, double epsilon, CItype ci1, CItype ci2,
oneInt& int1, twoInt& int2, twoIntHeatBathSHM& I2hb,
vector<int>& irreps, double coreE, double E0,
std::vector<Determinant>& dets,
schedule& schd, int Nmc, int nelec,
Determinant* SortedDets, int SortedDetsSize) {
//-----------------------------------------------------------------------------
/*!
Make the int represenation of open and closed orbitals of determinant
this helps to speed up the energy calculation
:Inputs:
Determinant& d:
The reference |D_i>
double epsilon:
The criterion for chosing new determinants (understood as epsilon/c_i)
CItype ci1:
The reference CI coefficient c_i
CItype ci2:
The reference CI coefficient c_i
oneInt& int1:
One-electron tensor of the Hamiltonian
twoInt& int2:
Two-electron tensor of the Hamiltonian
twoIntHeatBathSHM& I2hb:
The sorted two-electron integrals to choose the bi-excited determinants
vector<int>& irreps:
Irrep of the orbitals
double coreE:
The core energy
double E0:
The current variational energy
std::vector<Determinant>& dets:
The determinants' determinant
schedule& schd:
The schedule
int Nmc:
BM_description
int nelec:
Number of electrons
Determinant* SortedDets:
The sorted list of determinants
int SortedDetsSize:
The number of unique determinants
*/
//-----------------------------------------------------------------------------
// initialize variables
int norbs = d.norbs;
int nclosed = nelec;
int nopen = norbs-nclosed;
vector<int> closed(nelec,0);
vector<int> open(norbs-nelec,0);
d.getOpenClosed(open, closed);
int unpairedElecs = schd.enforceSeniority ? d.numUnpairedElectrons() : 0;
initiateRestrictions(schd.restrictionsV, closed);
// mono-excited determinants
for (int ia=0; ia<nopen*nclosed; ia++){
int i=ia/nopen, a=ia%nopen;
if (closed[i]/2 < schd.ncore || open[a]/2 >= schd.ncore+schd.nact) continue;
if (! satisfiesRestrictions(schd.restrictionsV, closed[i], open[a])) continue;
CItype integral = I2hb.Singles(open[a], closed[i]);//Hij_1Excite(open[a],closed[i],int1,int2, &closed[0], nclosed);
if (fabs(integral) > epsilon)
if (closed[i]%2 == open[a]%2)
integral = Hij_1Excite(open[a],closed[i],int1,int2, &closed[0], nclosed);
// generate determinant if integral is above the criterion
//if (fabs(integral/(E0-Energyd)) > epsilon ) {
if (fabs(integral) > epsilon ) {
Determinant di = d;
di.setocc(open[a], true); di.setocc(closed[i],false);
////if (schd.enforceSeniority && di.numUnpairedElectrons() > schd.maxSeniority) continue;
//if (schd.enforceSenioExc){
// if (di.ExcitationDistance(schd.HF) > schd.maxExcitation &&
// di.numUnpairedElectrons() > schd.maxSeniority){
// continue;
// }
//} else if (schd.enforceExcitation && di.ExcitationDistance(schd.HF) > schd.maxExcitation){
// continue;
//} else if (schd.enforceSeniority && di.numUnpairedElectrons() > schd.maxSeniority) {
// continue;
//}
if (!binary_search(SortedDets, SortedDets+SortedDetsSize, di)) dets.push_back(di);
#ifdef Complex
Determinant detcpy = di;
detcpy.flipAlphaBeta();
if (!binary_search(SortedDets, SortedDets+SortedDetsSize, detcpy)) dets.push_back(detcpy);
#endif
}
} // ia
// bi-excitated determinants
if (fabs(int2.maxEntry) < epsilon) return;
// for all pairs of closed
for (int ij=0; ij<nclosed*nclosed; ij++) {
int i=ij/nclosed, j = ij%nclosed;
if (i<=j) continue;
int I = closed[i]/2, J = closed[j]/2;
int X = max(I, J), Y = min(I, J);
if (closed[i]/2 < schd.ncore || closed[j]/2 < schd.ncore) continue;
int pairIndex = X*(X+1)/2+Y;
size_t start = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex] : I2hb.startingIndicesOppositeSpin[pairIndex];
size_t end = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex+1] : I2hb.startingIndicesOppositeSpin[pairIndex+1];
float* integrals = closed[i]%2==closed[j]%2 ? I2hb.sameSpinIntegrals : I2hb.oppositeSpinIntegrals;
short* orbIndices = closed[i]%2==closed[j]%2 ? I2hb.sameSpinPairs : I2hb.oppositeSpinPairs;
// for all HCI integrals
for (size_t index=start; index<end; index++) {
// if we are going below the criterion, break
if (fabs(integrals[index]) < epsilon) break;
// otherwise: generate the determinant corresponding to the current excitation
int a = 2* orbIndices[2*index] + closed[i]%2, b= 2*orbIndices[2*index+1]+closed[j]%2;
//double E = EnergyAfterExcitation(closed, nclosed, int1, int2, coreE, i, a, j, b, Energyd);
//if (abs(integrals[index]/(E0-Energyd)) <epsilon) continue;
if (a/2 >= schd.ncore+schd.nact || b/2 >= schd.ncore+schd.nact) continue;
if (! satisfiesRestrictions(schd.restrictionsV, closed[i], closed[j], a, b)) continue;
if (!(d.getocc(a) || d.getocc(b))) {
Determinant di = d;
di.setocc(a, true); di.setocc(b, true);di.setocc(closed[i],false); di.setocc(closed[j], false);
////if (schd.enforceSeniority && di.numUnpairedElectrons() > schd.maxSeniority) continue;
//if (schd.enforceSenioExc){
// if (!(di.ExcitationDistance(schd.HF) <= schd.maxExcitation ||
// di.numUnpairedElectrons() <= schd.maxSeniority)) continue;
//} else if (schd.enforceExcitation && di.ExcitationDistance(schd.HF) > schd.maxExcitation){
// continue;
//} else if (schd.enforceSeniority && di.numUnpairedElectrons() > schd.maxSeniority) {
// continue;
//}
if (!binary_search(SortedDets, SortedDets+SortedDetsSize, di)) dets.push_back(di);
#ifdef Complex
Determinant detcpy = di;
detcpy.flipAlphaBeta();
if (!binary_search(SortedDets, SortedDets+SortedDetsSize, detcpy)) dets.push_back(detcpy);
#endif
//if (Determinant::Trev != 0) di.makeStandard();
}
} // heatbath integrals
} // ij
return;
} // end SHCIgetdeterminants::getDeterminantsVariationalApprox
//=============================================================================
void SHCIgetdeterminants::getDeterminantsStochastic(
Determinant& d, double epsilon, CItype ci1, CItype ci2,
oneInt& int1, twoInt& int2, twoIntHeatBathSHM& I2hb,
vector<int>& irreps, double coreE, double E0,
std::vector<Determinant>& dets, std::vector<CItype>& numerator1, vector<double>& numerator2, std::vector<double>& energy,
schedule& schd, int Nmc, int nelec) {
//-----------------------------------------------------------------------------
/*!
BM_description
:Inputs:
Determinant& d:
The reference |D_i>
double epsilon:
The criterion for chosing new determinants (understood as epsilon/c_i)
CItype ci1:
The reference CI coefficient c_i
CItype ci2:
The reference CI coefficient c_i
oneInt& int1:
One-electron tensor of the Hamiltonian
twoInt& int2:
Two-electron tensor of the Hamiltonian
twoIntHeatBathSHM& I2hb:
The sorted two-electron integrals to choose the bi-excited determinants
vector<int>& irreps:
Irrep of the orbitals
double coreE:
The core energy
double E0:
The current variational energy
std::vector<Determinant>& dets:
The determinants' determinant
std::vector<CItype>& numerator1:
The determinants' numerator
vector<double>& numerator2:
The determinants' numerator
std::vector<double>& energy:
The determinants' energy
schedule& schd:
The schedule
int Nmc:
BM_description
int nelec:
Number of electrons
*/
//-----------------------------------------------------------------------------
// initialize variables
int norbs = d.norbs;
int nclosed = nelec;
int nopen = norbs-nclosed;
vector<int> closed(nelec,0);
vector<int> open(norbs-nelec,0);
d.getOpenClosed(open, closed);
//d.getRepArray(detArray);
double Energyd = d.Energy(int1, int2, coreE);
double Nmcd = 1. * Nmc;
initiateRestrictions(schd.restrictionsPT, closed);
// mono-excited determinants
for (int ia=0; ia<nopen*nclosed; ia++){
int i=ia/nopen, a=ia%nopen;
//if (open[a]/2 > schd.nvirt+nclosed/2) continue; //dont occupy above a certain orbital
if (! satisfiesRestrictions(schd.restrictionsPT, closed[i], open[a])) continue;
#ifndef Complex
if (closed[i]%2 != open[a]%2 || irreps[closed[i]/2] != irreps[open[a]/2]) continue;
#endif
CItype integral = Hij_1Excite(open[a],closed[i],int1,int2, &closed[0], nclosed);
// generate determinant if integral is above the criterion
if (fabs(integral) > epsilon ) {
dets.push_back(d);
Determinant& di = *dets.rbegin();
di.setocc(open[a], true); di.setocc(closed[i],false);
// numerator and energy
numerator1.push_back(integral*ci1);
#ifndef Complex
numerator2.push_back( integral*integral*ci1*(ci1*Nmcd/(Nmcd-1)- ci2));
#else
numerator2.push_back( (integral*integral*ci1*(ci1*Nmcd/(Nmcd-1)- ci2)).real());
#endif
#ifndef Complex
double E = EnergyAfterExcitation(closed, nclosed, int1, int2, coreE, i, open[a], Energyd);
#else
double E = di.Energy(int1, int2, coreE);
#endif
energy.push_back(E);
}
} // ia
// bi-excitated determinants
//#pragma omp parallel for schedule(dynamic)
if (fabs(int2.maxEntry) < epsilon) return;
// for all pairs of closed
for (int ij=0; ij<nclosed*nclosed; ij++) {
int i=ij/nclosed, j = ij%nclosed;
if (i<=j) continue;
int I = closed[i]/2, J = closed[j]/2;
int X = max(I, J), Y = min(I, J);
int pairIndex = X*(X+1)/2+Y;
size_t start = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex] : I2hb.startingIndicesOppositeSpin[pairIndex];
size_t end = closed[i]%2==closed[j]%2 ? I2hb.startingIndicesSameSpin[pairIndex+1] : I2hb.startingIndicesOppositeSpin[pairIndex+1];
float* integrals = closed[i]%2==closed[j]%2 ? I2hb.sameSpinIntegrals : I2hb.oppositeSpinIntegrals;
short* orbIndices = closed[i]%2==closed[j]%2 ? I2hb.sameSpinPairs : I2hb.oppositeSpinPairs;
// for all HCI integrals
for (size_t index=start; index<end; index++) {
// if we are going below the criterion, break
if (fabs(integrals[index]) < epsilon) break;
// otherwise: generate the determinant corresponding to the current excitation
int a = 2* orbIndices[2*index] + closed[i]%2, b= 2*orbIndices[2*index+1]+closed[j]%2;
if (! satisfiesRestrictions(schd.restrictionsPT, closed[i], closed[j], a, b)) continue;
if (!(d.getocc(a) || d.getocc(b))) {
dets.push_back(d);
Determinant& di = *dets.rbegin();
di.setocc(a, true), di.setocc(b, true), di.setocc(closed[i],false), di.setocc(closed[j], false);
// sgn
double sgn = 1.0;
di.parity(a, b, closed[i], closed[j], sgn);
// numerator and energy
numerator1.push_back(integrals[index]*sgn*ci1);
#ifndef Complex
numerator2.push_back( integrals[index]*integrals[index]*ci1*(ci1*Nmcd/(Nmcd-1)- ci2));
#else
numerator2.push_back( (integrals[index]*integrals[index]*1.0*ci1*(ci1*Nmcd/(Nmcd-1)- ci2)).real());
#endif
double E = EnergyAfterExcitation(closed, nclosed, int1, int2, coreE, i, a, j, b, Energyd);
energy.push_back(E);
}
} // heatbath integrals
} // ij
return;
} // end SHCIgetdeterminants::getDeterminantsStochastic
//=============================================================================
void SHCIgetdeterminants::getDeterminantsStochastic2Epsilon(
Determinant& d, double epsilon, double epsilonLarge, CItype ci1, CItype ci2,
oneInt& int1, twoInt& int2, twoIntHeatBathSHM& I2hb,
vector<int>& irreps, double coreE, double E0,
std::vector<Determinant>& dets, std::vector<CItype>& numerator1A, vector<CItype>& numerator2A, vector<char>& present, std::vector<double>& energy,
schedule& schd, int Nmc, int nelec) {
//-----------------------------------------------------------------------------
/*!
BM_description
:Inputs:
Determinant& d:
The reference |D_i>
double epsilon:
The criterion for chosing new determinants (understood as epsilon/c_i)
double epsilonLarge:
The criterion for chosing new determinants (understood as epsilon/c_i)
CItype ci1:
The reference CI coefficient c_i
CItype ci2:
The reference CI coefficient c_i
oneInt& int1:
One-electron tensor of the Hamiltonian
twoInt& int2:
Two-electron tensor of the Hamiltonian
twoIntHeatBathSHM& I2hb:
The sorted two-electron integrals to choose the bi-excited determinants
vector<int>& irreps:
Irrep of the orbitals
double coreE:
The core energy
double E0:
The current variational energy
std::vector<Determinant>& dets:
The determinants' determinant
std::vector<CItype>& numerator1A:
The determinants' numerator
vector<CItype>& numerator2A:
The determinants' numerator
vector<char>& present:
BM_description
std::vector<double>& energy:
The determinants' energy
schedule& schd:
The schedule
int Nmc:
BM_description
int nelec:
Number of electrons
*/
//-----------------------------------------------------------------------------
// initialize variables
int norbs = d.norbs;
int nclosed = nelec;
int nopen = norbs-nclosed;
vector<int> closed(nelec,0);
vector<int> open(norbs-nelec,0);
d.getOpenClosed(open, closed);
//d.getRepArray(detArray);
double Energyd = d.Energy(int1, int2, coreE);
double Nmcd = 1.*Nmc;
initiateRestrictions(schd.restrictionsPT, closed);
// mono-excited determinants
for (int ia=0; ia<nopen*nclosed; ia++){
int i=ia/nopen, a=ia%nopen;
if (! satisfiesRestrictions(schd.restrictionsPT, closed[i], open[a])) continue;
CItype integral = Hij_1Excite(open[a],closed[i],int1,int2, &closed[0], nclosed);
// sgn
if (closed[i]%2 != open[a]%2) {
double sgn = 1.0;
d.parity(min(open[a],closed[i]), max(open[a],closed[i]),sgn);
integral = int1(open[a], closed[i])*sgn;
}
// generate determinant if integral is above the criterion
if (fabs(integral) > epsilon ) {
dets.push_back(d);
Determinant& di = *dets.rbegin();
di.setocc(open[a], true); di.setocc(closed[i],false);
// numerator and energy
numerator1A.push_back(integral*ci1);
#ifndef Complex
numerator2A.push_back( integral*integral*ci1 *(ci1*Nmcd/(Nmcd-1)- ci2));
#else
numerator2A.push_back( pow( abs(integral*ci1),2)*Nmcd/(Nmcd-1) *(1. - abs(ci2)/abs(ci1)) );
//numerator2A.push_back( (integral*integral*ci1 *(ci1*Nmcd/(Nmcd-1)- ci2)).real() );
#endif
#ifndef Complex
double E = EnergyAfterExcitation(closed, nclosed, int1, int2, coreE, i, open[a], Energyd);
#else
double E = di.Energy(int1, int2, coreE);
#endif
energy.push_back(E);
// ...
if (fabs(integral) > epsilonLarge) present.push_back(true);
else present.push_back(false);
}
} // ia
// bi-excitated determinants
//#pragma omp parallel for schedule(dynamic)
if (fabs(int2.maxEntry) < epsilon) return;
// for all pairs of closed
for (int ij=0; ij<nclosed*nclosed; ij++) {
int i=ij/nclosed, j = ij%nclosed;
if (i<=j) continue;