torchref.base.scattering.anomalous_table module
Anomalous scattering factor lookup (f’ and f’’).
Uses gemmi for wavelength-dependent f’/f’’ values via the Cromer-Liberman calculation. These corrections account for the dispersive (f’) and absorptive (f’’) components of X-ray scattering near atomic absorption edges.
The complete scattering factor is: f(s, lambda) = f0(s) + f’(lambda) + i*f’’(lambda)
where f0 is the normal (Thomson) scattering factor and f’/f’’ are the wavelength-dependent anomalous corrections.
- torchref.base.scattering.anomalous_table.wavelength_to_energy_ev(wavelength)[source]
Convert X-ray wavelength in Angstroms to energy in eV.
Uses the gemmi.hc constant (hc in eV*Angstrom).
- torchref.base.scattering.anomalous_table.get_anomalous_correction(element, wavelength)[source]
Get f’ and f’’ for a single element at given wavelength.
Uses the Cromer-Liberman calculation via gemmi. Returns the standard crystallographic f’ and f’’ values as used in International Tables.
- Parameters:
- Returns:
f_prime (float) – Real anomalous correction (electrons)
f_double_prime (float) – Imaginary anomalous correction (electrons)
- Return type:
Examples
>>> f_prime, f_double_prime = get_anomalous_correction('Se', 0.9792) >>> print(f"Se at Se K-edge: f'={f_prime:.2f}, f''={f_double_prime:.2f}")
Notes
The gemmi.cromer_liberman function expects energy in eV, not keV.
- torchref.base.scattering.anomalous_table.get_significant_elements(elements, wavelength, threshold=0.5)[source]
Find elements with significant anomalous scattering.
An element is considered significant if |f'| > threshold OR |f''| > threshold. This filtering avoids unnecessary computation for light atoms (C, N, O, H) which have negligible anomalous contributions at typical wavelengths.
- Parameters:
- Returns:
{element: (f_prime, f_double_prime)} for significant elements only
- Return type:
Examples
>>> elements = ['C', 'N', 'O', 'S', 'Fe', 'Zn'] >>> significant = get_significant_elements(elements, wavelength=1.0) >>> print(f"Significant anomalous scatterers: {list(significant.keys())}")
- torchref.base.scattering.anomalous_table.get_anomalous_corrections_by_indices(element_list, significant_elements, device, dtype)[source]
Get anomalous corrections and mask for atoms needing correction.
This function creates tensors suitable for vectorized computation of the anomalous correction to structure factors.
- Parameters:
element_list (list of str) – Element symbols for all atoms (length n_atoms)
significant_elements (dict) – {element: (f_prime, f_double_prime)} from get_significant_elements()
device (torch.device) – Device for output tensors
dtype (torch.dtype) – Data type for output tensors
- Returns:
mask (torch.Tensor) – Boolean mask of shape (n_atoms,) - True for atoms needing correction
f_prime (torch.Tensor) – f’ values for significant atoms only (n_significant,)
f_double_prime (torch.Tensor) – f’’ values for significant atoms only (n_significant,)
- Return type:
Examples
>>> elements = ['C', 'C', 'N', 'Fe', 'O', 'Fe'] >>> significant = {'Fe': (-1.2, 3.1)} >>> mask, fp, fdp = get_anomalous_corrections_by_indices( ... elements, significant, torch.device('cpu'), torch.float32 ... ) >>> print(f"Atoms needing correction: {mask.sum().item()}") # 2 (two Fe atoms)