|
1 | | -#!/usr/bin/env python |
2 | | -"""Examples of python APIs.""" |
3 | | - |
4 | | -import numpy as np |
5 | | -import spglib |
6 | | - |
7 | | - |
8 | | -def _show_symmetry(symmetry): |
9 | | - for i in range(symmetry["rotations"].shape[0]): |
10 | | - print(" --------------- %4d ---------------" % (i + 1)) |
11 | | - rot = symmetry["rotations"][i] |
12 | | - trans = symmetry["translations"][i] |
13 | | - print(" rotation:") |
14 | | - for x in rot: |
15 | | - print(" [%2d %2d %2d]" % (x[0], x[1], x[2])) |
16 | | - print(" translation:") |
17 | | - print(" (%8.5f %8.5f %8.5f)" % (trans[0], trans[1], trans[2])) |
18 | | - |
19 | | - |
20 | | -def _show_lattice(lattice): |
21 | | - print("Basis vectors:") |
22 | | - for vec, axis in zip(lattice, ("a", "b", "c")): |
23 | | - print( |
24 | | - "%s %10.5f %10.5f %10.5f" |
25 | | - % ( |
26 | | - tuple( |
27 | | - axis, |
28 | | - ) |
29 | | - + tuple(vec) |
30 | | - ) |
31 | | - ) |
32 | | - |
33 | | - |
34 | | -def _show_cell(lattice, positions, numbers): |
35 | | - _show_lattice(lattice) |
36 | | - print("Atomic points:") |
37 | | - for p, s in zip(positions, numbers): |
38 | | - print("%2d %10.5f %10.5f %10.5f" % ((s,) + tuple(p))) |
39 | | - |
40 | | - |
41 | | -def main(): |
42 | | - silicon = ( |
43 | | - [(4, 0, 0), (0, 4, 0), (0, 0, 4)], |
44 | | - [ |
45 | | - (0, 0, 0), |
46 | | - (0, 0.5, 0.5), |
47 | | - (0.5, 0, 0.5), |
48 | | - (0.5, 0.5, 0), |
49 | | - (0.25, 0.25, 0.25), |
50 | | - (0.25, 0.75, 0.75), |
51 | | - (0.75, 0.25, 0.75), |
52 | | - (0.75, 0.75, 0.25), |
53 | | - ], |
54 | | - [ |
55 | | - 14, |
56 | | - ] |
57 | | - * 8, |
58 | | - ) |
59 | | - |
60 | | - silicon_dist = ( |
61 | | - [(4.01, 0, 0), (0, 4, 0), (0, 0, 3.99)], |
62 | | - [ |
63 | | - (0.001, 0, 0), |
64 | | - (0, 0.5, 0.5), |
65 | | - (0.5, 0, 0.5), |
66 | | - (0.5, 0.5, 0), |
67 | | - (0.25, 0.25, 0.251), |
68 | | - (0.25, 0.75, 0.75), |
69 | | - (0.75, 0.25, 0.75), |
70 | | - (0.75, 0.75, 0.25), |
71 | | - ], |
72 | | - [ |
73 | | - 14, |
74 | | - ] |
75 | | - * 8, |
76 | | - ) |
77 | | - |
78 | | - silicon_prim = ( |
79 | | - [(0, 2, 2), (2, 0, 2), (2, 2, 0)], |
80 | | - [(0, 0, 0), (0.25, 0.25, 0.25)], |
81 | | - [14, 14], |
82 | | - ) |
83 | | - |
84 | | - rutile = ( |
85 | | - [(4, 0, 0), (0, 4, 0), (0, 0, 3)], |
86 | | - [ |
87 | | - (0, 0, 0), |
88 | | - (0.5, 0.5, 0.5), |
89 | | - (0.3, 0.3, 0.0), |
90 | | - (0.7, 0.7, 0.0), |
91 | | - (0.2, 0.8, 0.5), |
92 | | - (0.8, 0.2, 0.5), |
93 | | - ], |
94 | | - [14, 14, 8, 8, 8, 8], |
95 | | - ) |
96 | | - |
97 | | - rutile_dist = ( |
98 | | - [(3.97, 0, 0), (0, 4.03, 0), (0, 0, 3.0)], |
99 | | - [ |
100 | | - (0, 0, 0), |
101 | | - (0.5001, 0.5, 0.5), |
102 | | - (0.3, 0.3, 0.0), |
103 | | - (0.7, 0.7, 0.002), |
104 | | - (0.2, 0.8, 0.5), |
105 | | - (0.8, 0.2, 0.5), |
106 | | - ], |
107 | | - [14, 14, 8, 8, 8, 8], |
108 | | - ) |
109 | | - |
110 | | - a = 3.07 |
111 | | - c = 3.52 |
112 | | - MgB2 = ( |
113 | | - [(a, 0, 0), (-a / 2, a / 2 * np.sqrt(3), 0), (0, 0, c)], |
114 | | - [(0, 0, 0), (1.0 / 3, 2.0 / 3, 0.5), (2.0 / 3, 1.0 / 3, 0.5)], |
115 | | - [12, 5, 5], |
116 | | - ) |
117 | | - |
118 | | - a = [3.0, 0.0, 0.0] |
119 | | - b = [-3.66666667, 3.68178701, 0.0] |
120 | | - c = [-0.66666667, -1.3429469, 1.32364995] |
121 | | - niggli_lattice = np.array([a, b, c]) |
122 | | - |
123 | | - |
124 | | - print("[get_spacegroup]") |
125 | | - print(" Spacegroup of Silicon is %s." % spglib.get_spacegroup(silicon)) |
126 | | - print("") |
127 | | - print("[get_spacegroup]") |
128 | | - print(" Spacegroup of Silicon is %s." % spglib.get_spacegroup(silicon)) |
129 | | - print("") |
130 | | - print("[get_spacegroup]") |
131 | | - print(" Spacegroup of Rutile is %s." % spglib.get_spacegroup(rutile)) |
132 | | - print("") |
133 | | - print("[get_spacegroup]") |
134 | | - print(" Spacegroup of MgB2 is %s." % spglib.get_spacegroup(MgB2)) |
135 | | - print("") |
136 | | - print("[get_symmetry]") |
137 | | - print(" Symmetry operations of Rutile unitcell are:") |
138 | | - print("") |
139 | | - symmetry = spglib.get_symmetry(rutile) |
140 | | - _show_symmetry(symmetry) |
141 | | - print("") |
142 | | - print("[get_symmetry]") |
143 | | - print(" Symmetry operations of MgB2 are:") |
144 | | - print("") |
145 | | - symmetry = spglib.get_symmetry(MgB2) |
146 | | - _show_symmetry(symmetry) |
147 | | - print("") |
148 | | - print("[get_pointgroup]") |
149 | | - print(" Pointgroup of Rutile is %s." % spglib.get_pointgroup(symmetry["rotations"])[0]) |
150 | | - print("") |
151 | | - |
152 | | - dataset = spglib.get_symmetry_dataset(rutile) |
153 | | - print("[get_symmetry_dataset] ['international']") |
154 | | - print( |
155 | | - " Spacegroup of Rutile is %s (%d)." % (dataset["international"], dataset["number"]) |
156 | | - ) |
157 | | - print("") |
158 | | - print("[get_symmetry_dataset] ['pointgroup']") |
159 | | - print(" Pointgroup of Rutile is %s." % (dataset["pointgroup"])) |
160 | | - print("") |
161 | | - print("[get_symmetry_dataset] ['hall']") |
162 | | - print(" Hall symbol of Rutile is %s (%d)." % (dataset["hall"], dataset["hall_number"])) |
163 | | - print("") |
164 | | - print("[get_symmetry_dataset] ['wyckoffs']") |
165 | | - alphabet = "abcdefghijklmnopqrstuvwxyz" |
166 | | - print(" Wyckoff letters of Rutile are: ", dataset["wyckoffs"]) |
167 | | - print("") |
168 | | - print("[get_symmetry_dataset] ['equivalent_atoms']") |
169 | | - print(" Mapping to equivalent atoms of Rutile are: ") |
170 | | - for i, x in enumerate(dataset["equivalent_atoms"]): |
171 | | - print(" %d -> %d" % (i + 1, x + 1)) |
172 | | - print("") |
173 | | - print("[get_symmetry_dataset] ['rotations'], ['translations']") |
174 | | - print(" Symmetry operations of Rutile unitcell are:") |
175 | | - for i, (rot, trans) in enumerate(zip(dataset["rotations"], dataset["translations"])): |
176 | | - print(" --------------- %4d ---------------" % (i + 1)) |
177 | | - print(" rotation:") |
178 | | - for x in rot: |
179 | | - print(" [%2d %2d %2d]" % (x[0], x[1], x[2])) |
180 | | - print(" translation:") |
181 | | - print(" (%8.5f %8.5f %8.5f)" % (trans[0], trans[1], trans[2])) |
182 | | - print("") |
183 | | - |
184 | | - print("[refine_cell]") |
185 | | - print(" Refine distorted rutile structure") |
186 | | - lattice, positions, numbers = spglib.refine_cell(rutile_dist, symprec=1e-1) |
187 | | - _show_cell(lattice, positions, numbers) |
188 | | - print("") |
189 | | - |
190 | | - print("[find_primitive]") |
191 | | - print(" Fine primitive distorted silicon structure") |
192 | | - lattice, positions, numbers = spglib.find_primitive(silicon_dist, symprec=1e-1) |
193 | | - _show_cell(lattice, positions, numbers) |
194 | | - print("") |
195 | | - |
196 | | - print("[standardize_cell]") |
197 | | - print(" Standardize distorted rutile structure:") |
198 | | - print(" (to_primitive=0 and no_idealize=0)") |
199 | | - lattice, positions, numbers = spglib.standardize_cell( |
200 | | - rutile_dist, to_primitive=0, no_idealize=0, symprec=1e-1 |
201 | | - ) |
202 | | - _show_cell(lattice, positions, numbers) |
203 | | - print("") |
204 | | - |
205 | | - print("[standardize_cell]") |
206 | | - print(" Standardize distorted rutile structure:") |
207 | | - print(" (to_primitive=0 and no_idealize=1)") |
208 | | - lattice, positions, numbers = spglib.standardize_cell( |
209 | | - rutile_dist, to_primitive=0, no_idealize=1, symprec=1e-1 |
210 | | - ) |
211 | | - _show_cell(lattice, positions, numbers) |
212 | | - print("") |
213 | | - |
214 | | - print("[standardize_cell]") |
215 | | - print(" Standardize distorted silicon structure:") |
216 | | - print(" (to_primitive=1 and no_idealize=0)") |
217 | | - lattice, positions, numbers = spglib.standardize_cell( |
218 | | - silicon_dist, to_primitive=1, no_idealize=0, symprec=1e-1 |
219 | | - ) |
220 | | - _show_cell(lattice, positions, numbers) |
221 | | - print("") |
222 | | - |
223 | | - print("[standardize_cell]") |
224 | | - print(" Standardize distorted silicon structure:") |
225 | | - print(" (to_primitive=1 and no_idealize=1)") |
226 | | - lattice, positions, numbers = spglib.standardize_cell( |
227 | | - silicon_dist, to_primitive=1, no_idealize=1, symprec=1e-1 |
228 | | - ) |
229 | | - _show_cell(lattice, positions, numbers) |
230 | | - print("") |
231 | | - |
232 | | - symmetry = spglib.get_symmetry(silicon) |
233 | | - print("[get_symmetry]") |
234 | | - print(" Number of symmetry operations of silicon conventional") |
235 | | - print(" unit cell is %d (192)." % len(symmetry["rotations"])) |
236 | | - _show_symmetry(symmetry) |
237 | | - print("") |
238 | | - |
239 | | - symmetry = spglib.get_symmetry_from_database(525) |
240 | | - print("[get_symmetry_from_database]") |
241 | | - print(" Number of symmetry operations of silicon conventional") |
242 | | - print(" unit cell is %d (192)." % len(symmetry["rotations"])) |
243 | | - _show_symmetry(symmetry) |
244 | | - print("") |
245 | | - |
246 | | - reduced_lattice = spglib.niggli_reduce(niggli_lattice) |
247 | | - print("[niggli_reduce]") |
248 | | - print(" Original lattice") |
249 | | - _show_lattice(niggli_lattice) |
250 | | - print(" Reduced lattice") |
251 | | - _show_lattice(reduced_lattice) |
252 | | - print("") |
253 | | - |
254 | | - |
255 | | - mapping, grid = spglib.get_ir_reciprocal_mesh( |
256 | | - [11, 11, 11], silicon_prim, is_shift=[0, 0, 0] |
257 | | - ) |
258 | | - num_ir_kpt = len(np.unique(mapping)) |
259 | | - print("[get_ir_reciprocal_mesh]") |
260 | | - print(" Number of irreducible k-points of primitive silicon with") |
261 | | - print(" 11x11x11 Monkhorst-Pack mesh is %d (56)." % num_ir_kpt) |
262 | | - print("") |
263 | | - |
264 | | - mapping, grid = spglib.get_ir_reciprocal_mesh([8, 8, 8], rutile, is_shift=[1, 1, 1]) |
265 | | - num_ir_kpt = len(np.unique(mapping)) |
266 | | - print("[get_ir_reciprocal_mesh]") |
267 | | - print(" Number of irreducible k-points of Rutile with") |
268 | | - print(" 8x8x8 Monkhorst-Pack mesh is %d (40)." % num_ir_kpt) |
269 | | - print("") |
270 | | - |
271 | | - mapping, grid = spglib.get_ir_reciprocal_mesh([9, 9, 8], MgB2, is_shift=[0, 0, 1]) |
272 | | - num_ir_kpt = len(np.unique(mapping)) |
273 | | - print("[get_ir_reciprocal_mesh]") |
274 | | - print(" Number of irreducible k-points of MgB2 with") |
275 | | - print(" 9x9x8 Monkhorst-Pack mesh is %s (48)." % num_ir_kpt) |
276 | | - print("") |
277 | | - |
278 | | - |
279 | | -if __name__ == '__main__': |
280 | | - main() |
| 1 | +"""Example to use get_symmetry_dataset with Wurtzite structure input (P6_3mc).""" |
| 2 | +from spglib import get_symmetry_dataset |
| 3 | + |
| 4 | +lattice = [[3.111, 0, 0], [-1.5555, 2.6942050311733885, 0], [0, 0, 4.988]] |
| 5 | +position = [ |
| 6 | + [1.0 / 3, 2.0 / 3, 0.0], |
| 7 | + [2.0 / 3, 1.0 / 3, 0.5], |
| 8 | + [1.0 / 3, 2.0 / 3, 0.6181], |
| 9 | + [2.0 / 3, 1.0 / 3, 0.1181], |
| 10 | +] |
| 11 | +types = [1, 1, 2, 2] |
| 12 | +symprec = 1e-5 |
| 13 | + |
| 14 | +cell = (lattice, position, types) |
| 15 | +dataset = get_symmetry_dataset(cell, symprec=symprec) |
| 16 | + |
| 17 | +print(f'International symbol: {dataset["international"]} ({dataset["number"]})') |
| 18 | +print(f'Hall symbol: {dataset["hall"]}') |
| 19 | +print("Wyckoff letters: ", end="") |
| 20 | +print(" ".join([f"{w}" for w in dataset["wyckoffs"]])) |
| 21 | +print("Equivalent atoms:") |
| 22 | +for i, equiv_atom in enumerate(dataset["equivalent_atoms"]): |
| 23 | + print(f"{i} -> {equiv_atom}") |
| 24 | +print("Space group operations:") |
| 25 | +for i, (r, t) in enumerate(zip(dataset["rotations"], dataset["translations"])): |
| 26 | + print(f"--- {i + 1} ---") |
| 27 | + for vec in r: |
| 28 | + print(f"{vec[0]:2d} {vec[1]:2d} {vec[2]:2d}") |
| 29 | + print(f"{t[0]:.5f} {t[1]:.5f} {t[2]:.5f}") |
0 commit comments