Skip to content

Commit

Permalink
ENH #426 K4CV
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Sep 27, 2020
1 parent 234c550 commit 326f994
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
42 changes: 42 additions & 0 deletions apstools/diffractometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
~DiffractometerMixin
~SoftE4CV
~SoftE6C
~SoftK4CV
"""

Expand All @@ -25,6 +26,7 @@
'DiffractometerMixin',
'SoftE4CV',
'SoftE6C',
'SoftK4CV',
]

from ophyd import Component, Device, PseudoSingle, SoftPositioner
Expand Down Expand Up @@ -261,3 +263,43 @@ def __init__(self, *args, **kwargs):

for axis in self.real_positioners:
axis.move(0)


class SoftK4CV(DiffractometerMixin, hkl.diffract.K4CV):
"""
K4CV: Simulated (soft) kappa as 4-circle diffractometer
EXAMPLE::
simk4c = SoftK4CV('', name='simk4c')
"""

h = Component(PseudoSingle, '',
labels=("hkl", "simk4c"), kind="hinted")
k = Component(PseudoSingle, '',
labels=("hkl", "simk4c"), kind="hinted")
l = Component(PseudoSingle, '',
labels=("hkl", "simk4c"), kind="hinted")

komega = Component(SoftPositioner,
labels=("motor", "simk4c"), kind="hinted")
kappa = Component(SoftPositioner,
labels=("motor", "simk4c"), kind="hinted")
kphi = Component(SoftPositioner,
labels=("motor", "simk4c"), kind="hinted")
tth = Component(SoftPositioner,
labels=("motor", "simk4c"), kind="hinted")

def __init__(self, *args, **kwargs):
"""
start the SoftPositioner objects with initial values
Since this diffractometer uses simulated motors,
prime the SoftPositioners (motors) with initial values.
Otherwise, with position == None, then describe(), and
other functions get borked.
"""
super().__init__(*args, **kwargs)

for axis in self.real_positioners:
axis.move(0)
34 changes: 34 additions & 0 deletions tests/test_diffractometer.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,40 @@ def test_sim6c_wh(self):
for r, e in zip(received, expected):
self.assertEqual(r, e)

def test_simk4c(self):
simk4c = APS_diffractometer.SoftK4CV('', name='simk4c')
self.assertIsNotNone(simk4c)
self.assertEqual(simk4c.komega.position, 0)
self.assertEqual(simk4c.h.position, 0)
self.assertEqual(simk4c.k.position, 0)
self.assertEqual(simk4c.l.position, 0)
self.assertEqual(
simk4c.calc.physical_axis_names,
['komega', 'kappa', 'kphi', 'tth'])

def test_simk4c_wh(self):
simk4c = APS_diffractometer.SoftK4CV('', name='simk4c')
tbl = simk4c.wh(printing=False)
received = str(tbl).splitlines()
expected = [
"===================== =========",
"term value ",
"===================== =========",
"diffractometer simk4c ",
"mode bissector",
"wavelength (angstrom) 1.54 ",
"h 0.0 ",
"k 0.0 ",
"l 0.0 ",
"komega 0 ",
"kappa 0 ",
"kphi 0 ",
"tth 0 ",
"===================== =========",
]
for r, e in zip(received, expected):
self.assertEqual(r, e)


def suite(*args, **kw):
test_list = [
Expand Down

0 comments on commit 326f994

Please sign in to comment.