Constraints#

Constraints are used to filter acceptable solutions computed by a Solver forward() method. One or more constraints (ConstraintBase) (a.k.a, cut points), together with a choice of operating mode are used to control the over-determined transformation from \(hkl\) to motor angles.

Tip

Constraints are implemented as cut points in other software. Similar in concept yet not entirely identical in implementation.

Show the current constraints#

Start with a diffractometer. This example starts with E6C, as shown in the Quickstart.

1>>> import hklpy2
2>>> sixc = hklpy2.creator(name="sixc", geometry="E6C", solver="hkl_soleil")

Show the constraints:

1>>> sixc.core.constraints
2['-180.0 <= mu <= 180.0', '-180.0 <= omega <= 180.0', '-180.0 <= chi <= 180.0', '-180.0 <= phi <= 180.0', '-180.0 <= gamma <= 180.0', '-180.0 <= delta <= 180.0']

Change a constraint#

Only accept forward() solutions where omega \(>= 0\).

1>>> sixc.core.constraints["omega"].low_limit
2-180.0
3>>> sixc.core.constraints["omega"].low_limit = 0
4>>> sixc.core.constraints["omega"]
50 <= omega <= 180.0

Apply axis cuts#

Only accept forward() solutions where chi is between $\pm90$:

1>>> sixc.core.constraints["chi"].limits
2(-180.0, 180.0)
3>>> sixc.core.constraints["chi"].limits = -90, 90
4>>> sixc.core.constraints["chi"].limits
5(-90.0, 90.0)

Freeze an axis#

Only accept forward() solutions where mu is zero:

1>>> sixc.core.constraints["mu"].limits
2(-180.0, 180.0)
3>>> sixc.core.constraints["mu"].limits = 0, 0
4>>> sixc.core.constraints["mu"].limits
5(0.0, 0.0)