id4_common.utils.hkl_utils_hklpy2#
Auxilary HKL functions.
Provide a simplified UI for hklpy2 diffractometer users.
The user must define a diffractometer instance, then register that instance here calling set_diffractometer(instance).
Module Contents#
- id4_common.utils.hkl_utils_hklpy2.polar_config#
- id4_common.utils.hkl_utils_hklpy2.RE#
- id4_common.utils.hkl_utils_hklpy2.pbar_manager#
- class id4_common.utils.hkl_utils_hklpy2.Geometries(huber_euler_nm, huber_euler_psi_nm, huber_hp_nm, huber_hp_psi_nm)#
Register the diffractometer geometries.
- configuration_wrapper = None#
- property huber_euler#
- property huber_euler_psi#
- property huber_hp#
- property huber_hp_psi#
- id4_common.utils.hkl_utils_hklpy2.geometries#
- id4_common.utils.hkl_utils_hklpy2.set_diffractometer(diffractometer)#
Wraps the hklpy2.user.set_diffractometer and adds the diffractometer configuration wrapper to the RunEngine preprocessors.
- Parameters:
diffractometer (str or DiffractometerBase, optional) – Name or device instance to activate.
- id4_common.utils.hkl_utils_hklpy2.change_diffractometer(diffractometer=None)#
Select and initialize the active diffractometer (huber_euler or huber_hp).
Selects the diffractometer (interactive prompt or argument).
Applies the appropriate axis constraints.
Creates aliases for all real diffractometer axes in the calling namespace (mu, gamma, delta, chi, phi, tau) and the reciprocal-space pseudo axes (h, k, l).
- Parameters:
diffractometer (str or DiffractometerBase, optional) – Name or device instance to activate. If not provided, prompts interactively with the current diffractometer as the default.
- id4_common.utils.hkl_utils_hklpy2.newsample()#
Interactively add a new sample with lattice constants.
- Prompts the user for:
sample name
lattice constants (a, b, c, alpha, beta, gamma)
Uses defaults if the user just presses Enter.
- id4_common.utils.hkl_utils_hklpy2.sampleList()#
List all samples currently defined in hklpy2; specify current one.
- id4_common.utils.hkl_utils_hklpy2.sampleChange(sample_key=None)#
Change selected sample in hklpy2.
- Parameters:
sample_key (string, optional) – Name of the sample as set in hklpy. If None it will ask for which sample.
- id4_common.utils.hkl_utils_hklpy2.sampleRemove(sample_key=None)#
Remove selected sample in hklpy.
- Parameters:
sample_key (string, optional) – Name of the sample as set in hklpy. If None it will ask for which sample.
- id4_common.utils.hkl_utils_hklpy2.list_reflections(all_samples=False)#
Lists all reflections defined in hklpy for six-circle geometry.
- Parameters:
all_samples (bool, optional) – If True, list reflections for all samples. If False, only the current sample. Defaults to False.
- id4_common.utils.hkl_utils_hklpy2.or_swap()#
Swaps the two orientation reflections in hklpy.
- id4_common.utils.hkl_utils_hklpy2.compute_UB()#
Calculates the UB matrix. v
This fixes one issue with the hklpy calc_UB in that using wh() right after will not work, it needs to run one calculation first.
- Parameters:
h (float, optional) – Values of H, K, L positions for current reflection. If None, it will ask for it.
k (float, optional) – Values of H, K, L positions for current reflection. If None, it will ask for it.
l (float, optional) – Values of H, K, L positions for current reflection. If None, it will ask for it.
- class id4_common.utils.hkl_utils_hklpy2.Sync_UB_Matrix(source, target)#
Keep the UB matrix of target in sync with source via an ophyd subscription.
Subscribes to source._ub_sync (an ArrayAttributeSignal pointing at core.sample.UB) so that whenever the signal is updated the callback copies the new matrix to the target and syncs simulated motor positions. Call cleanup() to remove the subscription when no longer needed.
- source#
- target#
- cleanup()#
Remove the UB-sync subscription.
- sync_callback(value=None, **kwargs)#
- id4_common.utils.hkl_utils_hklpy2.setor0()#
Sets the primary orientation in hklpy2.
- Parameters:
motors (diffractometer real) – Values of motor positions for current reflection. It will ask for it.
h (float, optional) – Values of H, K, L positions for current reflection. It will ask for it.
k (float, optional) – Values of H, K, L positions for current reflection. It will ask for it.
l (float, optional) – Values of H, K, L positions for current reflection. It will ask for it.
- id4_common.utils.hkl_utils_hklpy2.setor1()#
Sets the primary orientation in hklpy2.
- Parameters:
motors (diffractometer real) – Values of motor positions for current reflection. It will ask for it.
h (float, optional) – Values of H, K, L positions for current reflection. It will ask for it.
k (float, optional) – Values of H, K, L positions for current reflection. It will ask for it.
l (float, optional) – Values of H, K, L positions for current reflection. It will ask for it.
- id4_common.utils.hkl_utils_hklpy2.or0(h=None, k=None, l=None)#
Sets the primary orientation in hklpy2 using the current motor positions.
- Parameters:
h (float, optional) – Values of H, K, L positions for current reflection. If None, it will ask for it.
k (float, optional) – Values of H, K, L positions for current reflection. If None, it will ask for it.
l (float, optional) – Values of H, K, L positions for current reflection. If None, it will ask for it.
- id4_common.utils.hkl_utils_hklpy2.or1(h=None, k=None, l=None)#
Sets the secondary orientation in hklpy2 using the current motor positions.
- Parameters:
h (float, optional) – Values of H, K, L positions for current reflection. If None, it will ask for it.
k (float, optional) – Values of H, K, L positions for current reflection. If None, it will ask for it.
l (float, optional) – Values of H, K, L positions for current reflection. If None, it will ask for it.
- id4_common.utils.hkl_utils_hklpy2.set_orienting()#
Change the primary and secondary orienting reflections to existing reflections in the reflection list (hklpy2).
WARNING: Works only with six-circle geometry (fix in progress).
- id4_common.utils.hkl_utils_hklpy2.del_reflection()#
Delete a reflection from the current sample’s reflection list.
Displays reflections like set_orienting()
User inputs index number of reflection to delete
Orienting reflections (first/second) cannot be deleted
- id4_common.utils.hkl_utils_hklpy2.list_orienting()#
List the first and second orienting reflections only from the current sample’s reflection list.
- id4_common.utils.hkl_utils_hklpy2.setmode(mode=None)#
Set the mode of the currently selected diffractometer.
- Parameters:
mode (string, optional) – Mode to be selected. If None, it will ask.
- id4_common.utils.hkl_utils_hklpy2.freeze(*args)#
Set preset values for the constant axes of the current mode.
For psi constant modes: freezes psi. Uses args[0] if given, otherwise computes the current psi from the psi-engine counterpart diffractometer.
For ‘4-circles constant phi/mu/chi horizontal’: freezes that axis. Uses args[0] if given, otherwise uses the current motor position.
For other modes: prompts interactively for each constant axis, showing the current preset as the default.
Updates
_geom_.core.presetsor_geom_.core.extrasas appropriate.
- id4_common.utils.hkl_utils_hklpy2.freeze_general()#
Interactively set preset values for the constant axes of the current mode.
For each angle held constant in the current mode, prompts for a value (showing the current preset as default). Updates
_geom_.core.presets.
- id4_common.utils.hkl_utils_hklpy2.ca(h, k, l)#
Calculate the motors position of a reflection.
- id4_common.utils.hkl_utils_hklpy2.ubr(h, k, l)#
Move the motors to a reciprocal space point.
- id4_common.utils.hkl_utils_hklpy2.br(h, k, l)#
Move the motors to a reciprocal space point.
- Parameters:
- Return type:
Generator for the bluesky Run Engine.
Example
RE(br(2, 2, 0))
- id4_common.utils.hkl_utils_hklpy2.uan(*args)#
Moves the delta and eta motors.
WARNING: This function will only work with six circles. This will be fixed in future releases.
- id4_common.utils.hkl_utils_hklpy2.setlat(*args)#
Set the lattice constants for the current sample.
- Parameters:
a (float, optional) – Lattice constants. - If all 6 are provided as arguments, they are used directly. - If none are provided, the user will be prompted interactively.
b (float, optional) – Lattice constants. - If all 6 are provided as arguments, they are used directly. - If none are provided, the user will be prompted interactively.
c (float, optional) – Lattice constants. - If all 6 are provided as arguments, they are used directly. - If none are provided, the user will be prompted interactively.
alpha (float, optional) – Lattice constants. - If all 6 are provided as arguments, they are used directly. - If none are provided, the user will be prompted interactively.
beta (float, optional) – Lattice constants. - If all 6 are provided as arguments, they are used directly. - If none are provided, the user will be prompted interactively.
gamma (float, optional) – Lattice constants. - If all 6 are provided as arguments, they are used directly. - If none are provided, the user will be prompted interactively.
Notes
If two orienting reflections are defined, UB will be recomputed automatically.
- id4_common.utils.hkl_utils_hklpy2.setaz(*args)#
Set the azimuthal reference reflection (h2, k2, l2).
Always updates the psi counterpart of the active diffractometer (which uses the psi engine). If the main diffractometer is currently in a psi constant mode, its h2/k2/l2 extras are also updated while preserving the psi value. Works regardless of the current mode.
- Parameters:
h2 (int or float, optional) – Miller indices of the azimuthal reference reflection. If not provided, the user will be prompted interactively.
k2 (int or float, optional) – Miller indices of the azimuthal reference reflection. If not provided, the user will be prompted interactively.
l2 (int or float, optional) – Miller indices of the azimuthal reference reflection. If not provided, the user will be prompted interactively.
- id4_common.utils.hkl_utils_hklpy2.show_constraints()#
Show constraints (low, high) and cut point for each real axis.
- id4_common.utils.hkl_utils_hklpy2.reset_constraints()#
Reset all constraints
- id4_common.utils.hkl_utils_hklpy2.set_constraints(*args)#
Change constraint values (low/high limits and optional cut point).
Call patterns#
set_constraints(): prompt interactively for every axis.set_constraints(axis): prompt interactively for one axis.set_constraints(axis, low, high): set limits only.set_constraints(axis, low, high, cut): set limits and cut point.set_constraints(low1, high1, ..., low6, high6): 12 args, set limits for all axes (cut points unchanged).set_constraints(low1, high1, cut1, ..., low6, high6, cut6): 18 args, set limits and cut points for all axes.
Interactive input may supply 2 numbers (low, high) or 3 numbers (low, high, cut), separated by spaces or commas. Press Enter to keep the current values.
- id4_common.utils.hkl_utils_hklpy2.analyzer_configuration(energy=None)#
- Configure analyzer
Select analyzer crystal and determine d-spacing
- id4_common.utils.hkl_utils_hklpy2.analyzer_set()#
Set analyzer
- id4_common.utils.hkl_utils_hklpy2.update_lattice(lattice_constant=None)#
Update lattice constants.
- Parameters:
lattice_constant (string, optional) – a, b or c or auto (default)
- id4_common.utils.hkl_utils_hklpy2.write_config(filename='default', overwrite=False)#
Write diffractometer configuration to file in current directory.
- Parameters:
method (string, optional) – Only “File” is currently supported.
overwrite (bool, optional) – If False, asks for confirmation before overwriting an existing file.
- id4_common.utils.hkl_utils_hklpy2.read_config()#
Read diffractometer configuration from file in current directory.
Lists all files matching *_polar_config.yml, prompts the user to select one, and loads it. Defaults to default_polar_config.yml if it exists.
- id4_common.utils.hkl_utils_hklpy2.restore_huber_from_scan(scan_id, diffractometer=None, sample_name=None, force=False)#
Restore diffractometer orientation from a previous scan.
- Parameters:
scan_id (int or string) – Scan ID to restore orientation from.
diffractometer (diffractometer object, optional) – Diffractometer to restore. Defaults to the current diffractometer.
sample_name (string, optional) – Override the sample name stored in the scan.
force (bool, optional) – If True, use the first available diffractometer info even if the name does not match. Defaults to False.
- id4_common.utils.hkl_utils_hklpy2.set_detector()#
Interactively select detector on Huber detectorarm to be used. Detectors are mounted 25 degrees apart from each other in delta
- Prompts the user for:
Detector: (E)iger or (P)oint Detector/Analyzer
Uses defaults if the user just presses Enter.
- class id4_common.utils.hkl_utils_hklpy2.whClass#
_wh function used without parenthesis
- id4_common.utils.hkl_utils_hklpy2.wh#
- id4_common.utils.hkl_utils_hklpy2.theta0()#
Calculate 2-theta zero-offset and lattice parameter
a0for a cubic sample.Reads the current wavelength from the diffractometer beam object, displays the saved reflection list, asks the user to choose two reflections by index, then computes the zero-shift and
a0from those two reflections (Brueckel 1994).Assumes horizontal scattering geometry (
gamma = 2*theta,delta = 0).