forked from goodluck1982/MSGCorep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSGCorep.wl
3302 lines (2924 loc) · 161 KB
/
MSGCorep.wl
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
(* ::Package:: *)
(* A package for irreducible corepresentations of magnetic space group using the conventions in the book of
C.J. Bradley and A.P. Cracknell, "The Mathematical Theory of Symmetry in Solids",
called "the BC book" afterwards. *)
(* Package Name: MSGCorep *)
(* Author: Gui-Bin Liu *)
(* Package verseion: see MSGCorep`Private`Version *)
(* Dependency: SpaceGroupIrep, for version see MSGCorep`Private`SpaceGroupIrepDependency *)
(* Mathematica version: >=11.2 *)
(* License: GPLv3 http://www.gnu.org/licenses/gpl-3.0.txt *)
With[{p=DirectoryName[$InputFileName]}, If[!MemberQ[$Path,p],AppendTo[$Path, p]]];
MSGCorep`Private`Version={1,0,0}; (*Specify version here.*)
MSGCorep`Private`SpaceGroupIrepDependency={1,2,3}; (*Specify dependency here.*)
Check[BeginPackage["MSGCorep`", {"SpaceGroupIrep`","LittleGroupIrepData`"}],
Print["MSGCorep package (version ",StringRiffle[ToString/@MSGCorep`Private`Version,"."],") needs the SpaceGroupIrep (version>=",
StringRiffle[ToString/@MSGCorep`Private`SpaceGroupIrepDependency,"."],") package, please download and install it first.\n",
"URL: https://github.com/goodluck1982/SpaceGroupIrep"]; Abort[],
{Needs::nocont, Get::noopen}]
(*---------- check dependency ---------*)
Module[{v1,v2,sv1,sv2,sv,out=False},
v1=MSGCorep`Private`SpaceGroupIrepDependency; v2=SpaceGroupIrep`Private`Version;
If[ValueQ[SpaceGroupIrep`Private`Version], If[Last@Sort[{v1,v2}]!=v2,out=True;sv2=StringRiffle[v2,"."]], out=True;sv2="<=1.2.2" ];
If[out, sv1=StringRiffle[v1,"."]; sv=StringRiffle[MSGCorep`Private`Version,"."];
Print[Style["Warning:",Red]," The current version of SpaceGroupIrep "<>sv2<>" does not meet the dependency >="<>sv1<>" required "<>
"by MSGCorep v"<>sv<>"."," Please update SpaceGroupIrep to the latest version and reload it manually by <<SpaceGroupIrep`."] ];
];
Remove[v1,v2,sv1,sv2,sv,out];
(*-------------------------------------*)
Unprotect@@Names["MSGCorep`*"];
ClearAll@@Names["MSGCorep`*"];
Get["Usage.wl"];
Get["MSGData.wl"];
Begin["`Private`"]
cont="MSGCorep`Private`";
(* ::Section:: *)
(*Magnetic Space Group (MSG) Symbols*)
(* ::Subsection:: *)
(*MSGSymStd (MSGSymBNS)*)
(* ::Subsubsection::Closed:: *)
(*MSGSymStd *)
Options[MSGSymStd]={"TeX"->False, "BC"->False};
MSGSymStd[symtext_String, OptionsPattern[]]:=
Module[{tmp,tex,bar,sub,p1,p2,p3,chs,prime,subp},
tex=(OptionValue["TeX"]===True);
sub[s1_,s2_]:=If[tex, s1<>"_{"<>s2<>"}", Subscript[s1,s2]];
bar[s1_]:=If[tex, "\\bar{"<>s1<>"}", OverBar[s1]];
prime[s1_]:=If[tex, s1<>"'", Superscript[s1,"\[Prime]"]];
subp[s1_,s2_]:=If[tex, s1<>"_"<>s2<>"'", Subsuperscript[s1,s2,"\[Prime]"]];
chs=Characters[symtext];
AppendTo[chs,"END"];
p1=Position[chs,"-"];
If[p1!={}, p1=p1[[1,1]];
chs=Join[chs[[1;;p1-1]], {bar[chs[[p1+1]]]}, chs[[p1+2;;]]];
];
p2=Position[chs,"_"];
While[p2!={}, p2=p2[[1,1]];
If[p2==2&&chs[[3]]==="2",
chs=Prepend[chs[[5;;]], sub[chs[[1]], "2"<>chs[[4]]]],
If[chs[[p2+2]]==="'",
chs=Join[chs[[1;;p2-2]], {subp[chs[[p2-1]],chs[[p2+1]]]}, chs[[p2+3;;]]],
chs=Join[chs[[1;;p2-2]], {sub[chs[[p2-1]],chs[[p2+1]]]}, chs[[p2+2;;]]]
];
];
p2=Position[chs,"_"];
];
p3=Position[chs,"'"];
While[p3!={}, p3=p3[[1,1]];
chs=Join[chs[[1;;p3-2]], {prime[chs[[p3-1]]]}, chs[[p3+1;;]]];
p3=Position[chs,"'"];
];
If[tex, StringJoin["$",chs[[;;-2]],"$"], Row[chs[[;;-2]]]]
]
(*We take the BNS notation (N. V. Belov, N. N. Neronova and T. S. Smirnova) of MSGs as standard*)
MSGSymStd[{sgno_, num_}, OptionsPattern[]]:=Module[{nums, pos, text,bc},
{nums,pos}=checkMSGinput[{sgno,num},"MSGSymStd"];
bc=If[OptionValue["BC"]===True, "BC",""];
text=ToExpression["type"<>ToString[pos[[1,1]]]<>"MSGSymText"<>bc][{sgno,num}];
MSGSymStd[text,"TeX"->OptionValue["TeX"]]
]
MSGSymStd[sgno_Integer, OptionsPattern[]]/;1<=sgno<=230:=Module[{nums,nums2,nums3,syms,bc,ogsyms},
nums={type1num[sgno],type2num[sgno],type3nums[sgno],type4nums[sgno]}//Flatten;
bc="BC"->OptionValue["BC"];
syms={"BNS:", ToString[sgno]<>"."<>ToString[#], MSGSymStd[{sgno,#},bc]}&/@nums;
ogsyms={"OG:", StringRiffle[ToString/@#,"."], MSGSymOG[#]}&/@(BNStoOG[{sgno,#}]&/@nums);
Flatten/@({getMSGType[{sgno,#}]&/@nums, syms, ogsyms}//Transpose)/.{1->"I", 2->"II", 3->"III", 4->"IV"}
]
(* ::Subsubsection::Closed:: *)
(*MSGSymBNS*)
MSGSymBNS=MSGSymStd; (* define an alias *)
(* ::Subsection::Closed:: *)
(*MSGSymBC*)
Options[MSGSymBC]={"TeX"->False};
MSGSymBC[{sgno_Integer,num_Integer}, OptionsPattern[]]:=
MSGSymStd[{sgno,num},"TeX"->OptionValue["TeX"], "BC"->True]
MSGSymBC[sgno_Integer, OptionsPattern[]]:=MSGSymStd[sgno, "BC"->True]
(* ::Subsection::Closed:: *)
(*MSGSymOG*)
Options[MSGSymOG]={"TeX"->False};
MSGSymOG[sgno_Integer, OptionsPattern[]]/;1<=sgno<=230:=Module[{nums,types,tmp,bnsnums},
nums=Select[OGDataList[[All,1]],#[[1]]==sgno&];
bnsnums=OGtoBNS/@nums; types=getMSGType/@bnsnums;
tmp={types, {"OG:", StringRiffle[ToString/@#,"."], MSGSymOG[#]}&/@nums,
{"BNS:", StringRiffle[ToString/@#,"."], MSGSymStd[#]}&/@bnsnums}//Transpose;
Flatten/@tmp/.{1->"I", 2->"II", 3->"III", 4->"IV"}
]
MSGSymOG[{p_Integer,q_Integer,r_Integer}, OptionsPattern[]]/;1<=p<=230&&1<=r<=1651:=Module[{nums},
nums=Select[OGDataList[[All,1]],#[[1]]==p&];
If[Select[nums,#=={p,q,r}&]=={}, Print["MSGSymOG: Error, {p,q,r} should be in ",nums]; Abort[]];
MSGSymStd[MSGSymTextOG[{p,q,r}], "TeX"->OptionValue["TeX"]]
]
(* ::Subsection::Closed:: *)
(*showMSGSym*)
Options[showMSGSym]={"family"->"BNS", "BCstyle"->1, "color"->True};
showMSGSym[OptionsPattern[]]:=showMSGSym[All, (#->OptionValue[#])&/@{"family","BCstyle","color"}]
showMSGSym[listOrSpan_, OptionsPattern[]]:=Module[{sglist,tab,head,tmp1,tmp2,pos,outBC,
lt=0.96,cls,bgs},
sglist=If[IntegerQ[listOrSpan], {listOrSpan}, Range[230][[listOrSpan]]];
head={Column[{"BNS","Number"}], Column[{"BNS","Symbol"}], Column[{"BNS(BC)","Symbol"}],
Column[{"OG","Number"}],Column[{"OG","Symbol"}], "Type"};
If[!MemberQ[{1,2,3,4},OptionValue["BCstyle"]],
Print["showMSGSym: The option \"BCstyle\" should be in {1,2,3,4} which controls how to ",
"show the BNS symbol in BC orientation if it is the same with the standard BNS symbol:\n",
"1, show \[LeftArrow] to mean the same with the left symbol\n2, does not show\n3, show in gray ",
"color\n4, show in black color"]; Abort[],
outBC[bc_]:=Switch[OptionValue["BCstyle"], 1, "\[LeftArrow]", 2, "", 3, Style[bc, Gray], 4, bc]
];
If[OptionValue["family"]=!="OG", (* for BNS *)
tmp1=MSGSymStd/@sglist;
pos={FoldList[Plus,1,#][[;;-2]],FoldList[Plus,#]}&[Length/@tmp1]+1;
tmp1=(Join@@tmp1)[[All,{3,4,6,7,1}]]\[Transpose];
tmp2=MSGSymBC[ToExpression/@StringSplit[#,"."]]&/@tmp1[[1]];
tmp2=If[#1===#2, outBC[#2], Style[#2,Red]]&@@@Transpose[{tmp1[[2]],tmp2}];
tab=Prepend[tmp1,tmp2][[{2,3,1,4,5,6}]]\[Transpose];
, (*---------------else: OG ---------------*)
tmp1=MSGSymOG/@sglist;
pos={FoldList[Plus,1,#][[;;-2]],FoldList[Plus,#]}&[Length/@tmp1]+1;
tmp1=(Join@@tmp1)[[All,{3,4,6,7,1}]]\[Transpose];
tmp2=MSGSymBC[ToExpression/@StringSplit[#,"."]]&/@tmp1[[3]];
tmp2=If[#1===#2, outBC[#2], Style[#2,Red]]&@@@Transpose[{tmp1[[4]],tmp2}];
tab=Append[tmp1,tmp2][[{1,2,3,4,6,5}]]\[Transpose];
head=head[[{4,5,1,2,3,6}]];
];
tab=Prepend[tab,head];
cls=Which[1<=#<=2, Lighter[Red,lt], 3<=#<=15, Lighter[Blue,lt], 16<=#<=74, Lighter[Orange,lt],
75<=#<=142, Lighter[Cyan,lt], 143<=#<=167, Lighter[Yellow,lt],
168<=#<=194, Lighter[Green,lt], 195<=#<=230, Lighter[Purple,lt]]&;
bgs=Table[{pos[[All,i]],{1,-1}}->cls[sglist[[i]]],{i,Length[sglist]}];
bgs=Prepend[bgs,{{1,1},{1,-1}}->Lighter[Gray,lt]];
Grid[tab, Alignment->Left, ItemSize->Full, Spacings->{2,0.3}, Frame->True,
Dividers->{{},Prepend[#->Directive[Thin,Gray]&/@pos[[1,2;;]],2->True]},
Background->If[OptionValue["color"]===True,{None,None,bgs},{}]
]
]
(* ::Section:: *)
(*Elements of MSG and MLG (Magnetic little group)*)
(* ::Subsection::Closed:: *)
(*Elements for type-2 MSG*)
Options[getType2MSGElem]={"double"->False};
getType2MSGElem[sgno_Integer,OptionsPattern[]]:=
getType2MSGElem[{sgno,type2num[sgno]},"double"->OptionValue["double"]]
getType2MSGElem[{sgno_Integer,num_Integer},OptionsPattern[]]:=Module[{tmp,MSG,G},
tmp=type2num[sgno];
If[num!=tmp, Print["getType2MSGElem: for type-2 MSG ",sgno,".num, num should be ",tmp]; Abort[]];
G=getLGElem[sgno,"\[CapitalGamma]"];
MSG=Join[Append[#,0]&/@G, Append[#,1]&/@G];
If[OptionValue["double"]===True, Join[MSG,{"bar"<>#1,#2,#3}&@@@MSG], MSG]
]
(* ::Subsection::Closed:: *)
(*Elements for type-3 MSG*)
RotNameIndex=SpaceGroupIrep`Private`RotNameIndex;
(* Get the type-III MSG elements from the "colored" generators in BC-Tab. 7.2 *)
Options[getType3MSGElem]={"double"->False};
getType3MSGElem[sgno_Integer,cgens_List,OptionsPattern[]]/;AllTrue[cgens,StringQ]:=Module[
{gens0,gens,brav,times,MSG0,SG,MSG,tmp},
gens0=SGGenElem[sgno][[1,All,1]];
If[!SubsetQ[gens0,cgens],
Print["getType3MSGElem: cgens=",cgens," is not a subset of the generators ",
"(rotation parts) ",gens0," in the BC-Tab. 3.7"];
Abort[];
];
gens=Join[{#,0}&/@Complement[gens0,cgens], {#,1}&/@cgens];
brav=getSGLatt[sgno];
times[{R1_,a1_},{R2_,a2_}]:={getRotName[brav,getRotMat[brav,R1] . getRotMat[brav,R2]],Mod[a1+a2,2]};
MSG0=SortBy[generateGroup[gens,{"E",0},times],RotNameIndex[#[[1]]]&];
tmp=Association[Rule@@@MSG0];
SG=getLGElem[sgno,"\[CapitalGamma]"];
MSG={#[[1]],#[[2]],tmp[#[[1]]]}&/@SG;
If[OptionValue["double"]===True, Join[MSG,{"bar"<>#1,#2,#3}&@@@MSG], MSG]
]
getType3MSGElem[{sgno_Integer,num_Integer},OptionsPattern[]]:=Module[{tmp},
tmp=BCTab7d2[sgno]//Keys;
If[tmp=={}, Print["getType3MSGElem: There is no type-3 MSG begin with ",sgno]; Abort[],
If[!MemberQ[tmp,num],
Print["getType3MSGElem: for type-3 MSG ",sgno,".num, num should be in ",
Row[{#,"(", MSGSymStd[{sgno,#}],")"}]&/@tmp];
Abort[]]
];
getType3MSGElem[sgno,BCTab7d2[sgno,num],"double"->OptionValue["double"]]
]
(* ::Subsection::Closed:: *)
(*Elements for type-4 MSG*)
Options[getType4MSGElem]={"double"->False};
getType4MSGElem[{sgno_Integer,num_Integer},OptionsPattern[]]:=Module[{tmp,brav,BWlatt,A,MSG,G},
tmp=type4nums[sgno];
If[tmp=={}, Print["getType4MSGElem: There is no type-4 MSG begin with ",sgno]; Abort[],
If[!MemberQ[tmp,num],
Print["getType4MSGElem: for type-4 MSG ",sgno,".num, num should be in ",
Row[{#,"(",MSGSymStd[{sgno,#}],")"}]&/@tmp];
Abort[]]
];
brav=getSGLatt[sgno];
(*For orthorhombic system, we have to use the MSG symbol conforming to the BC orientation*)
If[16<=sgno<=74 (*orth system*),
BWlatt=StringTake[type4MSGSymTextBC[{sgno,num}],3],
BWlatt=StringTake[type4MSGSymText[{sgno,num}],3]
];
A=type4AUTrans[brav,BWlatt];
G=Append[#,0]&/@getLGElem[sgno,"\[CapitalGamma]"];
MSG=Join[G, MapAt[modone,MSGSeitzTimes[brav][A,#]&/@G,{All,2}]];
If[OptionValue["double"]===True, Join[MSG,{"bar"<>#1,#2,#3}&@@@MSG], MSG]
]
(* ::Subsection::Closed:: *)
(*getMSGElem: get elements of MSG*)
Options[getMSGElem]={"double"->False};
getMSGElem[{sgno_, num_},OptionsPattern[]]:=Module[{tmp,MSG,G,nums,pos,fun},
{nums,pos}=checkMSGinput[{sgno,num},"getMSGElem"];
pos=pos[[1,1]];
fun=ToExpression[cont<>"getType"<>ToString[pos]<>"MSGElem"];
If[pos==1,
Append[#,0]&/@getLGElem[sgno,"\[CapitalGamma]","DSG"->OptionValue["double"]],
fun[{sgno,num},"double"->OptionValue["double"]]
]
]
(* ::Subsection::Closed:: *)
(*getMLGElem: get elements of MLG*)
(* Get the magnetic little group. MSG is the element list of the magnetic space group.*)
getMLGElem[brav_String, MSG_List, k_]/;VectorQ[k]:=Module[{rotk,sele,LG,mLGu,mLGau},
rotk={getRotMatOfK[brav,StringReplace[#[[1]],"bar"->""]] . k, #}&/@MSG;
sele=Select[rotk,If[#[[2,3]]==0,keqmod[k,#[[1]]],keqmod[-k,#[[1]]]]&];
mLG=sele[[All,2]]; mLGu=Select[mLG,#[[3]]==0&]; mLGau=Select[mLG,#[[3]]==1&];
Join[mLGu,mLGau] (*put all unitary elements in front*)
]
Options[getMLGElem]={"double"->False};
getMLGElem[{sgno_, num_},k_,OptionsPattern[]]:=
Module[{ks,brav,tmp,kco,BZs,MSG},
MSG=getMSGElem[{sgno,num},"double"->OptionValue["double"]];
brav=getSGLatt[sgno];
kco=If[StringQ[k], kBCcoord[sgno,k][[1,1]], k];
getMLGElem[brav,MSG,kco]
]
(* ::Subsection::Closed:: *)
(*showMSGSeitz*)
Options[showMSGSeitz]={"format"->"std", "fullbar"->True, "antiUcolor"->Red};
showMSGSeitz[{R_,v_,au_},OptionsPattern[]]:=Module[{Rv,color,c},
Rv=showSeitz[{R,v}, "format"->OptionValue["format"], "fullbar"->OptionValue["fullbar"]];
color=OptionValue["antiUcolor"];
If[!ColorQ[color], Print["showMSGSeitz: option \"antiUcolor\" should be a color."]; Abort[]];
Switch[OptionValue["format"],
"std"|"simple", If[au==0, Rv, Style[Superscript[Rv,"\[Prime]"],color]],
"TeX", c="\\color[rgb]"<>ToString@(List@@color);
If[au==0, Rv, "${"<>c<>StringTake[Rv,{2,-2}]<>"'}$"]
]
];
(* ::Section:: *)
(*Common utilities*)
(* ::Subsection::Closed:: *)
(*checkMSGinput*)
checkMSGinput[{sgno_,num_}, fun_String]:=Module[{nums,pos,spc,tab,sty1},
If[!IntegerQ[sgno]||sgno<1||sgno>230,
Print[fun<>": {sgno,num} should be any of the 1651 integer pairs listed as follow:\n",
Partition[MSGSymText//Keys//Sort,UpTo[10]]//Grid[#,Alignment->Left,Spacings->{0.5,0.2}]&];
Abort[];
];
nums={type1num[sgno],type2num[sgno],type3nums[sgno],type4nums[sgno]};
pos=Position[nums,num];
If[pos=={},
spc=StringReplace[fun,_->" "]<>" ";
sty1={{}, #->GrayLevel[0.7]&/@{2,3,Length[nums[[3]]]+3}};
tab=Grid[#,Alignment->Left,Frame->True,FrameStyle->Thin, Dividers->sty1,Spacings->2]&;
Print[fun<>": for MSG ",sgno,".num, num should be in ",nums,".\n",spc<>"Refer to:\n", spc,
MSGSymStd[sgno][[All,{3,4,1}]]//tab];
Abort[]
];
{nums,pos}
]
(* ::Subsection::Closed:: *)
(*Multiplication for (double) magnetic space group*)
MSGSeitzTimes[brav_][{Rname1_,v1_,antiU1_}, {Rname2_,v2_,antiU2_}]/;SubsetQ[{1,0},{antiU1,antiU2}]:=
Append[SeitzTimes[brav][{Rname1,v1},{Rname2,v2}], Mod[antiU1+antiU2,2]]
MSGSeitzTimes[brav_][Rvau1_,Rvau2_,more__]:=Fold[MSGSeitzTimes[brav],Rvau1,{Rvau2,more}]
MSGinvSeitz[brav_][{Rname1_,v1_,antiU1_}]/;MemberQ[{1,0},antiU1]:=
Append[invSeitz[brav][{Rname1,v1}],antiU1]
MSGpowerSeitz[brav_][{Rname1_,v1_,antiU1_},n_Integer]/;MemberQ[{1,0},antiU1]&&n>=0:=
Append[powerSeitz[brav][{Rname1,v1},n],Mod[n*antiU1,2]]
(*NOTE: For double MSG, theta^2\[Equal]barE, where theta is the time reversal *)
DMSGSeitzTimes[brav_][{Rname1_,v1_,antiU1_}, {Rname2_,v2_,antiU2_}]/;SubsetQ[{1,0},{antiU1,antiU2}]:=
Module[{au=antiU1+antiU2, Rv},
Rv=DSGSeitzTimes[brav][{Rname1,v1},{Rname2,v2}];
If[au<2, Append[Rv,au], Append[DSGSeitzTimes[brav][Rv,{"barE",{0,0,0}}],0]]
]
DMSGSeitzTimes[brav_][Rvau1_,Rvau2_,more__]:=Fold[DMSGSeitzTimes[brav],Rvau1,{Rvau2,more}]
DMSGinvSeitz[brav_][{Rname1_,v1_,antiU1_}]/;MemberQ[{1,0},antiU1]:=
With[{iRv=DSGinvSeitz[brav][{Rname1,v1}]},
If[antiU1==0, Append[iRv,0], Append[DSGSeitzTimes[brav][iRv,{"barE",{0,0,0}}],1]]]
DMSGpowerSeitz[brav_][{Rname1_,v1_,antiU1_},n_Integer]/;MemberQ[{1,0},antiU1]&&n>=0:=
Module[{Rvn},
Rvn=DSGpowerSeitz[brav][{Rname1,v1},n];
Switch[Mod[n*antiU1,4],
0, Append[Rvn,0], 1, Append[Rvn,1],
2, Append[DSGSeitzTimes[brav][Rvn,{"barE",{0,0,0}}],0],
3, Append[DSGSeitzTimes[brav][Rvn,{"barE",{0,0,0}}],1]
]
]
(* ::Subsection::Closed:: *)
(*Multiplication for (double) magnetic point group*)
Options[checkMagRotInput]={"double"->False};
checkMagRotInput[R_, OptionsPattern[]]:=Module[{rots,rots2},
rots=Keys[getSpinRotOp];
If[OptionValue["double"]=!=True, rots=rots[[;;Length[rots]/2]]];
rots2=Join[rots, #<>"'"&/@rots];
If[StringQ[R]&&MemberQ[rots2,R]||ListQ[R]&&Length[R]==2&&MemberQ[rots,R[[1]]]&&MemberQ[{0,1},R[[2]]],
Return@If[StringQ[R], If[StringTake[R,-1]=="'", {StringTake[R,{1,-2}],1},{R,0}], R],
Print["The input ",R," should be one of the two forms:\n",
"(1) The string of rotation name for an element in the magnetic point group, i.e. \"Rname\" or \"Rname'\".\n",
"(2) {\"Rname\",0} for unitary rotation (equivalent to \"Rname\") or {\"Rname\",1} for antiunitary rotation ",
"(equivalent to \"Rname'\").\nAnd Rname should be in the list\n",rots,".\n"
]; Abort[];
]
]
MagRotTimes[R1_,R2_]:=Module[{rot1,rot2},
rot1=checkMagRotInput[R1];
rot2=checkMagRotInput[R2];
{RotTimes[rot1[[1]],rot2[[1]]], Mod[rot1[[2]]+rot2[[2]],2]}
]
MagRotTimes[R1_,R2_,more__]:=Fold[MagRotTimes,R1,{R2,more}]
invMagRot[R_]:=With[{rot=checkMagRotInput[R]}, MapAt[invRot,rot,1]]
powerMagRot[R_,n_Integer]:=With[{rot=checkMagRotInput[R]}, {powerRot[rot[[1]],n],Mod[rot[[2]]*n,2]}]
DMagRotTimes[R1_,R2_]:=Module[{rot1,rot2,rot,au},
rot1=checkMagRotInput[R1,"double"->True];
rot2=checkMagRotInput[R2,"double"->True];
rot=DRotTimes[rot1[[1]],rot2[[1]]]; au=rot1[[2]]+rot2[[2]];
If[au==2, rot=DRotTimes[rot,"barE"]; au=0];
{rot,au}
]
DMagRotTimes[R1_,R2_,more__]:=Fold[DMagRotTimes,R1,{R2,more}]
invDMagRot[R_]:=Module[{rot=checkMagRotInput[R,"double"->True],r,au},
r=invDRot[rot[[1]]]; au=rot[[2]];
If[au==1, r=DRotTimes[r,"barE"]];
{r,au}
]
powerDMagRot[R_,n_Integer]:=Module[{rot=checkMagRotInput[R,"double"->True],r},
r=powerDRot[rot[[1]],n];
Switch[Mod[n*rot[[2]],4],
0, {r,0}, 1, {r,1}, 2, {DRotTimes[r,"barE"],0}, 3, {DRotTimes[r,"barE"],1}
]
]
(* ::Subsection::Closed:: *)
(*getMagKStar*)
Options[getMagKStar]={"cosets"->False};
getMagKStar[{sgno_, mno_}, kin_, OptionsPattern[]]:=Module[{k,MSG,brav,kall,star0,star,cosets},
MSG=getMSGElem[{sgno,mno}]; brav=getSGLatt[sgno];
k=If[!StringQ[kin], kin, kBCcoord[sgno,kin][[1,1]]];
kall={If[#[[3]]==0,1,-1]*getRotMatOfK[brav,#[[1]]] . k, #}&/@MSG;
star0=Gather[kall,keqmod[#1[[1]],#2[[1]]]&];
star=star0[[All,1,1]]; cosets=star0[[All,All,2]];
If[OptionValue["cosets"]===True, {star,cosets}, star]
]
(* ::Subsection::Closed:: *)
(*getMSGType*)
getMSGType[{sgno_, mno_}]:=checkMSGinput[{sgno,mno},"getMSGType"][[2,1,1]]
(* ::Section:: *)
(*Magnetic point group (MPG)*)
(* ::Subsection::Closed:: *)
(*common*)
checkMPGinput[mpg_, fun_String]:=Module[{mpgno,mpgs,err=False,adjust},
If[IntegerQ[mpg]&&1<=mpg<=32,
Print[fun<>": Use any item as input listed as follow:\n",
TableForm[MapAt[InputForm,Select[MPGinfo[[All,2;;5]],#[[1,1]]==mpg&],{All,2;;4}],TableDepth->2]];
Abort[];
];
mpgno=Position[MPGinfo[[All,2;;5]],mpg,{2}];
If[mpgno!={}, mpgno=mpgno[[1,1]], err=True];
If[err,
adjust=MPGinfo[[All,2;;5]];
adjust=MapAt[InputForm,adjust,{All,2;;4}];
adjust=MapAt[Grid[{{#}},ItemSize->3.8,Alignment->Left]&, adjust, {All,1}];
adjust=MapAt[Grid[{{#}},ItemSize->3,Alignment->Left]&, adjust, {All,2}];
adjust=MapAt[Grid[{{#}},ItemSize->5.5,Alignment->Left]&, adjust, {All,3}];
adjust=MapAt[Grid[{{#}},ItemSize->5.5,Alignment->Left]&, adjust, {All,4}];
mpgs=TableForm@Partition[Row[#,"|"]&/@adjust,UpTo[3]];
Print[fun<>": To specify a mangnetic point group, use any one as input listed as follow:\n",mpgs];
Abort[]
];
mpgno
]
(* ::Subsection::Closed:: *)
(*getMPGElem and showMagRot*)
Options[getMPGElem]={"double"->False};
getMPGElem[mpg_, OptionsPattern[]]:=Module[{n,msg,elms},
n=checkMPGinput[mpg,"getMPGElem"]; msg=MPGinfo[[n,8]];
elms=getMLGElem[msg,"\[CapitalGamma]"][[All,{1,3}]];
If[OptionValue["double"]===True, elms=Join[elms, MapAt["bar"<>#&, elms, {All,1}]]];
elms
]
Options[showMagRot]={"format"->"std", "fullbar"->False, "antiUcolor"->Red};
showMagRot[R_,OptionsPattern[]]:=Module[{R0,hasbar,fmt,rot,fullbar,au,color},
fmt=OptionValue["format"]; fullbar=OptionValue["fullbar"];
If[!MemberQ[{"text","simple","std","TeX"},fmt],
Print["showMagRot: option \"format\" should be in ",InputForm/@{"text","simple","std","TeX"}]; Abort[];
];
rot=checkMagRotInput[R,"double"->True]; au=rot[[2]];
If[fmt=="text", Return@If[au==0, rot[[1]], rot[[1]]<>"'"]];
R0=showRot[rot[[1]],"format"->fmt,"fullbar"->fullbar];
If[au==0, Return[R0]];
R0=Switch[fmt, "simple"|"std", Superscript[R0,"\[Prime]"], "TeX", "{"<>R0<>"}'"];
color=OptionValue["antiUcolor"]; If[color===None, Return[R0]];
Switch[fmt, "simple"|"std", Style[R0,color],
"TeX", "{\\color[rgb]"<>ToString@(List@@color)<>R0<>"}" ]
]
(* ::Subsection::Closed:: *)
(*showMPGinfo*)
Options[showMPGinfo]={"long"->True, "color"->True, "elem"->False};
showMPGinfo[OptionsPattern[]]:=showMPGinfo[All,(#->OptionValue[#])&/@{"long","color","elem"}]
showMPGinfo[range_, OptionsPattern[]]:=Module[{stab,lt=0.90,bgc,bgs,cls,ncol,ltab,note,idx,nout,ifelm},
bgc[n1_,n2_,color_]:=#->color&/@Range[n1,n2];
idx=range;
If[IntegerQ[idx], idx=If[idx==0,All,{idx}]];
If[!(VectorQ[idx,IntegerQ]||Head[idx]===Span||idx===All),
Print["showMPGinfo: range can be an integer, a list of integers, a span, or just All ",
"to specify the magnetic point groups to show"]; Abort[]];
Check[idx=Range[Length[MPGinfo]][[DeleteCases[idx,0]]],
Print["showMPGinfo: out of range [0,",Length[MPGinfo],"]!"]; Abort[],
{Part::partw,Part::take}];
stab={Row[{"(",#[[1]],")"}],#[[3]],MSGSymStd[#[[5]]]}&/@MPGinfo[[idx]];
stab=Grid[{#}, ItemSize->{{3,3,Full}}, Alignment->Left, Spacings->0]&/@stab;
cls=Join[bgc[1,5,Lighter[Red,lt]], bgc[6,16,Lighter[Blue,lt]], bgc[17,28,Lighter[Orange,lt]],
bgc[29,59,Lighter[Cyan,lt]], bgc[60,75,Lighter[Yellow,lt]],
bgc[76,106,Lighter[Green,lt]],bgc[107,122,Lighter[Purple,lt]]]//Association;
ncol=5; nout=Length[idx];
bgs=Thread[Flatten[Table[{i,j},{i,Ceiling[nout/ncol]},{j,ncol}],1][[;;nout]] -> cls/@idx];
stab=Partition[stab, UpTo[ncol]]//Grid[#,Alignment->Left, Spacings->{2,0.3},
Background->If[OptionValue["color"],{None,None,bgs},{}]]&;
If[OptionValue["long"]==False, Return[stab]];
ifelm=If[OptionValue["elem"]===True,#,Nothing]&;
ltab={#[[1]], #[[3]], #[[4]], MSGSymStd[#[[5]]],
Row[{MSGSymStd[PGinfo[[#[[6]],3]]]," (",MSGSymStd[PGinfo[[#[[6]],2]]],")"}],
#[[7]], MSGSymStd[#[[8]]], ifelm[showMagRot/@getMPGElem[#[[2]]]]}&/@MPGinfo[[idx]];
ltab=Prepend[ltab, {Column[{"Seq.","No."}], Column[{"Number","(short)"}], Column[{"Number","(long)"}],
Column[{"Symbol"}], Column[{"Unitary","subgroup H"}],
Column[{"Type"}], "First MSG",ifelm["Elements of the MPG"]}];
cls=Prepend[Thread[Range[2,nout+1] -> Values[cls][[idx]]], 1->Lighter[Gray,lt]];
ltab=Grid[ltab, Alignment->Left, Spacings->{2,0.3}, Frame->True, Dividers->{{},{2->True}},
Background->If[OptionValue["color"],{{},cls},{}]];
note="The symbol of a magnetic point group (MPG) here is determined by the BNS symbol of\n"<>
"the first magnetic space group (MSG) with this MPG. And the order of MPGs also follows\n"<>
"the order of BNS MSG numbers. The symbols and long numbers here are consistent with\n"<>
"those on the BCS website. Note: the symbols and order of the type-3 MPGs here are not\n"<>
"always the same with those in BC-Tab. 7.1. For example, the mmm' in BC-Tab. 7.1 is \n"<>
"m'mm here, and 2/m' precedes 2'/m in BC-Tab. 7.1 while the order is reversed here.";
Column[{ltab,note}]
]
(* ::Subsection::Closed:: *)
(*getMPGCorep*)
Options[getMPGCorep]={"double"->False,"trace"->False};
getMPGCorep[mpg_,OptionsPattern[]]:=Module[{n,msgno,smap,dmap,MPG,subno,H,Hstd,A,nsir,subir,dbl,
matN,cordict,type,ir,nir,cor,lb,ncor,clb,ch,AH,elmidx,times,Hidx,AH2idx,inv,iAuA,i,j,subidx,
paired,aiA,aA,iAa,tmp,totrace},
n=checkMPGinput[mpg,"getMPGCorep"];
(*map the elements of the unitary subgroup to those of getPGElem*)
Switch[n,
22, smap=dmap={"\[Sigma]y"->"\[Sigma]z","bar\[Sigma]y"->"bar\[Sigma]z"},
26, smap=dmap={"C2x"->"C2z","\[Sigma]y"->"\[Sigma]x","\[Sigma]z"->"\[Sigma]y","barC2x"->"barC2z","bar\[Sigma]y"->"bar\[Sigma]x","bar\[Sigma]z"->"bar\[Sigma]y"},
46|50, smap=dmap={"\[Sigma]da"->"\[Sigma]y","\[Sigma]db"->"\[Sigma]x","bar\[Sigma]da"->"bar\[Sigma]y","bar\[Sigma]db"->"bar\[Sigma]x"},
56, smap=dmap={"C2a"->"C2y","C2b"->"C2x","\[Sigma]da"->"\[Sigma]y","\[Sigma]db"->"\[Sigma]x","barC2a"->"barC2y",
"barC2b"->"barC2x","bar\[Sigma]da"->"bar\[Sigma]y","bar\[Sigma]db"->"bar\[Sigma]x"},
73, smap={"\[Sigma]d1"->"\[Sigma]v2","\[Sigma]d2"->"\[Sigma]v3","\[Sigma]d3"->"\[Sigma]v1"}; dmap={"\[Sigma]d1"->"bar\[Sigma]v2","\[Sigma]d2"->"bar\[Sigma]v3",
"\[Sigma]d3"->"\[Sigma]v1","bar\[Sigma]d1"->"\[Sigma]v2","bar\[Sigma]d2"->"\[Sigma]v3","bar\[Sigma]d3"->"bar\[Sigma]v1"},
89, smap={"C21pp"->"C23p","C22pp"->"C21p","C23pp"->"C22p"}; dmap={"C21pp"->"C23p","C22pp"->"barC21p",
"C23pp"->"barC22p","barC21pp"->"barC23p","barC22pp"->"C21p","barC23pp"->"C22p"},
104,smap={"C21pp"->"C23p","C22pp"->"C21p","C23pp"->"C22p","\[Sigma]v1"->"\[Sigma]d3","\[Sigma]v2"->"\[Sigma]d1","\[Sigma]v3"->"\[Sigma]d2"};
dmap={"C21pp"->"C23p","C22pp"->"barC21p","C23pp"->"barC22p","\[Sigma]v1"->"\[Sigma]d3","\[Sigma]v2"->"bar\[Sigma]d1","\[Sigma]v3"->"bar\[Sigma]d2",
"barC21pp"->"barC23p","barC22pp"->"C21p","barC23pp"->"C22p","bar\[Sigma]v1"->"bar\[Sigma]d3","bar\[Sigma]v2"->"\[Sigma]d1","bar\[Sigma]v3"->"\[Sigma]d2"},
_, smap=dmap={}
];
msgno=MPGinfo[[n,2]]; subno=MPGinfo[[n,6]];
dbl=OptionValue["double"]===True;
MPG=getMPGElem[msgno,"double"->dbl];
subir=getPGIrepTab[subno,"double"->dbl,"trace"->False];
lb=subir["label"]; ir=subir["irep"]; nir=Length[ir]; Hstd=subir["elem"];
cordict=<||>;
cordict["number"]=MPGinfo[[n,{2,3}]]; cordict["symbol"]=MPGinfo[[n,5]];
cordict["USubG"]=PGinfo[[subno,1;;3]];
nsir=PGinfo[[subno,5]];
totrace=Map[If[MatrixQ[#],Simplify@Tr[#],#]&,#,{2}]&;
If[msgno[[2]]==1, (*------for type-1 MPG-------*)
cordict["elem"]={#,0}&/@Hstd;
cordict["A"]=None; cordict["N"]=None;
cordict["label"]=lb; cordict["type"]=Table["x",nir];
cordict["subidx"]=Range[nir];
cordict["sindex"]=Range[nsir];
cordict["dindex"]=Complement[Range[nir],Range[nsir]];
cordict["corep"]=If[OptionValue["trace"]===True, totrace[ir], ir];
Return[cordict]
];
ch=totrace[ir];
H=Select[MPG,#[[2]]==0&]; AH=Select[MPG,#[[2]]==1&]; A=AH[[1]];
elmidx=Association@Table[Hstd[[i]]->i,{i,Length[Hstd]}];
elmidx=elmidx/@(H[[All,1]]/.If[dbl,dmap,smap]);
ch=ch[[All,elmidx]]; ir=ir[[All,elmidx]];
times=If[dbl,DMagRotTimes,MagRotTimes];
Hidx=Association@Thread[H->Range[Length[H]]];
AH2idx=Hidx[times[#,#]]&/@AH;
type=Simplify[Total[#[[AH2idx]]]/Length[H]&/@ch]/.{1->"a",-1->"b",0->"c"};
inv=If[dbl,invDMagRot,invMagRot];
iAuA=Hidx@times[times[inv[A],#],A]&/@H;
matN=Table[None,nir];
For[i=1,i<=nir,i++, If[type[[i]]=="c", Continue[]];
matN[[i]]=findMatrixN[ir[[i]],ir[[i,iAuA]]\[Conjugate]]
];
subidx={}; paired=Table[False,nir];
For[i=1,i<=nir,i++, If[paired[[i]], Continue[]];
If[type[[i]]!="c", subidx=Append[subidx,i],
j=First@Select[Range[i+1,nir],Simplify[Conjugate@ch[[i,iAuA]]==ch[[#]]]&];
subidx=Append[subidx,{i,j}]; paired[[j]]=True;
]
];
ncor=Length[subidx]; clb=cor=Table[{},ncor];
aiA=Hidx@times[#,inv[A]]&/@AH;
aA=Hidx@times[#,A]&/@AH;
iAa=Hidx@times[inv[A],#]&/@AH;
For[i=1,i<=ncor,i++, j=subidx[[i]];
If[IntegerQ[j],
tmp=If[MatrixQ[ir[[j,1]]], # . matN[[j]]&/@ir[[j,aiA]], ir[[j,aiA]]];
If[type[[j]]=="a",
cor[[i]]=Join[ir[[j]], tmp]; clb[[i]]=lb[[j]], (*---next line else: b---*)
cor[[i]]=Join[ArrayFlatten[{{#,0},{0,#}}]&/@ir[[j]],ArrayFlatten[{{0,-#},{#,0}}]&/@tmp];
clb[[i]]=#<>#&/@lb[[j]]
], (*---------else: for type c----------*)
tmp=Mulliken2str@lb[[j[[1]],1]];
If[StringTake[tmp,1]=="1",
tmp=str2Mulliken@StringTake[tmp,{2,-1}],
If[StringLength[tmp]>4&&StringTake[tmp,4]=="bar1",
tmp=str2Mulliken["bar"<>StringTake[tmp,{5,-1}]], (*else*) tmp=StringJoin[lb[[j,1]]]
];
];
clb[[i]]={tmp,StringJoin[lb[[j,2]]]};
j=j[[1]];
cor[[i]]=Join[ArrayFlatten[{{#1,0},{0,#2}}]&@@@Transpose[{ir[[j]],ir[[j,iAuA]]\[Conjugate]}],
ArrayFlatten[{{0,#1},{#2,0}}]&@@@Transpose[{ir[[j,aA]],ir[[j,iAa]]\[Conjugate]}] ];
];
];
tmp=If[IntegerQ[#],#,#[[1]]]&/@subidx;
cordict["elem"]=Join[H,AH];
cordict["A"]=A; cordict["N"]=matN[[tmp]];
cordict["label"]=clb; cordict["type"]=type[[tmp]];
cordict["subidx"]=subidx;
tmp=Position[subidx,nsir][[1,1]];
cordict["sindex"]=Range[tmp];
cordict["dindex"]=Complement[Range[ncor],Range[tmp]];
cordict["corep"]=If[OptionValue["trace"]=!=True,cor,totrace[cor]];
cordict
]
(* ::Subsection::Closed:: *)
(*showMPGCorep*)
Options[showMPGCorep]={"double"->True,"rotmat"->True,"elem"->All,"corep"->All,"trace"->False,
"spin"->"downup","cartesian"->False,"linewidth"->2};
showMPGCorep[mpg_, OptionsPattern[]]:=Module[{n,mpgno,mpgcor,label,cor,elmopt,tmp,elmidx,dbl,type,
elems,nelm,elmerr,nscor,ndcor,ncor,sidx,didx,txtirl,iropt,irerr,iridx,row1,rots1,rots2,brav,tab,
nstart,grid,sty1,sty2,bg0,bg1,bg1a,bg2,bg3,bg4,bg5,spl,box},
(*-------check option "double"---------*)
dbl=OptionValue["double"];
If[!MemberQ[{True,False,Full},dbl],
Print["showMPGCorep: \"double\" should be one of True (default), False, or Full:\n",
"True: For coreps of double magnetic point groups. Only half of all elements, i.e. the ones without bar, are shown.\n",
"Full: For coreps of double magnetic point groups. All elements are shown.\n",
"False: For coreps of single magnetic point groups.\n"];
Abort[]
];
n=checkMPGinput[mpg,"showMPGCorep"]; mpgno=MPGinfo[[n,2]];
mpgcor=getMPGCorep[mpgno,"double"->OptionValue["double"]=!=False, "trace"->OptionValue["trace"]];
elems=mpgcor["elem"]; cor=mpgcor["corep"]; label=mpgcor["label"];
sidx=mpgcor["sindex"]; didx=mpgcor["dindex"]; type=mpgcor["type"];
nscor=Length[sidx]; ndcor=Length[didx]; ncor=nscor+ndcor;
nelm=Length[elems];
If[dbl=!=False,
tmp=Select[elems,StringTake[#[[1]]<>"xxx",3]!="bar"&];
tmp=Join[tmp, Select[elems,StringTake[#[[1]]<>"xxx",3]=="bar"&]];
tmp=Association@Table[tmp[[i]]->i,{i,nelm}]/@elems;
elems=elems[[tmp]];
cor=cor[[All,tmp]]
];
(*-------check option "elem"---------*)
elmopt=OptionValue["elem"];
elmerr:=Print["showMPGCorep: \"elem\" aims to reorder the columns and it can be:\n",
"A list of rotation names (elements). OR\n",
"A list of integers (or a span) for their sequence numbers. Refer to\n",
Grid[Partition[Grid[{#},ItemSize->{{1.5,Full}},Alignment->Left]&/@
Transpose@{Range[nelm],InputForm[showMagRot[#,"format"->"text"]]&/@elems},UpTo[10]],
ItemSize->Full, Frame->All, Alignment->Left, FrameStyle->Gray] ];
If[elmopt===0, elmopt=All];
If[StringQ[elmopt]||IntegerQ[elmopt], elmopt={elmopt}];
elmidx=elmopt;
If[VectorQ[elmidx,StringQ],
tmp=showMagRot[#,"format"->"text"]&/@elems;
If[SubsetQ[tmp,elmidx], elmidx=Position[tmp,#][[1,1]]&/@elmidx, elmerr; Abort[]], (*next line else*)
If[!(VectorQ[elmidx,IntegerQ]||Head[elmidx]===Span||elmidx===All), elmerr; Abort[]]
];
Check[elmidx=Range[nelm][[DeleteCases[elmidx,0]]],
Print["showMPGCorep: out of range! There are ",nelm," elements in total."]; Abort[],
{Part::partw,Part::take}];
(*-------check option "corep"---------*)
iropt=OptionValue["corep"];
irerr:=Print["showMPGCorep: \"corep\" aims to reorder the coreps (rows) and it can be:\n",
"An integer, a list of integers, a span, or just All (default) for the corep sequence numbers. ",
"The range is 1 to ", ncor, "."];
If[iropt===0, iropt=All];
iridx=If[StringQ[iropt]||IntegerQ[iropt], {iropt}, iropt];
If[!(VectorQ[iridx,IntegerQ]||Head[iridx]===Span||iridx===All), irerr; Abort[]]
Check[iridx=Range[ncor][[DeleteCases[iridx,0]]],
Print["showMPGCorep: out of range! There are ",ncor," coreps in total."]; Abort[],
{Part::partw,Part::take}];
If[dbl===True&&elmopt===All, nelm=nelm/2; elmidx=elmidx[[;;nelm]]];
cor=cor[[All,elmidx]]; elems=elems[[elmidx]];
tab=Map[formatRepMat,cor,{2}];
tab=Map[If[MatrixQ[#],MatrixForm[#],#]&, tab, {2}];
tab=Table[{i,Sequence@@label[[i]],type[[i]],Sequence@@tab[[i]]},{i,iridx}];
spl:=Sequence@@Table[SpanFromLeft,3];
tmp=Column[{Row[{"MPG: ", mpgcor["number"][[2]],", ",MSGSymStd@mpgcor["symbol"]}],
Row[{"USubG: ", MSGSymStd@mpgcor["USubG"][[3]], " (",str2Mulliken@mpgcor["USubG"][[2]],")"}]
}];
(*\:6ce8\:610f\:ff1a\:5982\:679c\:4e0d\:5bf9\:7fa4\:5143\:52a0\:4e2abox\:5c01\:88c5\:4e00\:4e0b\:ff0c\:5e26bar\:7684\:7fa4\:5143\:4f1a\:5bfc\:81f4\:4e0a\:4e00\:884c\:7684\:7f16\:53f7\:884c\:7684\:884c\:9ad8\:5f02\:5e38\:53d8\:5927*)
box=Grid[{{#}},Spacings->{0,0},Alignment->{Center,Center}]&;
row1={{tmp,spl,Sequence@@box/@elmidx},
{SpanFromAbove,Sequence@@Table[SpanFromBoth,3],Sequence@@(box@showMagRot[#]&/@elems)}};
If[OptionValue["rotmat"]=!=False,
brav=If[16<=mpgno[[1]]<=27, "HexaPrim", "CubiPrim"];
If[OptionValue["cartesian"]===True,
rots1=RotMatCart[StringReplace[#,"bar"->""]]&/@elems[[All,1]]; tmp="(cart.)",
rots1=getRotMat[brav,StringReplace[#,"bar"->""]]&/@elems[[All,1]]; tmp=Nothing
];
rots1={Column[{"Rotation","matrix",tmp}], spl, Sequence@@MatrixForm/@rots1};
rots2=ComplexExpand@First@getSpinRotOp[#]&/@elems[[All,1]];
tmp="(\[DownArrow]\[UpArrow])";
If[OptionValue["spin"]==="updown",
tmp="(\[UpArrow]\[DownArrow])"; rots2={{0,1},{1,0}} . # . {{0,1},{1,0}}&/@rots2
];
rots2={Column[{"Spin"<>tmp,"rotation","matrix"}], spl, Sequence@@MatrixForm/@rots2};
tab=Prepend[tab,rots1]; nstart=4;
If[dbl=!=False, tab=Insert[tab,rots2,2]; nstart=5];
, (*----else----*)
nstart=3
];
tab=Join[row1,tab];
sty1=Directive[Black,Thickness[OptionValue["linewidth"]]];
sty2=Directive[Thin,GrayLevel[0.8]];
bg0={1,1}->Lighter[Red,0.9];
bg1a={{2,nstart-1},{1,2}}->Lighter[Yellow,0.85];
bg1={{1,nstart-1},{2,-1}}->Lighter[Yellow,0.9];
sidx=Position[iridx,#][[1,1]]&/@Intersection[sidx,iridx];
didx=Complement[Range@Length[iridx],sidx];
bg2={{#,#}+nstart-1,{1,-1}}->Lighter[Green,0.95]&/@sidx;
bg3={{#,#}+nstart-1,{1,-1}}->Lighter[Blue,0.95]&/@didx;
bg4={{#,#}+nstart-1,{1,4}}->Lighter[Green,0.90]&/@sidx;
bg5={{#,#}+nstart-1,{1,4}}->Lighter[Blue,0.90]&/@didx;
grid=Grid[tab, Frame->All, Alignment->{Center,Center}, ItemSize->{{{},{2->3.1,3->2.9}},{}},
Dividers->{{{{sty2}},Join[#->sty1&/@{1,5,-1},#->sty2&/@{2}]},
{{{sty2}},#->sty1&/@{1,3,-1}}},
Background->{None,None,{bg0,bg1a,bg1,Sequence@@Join[bg2,bg3,bg4,bg5]}}
]
]
(* ::Subsection::Closed:: *)
(*MPGCorepDirectProduct*)
Options[MPGCorepDirectProduct]={"output"->1};
MPGCorepDirectProduct[mpg_, coreps1_, OptionsPattern[]]/;!VectorQ[Flatten[{coreps1}],MemberQ[{Rule,RuleDelayed},Head[#]]&]:=
MPGCorepDirectProduct[mpg, coreps1, coreps1, "output"->OptionValue["output"]]
MPGCorepDirectProduct[mpg_, OptionsPattern[]]:=MPGCorepDirectProduct[mpg, All, All, "output"->OptionValue["output"]]
MPGCorepDirectProduct[mpg_,coreps1_,coreps2_,OptionsPattern[]]/;
!Or@@(VectorQ[Flatten[{#}],MemberQ[{Rule,RuleDelayed},Head[#]]&]&/@{coreps1,coreps2}):=Module[{n,
mpgno,mpgcor,d,cijk,sub,type,subidx,subidx1,err,cr1idx,cr2idx,label,ncr,outopt,out1,out2,out3,dim},
n=checkMPGinput[mpg,"MPGCorepDirectProduct"]; mpgno=MPGinfo[[n,2]];
mpgcor=getMPGCorep[mpgno,"double"->True,"trace"->True];
sub=mpgcor["USubG"]; type=mpgcor["type"]; subidx=mpgcor["subidx"];
label=mpgcor["label"]; ncr=Length[label]; dim=mpgcor["corep"][[All,1]];
(*-------check input coreps1 and coreps2--------*)
err:=Print["MPGCorepDirectProduct: Inputs coreps1 and coreps2 can be:\n",
"An integer OR a list of integers for the corep sequence numbers. OR\n",
"A span such as 1;;5. OR All. Refer to\n",
Grid[Prepend[Transpose@label,Range[ncr]], Frame->All,FrameStyle->Gray] ];
If[coreps1===0||coreps2===0, err; Abort[]];
cr1idx=If[IntegerQ[coreps1], {coreps1}, coreps1];
If[!(VectorQ[cr1idx,IntegerQ]||Head[cr1idx]===Span||cr1idx===All), err; Abort[]]
Check[cr1idx=Range[ncr][[DeleteCases[cr1idx,0]]],
Print["MPGCorepDirectProduct: out of range! There are ",ncr," coreps in total."]; Abort[], {Part::partw,Part::take}];
cr2idx=If[IntegerQ[coreps2], {coreps2}, coreps2];
If[!(VectorQ[cr2idx,IntegerQ]||Head[cr2idx]===Span||cr2idx===All), err; Abort[]]
Check[cr2idx=Range[ncr][[DeleteCases[cr2idx,0]]],
Print["MPGCorepDirectProduct: out of range! There are ",ncr," coreps in total."]; Abort[], {Part::partw,Part::take}];
(*--------check option "output"---------------*)
outopt=OptionValue["output"];
If[!MemberQ[{1,2,3,4},outopt],
Print["MPGCorepDirectProduct: option \"output\" can be one of {1,2,3,4}:\n",
"1. Output the Mulliken label.\n2. Output the Gamma label.\n",
"3. Output the occurrence numbers of all coreps.\n4. Output all the above 1-3 results."
]; Abort[]
];
(*--------------------------------------------*)
subidx1=If[IntegerQ[#],#,#[[1]]]&/@subidx;
cijk=PGIrepDirectProduct[sub[[1]],"output"->3];
(* BC-Tab 7.8 *)
d[cri_Integer,crj_Integer]:=Module[{typei,typej,typek,facij,fack,si,sj,sij,re},
typei=type[[cri]]; typej=type[[crj]];
facij=1; If[typei=="b",facij*=2]; If[typej=="b",facij*=2];
si=subidx[[cri]]; If[typei!="c", si={si}];
sj=subidx[[crj]]; If[typej!="c", sj={sj}];
sij=Flatten[Table[{i,j},{i,si},{j,sj}],1];
fack=If[#!="b",1,1/2]&/@type;
Total[cijk/@sij][[subidx1]]*facij*fack
];
out3=Flatten[Table[{i,j}->d[i,j],{i,cr1idx},{j,cr2idx}],1]//Association;
out1=label[[#,1]]->(If[#[[1]]==1,#[[2]],#]&/@Select[Transpose@{out3[#],label[[All,1]]},#[[1]]!=0&])&/@Keys[out3]//Association;
out2=label[[#,2]]->(If[#[[1]]==1,#[[2]],#]&/@Select[Transpose@{out3[#],label[[All,2]]},#[[1]]!=0&])&/@Keys[out3]//Association;
(* (*Check dimensions*)
If[!And@@(Times@@dim[[#]]\[Equal]Total[out3[#]*dim])&/@Keys[out3], Print["MPGCorepDirectProduct: Corep dimensions error!"]];
*)
Switch[outopt, 1, out1, 2, out2, 3, out3, 4, {out1,out2,out3}]
]
(* ::Subsection::Closed:: *)
(*showMPGCorepDirectProduct*)
Options[showMPGCorepDirectProduct]={"label"->1, "double"->True, "linewidth"->2, "emph"->None};
showMPGCorepDirectProduct[mpg_, coreps1_, coreps2_, OptionsPattern[]]/;
!Or@@(VectorQ[Flatten[{#}],MemberQ[{Rule,RuleDelayed},Head[#]]&]&/@{coreps1,coreps2}):=Module[{n,
mpgno,mpgcor,ncor,dp,type,cor1,cor2,tmp,label,lopt,tab,scor1,dcor1,scor2,dcor2,sty1,sty2,bg0,bg1,
bg2,bg3,bg4,bg5,s1pos,d1pos,s2pos,d2pos,emopt,emidx,emerr,head,rowh,box},
lopt=OptionValue["label"];
If[!MemberQ[{1,2},lopt],
Print["showMPGCorepDirectProduct: option \"label\" can be 1 or 2:\n",
"1. Output the Mulliken label.\n2. Output the Gamma label."]; Abort[]
];
n=checkMPGinput[mpg,"showMPGCorepDirectProduct"]; mpgno=MPGinfo[[n,2]];
mpgcor=getMPGCorep[mpg, "double"->True];
label=mpgcor["label"]; ncor=Length[label]; type=mpgcor["type"];
(*-------check option "emph"--------*)
emopt=OptionValue["emph"]; If[emopt===None,emopt={}];
emerr:=Print["showMPGCorepDirectProduct: option \"emph\" specifies the corep(s) to be emphasized and can be:\n",
"An integer OR a list of integers for the corep sequence numbers. OR\n",
"A span such as 1;;5. OR All. Refer to\n",
Grid[Prepend[Transpose@label,Range[ncor]], Frame->All,FrameStyle->Gray] ];
If[emopt===0, emerr; Abort[]];
emidx=If[StringQ[emopt]||IntegerQ[emopt], {emopt}, emopt];
If[!(VectorQ[emidx,IntegerQ]||Head[emidx]===Span||emidx===All), emerr; Abort[]]
Check[emidx=Range[ncor][[DeleteCases[emidx,0]]],
Print["showMPGCorepDirectProduct: out of range! There are ",ncor," coreps in total."]; Abort[], {Part::partw,Part::take}];
dp=MPGCorepDirectProduct[mpg,coreps1,coreps2,"output"->4];
cor1=Keys[dp[[3]]][[All,1]]//DeleteDuplicates;
cor2=Keys[dp[[3]]][[All,2]]//DeleteDuplicates;
scor1=Intersection[cor1,mpgcor["sindex"]];
scor2=Intersection[cor2,mpgcor["sindex"]];
dcor1=Complement[cor1,scor1];
dcor2=Complement[cor2,scor2];
If[OptionValue["double"]===False, cor1=scor1; cor2=scor2];
tmp=Join@@(Position[dp,#]&/@label[[emidx,lopt]]);
If[emidx!={}, dp=MapAt[Style[#,{Red,Bold}]&,dp,tmp]];
dp=Row[#,"+"]&/@Map[If[ListQ[#],Row[#],#]&, dp[[lopt]], {2}];
If[emidx!={}, dp=Style[#,Gray]&/@dp];
tab=Table[dp[{label[[i,lopt]],label[[j,lopt]]}], {i,cor1}, {j,cor2}];
tab=Transpose@Join[{cor1}, Transpose@label[[cor1]], {type[[cor1]]}, Transpose@tab];
head=Column[{Row[{"MPG: ", mpgcor["number"][[2]],", ",MSGSymStd@mpgcor["symbol"]}],
Row[{"USubG: ", MSGSymStd@mpgcor["USubG"][[3]], " (",str2Mulliken@mpgcor["USubG"][[2]],")"}]
}];
box=Grid[{{#}},Spacings->{0,0},Alignment->{Center,Center}]&;
rowh={{head,SpanFromLeft,SpanFromLeft,SpanFromLeft,Sequence@@cor2},
{SpanFromAbove,SpanFromBoth,SpanFromBoth,SpanFromBoth,Sequence@@box/@label[[cor2,lopt]]}};
tab=Join[rowh,tab];
tmp=Association@Table[cor1[[i]]->i+2,{i,Length[cor1]}];
s1pos=tmp/@scor1; d1pos=tmp/@dcor1;
tmp=Association@Table[cor2[[i]]->i+4,{i,Length[cor2]}];
s2pos=tmp/@scor2; d2pos=tmp/@dcor2;
sty1=Directive[Black,Thickness[OptionValue["linewidth"]]];
sty2=Directive[Thin,GrayLevel[0.8]];
bg0={1,1}->Lighter[Red,0.9];
bg1=With[{c=Lighter[Green,0.85]}, Flatten@Join[Table[{#,i}->c,{i,4}]&/@s1pos,Table[{i,#}->c,{i,2}]&/@s2pos]];
bg2=With[{c=Lighter[Blue,0.85]}, Flatten@Join[Table[{#,i}->c,{i,4}]&/@d1pos,Table[{i,#}->c,{i,2}]&/@d2pos]];
bg3=Table[{i,j}->Lighter[Green,0.9],{i,s1pos},{j,s2pos}]//Flatten[#,1]&;
bg4=Table[{i,j}->Lighter[Yellow,0.9],{i,d1pos},{j,d2pos}]//Flatten[#,1]&;
bg5=Join[Table[{i,j}->Lighter[Blue,0.9],{i,s1pos},{j,d2pos}],
Table[{i,j}->Lighter[Blue,0.9],{i,d1pos},{j,s2pos}]]//Flatten[#,1]&;
Grid[tab, Frame->All, Alignment->{Center,Center}, ItemSize->{{{},{2->3.1,3->2.9}},{}},
Dividers->{{{{sty2}},Join[#->sty1&/@{1,5,-1},#->sty2&/@{2}]},
{{{sty2}},#->sty1&/@{1,3,-1}}},
Background->{None,None,{bg0,Sequence@@Join[bg1,bg2,bg3,bg4,bg5]}}
]
]
showMPGCorepDirectProduct[mpg_, coreps1_, OptionsPattern[]]/;!VectorQ[Flatten[{coreps1}],MemberQ[{Rule,RuleDelayed},Head[#]]&]:=
showMPGCorepDirectProduct[mpg, coreps1, coreps1, (#->OptionValue[#])&/@{"label","double","linewidth","emph"}]
showMPGCorepDirectProduct[mpg_, OptionsPattern[]]:=
showMPGCorepDirectProduct[mpg, All, All, (#->OptionValue[#])&/@{"label","double","linewidth","emph"}]
(* ::Section:: *)
(*MLG Corep (small corep)*)
(* ::Subsection::Closed:: *)
(*findMatrixN*)
(* find a unitary matrix N which satisfies \[CapitalDelta](R)=N*bar\[CapitalDelta](R)*N^-1, where bar\[CapitalDelta](R)=\[CapitalDelta](A^-1RA)^* *)
findMatrixN[Delta_, barDelta_]:=Module[{tryN,len,d,i,tmp,q,U1q},
(*----------method 1, only for 1D rep---------------*)
If[!MatrixQ[Delta[[1]]], Return[1]];
(*----------method 2, maybe not work in some cases--------------*)
len=Length[Delta]; d=Dimensions[Delta[[1]]]//First;
tryN=Total@Table[Delta[[i]] . barDelta[[i]]\[ConjugateTranspose],{i,len}]/len//Simplify[#,u\[Element]Reals]&;
If[Total@Flatten@Abs[tryN . tryN\[ConjugateTranspose]-IdentityMatrix[d]]<1*^-8, Return[tryN]];
(*----------method 3, work in any case--------------*)
For[i=1,i<=d,i++,
tmp=Total[Delta[[All,1,1]]\[Conjugate]*barDelta[[All,i,i]]]*d/len//Simplify[#,u\[Element]Reals]&//Chop;
If[Abs[tmp]>1*^-8, q=i; U1q=Sqrt[tmp]; Break[]]
];
tryN=Table[Total[Delta[[All,1,i]]\[Conjugate]*barDelta[[All,q,j]]],{i,d},{j,d}]*d/(len*U1q)//Simplify[#,u\[Element]Reals]&//Chop;
If[Total@Flatten@Abs[tryN . tryN\[ConjugateTranspose]-IdentityMatrix[d]]>1*^-8, Print["findMatrixN: N is not unitary"]];
tryN
]
(* ::Subsection::Closed:: *)
(*For type-3 MSG*)
(* ::Subsubsection::Closed:: *)
(*SeitzConvert*)
(*Convert the SG Seitz symbol from cell1 (with lattice brav1) to cell2 (with lattice brav2).
Suppose that cell1=(t1,t2,t3) where t1,t2,t3 are column vectors of the basic vectors of cell1,
then cell2=R.cell1.T and os is the components of the origin shift O1-O2 under the bases of cell2.
T is the transformation matrix and R is the rotation matrix.
The returned value contains two Seitz symbols: the first for single SG, and the second for double SG.
NOTE: If Rspin is not give, it will be calculated in SeitzConvert, however this will slow down
this function. In practice, Rspin had better be calculated out of the function. *)
SeitzConvert[brav1_String, brav2_String, T_, os_, R_]:=SeitzConvert[brav1, brav2, T, os, R, None]
SeitzConvert[brav1_String, brav2_String, T_, os_, R_, Rspin_]:=Function[{Rv},
Module[{rot,rot2,v2,RSpin,Rang,Raxis,sx,srot,srot2,o3det,Rn2,sRn2,Rname,v,iT},
sx={{0,1},{1,0}}; Rname=Rv[[1]]; v=Rv[[2]];
rot=getRotMat[brav1,StringReplace[Rname,"bar"->""]];
(* Making the matrics numeric will speed up the calculations! *)
iT=Inverse[T//N]; rot2=iT . rot . T; v2= iT . v-rot2 . os+os;
If[Rspin=!=None, RSpin=Rspin,
{Raxis,Rang}=rotAxisAngle[R//N][[{2,3}]];
RSpin=MatrixExp[-I*Rang*Raxis . (PauliMatrix/@{1,2,3})/2]//Simplify
];
{srot,o3det}=getSpinRotOp[Rname];
srot2=sx . RSpin . sx . srot . sx . RSpin\[ConjugateTranspose] . sx//Simplify;
Rn2=getRotName[brav2,rot2];
sRn2=getSpinRotName[brav2,{srot2,o3det}];
If[StringReplace[sRn2,"bar"->""]!=Rn2, Print["SeitzConvert: error, ",Rn2,"!=",sRn2]];