prjemian / hklpy2

2nd generation of hklpy
https://prjemian.github.io/hklpy2/
Other
1 stars 0 forks source link

How to compute psi #6

Open prjemian opened 4 months ago

prjemian commented 4 months ago

With 6-circle, how to compute psi given the hardware angles and (h2,k2,l2).

Put this in a notebook HOWTO

prjemian commented 4 months ago

The E6C geometry, psi engine, psi_vertical mode can compute psi using inverse(angles) and fixed (h2,k2,l2).

prjemian commented 4 months ago
import hklpy2
from ophyd import Component as Cpt
from ophyd import Device
from ophyd import Kind
from ophyd import PseudoSingle
from ophyd import SoftPositioner

H_OR_N = Kind.hinted | Kind.normal

class E6C_Psi(hklpy2.DiffractometerBase):
    # reciprocal
    psi = Cpt(PseudoSingle, "", kind="hinted")

    # angles
    mu = Cpt(SoftPositioner, limits=(-180, 180), init_pos=0, kind=H_OR_N)
    omega = Cpt(SoftPositioner, limits=(-180, 180), init_pos=0, kind=H_OR_N)
    chi = Cpt(SoftPositioner, limits=(-180, 180), init_pos=0, kind=H_OR_N)
    phi = Cpt(SoftPositioner, limits=(-180, 180), init_pos=0, kind=H_OR_N)
    gamma = Cpt(SoftPositioner, limits=(-180, 180), init_pos=0, kind=H_OR_N)
    delta = Cpt(SoftPositioner, limits=(-180, 180), init_pos=0, kind=H_OR_N)

    def __init__(self, *args, **kwargs):
        super().__init__(
            *args,
            solver="hkl_soleil",
            geometry="E6C",  # "PETRA3 P09 EH2" or "APS POLAR"
            solver_kwargs={"engine": "psi"},
            **kwargs,
        )

e6c = E6C_Psi("", name="e6c")
e6c.operator.auto_assign_axes()
print(f"{e6c.operator.solver.modes=}")
# e6c.operator.solver.modes=['psi_vertical']

print(f"{e6c.operator.sample=}")
# e6c.operator.sample=Sample(name='sample', lattice=Lattice(a=1, system='cubic'))

e6c.omega.move(15)
e6c.delta.move(30)
e6c.read()
# OrderedDict([('e6c_psi', {'value': 45.0, 'timestamp': 1720457927.8246849}),
#              ('e6c_psi_setpoint',
#               {'value': 45.0, 'timestamp': 1720457927.8247018}),
#              ('e6c_mu', {'value': 0, 'timestamp': 1720457950.6137168}),
#              ('e6c_omega', {'value': 15, 'timestamp': 1720457950.6137214}),
#              ('e6c_chi', {'value': 0, 'timestamp': 1720457950.6137247}),
#              ('e6c_phi', {'value': 0, 'timestamp': 1720457950.613728}),
#              ('e6c_gamma', {'value': 0, 'timestamp': 1720457950.6137314}),
#              ('e6c_delta', {'value': 30, 'timestamp': 1720457950.6137347})])

e6c.chi.move(90)
e6c.read()
# OrderedDict([('e6c_psi', {'value': -45.0, 'timestamp': 1720457927.8246849}),
#              ('e6c_psi_setpoint',
#               {'value': -45.0, 'timestamp': 1720457927.8247018}),
#              ('e6c_mu', {'value': 0, 'timestamp': 1720457969.8769462}),
#              ('e6c_omega', {'value': 15, 'timestamp': 1720457969.8769512}),
#              ('e6c_chi', {'value': 90, 'timestamp': 1720457969.8769548}),
#              ('e6c_phi', {'value': 0, 'timestamp': 1720457969.8769584}),
#              ('e6c_gamma', {'value': 0, 'timestamp': 1720457969.8769627}),
#              ('e6c_delta', {'value': 30, 'timestamp': 1720457969.8769655})])

e6c.phi.move(1)
e6c.read()
# OrderedDict([('e6c_psi', {'value': -46.0, 'timestamp': 1720457927.8246849}),
#              ('e6c_psi_setpoint',
#               {'value': -46.0, 'timestamp': 1720457927.8247018}),
#              ('e6c_mu', {'value': 0, 'timestamp': 1720457992.9123988}),
#              ('e6c_omega', {'value': 15, 'timestamp': 1720457992.9124033}),
#              ('e6c_chi', {'value': 90, 'timestamp': 1720457992.9124067}),
#              ('e6c_phi', {'value': 1, 'timestamp': 1720457992.91241}),
#              ('e6c_gamma', {'value': 0, 'timestamp': 1720457992.9124136}),
#              ('e6c_delta', {'value': 30, 'timestamp': 1720457992.9124165})])