Ways to Specify Real and Pseudo Axis Positions#

hklpy2 accepts several equivalent forms when specifying axis positions to forward(), inverse(), forward(), inverse(), add_reflection(), and related methods.

The examples use an E4CV diffractometer restored from a saved configuration:

import hklpy2
sim = hklpy2.simulator_from_config("e4cv-config.yml")

Pseudo axis positions (for diffractometer.forward())#

Pseudo axes are the reciprocal-space coordinates (h, k, l for an HKL geometry).

Pass values in the order the solver expects (h, k, l for E4CV):

sim.forward(1, 0, 0)

Real axis positions (for diffractometer.inverse())#

Real axes are the physical motor angles (omega, chi, phi, tth for E4CV).

Pass values in the order the solver expects:

sim.inverse(-145, 0, 0, 69)

Lower-level: core.forward() and core.inverse()#

The forward() and inverse() methods on the core object are lower-level and behave differently:

  • core.forward() returns all solutions as a list (unfiltered by constraints or the forward-solution picker).

  • core.inverse() returns a plain dict (not a named tuple).

  • Positional args and keyword args are not accepted.

Not available for core.forward() or core.inverse().

Use diffractometer.forward() and diffractometer.inverse() for everyday work — they apply constraints, pick the best solution, and return named tuples. Use core.forward() when you need access to all solutions before filtering.

Reflections: core.add_reflection()#

add_reflection() accepts Dictionary, Named tuple, and Bare tuple for both the pseudo (hkl) and real (motor angles) position arguments — Positional args and Keyword args are not available:

# Dictionary (recommended)
sim.core.add_reflection(
    dict(h=4, k=0, l=0),
    dict(omega=-145.451, chi=0, phi=0, tth=69.066),
)

# Named tuple
sim.core.add_reflection(
    sim.PseudoPosition(h=4, k=0, l=0),
    sim.RealPosition(omega=-145.451, chi=0, phi=0, tth=69.066),
)

# Bare tuple (positionally mapped in solver order)
sim.core.add_reflection((4, 0, 0), (-145.451, 0, 0, 69.066))

Reflections: user.setor() / user.add_reflection()#

The setor() function (also aliased as add_reflection()) has a distinct and more flexible interface. Pseudo positions are always Positional args (h, k, l). Real positions can be provided in three ways:

Real positions in solver order, appended after h, k, l:

from hklpy2.user import setor
setor(4, 0, 0, -145.451, 0, 0, 69.066)

Which form to use#

Method

Positional args

Keyword args

Dictionary

Named tuple

Bare tuple

diffractometer.forward()

diffractometer.inverse()

core.forward()

core.inverse()

core.add_reflection()

user.setor()

✓ (reals)

✓ (reals)

See also

Diffractometer Axis Names — axis naming, ordering, and custom axis names.

How to Choose the Default forward() Solution — choosing which forward() solution is returned.