This repository was archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGSASIIspc.py
More file actions
4303 lines (4092 loc) · 181 KB
/
GSASIIspc.py
File metadata and controls
4303 lines (4092 loc) · 181 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
########### SVN repository information ###################
# $Date: 2023-10-02 10:55:35 -0500 (Mon, 02 Oct 2023) $
# $Author: toby $
# $Revision: 5666 $
# $URL: https://subversion.xray.aps.anl.gov/pyGSAS/trunk/GSASIIspc.py $
# $Id: GSASIIspc.py 5666 2023-10-02 15:55:35Z toby $
########### SVN repository information ###################
''':mod:`GSASIIspc` Classes & routines follow
'''
from __future__ import division, print_function
import numpy as np
import numpy.linalg as nl
import scipy.optimize as so
import sys
import copy
import os.path as ospath
import GSASIIpath
GSASIIpath.SetVersionNumber("$Revision: 5666 $")
npsind = lambda x: np.sin(x*np.pi/180.)
npcosd = lambda x: np.cos(x*np.pi/180.)
nxs = np.newaxis
DEBUG = False
################################################################################
#### Space group codes
################################################################################
def SpcGroup(SGSymbol):
"""
Determines cell and symmetry information from a short H-M space group name
:param SGSymbol: space group symbol (string) with spaces between axial fields
:returns: (SGError,SGData)
* SGError = 0 for no errors; >0 for errors (see :func:`SGErrors` for details)
* SGData - is a dict (see :ref:`Space Group object<SGData_table>`) with entries:
* 'SpGrp': space group symbol, slightly cleaned up
* 'SGFixed': True if space group data can not be changed, e.g. from magnetic cif; otherwise False
* 'SGGray': True if 1' in symbol - gray group for mag. incommensurate phases
* 'SGLaue': one of '-1', '2/m', 'mmm', '4/m', '4/mmm', '3R',
'3mR', '3', '3m1', '31m', '6/m', '6/mmm', 'm3', 'm3m'
* 'SGInv': boolean; True if centrosymmetric, False if not
* 'SGLatt': one of 'P', 'A', 'B', 'C', 'I', 'F', 'R'
* 'SGUniq': one of 'a', 'b', 'c' if monoclinic, '' otherwise
* 'SGCen': cell centering vectors [0,0,0] at least
* 'SGOps': symmetry operations as [M,T] so that M*x+T = x'
* 'SGSys': one of 'triclinic', 'monoclinic', 'orthorhombic',
'tetragonal', 'rhombohedral', 'trigonal', 'hexagonal', 'cubic'
* 'SGPolax': one of ' ', 'x', 'y', 'x y', 'z', 'x z', 'y z',
'xyz', '111' for arbitrary axes
* 'SGPtGrp': one of 32 point group symbols (with some permutations), which
is filled by SGPtGroup, is external (KE) part of supersymmetry point group
* 'SSGKl': default internal (Kl) part of supersymmetry point group; modified
in supersymmetry stuff depending on chosen modulation vector for Mono & Ortho
* 'BNSlattsym': BNS lattice symbol & cenering op - used for magnetic structures
"""
LaueSym = ('-1','2/m','mmm','4/m','4/mmm','3R','3mR','3','3m1','31m','6/m','6/mmm','m3','m3m')
LattSym = ('P','A','B','C','I','F','R')
UniqSym = ('','','a','b','c','',)
SysSym = ('triclinic','monoclinic','orthorhombic','tetragonal','rhombohedral','trigonal','hexagonal','cubic')
SGData = {}
if len(SGSymbol.split()) < 2:
return SGErrors(0),SGData
if ':R' in SGSymbol:
SGSymbol = SGSymbol.replace(':',' ') #get rid of ':' in R space group symbols from some cif files
SGData['SGGray'] = False
if "1'" in SGSymbol: #set for incommensurate magnetic
SGData['SGGray'] = True
SGSymbol = SGSymbol.replace("1'",'')
SGSymbol = SGSymbol.split(':')[0] #remove :1/2 setting symbol from some cif files
if '-2' in SGSymbol: #replace bad but legal symbols with correct equivalents
SGSymbol = SGSymbol.replace('-2','m')
if SGSymbol.split()[1] =='3/m':
SGSymbol = SGSymbol.replace('3/m','-6')
import pyspg
SGInfo = pyspg.sgforpy(SGSymbol)
SGData['SpGrp'] = SGSymbol.strip().lower().capitalize()
SGData['SGLaue'] = LaueSym[SGInfo[0]-1]
SGData['SGInv'] = bool(SGInfo[1])
SGData['SGLatt'] = LattSym[SGInfo[2]-1]
SGData['SGUniq'] = UniqSym[SGInfo[3]+1]
SGData['SGFixed'] = False
SGData['SGOps'] = []
SGData['SGGen'] = []
for i in range(SGInfo[5]):
Mat = np.array(SGInfo[6][i])
Trns = np.array(SGInfo[7][i])
SGData['SGOps'].append([Mat,Trns])
if 'array' in str(type(SGInfo[8])): #patch for old fortran bin?
SGData['SGGen'].append(int(SGInfo[8][i]))
SGData['BNSlattsym'] = [LattSym[SGInfo[2]-1],[0,0,0]]
lattSpin = []
if SGData['SGLatt'] == 'P':
SGData['SGCen'] = np.array(([0,0,0],))
elif SGData['SGLatt'] == 'A':
SGData['SGCen'] = np.array(([0,0,0],[0,.5,.5]))
lattSpin += [1,]
elif SGData['SGLatt'] == 'B':
SGData['SGCen'] = np.array(([0,0,0],[.5,0,.5]))
lattSpin += [1,]
elif SGData['SGLatt'] == 'C':
SGData['SGCen'] = np.array(([0,0,0],[.5,.5,0,]))
lattSpin += [1,]
elif SGData['SGLatt'] == 'I':
SGData['SGCen'] = np.array(([0,0,0],[.5,.5,.5]))
lattSpin += [1,]
elif SGData['SGLatt'] == 'F':
SGData['SGCen'] = np.array(([0,0,0],[0,.5,.5],[.5,0,.5],[.5,.5,0,]))
lattSpin += [1,1,1,1]
elif SGData['SGLatt'] == 'R':
SGData['SGCen'] = np.array(([0,0,0],[2./3,1./3,1./3],[1./3,2./3,2./3]))
if SGData['SGInv']:
if SGData['SGLaue'] in ['-1','2/m','mmm']:
Ibar = 7
elif SGData['SGLaue'] in ['4/m','4/mmm']:
Ibar = 1
elif SGData['SGLaue'] in ['3R','3mR','3','3m1','31m','6/m','6/mmm']:
Ibar = 15 #8+4+2+1
else:
Ibar = 4
Ibarx = Ibar&14
else:
Ibarx = 8
if SGData['SGLaue'] in ['-1','2/m','mmm','m3','m3m']:
Ibarx = 0
moregen = []
for i,gen in enumerate(SGData['SGGen']):
if SGData['SGLaue'] in ['m3','m3m']:
if gen in [1,2,4]:
SGData['SGGen'][i] = 4
elif gen < 7:
SGData['SGGen'][i] = 0
elif SGData['SGLaue'] in ['4/m','4/mmm','3R','3mR','3','3m1','31m','6/m','6/mmm']:
if gen == 2:
SGData['SGGen'][i] = 4
elif gen in [3,5]:
SGData['SGGen'][i] = 3
elif gen == 6:
if SGData['SGLaue'] in ['4/m','4/mmm']:
SGData['SGGen'][i] = 128
else:
SGData['SGGen'][i] = 16
elif not SGData['SGInv'] and gen == 12:
SGData['SGGen'][i] = 8
elif (not SGData['SGInv']) and (SGData['SGLaue'] in ['3','3m1','31m','6/m','6/mmm']) and (gen == 1):
SGData['SGGen'][i] = 24
gen = SGData['SGGen'][i]
if gen == 99:
gen = 8
if SGData['SGLaue'] in ['3m1','31m','6/m','6/mmm']:
gen = 3
elif SGData['SGLaue'] == 'm3m':
gen = 12
SGData['SGGen'][i] = gen
elif gen == 98:
gen = 8
if SGData['SGLaue'] in ['3m1','31m','6/m','6/mmm']:
gen = 4
SGData['SGGen'][i] = gen
elif not SGData['SGInv'] and gen in [23,] and SGData['SGLaue'] in ['m3','m3m']:
SGData['SGGen'][i] = 24
elif gen >= 16 and gen != 128:
if not SGData['SGInv']:
gen = 31
else:
gen ^= Ibarx
SGData['SGGen'][i] = gen
if SGData['SGInv']:
if gen < 128:
moregen.append(SGData['SGGen'][i]^Ibar)
else:
moregen.append(1)
SGData['SGGen'] += moregen
if SGData['SGLaue'] in '-1':
SGData['SGSys'] = SysSym[0]
elif SGData['SGLaue'] in '2/m':
SGData['SGSys'] = SysSym[1]
elif SGData['SGLaue'] in 'mmm':
SGData['SGSys'] = SysSym[2]
elif SGData['SGLaue'] in ['4/m','4/mmm']:
SGData['SGSys'] = SysSym[3]
elif SGData['SGLaue'] in ['3R','3mR']:
SGData['SGSys'] = SysSym[4]
elif SGData['SGLaue'] in ['3','3m1','31m']:
SGData['SGSys'] = SysSym[5]
elif SGData['SGLaue'] in ['6/m','6/mmm']:
SGData['SGSys'] = SysSym[6]
elif SGData['SGLaue'] in ['m3','m3m']:
SGData['SGSys'] = SysSym[7]
SGData['SGPolax'] = SGpolar(SGData)
SGData['SGPtGrp'],SGData['SSGKl'] = SGPtGroup(SGData)
if SGData['SGLatt'] == 'R':
if SGData['SGPtGrp'] in ['3',]:
SGData['SGSpin'] = 3*[1,]
elif SGData['SGPtGrp'] in ['-3','32','3m']:
SGData['SGSpin'] = 4*[1,]
elif SGData['SGPtGrp'] in ['-3m',]:
SGData['SGSpin'] = 5*[1,]
else:
if SGData['SGPtGrp'] in ['1','3','23',]:
SGData['SGSpin'] = lattSpin+[1,]
elif SGData['SGPtGrp'] in ['-1','2','m','4','-4','-3','312','321','3m1','31m','6','-6','432','-43m']:
SGData['SGSpin'] = lattSpin+[1,1,]
elif SGData['SGPtGrp'] in ['2/m','4/m','422','4mm','-42m','-4m2','-3m1','-31m',
'6/m','622','6mm','-6m2','-62m','m3','m3m']:
SGData['SGSpin'] = lattSpin+[1,1,1,]
else: #'222'-'mmm','4/mmm','6/mmm'
SGData['SGSpin'] = lattSpin+[1,1,1,1,]
return SGInfo[-1],SGData
def SGErrors(IErr):
'''
Interprets the error message code from SpcGroup. Used in SpaceGroup.
:param IErr: see SGError in :func:`SpcGroup`
:returns:
ErrString - a string with the error message or "Unknown error"
'''
ErrString = [' ',
'Less than 2 operator fields were found',
'Illegal Lattice type, not P, A, B, C, I, F or R',
'Rhombohedral lattice requires a 3-axis',
'Minus sign does not preceed 1, 2, 3, 4 or 6',
'Either a 5-axis anywhere or a 3-axis in field not allowed',
' ',
'I for COMPUTED GO TO out of range.',
'An a-glide mirror normal to A not allowed',
'A b-glide mirror normal to B not allowed',
'A c-glide mirror normal to C not allowed',
'D-glide in a primitive lattice not allowed',
'A 4-axis not allowed in the 2nd operator field',
'A 6-axis not allowed in the 2nd operator field',
'More than 24 matrices needed to define group',
' ',
'Improper construction of a rotation operator',
'Mirror following a / not allowed',
'A translation conflict between operators',
'The 2bar operator is not allowed',
'3 fields are legal only in R & m3 cubic groups',
'Syntax error. Expected I -4 3 d at this point',
' ',
'A or B centered tetragonal not allowed',
' ','unknown error in sgroup',' ',' ',' ',
'Illegal character in the space group symbol',
]
try:
return ErrString[IErr]
except:
return "Unknown error"
def SGpolar(SGData):
'''
Determine identity of polar axes if any
'''
POL = ('','x','y','x y','z','x z','y z','xyz','111')
NP = [1,2,4]
NPZ = [0,1]
for M,T in SGData['SGOps']:
for i in range(3):
if M[i][i] <= 0.: NP[i] = 0
if M[0][2] > 0: NPZ[0] = 8
if M[1][2] > 0: NPZ[1] = 0
NPol = (NP[0]+NP[1]+NP[2]+NPZ[0]*NPZ[1])*(1-int(SGData['SGInv']))
return POL[NPol]
def SGPtGroup(SGData):
'''
Determine point group of the space group - done after space group symbol has
been evaluated by SpcGroup. Only short symbols are allowed
:param SGData: from :func:`SpcGroup`
:returns: SSGPtGrp & SSGKl (only defaults for Mono & Ortho)
'''
Flds = SGData['SpGrp'].split()
if len(Flds) < 2:
return '',[]
if SGData['SGLaue'] == '-1': #triclinic
if '-' in Flds[1]:
return '-1',[-1,]
else:
return '1',[1,]
elif SGData['SGLaue'] == '2/m': #monoclinic - default for 2D modulation vector
if '/' in SGData['SpGrp']:
return '2/m',[-1,1]
elif '2' in SGData['SpGrp']:
return '2',[-1,]
else:
return 'm',[1,]
elif SGData['SGLaue'] == 'mmm': #orthorhombic
if SGData['SpGrp'].count('2') == 3:
return '222',[-1,-1,-1]
elif SGData['SpGrp'].count('2') == 1:
if SGData['SGPolax'] == 'x':
return '2mm',[-1,1,1]
elif SGData['SGPolax'] == 'y':
return 'm2m',[1,-1,1]
elif SGData['SGPolax'] == 'z':
return 'mm2',[1,1,-1]
else:
return 'mmm',[1,1,1]
elif SGData['SGLaue'] == '4/m': #tetragonal
if '/' in SGData['SpGrp']:
return '4/m',[1,-1]
elif '-' in Flds[1]:
return '-4',[-1,]
else:
return '4',[1,]
elif SGData['SGLaue'] == '4/mmm':
if '/' in SGData['SpGrp']:
return '4/mmm',[1,-1,1,1]
elif '-' in Flds[1]:
if '2' in Flds[2]:
return '-42m',[-1,-1,1]
else:
return '-4m2',[-1,1,-1]
elif '2' in Flds[2:]:
return '422',[1,-1,-1]
else:
return '4mm',[1,1,1]
elif SGData['SGLaue'] in ['3','3R']: #trigonal/rhombohedral
if '-' in Flds[1]:
return '-3',[-1,]
else:
return '3',[1,]
elif SGData['SGLaue'] == '3mR' or 'R' in Flds[0]:
if '2' in Flds[2]:
return '32',[1,-1]
elif '-' in Flds[1]:
return '-3m',[-1,1]
else:
return '3m',[1,1]
elif SGData['SGLaue'] == '3m1':
if '2' in Flds[2]:
return '321',[1,-1,1]
elif '-' in Flds[1]:
return '-3m1',[-1,1,1]
else:
return '3m1',[1,1,1]
elif SGData['SGLaue'] == '31m':
if '2' in Flds[3]:
return '312',[1,1,-1]
elif '-' in Flds[1]:
return '-31m',[-1,1,1]
else:
return '31m',[1,1,1]
elif SGData['SGLaue'] == '6/m': #hexagonal
if '/' in SGData['SpGrp']:
return '6/m',[1,-1]
elif '-' in SGData['SpGrp']:
return '-6',[-1,]
else:
return '6',[1,]
elif SGData['SGLaue'] == '6/mmm':
if '/' in SGData['SpGrp']:
return '6/mmm',[1,-1,1,1]
elif '-' in Flds[1]:
if '2' in Flds[2]:
return '-62m',[-1,-1,1]
else:
return '-6m2',[-1,1,-1]
elif '2' in Flds[2:]:
return '622',[1,-1,-1]
else:
return '6mm',[1,1,1]
elif SGData['SGLaue'] == 'm3': #cubic - no (3+1) supersymmetry
if '2' in Flds[1]:
return '23',[]
else:
return 'm3',[]
elif SGData['SGLaue'] == 'm3m':
if '4' in Flds[1]:
if '-' in Flds[1]:
return '-43m',[]
else:
return '432',[]
else:
return 'm3m',[]
def SGPrint(SGData,AddInv=False):
'''
Print the output of SpcGroup in a nicely formatted way. Used in SpaceGroup
:param SGData: from :func:`SpcGroup`
:returns:
SGText - list of strings with the space group details
SGTable - list of strings for each of the operations
'''
if SGData.get('SGFixed',False): #inverses included in ops for cif fixed
Mult = len(SGData['SGCen'])*len(SGData['SGOps'])
else:
Mult = len(SGData['SGCen'])*len(SGData['SGOps'])*(int(SGData['SGInv'])+1)
SGText = []
SGText.append(' Space Group: '+SGData['SpGrp'])
SGCen = list(SGData['SGCen'])
if SGData.get('SGGray',False):
SGText[-1] += " 1'"
if SGData.get('SGFixed',False):
Mult //= 2
else:
SGCen += list(SGData['SGCen']+[0,0,0])
SGCen = np.array(SGCen)%1.
CentStr = 'centrosymmetric'
if not SGData['SGInv']:
CentStr = 'non'+CentStr
if SGData['SGLatt'] in 'ABCIFR':
SGText.append(' The lattice is '+CentStr+' '+SGData['SGLatt']+'-centered '+SGData['SGSys'].lower())
else:
SGText.append(' The lattice is '+CentStr+' '+'primitive '+SGData['SGSys'].lower())
SGText.append(' The Laue symmetry is '+SGData['SGLaue'])
if 'SGPtGrp' in SGData: #patch
SGText.append(' The lattice point group is '+SGData['SGPtGrp'])
SGText.append(' Multiplicity of a general site is '+str(Mult))
if SGData['SGUniq'] in ['a','b','c']:
SGText.append(' The unique monoclinic axis is '+SGData['SGUniq'])
if SGData['SGInv']:
SGText.append(' The inversion center is located at 0,0,0')
if SGData['SGPolax']:
SGText.append(' The location of the origin is arbitrary in '+SGData['SGPolax'])
SGText.append(' ')
if len(SGData['SGCen']) == 1:
SGText.append(' The equivalent positions are:\n')
else:
SGText.append(' The equivalent positions are:\n')
SGText.append(' ('+Latt2text(SGCen)+')+\n')
SGTable = []
for i,Opr in enumerate(SGData['SGOps']):
SGTable.append('(%2d) %s'%(i+1,MT2text(Opr)))
if AddInv and SGData['SGInv']:
for i,Opr in enumerate(SGData['SGOps']):
IOpr = [-Opr[0],-Opr[1]]
SGTable.append('(%2d) %s'%(i+1,MT2text(IOpr)))
return SGText,SGTable
def AllOps(SGData):
'''
Returns a list of all operators for a space group, including those for
centering and a center of symmetry
:param SGData: from :func:`SpcGroup`
:returns: (SGTextList,offsetList,symOpList,G2oprList) where
* SGTextList: a list of strings with formatted and normalized
symmetry operators.
* offsetList: a tuple of (dx,dy,dz) offsets that relate the GSAS-II
symmetry operation to the operator in SGTextList and symOpList.
these dx (etc.) values are added to the GSAS-II generated
positions to provide the positions that are generated
by the normalized symmetry operators.
* symOpList: a list of tuples with the normalized symmetry
operations as (M,T) values
(see ``SGOps`` in the :ref:`Space Group object<SGData_table>`)
* G2oprList: a list with the GSAS-II operations for each symmetry operation as
a tuple with (center,mult,opnum,opcode), where center is (0,0,0), (0.5,0,0),
(0.5,0.5,0.5),...; where mult is 1 or -1 for the center of symmetry
where opnum is the number for the symmetry operation, in ``SGOps``
(starting with 0) and opcode is mult*(100*icen+j+1).
* G2opcodes: a list with the name that GSAS-II uses for each symmetry
operation (same as opcode, above)
'''
SGTextList = []
offsetList = []
symOpList = []
G2oprList = []
G2opcodes = []
onebar = (1,)
if SGData['SGInv']:
onebar += (-1,)
for icen,cen in enumerate(SGData['SGCen']):
for mult in onebar:
for j,(M,T) in enumerate(SGData['SGOps']):
offset = [0,0,0]
Tprime = (mult*T)+cen
for i in range(3):
while Tprime[i] < 0:
Tprime[i] += 1
offset[i] += 1
while Tprime[i] >= 1:
Tprime[i] += -1
offset[i] += -1
Opr = [mult*M,Tprime]
OPtxt = MT2text(Opr)
SGTextList.append(OPtxt.replace(' ',''))
offsetList.append(tuple(offset))
symOpList.append((mult*M,Tprime))
G2oprList.append((cen,mult,j))
G2opcodes.append(mult*(100*icen+j+1))
return SGTextList,offsetList,symOpList,G2oprList,G2opcodes
def TextOps(text,table,reverse=False):
''' Makes formatted operator list
:param text,table: arrays of text made by SGPrint
:param reverse: True for x+1/2 form; False for 1/2+x form
:returns: OpText: full list of symmetry operators; one operation per line
generally printed to console for use via cut/paste in other programs, but
could be used for direct input
'''
OpText = []
Inv = True
Super = False
if 'noncentro' in text[1]:
Inv = False
if 'Super' in text[0]:
Super = True
Cent = [[0,0,0],]
if Super:
Cent = [[0,0,0,0],]
if '0,0,0' in text[-1]:
Cent = np.array(eval(text[-1].split('+')[0].replace(';','),(')))
OpsM = []
OpsT = []
for item in table:
if 'for' in item: continue
if Super:
M,T = MagSSText2MTS(item.split(')')[1].replace(' ',''),G2=True)[:2]
else:
M,T = Text2MT(item.split(')')[1].replace(' ',''),CIF=True)
OpsM.append(M)
OpsT.append(T)
OpsM = np.array(OpsM)
OpsT = np.array(OpsT)
if Inv and not Super: #inversion ops altready listed in supersymmetries
OpsM = np.concatenate((OpsM,-OpsM))
OpsT = np.concatenate((OpsT,-OpsT%1.))
for cent in Cent:
for iop,opM in enumerate(list(OpsM)):
if Super:
txt = SSMT2text([opM,(OpsT[iop]+cent)%1.])
else:
txt = MT2text([opM,(OpsT[iop]+cent)%1.],reverse)
OpText.append(txt.replace(' ','').lower())
return OpText
def TextGen(SGData,reverse=False): #does not always work correctly - not used anyway
GenSym,GenFlg,BNSsym = GetGenSym(SGData)
SGData['GenSym'] = GenSym
SGData['GenFlg'] = GenFlg
text,table = SGPrint(SGData)
GenText = []
OprNames = GetOprNames(SGData)
OpText = TextOps(text,table,reverse)
for name in SGData['GenSym']:
gid = OprNames.index(name.replace(' ',''))
GenText.append(OpText[gid])
if len(SGData['SGCen']) > 1:
GenText.append(OpText[-1])
return GenText
def GetOprNames(SGData):
OprNames = [GetOprPtrName(str(irtx)) for irtx in PackRot(SGData['SGOps'])]
if SGData['SGInv']:
OprNames += [GetOprPtrName(str(-irtx)) for irtx in PackRot(SGData['SGOps'])]
return OprNames
def MT2text(Opr,reverse=False):
"From space group matrix/translation operator returns text version"
XYZ = ('-Z','-Y','-X','X-Y','ERR','Y-X','X','Y','Z')
TRA = (' ','ERR','1/6','1/4','1/3','ERR','1/2','ERR','2/3','3/4','5/6','ERR')
Fld = ''
M,T = Opr
for j in range(3):
IJ = int(round(2*M[j][0]+3*M[j][1]+4*M[j][2]+4))%12
IK = int(round(T[j]*12))%12
if IK:
if IJ < 3:
if reverse:
Fld += (XYZ[IJ]+'+'+TRA[IK]).rjust(5)
else:
Fld += (TRA[IK]+XYZ[IJ]).rjust(5)
else:
if reverse:
Fld += (XYZ[IJ]+'+'+TRA[IK]).rjust(5)
else:
Fld += (TRA[IK]+'+'+XYZ[IJ]).rjust(5)
else:
Fld += XYZ[IJ].rjust(5)
if j != 2: Fld += ', '
return Fld
def Latt2text(Cen):
"From lattice centering vectors returns ';' delimited cell centering vectors"
lattTxt = ''
fracList = ['1/2','1/3','2/3','1/4','3/4','1/5','2/5','3/5','4/5','1/6','5/6',
'1/7','2/7','3/7','4/7','5/7','6/7','1/8','3/8','5/8','7/8','1/9','2/9','4/9','5/9','7/9','8/9']
mulList = [2,3,3,4,4,5,5,5,5,6,6,7,7,7,7,7,7,8,8,8,8,9,9,9,9,9,9]
prodList = [1.,1.,2.,1.,3.,1.,2.,3.,4.,1.,5.,1.,2.,3.,4.,5.,6.,1.,3.,5.,7.,1.,2.,4.,5.,7.,8.]
nCen = len(Cen)
for i,cen in enumerate(Cen):
txt = ''
for icen in cen:
if icen == 1:
txt += '1,'
continue
if not icen:
txt += '0,'
continue
if icen < 0:
txt += '-'
icen *= -1
for mul,prod,frac in zip(mulList,prodList,fracList):
if abs(icen*mul-prod) < 1.e-5:
txt += frac+','
break
lattTxt += txt[:-1]+'; '
if i and not i%8 and i < nCen-1: #not for the last cen!
lattTxt += '\n '
return lattTxt[:-2]
def SpaceGroup(SGSymbol):
'''
Print the output of SpcGroup in a nicely formatted way.
:param SGSymbol: space group symbol (string) with spaces between axial fields
:returns: nothing
'''
E,A = SpcGroup(SGSymbol)
if E > 0:
print (SGErrors(E))
return
for l in SGPrint(A):
print (l)
################################################################################
#### Magnetic space group stuff
################################################################################
def SplitMagSpSG(MSpSg):
SpSG = StandardizeSpcName(MSpSg.replace("'",'')) #removes all mag. op. marks & makes axial fields
Sflds = SpSG.split() #2-4 axial fields
Axf = []
MSpSg += ' '
Psym = MSpSg[0]
Ib = 0
if '_' in MSpSg:
Psym = MSpSg[:3]
Ib = 2
Ib += 1
if len(Sflds) == 2: #simple: one axial field
return Psym+' '+MSpSg[Ib:]
if '/' in MSpSg[Ib:]: #more fields - do 1st axial field
Is = MSpSg.index('/')
If = Is+1
if "'" in MSpSg[Is+2]:
If += 1
Axf.append(MSpSg[Ib:If+1])
Ib = If+1
else:
If = Ib+len(Sflds[1])
if "'" == MSpSg[If]:
If += 1
Axf.append(MSpSg[Ib:If])
Ib = If
for i in range(len(Sflds)-2): #do rest
If = Ib+len(Sflds[i+2])
if "'" == MSpSg[If]:
If += 1
Axf.append(MSpSg[Ib:If])
Ib = If
MSpcGp = Psym+' '+' '.join(Axf)
return MSpcGp
def SetMagnetic(SGData):
GenSym,GenFlg,BNSsym = GetGenSym(SGData)
SGData['GenSym'] = GenSym
SGData['GenFlg'] = GenFlg
OprNames,SpnFlp = GenMagOps(SGData)
SGData['SpnFlp'] = SpnFlp
SGData['MagSpGrp'] = MagSGSym(SGData)
def GetGenSym(SGData):
'''
Get the space group generator symbols
:param SGData: from :func:`SpcGroup`
LaueSym = ('-1','2/m','mmm','4/m','4/mmm','3R','3mR','3','3m1','31m','6/m','6/mmm','m3','m3m')
LattSym = ('P','A','B','C','I','F','R')
'''
BNSsym = {}
OprNames = [GetOprPtrName(str(irtx)) for irtx in PackRot(SGData['SGOps'])]
if SGData['SGInv']:
OprNames += [GetOprPtrName(str(-irtx)) for irtx in PackRot(SGData['SGOps'])]
Nsyms = len(SGData['SGOps'])
if SGData['SGInv'] and not SGData['SGFixed']: Nsyms *= 2
UsymOp = ['1',]
OprFlg = [0,]
if Nsyms == 2: #Centric triclinic or acentric monoclinic
UsymOp.append(OprNames[1])
OprFlg.append(SGData['SGGen'][1])
elif Nsyms == 4: #Point symmetry 2/m, 222, 22m, or 4
if '4z' in OprNames[1]: #Point symmetry 4 or -4
UsymOp.append(OprNames[1])
OprFlg.append(SGData['SGGen'][1])
elif not SGData['SGInv']: #Acentric Orthorhombic
if 'm' in OprNames[1:4]: #22m, 2m2 or m22
if '2' in OprNames[1]: #Acentric orthorhombic, 2mm
UsymOp.append(OprNames[2])
OprFlg.append(SGData['SGGen'][2])
UsymOp.append(OprNames[3])
OprFlg.append(SGData['SGGen'][3])
elif '2' in OprNames[2]: #Acentric orthorhombic, m2m
UsymOp.append(OprNames[1])
OprFlg.append(SGData['SGGen'][1])
UsymOp.append(OprNames[3])
OprFlg.append(SGData['SGGen'][3])
else: #Acentric orthorhombic, mm2
UsymOp.append(OprNames[1])
OprFlg.append(SGData['SGGen'][1])
UsymOp.append(OprNames[2])
OprFlg.append(SGData['SGGen'][2])
else: #Acentric orthorhombic, 222
SGData['SGGen'][1:] = [4,2,1]
UsymOp.append(OprNames[1])
OprFlg.append(SGData['SGGen'][1])
UsymOp.append(OprNames[2])
OprFlg.append(SGData['SGGen'][2])
UsymOp.append(OprNames[3])
OprFlg.append(SGData['SGGen'][3])
else: #Centric Monoclinic
UsymOp.append(OprNames[1])
OprFlg.append(SGData['SGGen'][1])
UsymOp.append(OprNames[3])
OprFlg.append(SGData['SGGen'][3])
elif Nsyms == 6: #Point symmetry 32, 3m or 6
if '6' in OprNames[1]: #Hexagonal 6/m Laue symmetry
UsymOp.append(OprNames[1])
OprFlg.append(SGData['SGGen'][1])
else: #Trigonal
UsymOp.append(OprNames[4])
OprFlg.append(SGData['SGGen'][3])
if '2110' in OprNames[1]: UsymOp[-1] = ' 2100 '
elif Nsyms == 8: #Point symmetry mmm, 4/m, or 422, etc
if '4' in OprNames[1]: #Tetragonal
if SGData['SGInv']: #4/m
UsymOp.append(OprNames[1])
OprFlg.append(SGData['SGGen'][1])
UsymOp.append(OprNames[6])
OprFlg.append(SGData['SGGen'][6])
else:
if 'x' in OprNames[4]: #4mm type group
UsymOp.append(OprNames[4])
OprFlg.append(6)
UsymOp.append(OprNames[7])
OprFlg.append(8)
else: #-42m, -4m2, and 422 type groups
UsymOp.append(OprNames[5])
OprFlg.append(8)
UsymOp.append(OprNames[6])
OprFlg.append(19)
else: #Orthorhombic, mmm
UsymOp.append(OprNames[1])
OprFlg.append(SGData['SGGen'][1])
UsymOp.append(OprNames[2])
OprFlg.append(SGData['SGGen'][2])
UsymOp.append(OprNames[7])
OprFlg.append(SGData['SGGen'][7])
elif Nsyms == 12 and '3' in OprNames[1] and SGData['SGSys'] != 'cubic': #Trigonal
UsymOp.append(OprNames[3])
OprFlg.append(SGData['SGGen'][3])
UsymOp.append(OprNames[9])
OprFlg.append(SGData['SGGen'][9])
elif Nsyms == 12 and '6' in OprNames[1]: #Hexagonal
if 'mz' in OprNames[9]: #6/m
UsymOp.append(OprNames[1])
OprFlg.append(SGData['SGGen'][1])
UsymOp.append(OprNames[6])
OprFlg.append(SGData['SGGen'][6])
else: #6mm, -62m, -6m2 or 622
UsymOp.append(OprNames[6])
OprFlg.append(18)
if 'm' in UsymOp[-1]: OprFlg[-1] = 20
UsymOp.append(OprNames[7])
OprFlg.append(24)
elif Nsyms in [16,24]:
if '3' in OprNames[1]:
UsymOp.append('')
OprFlg.append(SGData['SGGen'][3])
for i in range(Nsyms):
if 'mx' in OprNames[i]:
UsymOp[-1] = OprNames[i]
elif 'm11' in OprNames[i]:
UsymOp[-1] = OprNames[i]
elif '211' in OprNames[i]:
UsymOp[-1] = OprNames[i]
OprFlg[-1] = 24
else: #4/mmm or 6/mmm
UsymOp.append(' mz ')
OprFlg.append(1)
if '4' in OprNames[1]: #4/mmm
UsymOp.append(' mx ')
OprFlg.append(20)
UsymOp.append(' m110 ')
OprFlg.append(24)
else: #6/mmm
UsymOp.append(' m110 ')
OprFlg.append(4)
UsymOp.append(' m+-0 ')
OprFlg.append(8)
else: #System is cubic
if Nsyms == 48:
UsymOp.append(' mx ')
OprFlg.append(4)
UsymOp.append(' m110 ')
OprFlg.append(24)
if 'P' in SGData['SGLatt']:
if SGData['SGSys'] == 'triclinic':
BNSsym = {'P_a':[.5,0,0],'P_b':[0,.5,0],'P_c':[0,0,.5]}
elif SGData['SGSys'] == 'monoclinic':
BNSsym = {'P_a':[.5,0,0],'P_b':[0,.5,0],'P_c':[0,0,.5],'P_I':[.5,.5,.5]}
if SGData['SGUniq'] == 'a':
BNSsym.update({'P_B':[.5,0,.5],'P_C':[.5,.5,0]})
elif SGData['SGUniq'] == 'b':
BNSsym.update({'P_A':[.5,.5,0],'P_C':[0,.5,.5]})
elif SGData['SGUniq'] == 'c':
BNSsym.update({'P_A':[0,.5,.5],'P_B':[.5,0,.5]})
elif SGData['SGSys'] == 'orthorhombic':
BNSsym = {'P_a':[.5,0,0],'P_b':[0,.5,0],'P_c':[0,0,.5],
'P_A':[0,.5,.5],'P_B':[.5,0,.5],'P_C':[.5,.5,0],'P_I':[.5,.5,.5]}
elif SGData['SGSys'] == 'tetragonal':
BNSsym = {'P_c':[0,0,.5],'P_C':[.5,.5,0],'P_I':[.5,.5,.5]}
elif SGData['SGSys'] in ['trigonal','hexagonal']:
BNSsym = {'P_c':[0,0,.5]}
elif SGData['SGSys'] == 'cubic':
BNSsym = {'P_I':[.5,.5,.5]}
elif 'A' in SGData['SGLatt']:
if SGData['SGSys'] == 'monoclinic':
BNSsym = {}
if SGData['SGUniq'] == 'b':
BNSsym.update({'A_a':[.5,0,0],'A_c':[0,0,.5]})
elif SGData['SGUniq'] == 'c':
BNSsym.update({'A_a':[.5,0,0],'A_b':[0,.5,0]})
elif SGData['SGSys'] == 'orthorhombic':
BNSsym = {'A_a':[.5,0,0],'A_b':[0,.5,0],'A_c':[0,0,.5],
'A_B':[.5,0,.5],'A_C':[.5,.5,0]}
elif SGData['SGSys'] == 'triclinic':
BNSsym = {'A_a':[.5,0,0],'A_b':[0,.5,0],'A_c':[0,0,.5]}
elif 'B' in SGData['SGLatt']:
if SGData['SGSys'] == 'monoclinic':
BNSsym = {}
if SGData['SGUniq'] == 'a':
BNSsym.update({'B_b':[0,.5,0],'B_c':[0,0,.5]})
elif SGData['SGUniq'] == 'c':
BNSsym.update({'B_a':[.5,0,0],'B_b':[0,.5,0]})
elif SGData['SGSys'] == 'orthorhombic':
BNSsym = {'B_a':[.5,0,0],'B_b':[0,.5,0],'B_c':[0,0,.5],
'B_A':[0,.5,.5],'B_C':[.5,.5,0]}
elif SGData['SGSys'] == 'triclinic':
BNSsym = {'B_a':[.5,0,0],'B_b':[0,.5,0],'B_c':[0,0,.5]}
elif 'C' in SGData['SGLatt']:
if SGData['SGSys'] == 'monoclinic':
BNSsym = {}
if SGData['SGUniq'] == 'a':
BNSsym.update({'C_b':[0,.5,.0],'C_c':[0,0,.5]})
elif SGData['SGUniq'] == 'b':
BNSsym.update({'C_a':[.5,0,0],'C_c':[0,0,.5],'C_B':[.5,0.,.5]})
elif SGData['SGSys'] == 'orthorhombic':
BNSsym = {'C_a':[.5,0,0],'C_b':[0,.5,0],'C_c':[0,0,.5],
'C_A':[0,.5,.5],'C_B':[.5,0,.5]}
elif SGData['SGSys'] == 'triclinic':
BNSsym = {'C_a':[.5,0,0],'C_b':[0,.5,0],'C_c':[0,0,.5]}
elif 'I' in SGData['SGLatt']:
if SGData['SGSys'] in ['monoclinic','orthorhombic','triclinic']:
BNSsym = {'I_a':[.5,0,0],'I_b':[0,.5,0],'I_c':[0,0,.5]}
elif SGData['SGSys'] == 'tetragonal':
BNSsym = {'I_c':[0,0,.5]}
elif SGData['SGSys'] == 'cubic':
BNSsym = {}
elif 'F' in SGData['SGLatt']:
if SGData['SGSys'] in ['monoclinic','orthorhombic','cubic','triclinic']:
BNSsym = {'F_S':[.5,.5,.5]}
elif 'R' in SGData['SGLatt']:
BNSsym = {'R_I':[0,0,.5]}
if SGData['SGGray']:
for bns in BNSsym:
BNSsym[bns].append(0.5)
return UsymOp,OprFlg,BNSsym
def ApplyBNSlatt(SGData,BNSlatt):
Tmat = np.eye(3)
BNS = BNSlatt[0]
A = np.array(BNSlatt[1])
Laue = SGData['SGLaue']
SGCen = SGData['SGCen']
if '_a' in BNS:
Tmat[0,0] = 2.0
elif '_b' in BNS:
Tmat[1,1] = 2.0
elif '_c' in BNS:
Tmat[2,2] = 2.0
elif '_A' in BNS:
Tmat[0,0] = 2.0
elif '_B' in BNS:
Tmat[1,1] = 2.0
elif '_C' in BNS:
Tmat[2,2] = 2.0
elif '_I' in BNS:
Tmat *= 2.0
if 'R' in Laue:
SGData['SGSpin'][-1] = -1
else:
SGData['SGSpin'].append(-1)
elif '_S' in BNS:
SGData['SGSpin'][-1] = -1
SGData['SGSpin'] += [-1,-1,-1,]
Tmat *= 2.0
else:
return Tmat
if SGData.get('SGGray',False):
SGData['SGSpin'].append(1) #BNS centering are spin invrsion
else:
SGData['SGSpin'].append(-1) #BNS centering in grey are not spin invrsion
C = SGCen+A[:3]
SGData['SGCen'] = np.vstack((SGCen,C))%1.
return Tmat
def CheckSpin(isym,SGData):
''' Check for exceptions in spin rules
'''
if SGData['SGPtGrp'] in ['222','mm2','2mm','m2m']: #only 2/3 can be red; not 1/3 or 3/3
if SGData['SGSpin'][1]*SGData['SGSpin'][2]*SGData['SGSpin'][3] < 0:
SGData['SGSpin'][(isym+1)%3+1] *= -1
if SGData['SpGrp'][0] == 'F' and isym > 2:
SGData['SGSpin'][(isym+1)%3+3] == 1
elif SGData['SGPtGrp'] == 'mmm':
if SGData['SpGrp'][0] == 'F' and isym > 2:
SGData['SGSpin'][(isym+1)%3+3] == 1
def MagSGSym(SGData): #needs to use SGPtGrp not SGLaue!
SGLaue = SGData['SGLaue']
if '1' not in SGData['GenSym']: #patch for old gpx files
SGData['GenSym'] = ['1',]+SGData['GenSym']
SGData['SGSpin'] = [1,]+list(SGData['SGSpin'])
if len(SGData['SGSpin'])<len(SGData['GenSym']):
SGData['SGSpin'] = [1,]+list(SGData['SGSpin']) #end patch
GenSym = SGData['GenSym'][1:] #skip identity
SpnFlp = SGData['SGSpin']
# print('SpnFlp',SpnFlp)
SGPtGrp = SGData['SGPtGrp']
if len(SpnFlp) == 1:
SGData['MagPtGp'] = SGPtGrp
return SGData['SpGrp']
magSym = SGData['SpGrp'].split()
if SGLaue in ['-1',]:
SGData['MagPtGp'] = SGPtGrp
if SpnFlp[1] == -1:
magSym[1] += "'"
SGData['MagPtGp'] += "'"
elif SGLaue in ['2/m','4/m','6/m']: #all ok
Uniq = {'a':1,'b':2,'c':3,'':1}
Id = [0,1]
if len(magSym) > 2:
Id = [0,Uniq[SGData['SGUniq']]]
sym = magSym[Id[1]].split('/')
Ptsym = SGLaue.split('/')
if len(GenSym) == 3:
for i in [0,1,2]:
if SpnFlp[i+1] < 0:
sym[i] += "'"
Ptsym[i] += "'"
else:
for i in range(len(GenSym)):
if SpnFlp[i+1] < 0:
sym[i] += "'"
Ptsym[i] += "'"
SGData['MagPtGp'] = '/'.join(Ptsym)
magSym[Id[1]] = '/'.join(sym)
elif SGPtGrp in ['mmm','mm2','m2m','2mm','222']:
SGData['MagPtGp'] = ''
for i in [0,1,2]:
SGData['MagPtGp'] += SGPtGrp[i]
if SpnFlp[i+1] < 0:
magSym[i+1] += "'"
SGData['MagPtGp'] += "'"
elif SGLaue == '6/mmm': #ok
magPtGp = list(SGPtGrp)
if len(GenSym) == 2:
for i in [0,1]:
if SpnFlp[i+1] < 0:
magSym[i+2] += "'"
magPtGp[i+1] += "'"
if SpnFlp[1]*SpnFlp[2] < 0:
magSym[1] += "'"
magPtGp[0] += "'"
else:
sym = magSym[1].split('/')