UB matrix : calculate from 2 reflections.#

\(UB\) is the 3x3 orientation matrix used to transform coordinates between reciprocal space directions (of the crystal lattice planes) and the rotational axes of the diffractometer.

Create a diffractometer object#

First, create a diffractometer object that uses the "hkl_soleil" solver with the "hkl" computation engine. This solver provides support for many diffractometer geometries. This example will use the simulated 4-circle geometry from the solver’s "E4CV".

[1]:
from hklpy2 import SimulatedE4CV

diffractometer = SimulatedE4CV(name="diffractometer")

Defaults#

The diffractometer object starts with a default sample. The structure is cubic (\(a=b=c\), 90 degree corners).

[2]:
diffractometer.sample
[2]:
Sample(name='sample', lattice=Lattice(a=1, system='cubic'))

Add 2 reflections#

Two reflections are needed to calculate \(UB\). Since we do not specify the wavelength, the support assumes the diffractometer’s current wavelength.

[3]:
diffractometer.wavelength.get()
[3]:
1.0

Add two non-parallel reflections. Here, just the values of the pseudos and reals are specified as Python tuples, in the exact order expected by the solver geometry.

[4]:
r100 = diffractometer.add_reflection((1, 0, 0), (-145.451, 5, -5, 69.0966), name="(100)")
r010 = diffractometer.add_reflection((0, 1, 0), (-145.451, 5, 85, 69.0966), name="(010)")

Compute UB#

Compute \(UB\) with these two reflections:

[5]:
diffractometer.operator.calcUB(r100, r010)

Show the calculated \(UB\) matrix:

[6]:
diffractometer.operator.solver.UB
[6]:
[[0.545455367746, -6.239787515781, -0.495931249329],
 [-0.547615682228, -0.543471605558, 6.235637359796],
 [-6.235464145574, -0.498104382852, -0.591013127949]]

Try it out#

corresponding to the \((1,0,0)\) reflection:

[7]:
diffractometer.forward(1, 0, 0)
[7]:
SimulatedE4CVRealPos(omega=-149.999999959667, chi=4.999999963097, phi=-4.999297295242, tth=60.000000080666)

Show the (first set of computed) angles corresponding to the \((1 \bar1 1)\) reflection:

[8]:
diffractometer.forward(1, -1, 1)
[8]:
SimulatedE4CVRealPos(omega=-119.999999996665, chi=-34.931758281633, phi=-44.822626886902, tth=120.00000000667)