garnet.utilities package#
Submodules#
garnet.utilities.autoreduce module#
garnet.utilities.calculate module#
- class CalculateUB(a, b, c, alpha, beta, gamma)[source]#
Bases:
objectOptimizer of crystal orientation from peaks and known lattice parameters.
- Attributes:
- a, b, cfloat
Lattice constants in ansgroms.
- alpha, beta, gammafloat
Lattice angles in degrees.
Methods
UB_matrix(U, B)Calculate \(UB\)-matrix.
cost(param, B, kf_ki_dir, wavelength)Cost function for indexing given a proposed orientation.
indexer(UB, kf_ki_dir, wavelength[, tol, alpha])Laue indexer for a given \(UB\) matrix.
Calculate the reciprocal metric tensor \(G^*\).
Calculate the metric tensor \(G\).
minimize(kf_ki_dir, wavelength[, n_proc])Fit the orientation and other parameters.
objective(x)Objective function.
orientation_U(u0, u1, u2)The sample orientation matrix \(U\).
The reciprocal lattice \(B\)-matrix.
refine(kf_ki_dir, wavelength[, cell, error])Refine the orientation and lattice parameters under constraints.
residual(x, kf_ki_dir, hkl, wavelength, fun)Optimization residual function.
cartesian_matrix_metric_tensor
cubic
get_lattice_constants
get_orientation_parameters
hexagonal
index
monoclinic
orthorhombic
rhombohedral
set_lattice_constants
set_orientation_parameters
softplus
tetragonal
triclinic
- UB_matrix(U, B)[source]#
Calculate \(UB\)-matrix.
- Parameters:
- U2d-array
3x3 orientation matrix.
- B2d-array
3x3 reciprocal lattice vectors Cartesian matrix.
- Returns:
- UB2d-array
3x3 oriented reciprocal lattice.
- cost(param, B, kf_ki_dir, wavelength)[source]#
Cost function for indexing given a proposed orientation.
- Parameters:
- paramtuple, float
Orientation parameters.
- Barray, float
Reciprocal lattice B-matrix.
- kf_ki_dirarray, float
- wavelengthlist, float
Wavelength band (min, max).
- Returns:
- errorfloat
Total indexing cost.
- indexer(UB, kf_ki_dir, wavelength, tol=0.1, alpha=0.1)[source]#
Laue indexer for a given \(UB\) matrix.
- Parameters:
- UB2d-array
3x3 sample oriented lattice matrix.
- kf_ki_dirlist
Difference between scattering and incident beam directions.
- wavelengthlist
Wavelength of each reflection.
- tolfloat, optional
Indexing tolerance. Default is 0.15.
- Returns:
- errfloat
Indexing cost.
- numint
Number of peaks index.
- hkllist
Miller indices. Un-indexed are labeled [0,0,0].
- lamdalist
Resolved wavelength. Unindexed are labeled inf.
- metric_G_star_tensor()[source]#
Calculate the reciprocal metric tensor \(G^*\).
- Returns:
- Gstar2d-array
3x3 matrix of reciprocal lattice info for Cartesian transforms.
- metric_G_tensor()[source]#
Calculate the metric tensor \(G\).
- Returns:
- G2d-array
3x3 matrix of lattice parameter info for Cartesian transforms.
- minimize(kf_ki_dir, wavelength, n_proc=-1)[source]#
Fit the orientation and other parameters.
- Parameters:
- n_procint, optional
Number of processes to use. The default is -1.
- Returns:
- numint
Number of peaks index.
- hkllist
Miller indices. Un-indexed are labeled [0,0,0].
- lamdalist
Resolved wavelength. Un-indexed are labeled inf.
- objective(x)[source]#
Objective function.
- Parameters:
- xarray
Refineable parameters.
- Returns:
- neg_indint
Negative number of peaks indexed.
- orientation_U(u0, u1, u2)[source]#
The sample orientation matrix \(U\).
- Parameters:
- u0, u1, u2float
Rotation paramters.
- Returns:
- U2d-array
3x3 sample orientation matrix.
- reciprocal_lattice_B()[source]#
The reciprocal lattice \(B\)-matrix.
- Returns:
- B2d-array
3x3 matrix of reciprocal lattice in Cartesian coordinates.
- refine(kf_ki_dir, wavelength, cell='Triclinic', error=0.15)[source]#
Refine the orientation and lattice parameters under constraints.
garnet.utilities.calibration module#
- class Calibration(config)[source]#
Bases:
objectMethods
calculate_goniometer_angles
calculate_goniometer_matrix
calculate_orientation_matrix
calculate_orientation_vector
calculate_tilt_matrices
calculate_tilt_matrix
calibrate_goniometer
calibrate_instrument
cell_symmetry_matrices
fix_offsets
generate_diagnostic
gravity_angle
initialize_peaks
load_instrument
load_peaks
optimize_goniometer
refine_goniometer
refine_offsets
reindex_peaks
residual
run
garnet.utilities.combine module#
garnet.utilities.confirm module#
- confirm_autoreduce(filename)[source]#
Confirm autoreduction status based on reduction logs.
- Parameters:
- filenamestr
Full data path containing facility, instrument, and IPTS fields.
Notes
Confirmation logic:
Unknown→ No.logfiles detectedYes→ Logs exist and no failures detectedPartially→ Some runs failedNo→ All runs failed
garnet.utilities.crystal module#
garnet.utilities.ipts module#
garnet.utilities.macromolecular module#
garnet.utilities.peaks module#
- class Laue(ws)[source]#
Bases:
objectMethods
find_UB(a, b, c, alpha, beta, gamma[, ...])Fit the orientation and other parameters.
transform_lattice(peaks, transform[, tol])Apply a cell transformation to the lattice.
The scattering vector scaled with the (unknown) wavelength.
The Laue resolved wavelength.
calculate_transform
convert_conventional_to_primitive
refine_UB
- find_UB(a, b, c, alpha, beta, gamma, centering='P', n_proc=1)[source]#
Fit the orientation and other parameters.
- Parameters:
- a, b, cfloat
Lattice lengths.
- alpha, beta, gammafloat
Lattice angles.
- centeringstr
Lattice centering.
- n_procint, optional
Number of processes to use. The default is -1.
- transform_lattice(peaks, transform, tol=0.2)[source]#
Apply a cell transformation to the lattice.
- Parameters:
- transform3x3 array-like
Transform to apply to hkl values.
- tolfloat, optional
Indexing tolerance. The default is 0.1.
garnet.utilities.peakview module#
garnet.utilities.refinement module#
- class NuclearStructureRefinement(cell, space_group, sites, filename, parameters=None)[source]#
Bases:
objectMethods
beam_weights(sample_points, G, ds, bx, by, sigma)Calculate Gaussian beam weights for sample points.
calculate_structure_amplitudes(params)Compute complex structure amplitudes Fs (per unique hkl) for given params.
extinction_correction(param, F2)Calculate structure factor-dependent extinction correction.
objective_correction(params)Objective for absorption/extinction refinement.
objective_structure(params)Objective for structure + scale refinement.
plot_hkl_families([filename])Create multi-page PDF with one page per hkl family.
Plot the refined ellipsoidal sample shape with beam directions.
plot_wobble_correction(off[, filename])Plot wobble correction scale factors vs rotation angle.
refine([report, cutoff, n_iter, abs_corr, ...])Iterative refinement protocol: 7 stages per iteration.
Apply absorption corrections to all peaks and save to new file.
wobble_correction(off)Scale model for off-centering/wobble correction.
absorption_correction
add_absorption_extinction_parameters
add_beam_parameters
add_detector_run_scale_parameters
calculate_ellipsoid_surface
calculate_scale_factor
calculate_statistics
calculate_structure_factors
chemical_formula_z_parameter
cost
detector_bank_scale_factors
ellipsoid_parameters
extinction_xp
extinction_xs
extinction_xx
extract_info
extract_parameters
generate_parameters
generate_symmetry_transforms
initialize_correction
initialize_crystal_structure
initialize_material
initialize_unit_cell_atoms
load_hkls
normalization_correction
plot_absorption_correction
plot_result
prepare_absorption_table
report
run_angle_scale_factors
save_detector_scales
spherical_absorption
spherical_absorption_correction
spherical_extinction
update_sample
- beam_weights(sample_points, G, ds, bx, by, sigma)[source]#
Calculate Gaussian beam weights for sample points.
- Parameters:
- sample_pointsndarray, shape (N, 3)
Monte Carlo sample points in sample frame
- Gndarray, shape (P, 3, 3)
Goniometer matrices for each peak
- dsndarray, shape (P, 3)
Sample center offset in sample frame for each peak
- bx, byfloat
Beam center position in lab frame
- sigmafloat
Gaussian beam width
- Returns:
- bwndarray, shape (N, P)
Beam weights for each sample point and peak
- calculate_structure_amplitudes(params)[source]#
Compute complex structure amplitudes Fs (per unique hkl) for given params.
This is identical to the inner part of calculate_structure_factors but returns the complex amplitudes (not squared magnitudes).
- extinction_correction(param, F2)[source]#
Calculate structure factor-dependent extinction correction.
Model
Nature
Parameter
Type I, GaussianSecondary
Mosaic [unitless]
Type I, LorentzianSecondary
Mosaic [unitless]
Type IIPrimary
Block size² [um²]
SHELXPhenomenological
Crystal size [cm]
[1] P. J. Becker and P. Coppens, Acta Cryst A 30, 2 (1974). [2] P. J. Becker and P. Coppens, Acta Cryst A 30, 2 (1974). [3] A. C. Larson, Crystallographic Computing (1970).
- Parameters:
- paramfloat
Exinction parameter.
- F2array
Structure factors (fm^2).
- Returns:
- yarray
Extinction (unitless).
- objective_correction(params)[source]#
Objective for absorption/extinction refinement.
Structure and scale are held fixed; F2s are precomputed for the current structural model.
- objective_structure(params)[source]#
Objective for structure + scale refinement.
This stage varies positional, occupancy and displacement parameters together with the overall scale, while using the current absorption/extinction parameters as fixed values.
- plot_wobble_correction(off, filename=None)[source]#
Plot wobble correction scale factors vs rotation angle.
Shows observed data points and model curves for different wavelengths.
- refine(report=True, cutoff=10, n_iter=3, abs_corr=False, off_corr=False, det_corr=False, run_corr=False, norm_corr=False, ext_model='shelx')[source]#
Iterative refinement protocol: 7 stages per iteration.
- Per iteration:
Structure + scale (fixed corrections).
Absorption only.
Extinction only.
Wobble only.
Detector scales (optional).
Run/orientation scales (optional).
Normalization scales (optional).
- wobble_correction(off)[source]#
Scale model for off-centering/wobble correction.
Based on WobbleCorrection model: accounts for beam displacement and sample misalignment effects on intensity measurements.
- Parameters:
- offarray-like
[b, c, rx, rz] where: - b: spread (wavelength-dependent scaling) - c: center displacement - rx: in-plane displacement - rz: beam displacement
- Returns:
- array
Scale factors for each reflection
garnet.utilities.reflections module#
- class AbsorptionCorrection(peaks, chemical_formula, z_parameter, u_vector=[0, 0, 1], v_vector=[1, 0, 0], params=None, filename=None)[source]#
Bases:
objectMethods
apply_correction
calculate_correction
save_ellipsoid_stl
set_material
set_orientation
set_shape
verify_chemical_formula
write_absortion_parameters
- class Peaks(peaks, filename, scale=None, point_group=None)[source]#
Bases:
objectMethods
calculate_statistics
get_cell
load_peaks
load_spectrum
median_absolute_devation
merge_intensities
peak_info
refine_UB
refine_ellipsoids
remove_non_indexed
remove_non_integrated
remove_off_centered
remove_volume_outliers
renormalize_intensities
renumber_peaks
rescale_intensities
reset_satellite
resort_hkl
save_peaks
update_monitor