hklpy2.user#
Simplified interface for hklpy2 diffractometer users.
|
Define an ORienting reflection. |
|
Add (and select) a new crystal sample. |
|
Calculate motor positions for specified 'h, k l' - DOES NOT MOVE motors. |
|
Print a table with motor positions for each reflection given. |
|
Compute the UB matrix with two reflections. |
Return the currently-selected diffractometer (or |
|
|
Summarize diffractometer's samples. |
|
Swap the first 2 ORienting reflections, re-compute & return new [UB]. |
|
Pop the named reflection and remove it from list of orienting reflections. |
|
Pop the named sample, set "selected" sample name to a valid one. |
|
Report (all) the diffractometer settings. |
|
Declare the diffractometer to be used. |
|
Set the energy (thus wavelength) to be used (does not change control system value). |
|
Redefine the sample's lattice. |
|
Define an ORienting reflection. |
|
Table of diffractometer solver's modes, axes, ... |
|
Report (brief) where is the diffractometer. |
See also
Attributes#
Classes#
Module class to maintain the diffractometer selection. |
Functions#
|
Add (and select) a new crystal sample. |
|
Calculate motor positions for specified 'h, k l' - DOES NOT MOVE motors. |
|
Print a table with motor positions for each reflection given. |
|
Compute the UB matrix with two reflections. |
|
Table of diffractometer solver's modes, axes, ... |
Return the currently-selected diffractometer (or |
|
|
Summarize diffractometer's samples. |
|
Swap the first 2 ORienting reflections, re-compute & return new [UB]. |
|
Report (all) the diffractometer settings. |
|
Pop the named reflection and remove it from list of orienting reflections. |
|
Pop the named sample, set "selected" sample name to a valid one. |
|
Declare the diffractometer to be used. |
|
Set the energy (thus wavelength) to be used (does not change control system value). |
|
Redefine the sample's lattice. |
|
Define an ORienting reflection. |
|
Report (brief) where is the diffractometer. |
Module Contents#
- class hklpy2.user._SelectedDiffractometer[source]#
Module class to maintain the diffractometer selection.
The current diffractometer.
- property diffractometer: hklpy2.diffract.DiffractometerBase[source]#
- hklpy2.user.add_sample(name: str, a: float, b: float = None, c: float = None, alpha: float = 90, beta: float = None, gamma: float = None, digits: int = 4, replace: bool = False)[source]#
Add (and select) a new crystal sample.
EXAMPLE:
>>> add_sample("example", 2, 4, 5) Sample(name='example', lattice=Lattice(a=2, b=4, c=5, system='orthorhombic'))
See also
- hklpy2.user.cahkl(h: float, k: float, l: float)[source]#
Calculate motor positions for specified ‘h, k l’ - DOES NOT MOVE motors.
Returns a namedtuple.
EXAMPLE:
>>> cahkl(1,-1, 1) Hklpy2DiffractometerRealPos( omega=12.254918848391, chi=-35.26440860898, phi=45.015980687529, tth=24.509837696782)
- hklpy2.user.cahkl_table(*reflections: list[hklpy2.misc.AxesTuple], digits=4)[source]#
Print a table with motor positions for each reflection given.
EXAMPLE:
1>>> cahkl_table((1, 1, 0), (1, 1, 1)) 2======= = ====== ========= ====== ====== 3(hkl) # omega chi phi tth 4======= = ====== ========= ====== ====== 5(1 1 0) 1 45.0 45.0 90.0 90.0 6(1 1 0) 2 -45.0 -45.0 -90.0 -90.0 7(1 1 0) 3 45.0 135.0 -90.0 90.0 8(1 1 0) 4 -135.0 -45.0 -90.0 90.0 9(1 1 0) 5 -45.0 -135.0 90.0 -90.0 10(1 1 0) 6 -135.0 -135.0 90.0 90.0 11(1 1 1) 1 60.0 35.2644 45.0 120.0 12(1 1 1) 2 -60.0 -35.2644 -135.0 -120.0 13(1 1 1) 3 -60.0 -144.7356 45.0 -120.0 14(1 1 1) 4 -120.0 -35.2644 -135.0 120.0 15(1 1 1) 5 -120.0 -144.7356 45.0 120.0 16(1 1 1) 6 60.0 144.7356 -135.0 120.0 17======= = ====== ========= ====== ======
- Parameters:
reflections (list(tuple(number,number,number))) –
This is a list of reflections where each reflection is a tuple of 3 numbers specifying (h, k, l) of the reflection to compute the
forward()
computation.Example:
[(1,0,0), (1,1,1)]
digits (int) – Number of digits to roundoff each position value. Default is 5.
- hklpy2.user.calc_UB(r1: hklpy2.blocks.reflection.Reflection | str, r2: hklpy2.blocks.reflection.Reflection | str, wavelength: float = None) list[list[float]] [source]#
Compute the UB matrix with two reflections.
EXAMPLE:
1>>> r400 = setor(name='r400', 4, 0, 0, omega=-145.451, chi=0, phi=0, tth=69.066) 2>>> r004 = setor(name='r004', 0, 0, 4, omega=-145.451, chi=90, phi=0, tth=69.066) 3>>> calc_UB(r400, r004) 4[[-0.000279252712, 0.999999913446, -0.000279252646], 5[0.0, -0.000279400627, -1.000000132342], 6[-1.000000087766, -0.000280008582, 2.82915e-07]]
- hklpy2.user.solver_summary(write=True)[source]#
Table of diffractometer solver’s modes, axes, …
EXAMPLE:
1>>> import hklpy2 2>>> from hklpy2.user import * 3>>> e4cv = hklpy2.creator(name="e4cv") 4>>> set_diffractometer(e4cv) 5>>> solver_summary() 6========= ================== ================== ==================== ==================== =============== 7engine mode pseudo(s) real(s) writable(s) extra(s) 8========= ================== ================== ==================== ==================== =============== 9hkl bissector h, k, l omega, chi, phi, tth omega, chi, phi, tth 10hkl constant_omega h, k, l omega, chi, phi, tth chi, phi, tth 11hkl constant_chi h, k, l omega, chi, phi, tth omega, phi, tth 12hkl constant_phi h, k, l omega, chi, phi, tth omega, chi, tth 13hkl double_diffraction h, k, l omega, chi, phi, tth omega, chi, phi, tth h2, k2, l2 14hkl psi_constant h, k, l omega, chi, phi, tth omega, chi, phi, tth h2, k2, l2, psi 15psi psi psi omega, chi, phi, tth omega, chi, phi, tth h2, k2, l2 16q q q tth tth 17incidence incidence incidence, azimuth omega, chi, phi x, y, z 18emergence emergence emergence, azimuth omega, chi, phi, tth x, y, z 19========= ================== ================== ==================== ==================== ===============
- hklpy2.user.get_diffractometer()[source]#
Return the currently-selected diffractometer (or
None
).EXAMPLE:
1>>> get_diffractometer() 2Hklpy2Diffractometer( 3 prefix='', 4 name='e4cv', 5 settle_time=0.0, 6 timeout=None, egu='', 7 limits=(0, 0), 8 source='computed', 9 read_attrs=['h', 'h.readback', 'h.setpoint', 'k', 'k.readback', 'k.setpoint', 'l', 'l.readback', 'l.setpoint', 'omega', 'chi', 'phi', 'tth'], 10 configuration_attrs=['geometry', 'solver', 'wavelength', 'h', 'k', 'l'], 11 concurrent=True)
- hklpy2.user.list_samples(full=False)[source]#
Summarize diffractometer’s samples.
Current sample appears first (with prefix
"> "
).EXAMPLE:
1>>> list_samples() 2> Sample(name='vibranium', lattice=Lattice(a=6.2832, system='cubic')) 3Sample(name='sample', lattice=Lattice(a=1, system='cubic'))
See also
- hklpy2.user.or_swap() list[list[float]] [source]#
Swap the first 2 ORienting reflections, re-compute & return new [UB].
Note
The SPEC user community knows this function as
or_swap
(swap the first two orienting reflections).EXAMPLE:
1>>> # define 2 reflections 2>>> r400 = setor(4, 0, 0, tth=69.0966, omega=-145.451, chi=0, phi=0, wavelength=1.54) 3>>> r040 = setor(0, 4, 0, tth=69.0966, omega=-145.451, chi=0, phi=90, wavelength=1.54) 4>>> # calculate UB 5>>> calc_UB(r400, r040) 6>>> # swap the two reflections (and recalculate UB) 7>>> or_swap()
See also
- hklpy2.user.pa(digits=4)[source]#
Report (all) the diffractometer settings.
EXAMPLE:
1>>> pa() 2diffractometer='e4cv' 3HklSolver(name='hkl_soleil', version='5.1.2', geometry='E4CV', engine_name='hkl', mode='bissector') 4Sample(name='vibranium', lattice=Lattice(a=6.2832, system='cubic')) 5U=[[0.000278604397, -0.99999996119, -3.9081e-08], [1.6307e-08, 3.9086e-08, -1.0], [0.99999996119, 0.000278604397, 1.6317e-08]] 6UB=[[0.000278604432, -0.999999952659, -1.87102e-07], [1.6307e-08, 3.9086e-08, -1.000000171333], [1.000000087947, 0.000279360313, -1.88574e-07]] 7Reflection(name='r400', geometry='E4CV', pseudos={'h': 4, 'k': 0, 'l': 0}, reals={'omega': -145.451, 'chi': 0, 'phi': 0, 'tth': 69.066}, wavelength=1.54, digits=4) 8Reflection(name='r040', geometry='E4CV', pseudos={'h': 0, 'k': 4, 'l': 0}, reals={'omega': -145.451, 'chi': 0, 'phi': 90, 'tth': 69.066}, wavelength=1.54, digits=4) 9Reflection(name='r004', geometry='E4CV', pseudos={'h': 0, 'k': 0, 'l': 4}, reals={'omega': -145.451, 'chi': 90, 'phi': 0, 'tth': 69.066}, wavelength=1.54, digits=4) 10Orienting reflections: ['r040', 'r004'] 11constraint: -180.2 <= omega <= 180.2 12constraint: -180.2 <= chi <= 180.2 13constraint: -180.2 <= phi <= 180.2 14constraint: -180.2 <= tth <= 180.2 15h=0, k=0, l=0 16wavelength=1.54 17omega=0, chi=0, phi=0, tth=0
See also
- hklpy2.user.remove_reflection(name: str, error: bool = True) None [source]#
Pop the named reflection and remove it from list of orienting reflections.
EXAMPLE:
>>> remove_reflection("r100")
PARAMETERS
- name: str
Reflection name to be removed.
- error: bool
When
True
(default),KeyError
is raised ifname
is not found. Provideerror=False
to skip the exception.
See also
- hklpy2.user.remove_sample(name: str, error: bool = True) None [source]#
Pop the named sample, set “selected” sample name to a valid one.
EXAMPLE:
>>> remove_sample("sample")
PARAMETERS
- name: str
Sample name to be removed.
- error: bool
When
error=True
(default):and
will raise
name
is not found.KeyError
name
is the only sample.CoreError
Provide
error=False
to avoid raising an exception.
See also
- hklpy2.user.set_diffractometer(diffractometer: hklpy2.diffract.DiffractometerBase = None) None [source]#
Declare the diffractometer to be used.
EXAMPLE:
>>> set_diffractometer(e4cv)
See also
- hklpy2.user.set_energy(value: float, units=None, offset=None)[source]#
Set the energy (thus wavelength) to be used (does not change control system value).
EXAMPLE:
>>> set_energy(12400, units="eV")
- hklpy2.user.set_lattice(a: float, b: float = None, c: float = None, alpha: float = 90, beta: float = None, gamma: float = None, digits: int = 4)[source]#
Redefine the sample’s lattice.
EXAMPLE:
>>> set_lattice(3, c=4, gamma=120)
- hklpy2.user.setor(h, k, l, *reals: hklpy2.misc.AnyAxesType, wavelength=None, name=None, **kwreals: hklpy2.misc.AxesDict)[source]#
Define an ORienting reflection.
Aliases:
add_reflection()
,setor()
A reflection is defined by its reciprocal space coordinates (pseudos) and its motor positions (reals). For convenience of the user, each reflection is named.
Note
The SPEC user community knows this function as
setor
.EXAMPLES:
>>> setor(4, 0, 0) Reflection(name='r_4ad1', geometry='E4CV', pseudos={'h': 4, 'k': 0, 'l': 0}, reals={'omega': -145.451, 'chi': 0, 'phi': 0, 'tth': 69.0966}, wavelength=1.54, digits=4) >>> setor(0, 4, 0, -145.451, 0, 90, 69.0966, name="r040") Reflection(name='r040', geometry='E4CV', pseudos={'h': 0, 'k': 4, 'l': 0}, reals={'omega': -145.451, 'chi': 0, 'phi': 90, 'tth': 69.0966}, wavelength=1.54, digits=4) >>> setor(0, 0, 4, omega=-145.451, chi=90, phi=0, tth=69.0966, name="r004") Reflection(name='r004', geometry='E4CV', pseudos={'h': 0, 'k': 0, 'l': 4}, reals={'omega': -145.451, 'chi': 90, 'phi': 0, 'tth': 69.0966}, wavelength=1.54, digits=4)
PARAMETERS
- h, k, l: float
Reciprocal-space coordinates of this reflection.
- reals: AnyAxesType
(optional) Real-space values of this reflection. Must provide all values in the order expected by the geometry. See Positions tip below.
- kwreals: AxesDict
(optional) Real-space axis names and values of this reflection. Must provide all axes expected by the geometry. See Positions tip below.
- wavelength: float
(optional) Wavelength of this reflection. When not specified, use the current diffractometer value.
- name: str
(optional) Reference text identifying this reflection. When not specified, a unique name will be assigned.
Tip
Positions (
reals
,kwreals
, or omitted entirely):Specified by values (in
reals
). Must use expected order. Will skipkwreals
if also provided.Specified by names (in
kwreals
). Axes, can appear in any order.reals
andkwreals
can be omitted entirely (use current values from diffractometer)
See the examples above.