-
Notifications
You must be signed in to change notification settings - Fork 0
/
MBEq.py
executable file
·10655 lines (8029 loc) · 361 KB
/
MBEq.py
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
from pdb import set_trace
import copy
print "\n\n\n"
print " Welcome to Automatic Equation Generator\n\n"
print " Liguo Kong and Marcel Nooijen\n"
print " Department of Chemistry, University of Waterloo, Waterloo, ON, Canada\n\n\n"
# notation:
# 'sf': 'spin-free'
# 'so': 'spin-orbital'
# 'km': 'MR normal order by Mukherjee and Kutzelnigg'
#**************
# Directory *
#**************
Public = ['Classes and Related',
'Index and Excitation Operator Base',
'Contraction Functions',
'KM-GWT',
'Tools Library',
'Spatial Orbital Canonicalization: connected',
'Spatial Orbital Canonicalization: permutation',
'Spin Orbital Canonicalization',
'spin expansion',
'SRCC',
'MR-F12',
'Factorization',
'Latex',
'Ohio Tensor Contraction Engine Interface']
#******************************
# System Control Parameters *
#******************************
system_switch = { 'use spin orbital' : 0, # this global variable controls whether we are doing spin or spatial orbital work, which will affect
# , e.g., coeff(), or even generalIndex, we also need completely different merge_all/canonical functions
# at the beginning, this is due to the demand of Ohio TCE people, but we might use it in our own work later.
# WHENEVER DOING SPIN ORBITAL WORK, TURN THIS ON
'normal order' : 'T',
# if system_switch['normal order'] == 'T', use traditional normal order contraction scheme
# if system_switch['normal order'] == 'KM', use the KM`-normal order contraction scheme; spin-free version shall not be used
# if system_switch['normal order'] == 'V', genuine vacuum normal order, based on tweaking of KM normal order
# MN normal ordering is deprecated
'matrix value table': 'r12',
'explicit spin' : 0,
'canonical scheme' : 'p', # how to canonicalize: 'p' means 'permu', works generally; 'c' means 'connect', works for spin-free connected expression not involving
# quantities of rank higher than 2
'GWT CU truncate rank' : 1, # In MR normal order expansion, truncate cumulant rank; if N = 0, no truncation, keep all;
'EXCLUDE Particle Ind from CU': 1, # if reference WFN is a CAS reference function, then cumulants containing particle indices will be zero;
# if it is a general wavefunction, then cumulants containing particle indices may not be zero
'Allow Internal Contraction': 0, # either 0 or 1; used for MR normal order expansion; this is useful for expanding DM into cumulants, via a trick
'expand tensor' : [], # this is the contraction variable used in MN/MN2-normal order theory, e.g. ['DEN', 'Cbar']
'Max DM rank': 2,
'DM coefficient': 'normal'}
# in this definition of density matrix, D_ij^kl is not <L|k^+l^+ ji |R>, so use this global variable to
# control; if D_ij^kl = <L|k^+l^+ ji |R>, we set system_switch['DM coefficient'] == 'normal'
# otherwise it is '1/n!'
# it should be 'normal 'when we do KM theory ! because that is how we define the lists
#**************************************
# Parameters used in the code *
#**************************************
typelist = ['p', 'e', 'h', 'm', 'g']
type_value = [0, 1, 2, 3, 4]
dm_or_cumu_names = ['Lambda', 'lambda', 'lambda1', 'Lambda1', 'DEN', 'Gamma', 'gamma', 'd', 'd1', 'd2', 'd3', 'd4']
dic_type_value = {'P': 0,
'p': 1, # this capital letter stands for alpha spin orbital index; used in explict spin cases
'E': 10,
'e': 11,
'H': 100,
'h': 101,
'M': 1000,
'm': 1001,
'g': 10001,
'A': 0,
'a': 1,
'I': 100,
'i': 101}
dic_active_value = {-1: 3,
0: 31,
1: 301}
dic_fix_value = {0: 7,
1: 700}
dic_matname_value_all = {'f': 41,
'nf': 41,
'kmf': 41,
'v': 43,
'nv': 43,
'kmv': 43,
'lvsA': 47,
'lvsB': 53,
'lvsC': 59,
'lvsD': 61,
't': 79,
't1': 83,
't2': 97,
'ltA': 101,
'lc': 103,
's': 107,
's1': 109,
's2': 113,
's3': 119,
'lsB': 121,
's4': 127,
'lsA': 131,
's5': 133,
's6': 134,
'w': 137,
'lsC': 139,
'nd': 199,
'X': 142, # 'X' will not appear in tenta_final()
'z': 100000, # 'z' is used occasionally in mcscf
'lx': 150, # 'lx' is used occasionally in mrucc
'delta': 151,
'F_t1': 155,
'F_t2': 157,
'F(t1)_': 159,
'F(t2)_': 161,
'hbar1': 169, # for ccsd_h
'hbar2': 179,
'g1': 171, # for steom_g
'g2': 173,
'g3': 177,
'M': 183,
'DEN': 187,
'Cbar': 193,
't3': 199,
'eta': 209,
'gamma': 217,
'Gamma': 211,
'lambda': 221,
'Lambda': 212,
'lambda1': 223,
'Lambda1': 227,
'd': 233,
'd1': 239,
'd2': 240,
'd3': 241,
'd4': 242,
'G': 243,
'K': 244,
'D_INV': 245,
'Cbar_INV': 246,
'x1': 253, # this quantity is used to MN2-n.o.; I will also use this to temperarily simulate lambda1_inv to avoid introducing new mats
'x2': 257,
'x3': 259,
'r': 263} # this corresponds to the r12 integral
dic_matname_value_r12 = {'t2': 1,
'Gamma': 10,
'Lambda': 20,
'f': 30,
'v': 40,
'Lambda1': 50,
'r': 60,
'x1': 70, # this corresponds to the r12 integral
'd1': 80,
'd2': 90,
'd3': 100,
'delta': 110}
dic_matname_value_srsd = {'f': 41,
'v': 43,
't1': 83,
't2': 97,
'delta': 151,
't3': 199}
# this is to allow more freedom; it only affects the looking of the final expressions.
if system_switch['matrix value table'] == 'r12': dic_matname_value = dic_matname_value_r12
elif system_switch['matrix value table'] == 'srsd': dic_matname_value = dic_matname_value_srsd
elif system_switch['matrix value table'] == 'showcase': dic_matname_value = dic_matname_value_all
else:
print "please specify"
set_trace()
new_dic_mat_value = {'t2': 1,
'd': 5}
dic_matname_va = { 't': 't',
't1': 't',
't2': 't',
't3': 't',
's1': 's',
's2': 's',
's3': 's',
's4': 's',
's5': 's',
's6': 's',
'w': 'w',
'f': 'f',
'nf': 'F',
'kmf': 'F',
'v': 'v',
'nv': 'V',
'kmv': 'V',
'd': 'd',
'd1': 'd',
'd2': 'd',
'd3': 'd',
'd4': 'd',
'nd': 'nd',
'M': 'M',
't': 't',
'lvsA': '\wp',
'lvsB': '\\aleph',
'lvsC': '\Im',
'lvsD': '\Re',
'ltA': '\mho',
'lc': '\sigma',
'lsA': '\zeta',
'lsB': '\\xi',
'lsC': '\eta',
'X': 'X',
'lx': '\Delta',
'delta': '\delta',
'I': 'I',
'cor': ' E ',
'hbar1': '\\bar{H}',
'hbar2': '\\bar{H}',
'g1': 'g',
'g2': 'g',
'g3': 'g',
'g4': 'g',
'J1': 'J_eom_1',
'J2': 'J_eom_2',
'A': 'A',
'B': 'B',
'C': 'C',
'D': 'D',
'E': 'E',
'F': 'F',
'DEN': '\\gamma',
'x1': '\\xi',
'x2': '\\xi',
'x3': '\\xi',
'G': 'G',
'K': 'K',
'D_INV': '{\\bar{\mathbb{D}}}',
'Cbar_INV': '{\\bar{\\eta}}',
'Cbar': '\\bar{D}',
'eta': '\\eta',
'Gamma': '\\Gamma',
'Lambda': '\\Lambda',
#'Lambda1': '\\Lambda',
'Lambda1': '\\Gamma',
'lambda': '\\lambda',
'lambda1': '\\lambda',
'gamma': '\\gamma',
#'r': '\\bar{r}'}
'r': 'R'}
#--------------------------------------------------------------------------------------------------------------------------------------
# Section 1: CLASSES AND RELATED METHODS
#--------------------------------------------------------------------------------------------------------------------------------------
#**************************************************
# class-Index *
#**************************************************
class Index:
# in the following line, num = "" can be simplified to "", but the form below is more reminicent
def __init__(self, type = "", num = "", att = "", fix = 0, active = 0, other = ["", "", ""]):
self.type = type
self.num = num
self.att = att
self.fix = fix
self.active = active
self.other = other
def equal(one, two):
if one.type == two.type and one.num == two.num and one.fix == two.fix and one.active == two.active: return 1
else: return 0
def similar(one, two):
if one.type == two.type: return 1
else: return 0
def inArray(ind, array):
for a in array:
if a.equal(ind): return 1
return 0
def gvIndexNo(ind, array):
AA = range(len(array))
for a in AA:
if array[a].equal(ind): return a
return res # -1000 indicates: not in array
def gvType(indx):
return indx.type
def gvIndex(index):
return index.type + index.num
def printindex(index):
print index.gvIndex()
def null_index_att_s(terms): # refer to the above
result = []
for xx in terms:
result.append(null_index_att(xx))
return result
#**************************************************
# class-Uoperator *
#**************************************************
class Uoperator:
def __init__(self, upperIndicees = [], lowerIndicees = [], cha = -1, other = []):
self.upperIndicees = upperIndicees
self.lowerIndicees = lowerIndicees
self.cha = cha
self.other = other
def gvUppInd(self):
return self.upperIndicees
def gvLowInd(self):
return self.lowerIndicees
def equals(self, operator2):
result = 0
set1 = makeIndexSet(self.upperIndicees, self.lowerIndicees)
set2 = makeIndexSet(operator2.upperIndicees, operator2.lowerIndicees)
for a in set1.indexPairs:
if(a.inArray(set2.indexPairs)): result += 1
else: pass
if(result == len(set1.indexPairs) == len(set2.indexPairs)): return 1
else: return 0
#**************************************************
# class-TypeContract *
#**************************************************
class TypeContract:
def __init__(self, indexList1 = [], indexList2 = []):
""" indexList1 has the index no. of labels of first operator and indexList2 has of second operator, so they record which indices are contracted """
self.indexList1 = indexList1
self.indexList2 = indexList2
#**************************************************
# class-Contract *
#**************************************************
class Contract:
""" class of sets of contractions has several particle-type contractions and several hole-type contractions """
def __init__(self, pTypeContract = TypeContract(), hTypeContract = TypeContract()):
self.pTypeContract = pTypeContract
self.hTypeContract = hTypeContract
#**************************************************
# class-ContableArrays *
#**************************************************
class ContableArrays:
""" the class of arrays of labels which can be contracted. e.g.: a hole label can not be contracted in a p-type contraction """
def __init__(self, array11 = [], array12 = [], array21 = [], array22 = []):
self.array11 = array11
self.array12 = array12
self.array21 = array21
self.array22 = array22
#**************************************************
# class-MatElement *
#**************************************************
class MatElement:
""" class for matrix elements, mainly attributes: name, matLowerIndicees, matUpperIndicees """
def __init__(self, name = "", matUpperIndicees = [], matLowerIndicees = [], connectivity = 0, other = []):
self.name = name
self.matLowerIndicees = matLowerIndicees
self.matUpperIndicees = matUpperIndicees
self.connectivity = connectivity # used in STORNGLY CONNECTED COUPLED CLUSTER. I think this
self.other = other # attribute is only used temporarily, to select strongly connected terms
def equals(element1, element2):
""" MatElement class method: determine whether element1 and element2 are the same or not """
result = 0
if(element1.name == element2.name):
if(len(element1.matUpperIndicees) != len(element2.matUpperIndicees)):
result = 0
else:
set1 = makeIndexSet(element1.matUpperIndicees, element1.matLowerIndicees)
set2 = makeIndexSet(element2.matUpperIndicees, element2.matLowerIndicees)
for a in set1.indexPairs:
if(a.inArray(set2.indexPairs)):
result = 1
else:
result = 0
break
return result
def mat_2_indexset(self):
""" convert a 'mat' object to an IndexSet object; if later on we do conversion back, then mat.connectivity and mat.other information is lost """
indp = []
for n in range(len(self.matLowerIndicees)):
indp += [IndexPair(self.matUpperIndicees[n], self.matLowerIndicees[n])]
return IndexSet(indp)
def find_outer(mats):
""" find external indices """
if len(mats) == 0: return Uoperator([], [])
elif len(mats) == 1: return Uoperator(mats[0].matUpperIndicees, mats[0].matLowerIndicees)
else:
yy = mats[0]
for xx in range(len(mats)-1):
yy = find_outer_2([yy, mats[xx + 1]])
return Uoperator(yy.matUpperIndicees, yy.matLowerIndicees)
def find_outer_2(mat2):
""" the difference from find_outer_2_bk is that here by the minor change we avoid the problem happening with, say, diagnaol mat element f^a_a, not tested yet """
upp = copy.deepcopy(mat2[0].matUpperIndicees + mat2[0].matLowerIndicees)
low = copy.deepcopy(mat2[1].matUpperIndicees + mat2[1].matLowerIndicees)
L1 = []
L2 = []
LL = []
for xxx in range(len(upp)):
if(not upp[xxx].inArray(low)): L1 += [upp[xxx]]
else: low = delete(low, upp[xxx].gvIndexNo(low))
LL = L1 + low
n = len(LL) # a simple check here
if(n - 2*(n/2) != 0):
print "\n\n Odd number of overall indices in find_outer_2()!"
set_trace
if(len(LL) > 0):
x = len(LL)/2
L1 = LL[:x]
L2 = LL[x:]
return MatElement("", L1, L2, mat2[0].connectivity, mat2[0].other)
#**************************************************
# class-Coefficient *
#**************************************************
class Coefficient:
""" two attributes: const, matElement, e.g. for the term 0.5 t^ab_ij E^ab_ij, Coefficient = 0.5 t^ab_ij, Coefficient.const = 0.5, Coefficient.matElement = [t^ab_ij] """
def __init__(self, const = 1, matElement = []):
self.const = const
self.matElement= matElement
def equals(c1, c2):
result = 0
co1 = []
co2 = []
if(len(c2.matElement) == len(c1.matElement)):
for a in range(len(c1.matElement)):
for b in range(len(c2.matElement)):
if(c1.matElement[a].equals(c2.matElement[b])):
if(b in co1): pass
else:
co1.append(b)
result += 1
if(result == len(c1.matElement)): return 1
else: return 0
return 0
def construct_0_op_term(self):
return Term(coefficient = self)
def coeff_s_times_coeff_s(cos1, cos2):
return [Coefficient(const = a.const * b.const, matElement = a.matElement + b.matElement) for a in cos1 for b in cos2]
def coeff_s_to_2_op_terms(cos):
return [Term(coefficient = ss) for ss in cos]
#**************************************************
# class-Term *
#**************************************************
class Term:
def __init__(self, coefficient = Coefficient(), uOperators = [Uoperator([], [])], type = -1, other = []): # add 'other' for future generalization
self.coefficient = coefficient
self.uOperators = uOperators
self.type = type
self.other = other
def gvFirstOp(term):
return term.uOperators[0]
def gvSecondOp(term):
return term.uOperators[1]
def equals(t1, t2):
result = 1
if(t1.coefficient.equals(t2.coefficient)): pass
else: result = 0
for a in range(len(t1.uOperators)):
if(t1.uOperators[a].equals(t2.uOperators[a])): pass
else: result = 0
return result
def inArray(term, terms):
res = 0
for a in terms:
if(a.equals(term)):
res = 1
break
return res
def inArray2(term, terms):
res = 0
pos = 0
for nn, a in enumerate(terms):
if(a.equals(term)):
res = 1
pos = nn
return [res, pos]
def gvIndexNo(term, terms):
res = 0
for a in range(len(terms)):
if(terms[a].equals(term)):
res = a
break
else:
pass
return res
def null_term_type(term):
term.type =-1
return term
def reorder_term(term1):
term = copy.deepcopy(term1)
term = reorder(term)
for i in range(len(term.coefficient.matElement)):
term = term.reorder_mat_i(i)
return term
def null_index_att(term):
""" reset index.att to default """
for inde in term.uOperators[0].upperIndicees + term.uOperators[0].lowerIndicees:
inde.att = ""
for xx in term.coefficient.matElement:
for yy in xx.matUpperIndicees + xx.matLowerIndicees:
yy.att = ""
return term
def null_index_fix(term): # reset index.fix to default
for inde in term.uOperators[0].upperIndicees + term.uOperators[0].lowerIndicees:
inde.fix = 0
for xx in term.coefficient.matElement:
for yy in xx.matUpperIndicees + xx.matLowerIndicees:
yy.fix = 0
return term
def null_index_active(term): # reset index.active to default
for inde in term.uOperators[0].upperIndicees + term.uOperators[0].lowerIndicees:
inde.active = 0
for xx in term.coefficient.matElement:
for yy in xx.matUpperIndicees + xx.matLowerIndicees:
yy.active = 0
return term
def reorder_mat_i(term1, i):
""" arrange indexpairs in term1.coefficient.matElement[i] in an convenient order, pp-pe-...-gg """
mattotal = []
term = copy.deepcopy(term1)
for k in range(25):
mattotal = mattotal + [[]]
map = []
totalnum = []
typelist = ["p", "e", "h", "m", "g"]
for dd in typelist:
for ff in typelist:
map = map + [[dd, ff]]
oo = term.coefficient.matElement[i]
for ii in range(len(oo.matUpperIndicees)):
jj = [oo.matLowerIndicees[ii].type, oo.matLowerIndicees[ii].type]
mattotal[map.index(jj)] = mattotal[map.index(jj)] + [ii]
upp = []
low = []
for kk in mattotal:
for ll in kk:
upp = upp + [oo.matUpperIndicees[ll]]
low = low + [oo.matLowerIndicees[ll]]
oo.matUpperIndicees = upp
oo.matLowerIndicees = low
term.coefficient.matElement[i] = MatElement(term.coefficient.matElement[i].name, upp, low, term.coefficient.matElement[i].connectivity, term.coefficient.matElement[i].other)
return term
def reorder_mats(self, preferorder):
""" preferorder gives the ones you want to appear first """
mats1 = []
mats2 = []
if len(preferorder) == 1:
for xx in self.coefficient.matElement:
if xx.name == preferorder[0]: mats1.append(xx)
else: mats2.append(xx)
return Term(Coefficient(self.coefficient.const, mats1 + mats2), self.uOperators)
else: set_trace() # only 1 is implemented so far
def hasmat_name(self, matname):
""" tell whether termm contain a mat named 'matnmae'; return [yesorno (0/1), numbers] """
find = 0
num = 0
for xx in self.coefficient.matElement:
if xx.name == matname:
find = 1
num += 1
return [find, num]
def hasmat(self, matt):
""" tell whether termm contain matt or not; if yes, return 'pos'; otherwise return -1 """
res = -1
nummats = len(self.coefficient.matElement)
for xx in range(nummats):
if(matt.equals(self.coefficient.matElement[xx])):
res = xx
break
return res
def hasmats(self, mats):
""" tell if term has all mats; and separate them into 2 groups """
termm = copy.deepcopy(self)
hasall = 1
poss = []
mm = copy.deepcopy(self.coefficient.matElement)
for xx in mats:
pos = self.hasmat(xx)
if pos == -1:
hasall = 0
break
else: poss.append(pos)
if hasall:
poss.sort()
poss.reverse()
mm = copy.deepcopy(self.coefficient.matElement)
for xx in poss: mm.pop(xx) # remove mats from the term
return [hasall, mm]
def has_indices_more_than_twice(self):
find = 0
allinds = give_all_ind(self)
uniqueinds = give_indlist(self)
for xx in uniqueinds:
if appear_time(xx, allinds) > 2:
xx.printindex()
find = 1
break
return find
def give_ex_deex_rank(self):
""" Give the excitation and deexcitation rank in diagrammatic sense.
assume no 'general' indices exist """
ex = 0
deex = 0
for yy in self.uOperators[0].upperIndicees:
if yy.type in ['p', 'e', 'P', 'E']:
ex += 1
elif yy.type in ['h', 'm', 'H', 'M']:
deex += 1
else:
print "general indices? Not handled. Break it first"
printterm(term)
set_trace()
for yy in self.uOperators[0].lowerIndicees:
if yy.type in ['p', 'e', 'P', 'E']:
deex += 1
elif yy.type in ['h', 'm', 'H', 'M']:
ex += 1
else:
print "general indices? Not handled. Break it first"
printterm(term)
set_trace()
return [ex, deex, ex-deex]
def replace_2b_cumu_with_dm_1(self):
if(system_switch['use spin orbital'] == 1): CumulantName = 'lambda'
else: CumulantName = 'Lambda'
flag = 0
others = []
flag2 = 1
for xx in self.coefficient.matElement:
if(xx.name == CumulantName and len(xx.matUpperIndicees) == 2 and flag2 == 1): # since we only replace ONE cumulant, we use flag2 to monitor
flag += 1
eta = xx
flag2 = 0
else:
others += [xx]
if(flag == 0):
printterm(self)
pdb.set_trace()
return
elif(system_switch['use spin orbital'] == 1):
return [Term(Coefficient(self.coefficient.const, others + [MatElement('gamma', eta.matUpperIndicees, eta.matLowerIndicees)]), self.uOperators),
Term(Coefficient(-1.0*self.coefficient.const, others + [MatElement('lambda1', eta.matUpperIndicees[:1], eta.matLowerIndicees[:1]), MatElement('lambda1', eta.matUpperIndicees[1:], eta.matLowerIndicees[1:])]), self.uOperators),
Term(Coefficient(self.coefficient.const, others + [MatElement('lambda1', eta.matUpperIndicees[:1], eta.matLowerIndicees[1:]), MatElement('lambda1', eta.matUpperIndicees[1:], eta.matLowerIndicees[:1])]), self.uOperators)]
else:
return [Term(Coefficient(self.coefficient.const, others + [MatElement('Gamma', eta.matUpperIndicees, eta.matLowerIndicees)]), self.uOperators),
Term(Coefficient(-1.0*self.coefficient.const, others + [MatElement('Lambda1', eta.matUpperIndicees[:1], eta.matLowerIndicees[:1]), MatElement('Lambda1', eta.matUpperIndicees[1:], eta.matLowerIndicees[1:])]), self.uOperators),
Term(Coefficient(self.coefficient.const * 0.5, others + [MatElement('Lambda1', eta.matUpperIndicees[:1], eta.matLowerIndicees[1:]), MatElement('Lambda1', eta.matUpperIndicees[1:], eta.matLowerIndicees[:1])]), self.uOperators)]
def replace_2b_dm_with_cumu_1(self):
term = self
if system_switch['use spin orbital'] == 1: DMName = 'gamma'
else: DMName = 'Gamma'
flag = 0
others = []
flag2 = 1
for xx in term.coefficient.matElement:
if flag2 == 1 and xx.name == DMName and len(xx.matUpperIndicees) == 2: # since we only replace ONE DM, we use flag2 to monitor
flag += 1
eta = xx
flag2 = 0
else: others += [xx]
if flag == 0:
printterm(term)
set_trace()
elif system_switch['use spin orbital'] == 1:
return [Term(Coefficient(term.coefficient.const, others + [MatElement('lambda', eta.matUpperIndicees, eta.matLowerIndicees)]), term.uOperators),
Term(Coefficient(term.coefficient.const, others + [MatElement('lambda1', eta.matUpperIndicees[:1], eta.matLowerIndicees[:1]), MatElement('lambda1', eta.matUpperIndicees[1:], eta.matLowerIndicees[1:])]), term.uOperators),
Term(Coefficient(-1.0 * term.coefficient.const, others + [MatElement('lambda1', eta.matUpperIndicees[:1], eta.matLowerIndicees[1:]), MatElement('lambda1', eta.matUpperIndicees[1:], eta.matLowerIndicees[:1])]), term.uOperators)]
else:
return [Term(Coefficient(term.coefficient.const, others + [MatElement('Lambda', eta.matUpperIndicees, eta.matLowerIndicees)]), term.uOperators),
Term(Coefficient(term.coefficient.const, others + [MatElement('Lambda1', eta.matUpperIndicees[:1], eta.matLowerIndicees[:1]), MatElement('Lambda1', eta.matUpperIndicees[1:], eta.matLowerIndicees[1:])]), term.uOperators),
Term(Coefficient(term.coefficient.const * (-0.5), others + [MatElement('Lambda1', eta.matUpperIndicees[:1], eta.matLowerIndicees[1:]), MatElement('Lambda1', eta.matUpperIndicees[1:], eta.matLowerIndicees[:1])]), term.uOperators)]
def replace_12b_sf_dm_with_delta_1(self):
if(system_switch['use spin orbital'] != 0): set_trace()
term = self
DMNames = ['Gamma', 'Lambda1']
flag = 0
others = []
flag2 = 0
for xx in term.coefficient.matElement:
if flag == 0 and xx.name in DMNames and len(xx.matUpperIndicees) in [1, 2]: # since we only replace ONE DM, we use flag2 to monitor
flag = 1
ga = xx
else:
others += [xx]
if(flag == 0):
printterm(term)
set_trace()
return
else:
if len(ga.matUpperIndicees) == 2:
return [Term(Coefficient(term.coefficient.const * 4.0, others + [MatElement('delta', ga.matUpperIndicees[:1], ga.matLowerIndicees[:1]),MatElement('delta', ga.matUpperIndicees[1:], ga.matLowerIndicees[1:])]), term.uOperators),
Term(Coefficient(term.coefficient.const * (-2.0), others + [MatElement('delta', ga.matUpperIndicees[:1], ga.matLowerIndicees[1:]),MatElement('delta', ga.matUpperIndicees[1:], ga.matLowerIndicees[:1])]), term.uOperators)]
elif len(ga.matUpperIndicees) == 1:
return [Term(Coefficient(term.coefficient.const * 2.0, others + [MatElement('delta', ga.matUpperIndicees, ga.matLowerIndicees)]), term.uOperators)]
else: set_trace()
def replace_sf_3_dm_with_cumu_1(term):
""" Replace spin-free 3-RDM by 1/2-cumulant (spin-free), as in the MolPhys paper by Kutzelnigg, Eq. (75) """
flag = 0
others = []
flag2 = 1
for xx in term.coefficient.matElement:
if(xx.name == 'd3' and flag2 == 1):
flag += 1
gamma3 = xx
flag2 = 0
else: others += [xx]
if(flag == 0):
printterm(term)
set_trace()
return
elif(system_switch['use spin orbital'] == 0):
[P1, P2, P3, Q1, Q2, Q3] = gamma3.matUpperIndicees + gamma3.matLowerIndicees
Coeffs = [ Coefficient(1.0, [MatElement('Lambda1', [P1], [Q1]),MatElement('Lambda1', [P2], [Q2]), MatElement('Lambda1', [P3], [Q3]) ]),
Coefficient(0.25, [MatElement('Lambda1', [P1], [Q2]),MatElement('Lambda1', [P2], [Q3]), MatElement('Lambda1', [P3], [Q1]) ]),
Coefficient(0.25, [MatElement('Lambda1', [P1], [Q3]),MatElement('Lambda1', [P2], [Q1]), MatElement('Lambda1', [P3], [Q2]) ]),
Coefficient(-0.5, [MatElement('Lambda1', [P1], [Q2]),MatElement('Lambda1', [P2], [Q1]), MatElement('Lambda1', [P3], [Q3]) ]),
Coefficient(-0.5, [MatElement('Lambda1', [P1], [Q1]),MatElement('Lambda1', [P2], [Q3]), MatElement('Lambda1', [P3], [Q2]) ]),
Coefficient(-0.5, [MatElement('Lambda1', [P1], [Q3]),MatElement('Lambda1', [P2], [Q2]), MatElement('Lambda1', [P3], [Q1]) ]),
Coefficient(1.0, [MatElement('Lambda1', [P1], [Q1]),MatElement('Lambda', [P2, P3], [Q2, Q3]) ]),
Coefficient(1.0, [MatElement('Lambda1', [P2], [Q2]),MatElement('Lambda', [P1, P3], [Q1, Q3]) ]),
Coefficient(1.0, [MatElement('Lambda1', [P3], [Q3]),MatElement('Lambda', [P1, P2], [Q1, Q2]) ]),
Coefficient(-0.5, [MatElement('Lambda1', [P1], [Q2]),MatElement('Lambda', [P2, P3], [Q1, Q3]) ]),
Coefficient(-0.5, [MatElement('Lambda1', [P1], [Q3]),MatElement('Lambda', [P2, P3], [Q2, Q1]) ]),
Coefficient(-0.5, [MatElement('Lambda1', [P2], [Q1]),MatElement('Lambda', [P1, P3], [Q2, Q3]) ]),
Coefficient(-0.5, [MatElement('Lambda1', [P2], [Q3]),MatElement('Lambda', [P1, P3], [Q1, Q2]) ]),
Coefficient(-0.5, [MatElement('Lambda1', [P3], [Q1]),MatElement('Lambda', [P1, P2], [Q3, Q2]) ]),
Coefficient(-0.5, [MatElement('Lambda1', [P3], [Q2]),MatElement('Lambda', [P1, P2], [Q1, Q3]) ])]
TempTerm = Term(Coefficient(term.coefficient.const, others), term.uOperators)
res = []
for xx in Coeffs: res.append(Term(Coefficient(TempTerm.coefficient.const * xx.const, others + xx.matElement), TempTerm.uOperators))
return res