-
Notifications
You must be signed in to change notification settings - Fork 0
/
xtal.py
2324 lines (1909 loc) · 79.9 KB
/
xtal.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
# -*- coding: utf-8 -*-
'''
ovlib.xtal: Crystallography
===============================================================================
'''
def point_group_number_from_space_group_number(spacegroup):
""" extract point group from space group
Get the point group number from the space group number
Parameters
----------
spacegroup : int
space group number
Returns
-------
pointgroup : int
point group number
Notes
-----
Point groups and space groups are numbered according to the international
notation, NOT python 0-based indexing.
"""
pg = 1
if spacegroup > 1: pg = 2
if spacegroup > 2: pg = 3
if spacegroup > 5: pg = 4
if spacegroup > 9: pg = 5
if spacegroup > 15: pg = 6
if spacegroup > 24: pg = 7
if spacegroup > 46: pg = 8
if spacegroup > 74: pg = 9
if spacegroup > 80: pg = 10
if spacegroup > 82: pg = 11
if spacegroup > 88: pg = 12
if spacegroup > 98: pg = 13
if spacegroup > 110: pg = 14
if spacegroup > 122: pg = 15
if spacegroup > 142: pg = 16
if spacegroup > 146: pg = 17
if spacegroup > 148: pg = 18
if spacegroup > 155: pg = 19
if spacegroup > 161: pg = 20
if spacegroup > 167: pg = 21
if spacegroup > 173: pg = 22
if spacegroup > 174: pg = 23
if spacegroup > 176: pg = 24
if spacegroup > 182: pg = 25
if spacegroup > 186: pg = 26
if spacegroup > 190: pg = 27
if spacegroup > 194: pg = 28
if spacegroup > 199: pg = 29
if spacegroup > 206: pg = 30
if spacegroup > 214: pg = 31
if spacegroup > 220: pg = 32
return pg
def laueclass(pointgroup, notation='international'):
''' get the Laue class
Returns the Laue class of the given point group.
Parameters
----------
pointgroup : int
Point group number
notation : str (optional)
Name of convention used: {'schoenflies', 'geo', 'international', 'tsl'}
Default: 'international'
Returns
-------
laueclass : int
the number corresponding to the Laue class of the point group
Notes
-----
The Laue class of a point group is the next higher-order group in the same
Bravais lattice that contains a center of symmetry.
=========== ============ =============== ===== =========================
Point Group Space Groups Bravais Lattice Name Notes
=========== ============ =============== ===== =========================
1 1 Triclinic 1
2 2 -1
3 3-5 Monoclinic 2
4 6-9 m
5 10-15 2/m
6 16-24 Orthorhombic 222
7 25-46 mm2 39: bc in MDG code (why not in 222?)
8 47-74 mmm
9 75-80 Tetragonal 4
10 81-82 -4
11 83-88 4/m
12 89-98 422 90: bg and no c in MDG code (why not in Tetrag 4?)
13 99-110 4mm
14 111-122 -42m 115-120: bmj
15 123-142 4/mmm
16 143-146 Trigonal 3
17 147-148 (Rhombohedral) -3
18 149-155 32 149,151,153: nf
19 156-161 3m 157,159: nl
20 162-167 -3m 162,163: nf
21 168-173 Hexagonal 6
22 174 -6
23 175-176 6/m
24 177-182 622
25 183-186 6mm
26 187-190 -6m2 187,188: nik
27 191-194 6/mmm
28 195-199 Cubic 23
29 200-206 m3
30 207-214 432
31 215-220 -43m
32 221-230 m-3m
=========== ============ =============== ===== =========================
'''
if type(pointgroup)==str:
pgid = interpret_point_group_name(pointgroup, notation)
elif type(pointgroup)==int:
pgid = pointgroup
else:
print 'pointgroup input to laueclass was neither a string \
nor an integer. Using laue class m.'
pgid = 1
if pgid > 32:
print 'Invalid point group number. Returning 32.'
laue = 32
if pgid <= 29:
laue = 29
if pgid <= 27:
laue = 27
if pgid <= 23:
laue = 23
if pgid <= 20:
laue = 20
if pgid <= 17:
laue = 17
if pgid <= 15:
laue = 15
if pgid <= 11:
laue = 11
if pgid <= 8:
laue = 8
if pgid <= 5:
laue = 5
if pgid <= 2:
laue = 2
return laue
#-------------------------------------------------------------------------------
def ctf_laue_from_laue_group(laueclass):
''' channel text file laue group interpretation
Converts between the identification scheme for Laue groups used in ovlib
(which is the point group corresponding to the Laue class) to the scheme
used in Channel Text Files (*.ctf).
Parameters
----------
laueclass : int
Point group number corresponding to the laue class of the phase.
Returns
-------
ctflaue : int
The Laue class number (as used in *.ctf files)
'''
# convert to internal naming scheme
pgid = laueclass
del laueclass
laue = 11
if pgid == 29:
laue = 10
if pgid == 27:
laue = 9
if pgid == 23:
laue = 8
if pgid == 20:
laue = 7
if pgid == 17:
laue = 6
if pgid == 15:
laue = 5
if pgid == 11:
laue = 4
if pgid == 8:
laue = 3
if pgid == 5:
laue = 2
if pgid == 2:
laue = 1
return laue
#-------------------------------------------------------------------------------
def rotationelements(point_group_name, notation='international'):
"""
Function for generating rotational symmetries
Parameters
----------
point_group_name : str
The name of the point group.
notation : string (optional)
Name of convention used: {'schoenflies', 'geo', 'international', 'tsl'}
Default: 'international'
Returns
-------
rotsymm : quaternion class
The set of rotational symmetries.
Notes
-----
As the name suggests, this function returns only the rotational symmetry
elements and NOT the full symmetry, which may include rotoinversions. Thus,
this should be used carefully and only applied to orientations. Many
symmetry-related operations on vectors or miller indices should use the
full set of symmetry operations.
"""
import numpy as np
import numpy.linalg as npla
import cryspy.util as util
pge = pointgroupelements(point_group_name, notation)
n = pge.numel()
a = pge.to_array()
# proper rotations have determinants == positive unity
determinant = np.zeros([n,1])
for i in range(0,n):
determinant[i] = npla.det(a[i,:].reshape(3,3))
determinant = util.sigdec(determinant, 1)
if np.shape(determinant)[0] > 1:
rotsymm = pge[np.squeeze(determinant == 1)]
else:
rotsymm = pge[0]
return rotsymm
#-------------------------------------------------------------------------------
def interpret_point_group_number(point_group_number, notation='international'):
""" convert point group number to point group name
Parses a point group number and converts it to the point group name in the
desired notation.
Parameters
----------
point_group_number : int {1:32}
notation : string (optional)
Name of convention used: {'schoenflies', 'geo', 'international', 'tsl'}
Default: 'international'
Returns
-------
point_group_name : string
Notes
-----
- In the Schoenflies and geometric notations, there are multiple possible
identification names for some of the point groups. For these cases,
this function only returns one of the possible names.
- The geometric notation information comes from [1]_.
- 'tsl' is the convention used in TSL/EDAX *.ang files. It bears some
resemblance to the geometric convention
References
----------
.. [1] D. Hestenes, J. Holt. "The Crystallographic Space Groups in
Geometric Algebra." J Math Phy, 2007.
"""
if notation=='international': # default
opts=['1' , # 1
'-1' , # 2
'2' , # 3
'm' , # 4
'2/m' , # 5
'222' , # 6
'mm2' , # 7
'mmm' , # 8
'4' , # 9
'-4' , #10
'4/m' , #11
'422' , #12
'4mm' , #13
'42m' , #14
'4/mmm', #15
'3' , #16
'-3' , #17
'32' , #18
'3m' , #19
'-3m' , #20
'6' , #21
'-6' , #22
'6/m' , #23
'622' , #24
'6mm' , #25
'-6m2' , #26
'6/mmm', #27
'23' , #28
'm-3' , #29
'432' , #30
'-43m' , #31
'm-3m' ] #32
elif notation=='schoenflies':
opts=[ 'C1' , # 1
'S2' , # 2
'C2' , # 3
'C1h', # 4
'C2h', # 5
'V' , # 6
'C2v', # 7
'D2h', # 8
'C4' , # 9
'S4' , #10
'C4h', #11
'D4' , #12
'C4v', #13
'D2d', #14
'D4h', #15
'C3' , #16
'S6' , #17
'D3' , #18
'C3v', #19
'D3d', #20
'C6' , #21
'C3h', #22
'C6h', #23
'D6' , #24
'C6v', #25
'D3h', #26
'D6h', #27
'T' , #28
'Th' , #29
'O' , #30
'Td' , #31
'Oh' ] #32
elif notation=="geo":
opts=[ '-1' , # 1
'-2-2', # 2
'-2' , # 3
'1' , # 4
'-22' , # 5
'-2-2', # 6
'2' , # 7
'22' , # 8
'-4' , # 9
'-4-2', #10
'-42' , #11
'-4-2', #12
'4' , #13
'4-2' , #14
'42' , #15
'-3' , #16
'-6-2' , #17
'-3-2' , #18
'3' , #19
'6-2' , #20
'-6' , #21
'-32' , #22
'-62' , #23
'-6-2' , #24
'6' , #25
'32' , #26
'62' , #27
'-3-3' , #28
'4-3' , #29
'-4-3' , #30
'-33' , #31
'-43' ] #32
elif notation=="tsl":
# TSL uses the rotation symmetries of the corresponding Laue group.
opts=[ '1' , # 1
'1' , # 2
'20', # 3
'20', # 4
'20', # 5
'22', # 6
'22', # 7
'22', # 8
'4' , # 9
'4' , #10
'4' , #11
'42', #12
'42', #13
'42', #14
'42', #15
'3' , #16
'3' , #17
'32', #18
'32', #19
'32', #20
'6' , #21
'6' , #22
'6' , #23
'62', #24
'62', #25
'62', #26
'62', #27
'23', #28
'23', #29
'43', #30
'43', #31
'43'] #32
return opts[point_group_number - 1]
#-------------------------------------------------------------------------------
def interpret_point_group_name(point_group_name, notation='international'):
''' convert point group name to number
Parses a point group name and converts it to the point group number.
Parameters
----------
point_group_name : string
Name of point group in Schoenflies, geometric, international, or TSL
convention.
notation : string
Name of convention used: {'schoenflies', 'geo', 'international', 'tsl'}
Default: 'international'
Returns
-------
point_group_number : integer
Notes
-----
- 'tsl' is the convention used in TSL/EDAX *.ang files. It bears some
resemblance to the geometric convention.
'''
# The 32 point groups in international and schoenflies notations have
# no conflicting names
if ((notation==None) or
(notation=='schoenflies') or
(notation=='international')): # default
# Assign our possible options
opts=[ '1','C1',#1
'-1','S2','Ci',#2
'2','C2',#3
'm','C1h','Cs',#4
'2/m','C2h',#5
'222','D2','V',#6
'mm2','C2v',#7
'mmm','D2h','Vh',#8
'4','C4',#9
'-4','S4',#10
'4/m','C4h',#11
'422','D4',#12
'4mm','C4v',#13
'42m','D2d','Vd','-42m',#14
'4/mmm','D4h',#15
'3','C3',#16
'-3','S6','C31','C3i',#17
'32','D3',#18
'3m','C3v',#19
'-3m','D3d',#20
'6','C6',#21
'-6','C3h',#22
'6/m','C6h',#23
'622','D6',#24
'6mm','C6v',#25
'6m2','-6m2','-62m','62m','D3h',#26
'6/mmm','D6h',#27
'23','T',#28
'm3','m-3','Th',#29
'432','O',#30
'43m','-43m','Td',#31
'm3m','m-3m','Oh'#32
]
# assign the key to understanding those options
key = [ 0,0,
1,1,1,
2,2,
3,3,3,
4,4,
5,5,5,
6,6,
7,7,7,
8,8,
9,9,
10,10,
11,11,
12,12,
13,13,13,13,
14,14,
15,15,
16,16,16,16,
17,17,
18,18,
19,19,
20,20,
21,21,
22,22,
23,23,
24,24,
25,25,25,25,25,
26,26,
27,27,
28,28,28,
29,29,
30,30,30,
31,31,31];
if notation=="geo":
# The geometric convention conflicts terribly with the international convention
opts=['-1',
'-2-2',
'-2',
'1',
'-22',
'-2-2',
'2',
'22',
'-4',
'-4-2',
'-42',
'-4-2',
'4',
'4-2',
'42',
'-3',
'-6-2',
'-3-2',
'3',
'6-2',
'-6',
'-32',
'-62',
'-6-2',
'6',
'32',
'62',
'-3-3',
'4-3',
'-4-3',
'33','-33',
'43','-43']
key=[0,
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,30,
31,31]
if notation=="tsl":
# TSL uses the rotation symmetries of the corresponding Laue group.
opts=['1', #2
'2','20', #5 (also allowing "2" since "20" does not appear to
# follow the rest of the convention)
'22', #8
'4', #11
'42', #15
'3', #17
'32', #20
'6', #23
'62', #27
'23', #29
'43'] #32
key=[1,4,4,7,10,14,16,19,22,26,28,31]
# Get the point group number from the point group name, converting indexing
point_group_id_number=key[opts.index(point_group_name)] + 1
return point_group_id_number
def pointgroupelements(point_group_name, notation='international'):
''' generate point group elements
Function for generating point group symmetry elements containing
subfunctions for creating the point group symmetries.
Parameters
----------
point_group_name : {str, int}
The name of the point group.
notation : str
Name of convention used: {'schoenflies', 'geo', 'international', 'tsl'}
Default: 'international'
Returns
-------
pge : rmat class
Rotation matrices for the point group elements.
Notes
-----
This is a Python translation of the codes from [1]_.
References
----------
.. [1] M. De Graef, "Introduction to Conventional Transmission Electron
Microscopy." Cambridge University Press, 2003.
'''
def make_generator_string(point_group_id_number):
"""
Notes:
- Need to check that point groups 39 and 90 are correct.
- The matrices produced may be incorrect for space groups 115-120,
149, 151, 153, 157, 159, 162, 163, 187, and 188 due to setting
issues. This is a total of 15 out of 230 space groups.
"""
# Code Point Group Space Groups Bravais Lattice Name Notes
opts=[ 'a', # 1 1 --- Triclinic 1
'h', # 2 2 -1
'c', # 3 3-5 --- Monoclinic 2
'j', # 4 6-9 m
'ch', # 5 10-15 2/m
'bc', # 6 16-24 --- Orthorhombic 222
'bj', # 7 25-46 mm2 39: bc in MDG code (why not in 222?)
'bch', # 8 47-74 mmm
'bg', # 9 75-80 --- Tetragonal 4
'bm', # 10 81-82 -4
'bgh', # 11 83-88 4/m
'bgc', # 12 89-98 422 90: bg and no c in MDG code (why not in Tetrag 4?)
'bgj', # 13 99-110 4mm
'bmc', # 14 111-122 -42m 115-120: bmj
'bgch', # 15 123-142 4/mmm
'n', # 16 143-146 --- Trigonal 3
'nh', # 17 147-148 (Rhombohedral) -3
'ne', # 18 149-155 32 149,151,153: nf
'nk', # 19 156-161 3m 157,159: nl
'neh', # 20 162-167 -3m 162,163: nf
'nb', # 21 168-173 --- Hexagonal 6
'ni', # 22 174 -6
'nbh', # 23 175-176 6/m
'nbe', # 24 177-182 622
'nbk', # 25 183-186 6mm
'nie', # 26 187-190 -6m2 187,188: nik
'nbeh', # 27 191-194 6/mmm
'bcd', # 28 195-199 --- Cubic 23
'bcdh', # 29 200-206 m3
'bcde', # 30 207-214 432
'bcdl', # 31 215-220 -43m
'bcdeh' # 32 221-230 m-3m
]
# pass the point group number through the option list to obtain the
# generator string
generator_string=opts[point_group_id_number]
return generator_string
'''
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'''
def interpret_generator_string(generator_string):
import numpy as np
n = len(generator_string)
generator_matrices = np.zeros([n,9])
for i in range(0,n):
tmp = make_generator_matrix(generator_string[i]).T
generator_matrices[i,:] = tmp.reshape(1,9)
return generator_matrices
'''
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'''
def make_generator_matrix(t):
# Create the generator matrices. Follows De Graef's approach.
import numpy as np
gmx = np.zeros([3,3]) # preallocate the generator matrix
if t == 'a':
gmx[0,0]= 1.0; gmx[1,1]= 1.0; gmx[2,2]= 1.0;
elif t == 'b':
gmx[0,0]=-1.0; gmx[1,1]=-1.0; gmx[2,2]= 1.0;
elif t == 'c':
gmx[0,0]=-1.0; gmx[1,1]= 1.0; gmx[2,2]=-1.0;
elif t == 'd':
gmx[0,2]= 1.0; gmx[1,0]= 1.0; gmx[2,1]= 1.0;
elif t == 'e':
gmx[0,1]= 1.0; gmx[1,0]= 1.0; gmx[2,2]=-1.0;
elif t == 'f':
gmx[0,1]=-1.0; gmx[1,0]=-1.0; gmx[2,2]=-1.0;
elif t == 'g':
gmx[0,1]=-1.0; gmx[1,0]= 1.0; gmx[2,2]= 1.0;
elif t == 'h':
gmx[0,0]=-1.0; gmx[1,1]=-1.0; gmx[2,2]=-1.0;
elif t == 'i':
gmx[0,0]= 1.0; gmx[1,1]= 1.0; gmx[2,2]=-1.0;
elif t == 'j':
gmx[0,0]= 1.0; gmx[1,1]=-1.0; gmx[2,2]= 1.0;
elif t == 'k':
gmx[0,1]=-1.0; gmx[1,0]=-1.0; gmx[2,2]= 1.0;
elif t == 'l':
gmx[0,1]= 1.0; gmx[1,0]= 1.0; gmx[2,2]= 1.0;
elif t == 'm':
gmx[0,1]= 1.0; gmx[1,0]=-1.0; gmx[2,2]=-1.0;
elif t == 'n':
gmx[0,1]=-1.0; gmx[1,0]= 1.0; gmx[1,1]=-1.0; gmx[2,2]= 1.0;
return gmx
'''
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'''
def generate_point_group_elements(generator_matrices):
'''
Multiply the generator matrices together until no new matrices are
created. The correct number of matrices are produced (see OJ Curnow,
Chemical Education Today 84 (2007) p1430 for a nice mnemonic trick).
I have some concerns that the exact matrices produced in the present
code may, however, not all be correct. See "notes" in
make_generator_string.
Parameters
----------
generator_matrices : numpy array
Returns
-------
'''
import cryspy.util as util
import numpy as np
n1 = 0
n2 = generator_matrices.shape[0]
while n1<n2:
for i in range(n1,n2):
for j in range(0,n2):
tmp = np.dot(generator_matrices[i,:].reshape(3,3).T,
generator_matrices[j,:].reshape(3,3).T).T
generator_matrices = np.concatenate((generator_matrices,
tmp.reshape(1,9)), axis=0)
generator_matrices, loc, tmp = util.uniquerows(generator_matrices)
n1 = n2
n2 = generator_matrices.shape[0]-1
return generator_matrices
###########################################################################
#if point_group_name.__class__
point_group_number = interpret_point_group_name(point_group_name, notation)
generator_string = make_generator_string(point_group_number - 1)
generator_matrices = interpret_generator_string(generator_string)
point_group_symmetry_matrices = generate_point_group_elements(
generator_matrices)
import cryspy.rot as rot
point_group_symmetry_elements = rot.rmat(
g11 = point_group_symmetry_matrices[:,0],
g12 = point_group_symmetry_matrices[:,1],
g13 = point_group_symmetry_matrices[:,2],
g21 = point_group_symmetry_matrices[:,3],
g22 = point_group_symmetry_matrices[:,4],
g23 = point_group_symmetry_matrices[:,5],
g31 = point_group_symmetry_matrices[:,6],
g32 = point_group_symmetry_matrices[:,7],
g33 = point_group_symmetry_matrices[:,8],
)
return point_group_symmetry_elements
#-------------------------------------------------------------------------------
class lattsite(object):
'''Lattice Site class
REFERENCES:
- M. De Graef, M. E. McHenry, "Structure of Materials: An Introduction to
Crystallography, Diffraction, and Symmetry." New York, NY: Cambridge
University Press, 2007.
- B. D. Cullity, S. R. Stock, "Elements of X-Ray Diffraction." 3rd Ed. Upper
Saddle River, NJ: Prentice Hall, 2001.
- D. E. Sands, "Introduction to Crystallography." Mineaola, NY:
Courier Dover Publications, 1993. p68, Eq. 3.3.
'''
def __init__(self, x=0, y=0, z=0):
# note that in the above initialization, the default values will be
# be given for the remaining parameters if insufficient values are
# passed to the function. The best way to avoid this problem is to
# always type u=..., v=..., w=... etc.
import numpy as np
import cryspy.util as util
# check that the shapes of all are the same
if np.shape(x)==np.shape(y)==np.shape(z):
# the following may look ridiculous, but it allows the arguments to
# be passed as np.matrices, np.arrays, tuples, or lists...
self.x = util.vecarrayconvert(x)
self.y = util.vecarrayconvert(y)
self.z = util.vecarrayconvert(z)
else:
print "lattvec construction error: check that the lengths of u,"\
" v, and w are all the same."
return None
#-------------------------------------------------------------------------------
def rotate(self, q2):
'''
Multiplication of lattice site coordinates.
When multiplied by quaternion, we rotate the coordinates of the
lattice site
'''
import numpy as np
import cryspy.rot as rot
if isinstance(q2, rot.quat):
t2 = q2.a * q2.b
t3 = q2.a * q2.c
t4 = q2.a * q2.d
t5 = -q2.b * q2.b
t6 = q2.b * q2.c
t7 = q2.b * q2.d
t8 = -q2.c * q2.c
t9 = q2.c * q2.d
t10 = -q2.d * q2.d
v1new = np.array([2.0*( (t8 + t10)*self.x +
(t6 - t4)*self.y +
(t3 + t7)*self.z ) + self.x])
v2new = np.array([2.0*( (t4 + t6)*self.x +
(t5 + t10)*self.y +
(t9 - t2)*self.z ) + self.y])
v3new = np.array([2.0*( (t7 - t3)*self.x +
(t2 + t9)*self.y +
(t5 + t8)*self.z ) + self.z])
return lattsite(x=v1new, y=v2new, z=v3new)
#-------------------------------------------------------------------------------
def to_cartesian(self, unit_cell):
'''
multiply by direct structure matrix to get cartesian vector
'''
if isinstance(unit_cell, unitcell):
d = unit_cell.d
vx = d[0, 0] * self.x + d[0, 1] * self.y + d[0, 2] * self.z
vy = d[1, 0] * self.x + d[1, 1] * self.y + d[1, 2] * self.z
vz = d[2, 0] * self.x + d[2, 1] * self.y + d[2, 2] * self.z
return [vx, vy, vz]
#-------------------------------------------------------------------------------
@classmethod
def from_cartesian(cls, arg, unit_cell, maxval=9):
'''
multiply by inverse transpose direct structure matrix
'''
import cryspy.util as util
if isinstance(unit_cell, unitcell):
x = arg[0]
y = arg[1]
z = arg[2]
d = unit_cell.dinv.T
un = d[0, 0] * x + d[0, 1] * y + d[0, 2] * z
vn = d[1, 0] * x + d[1, 1] * y + d[1, 2] * z
wn = d[2, 0] * x + d[2, 1] * y + d[2, 2] * z
u, v, w, dev = util.rationalize([un, vn, wn], maxval)
return cls(u, v, w), dev
#-------------------------------------------------------------------------------
def distance(self, site2, unit_cell):
'''
returns the distance between two lattice sites.
'''
import numpy as np
import cryspy.util as util
if isinstance(site2, lattsite) and isinstance(unit_cell, unitcell):
x = site2.x - self.x
y = site2.y - self.y
z = site2.z - self.z
# multiply by metric matrix to get cartesian vector
m = unit_cell.m
return np.sqrt(util.xtaldot(p1=x,p2=y,p3=z,
g11=m[0,0], g12=m[0,1], g13=m[0,2],
g21=m[1,0], g22=m[1,1], g23=m[1,2],
g31=m[2,0], g32=m[2,1], g33=m[2,2],
q1=x, q2=y, q3=z))
#-------------------------------------------------------------------------------
def angle(self, site2, unit_cell, origin):
'''
returns the angle between one lattice site and another lattice site,
relative to an origin and a given crystal description
'''
import cryspy.util as util
import numpy as np
if isinstance(site2, lattsite) and isinstance(origin, lattsite) and \
isinstance(unit_cell, unitcell):
pp1 = site2.x - origin.x
pp2 = site2.y - origin.y
pp3 = site2.z - origin.z
qq1 = self.x - origin.x
qq2 = self.y - origin.y
qq3 = self.z - origin.z
m = unit_cell.m
nrm = 1.0 / (util.vecarraynorm([pp1, pp2, pp3]) * \
util.vecarraynorm([qq1, qq2, qq3]))
return np.arccos(nrm *
util.xtaldot(p1=pp1, p2=pp2, p3=pp3,
g11=m[0,0], g12=m[0,1], g13=m[0,2],
g21=m[1,0], g22=m[1,1], g23=m[1,2],
g31=m[2,0], g32=m[2,1], g33=m[2,2],
q1=qq1, q2=qq2, q3=qq3))
#-------------------------------------------------------------------------------
def __sub__(self,vec2):
if isinstance(vec2, lattsite):
return lattsite(self.x-vec2.x, self.y-vec2.y, self.z-vec2.z)
#-------------------------------------------------------------------------------
def __add__(self,vec2):
if isinstance(vec2, lattvec):
return lattsite(self.x+vec2.x,self.y+vec2.y,self.z+vec2.z)
#-------------------------------------------------------------------------------