Add diffraction conversion routines

This commit is contained in:
leonarski_f committed 2025-06-02 15:37:39 +02:00
1 parent 7d65a18d28
commit 439a77b830
1 file changed
+47
+47
View File
@@ -0,0 +1,47 @@
import math
def cal_res_A(detector_distance_mm: float,
wavelength_angstrom: float,
radius_mm: float) -> float:
"""
Calculate maximum achievable resolution in Angstroms.
Args:
detector_distance_mm: Distance from crystal to detector in mm
wavelength_angstrom: X-ray wavelength in Angstroms
radius_mm: Detector radius in mm
Returns:
Resolution in Angstroms
"""
# Calculate theta using arctangent of opposite/adjacent
theta = math.atan(radius_mm / detector_distance_mm) / 2.0
# Using Bragg's law: n𝜆 = 2d*sin(θ)
# Solving for d: d = 𝜆/(2*sin(θ))
resolution = wavelength_angstrom / (2 * math.sin(theta))
return resolution
def calc_dtz_mm(desired_resolution_angstrom: float,
wavelength_angstrom: float,
radius_mm: float) -> float:
"""
Calculate required detector distance for desired resolution.
Args:
desired_resolution_angstrom: Desired resolution in Angstroms
wavelength_angstrom: X-ray wavelength in Angstroms
radius_mm: Detector radius in mm
Returns:
Required detector distance in mm
"""
# From Bragg's law: sin(θ) = 𝜆/(2d)
theta = math.asin(wavelength_angstrom / (2 * desired_resolution_angstrom))
# Using tangent: tan(2θ) = opposite/adjacent
# Therefore: distance = radius/tan(2θ)
distance = radius_mm / math.tan(2 * theta)
return distance