hklpy2.diffract#

Base class for all diffractometers

creator(*[, prefix, name, solver, geometry, ...])

Factory function to create a diffractometer instance.

diffractometer_class_factory(*[, solver, ...])

Build a custom class for this diffractometer geometry.

DiffractometerBase([prefix, solver, ...])

Base class for all diffractometers.

Hklpy2PseudoAxis([prefix, limits, egu, ...])

Override to allow additional pseudos.

pick_first_item(now, solutions)

Choose first item from list.

Attributes#

Classes#

Hklpy2PseudoAxis

Override to allow additional pseudos.

DiffractometerBase

Base class for all diffractometers.

Functions#

pick_first_item(now, solutions)

Choose first item from list.

creator(*[, prefix, name, solver, geometry, ...])

Factory function to create a diffractometer instance.

diffractometer_class_factory(→ DiffractometerBase)

Build a custom class for this diffractometer geometry.

Module Contents#

hklpy2.diffract.__all__[source]#
hklpy2.diffract.logger[source]#
hklpy2.diffract.DEFAULT_PHOTON_ENERGY_KEV = 8.0[source]#
hklpy2.diffract.H_OR_N[source]#
hklpy2.diffract.pick_first_item(now: tuple, solutions: list)[source]#

Choose first item from list.

Used by ‘.forward()’ method to pick the first solution from a list of possible solutions.

User can provide an alternative function and assign to diffractometer’s _forward_solution() method.

Parameters

  • now (tuple) : Current position.

  • solutions ([tuple]) : List of positions.

class hklpy2.diffract.Hklpy2PseudoAxis(prefix='', *, limits=None, egu='', parent=None, name=None, source='computed', target_initial_position=False, **kwargs)[source]#

Bases: ophyd.PseudoSingle

Override to allow additional pseudos.

_sub_proxy_readback(obj=None, value=None, **kwargs)[source]#

Parent callbacks including a position value will be filtered through this function and re-broadcast using only the relevant position to this pseudo axis.

class hklpy2.diffract.DiffractometerBase(prefix: str = '', *, solver: str = None, geometry: str = None, solver_kwargs: dict = {}, pseudos: list[str] = [], reals: list[str] = [], **kwargs)[source]#

Bases: ophyd.PseudoPositioner

Base class for all diffractometers.

Parameters

  • solver (str) : Name of Solver library. (default: unspecified)

  • geometry: (str) : Name of Solver geometry. (default: unspecified)

  • solver_kwargs (dict) : Any additional keyword arguments needed by Solver library. (default: empty)

  • pseudos ([str]) : List of diffractometer axis names to be used as pseudo axes. (default: unspecified)

  • reals ([str]) : List of diffractometer axis names to be used as real axes. (default: unspecified)

(ophyd) Components

(ophyd) Attribute Components

geometry

Name of backend Solver geometry.

solver

Name of backend Solver (library).

wavelength

Wavelength of incident radiation.

Python Methods

add_reflection(pseudos[, reals, wavelength, ...])

Add a new reflection with this geometry to the selected sample.

add_sample(name, a[, b, c, alpha, beta, ...])

Add a new sample.

export(file[, comment])

Export the diffractometer configuration to a YAML file.

forward(pseudos[, wavelength])

Compute real-space coordinates from pseudos (hkl -> angles).

full_position([digits])

Return dict with positions of pseudos, reals, & extras.

inverse(reals[, wavelength])

Compute pseudo-space coordinates from reals (angles -> hkl).

move_dict(axes)

(plan) Move diffractometer axes to positions in 'axes'.

move_forward_with_extras(pseudos, extras)

(plan stub) Set extras and compute forward solution at fixed Q and extras.

move_reals(reals)

(not a plan) Move the real-space axes as specified in 'real_positions'.

restore(config[, clear, ...])

Restore diffractometer configuration.

scan_extra(detectors[, axis, start, finish, ...])

Scan one extra diffractometer parameter, such as 'psi'.

wh([digits, full])

Concise report of the current diffractometer positions.

Python Properties

configuration

Diffractometer configuration (orientation).

pseudo_axis_names

Names of all the pseudo axes, in order of appearance.

real_axis_names

Names of all the real axes, in order of appearance.

sample

Current sample object.

samples

Dictionary of samples.

solver_name

Backend Solver library name.

geometry[source]#

Name of backend Solver geometry.

solver[source]#

Name of backend Solver (library).

wavelength[source]#

Wavelength of incident radiation.

_backend = None[source]#
_forward_solution[source]#
_source[source]#
core[source]#
add_reflection(pseudos, reals=None, wavelength=None, name=None, replace: bool = False) hklpy2.blocks.reflection.Reflection[source]#

Add a new reflection with this geometry to the selected sample.

Parameters

  • pseudos (various): pseudo-space axes and values.

  • reals (various): dictionary of real-space axes and values.

  • wavelength (float): Wavelength of incident radiation. If None, diffractometer’s current wavelength will be assigned.

  • name (str): Reference name for this reflection. If None, a random name will be assigned.

  • replace (bool): If True, replace existing reflection of this name. (default: False)

add_sample(name: str, a: float, b: float = None, c: float = None, alpha: float = 90.0, beta: float = None, gamma: float = None, digits: int = 4, replace: bool = False) hklpy2.blocks.sample.Sample[source]#

Add a new sample.

property configuration: dict[source]#

Diffractometer configuration (orientation).

export(file, comment='')[source]#

Export the diffractometer configuration to a YAML file.

Example:

import hklpy2

e4cv = hklpy2.creator(name="e4cv")
e4cv.export("e4cv-config.yml", comment="example")
restore(config, clear=True, restore_constraints=True, restore_wavelength=True)[source]#

Restore diffractometer configuration.

Example:

import hklpy2

e4cv = hklpy2.creator(name="e4cv")
e4cv.restore("e4cv-config.yml")

PARAMETERS

config dict, str, or pathlib.Path object:

Dictionary with configuration, or name (str or pathlib object) of diffractometer configuration YAML file.

clear bool:

If True (default), remove any previous configuration of the diffractometer and reset it to default values before restoring the configuration.

If False, sample reflections will be append with all reflections included in the configuration data for that sample. Existing reflections will not be changed. The user may need to edit the list of reflections after restore(clear=False).

restore_constraints bool:

If True (default), restore any constraints provided.

restore_wavelength bool:

If True (default), restore wavelength.

Note: Can’t name this method “import”, it’s a reserved Python word.

forward(pseudos: dict, wavelength: float = None) tuple[source]#

Compute real-space coordinates from pseudos (hkl -> angles).

full_position(digits=4) dict[source]#

Return dict with positions of pseudos, reals, & extras.

inverse(reals: tuple, wavelength: float = None) tuple[source]#

Compute pseudo-space coordinates from reals (angles -> hkl).

move_dict(axes: hklpy2.misc.AxesDict)[source]#

(plan) Move diffractometer axes to positions in ‘axes’.

move_forward_with_extras(pseudos: hklpy2.misc.AnyAxesType, extras: hklpy2.misc.AxesDict)[source]#

(plan stub) Set extras and compute forward solution at fixed Q and extras.

EXAMPLE:

RE(
    move_forward_with_extras(
        diffractometer,
        Q=dict(h=2, k=1, l=0),
        extras=dict(h2=2, k2=2, l2=0, psi=25),
    )
)
move_reals(reals: hklpy2.misc.AnyAxesType) None[source]#

(not a plan) Move the real-space axes as specified in ‘real_positions’.

scan_extra(detectors: list, axis: str | None = None, start: float | None = None, finish: float | None = None, num: int | None = 2, *, pseudos: dict | None = None, reals: dict | None = None, extras: dict | None = {}, fail_on_exception: bool | None = False, md: dict | None = None)[source]#

Scan one extra diffractometer parameter, such as ‘psi’.

  • TODO: one or more (such as bp.scan)

  • TODO: support “inverse” transformation scan

  • iterate extra positions as decribed:
    • set extras

    • solution = forward(pseudos)

    • move to solution

    • acquire (trigger) all controls

    • read and record all controls

property pseudo_axis_names[source]#

Names of all the pseudo axes, in order of appearance.

Example:

>>> fourc.pseudo_axis_names
['h', 'k', 'l']
property real_axis_names[source]#

Names of all the real axes, in order of appearance.

Example:

>>> fourc.real_axis_names
['omega', 'chi, 'phi', 'tth']
property samples[source]#

Dictionary of samples.

property sample[source]#

Current sample object.

property solver_name[source]#

Backend Solver library name.

wh(digits=4, full=False)[source]#

Concise report of the current diffractometer positions.

hklpy2.diffract.creator(*, prefix: str = '', name: str = '', solver: str = 'hkl_soleil', geometry: str = 'E4CV', solver_kwargs: dict = {}, pseudos: list = [], reals: list[str] | dict[str, str | None] = {}, aliases: dict[str, list[str]] = {}, motor_labels: list = ['motors'], labels: list = ['diffractometer'], class_name: str = 'Hklpy2Diffractometer', class_bases: list = [DiffractometerBase], **kwargs)[source]#

Factory function to create a diffractometer instance.

EXAMPLES:

Four-circle diffractometer, vertical orientation, Eulerian rotations, canonical real axis names, EPICS motor PVs:

e4cv = creator(name="e4cv",
    solver="hkl_soleil", geometry="E4CV",
    reals=dict(omega="IOC:m1", chi="IOC:m2", phi="IOC:m3", tth="IOC:m4"),
)

Four-circle diffractometer, vertical orientation, Eulerian rotations, custom real axis names, simulated positioners:

sim4c = creator(name="sim4c",
    solver="hkl_soleil", geometry="E4CV",
    reals=dict(uno=None, dos=None, tres=None, cuatro=None),
)

(Simplest case to get a simulator.) Four-circle diffractometer, vertical orientation, Eulerian rotations, canonical real axis names, simulated positioners (all default settings):

sim4c = creator(name="sim4c")

Kappa six-circle diffractometer, simulated motors:

simk6c = creator(name="simk6c",
    solver="hkl_soleil", geometry="K6C"
)

PARAMETERS

prefixstr

EPICS PV prefix (default: empty string)

namestr

Name of the ophyd diffractometer object to be created. (default: ‘””’)

solverstr

Name of the backend solver providing the geometry. (default: ‘“hkl_soleil”’)

geometrystr

Name of the diffractometer geometry. (default: ‘“E4CV”’)

solver_kwargsstr

Additional configuration for the solver. (default: ‘{“engine”: “hkl”}’)

pseudoslist

Specification of the names of any pseudo axis positioners in addition to the ones provided by the solver.

(default: ‘[]’ which means no additional pseudo axes)

realsdict

Specification of the real axis motors. Dictionary keys are the motor names, values are the EPICS motor PV for that axis. If the PV is ‘None’, use a simulated positioner.

The dictionary can be empty or must have at least the canonical number of real axes. The order of the axes is important. The names provided will be mapped to the canonical order defined by the solver. Components will be created for any extra reals.

(default: ‘{}’ which means use the canonical names for the real axes and use simulated positioners)

aliases: dict[str, list[str]]

Aliases of diffractometer axes for solver’s pseudos and reals.

(default: ‘{}’ which means use the first diffractometer axes from each to match the solver.)

motor_labelslist

Ophyd object labels for each real positioner. (default: ‘[“motors”]’)

labelslist

Ophyd object labels for the diffractometer object. (default: ‘[“diffractometer”]’)

class_namestr

Name to use for the diffractometer class. (default: ‘“Hklpy2Diffractometer”’)

class_baseslist

List of base classes to use for the diffractometer class. (default: ‘[DiffractometerBase]’)

kwargsany

Additional keyword arguments will be added when constructing the new diffractometer object.

hklpy2.diffract.diffractometer_class_factory(*, solver: str = 'hkl_soleil', geometry: str = 'E4CV', solver_kwargs: dict = {'engine': 'hkl'}, pseudos: list = [], reals: list[str] | dict[str, str | None] = {}, motor_labels: list = ['motors'], class_name: str = 'Hklpy2Diffractometer', class_bases: list = [DiffractometerBase], aliases: dict[str, list[str]] = {}) DiffractometerBase[source]#

Build a custom class for this diffractometer geometry.

PARAMETERS

solverstr

Name of the backend solver providing the geometry. (default: ‘“hkl_soleil”’)

geometrystr

Name of the diffractometer geometry. (default: ‘“E4CV”’)

solver_kwargsstr

Additional configuration for the solver. (default: ‘{“engine”: “hkl”}’)

pseudoslist

Specification of the names of any pseudo axis positioners in addition to the ones provided by the solver.

(default: ‘[]’ which means no additional pseudo axes)

realsdict

Specification of the real axis motors. Dictionary keys are the motor names, values are the EPICS motor PV for that axis. If the PV is ‘None’, use a simulated positioner.

The dictionary can be empty or must have at least the canonical number of real axes. The order of the axes is important. The names provided will be mapped to the canonical order defined by the solver. Components will be created for any extra reals.

(default: ‘{}’ which means use the canonical names for the real axes and use simulated positioners)

motor_labelslist

Ophyd object labels for each real positioner. (default: ‘[“motors”]’)

class_namestr

Name to use for the diffractometer class. (default: ‘“Hklpy2Diffractometer”’)

class_baseslist

List of base classes to use for the diffractometer class. (default: ‘[DiffractometerBase]’)

aliases: dict[str, list[str]]

Aliases of diffractometer axes for solver’s pseudos and reals.

(default: ‘{}’ which means use the first diffractometer axes from each to match the solver.)