Пример #1
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")
Пример #2
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)
Пример #3
0
    def test__str__(self):
        sess = scenarios.sessions()[0]
        print "***"
        print self.ubcalc.__str__()

        print "***"
        self.ubcalc.start_new('test')
        print self.ubcalc.__str__()

        print "***"
        self.ubcalc.set_lattice(sess.name, *sess.lattice)
        print self.ubcalc.__str__()

        print "***"
        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)
        print self.ubcalc.__str__()

        print "***"
        self.ubcalc.calculate_UB()
        print self.ubcalc.__str__()
Пример #4
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")
Пример #5
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)
Пример #6
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)
    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")
Пример #8
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")
Пример #9
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")
Пример #10
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")
Пример #11
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")
Пример #12
0
 def setSessionAndCalculation(self):
     self.sess = scenarios.sessions()[2]
     self.calc = self.sess.calculations[0]
Пример #13
0
 def setSessionAndCalculation(self):
     self.sess = scenarios.sessions()[0]
     self.calc = None