20
20
from numpy .typing import NDArray
21
21
22
22
from pymatgen .core import Structure
23
- from pymatgen .util .typing import Tuple3Ints
24
23
25
24
__author__ = "Frank Wan, Jason Liang"
26
25
__copyright__ = "Copyright 2020, The Materials Project"
@@ -48,7 +47,7 @@ def __init__(
48
47
self ,
49
48
symprec : float | None = None ,
50
49
voltage : float = 200 ,
51
- beam_direction : Tuple3Ints = (0 , 0 , 1 ),
50
+ beam_direction : tuple [ int , int , int ] = (0 , 0 , 1 ),
52
51
camera_length : int = 160 ,
53
52
debye_waller_factors : dict [str , float ] | None = None ,
54
53
cs : float = 1 ,
@@ -105,7 +104,9 @@ def generate_points(coord_left: int = -10, coord_right: int = 10) -> np.ndarray:
105
104
points_matrix = (np .ravel (points [i ]) for i in range (3 ))
106
105
return np .vstack (list (points_matrix )).transpose ()
107
106
108
- def zone_axis_filter (self , points : list [Tuple3Ints ] | np .ndarray , laue_zone : int = 0 ) -> list [Tuple3Ints ]:
107
+ def zone_axis_filter (
108
+ self , points : list [tuple [int , int , int ]] | np .ndarray , laue_zone : int = 0
109
+ ) -> list [tuple [int , int , int ]]:
109
110
"""Filter out all points that exist within the specified Laue zone according to the zone axis rule.
110
111
111
112
Args:
@@ -121,11 +122,11 @@ def zone_axis_filter(self, points: list[Tuple3Ints] | np.ndarray, laue_zone: int
121
122
return []
122
123
filtered = np .where (np .dot (np .array (self .beam_direction ), np .transpose (points )) == laue_zone )
123
124
result = points [filtered ]
124
- return cast ("list[Tuple3Ints ]" , [tuple (x ) for x in result .tolist ()])
125
+ return cast ("list[tuple[int, int, int] ]" , [tuple (x ) for x in result .tolist ()])
125
126
126
127
def get_interplanar_spacings (
127
- self , structure : Structure , points : list [Tuple3Ints ] | np .ndarray
128
- ) -> dict [Tuple3Ints , float ]:
128
+ self , structure : Structure , points : list [tuple [ int , int , int ] ] | np .ndarray
129
+ ) -> dict [tuple [ int , int , int ] , float ]:
129
130
"""
130
131
Args:
131
132
structure (Structure): the input structure.
@@ -141,7 +142,9 @@ def get_interplanar_spacings(
141
142
interplanar_spacings_val = np .array ([structure .lattice .d_hkl (x ) for x in points_filtered ])
142
143
return dict (zip (points_filtered , interplanar_spacings_val , strict = True ))
143
144
144
- def bragg_angles (self , interplanar_spacings : dict [Tuple3Ints , float ]) -> dict [Tuple3Ints , float ]:
145
+ def bragg_angles (
146
+ self , interplanar_spacings : dict [tuple [int , int , int ], float ]
147
+ ) -> dict [tuple [int , int , int ], float ]:
145
148
"""Get the Bragg angles for every hkl point passed in (where n = 1).
146
149
147
150
Args:
@@ -155,7 +158,7 @@ def bragg_angles(self, interplanar_spacings: dict[Tuple3Ints, float]) -> dict[Tu
155
158
bragg_angles_val = np .arcsin (self .wavelength_rel () / (2 * interplanar_spacings_val ))
156
159
return dict (zip (plane , bragg_angles_val , strict = True ))
157
160
158
- def get_s2 (self , bragg_angles : dict [Tuple3Ints , float ]) -> dict [Tuple3Ints , float ]:
161
+ def get_s2 (self , bragg_angles : dict [tuple [ int , int , int ], float ]) -> dict [tuple [ int , int , int ] , float ]:
159
162
"""
160
163
Calculates the s squared parameter (= square of sin theta over lambda) for each hkl plane.
161
164
@@ -172,8 +175,8 @@ def get_s2(self, bragg_angles: dict[Tuple3Ints, float]) -> dict[Tuple3Ints, floa
172
175
return dict (zip (plane , s2_val , strict = True ))
173
176
174
177
def x_ray_factors (
175
- self , structure : Structure , bragg_angles : dict [Tuple3Ints , float ]
176
- ) -> dict [str , dict [Tuple3Ints , float ]]:
178
+ self , structure : Structure , bragg_angles : dict [tuple [ int , int , int ] , float ]
179
+ ) -> dict [str , dict [tuple [ int , int , int ] , float ]]:
177
180
"""
178
181
Calculates x-ray factors, which are required to calculate atomic scattering factors. Method partially inspired
179
182
by the equivalent process in the xrd module.
@@ -202,8 +205,8 @@ def x_ray_factors(
202
205
return x_ray_factors
203
206
204
207
def electron_scattering_factors (
205
- self , structure : Structure , bragg_angles : dict [Tuple3Ints , float ]
206
- ) -> dict [str , dict [Tuple3Ints , float ]]:
208
+ self , structure : Structure , bragg_angles : dict [tuple [ int , int , int ] , float ]
209
+ ) -> dict [str , dict [tuple [ int , int , int ] , float ]]:
207
210
"""
208
211
Calculates atomic scattering factors for electrons using the Mott-Bethe formula (1st order Born approximation).
209
212
@@ -229,8 +232,8 @@ def electron_scattering_factors(
229
232
return electron_scattering_factors
230
233
231
234
def cell_scattering_factors (
232
- self , structure : Structure , bragg_angles : dict [Tuple3Ints , float ]
233
- ) -> dict [Tuple3Ints , int ]:
235
+ self , structure : Structure , bragg_angles : dict [tuple [ int , int , int ] , float ]
236
+ ) -> dict [tuple [ int , int , int ] , int ]:
234
237
"""
235
238
Calculates the scattering factor for the whole cell.
236
239
@@ -255,7 +258,9 @@ def cell_scattering_factors(
255
258
scattering_factor_curr = 0
256
259
return cell_scattering_factors
257
260
258
- def cell_intensity (self , structure : Structure , bragg_angles : dict [Tuple3Ints , float ]) -> dict [Tuple3Ints , float ]:
261
+ def cell_intensity (
262
+ self , structure : Structure , bragg_angles : dict [tuple [int , int , int ], float ]
263
+ ) -> dict [tuple [int , int , int ], float ]:
259
264
"""
260
265
Calculates cell intensity for each hkl plane. For simplicity's sake, take I = |F|**2.
261
266
@@ -312,8 +317,8 @@ def get_pattern(
312
317
return pd .DataFrame (rows , columns = field_names )
313
318
314
319
def normalized_cell_intensity (
315
- self , structure : Structure , bragg_angles : dict [Tuple3Ints , float ]
316
- ) -> dict [Tuple3Ints , float ]:
320
+ self , structure : Structure , bragg_angles : dict [tuple [ int , int , int ] , float ]
321
+ ) -> dict [tuple [ int , int , int ] , float ]:
317
322
"""
318
323
Normalizes the cell_intensity dict to 1, for use in plotting.
319
324
@@ -335,8 +340,8 @@ def normalized_cell_intensity(
335
340
def is_parallel (
336
341
self ,
337
342
structure : Structure ,
338
- plane : Tuple3Ints ,
339
- other_plane : Tuple3Ints ,
343
+ plane : tuple [ int , int , int ] ,
344
+ other_plane : tuple [ int , int , int ] ,
340
345
) -> bool :
341
346
"""Checks if two hkl planes are parallel in reciprocal space.
342
347
@@ -351,7 +356,7 @@ def is_parallel(
351
356
phi = self .get_interplanar_angle (structure , plane , other_plane )
352
357
return phi in (180 , 0 ) or np .isnan (phi )
353
358
354
- def get_first_point (self , structure : Structure , points : list ) -> dict [Tuple3Ints , float ]:
359
+ def get_first_point (self , structure : Structure , points : list ) -> dict [tuple [ int , int , int ] , float ]:
355
360
"""Get the first point to be plotted in the 2D DP, corresponding to maximum d/minimum R.
356
361
357
362
Args:
@@ -372,7 +377,7 @@ def get_first_point(self, structure: Structure, points: list) -> dict[Tuple3Ints
372
377
return {max_d_plane : max_d }
373
378
374
379
@staticmethod
375
- def get_interplanar_angle (structure : Structure , p1 : Tuple3Ints , p2 : Tuple3Ints ) -> float :
380
+ def get_interplanar_angle (structure : Structure , p1 : tuple [ int , int , int ], p2 : tuple [ int , int , int ] ) -> float :
376
381
"""Get the interplanar angle (in degrees) between the normal of two crystal planes.
377
382
Formulas from International Tables for Crystallography Volume C pp. 2-9.
378
383
@@ -426,9 +431,9 @@ def get_interplanar_angle(structure: Structure, p1: Tuple3Ints, p2: Tuple3Ints)
426
431
427
432
@staticmethod
428
433
def get_plot_coeffs (
429
- p1 : Tuple3Ints ,
430
- p2 : Tuple3Ints ,
431
- p3 : Tuple3Ints ,
434
+ p1 : tuple [ int , int , int ] ,
435
+ p2 : tuple [ int , int , int ] ,
436
+ p3 : tuple [ int , int , int ] ,
432
437
) -> np .ndarray :
433
438
"""
434
439
Calculates coefficients of the vector addition required to generate positions for each DP point
@@ -448,7 +453,7 @@ def get_plot_coeffs(
448
453
x = np .dot (a_pinv , b )
449
454
return np .ravel (x )
450
455
451
- def get_positions (self , structure : Structure , points : list ) -> dict [Tuple3Ints , np .ndarray ]:
456
+ def get_positions (self , structure : Structure , points : list ) -> dict [tuple [ int , int , int ] , np .ndarray ]:
452
457
"""
453
458
Calculates all the positions of each hkl point in the 2D diffraction pattern by vector addition.
454
459
Distance in centimeters.
@@ -518,7 +523,7 @@ def tem_dots(self, structure: Structure, points) -> list:
518
523
519
524
class dot (NamedTuple ):
520
525
position : NDArray
521
- hkl : Tuple3Ints
526
+ hkl : tuple [ int , int , int ]
522
527
intensity : float
523
528
film_radius : float
524
529
d_spacing : float
0 commit comments