1
+ from __future__ import annotations
2
+
1
3
import math
2
4
3
5
import numpy as np
@@ -33,7 +35,7 @@ def __init__(self, *args, initial_structure=None, **kwargs):
33
35
super ().__init__ (* args , ** kwargs )
34
36
self .create_store ("structure" , initial_data = initial_structure )
35
37
36
- def layout (self ):
38
+ def layout (self ) -> Columns :
37
39
38
40
voltage = self .get_numerical_input (
39
41
kwarg_label = "voltage" ,
@@ -84,7 +86,7 @@ def generate_diffraction_pattern(structure, *args):
84
86
return dcc .Graph (
85
87
figure = calculator .get_plot_2d (structure ),
86
88
responsive = False ,
87
- config = { " displayModeBar" : False , " displaylogo" : False } ,
89
+ config = dict ( displayModeBar = False , displaylogo = False ) ,
88
90
)
89
91
90
92
@@ -166,32 +168,39 @@ def V(x, c, alphagamma):
166
168
)
167
169
168
170
@staticmethod
169
- def twotheta_to_q (twotheta , xray_wavelength ):
170
- """
171
- Convert twotheta to Q.
171
+ def two_theta_to_q (two_theta : float , xray_wavelength : float ) -> float :
172
+ """Angular conversion from 2*theta to q in small-angle scattering (SAS).
172
173
173
- :param twotheta: in degrees
174
- :param xray_wavelength: in Ångstroms
175
- :return:
174
+ Args:
175
+ two_theta (float): in degrees
176
+ xray_wavelength (float): in Ångstroms
177
+
178
+ Returns:
179
+ float: Q in Ångstroms^-1
176
180
"""
177
181
# thanks @rwoodsrobinson
178
- return (4 * np .pi / xray_wavelength ) * np .sin (np .deg2rad (twotheta ) / 2 )
182
+ return (4 * np .pi / xray_wavelength ) * np .sin (np .deg2rad (two_theta ) / 2 )
179
183
180
184
@staticmethod
181
- def grain_to_hwhm (tau , two_theta , K = 0.9 , wavelength = "CuKa" ):
182
- """
183
- :param tau: grain size in nm
184
- :param two_theta: angle (in 2-theta)
185
- :param K: shape factor (default 0.9)
186
- :param wavelength: wavelength radiation in nm
187
- :return: half-width half-max (alpha or gamma), for line profile
185
+ def grain_to_hwhm (
186
+ tau : float , two_theta : float , K : float = 0.9 , wavelength : float | str = "CuKa"
187
+ ) -> float :
188
+ """_summary_
189
+
190
+ Args:
191
+ tau (float): grain size in nm
192
+ two_theta (float): angle (in 2-theta)
193
+ K (float, optional): shape factor (default 0.9). Defaults to 0.9.
194
+ wavelength (float | str, optional): wavelength radiation in nm. Defaults to "CuKa".
195
+
196
+ Returns:
197
+ float: half-width half-max (alpha or gamma), for line profile
188
198
"""
189
199
if isinstance (wavelength , str ):
190
200
wavelength = WAVELENGTHS [wavelength ]
201
+ # Scherrer equation for half-width half max
191
202
# factor of 0.1 to convert wavelength to nm
192
- return (
193
- 0.5 * K * 0.1 * wavelength / (tau * abs (np .cos (two_theta / 2 )))
194
- ) # Scherrer equation for half-width half max
203
+ return 0.5 * K * 0.1 * wavelength / (tau * abs (np .cos (two_theta / 2 )))
195
204
196
205
@property
197
206
def _sub_layouts (self ):
@@ -200,7 +209,7 @@ def _sub_layouts(self):
200
209
"peak_profile" : "G" ,
201
210
"shape_factor" : 0.94 ,
202
211
"rad_source" : "CuKa" ,
203
- "x_axis" : "twotheta " ,
212
+ "x_axis" : "two_theta " ,
204
213
"crystallite_size" : 0.1 ,
205
214
}
206
215
@@ -288,7 +297,7 @@ def _sub_layouts(self):
288
297
help_str = "Can choose between 2𝜃 or Q, where Q is the magnitude of the reciprocal lattice and "
289
298
"independent of radiation source." , # TODO: improve
290
299
options = [
291
- {"label" : "2𝜃" , "value" : "twotheta " },
300
+ {"label" : "2𝜃" , "value" : "two_theta " },
292
301
{"label" : "Q" , "value" : "Q" },
293
302
],
294
303
)
@@ -323,14 +332,16 @@ def _sub_layouts(self):
323
332
"static_image" : static_image ,
324
333
}
325
334
326
- def layout (self , static_image = False ):
327
- """
328
- Get the standard XRD diffraction pattern layout.
335
+ def layout (self , static_image : bool = False ) -> Columns :
336
+ """Get the standard XRD diffraction pattern layout.
329
337
330
- :param static_image: If True, will show a static image instead of an interactive graph.
331
- :return:
332
- """
338
+ Args:
339
+ static_image (bool, optional): If True, will show a static image instead of an interactive graph.
340
+ Defaults to False.
333
341
342
+ Returns:
343
+ Columns: from crystal_toolkit.helpers.layouts
344
+ """
334
345
sub_layouts = self ._sub_layouts
335
346
if static_image :
336
347
inner = sub_layouts ["static_image" ]
@@ -415,10 +426,10 @@ def get_figure(
415
426
layout = XRayDiffractionComponent .default_xrd_plot_style
416
427
417
428
if x_axis == "Q" :
418
- x_peak = XRayDiffractionComponent .twotheta_to_q (
429
+ x_peak = XRayDiffractionComponent .two_theta_to_q (
419
430
x_peak , WAVELENGTHS [rad_source ]
420
431
)
421
- x = XRayDiffractionComponent .twotheta_to_q (x , WAVELENGTHS [rad_source ])
432
+ x = XRayDiffractionComponent .two_theta_to_q (x , WAVELENGTHS [rad_source ])
422
433
layout ["xaxis" ]["title" ] = "Q / Å⁻¹"
423
434
else :
424
435
layout ["xaxis" ]["title" ] = "2𝜃 / º"
0 commit comments