-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrigid.py
273 lines (248 loc) · 12.9 KB
/
rigid.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
"""
Crystallographic viewing directions
Triclinic: -
Monoclinic: b(c)
Orthorhombic: a b c
Tetragonal: c a [110]
Trigonal: c a [210]
Hexagonal: c a [210]
cubic: a [111] [110]
"""
from functions import *
from readinginput import *
def sym_to_lattice(sym_no):
if 1 <= sym_no <= 2:
lattice = 'Triclinic'
elif 3 <= sym_no <= 15:
lattice = 'Monoclinic'
elif 16 <= sym_no <= 74:
lattice = 'Orthorhombic'
elif 75 <= sym_no <= 142:
lattice = 'Tetragonal'
elif 143 <= sym_no <= 167:
lattice = 'Trigonal'
elif 168 <= sym_no <= 194:
lattice = 'Hexagonal'
elif 195 <= sym_no <= 230:
lattice = 'Cubic'
return lattice
# initial wyckoff_positions are direct coordinates
# initial_positions are car coordinaties
def move_rigid_to_wyckoff(initial_positions, wyckoff_positions, rigid_type, cell):
wyckoff_move = np.array([0.0, 0.0, 0.0])
random_wyckoff = np.array([0.0, 0.0, 0.0])
rigid_class = rigid_select(rigid_type)(1, 1.0)
if wyckoff_positions[0] != 'x':
random_wyckoff[0] = wyckoff_positions[0]
elif wyckoff_positions[0] == 'x':
random_wyckoff[0] = round(random.uniform(0, 1), 3)
if wyckoff_positions[1] != 'y' and wyckoff_positions[1] != '-x' and wyckoff_positions[1] != 'x+0.5':
random_wyckoff[1] = wyckoff_positions[1]
elif wyckoff_positions[1] == '-x':
random_wyckoff[1] = (-1.0) * random_wyckoff[0]
elif wyckoff_positions[1] == 'x+0.5':
random_wyckoff[1] = random_wyckoff[0] + 0.5
elif wyckoff_positions[1] == 'y':
random_wyckoff[1] = round(random.uniform(0, 1), 3)
if wyckoff_positions[2] != 'z':
random_wyckoff[2] = wyckoff_positions[2]
elif wyckoff_positions[2] == 'z':
random_wyckoff[2] = round(random.uniform(0, 1), 3)
random_wyckoff_car = direct_cartesian_transform(random_wyckoff, cell, 'DtoC')
rigid_center = rigid_class.center(initial_positions)
wyckoff_move = random_wyckoff_car - rigid_center
final_positions = initial_positions + wyckoff_move
return final_positions
def rigid_select(rigid_type):
if rigid_type == 'Tetrahedron':
rigid_sele = Tetrahedron
if rigid_type == 'GeSe':
rigid_sele = GeSe
return rigid_sele
class rigid_rotation:
def __init__(self, positions, center):
self.positions = positions
self.center = center
def random_rotation(self, sym_no, sym_element, angle_range, cell):
lattice_type = sym_to_lattice(sym_no)
random_angle = round(random.uniform(-angle_range, angle_range), 0)
random_vector = np.random.rand(3)
random_unit_vector = random_vector / np.linalg.norm(random_vector)
r_matrix = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
if lattice_type == 'Triclinic':
if sym_element == ['1'] or sym_element == ['-1']:
r_matrix = rotation_matrix(random_unit_vector, random_angle)
elif lattice_type == 'Monoclinic':
if sym_element == ['1'] or sym_element == ['-1']:
r_matrix = rotation_matrix(random_unit_vector, random_angle)
elif sym_element == ['2'] or ['m'] or ['2/m']:
b_unit = cell[1] / np.linalg.norm(cell[1])
r_matrix = rotation_matrix(b_unit, random_angle)
elif lattice_type == 'Orthorhombic':
if sym_element == ['1'] or sym_element == ['-1']:
r_matrix = rotation_matrix(random_unit_vector, random_angle)
elif sym_element == ['x', 'y', '2'] or sym_element == ['x', 'y', 'm'] or sym_element == ['x', 'y', '2/m']:
r_matrix = rotation_matrix([0, 0, 1], random_angle)
elif sym_element == ['x', '2', 'z'] or sym_element == ['x', 'm', 'z'] or sym_element == ['x', '2/m', 'z']:
r_matrix = rotation_matrix([0, 1, 0], random_angle)
elif sym_element == ['2', 'y', 'z'] or sym_element == ['m', 'y', 'z'] or sym_element == ['2/m', 'y', 'z']:
r_matrix = rotation_matrix([1, 0, 0], random_angle)
elif sym_element == ['2', '2', '2']:
ra = rotation_matrix([1, 0, 0], random_angle)
rb = rotation_matrix([0, 1, 0], random_angle)
rc = rotation_matrix([0, 0, 1], random_angle)
r_matrix = ra @ rb @ rc
move_array = np.array([0, 0, 0]) - self.center
origin_positions = self.positions + move_array
rotate_positions = origin_positions @ r_matrix
final_positions = rotate_positions - move_array
return final_positions
def setup_random_rotation(sym_no, sym_element, angle_range, cell):
lattice_type = sym_to_lattice(sym_no)
random_angle = round(random.uniform(-angle_range, angle_range), 0)
random_vector = np.random.rand(3)
random_unit_vector = random_vector / np.linalg.norm(random_vector)
# r_matrix = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
if lattice_type == 'Triclinic':
if sym_element == ['1'] or sym_element == ['-1']:
r_matrix = rotation_matrix(random_unit_vector, random_angle)
elif lattice_type == 'Monoclinic':
if sym_element == ['1'] or sym_element == ['-1']:
r_matrix = rotation_matrix(random_unit_vector, random_angle)
elif sym_element == ['2'] or ['m'] or ['2/m']:
b_unit = cell[1] / np.linalg.norm(cell[1])
r_matrix = rotation_matrix(b_unit, random_angle)
elif lattice_type == 'Orthorhombic':
if sym_element == ['1'] or sym_element == ['-1']:
r_matrix = rotation_matrix(random_unit_vector, random_angle)
elif sym_element == ['x', 'y', '2'] or sym_element == ['x', 'y', 'm'] or sym_element == ['x', 'y', '2/m']:
r_matrix = rotation_matrix([0, 0, 1], random_angle)
elif sym_element == ['x', '2', 'z'] or sym_element == ['x', 'm', 'z'] or sym_element == ['x', '2/m', 'z']:
r_matrix = rotation_matrix([0, 1, 0], random_angle)
elif sym_element == ['2', 'y', 'z'] or sym_element == ['m', 'y', 'z'] or sym_element == ['2/m', 'y', 'z']:
r_matrix = rotation_matrix([1, 0, 0], random_angle)
elif sym_element == ['2', '2', '2']:
ra = rotation_matrix([1, 0, 0], random_angle)
rb = rotation_matrix([0, 1, 0], random_angle)
rc = rotation_matrix([0, 0, 1], random_angle)
r_matrix = ra @ rb @ rc
return r_matrix
class Tetrahedron:
def __init__(self, sym_no, bond_len):
self.sym_no = sym_no
self.bond_len = bond_len
self.atom_no = 5
def atoms_position(self):
site_ori = np.array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0], [1.0, -1.0, -1.0], [-1.0, 1.0, -1.0], [-1.0, -1.0, 1.0]])
site_fin = (site_ori / 1.73205) * self.bond_len
return site_fin
def center(self, atom_positions):
center_position = atom_positions[0]
return center_position
def wyckoff_sym(self):
lattice_type = sym_to_lattice(self.sym_no)
if lattice_type == 'Triclinic':
wyck_sym = [['1'], ['m'], ['2']]
elif lattice_type == 'Monoclinic':
wyck_sym = [['1'], ['m'], ['2']]
elif lattice_type == 'Orthorhombic':
wyck_sym = [['1'], ['m', 'y', 'z'], ['x', 'm', 'z'], ['x', 'y', 'm'], ['2', 'y', 'z'],
['x', '2', 'z'],['x', 'y', '2'], ['2', 'm', 'm'], ['m', '2', 'm'], ['m', 'm', '2']]
elif lattice_type == 'Tetragonal':
wyck_sym = [['1'], ['m', 'y', 'z'], ['x', 'm', 'z'], ['x', 'y', 'm'], ['2', 'y', 'z'],
['x', '2', 'z'], ['x', 'y', '2'], ['-4', 'y', 'z'], ['-4', '2', 'm']]
elif lattice_type == 'Trigonal':
wyck_sym = [['1'], ['m', 'y', 'z'], ['x', 'm', 'z'], ['x', 'y', 'm'], ['2', 'y', 'z'],
['x', '2', 'z'], ['x', 'y', '2'], ['-4', 'y', 'z'], ['-4', '2', 'm']]
elif lattice_type == 'Hexagonal':
wyck_sym = [['1'], ['2', 'y', 'z'], ['3', 'y', 'z']]
return wyck_sym
def rotaiton_matrix(self, sym_element):
lattice_type = sym_to_lattice(self.sym_no)
r_matrix = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
if lattice_type == 'Monoclinic':
if sym_element == ['m']:
r_matrix = rotation_matrix([1, 0, 0], 45)
elif sym_element == ['2']:
r_matrix = rotation_matrix([1, 0, 0], 45) @ rotation_matrix([0, 0, 1], 90)
elif lattice_type == 'Orthorhombic':
if sym_element == ['m', 'y', 'z'] or sym_element == ['x', 'm', 'z'] or \
sym_element == ['x', 'y', '2'] or sym_element == ['m', 'm', '2']:
r_matrix = rotation_matrix([0, 0, 1], 45)
elif sym_element == ['x', 'y', 'm'] or sym_element == ['x', '2', 'z'] or \
sym_element == ['m', '2', 'm']:
r_matrix == rotation_matrix([0, 0, 1], 45) @ rotation_matrix([1, 0, 0], 90)
elif sym_element == ['2', 'y', 'z'] or sym_element == ['2', 'm', 'm']:
r_matrix == rotation_matrix([0, 0, 1], 45) @ rotation_matrix([0, 1, 0], 90)
elif lattice_type == 'Tetragonal':
pass
elif lattice_type == 'Trigonal':
if sym_element == ['x', 'y', '2']:
r_matrix = rotation_matrix([0, 0, 1], 45)
elif sym_element == ['x', 'y', 'm'] or sym_element == ['x', '2', 'z']:
r_matrix == rotation_matrix([0, 0, 1], 45) @ rotation_matrix([1, 0, 0], 90)
elif sym_element == ['2', 'y', 'z']:
r_matrix == rotation_matrix([0, 0, 1], 45) @ rotation_matrix([0, 1, 0], 90)
elif lattice_type == 'Hexagonal':
pass
elif lattice_type == 'cubic':
pass
return r_matrix
class GeSe:
def __init__(self, sym_no, bond_len):
self.sym_no = sym_no
self.bond_len = bond_len
self.atom_no = 8
def atoms_position(self):
site_ori = np.array([[0.00000000e+00, 0.00000000e+00, 8.66025000e-01],
[0.00000000e+00, 0.00000000e+00, -8.66025000e-01],
[1.41421356e+00, 8.16496477e-01, 1.44337542e+00],
[1.11022302e-16, -1.63299327e+00, 1.44337498e+00],
[-1.41421356e+00, 8.16496477e-01, 1.44337542e+00],
[-8.88175036e-08, 1.63299311e+00, -1.44337542e+00],
[-1.41421366e+00, -8.16496635e-01, -1.44337498e+00],
[1.41421347e+00, -8.16496631e-01, -1.44337542e+00]])
site_fin = (site_ori / 1.73205) * self.bond_len
return site_fin
def center(self, atom_positions):
center_position = (atom_positions[0] + atom_positions[1]) / 2.0
return center_position
def wyckoff_sym(self):
lattice_type = sym_to_lattice(self.sym_no)
if lattice_type == 'Triclinic':
wyck_sym = [['1'], ['-1'], ['-2']]
elif lattice_type == 'Monoclinic':
wyck_sym = [['1'], ['-1'], ['m'], ['-2']]
elif lattice_type == 'Orthorhombic':
wyck_sym = [['1'], ['m', 'y', 'z'], ['x', 'm', 'z'], ['x', 'y', 'm'], ['2', 'y', 'z'], ['x', '2', 'y'],
['x', 'y', '2']]
elif lattice_type == 'Tetragonal':
wyck_sym = [['1'], ['-1'], ['2', 'y', 'z'], ['x', '2', 'z'], ['x', 'y', '2'], ['3', 'y', 'z'], ['x', 'm', 'z'], ['m', 'y', 'z'], ['x', 'y', 'm'],
['-3', 'y', 'z'], ['3', '2', 'z'], ['3', 'm', 'z'], ['-3', 'm', 'z']]
elif lattice_type == 'Trigonal':
wyck_sym = [['1'], ['-1'], ['2', 'y', 'z'], ['x', '2', 'z'], ['x', 'y', '2'], ['3', 'y', 'z'], ['x', 'm', 'z'], ['m', 'y', 'z'], ['x', 'y', 'm'],
['-3', 'y', 'z'], ['3', '2', 'z'], ['3', 'm', 'z'], ['-3', 'm', 'z']]
elif lattice_type == 'Hexagonal':
wyck_sym = [['1'], ['-1'], ['2', 'y', 'z'], ['x', '2', 'z'], ['x', 'y', '2'], ['3', 'y', 'z'], ['x', 'm', 'z'], ['m', 'y', 'z'], ['x', 'y', 'm'],
['-3', 'y', 'z'], ['3', '2', 'z'], ['3', 'm', 'z'], ['-3', 'm', 'z']]
return wyck_sym
def rotaiton_matrix(self, sym_element):
lattice_type = sym_to_lattice(self.sym_no)
r_matrix = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
if lattice_type == 'Monoclinic':
if sym_element == ['m']:
r_matrix = rotation_matrix([0, 0, 1], 90)
elif lattice_type == 'Orthorhombic':
if sym_element == ['x', 'm', 'z']:
r_matrix = rotation_matrix([0, 0, 1], 90)
elif sym_element == ['x', 'y', 'm']:
r_matrix == rotation_matrix([1, 0, 0], 90) @ rotation_matrix([0, 1, 0], 90)
elif lattice_type == 'Tetragonal':
pass
elif lattice_type == 'Trigonal':
pass
elif lattice_type == 'Hexagonal':
pass
elif lattice_type == 'cubic':
pass
return r_matrix