Module: sample#

Sample on the diffractometer.

class hkl.sample.HklSample(calc, sample=None, units='user', **kwargs)[source]#

Represents a sample in diffractometer calculations

Parameters:
  • calc (instance of CalcRecip) – Reciprocal space calculation class

  • name (str) – A user-defined name used to refer to the sample

  • sample (Hkl.Sample, optional) – A Sample instance from the wrapped Hkl library. Created automatically if not specified.

  • units ({'user', 'default'}) – Units to use

  • lattice (np.ndarray, optional) – The lattice

  • U (np.ndarray, optional) – The crystal orientation matrix, U

  • UB (np.ndarray, optional) – The UB matrix, where U is the crystal orientation matrix and B is the transition matrix of a non-orthonormal (the reciprocal of the crystal) in an orthonormal system

  • ux (np.ndarray, optional) – ux part of the U matrix

  • uy (np.ndarray, optional) – uy part of the U matrix

  • uz (np.ndarray, optional) – uz part of the U matrix

  • reflections

    All reflections for the current sample in the form:

    [(h, k, l), ...]
    

    This assumes the hkl engine is used; generally, the ordered set of positions for the engine in-use should be specified.

  • API (PRIVATE)

  • autosummary:: (..) – ~name ~add_reflection ~remove_reflection ~swap_orientation_reflections ~clear_reflections ~affine ~compute_UB ~lattice ~reciprocal ~reflection_measured_angles ~reflection_theoretical_angles ~reflections ~reflections_details ~U ~UB ~ux ~uy ~uz

  • API

  • autosummary:: – ~hkl_calc ~hkl_sample ~__repr__ ~__str__ ~_create_reflection ~_get_reflection_dict ~_refl_matrix ~_repr_info

property U#

The crystal orientation matrix, U

property UB#

The UB matrix, where U is the crystal orientation matrix and B is the transition matrix of a non-orthonormal (the reciprocal of the crystal) in an orthonormal system

If written to, the B matrix will be kept constant:

U * B = UB -> U = UB * B^-1

_create_reflection(h, k, l, detector=None)[source]#

Create a new reflection with the current geometry/detector

_get_reflection_dict(refl)[source]#

Return dictionary with reflection details.

_refl_matrix(fcn)[source]#

Get a reflection angle matrix.

add_reflection(h: float, k: float, l: float, position=None, detector=None, compute_ub: bool = False)[source]#

Add a reflection, optionally specifying the detector to use

Parameters:
  • h ((int, float)) – Reflection h

  • k ((int, float)) – Reflection k

  • l ((int, float)) – Reflection l

  • detector (Hkl.Detector, optional) – The detector

  • position (list, tuple, or namedtuple, optional) – The physical motor position that this reflection corresponds to If not specified, the current geometry of the calculation engine is assumed.

  • compute_ub (bool, optional) – Calculate the UB matrix with the last two reflections

affine()[source]#

Refine (affine) the sample lattice parameters from the list of reflections.

clear_reflections()[source]#

Clear all reflections for the current sample.

compute_UB(r1, r2)[source]#

Compute the UB matrix with two reflections.

Using the Busing and Levy method, compute the UB matrix for two sample reflections, r1 and r2.

Returns the UB matrix or raises gi.repository.GLib.GError (a change from 0.3.15 and before). Returns None if no error raised but computation was not successful.

Parameters:
  • r1 (HklReflection) – Reflection 1

  • r2 (HklReflection) – Reflection 2

Return type:

UB matrix or raises gi.repository.GLib.GError

property hkl_calc#

The HklCalc instance associated with the sample

property hkl_sample#

The HKL library sample object

property lattice#

The lattice (a, b, c, alpha, beta, gamma)

a, b, c [nm] alpha, beta, gamma [deg]

property name#

The name of the currently selected sample

property reciprocal#

The reciprocal lattice

property reflections#

All reflections for the current sample in the form: [(h, k, l), …]

property reflections_details#

Return a list with details of all reflections.

NOTE: reflections_details() uses the canonical names for the real positioners. The mapping to physical axis names happens in :mod`hkl.calc`.

remove_reflection(refl)[source]#

Remove a specific reflection

swap_orientation_reflections()[source]#

Swap the 2 [UB] reflections, re-compute & return new [UB].

property ux#

ux part of the U matrix

property uy#

uy part of the U matrix

property uz#

uz part of the U matrix

hkl.sample.check_lattice(lattice)[source]#

Check an Hkl.Lattice for validity

Raises:

ValueError


Examples#

We limit our examples here to just a few brief examples will show how to define a sample, its crystal lattice, and orient the crystal to position it using reciprocal space coordinates. We’ll leave it to others (for now) to show more comprehensive examples that show additional capabilities, such as limiting the ranges of the motors for acceptable solutions of the forward calculation from (hkl) to motor positions.

These examples use a diffractometer object called fourc which we’ll take to be an instance of a 4-circle diffractometer in vertical scattering geometry (E4CV) with simulated motors. (This is similar to the 6-circle example sim6c: Eulerian 6-circle with simulated motors.)

 1import hkl
 2from ophyd import Component, PseudoSingle, SoftPositioner
 3
 4class SimulatedE4CV(hkl.E4CV):
 5
 6    h = Component(PseudoSingle, '')
 7    k = Component(PseudoSingle, '')
 8    l = Component(PseudoSingle, '')
 9
10    omega = Component(SoftPositioner, limits=(-180, 180), init_pos=0)
11    chi = Component(SoftPositioner, limits=(-180, 180), init_pos=0)
12    phi = Component(SoftPositioner, limits=(-180, 180), init_pos=0)
13    tth = Component(SoftPositioner, limits=(-180, 180), init_pos=0)

Then, create the fourc object for these examples:

fourc = SimulatedE4CV('', name='fourc')

define a sample with a lattice#

Define a sample with the name EuPtIn4_eh1_ver and define its crystal lattice. Use angstroms as units for the unit cell edges and degrees for the angles.

from hkl import Lattice
fourc.calc.new_sample('EuPtIn4_eh1_ver',
    lattice=Lattice(
        a=4.542, b=16.955, c=7.389,
        alpha=90.0, beta=90.0, gamma=90.0))

define an orientation matrix#

This is a brief example to define two reflections and then apply the method of Busing & Levy [1] to calculate an orientation matrix.

For this example, the reflection positions were found at a wavelength of 1.62751693358 angstroms.

fourc.calc.wavelength = 1.62751693358

We found the (080) reflection at these motor positions:

p = fourc.calc.Position(
    omega=22.31594, chi=89.1377, phi=0, tth=45.15857)

Associate p (the motor positions) with the (080) reflection:

r1 = fourc.calc.sample.add_reflection(0, 8, 0, p)

Do the same for the (0 12 1) reflection:

p = fourc.calc.Position(
    omega=34.96232, chi=78.3139, phi=0, tth=71.8007)
r2 = fourc.calc.sample.add_reflection(0, 12, 1, p)

Compute the UB matrix:

fourc.calc.sample.compute_UB(r1, r2)

See the libhkl documentation [2] for more details.

compute the motor positions for a reflection#

Compute the motor positions for the (100) reflection:

fourc.forward(1,0,0)

This can be assigned to a python object:

p = fourc.forward(0,1,1)

Then, the motor positions can be accessed: p.omega, p.chi, p.phi, p.tth.

These are the motor angles computed as the first solution:

(hkl)

omega

chi

phi

tth

(1, 0, 0)

10.32101

0.20845

86.38310

20.64202