19
19
import collections
20
20
import math
21
21
22
- import diffpy . structure
22
+ from numba import njit
23
23
import numpy as np
24
24
from scipy .constants import h , m_e , e , c , pi , mu_0
25
25
@@ -215,7 +215,7 @@ def get_vectorized_list_for_atomic_scattering_factors(
215
215
216
216
return coeffs , fcoords , occus , dwfactors
217
217
218
-
218
+ @ njit ( fastmath = True )
219
219
def get_atomic_scattering_factors (g_hkl_sq , coeffs , scattering_params ):
220
220
"""Calculate atomic scattering factors for n atoms.
221
221
@@ -277,9 +277,32 @@ def _get_kinematical_structure_factor(
277
277
# Set all atomic scattering factors to 1
278
278
atomic_scattering_factor = np .ones ((gspacing_squared .shape [0 ], coeffs .shape [0 ]))
279
279
280
+ return _numba_get_kinematical_structure_factor (
281
+ structure .lattice .stdbase ,
282
+ structure .lattice .recbase ,
283
+ xyz ,
284
+ atomic_scattering_factor ,
285
+ occupancy ,
286
+ g_indices ,
287
+ gspacing_squared ,
288
+ dwfactors ,
289
+ )
290
+
291
+
292
+ @njit (fastmath = True )
293
+ def _numba_get_kinematical_structure_factor (
294
+ stdbase : np .ndarray ,
295
+ recbase : np .ndarray ,
296
+ xyz : np .ndarray ,
297
+ atomic_scattering_factor : np .ndarray ,
298
+ occupancy : np .ndarray ,
299
+ g_indices : np .ndarray ,
300
+ g_spacing_squared : np .ndarray ,
301
+ dwfactors : np .ndarray ,
302
+ ) -> np .ndarray :
280
303
# Express the atom positions in the same reference frame as the
281
304
# Miller indices
282
- mat = np .linalg .inv (np .dot (structure . lattice . stdbase , structure . lattice . recbase ))
305
+ mat = np .linalg .inv (np .dot (stdbase , recbase ))
283
306
xyz = np .dot (xyz , mat )
284
307
285
308
# Calculate the complex structure factor
@@ -288,11 +311,10 @@ def _get_kinematical_structure_factor(
288
311
* occupancy
289
312
* np .exp (
290
313
2j * np .pi * np .dot (g_indices , xyz .T )
291
- - 0.25 * np .outer (gspacing_squared , dwfactors )
314
+ - 0.25 * np .outer (g_spacing_squared , dwfactors )
292
315
),
293
316
axis = - 1 ,
294
317
)
295
-
296
318
return structure_factor
297
319
298
320
0 commit comments