{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example 4-circle diffractometer using creator()\n", "\n", "Similar to {doc}`example-4-circle-custom-class`, this example builds a custom\n", "4-circle. This version uses the {func}`~hklpy2.diffract.creator()` function." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Hklpy2Diffractometer(prefix='gp:', name='fourc', settle_time=0.0, timeout=None, egu='', limits=(0, 0), source='computed', read_attrs=['beam', 'beam.wavelength', 'beam.energy', 'h', 'h.readback', 'h.setpoint', 'k', 'k.readback', 'k.setpoint', 'l', 'l.readback', 'l.setpoint', 'h2', 'h2.readback', 'h2.setpoint', 'k2', 'k2.readback', 'k2.setpoint', 'l2', 'l2.readback', 'l2.setpoint', 'theta', 'theta.user_readback', 'theta.user_setpoint', 'chi', 'chi.user_readback', 'chi.user_setpoint', 'phi', 'phi.user_readback', 'phi.user_setpoint', 'ttheta', 'ttheta.user_readback', 'ttheta.user_setpoint', 'psi', 'temperature'], configuration_attrs=['solver_signature', 'beam', 'beam.source_type', 'beam.wavelength_units', 'beam.wavelength_deadband', 'beam.energy_units', 'h', 'k', 'l', 'h2', 'k2', 'l2', 'theta', 'theta.user_offset', 'theta.user_offset_dir', 'theta.velocity', 'theta.acceleration', 'theta.motor_egu', 'chi', 'chi.user_offset', 'chi.user_offset_dir', 'chi.velocity', 'chi.acceleration', 'chi.motor_egu', 'phi', 'phi.user_offset', 'phi.user_offset_dir', 'phi.velocity', 'phi.acceleration', 'phi.motor_egu', 'ttheta', 'ttheta.user_offset', 'ttheta.user_offset_dir', 'ttheta.velocity', 'ttheta.acceleration', 'ttheta.motor_egu'], concurrent=True)" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import hklpy2\n", "from ophyd import Kind\n", "\n", "NORMAL_HINTED = Kind.hinted | Kind.normal\n", "\n", "fourc = hklpy2.creator(\n", " prefix=\"gp:\",\n", " name=\"fourc\",\n", " solver=\"hkl_soleil\",\n", " geometry=\"E4CV\",\n", " pseudos=\"h k l h2 k2 l2\".split(),\n", " reals=dict(\n", " theta=\"m30\",\n", " chi=\"m31\",\n", " phi=\"m32\",\n", " ttheta=\"m29\",\n", " psi=None,\n", " temperature=None,\n", " ),\n", " beam_kwargs={\n", " \"class\": \"hklpy2.incident.EpicsMonochromatorRO\",\n", " \"prefix\": \"gp:\",\n", " \"source_type\": \"Simulated read-only EPICS Monochromator\",\n", " \"pv_energy\": \"BraggERdbkAO\", # the energy readback PV\n", " \"energy_units\": \"keV\",\n", " \"pv_wavelength\": \"BraggLambdaRdbkAO\", # the wavelength readback PV\n", " \"wavelength_units\": \"angstrom\",\n", " \"wavelength_deadband\": 0.000_150,\n", " \"kind\": NORMAL_HINTED,\n", " },\n", ")\n", "fourc.wait_for_connection() # Recommended when connecting to control system.\n", "fourc" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Most features can be implemented using the {func}`~hklpy2.diffract.creator()`. Only the limits and initial values of the `temperature` Component cannot be specified." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Continuing with the same Python commands..." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "wavelength=1.2155268902481402\n", "h=0, k=0, l=0\n", "theta=0, chi=0, phi=0, ttheta=0\n" ] } ], "source": [ "fourc.wh()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "diffractometer='fourc'\n", "HklSolver(name='hkl_soleil', version='5.1.2', geometry='E4CV', engine_name='hkl', mode='bissector')\n", "Sample(name='sample', lattice=Lattice(a=1, system='cubic'))\n", "Orienting reflections: []\n", "U=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]\n", "UB=[[6.283185307179586, 0.0, 0.0], [0.0, 6.283185307179586, 0.0], [0.0, 0.0, 6.283185307179586]]\n", "constraint: -180.0 <= theta <= 180.0\n", "constraint: -180.0 <= chi <= 180.0\n", "constraint: -180.0 <= phi <= 180.0\n", "constraint: -180.0 <= ttheta <= 180.0\n", "Mode: bissector\n", "beam={'class': 'EpicsMonochromatorRO', 'source_type': 'Simulated read-only EPICS Monochromator', 'energy': 10.200041232710992, 'wavelength': 1.2155268902481402, 'energy_units': 'keV', 'wavelength_units': 'angstrom', 'wavelength_PV': 'gp:BraggLambdaRdbkAO', 'energy_PV': 'gp:BraggERdbkAO'}\n", "h=0, k=0, l=0\n", "theta=0, chi=0, phi=0, ttheta=0\n" ] } ], "source": [ "fourc.wh(full=True)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Hklpy2DiffractometerRealPos(theta=-37.427950523067, chi=-1.3100774e-05, phi=-90.000002713098, ttheta=-74.855901046133)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fourc.forward(1, 0, 0) # Shows the default choice." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[Hklpy2DiffractometerRealPos(theta=-37.427950303513, chi=-1.3030092e-05, phi=-90.000002721039, ttheta=-74.855900607027),\n", " Hklpy2DiffractometerRealPos(theta=37.427950303513, chi=1.3030092e-05, phi=89.999997278961, ttheta=74.855900607027),\n", " Hklpy2DiffractometerRealPos(theta=-142.572049696487, chi=-1.3030092e-05, phi=-90.000002721039, ttheta=74.855900607027),\n", " Hklpy2DiffractometerRealPos(theta=-37.427950303513, chi=-179.999986969908, phi=89.999997278961, ttheta=-74.855900607027),\n", " Hklpy2DiffractometerRealPos(theta=37.427950303513, chi=179.999986969908, phi=-90.000002721039, ttheta=74.855900607027),\n", " Hklpy2DiffractometerRealPos(theta=-142.572049696487, chi=-179.999986969908, phi=89.999997278961, ttheta=74.855900607027)]" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fourc.core.forward(dict(h=1, k=0, l=0)) # Shows ALL the possibilities." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'h': 0.822688693552, 'k': -1.8798e-07, 'l': -3.8844e-08}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fourc.core.inverse(dict(ttheta=60, theta=30, chi=0, phi=90))" ] } ], "metadata": { "kernelspec": { "display_name": "hklpy2", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.2" } }, "nbformat": 4, "nbformat_minor": 2 }