-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Labels
hklpy2For hklpy2For hklpy2
Milestone
Description
@rodolakis suggests:
cahkl(): would be nice to catch errors (like cahkl_table does) to tell you that the reflection is unreachable
Presently, it raises anUnreachableError exception.
Details
cahkl(4,0,0)
>
/
Name
Last Modified
import gi
gi.require_version('Hkl', '5.0')
from hkl.geometries import SimulatedE4CV
from hkl.user import *
fourc = SimulatedE4CV("", name="fourc")
select_diffractometer(fourc)
pa()
===================== ====================================================================
term value
===================== ====================================================================
diffractometer fourc
geometry E4CV
class SimulatedE4CV
energy (keV) 8.05092
wavelength (angstrom) 1.54000
calc engine hkl
mode bissector
positions ===== =======
name value
===== =======
omega 0.00000
chi 0.00000
phi 0.00000
tth 0.00000
===== =======
constraints ===== ========= ========== ===== ====
axis low_limit high_limit value fit
===== ========= ========== ===== ====
omega -180.0 180.0 0.0 True
chi -180.0 180.0 0.0 True
phi -180.0 180.0 0.0 True
tth -180.0 180.0 0.0 True
===== ========= ========== ===== ====
sample: main ================ ===================================================
term value
================ ===================================================
unit cell edges a=1.54, b=1.54, c=1.54
unit cell angles alpha=90.0, beta=90.0, gamma=90.0
[U] [[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
[UB] [[ 4.07999046e+00 -2.49827363e-16 -2.49827363e-16]
[ 0.00000000e+00 4.07999046e+00 -2.49827363e-16]
[ 0.00000000e+00 0.00000000e+00 4.07999046e+00]]
================ ===================================================
===================== ====================================================================
# add the sample to the calculation engine
a0 = 5.431
fourc.calc.new_sample("silicon", (a0, a0, a0, 90, 90, 90))
HklSample(name='silicon', lattice=LatticeTuple(a=1.54, b=1.54, c=1.54, alpha=90.0, beta=90.0, gamma=90.0), ux=Parameter(name='None (internally: ux)', limits=(min=-180.0, max=180.0), value=0.0, fit=True, inverted=False, units='Degree'), uy=Parameter(name='None (internally: uy)', limits=(min=-180.0, max=180.0), value=0.0, fit=True, inverted=False, units='Degree'), uz=Parameter(name='None (internally: uz)', limits=(min=-180.0, max=180.0), value=0.0, fit=True, inverted=False, units='Degree'), U=array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]]), UB=array([[ 4.07999046e+00, -2.49827363e-16, -2.49827363e-16],
[ 0.00000000e+00, 4.07999046e+00, -2.49827363e-16],
[ 0.00000000e+00, 0.00000000e+00, 4.07999046e+00]]), reflections=[])
r_400 = fourc.calc.sample.add_reflection(
4, 0, 0,
position=fourc.calc.Position(
tth=69.0966,
omega=-145.451,
chi=0,
phi=0,
)
)
r_040 = fourc.calc.sample.add_reflection(
0, 4, 0,
position=fourc.calc.Position(
tth=69.0966,
omega=-145.451,
chi=90,
phi=0,
)
)
fourc.calc.sample.compute_UB(r_400, r_040)
array([[-4.98464869e-05, -4.98464869e-05, -4.07999046e+00],
[ 0.00000000e+00, -4.07999046e+00, 4.98464869e-05],
[-4.07999046e+00, 6.08989971e-10, 4.98464869e-05]])
pa()
===================== ===========================================================================
term value
===================== ===========================================================================
diffractometer fourc
geometry E4CV
class SimulatedE4CV
energy (keV) 8.05092
wavelength (angstrom) 1.54000
calc engine hkl
mode bissector
positions ===== =======
name value
===== =======
omega 0.00000
chi 0.00000
phi 0.00000
tth 0.00000
===== =======
constraints ===== ========= ========== ===== ====
axis low_limit high_limit value fit
===== ========= ========== ===== ====
omega -180.0 180.0 0.0 True
chi -180.0 180.0 0.0 True
phi -180.0 180.0 0.0 True
tth -180.0 180.0 0.0 True
===== ========= ========== ===== ====
sample: silicon ================= =========================================================
term value
================= =========================================================
unit cell edges a=1.54, b=1.54, c=1.54
unit cell angles alpha=90.0, beta=90.0, gamma=90.0
ref 1 (hkl) h=4.0, k=0.0, l=0.0
ref 1 positioners omega=-145.45100, chi=0.00000, phi=0.00000, tth=69.09660
ref 2 (hkl) h=0.0, k=4.0, l=0.0
ref 2 positioners omega=-145.45100, chi=90.00000, phi=0.00000, tth=69.09660
[U] [[-1.22173048e-05 -1.22173048e-05 -1.00000000e+00]
[ 0.00000000e+00 -1.00000000e+00 1.22173048e-05]
[-1.00000000e+00 1.49262536e-10 1.22173048e-05]]
[UB] [[-4.98464869e-05 -4.98464869e-05 -4.07999046e+00]
[ 0.00000000e+00 -4.07999046e+00 4.98464869e-05]
[-4.07999046e+00 6.08989971e-10 4.98464869e-05]]
================= =========================================================
===================== ===========================================================================
import hkl
print(f"{hkl.__version__ = }")
hkl.__version__ = '0.3.16'
cahkl(4,0,0)
---------------------------------------------------------------------------
Error Traceback (most recent call last)
~/.conda/envs/bluesky_2021_2/lib/python3.8/site-packages/hkl/engine.py in pseudo_positions(self, values)
233 try:
--> 234 geometry_list = self._engine.pseudo_axis_values_set(values, self._units)
235 except GLib.GError as ex:
Error: hkl-mode-auto-error-quark: none of the functions were solved !!! (0)
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
~/.conda/envs/bluesky_2021_2/lib/python3.8/site-packages/hkl/calc.py in forward_iter(self, start, end, max_iters, threshold, decision_fcn)
533 try:
--> 534 self.engine.pseudo_positions = end
535 return self.engine.solutions
~/.conda/envs/bluesky_2021_2/lib/python3.8/site-packages/hkl/engine.py in pseudo_positions(self, values)
235 except GLib.GError as ex:
--> 236 raise ValueError("Calculation failed (%s)" % ex)
237
ValueError: Calculation failed (hkl-mode-auto-error-quark: none of the functions were solved !!! (0))
During handling of the above exception, another exception occurred:
UnreachableError Traceback (most recent call last)
<ipython-input-10-4d4059620025> in <module>
----> 1 cahkl(4,0,0)
~/.conda/envs/bluesky_2021_2/lib/python3.8/site-packages/hkl/user.py in cahkl(h, k, l)
74 _check_geom_selected()
75 # TODO: make certain this will not move the motors!
---> 76 return _geom_.forward(h, k, l)
77
78
~/.local/lib/python3.8/site-packages/ophyd/pseudopos.py in wrapped(self, *args, **kwargs)
186 pos, new_kwargs = m(*args, **kwargs)
187
--> 188 return method(self, pos, **new_kwargs)
189
190 return wrapped
~/.conda/envs/bluesky_2021_2/lib/python3.8/site-packages/hkl/diffract.py in forward(self, pseudo)
361 @pseudo_position_argument
362 def forward(self, pseudo):
--> 363 solutions = self.calc.forward_iter(start=self.position, end=pseudo, max_iters=100)
364 logger.debug("pseudo to real: %s", solutions)
365 return self._decision_fcn(pseudo, solutions)
~/.conda/envs/bluesky_2021_2/lib/python3.8/site-packages/hkl/calc.py in wrapped(self, *args, **kwargs)
69 initial_pos = self.physical_positions
70 try:
---> 71 return func(self, *args, **kwargs)
72 finally:
73 self.physical_positions = initial_pos
~/.conda/envs/bluesky_2021_2/lib/python3.8/site-packages/hkl/calc.py in forward_iter(self, start, end, max_iters, threshold, decision_fcn)
535 return self.engine.solutions
536 except ValueError:
--> 537 raise UnreachableError(
538 f"Unable to solve. iterations={iters}/{max_iters}\n"
539 f"Last valid position: {valid_pseudo}\n{valid_real} ",
UnreachableError: Unable to solve. iterations=100/100
Last valid position: [2.000000024214387, 0.0, 0.0]
PosCalcE4CV(omega=-89.99992012214125, chi=2.855295202578513e-33, phi=0.0007000001047290803, tth=-179.9998402442825) Metadata
Metadata
Assignees
Labels
hklpy2For hklpy2For hklpy2