Пример #1
0
    def test_peak_setQSampleFrame(self):
        pws = WorkspaceCreationHelper.createPeaksWorkspace(1, True)
        p = pws.getPeak(0)
        try:
            p.setQSampleFrame(V3D(1, 1, 1))
        except Exception:
            self.fail("Tried setQSampleFrame with one V3D argument")
        self.assertAlmostEquals(p.getQSampleFrame().X(),
                                -1.4976057446828845,
                                places=10)
        self.assertAlmostEquals(p.getQSampleFrame().Y(),
                                0.059904229787315376,
                                places=10)
        self.assertAlmostEquals(p.getQSampleFrame().Z(),
                                1.4400957702126842,
                                places=10)

        try:
            p.setQSampleFrame(V3D(1, 1, 1), 1)
        except Exception:
            self.fail(
                "Tried setQSampleFrame with one V3D argument and a double distance"
            )
        self.assertAlmostEquals(p.getQSampleFrame().X(), 1.0, places=10)
        self.assertAlmostEquals(p.getQSampleFrame().Y(), 1.0, places=10)
        self.assertAlmostEquals(p.getQSampleFrame().Z(), 1.0, places=10)
Пример #2
0
    def create_indexed_peaksworkspace(self, fractional_peaks, qs, hklm):
        """Create a PeaksWorkspace that contains indexed peak data.

        :param fractional_peaks: the peaks workspace containing peaks with
            fractional HKL values.
        :param qs: The set of modulation vectors determined
        :param hklm: the new higher dimensional miller indices to add.
        :returns: a peaks workspace with the indexed peak data
        """
        # pad to 6 columns so we can assume a (hkl) (mnp) layout
        hklm = np.pad(hklm,
                      pad_width=(0, 6 - hklm.shape[1]),
                      mode='constant',
                      constant_values=0)
        indexed = api.CloneWorkspace(fractional_peaks, StoreInADS=False)
        # save modulation vectors. ensure qs has 3 rows
        qs = np.pad(qs,
                    pad_width=((0, 3 - qs.shape[0]), (0, 0)),
                    mode='constant',
                    constant_values=0)
        lattice = fractional_peaks.sample().getOrientedLattice()
        lattice.setModVec1(V3D(*qs[0]))
        lattice.setModVec2(V3D(*qs[1]))
        lattice.setModVec3(V3D(*qs[2]))
        # save indices
        for row, peak in enumerate(indexed):
            row_indices = hklm[row]
            peak.setHKL(*row_indices[:3])
            peak.setIntMNP(V3D(*row_indices[3:]))

        return indexed
Пример #3
0
 def test_that_quaternion_can_be_converted_to_axis_and_angle_for_0_degree(self):
     # Arrange
     angle = 0.0
     axis = V3D(1.0, 0.0, 0.0)
     # There shouldn't be an axis for angle 0
     expected_axis = V3D(0.0, 0.0, 0.0)
     self._do_test_quaternion(angle, axis, expected_axis)
Пример #4
0
 def test_crossprod(self):
     a = V3D(1.0, 0.0, 0.0)
     b = V3D(0.0, 1.0, 0.0)
     c = a.cross_prod(b)
     self.assertAlmostEquals(c.X(), 0.0)
     self.assertAlmostEquals(c.Y(), 0.0)
     self.assertAlmostEquals(c.Z(), 1.0)
Пример #5
0
    def test_getReflectionFamily(self):
        hkl1 = V3D(0, 0, 1)
        hkl2 = V3D(-1, 0, 0)

        pg = PointGroupFactoryImpl.Instance().createPointGroup("m-3m")
        self.assertEquals(pg.getReflectionFamily(hkl1),
                          pg.getReflectionFamily(hkl2))
Пример #6
0
 def test_detector_retrieval(self):
     det = self._test_ws.getDetector(0)
     self.assertTrue(isinstance(det, Detector))
     self.assertEquals(det.getID(), 1)
     self.assertFalse(det.isMasked())
     self.assertAlmostEqual(2.71496516,
                            det.getTwoTheta(V3D(0, 0, 11), V3D(0, 0, 1)))
Пример #7
0
    def structf(self):
        sample_ws = CreateSampleWorkspace()
        LoadCIF(sample_ws, self.cif)
        self.sample = sample_ws.sample().getCrystalStructure()
        self.generator = ReflectionGenerator(self.sample)
        if self.unique == True:
            hkls = self.generator.getUniqueHKLsUsingFilter(
                self.qrange[0], self.qrange[1],
                ReflectionConditionFilter.StructureFactor)
        else:
            hkls = self.generator.getHKLsUsingFilter(
                self.qrange[0], self.qrange[1],
                ReflectionConditionFilter.StructureFactor)

        pg = self.sample.getSpaceGroup().getPointGroup()

        df = pd.DataFrame(data=np.array(hkls), columns=list('hkl'))

        df['d(A)'] = self.generator.getDValues(hkls)
        df['F^2'] = self.generator.getFsSquared(hkls)
        df['hkl'] = hkls
        df['M'] = df['hkl'].map(lambda x: len(pg.getEquivalents(x)))
        df['II_powder'] = df['F^2'] * df['M']
        df['q'] = 2 * np.pi / df['d(A)']
        df['qh'] = df['h'].map(lambda x: np.sign(x) * 2 * np.pi / self.
                               generator.getDValues([V3D(x, 0, 0)])[0])
        df['qk'] = df['k'].map(lambda x: np.sign(x) * 2 * np.pi / self.
                               generator.getDValues([V3D(0, x, 0)])[0])
        df['ql'] = df['l'].map(lambda x: np.sign(x) * 2 * np.pi / self.
                               generator.getDValues([V3D(0, 0, x)])[0])
        self.data = df
def quat2RotxRotyRotz(quat):
    X = V3D(1, 0, 0)
    Y = V3D(0, 1, 0)
    Z = V3D(0, 0, 1)
    quat.rotate(X)
    quat.rotate(Y)
    quat.rotate(Z)
    if (Z.Y() != 0 or Z.Z() != 0):
        tx = math.atan2(-Z.Y(), Z.Z())
        tz = math.atan2(-Y.X(), X.X())
        cosy = Z.Z() / math.cos(tx)
        ty = math.atan2(Z.X(), cosy)
        Rotx = (tx * 180. / math.pi)
        Roty = (ty * 180. / math.pi)
        Rotz = (tx * 180. / math.pi)
    else:
        k = 1
        if Z.X() < 0:
            k = -1
        roty = k * 90
        rotx = 0
        rotz = math.atan2(X.Z(), Y.Z())
        Rotx = rotx * 180. / math.pi
        Roty = roty * 180. / math.pi
        Rotz = rotz * 180. / math.pi
    return (Rotx, Roty, Rotz)
Пример #9
0
    def test_getUniqueHKLs(self):
        generator = ReflectionGenerator(self.crystalStructure)
        hkls = generator.getUniqueHKLs(1.0, 10.0)

        self.assertEqual(len(hkls), 9)

        self.assertTrue(V3D(2, 2, 2) in hkls)
        self.assertFalse(V3D(1, 0, 0) in hkls)
Пример #10
0
def eulerToQuat(alpha, beta, gamma, convention):
    """                    
    Convert Euler angles to a quaternion
    """
    from mantid.kernel import Quat, V3D
    getV3D = {'X': V3D(1, 0, 0), 'Y': V3D(0, 1, 0), 'Z': V3D(0, 0, 1)}
    return (Quat(alpha, getV3D[convention[0]]) * Quat(beta, getV3D[convention[1]]) *
            Quat(gamma, getV3D[convention[2]]))
Пример #11
0
    def test_apply(self):
        symOp = SymmetryOperationFactory.createSymOp("x,y,-z")

        hkl1 = V3D(1, 1, 1)
        hkl2 = symOp.apply(hkl1)

        self.assertEquals(hkl2, V3D(1, 1, -1))
        self.assertEquals(symOp.transformHKL(hkl2), hkl1)
Пример #12
0
    def test_hash(self):
        v1 = V3D(1, 1, 1)
        v2 = V3D(1, 1, 1)
        v3 = V3D(1, 0, 0)

        a = set([v1, v2, v3])

        self.assertEquals(len(a), 2)
Пример #13
0
    def test_isEquivalent(self):
        hkl1 = V3D(1, 1, 1)
        hkl2 = V3D(-1, -1, -1)
        hkl3 = V3D(-1, -1, 2)

        pg = PointGroupFactoryImpl.Instance().createPointGroup("m-3m")
        self.assertTrue(pg.isEquivalent(hkl1, hkl2))
        self.assertFalse(pg.isEquivalent(hkl1, hkl3))
Пример #14
0
 def _eulerToQuat(self, alpha, beta, gamma, convention):
     """
     Convert Euler angles to a quaternion
     """
     getV3D = {'X': V3D(1, 0, 0), 'Y': V3D(0, 1, 0), 'Z': V3D(0, 0, 1)}
     return (Quat(alpha, getV3D[convention[0]]) *
             Quat(beta, getV3D[convention[1]]) *
             Quat(gamma, getV3D[convention[2]]))
Пример #15
0
    def test_apply(self):
        symOp = SymmetryOperationFactoryImpl.Instance().createSymOp("x,y,-z")

        hkl1 = V3D(1, 1, 1)
        hkl2 = symOp.apply(hkl1)

        self.assertEquals(hkl2, V3D(1, 1, -1))
        self.assertEquals(symOp.apply(hkl2), hkl1)
Пример #16
0
    def test_set_and_extract_v3d_columns(self):
        from mantid.kernel import V3D

        table = WorkspaceFactory.createTable()
        table.addColumn(type='V3D', name='pos')
        table.addRow([V3D(1, 1, 1)])

        self.assertEqual(V3D(1, 1, 1), table.cell(0, 0))
Пример #17
0
    def test_setaxis_with_numpy_int64(self):
        p = Projection()

        p.setAxis(0, np.array([1, 2, 3], dtype='int64'))
        p.setAxis(1, np.array([3, 4, 5], dtype='int64'))
        p.setAxis(2, np.array([6, 7, 8], dtype='int64'))
        self.assertEqual(p.getAxis(0), V3D(1, 2, 3))
        self.assertEqual(p.getAxis(1), V3D(3, 4, 5))
        self.assertEqual(p.getAxis(2), V3D(6, 7, 8))
Пример #18
0
 def test_angle(self):
     a = V3D(2.0, 0.0, 0.0)
     b = V3D(0.0, 1.0, 0.0)
     c = V3D(1.0, 1.0, 0.0)
     d = V3D(-1.0, 0.0, 0.0)
     self.assertAlmostEquals(a.angle(a), 0.0)
     self.assertAlmostEquals(a.angle(b), math.pi / 2.0)
     self.assertAlmostEquals(a.angle(c), math.pi / 4.0)
     self.assertAlmostEquals(a.angle(d), math.pi)
Пример #19
0
    def test_getHKLs(self):
        generator = ReflectionGenerator(self.crystalStructure)
        hkls = generator.getHKLs(1.0, 10.0)

        self.assertEqual(len(hkls), 138)

        # default is filtering by space group reflection condition
        self.assertTrue(V3D(2, 2, 2) in hkls)
        self.assertFalse(V3D(1, 0, 0) in hkls)
Пример #20
0
 def test_cos_angle(self):
     a = V3D(2.0, 0.0, 0.0)
     b = V3D(0.0, 1.0, 0.0)
     c = V3D(1.0, 1.0, 0.0)
     d = V3D(-1.0, 0.0, 0.0)
     self.assertAlmostEquals(a.cosAngle(a), 1.0)
     self.assertAlmostEquals(a.cosAngle(b), 0.0)
     self.assertAlmostEquals(a.cosAngle(c), 1.0 / np.sqrt(2.))
     self.assertAlmostEquals(a.cosAngle(d), -1.0)
Пример #21
0
    def test_setaxis_with_numpy_float(self):
        p = Projection()

        p.setAxis(0, np.array([0, 1, 2], dtype='float64'))
        p.setAxis(1, np.array([3, 4, 5], dtype='float64'))
        p.setAxis(2, np.array([6, 7, 8], dtype='float64'))
        self.assertEqual(p.getAxis(0), V3D(0, 1, 2))
        self.assertEqual(p.getAxis(1), V3D(3, 4, 5))
        self.assertEqual(p.getAxis(2), V3D(6, 7, 8))
Пример #22
0
    def test_getDValues(self):
        generator = ReflectionGenerator(self.crystalStructure)
        hkls = [V3D(1, 0, 0), V3D(1, 1, 1)]

        dValues = generator.getDValues(hkls)

        self.assertEqual(len(hkls), len(dValues))
        self.assertAlmostEqual(dValues[0], 5.431, places=10)
        self.assertAlmostEqual(dValues[1], 5.431 / np.sqrt(3.), places=10)
Пример #23
0
    def test_that_SANS2D_can_move(self):
        # Arrange
        file_name = "SANS2D00028784"
        lab_z_translation_correction = 123.

        workspace = load_workspace(file_name)
        state = SANSMoveTest._get_simple_state(sample_scatter=file_name,
                                               lab_z_translation_correction=lab_z_translation_correction)
        beam_coordinates = [0.1076, -0.0835]

        # Act
        # The component input is not relevant for SANS2D's initial move. All detectors are moved
        component = None
        move_alg = self._run_move(state, workspace=workspace, move_type="InitialMove",
                                  beam_coordinates=beam_coordinates, component=component)

        # Assert for initial move for low angle bank
        # These values are on the workspace and in the sample logs,
        component_to_investigate = DetectorType.to_string(DetectorType.LAB)
        initial_z_position = 23.281
        rear_det_z = 11.9989755859
        offset = 4.
        total_x = 0.
        total_y = 0.
        total_z = initial_z_position + rear_det_z - offset + lab_z_translation_correction
        expected_position = V3D(total_x - beam_coordinates[0], total_y - beam_coordinates[1], total_z)
        expected_rotation = Quat(1., 0., 0., 0.)
        self.compare_expected_position(expected_position, expected_rotation,
                                       component_to_investigate, state.move, workspace)

        # Assert for initial move for high angle bank
        # These values are on the workspace and in the sample logs
        component_to_investigate = DetectorType.to_string(DetectorType.HAB)
        initial_x_position = 1.1
        x_correction = -0.187987540973
        initial_z_position = 23.281
        z_correction = 1.00575649188
        total_x = initial_x_position + x_correction
        total_y = 0.
        total_z = initial_z_position + z_correction
        expected_position = V3D(total_x - beam_coordinates[0], total_y - beam_coordinates[1], total_z)
        expected_rotation = Quat(0.9968998362876025, 0., 0.07868110579898738, 0.)
        self.compare_expected_position(expected_position, expected_rotation,
                                       component_to_investigate, state.move, workspace)

        # Act + Assert for elementary move
        component_elementary_move = "rear-detector"
        component_elementary_move_key = DetectorType.to_string(DetectorType.LAB)
        beam_coordinates_elementary_move = [120, 135]
        self.check_that_elementary_displacement_with_only_translation_is_correct(workspace, move_alg, state.move,
                                                                                 beam_coordinates_elementary_move,
                                                                                 component_elementary_move,
                                                                                 component_elementary_move_key)

        # # Act + Assert for setting to zero position for all
        self.check_that_sets_to_zero(workspace, move_alg, state.move, comp_name=None)
Пример #24
0
    def test_setModVec_accepts_v3d(self):
        unit = UnitCell(3, 3, 3)

        vectors = (V3D(1, 2, 3), V3D(2, 1, 3), V3D(3, 2, 1))
        unit.setModVec1(vectors[0])
        unit.setModVec2(vectors[1])
        unit.setModVec3(vectors[2])

        for index, expected in enumerate(vectors):
            self.assertEquals(vectors[index], unit.getModVec(index))
Пример #25
0
def create_mock_peak(center):
    peak = MagicMock()
    # set all 3 methods to return the same thing. Check appropriate method called in test
    peak.getQLabFrame.return_value = V3D(*center)
    peak.getQSampleFrame.return_value = V3D(*center)
    peak.getHKL.return_value = V3D(*center)
    shape = MagicMock()
    shape.shapeName.return_value = 'none'
    peak.getPeakShape.return_value = shape
    return peak
Пример #26
0
    def test_getEquivalents(self):
        hkl1 = V3D(1, 0, 0)
        hkl2 = V3D(-1, 0, 0)

        pg = PointGroupFactoryImpl.Instance().createPointGroup("-1")
        equivalents = pg.getEquivalents(hkl1)

        self.assertTrue(hkl1 in equivalents)
        self.assertTrue(hkl2 in equivalents)

        self.assertEquals(len(equivalents), 2)
Пример #27
0
    def _create_indexed_workspace(self, fractional_peaks, m1m2):
        # Create table with the number of columns we need
        modulated = CloneWorkspace(fractional_peaks)
        lattice = modulated.sample().getOrientedLattice()
        lattice.setModVec1(V3D(0.5, 0.0, 0.5))
        lattice.setModVec2(V3D(0.333, 0.333, 0.))
        for row, peak in enumerate(modulated):
            row_indices = m1m2[row]
            peak.setIntMNP(V3D(row_indices[0], row_indices[1], 0))

        return modulated
def GenerateAxisVector(Rotations=None, Vector=[0, 0, 1]):
    # Get vector to manipulate
    x, y, z = Vector
    axis_vector = V3D(x, y, z)

    # Apply rotations
    for rotation in Rotations:
        x, y, z = rotation["Axis"]
        axis_vector = MyRotateFunction(axis_vector, V3D(x, y, z),
                                       rotation["Angle"])

    return axis_vector
Пример #29
0
    def test_creation_axis(self):
        symOp = SymmetryOperationFactory.createSymOp("x,y,-z")
        symEle = SymmetryElementFactory.createSymElement(symOp)

        self.assertEquals(symEle.getHMSymbol(), "m")
        self.assertEquals(symEle.getAxis(), V3D(0, 0, 1))

        rotation = SymmetryOperationFactory.createSymOp("x,-y,-z")
        rotationElement = SymmetryElementFactory.createSymElement(rotation)

        self.assertEquals(rotationElement.getHMSymbol(), "2")
        self.assertEquals(rotationElement.getAxis(), V3D(1, 0, 0))
Пример #30
0
    def test_setCell_with_column_name(self):
        pws = WorkspaceCreationHelper.createPeaksWorkspace(1, True)
        pws.setCell("h", 0, 1)
        pws.setCell("k", 0, 2)
        pws.setCell("l", 0, 3)
        pws.setCell("QLab", 0, V3D(1,1,1))
        pws.setCell("QSample", 0, V3D(1,1,1))

        self.assertEquals(pws.cell("h", 0), 1)
        self.assertEquals(pws.cell("k", 0), 2)
        self.assertEquals(pws.cell("l", 0), 3)
        self.assertEquals(pws.cell("QLab", 0), V3D(1,1,1))
        self.assertEquals(pws.cell("QSample", 0), V3D(1,1,1))