hklpy2.diffract#
Base class for all diffractometers
|
Factory function to create a diffractometer instance. |
|
Build a custom class for this diffractometer geometry. |
|
Base class for all diffractometers. |
|
Override to allow additional pseudos. |
|
Choose first item from list. |
Attributes#
Classes#
Override to allow additional pseudos. |
|
Base class for all diffractometers. |
Functions#
|
Choose first item from list. |
|
Factory function to create a diffractometer instance. |
|
Build a custom class for this diffractometer geometry. |
Module Contents#
- 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.
- 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
Name of backend Solver geometry.
Name of backend Solver (library).
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
Diffractometer configuration (orientation).
Names of all the pseudo axes, in order of appearance.
Names of all the real axes, in order of appearance.
Current sample object.
Dictionary of samples.
Backend Solver library name.
- 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. IfNone
, diffractometer’s current wavelength will be assigned.name
(str): Reference name for this reflection. IfNone
, a random name will be assigned.replace
(bool): IfTrue
, 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.
- 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 afterrestore(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).
- 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']
- 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.)