Beispiel #1
0
def test_tasAngleBetweenReflections():
    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 #2
0
def test_calcTwoTheta():
    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, ll), res in zip(hkl, result):

        qm = np.linalg.norm(np.dot(B, [h, k, ll]))
        r1 = tasReflection(ki=1.553424,
                           kf=1.553424,
                           qh=h,
                           qk=k,
                           ql=ll,
                           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, ll, tt, res))
            assert False

    try:
        h, k, ll = 10, -10, 10
        qm = np.linalg.norm(np.dot(B, [h, k, ll]))  # HKL is far out of reach
        r1 = tasReflection(ki=1.553424,
                           kf=1.553424,
                           qh=h,
                           qk=k,
                           ql=ll,
                           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
    except RuntimeError:
        assert True
Beispiel #3
0
def test_calcPlaneNormal():
    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))
            assert False
Beispiel #4
0
def test_makeAuxReflection():
    lattice = Cell(12.32, 3.32, 9.8, 92, 91, 120)
    B = lattice.calculateBMatrix()

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

    r1 = tasReflection(ki=ki,
                       kf=ki,
                       qh=h,
                       qk=k,
                       ql=ll,
                       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])
        assert False
    except RuntimeError:
        assert True
Beispiel #5
0
 def _rfl_to_reflection(self, r):
     """convert a reflection from reflection list format to internal
     tasublib format """
     # ei, ef is assumed to be in aux
     ki = energyToK(r[2][0])
     kf = energyToK(r[2][1])
     qe = tasQEPosition(ki, kf, r[0][0], r[0][1], r[0][2], .0)
     angles = tasAngles(0, r[1][0], r[1][1], r[1][2], r[1][3], 0)
     return tasReflection(qe=qe, angles=angles)
Beispiel #6
0
def test_calcTasQAngles():
    # SeCuO3
    latticeSeCuo = Cell(7.725, 8.241, 8.502, 90.0, 99.16, 90.0)
    Ei = 5.0000076

    ki = energyToK(Ei)
    Ef = 4.9221945
    kf = energyToK(Ef)

    r1 = tasReflection(ki=ki,
                       kf=kf,
                       qh=2,
                       qk=1,
                       ql=0,
                       a3=47.841908,
                       sample_two_theta=-71.840689064,
                       sgl=0,
                       sgu=0)
    r2 = tasReflection(ki=ki,
                       kf=kf,
                       qh=2,
                       qk=-1,
                       ql=0,
                       a3=-1.819579944281713,
                       sample_two_theta=-71.840689064,
                       sgl=0,
                       sgu=0)
    UB = calcTasUBFromTwoReflections(latticeSeCuo, r1, r2)
    planeNormal = calcPlaneNormal(r1, r2)

    ss = -1
    a3Off = 0.0
    for (h, k,
         l), a3, a4 in zip([[r1.qh, r1.qk, r1.ql], [r2.qh, r2.qk, r2.ql]],
                           [r1.a3, r2.a3],
                           [r1.sample_two_theta, r2.sample_two_theta]):
        R = tasReflection(ki=ki, kf=kf, qh=h, qk=k, ql=l)
        qm = np.linalg.norm(np.dot(UB, [h, k, l]))

        qe = tasQEPosition(ki, kf, R.qh, R.qk, R.ql, qm=qm)
        angles = calcTasQAngles(UB, planeNormal, ss, a3Off, qe)

        assert (np.isclose(a3, angles.a3))
        assert (np.isclose(a4, angles.sample_two_theta))
Beispiel #7
0
def test_tasReflectionToHC():
    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

    assert (np.all(np.isclose(hc, result)))
Beispiel #8
0
def test_calcTasUVectorFromAngles():
    tR = tasReflection(ki=1.5,
                       kf=2.5,
                       qh=1,
                       qk=2,
                       ql=3,
                       qm=2.0,
                       monochromator_two_theta=72,
                       a3=10.0,
                       sample_two_theta=-60.6,
                       sgu=0.1,
                       sgl=-0.1,
                       analyzer_two_theta=50.0)

    assert (np.all(
        np.isclose(calcTasUVectorFromAngles(tR),
                   np.array([+0.955598330, -0.294664334, +0.002182125]))))
Beispiel #9
0
def test_calcTasUBFromTwoReflections():
    lattices = []
    r1s = []
    r2s = []
    UBs = []

    # YMnO3, Eu
    latticeYMnO3 = Cell(6.11, 6.11, 11.35, 90.0, 90.0, 120.0)
    Ei = 5.0
    ki = energyToK(Ei)
    Ef = 4.96
    kf = energyToK(Ef)

    r1 = tasReflection(ki=ki,
                       kf=kf,
                       qh=0,
                       qk=-1,
                       ql=0,
                       a3=-60,
                       sample_two_theta=-45.23,
                       sgl=0,
                       sgu=0)
    r2 = tasReflection(ki=ki,
                       kf=kf,
                       qh=1,
                       qk=0,
                       ql=0,
                       a3=0,
                       sample_two_theta=-45.23,
                       sgl=0,
                       sgu=0)

    UB = np.array([[0.023387708, -0.150714153, 0.0],
                   [-0.187532612, -0.114020655, -0.0],
                   [0.0, -0.0, -0.088105727]])

    lattices.append(latticeYMnO3)
    r1s.append(r1)
    r2s.append(r2)
    UBs.append(UB)

    # PbTi
    latticePbTi = Cell(9.556, 9.556, 7.014, 90.0, 90.0, 90.0)
    Ei = 5.0000076

    ki = energyToK(Ei)
    Ef = 4.924756

    kf = energyToK(Ef)

    r1 = tasReflection(ki=ki,
                       kf=kf,
                       qh=0,
                       qk=0,
                       ql=2,
                       a3=74.2,
                       sample_two_theta=-71.1594,
                       sgl=0,
                       sgu=0)
    r2 = tasReflection(ki=ki,
                       kf=kf,
                       qh=1,
                       qk=1,
                       ql=2,
                       a3=41.33997,
                       sample_two_theta=-81.6363,
                       sgl=0,
                       sgu=0)

    UB = np.array([[0.06949673, 0.0694967, -0.048957292],
                   [-0.025409263, -0.025409255, -0.13390279],
                   [-0.07399609, 0.07399613, -4.2151984E-9]])

    lattices.append(latticePbTi)
    r1s.append(r1)
    r2s.append(r2)
    UBs.append(UB)

    # SecuO3
    latticeSeCuo = Cell(7.725, 8.241, 8.502, 90.0, 99.16, 90.0)
    Ei = 5.0000076

    ki = energyToK(Ei)
    Ef = 4.9221945
    kf = energyToK(Ef)

    r1 = tasReflection(ki=ki,
                       kf=kf,
                       qh=2,
                       qk=1,
                       ql=0,
                       a3=47.841908,
                       sample_two_theta=-72.0,
                       sgl=0,
                       sgu=0)
    r2 = tasReflection(ki=ki,
                       kf=kf,
                       qh=2,
                       qk=-1,
                       ql=0,
                       a3=-1.8000551,
                       sample_two_theta=-72.0,
                       sgl=0,
                       sgu=0)

    UB = np.array([[0.066903256, -0.10436039, 0.009677114],
                   [-0.11276933, -0.061914437, -0.016311338],
                   [-0.0, 0.0, -0.11761938]])

    lattices.append(latticeSeCuo)
    r1s.append(r1)
    r2s.append(r2)
    UBs.append(UB)

    # SICS
    cellSX = Cell(9.297644, 3.032419, 10.769930, 90., 90., 90.)
    ki = energyToK(5.)
    r1 = tasReflection(ki=ki,
                       kf=ki,
                       qh=2,
                       qk=0,
                       ql=0,
                       a3=-21.92,
                       sample_two_theta=-51.57,
                       sgu=.057,
                       sgl=-.844)
    r2 = tasReflection(ki=ki,
                       kf=ki,
                       qh=0,
                       qk=1,
                       ql=0,
                       a3=52.03,
                       sample_two_theta=-83.659,
                       sgu=.377,
                       sgl=.025)
    UB = np.array([[0.6741724, -.13984819, 0.00833411],
                   [-0.04554178, -2.06723436, -0.0044177],
                   [0.00997698, 0.01365775, -0.5833245]])
    UB /= 2. * np.pi

    lattices.append(cellSX)
    r1s.append(r1)
    r2s.append(r2)
    UBs.append(UB)

    for lat, r1, r2, UBSix in zip(lattices, r1s, r2s, UBs):
        UB = calcTasUBFromTwoReflections(lat, r1, r2)
        assert (np.all(np.isclose(UB, UBSix * 2 * np.pi, atol=1e-6)))
Beispiel #10
0
def test_tasReflection_initialization():
    tR = tasReflection(ki=1.5,
                       kf=2.5,
                       qh=1,
                       qk=2,
                       ql=3,
                       qm=2.0,
                       monochromator_two_theta=72,
                       a3=0.0,
                       sample_two_theta=60.6,
                       sgl=0.1,
                       sgu=-0.1,
                       analyzer_two_theta=50.0)

    for key, val in {
            'ki': 1.5,
            'kf': 2.5,
            'qh': 1,
            'qk': 2,
            'ql': 3,
            'qm': 2.0,
            'monochromator_two_theta': 72,
            'a3': 0.0,
            'sample_two_theta': 60.6,
            'sgl': 0.1,
            'sgu': -0.1,
            'analyzer_two_theta': 50.0
    }.items():
        assert (np.isclose(getattr(tR, key), val))

    qe = tasQEPosition(1.25, 2.0, -3, 2, -0, 1.2)
    angles = tR.angles

    tR2 = tasReflection(qe, angles)

    angles2 = tR2.angles
    qe2 = tR2.qe
    for key in [
            'monochromator_two_theta', 'a3', 'sample_two_theta', 'sgl', 'sgu',
            'analyzer_two_theta'
    ]:
        assert (np.isclose(getattr(angles2, key), getattr(angles, key)))

    for key, val in {
            'ki': 1.25,
            'kf': 2.0,
            'qh': -3,
            'qk': 2,
            'ql': -0,
            'qm': 1.2
    }.items():
        assert (np.isclose(getattr(qe, key), val))
        assert (np.isclose(getattr(qe, key), getattr(qe2, key)))

    # pylint: disable=pointless-statement
    try:
        tR2.notExisting
        assert (False)
    except AttributeError as e:
        str(e)
        assert True