Ejemplo n.º 1
0
    def testAddorient(self):
        with pytest.raises(TypeError):
            self.ub.addorient(1)
        with pytest.raises(TypeError):
            self.ub.addorient(1, 2)
        with pytest.raises(TypeError):
            self.ub.addorient(1, 2, 'blarghh')
        # start new ubcalc
        self.ub.newub('testing_addorient')
        orientlist = self.ub.ubcalc._state.orientlist  # for convenience

        hkl1 = [1.1, 1.2, 1.3]
        hkl2 = [2.1, 2.2, 2.3]
        orient1 = [1.4, 1.5, 1.6]
        orient2 = [2.4, 2.5, 2.6]
        #
        self.ub.addorient(hkl1, orient1)
        result = orientlist.getOrientation(1)
        trans_orient1 = self.t_matrix.I * matrix([orient1]).T
        eq_(result[0], hkl1)
        mneq_(matrix([result[1]]), trans_orient1.T)
        eq_(result[2], None)

        self.ub.addorient(hkl2, orient2, 'atag')
        result = orientlist.getOrientation(2)
        trans_orient2 = self.t_matrix.I * matrix([orient2]).T
        eq_(result[0], hkl2)
        mneq_(matrix([result[1]]), trans_orient2.T)
        eq_(result[2], 'atag')
Ejemplo n.º 2
0
    def testSetub(self):
        self.ub.newub('testsetub_custom')
        self.ub.setlat('NaCl', 1.1)
        zrot = xyz_rotation([0, 0 , 1], 30. * TORAD)
        self.ub.setu(zrot.tolist())

        mneq_(self.ub.ubcalc.UB, self.conv.transform(self.zrot) * self.ub.ubcalc._state.crystal.B)
Ejemplo n.º 3
0
    def testOrientub(self):
        with pytest.raises(TypeError):
            self.ub.orientub(1)  # wrong input
        # no ubcalc started:
        with pytest.raises(DiffcalcException):
            self.ub.orientub()
        self.ub.newub('testorientub')
        # not enough orientations:
        with pytest.raises(DiffcalcException):
            self.ub.orientub()

        self.ub.newub('testorientub')
        s = scenarios.sessions(settings.Pos)[1]
        self.ub.setlat(s.name, *s.lattice)
        r1 = s.ref1
        orient1 = self.t_matrix * matrix('1; 0; 0')
        self.ub.addorient((r1.h, r1.k, r1.l), orient1.T.tolist()[0], r1.tag)
        r2 = s.ref2
        orient2 = self.t_matrix * matrix('0; -1; 0')
        self.ub.addorient((r2.h, r2.k, r2.l), orient2.T.tolist()[0], r2.tag)
        self.ub.orientub()
        mneq_(self.ub.ubcalc.UB,
              matrix(s.umatrix) * matrix(s.bmatrix),
              4,
              note="wrong UB matrix after calculating U")
Ejemplo n.º 4
0
    def testAddorientInteractively(self):
        prepareRawInput([])
        # start new ubcalc
        self.ub.newub('testing_addorient')
        orientlist = self.ub.ubcalc._state.orientlist  # for convenience

        hkl1 = [1.1, 1.2, 1.3]
        hkl2 = [2.1, 2.2, 2.3]
        orient1 = [1.4, 1.5, 1.6]
        orient2 = [2.4, 2.5, 2.6]
        #
        prepareRawInput(['1.1', '1.2', '1.3', '1.4', '1.5', '1.6', ''])
        self.ub.addorient()
        result = orientlist.getOrientation(1)
        trans_orient1 = self.t_matrix.I * matrix([orient1]).T
        eq_(result[0], hkl1)
        mneq_(matrix([result[1]]), trans_orient1.T)
        eq_(result[2], None)

        prepareRawInput(['2.1', '2.2', '2.3', '2.4', '2.5', '2.6', 'atag'])
        self.ub.addorient()
        result = orientlist.getOrientation(2)
        trans_orient2 = self.t_matrix.I * matrix([orient2]).T
        eq_(result[0], hkl2)
        mneq_(matrix([result[1]]), trans_orient2.T)
        eq_(result[2], 'atag')
Ejemplo n.º 5
0
    def testSetub(self):
        self.ub.newub('testsetub_custom')
        self.ub.setlat('NaCl', 1.1)
        zrot = xyz_rotation([0, 0, 1], self.t_hand * 30. * TORAD)
        self.ub.setu(zrot.tolist())

        mneq_(self.ub.ubcalc.UB, self.xrot * self.ub.ubcalc._state.crystal.B)
Ejemplo n.º 6
0
    def testCalculateU(self):

        for sess in scenarios.sessions():
            self.setup_method()
            self.ubcalc.start_new('testcalc')
            # Skip this test case unless it contains a umatrix
            if sess.umatrix is None:
                continue

            self.ubcalc.set_lattice(sess.name, *sess.lattice)
            ref1 = sess.ref1
            ref2 = sess.ref2
            t = sess.time
            self.ubcalc.add_reflection(
                ref1.h, ref1.k, ref1.l, ref1.pos, ref1.energy, ref1.tag, t)
            self.ubcalc.add_reflection(
                ref2.h, ref2.k, ref2.l, ref2.pos, ref2.energy, ref2.tag, t)
            self.ubcalc.calculate_UB()
            returned = self.ubcalc.U.tolist()
            print "*Required:"
            print sess.umatrix
            print "*Returned:"
            print returned
            mneq_(self.ubcalc.U, matrix(sess.umatrix), 4,
                  note="wrong U calulated for sess.name=" + sess.name)
Ejemplo n.º 7
0
    def testset_U_manually(self):

        # Test the calculations with U=I
        U = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        for sess in scenarios.sessions():
            self.setup_method()
            self.ubcalc.start_new('testcalc')
            self.ubcalc.set_lattice(sess.name, *sess.lattice)
            self.ubcalc.set_U_manually(U)
            # Check the U matrix
            mneq_(self.ubcalc.U,
                  matrix(U),
                  4,
                  note="wrong U after manually setting U")

            # Check the UB matrix
            if sess.bmatrix is None:
                continue
            print "U: ", U
            print "actual ub: ", self.ubcalc.UB.tolist()
            print " desired b: ", sess.bmatrix
            mneq_(self.ubcalc.UB,
                  matrix(sess.bmatrix),
                  4,
                  note="wrong UB after manually setting U")
Ejemplo n.º 8
0
 def testRefineub(self):
     self.ub.newub('testing_refineub')
     self.ub.setlat('xtal', 1, 1, 1, 90, 90, 90)
     self.ub.setmiscut(0)
     prepareRawInput(['y', 'y'])
     self.ub.refineub([1, 1, 0], [0, 60, 0, 30, 0, 0])
     getLattice = self.ub.ubcalc._state.crystal.getLattice
     eq_(('xtal', sqrt(2.), sqrt(2.), 1, 90, 90, 90), getLattice())
     mneq_(self.ub.ubcalc.U, self._refineub_matrix,
           4, note="wrong U matrix after refinement")
Ejemplo n.º 9
0
 def testRefineubInteractively(self):
     self.ub.newub('testing_refineubinteractive')
     self.ub.setlat('xtal', 1, 1, 1, 90, 90, 90)
     self.ub.setmiscut(0)
     prepareRawInput(['1', '1', '', 'n', '0', '60', '0', '30', '0', '0', 'y', 'y'])
     self.ub.refineub()
     getLattice = self.ub.ubcalc._state.crystal.getLattice
     eq_(('xtal', sqrt(2.), sqrt(2.), 1, 90, 90, 90), getLattice())
     mneq_(self.ub.ubcalc.U, self._refineub_matrix,
           4, note="wrong U matrix after refinement")
Ejemplo n.º 10
0
def test__orientation_phase():
    _orient()
    you.ub()
    you.checkub()
    you.showref()

    U = matrix('1 0 0; 0 1 0; 0 0 1')
    UB = U * 2 * pi
    mneq_(you.ubcalc.U, U)
    mneq_(you.ubcalc.UB, UB)
    def test_orientation_phase(self):
        self._orient()
        ub()
        checkub()
        showref()

        U = matrix('1 0 0; 0 1 0; 0 0 1')
        UB = U * 2 * pi
        mneq_(dc.ub._ubcalc.U, U)
        mneq_(dc.ub._ubcalc.UB, UB)
Ejemplo n.º 12
0
def test__orientation_phase():
    _orient()
    you.ub()
    you.checkub()
    you.showref()

    U = matrix('1 0 0; 0 1 0; 0 0 1')
    UB = U * 2 * pi
    mneq_(you.ubcalc.U, U)
    mneq_(you.ubcalc.UB, UB)
Ejemplo n.º 13
0
def test_orientation_phase():
    # assumes reflections added were ideal (with no mis-mount)
    dc.ub()
    dc.checkub()
    dc.showref()

    U = matrix('1 0 0; 0 1 0; 0 0 1')
    UB = U * 2 * pi
    mneq_(dc._ub.ubcalc.U, U)
    mneq_(dc._ub.ubcalc.UB, UB)
Ejemplo n.º 14
0
 def testRefineubInteractivelyWithHKL(self):
     self.ub.newub('testing_refineubinteractivehkl')
     self.ub.setlat('xtal', 1, 1, 1, 90, 90, 90)
     self.ub.setmiscut(0)
     self.hardware.position = [0, 60, 0, 30, 0, 0]
     prepareRawInput(['y', 'y', 'y'])
     self.ub.refineub([1, 1, 0])
     getLattice = self.ub.ubcalc._state.crystal.getLattice
     eq_(('xtal', sqrt(2.), sqrt(2.), 1, 90, 90, 90), getLattice())
     mneq_(self.ub.ubcalc.U, self._refineub_matrix,
           4, note="wrong U matrix after refinement")
Ejemplo n.º 15
0
 def testGetBMatrix(self):
     # Check the calculated B Matrix
     for sess in scenarios.sessions():
         if sess.bmatrix is None:
             continue
         cut = CrystalUnderTest('tc', *sess.lattice)
         desired = matrix(sess.bmatrix)
         print desired.tolist()
         answer = cut.B
         print answer.tolist()
         note = "Incorrect B matrix calculation for scenario " + sess.name
         mneq_(answer, desired, 4, note=note)
Ejemplo n.º 16
0
 def testGetBMatrix(self):
     # Check the calculated B Matrix
     for sess in scenarios.sessions():
         if sess.bmatrix is None:
             continue
         cut = CrystalUnderTest('tc', *sess.lattice)
         desired = matrix(sess.bmatrix)
         print desired.tolist()
         answer = cut.B
         print answer.tolist()
         note = "Incorrect B matrix calculation for scenario " + sess.name
         mneq_(answer, desired, 4, note=note)
Ejemplo n.º 17
0
    def test_hkl_to_angles(self):
        s = self.sess
        c = self.calc

        ## setup session info
        self.dc.newub(s.name)
        self.dc.setlat(s.name, *s.lattice)
        r = s.ref1
        self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        r = s.ref2
        self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        self.dc.calcub()
        # check the ubcalculation is okay before continuing
        # (useful to check for typos !)
        mneq_(self.dc.ubcalc.UB,
              matrix(s.umatrix) * matrix(s.bmatrix),
              4,
              note="wrong UB matrix after calculating U")

        ## setup calculation info
        self.dc.hklmode(c.modeNumber)
        # Set fixed parameters
        if c.alpha != None:
            self.dc.setpar('alpha', c.alpha)
        if c.gamma != None:
            self.dc.setpar('gamma', c.alpha)

        # Test each hkl/position pair
        for idx in range(len(c.hklList)):
            (h, k, l) = c.hklList[idx]

            expectedangles = \
                self.geometry.internal_position_to_physical_angles(c.posList[idx])
            (angles, params) = self.dc.hkl_to_angles(h, k, l, c.energy)
            expectedAnglesStr = ("%f " * len(expectedangles)) % expectedangles
            anglesString = ("%f " * len(angles)) % angles
            namesString = (("%s " * len(self.hardware.get_axes_names())) %
                           self.hardware.get_axes_names())
            note = ("wrong position calcualted for TestScenario=%s, "
                    "AngleTestScenario=%s, hkl=%f %f %f:\n"
                    "                       { %s }\n"
                    "  expected pos=%s\n  returned pos=%s " %
                    (s.name, c.tag, h, k, l, namesString, expectedAnglesStr,
                     anglesString))
            mneq_(matrix([list(expectedangles)]),
                  matrix([list(angles)]),
                  2,
                  note=note)
            del params
    def test_angles_to_hkl(self):

        self.assertRaises(DiffcalcException, self.d.angles_to_hkl,
                          (1, 2, 3, 4, 5, 6))  # no energy has been set yet
        self.d._hardware.energy = 10
        self.assertRaises(DiffcalcException, self.d.angles_to_hkl,
                          (1, 2, 3, 4, 5, 6))  # no ub calculated yet
        s = self.sess
        c = self.calc

        # setup session info
        self.d.ub.newub(s.name)
        self.d.ub.setlat(s.name, *s.lattice)
        r = s.ref1
        self.d.ub.addref(
            [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        r = s.ref2
        self.d.ub.addref(
            [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        self.d.ub.calcub()

        # check the ubcalculation is okay before continuing
        # (useful to check for typos!)
        mneq_(self.d._ubcalc.UB,
              matrix(s.umatrix) * matrix(s.bmatrix), 4,
              note="wrong UB matrix after calculating U")
        # Test each hkl/position pair
        for idx in range(len(c.hklList)):
            hkl = c.hklList[idx]
            pos = c.posList[idx]
            # 1) specifying energy explicitely
            ((h, k, l), params) = self.d.angles_to_hkl(pos.totuple(), c.energy)
            msg = ("wrong hkl calc for TestScenario=%s, AngleTestScenario"
                   "=%s, pos=%s):\n  expected hkl=%f %f %f\n  returned hkl="
                   "%f %f %f "
                   % (s.name, c.tag, str(pos), hkl[0], hkl[1], hkl[2], h, k, l)
                   )
            self.assert_((abs(h - hkl[0]) < .001) & (abs(k - hkl[1]) < .001)
                         & (abs(l - hkl[2]) < .001), msg)
            # 2) specifying energy via hardware
            self.d._hardware.energy = c.energy
            msg = ("wrong hkl calcualted for TestScenario=%s, "
                   "AngleTestScenario=%s, pos=%s):\n  expected hkl=%f %f %f\n"
                   "  returned hkl=%f %f %f " %
                   (s.name, c.tag, str(pos), hkl[0], hkl[1], hkl[2], h, k, l))
            ((h, k, l), params) = self.d.angles_to_hkl(pos.totuple())
            self.assert_((abs(h - hkl[0]) < .001) & (abs(k - hkl[1]) < .001) &
                         (abs(l - hkl[2]) < .001), msg)
            del params
Ejemplo n.º 19
0
    def test_hkl_to_angles(self):
        s = self.sess
        c = self.calc

        ## setup session info
        self.dc.newub(s.name)
        self.dc.setlat(s.name, *s.lattice)
        r = s.ref1
        self.dc.addref(
            [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        r = s.ref2
        self.dc.addref(
            [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        self.dc.calcub()
        # check the ubcalculation is okay before continuing
        # (useful to check for typos !)
        mneq_(self.dc.ubcalc.UB,
              matrix(s.umatrix) * matrix(s.bmatrix), 4,
              note="wrong UB matrix after calculating U")

        ## setup calculation info
        self.dc.hklmode(c.modeNumber)
        # Set fixed parameters
        if c.alpha != None:
            self.dc.setpar('alpha', c.alpha)
        if c.gamma != None:
            self.dc.setpar('gamma', c.alpha)

        # Test each hkl/position pair
        for idx in range(len(c.hklList)):
            (h, k, l) = c.hklList[idx]

            expectedangles = \
                self.geometry.internal_position_to_physical_angles(c.posList[idx])
            (angles, params) = self.dc.hkl_to_angles(h, k, l, c.energy)
            expectedAnglesStr = ("%f " * len(expectedangles)) % expectedangles
            anglesString = ("%f " * len(angles)) % angles
            namesString = (("%s " * len(self.hardware.get_axes_names()))
                           % self.hardware.get_axes_names())
            note = ("wrong position calcualted for TestScenario=%s, "
                    "AngleTestScenario=%s, hkl=%f %f %f:\n"
                    "                       { %s }\n"
                    "  expected pos=%s\n  returned pos=%s "
                    % (s.name, c.tag, h, k, l, namesString, expectedAnglesStr,
                       anglesString))
            mneq_(matrix([list(expectedangles)]), matrix([list(angles)]), 2,
                  note=note)
            del params
Ejemplo n.º 20
0
 def testRefineubInteractivelyWithPosition(self):
     self.ub.newub('testing_refineubinteractivepos')
     self.ub.setlat('xtal', 1, 1, 1, 90, 90, 90)
     self.ub.setmiscut(0)
     self.hardware.position = [0, 60, 0, 30, 0, 0]
     prepareRawInput(['1', '1', '', 'y', 'y', 'y'])
     self.ub.refineub()
     getLattice = self.ub.ubcalc._state.crystal.getLattice
     eq_(('xtal', sqrt(2.), sqrt(2.), 1, 90, 90, 90), getLattice())
     mneq_(
         self.ub.ubcalc.U,
         matrix(
             '0.70711   0.70711   0.00000; -0.70711   0.70711   0.00000; 0.00000   0.00000   1.00000'
         ),
         4,
         note="wrong U matrix after refinement")
Ejemplo n.º 21
0
    def test_angles_to_hkl(self):
        with pytest.raises(DiffcalcException):
            self.dc.angles_to_hkl((1, 2, 3, 4, 5, 6))  # no energy set
        settings.hardware.energy = 10
        with pytest.raises(DiffcalcException):
            self.dc.angles_to_hkl((1, 2, 3, 4, 5, 6))  # no ub calculated
        s = self.sess
        c = self.calc

        # setup session info
        self.dc.newub(s.name)
        self.dc.setlat(s.name, *s.lattice)
        r = s.ref1
        self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        r = s.ref2
        self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        self.dc.calcub()

        # check the ubcalculation is okay before continuing
        # (useful to check for typos!)
        mneq_(self.dc.ubcalc.UB,
              matrix(s.umatrix) * matrix(s.bmatrix),
              4,
              note="wrong UB matrix after calculating U")
        # Test each hkl/position pair
        for idx in range(len(c.hklList)):
            hkl = c.hklList[idx]
            pos = c.posList[idx]
            # 1) specifying energy explicitely
            ((h, k, l),
             params) = self.dc.angles_to_hkl(pos.totuple(), c.energy)
            msg = ("wrong hkl calc for TestScenario=%s, AngleTestScenario"
                   "=%s, pos=%s):\n  expected hkl=%f %f %f\n  returned hkl="
                   "%f %f %f " %
                   (s.name, c.tag, str(pos), hkl[0], hkl[1], hkl[2], h, k, l))
            assert [h, k, l] == pytest.approx(hkl, abs=.001)
            #             self.assert_((abs(h - hkl[0]) < .001) & (abs(k - hkl[1]) < .001)
            #                          & (abs(l - hkl[2]) < .001), msg)
            # 2) specifying energy via hardware
            settings.hardware.energy = c.energy
            msg = ("wrong hkl calcualted for TestScenario=%s, "
                   "AngleTestScenario=%s, pos=%s):\n  expected hkl=%f %f %f\n"
                   "  returned hkl=%f %f %f " %
                   (s.name, c.tag, str(pos), hkl[0], hkl[1], hkl[2], h, k, l))
            ((h, k, l), params) = self.dc.angles_to_hkl(pos.totuple())
            assert [h, k, l] == pytest.approx(hkl, abs=.001)
            del params
Ejemplo n.º 22
0
    def testSimWithHklAndSixc(self):
        dummyAxes = createDummyAxes(
            ['alpha', 'delta', 'gamma', 'omega', 'chi', 'phi'])
        dummySixcScannableGroup = ScannableGroup('sixcgrp', dummyAxes)
        sixcdevice = DiffractometerScannableGroup(
            'SixCircleGammaOnArmGeometry', self.dc, dummySixcScannableGroup)
        hkldevice = Hkl('hkl', sixcdevice, self.dc)
        with pytest.raises(TypeError):
            sim()
        with pytest.raises(TypeError):
            sim(hkldevice)
        with pytest.raises(TypeError):
            sim(hkldevice, 1, 2, 3)
        with pytest.raises(TypeError):
            sim('not a proper scannable', 1)
        with pytest.raises(TypeError):
            sim(hkldevice, (1, 2, 'not a number'))
        with pytest.raises(TypeError):
            sim(hkldevice, 1)
        with pytest.raises(ValueError):
            sim(hkldevice, (1, 2, 3, 4))

        s = self.sess
        c = self.calc
        # setup session info
        self.dc.newub(s.name)
        self.dc.setlat(s.name, *s.lattice)
        r = s.ref1
        self.dc.addref(
            [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        r = s.ref2
        self.dc.addref(
            [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        self.dc.calcub()

        # check the ubcalculation is okay before continuing
        # (useful to check for typos!)
        mneq_(self.dc.ubcalc.UB,
              (matrix(s.umatrix) * (matrix(s.bmatrix))),
              4, note="wrong UB matrix after calculating U")
        self.hardware.energy = c.energy
        # Test each hkl/position pair
        for idx in range(len(c.hklList)):
            hkl = c.hklList[idx]
            pos = c.posList[idx].totuple()
            sim(sixcdevice, pos)
            sim(hkldevice, hkl)
Ejemplo n.º 23
0
    def testEditOrientInteractively(self):
        hkl1 = [1.1, 1.2, 1.3]
        hkl2 = [1.1, 1.2, 3.1]
        orient1 = [1.4, 1.5, 1.6]
        orient2 = [2.4, 1.5, 2.6]
        orient2s = ['2.4', '', '2.6']
        self.ub.newub('testing_editorient')
        self.ub.addorient(hkl1, orient1, 'tag1')
        prepareRawInput(['1.1', '', '3.1'] + orient2s + ['y', 'newtag',])
        self.ub.editorient(1)

        orientlist = self.ub.ubcalc._state.orientlist
        result = orientlist.getOrientation(1)
        trans_orient2 = self.conv.transform(matrix([orient2]).T)
        eq_(result[0], hkl2)
        mneq_(matrix([result[1]]), trans_orient2.T)
        eq_(result[-2], 'newtag')
Ejemplo n.º 24
0
    def testSimWithHklAndSixc(self):
        dummyAxes = createDummyAxes(
            ['alpha', 'delta', 'gamma', 'omega', 'chi', 'phi'])
        dummySixcScannableGroup = ScannableGroup('sixcgrp', dummyAxes)
        sixcdevice = DiffractometerScannableGroup(
            'SixCircleGammaOnArmGeometry', self.dc, dummySixcScannableGroup)
        hkldevice = Hkl('hkl', sixcdevice, self.dc)
        with pytest.raises(TypeError):
            sim()
        with pytest.raises(TypeError):
            sim(hkldevice)
        with pytest.raises(TypeError):
            sim(hkldevice, 1, 2, 3)
        with pytest.raises(TypeError):
            sim('not a proper scannable', 1)
        with pytest.raises(TypeError):
            sim(hkldevice, (1, 2, 'not a number'))
        with pytest.raises(TypeError):
            sim(hkldevice, 1)
        with pytest.raises(ValueError):
            sim(hkldevice, (1, 2, 3, 4))

        s = self.sess
        c = self.calc
        # setup session info
        self.dc.newub(s.name)
        self.dc.setlat(s.name, *s.lattice)
        r = s.ref1
        self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        r = s.ref2
        self.dc.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        self.dc.calcub()

        # check the ubcalculation is okay before continuing
        # (useful to check for typos!)
        mneq_(self.dc.ubcalc.UB, (matrix(s.umatrix) * (matrix(s.bmatrix))),
              4,
              note="wrong UB matrix after calculating U")
        self.hardware.energy = c.energy
        # Test each hkl/position pair
        for idx in range(len(c.hklList)):
            hkl = c.hklList[idx]
            pos = c.posList[idx].totuple()
            sim(sixcdevice, pos)
            sim(hkldevice, hkl)
Ejemplo n.º 25
0
    def testCalcub(self):
        self.assertRaises(TypeError, self.ubcommands.calcub, 1)  # wrong input
        # no ubcalc started:
        self.assertRaises(DiffcalcException, self.ubcommands.calcub)
        self.ubcommands.newub('testcalcub')
        # not enougth reflections:
        self.assertRaises(DiffcalcException, self.ubcommands.calcub)

        s = scenarios.sessions()[0]
        self.ubcommands.setlat(s.name, *s.lattice)
        r = s.ref1
        self.ubcommands.addref(
            [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        r = s.ref2
        self.ubcommands.addref(
            [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        self.ubcommands.calcub()
        mneq_(self.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix),
              4, note="wrong UB matrix after calculating U")
    def testset_U_manually(self):

        # Test the calculations with U=I
        U = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
        for sess in scenarios.sessions():
            self.setUp()
            self.ubcalc.start_new("testcalc")
            self.ubcalc.set_lattice(sess.name, *sess.lattice)
            self.ubcalc.set_U_manually(U)
            # Check the U matrix
            mneq_(self.ubcalc.U, matrix(U), 4, note="wrong U after manually setting U")

            # Check the UB matrix
            if sess.bmatrix is None:
                continue
            print "U: ", U
            print "actual ub: ", self.ubcalc.UB.tolist()
            print " desired b: ", sess.bmatrix
            mneq_(self.ubcalc.UB, matrix(sess.bmatrix), 4, note="wrong UB after manually setting U")
Ejemplo n.º 27
0
    def testOrientation(self):
        self.dc.newub('cubic')
        self.dc.setlat('cubic', 1, 1, 1)
        self.en(39842 / 1)
        self.dc.sigtau(0, 0)
        self.sixc([0, 90, 0, 45, 45, 0])
        self.dc.addref([1, 0, 1])
        self.sixc([0, 90, 0, 45, 45, 90])
        self.dc.addref([0, 1, 1])
        self.dc.checkub()
        res = self.dc.ubcalc.U
        des = matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        mneq_(res, des, 4)
#         print "***"
#         self.dc.dc()
        print "***"
        self.dc.showref()
        print "***"
        self.dc.hklmode()
        print "***"
Ejemplo n.º 28
0
 def testOrientation(self):
     self.dc.newub('cubic')
     self.dc.setlat('cubic', 1, 1, 1)
     self.en(39842 / 1)
     self.dc.sigtau(0, 0)
     self.sixc([0, 90, 0, 45, 45, 0])
     self.dc.addref([1, 0, 1])
     self.sixc([0, 90, 0, 45, 45, 90])
     self.dc.addref([0, 1, 1])
     self.dc.checkub()
     res = self.dc.ubcalc.U
     des = matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
     mneq_(res, des, 4)
     #         print "***"
     #         self.dc.dc()
     print "***"
     self.dc.showref()
     print "***"
     self.dc.hklmode()
     print "***"
Ejemplo n.º 29
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
Ejemplo n.º 30
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
Ejemplo n.º 31
0
    def testCalcub(self):
        with pytest.raises(TypeError):
            self.ub.calcub(1)  # wrong input
        # no ubcalc started:
        with pytest.raises(DiffcalcException):
            self.ub.calcub()
        self.ub.newub('testcalcub')
        # not enough reflections:
        with pytest.raises(DiffcalcException):
            self.ub.calcub()

        s = scenarios.sessions(settings.Pos)[0]
        self.ub.setlat(s.name, *s.lattice)
        r = s.ref1
        self.ub.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        r = s.ref2
        self.ub.addref([r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
        self.ub.calcub()
        mneq_(self.ub.ubcalc.UB,
              matrix(s.umatrix) * matrix(s.bmatrix),
              4,
              note="wrong UB matrix after calculating U")
Ejemplo n.º 32
0
    def testFitub(self):
        self.ub.newub('testfitub')
        for s in scenarios.sessions(settings.Pos)[-3:]:
            a, b, c, alpha, beta, gamma = s.lattice
            self.ub.clearref()
            for r in s.reflist:
                self.ub.addref(
                    [r.h, r.k, r.l], r.pos.totuple(), r.energy, r.tag)
            self.ub.setlat(s.name, s.system, *s.lattice)
            self.ub.calcub(s.ref1.tag, s.ref2.tag)

            init_latt = (1.06 * a, 1.07 * b, 0.94 * c,
                         1.05 * alpha, 1.06 * beta, 0.95 * gamma)
            self.ub.setlat(s.name, s.system, *init_latt)
            self.ub.addmiscut(3., [0.2, 0.8, 0.1])

            prepareRawInput(['y', 'y'])
            self.ub.fitub(*tuple(r.tag for r in s.reflist))
            assert self.ub.ubcalc._state.crystal._system == s.system
            mneq_(matrix((self.ub.ubcalc._state.crystal.getLattice()[1:])), matrix(s.lattice),
                  2, note="wrong lattice after fitting UB")
            mneq_(self.ub.ubcalc.U, matrix(s.umatrix),
                  3, note="wrong U matrix after fitting UB")
Ejemplo n.º 33
0
 def testMiscut(self):
     self.ub.newub('testsetmiscut')
     self.ub.ubcalc._state.reference._set_n_phi_configured(matrix('0; 0; 1'))
     self.ub.setlat('cube', 1, 1, 1, 90, 90, 90)
     beam_axis = self.conv.transform(matrix('0; 1; 0'), True).T.tolist()[0]
     beam_maxis = self.conv.transform(matrix('0; -1; 0'), True).T.tolist()[0]
     self.ub.setmiscut(self.t_hand * 30, beam_axis)
     mneq_(self.ub.ubcalc._state.reference.n_hkl, matrix('-0.5000000; 0.00000; 0.8660254'))
     self.ub.addmiscut(self.t_hand * 15, beam_axis)
     mneq_(self.ub.ubcalc._state.reference.n_hkl, matrix('-0.7071068; 0.00000; 0.7071068'))
     self.ub.addmiscut(self.t_hand * 45, beam_maxis)
     mneq_(self.ub.ubcalc._state.reference.n_hkl, matrix('0.0; 0.0; 1.0'))
Ejemplo n.º 34
0
 def testMiscut(self):
     self.ub.newub('testsetmiscut')
     self.ub.setlat('cube', 1, 1, 1, 90, 90, 90)
     beam_axis = (self.t_matrix * matrix('0; 1; 0')).T.tolist()[0]
     beam_maxis = (self.t_matrix * matrix('0; -1; 0')).T.tolist()[0]
     self.ub.setmiscut(self.t_hand * 30, beam_axis)
     mneq_(self.ub.ubcalc._state.reference.n_hkl,
           matrix('-0.5000000; 0.00000; 0.8660254'))
     self.ub.addmiscut(self.t_hand * 15, beam_axis)
     mneq_(self.ub.ubcalc._state.reference.n_hkl,
           matrix('-0.7071068; 0.00000; 0.7071068'))
     self.ub.addmiscut(self.t_hand * 45, beam_maxis)
     mneq_(self.ub.ubcalc._state.reference.n_hkl, matrix('0.0; 0.0; 1.0'))
Ejemplo n.º 35
0
    def testOrientub(self):
        with pytest.raises(DiffcalcException):
            self.ub.orientub(1)  # wrong input
        # no ubcalc started:
        with pytest.raises(DiffcalcException):
            self.ub.orientub()
        self.ub.newub('testorientub')
        # not enough orientations:
        with pytest.raises(DiffcalcException):
            self.ub.orientub()

        s = scenarios.sessions(settings.Pos)[1]
        self.ub.setlat(s.name, *s.lattice)
        r1 = s.ref1
        orient1 = self.conv.transform(matrix('1; 0; 0'), True)
        tag1 = 'or'+r1.tag
        self.ub.addorient(
            (r1.h, r1.k, r1.l), orient1.T.tolist()[0], tag1)
        r2 = s.ref2
        orient2 = self.conv.transform(matrix('0; -1; 0'), True)
        tag2 = 'or'+r2.tag
        self.ub.addorient(
            (r2.h, r2.k, r2.l), orient2.T.tolist()[0], tag2)
        self.ub.orientub()
        mneq_(self.ub.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix),
              4, note="wrong UB matrix after calculating U")
        self.ub.orientub(tag1, tag2)
        mneq_(self.ub.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix),
              4, note="wrong UB matrix after calculating U")
        self.ub.addref(
            [r1.h, r1.k, r1.l], r1.pos.totuple(), r1.energy, r1.tag)
        self.ub.orientub(r1.tag, tag2)
        mneq_(self.ub.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix),
              4, note="wrong UB matrix after calculating U")
        self.ub.addref(
            [r2.h, r2.k, r2.l], r2.pos.totuple(), r2.energy, r2.tag)
        self.ub.orientub(tag1, r2.tag)
        mneq_(self.ub.ubcalc.UB, matrix(s.umatrix) * matrix(s.bmatrix),
              4, note="wrong UB matrix after calculating U")
Ejemplo n.º 36
0
 def testCalcUB(self):
     UB = matrix([[2 * pi, 0, 0], [0, 2 * pi, 0], [0, 0, 2 * pi]])
     mneq_(self.scc.UB, UB)
Ejemplo n.º 37
0
 def testInternalPositionToPhysicalAngles(self):
     pos = VliegPosition(1, 2, 3, 4, 5, 6)
     result = self.geometry.internal_position_to_physical_angles(pos)
     mneq_(matrix([pos.totuple()]), matrix([result]), 4)
Ejemplo n.º 38
0
 def testCalcUB(self):
     UB = matrix([[2 * pi, 0, 0], [0, 2 * pi, 0], [0, 0, 2 * pi]])
     mneq_(self.scc.UB, UB)
Ejemplo n.º 39
0
 def testInternalPositionToPhysicalAngles(self):
     pos = VliegPosition(1, 2, 3, 4, 5, 6)
     result = self.geometry.internal_position_to_physical_angles(pos)
     mneq_(matrix([pos.totuple()]), matrix([result]), 4)