Beispiel #1
0
def test_calcTwoTheta():
    from cell import Cell
    lattice = Cell(6.11, 6.11, 11.35, 90.0, 90.0, 120.0)
    B = lattice.calculateBMatrix()

    hkl = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [-1, 0, 0], [0, -1, 0], [0, 0, 1],
           [0, 0, -1], [2, -1, 3]]
    result = [
        0.0, 44.93975435373514, 44.93975435373514, 44.93975435373514,
        44.93975435373514, 20.52777682289506, 20.52777682289506,
        116.61092637820377
    ]
    for (h, k, l), res in zip(hkl, result):

        qm = np.linalg.norm(np.dot(B, [h, k, l]))
        r1 = tasReflection(ki=1.553424,
                           kf=1.553424,
                           qh=h,
                           qk=k,
                           ql=l,
                           qm=qm,
                           monochromator_two_theta=74.2,
                           a3=0.0,
                           sample_two_theta=-200,
                           sgu=0.0,
                           sgl=0.0,
                           analyzer_two_theta=74.2)

        tt = calcTwoTheta(B, r1, 1)

        if not np.isclose(tt, res):
            print('Two theta for ({},{},{})={} but expected {}'.format(
                h, k, l, tt, res))  # pragma: no cover
            assert (False)  # pragma: no cover

    try:
        h, k, l = 10, -10, 10
        qm = np.linalg.norm(np.dot(B, [h, k, l]))  # HKL is far out of reach
        r1 = tasReflection(ki=1.553424,
                           kf=1.553424,
                           qh=h,
                           qk=k,
                           ql=l,
                           qm=qm,
                           monochromator_two_theta=74.2,
                           a3=0.0,
                           sample_two_theta=-200,
                           sgu=0.0,
                           sgl=0.0,
                           analyzer_two_theta=74.2)
        tt = calcTwoTheta(B, r1, 1)
        assert False  # pragma: no cover
    except RuntimeError:
        assert True
Beispiel #2
0
def test_tasAngleBetweenReflections():

    from cell import Cell
    lattice = Cell(6.11, 6.11, 11.35, 90.0, 90.0, 120.0)
    B = lattice.calculateBMatrix()

    r1 = tasReflection(qh=1.0, qk=-2.0, ql=0.0)
    r2 = tasReflection(qh=-1.5, qk=1.1, ql=1.0)

    angle = tasAngleBetweenReflections(B, r1, r2)
    assert (np.isclose(angle, 131.993879212))
Beispiel #3
0
def test_calcPlaneNormal():
    from cell import Cell
    lattice = Cell(6.11, 6.11, 11.35, 90.0, 90.0, 120.0)
    B = lattice.calculateBMatrix()

    HKL1 = [[1, 0, 0], [1, 1, 0], [1, 0, 0]]
    HKL2 = [[0, 1, 0], [1, -1, 0], [0, 0, 1]]
    result = [[0, 0, 1], [0, 0, 1], [0, 0, 1]]

    for hkl1, hkl2, res in zip(HKL1, HKL2, result):

        qm = np.linalg.norm(np.dot(B, hkl1))
        r1 = tasReflection(ki=1.553424,
                           kf=1.553424,
                           qh=hkl1[0],
                           qk=hkl1[1],
                           ql=hkl1[2],
                           qm=qm,
                           monochromator_two_theta=74.2,
                           a3=0.0,
                           sample_two_theta=-200,
                           sgu=0.0,
                           sgl=0.0,
                           analyzer_two_theta=74.2)
        tt = calcTwoTheta(B, r1, 1)
        r1.angles.sample_two_theta = tt
        r1.angles.a3 = calcTheta(r1.ki, r1.kf, tt)
        print('r1.a3: ', r1.a3)

        qm = np.linalg.norm(np.dot(B, hkl2))
        r2 = tasReflection(ki=1.553424,
                           kf=1.553424,
                           qh=hkl2[0],
                           qk=hkl2[1],
                           ql=hkl2[2],
                           qm=qm,
                           monochromator_two_theta=74.2,
                           a3=0.0,
                           sample_two_theta=-200,
                           sgu=0.0,
                           sgl=0.0,
                           analyzer_two_theta=74.2)
        tt = calcTwoTheta(B, r2, 1)
        r2.angles.sample_two_theta = tt
        r2.angles.a3 = calcTheta(r2.ki, r2.kf,
                                 tt) + tasAngleBetweenReflections(B, r1, r2)
        print('r2.a3: ', r2.a3)

        planeNormal = calcPlaneNormal(r1, r2)
        if not np.all(np.isclose(planeNormal, res)):
            print('Plane normal for {} and {} = {} but expected {}'.format(
                hkl1, hkl2, planeNormal, res))  # pragma: no cover
            assert False  # pragma: no cover
Beispiel #4
0
def test_tasReflectionToQC():
    r = tasQEPosition(ki=1.5, kf=2.5, qh=1, qk=2, ql=3, qm=2.0)
    from cell import Cell
    lattice = Cell(6.11, 6.11, 11.35, 90.0, 90.0, 120.0)
    B = lattice.calculateBMatrix()

    Q = tasReflectionToQC(r, B)
    assert (np.all(
        np.isclose(
            Q,
            np.array([+0.377970716, +0.327332242, +0.264317181]) * 2 * np.pi))
            )  # 2*pi for convention change
Beispiel #5
0
def test_tasReflectionToHC():
    from cell import Cell

    lattice = Cell(12.32, 3.32, 9.8, 93, 45, 120)
    B = lattice.calculateBMatrix()
    energy = 5.00
    K = energyToK(energy)

    reflection = tasReflection(ki=K, kf=K, qh=2, qk=0, ql=-1)
    hc = tasReflectionToHC(reflection, B)

    result = np.array([+0.434561180, -0.005347733, -0.102040816
                       ]) * 2 * np.pi  # From Six

    assert (np.all(np.isclose(hc, result)))
Beispiel #6
0
def test_makeAuxReflection():
    from cell import Cell
    lattice = Cell(12.32, 3.32, 9.8, 92, 91, 120)
    B = lattice.calculateBMatrix()

    E = 22
    ki = energyToK(E)
    h, k, l = 1, 0, -1
    qm = np.linalg.norm(np.dot(B, [h, k, l]))

    r1 = tasReflection(ki=ki,
                       kf=ki,
                       qh=h,
                       qk=k,
                       ql=l,
                       qm=qm,
                       monochromator_two_theta=74.2,
                       a3=12.2,
                       sgu=0.0,
                       sgl=0.0,
                       analyzer_two_theta=74.2)

    tt = calcTwoTheta(B, r1, -1)
    r1.angles.sample_two_theta = tt

    r2 = makeAuxReflection(B, r1, -1.0, [3, 1, -1])

    assert (np.isclose(r2.a3, 35.875022341))
    assert (np.isclose(r2.sample_two_theta, -64.129182823))

    try:
        r2 = makeAuxReflection(B, r1, -1.0,
                               [30, 1, -1])  # HKL is far out of reach
        assert False  # pragma: no cover
    except RuntimeError:
        assert True