示例#1
0
    def testAnglesToHkl(self):
        mockUbcalc = createMockUbcalc(
            matrix(self.sess.umatrix) * matrix(self.sess.bmatrix))

        self.ac = VliegHklCalculator(mockUbcalc,
                                     createMockDiffractometerGeometry(),
                                     createMockHardwareMonitor())
        self.ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True

        # Check the two given reflections
        (hklactual1, params) = self.ac.anglesToHkl(self.sess.ref1.pos,
                                                   self.sess.ref1.wavelength)
        del params
        (hklactual2, params) = self.ac.anglesToHkl(self.sess.ref2.pos,
                                                   self.sess.ref2.wavelength)
        mneq_(matrix([hklactual1]), matrix([self.sess.ref1calchkl]), 3)
        mneq_(matrix([hklactual2]), matrix([self.sess.ref2calchkl]), 3)

        # ... znd in each calculation through the hkl/posiiont pairs
        if self.calc:
            for hkl, pos, param in zip(self.calc.hklList, self.calc.posList,
                                       self.calc.paramList):
                (hkl_actual,
                 params) = self.ac.anglesToHkl(pos, self.calc.wavelength)
                note = ("wrong hkl calcualted for scenario.name=%s, "
                        "calculation.tag=%s\n  expected hkl=(%f,%f,%f)\n"
                        "calculated hkl=(%f,%f,%f)" %
                        (self.sess.name, self.calc.tag, hkl[0], hkl[1], hkl[2],
                         hkl_actual[0], hkl_actual[1], hkl_actual[2]))
                mneq_(matrix([hkl_actual]), matrix([hkl]), 3, note=note)
                print "***anglesToHkl***"
                print "*** ", str(hkl), " ***"
                print params
                print param
示例#2
0
    def testAnglesToHkl(self):
        mockUbcalc = createMockUbcalc(
            matrix(self.sess.umatrix) * matrix(self.sess.bmatrix))

        self.ac = VliegHklCalculator(mockUbcalc,
                                     createMockDiffractometerGeometry(),
                                     createMockHardwareMonitor())
        self.ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True

        # Check the two given reflections
        (hklactual1, params) = self.ac.anglesToHkl(self.sess.ref1.pos,
                                                   self.sess.ref1.wavelength)
        del params
        (hklactual2, params) = self.ac.anglesToHkl(self.sess.ref2.pos,
                                                   self.sess.ref2.wavelength)
        mneq_(matrix([hklactual1]), matrix([self.sess.ref1calchkl]), 3)
        mneq_(matrix([hklactual2]), matrix([self.sess.ref2calchkl]), 3)

        # ... znd in each calculation through the hkl/posiiont pairs
        if self.calc:
            for hkl, pos, param in zip(self.calc.hklList,
                                       self.calc.posList,
                                       self.calc.paramList):
                (hkl_actual, params) = self.ac.anglesToHkl(pos,
                                                        self.calc.wavelength)
                note = ("wrong hkl calcualted for scenario.name=%s, "
                        "calculation.tag=%s\n  expected hkl=(%f,%f,%f)\n"
                        "calculated hkl=(%f,%f,%f)" %
                        (self.sess.name, self.calc.tag, hkl[0], hkl[1], hkl[2],
                         hkl_actual[0], hkl_actual[1], hkl_actual[2]))
                mneq_(matrix([hkl_actual]), matrix([hkl]), 3, note=note)
                print "***anglesToHkl***"
                print "*** ", str(hkl), " ***"
                print params
                print param
示例#3
0
    def testHklToAngles(self):
        if self.calc:
            # Configure the angle calculator for this session scenario
            UB = matrix(self.sess.umatrix) * matrix(self.sess.bmatrix)
            mockUbcalc = createMockUbcalc(UB)
            hw = createMockHardwareMonitor()
            settings.geometry = createMockDiffractometerGeometry()
            settings.hardware = hw
            ac = VliegHklCalculator(mockUbcalc)
            ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True

            ## configure the angle calculator for this calculation
            ac.mode_selector.setModeByName(self.calc.modeToTest)

            # Set fixed parameters
            if self.calc.modeToTest in ('4cBeq', '4cFixedw'):

                #ac.setParameter('alpha', self.calc.alpha )
                ac.parameter_manager.setTrackParameter('alpha', True)
                hw.get_position.return_value = 888, self.calc.alpha, 999
                ac.parameter_manager.set_constraint('gamma', self.calc.gamma)

            # Test each hkl/position pair
            for idx in range(len(self.calc.hklList)):
                hkl = self.calc.hklList[idx]
                expectedpos = self.calc.posList[idx]
                (pos, params) = ac.hklToAngles(hkl[0], hkl[1], hkl[2],
                                               self.calc.wavelength)
                note = ("wrong positions calculated for TestScenario=%s, "
                        "AngleTestScenario=%s, hkl=(%f,%f,%f):\n"
                        "  expected pos=%s;\n"
                        "  returned pos=%s " %
                        (self.sess.name, self.calc.tag, hkl[0], hkl[1], hkl[2],
                         str(expectedpos), str(pos)))
                assert pos.nearlyEquals(expectedpos, 0.01), note
                print "*** hklToAngles ***"
                print "*** ", str(hkl), " ***"
                print params
                try:
                    print self.calc.paramList[idx]
                except IndexError:  # Not always specified
                    pass
示例#4
0
    def testHklToAngles(self):
        if self.calc:
            # Configure the angle calculator for this session scenario
            UB = matrix(self.sess.umatrix) * matrix(self.sess.bmatrix)
            mockUbcalc = createMockUbcalc(UB)
            hw = createMockHardwareMonitor()
            ac = VliegHklCalculator(mockUbcalc,
                                    createMockDiffractometerGeometry(), hw)
            ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True

            ## configure the angle calculator for this calculation
            ac.mode_selector.setModeByName(self.calc.modeToTest)

            # Set fixed parameters
            if self.calc.modeToTest in ('4cBeq', '4cFixedw'):

                #ac.setParameter('alpha', self.calc.alpha )
                ac.parameter_manager.setTrackParameter('alpha', True)
                hw.get_position.return_value = 888, self.calc.alpha, 999
                ac.parameter_manager.set_constraint('gamma', self.calc.gamma)

            # Test each hkl/position pair
            for idx in range(len(self.calc.hklList)):
                hkl = self.calc.hklList[idx]
                expectedpos = self.calc.posList[idx]
                (pos, params) = ac.hklToAngles(hkl[0], hkl[1], hkl[2],
                                               self.calc.wavelength)
                note = ("wrong positions calculated for TestScenario=%s, "
                        "AngleTestScenario=%s, hkl=(%f,%f,%f):\n"
                        "  expected pos=%s;\n"
                        "  returned pos=%s " %
                        (self.sess.name, self.calc.tag, hkl[0], hkl[1], hkl[2],
                         str(expectedpos), str(pos)))
                assert pos.nearlyEquals(expectedpos, 0.01), note
                print "*** hklToAngles ***"
                print "*** ", str(hkl), " ***"
                print params
                try:
                    print self.calc.paramList[idx]
                except IndexError:  # Not always specified
                    pass
示例#5
0
 def setup_method(self):
     from diffcalc import settings
     settings.geometry = SixCircleGammaOnArmGeometry()
     dummy = 'alpha', 'delta', 'gamma', 'omega', 'chi', 'phi'
     settings.hardware = DummyHardwareAdapter(dummy)
     self.mock_ubcalc = Mock(spec=UBCalculation)
     self.hklcalc = VliegHklCalculator(self.mock_ubcalc, True)
     settings.ubcalc_persister = UbCalculationNonPersister()
     
     from diffcalc.hkl.vlieg import hkl
     reload(hkl)
     hkl.hklcalc = self.hklcalc
     self.hkl = hkl
     prepareRawInput([])
示例#6
0
 def setup_method(self):
     self.ac = VliegHklCalculator(None, createMockDiffractometerGeometry(),
                                  createMockHardwareMonitor())
     self.ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True
     self.setSessionAndCalculation()
示例#7
0
class BaseTestHklCalculator():

    def setSessionAndCalculation(self):
        raise Exception("Abstract")

    def setup_method(self):
        self.ac = VliegHklCalculator(None, createMockDiffractometerGeometry(),
                                     createMockHardwareMonitor())
        self.ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True
        self.setSessionAndCalculation()

    def testAnglesToHkl(self):
        mockUbcalc = createMockUbcalc(
            matrix(self.sess.umatrix) * matrix(self.sess.bmatrix))

        self.ac = VliegHklCalculator(mockUbcalc,
                                     createMockDiffractometerGeometry(),
                                     createMockHardwareMonitor())
        self.ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True

        # Check the two given reflections
        (hklactual1, params) = self.ac.anglesToHkl(self.sess.ref1.pos,
                                                   self.sess.ref1.wavelength)
        del params
        (hklactual2, params) = self.ac.anglesToHkl(self.sess.ref2.pos,
                                                   self.sess.ref2.wavelength)
        mneq_(matrix([hklactual1]), matrix([self.sess.ref1calchkl]), 3)
        mneq_(matrix([hklactual2]), matrix([self.sess.ref2calchkl]), 3)

        # ... znd in each calculation through the hkl/posiiont pairs
        if self.calc:
            for hkl, pos, param in zip(self.calc.hklList,
                                       self.calc.posList,
                                       self.calc.paramList):
                (hkl_actual, params) = self.ac.anglesToHkl(pos,
                                                        self.calc.wavelength)
                note = ("wrong hkl calcualted for scenario.name=%s, "
                        "calculation.tag=%s\n  expected hkl=(%f,%f,%f)\n"
                        "calculated hkl=(%f,%f,%f)" %
                        (self.sess.name, self.calc.tag, hkl[0], hkl[1], hkl[2],
                         hkl_actual[0], hkl_actual[1], hkl_actual[2]))
                mneq_(matrix([hkl_actual]), matrix([hkl]), 3, note=note)
                print "***anglesToHkl***"
                print "*** ", str(hkl), " ***"
                print params
                print param

    def testHklToAngles(self):
        if self.calc:
            # Configure the angle calculator for this session scenario
            UB = matrix(self.sess.umatrix) * matrix(self.sess.bmatrix)
            mockUbcalc = createMockUbcalc(UB)
            hw = createMockHardwareMonitor()
            ac = VliegHklCalculator(mockUbcalc,
                                    createMockDiffractometerGeometry(), hw)
            ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True

            ## configure the angle calculator for this calculation
            ac.mode_selector.setModeByName(self.calc.modeToTest)

            # Set fixed parameters
            if self.calc.modeToTest in ('4cBeq', '4cFixedw'):

                #ac.setParameter('alpha', self.calc.alpha )
                ac.parameter_manager.setTrackParameter('alpha', True)
                hw.get_position.return_value = 888, self.calc.alpha, 999
                ac.parameter_manager.set_constraint('gamma', self.calc.gamma)

            # Test each hkl/position pair
            for idx in range(len(self.calc.hklList)):
                hkl = self.calc.hklList[idx]
                expectedpos = self.calc.posList[idx]
                (pos, params) = ac.hklToAngles(hkl[0], hkl[1], hkl[2],
                                               self.calc.wavelength)
                note = ("wrong positions calculated for TestScenario=%s, "
                        "AngleTestScenario=%s, hkl=(%f,%f,%f):\n"
                        "  expected pos=%s;\n"
                        "  returned pos=%s " %
                        (self.sess.name, self.calc.tag, hkl[0], hkl[1], hkl[2],
                         str(expectedpos), str(pos)))
                assert pos.nearlyEquals(expectedpos, 0.01), note
                print "*** hklToAngles ***"
                print "*** ", str(hkl), " ***"
                print params
                try:
                    print self.calc.paramList[idx]
                except IndexError:  # Not always specified
                    pass
示例#8
0
 def setup_method(self):
     self.ac = VliegHklCalculator(None, createMockDiffractometerGeometry(),
                                  createMockHardwareMonitor())
     self.ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True
     self.setSessionAndCalculation()
示例#9
0
class BaseTestHklCalculator():
    def setSessionAndCalculation(self):
        raise Exception("Abstract")

    def setup_method(self):
        self.ac = VliegHklCalculator(None, createMockDiffractometerGeometry(),
                                     createMockHardwareMonitor())
        self.ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True
        self.setSessionAndCalculation()

    def testAnglesToHkl(self):
        mockUbcalc = createMockUbcalc(
            matrix(self.sess.umatrix) * matrix(self.sess.bmatrix))

        self.ac = VliegHklCalculator(mockUbcalc,
                                     createMockDiffractometerGeometry(),
                                     createMockHardwareMonitor())
        self.ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True

        # Check the two given reflections
        (hklactual1, params) = self.ac.anglesToHkl(self.sess.ref1.pos,
                                                   self.sess.ref1.wavelength)
        del params
        (hklactual2, params) = self.ac.anglesToHkl(self.sess.ref2.pos,
                                                   self.sess.ref2.wavelength)
        mneq_(matrix([hklactual1]), matrix([self.sess.ref1calchkl]), 3)
        mneq_(matrix([hklactual2]), matrix([self.sess.ref2calchkl]), 3)

        # ... znd in each calculation through the hkl/posiiont pairs
        if self.calc:
            for hkl, pos, param in zip(self.calc.hklList, self.calc.posList,
                                       self.calc.paramList):
                (hkl_actual,
                 params) = self.ac.anglesToHkl(pos, self.calc.wavelength)
                note = ("wrong hkl calcualted for scenario.name=%s, "
                        "calculation.tag=%s\n  expected hkl=(%f,%f,%f)\n"
                        "calculated hkl=(%f,%f,%f)" %
                        (self.sess.name, self.calc.tag, hkl[0], hkl[1], hkl[2],
                         hkl_actual[0], hkl_actual[1], hkl_actual[2]))
                mneq_(matrix([hkl_actual]), matrix([hkl]), 3, note=note)
                print "***anglesToHkl***"
                print "*** ", str(hkl), " ***"
                print params
                print param

    def testHklToAngles(self):
        if self.calc:
            # Configure the angle calculator for this session scenario
            UB = matrix(self.sess.umatrix) * matrix(self.sess.bmatrix)
            mockUbcalc = createMockUbcalc(UB)
            hw = createMockHardwareMonitor()
            ac = VliegHklCalculator(mockUbcalc,
                                    createMockDiffractometerGeometry(), hw)
            ac.raiseExceptionsIfAnglesDoNotMapBackToHkl = True

            ## configure the angle calculator for this calculation
            ac.mode_selector.setModeByName(self.calc.modeToTest)

            # Set fixed parameters
            if self.calc.modeToTest in ('4cBeq', '4cFixedw'):

                #ac.setParameter('alpha', self.calc.alpha )
                ac.parameter_manager.setTrackParameter('alpha', True)
                hw.get_position.return_value = 888, self.calc.alpha, 999
                ac.parameter_manager.set_constraint('gamma', self.calc.gamma)

            # Test each hkl/position pair
            for idx in range(len(self.calc.hklList)):
                hkl = self.calc.hklList[idx]
                expectedpos = self.calc.posList[idx]
                (pos, params) = ac.hklToAngles(hkl[0], hkl[1], hkl[2],
                                               self.calc.wavelength)
                note = ("wrong positions calculated for TestScenario=%s, "
                        "AngleTestScenario=%s, hkl=(%f,%f,%f):\n"
                        "  expected pos=%s;\n"
                        "  returned pos=%s " %
                        (self.sess.name, self.calc.tag, hkl[0], hkl[1], hkl[2],
                         str(expectedpos), str(pos)))
                assert pos.nearlyEquals(expectedpos, 0.01), note
                print "*** hklToAngles ***"
                print "*** ", str(hkl), " ***"
                print params
                try:
                    print self.calc.paramList[idx]
                except IndexError:  # Not always specified
                    pass
示例#10
0
文件: hkl.py 项目: jackey-qiu/DaFy
###

from diffcalc.hkl.common import getNameFromScannableOrString
from diffcalc.util import command
from diffcalc import settings


from diffcalc.ub import ub
from diffcalc.hkl.vlieg.calc import VliegHklCalculator


__all__ = ['hklmode', 'setpar', 'trackalpha', 'trackgamma', 'trackphi',
           'parameter_manager', 'hklcalc']


hklcalc = VliegHklCalculator(ub.ubcalc)

parameter_manager = hklcalc.parameter_manager

def __str__(self):
    return hklcalc.__str__()

@command
def hklmode(num=None):
    """hklmode {num} -- changes mode or shows current and available modes and all settings""" #@IgnorePep8

    if num is None:
        print hklcalc.__str__()
    else:
        hklcalc.mode_selector.setModeByIndex(int(num))
        pm = hklcalc.parameter_manager
示例#11
0
文件: hkl.py 项目: jamesmudd/diffcalc
###

from diffcalc.hkl.common import getNameFromScannableOrString
from diffcalc.util import command
from diffcalc import settings


from diffcalc.ub import ub
from diffcalc.hkl.vlieg.calc import VliegHklCalculator


__all__ = ['hklmode', 'setpar', 'trackalpha', 'trackgamma', 'trackphi',
           'parameter_manager', 'hklcalc']


hklcalc = VliegHklCalculator(ub.ubcalc, settings.geometry, settings.hardware)

parameter_manager = hklcalc.parameter_manager

def __str__(self):
    return hklcalc.__str__()

@command
def hklmode(num=None):
    """hklmode {num} -- changes mode or shows current and available modes and all settings""" #@IgnorePep8

    if num is None:
        print hklcalc.__str__()
    else:
        hklcalc.mode_selector.setModeByIndex(int(num))
        pm = hklcalc.parameter_manager