garnet.utilities package#

Submodules#

garnet.utilities.autoreduce module#

class AutoReduce(filename)[source]#

Bases: object

Methods

compress

elastic

plot_instrument

publish_plots

compress(ws)[source]#
elastic(time_offset=14000)[source]#
plot_instrument()[source]#
publish_plots()[source]#

garnet.utilities.calculate module#

class CalculateUB(a, b, c, alpha, beta, gamma)[source]#

Bases: object

Optimizer 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.

metric_G_star_tensor()

Calculate the reciprocal metric tensor \(G^*\).

metric_G_tensor()

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\).

reciprocal_lattice_B()

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.

cartesian_matrix_metric_tensor(a, b, c, alpha, beta, gamma)[source]#
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.

cubic(x)[source]#
get_lattice_constants()[source]#
get_orientation_parameters()[source]#
hexagonal(x)[source]#
index(kf_ki_dir, wavelength)[source]#
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.

monoclinic(x)[source]#
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.

orthorhombic(x)[source]#
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.

residual(x, kf_ki_dir, hkl, wavelength, fun)[source]#

Optimization residual function.

Parameters:
xlist

Parameters.

hkllist

Miller indices.

Qlist

Q-sample vectors.

funfunction

Lattice constraint function.

Returns:
residuallist

Least squares residuals.

rhombohedral(x)[source]#
set_lattice_constants(a, b, c, alpha, beta, gamma)[source]#
set_orientation_parameters(x)[source]#
softplus(z)[source]#
tetragonal(x)[source]#
triclinic(x)[source]#

garnet.utilities.calibration module#

class Calibration(config)[source]#

Bases: object

Methods

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

calculate_goniometer_angles(R)[source]#
calculate_goniometer_matrix(omega, chi, phi)[source]#
calculate_orientation_matrix(u0, u1, u2)[source]#
calculate_orientation_vector(U)[source]#
calculate_tilt_matrices(alpha, beta, gamma)[source]#
calculate_tilt_matrix(alpha, beta, gamma)[source]#
calibrate_goniometer(iteration)[source]#
calibrate_instrument(iteration)[source]#
cell_symmetry_matrices()[source]#
fix_offsets(x)[source]#
generate_diagnostic(iteration)[source]#
gravity_angle()[source]#
initialize_peaks()[source]#
load_instrument()[source]#
load_peaks()[source]#
optimize_goniometer()[source]#
refine_goniometer()[source]#
refine_offsets(x)[source]#
reindex_peaks()[source]#
residual(x, peak_dict, func, gamma)[source]#
run()[source]#

garnet.utilities.combine module#

combine(filename)[source]#
find_partial_files(instance)[source]#
parse_args(argv=None)[source]#

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 .log files detected

  • Yes → Logs exist and no failures detected

  • Partially → Some runs failed

  • No → All runs failed

garnet.utilities.crystal module#

class CrystalStructure(filename)[source]#

Bases: object

Methods

add_material_info

get_chemical_formula_z_parameter

get_lattice_constants

get_scatterers

get_space_group

get_unit_cell_volume

add_material_info(filename)[source]#
get_chemical_formula_z_parameter()[source]#
get_lattice_constants()[source]#
get_scatterers()[source]#
get_space_group()[source]#
get_unit_cell_volume()[source]#
class SampleParameters(radii, u_vector=[0, 0, 1], v_vector=[1, 0, 0])[source]#

Bases: object

Methods

add_sample_info

add_sample_info(filename)[source]#

garnet.utilities.ipts module#

garnet.utilities.macromolecular module#

class Macromolecular(peaks='peaks')[source]#

Bases: object

Methods

write_mtz

write_mtz(filename, space_group='P 1')[source]#

garnet.utilities.peaks module#

class Laue(ws)[source]#

Bases: object

Methods

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.

uncertainty_line_segements()

The scattering vector scaled with the (unknown) wavelength.

wavelengths()

The Laue resolved wavelength.

calculate_transform

convert_conventional_to_primitive

refine_UB

calculate_transform(centering)[source]#
convert_conventional_to_primitive(a, b, c, alpha, beta, gamma, centering)[source]#
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.

refine_UB(cell, wavelength)[source]#
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.

uncertainty_line_segements()[source]#

The scattering vector scaled with the (unknown) wavelength.

Returns:
kf_ki_dirlist

Difference between scattering and incident beam directions.

wavelengths()[source]#

The Laue resolved wavelength.

Returns:
Wavelengthlist

Peak wavelength.

class Peaks(config)[source]#

Bases: object

Methods

calculate_limits

finalize_and_save

load_convert_runs

load_instrument

run

calculate_limits()[source]#
finalize_and_save(tol=0.2)[source]#
load_convert_runs(ipts, run_nos, tol=0.2, n_proc=10)[source]#
load_instrument()[source]#
run()[source]#

garnet.utilities.peakview module#

garnet.utilities.refinement module#

class NuclearStructureRefinement(cell, space_group, sites, filename, parameters=None)[source]#

Bases: object

Methods

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_sample_shape()

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.

save_corrected_peaks()

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

absorption_correction(coeffs)[source]#
add_absorption_extinction_parameters(params)[source]#
add_beam_parameters(params)[source]#
add_detector_run_scale_parameters(params)[source]#
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_ellipsoid_surface(coeffs)[source]#
calculate_scale_factor(F2s)[source]#
calculate_statistics(cutoff)[source]#
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).

calculate_structure_factors(params)[source]#
chemical_formula_z_parameter()[source]#
cost(params, F2s, I_obs, sig)[source]#
detector_bank_scale_factors(params)[source]#
ellipsoid_parameters(coeffs)[source]#
extinction_correction(param, F2)[source]#

Calculate structure factor-dependent extinction correction.

Model

Nature

Parameter

Type I, Gaussian

Secondary

Mosaic [unitless]

Type I, Lorentzian

Secondary

Mosaic [unitless]

Type II

Primary

Block size² [um²]

SHELX

Phenomenological

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).

extinction_xp(r2, F2, lamda, V)[source]#
extinction_xs(g, F2, two_theta, lamda, Tbar, V)[source]#
extinction_xx(x, F2, two_theta, lamda, V)[source]#
extract_info()[source]#
extract_parameters(params, Uiso=0)[source]#
generate_parameters()[source]#
generate_symmetry_transforms()[source]#
initialize_correction(model='type II')[source]#
initialize_crystal_structure(sites)[source]#
initialize_material()[source]#
initialize_unit_cell_atoms(tol=1e-06, rcond=None, enforce_identity=True)[source]#
load_hkls(filename)[source]#
normalization_correction(params)[source]#
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_absorption_correction(filename=None)[source]#
plot_hkl_families(filename=None)[source]#

Create multi-page PDF with one page per hkl family.

plot_result()[source]#
plot_sample_shape()[source]#

Plot the refined ellipsoidal sample shape with beam directions.

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.

prepare_absorption_table(N=100, seed=42, beta=3)[source]#
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:
  1. Structure + scale (fixed corrections).

  2. Absorption only.

  3. Extinction only.

  4. Wobble only.

  5. Detector scales (optional).

  6. Run/orientation scales (optional).

  7. Normalization scales (optional).

report(result, det_corr, run_corr)[source]#
run_angle_scale_factors(params)[source]#
save_corrected_peaks()[source]#

Apply absorption corrections to all peaks and save to new file.

save_detector_scales(params)[source]#
spherical_absorption()[source]#
spherical_absorption_correction(muR, two_theta)[source]#
spherical_extinction()[source]#
update_sample(parameters)[source]#
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: object

Methods

apply_correction

calculate_correction

save_ellipsoid_stl

set_material

set_orientation

set_shape

verify_chemical_formula

write_absortion_parameters

apply_correction()[source]#
calculate_correction()[source]#
save_ellipsoid_stl(params, filename='/tmp/ellipsoid.stl')[source]#
set_material()[source]#
set_orientation()[source]#
set_shape()[source]#
verify_chemical_formula(formula)[source]#
write_absortion_parameters()[source]#
class Peaks(peaks, filename, scale=None, point_group=None)[source]#

Bases: object

Methods

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

calculate_statistics(name, filename)[source]#
get_cell()[source]#
load_peaks()[source]#
load_spectrum(filename, instrument)[source]#
median_absolute_devation(arr)[source]#
merge_intensities(name=None)[source]#
peak_info()[source]#
refine_UB(peaks)[source]#
refine_ellipsoids(peaks)[source]#
remove_non_indexed(tol=0.1)[source]#
remove_non_integrated()[source]#
remove_off_centered()[source]#
remove_volume_outliers(n_sigma=5.0)[source]#
renormalize_intensities(flux, solid_angle)[source]#
renumber_peaks(peaks, k=60, decimals=6, linkage='average')[source]#
rescale_intensities()[source]#
reset_satellite(peaks=None)[source]#
resort_hkl(peaks, filename)[source]#
save_peaks(name=None, fit_dict=None)[source]#
update_monitor()[source]#
main()[source]#

garnet.utilities.sliceview module#

garnet.utilities.structure module#

class StructureAnalysis(config, filename)[source]#

Bases: object

Methods

apply_correction

load_peaks

refimenent

save_mtz

save_peaks

apply_correction()[source]#
load_peaks()[source]#
refimenent(n_iter=10)[source]#
save_mtz()[source]#
save_peaks()[source]#

garnet.utilities.vanadium module#

class Vanadium(config)[source]#

Bases: object

Methods

apply_absorption_correction

apply_calibration

apply_masks

finalize_and_save

load_instrument

load_runs

process_data

run

set_sample_geometry

subtract_background

apply_absorption_correction()[source]#
apply_calibration()[source]#
apply_masks()[source]#
finalize_and_save()[source]#
load_instrument()[source]#
load_runs(workspace, ipts, run_nos, time_stop=None)[source]#
process_data()[source]#
run()[source]#
set_sample_geometry(x=0)[source]#
subtract_background()[source]#

Module contents#