diff --git a/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/SymmetryOperationFactory.cpp b/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/SymmetryOperationFactory.cpp index 46186e33b133..8c991161b1d0 100644 --- a/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/SymmetryOperationFactory.cpp +++ b/Code/Mantid/Framework/PythonInterface/mantid/geometry/src/Exports/SymmetryOperationFactory.cpp @@ -6,12 +6,23 @@ using namespace Mantid::Geometry; using namespace boost::python; +namespace { + using namespace Mantid::PythonInterface; + + SymmetryOperation_sptr createSymOpPython(SymmetryOperationFactoryImpl & self, const std::string &identifier) + { + SymmetryOperation_const_sptr constSymOp = self.createSymOp(identifier); + + return boost::const_pointer_cast(constSymOp); + } +} + void export_SymmetryOperationFactory() { class_("SymmetryOperationFactoryImpl", no_init) .def("exists", &SymmetryOperationFactoryImpl::exists) - .def("createSymOp", &SymmetryOperationFactoryImpl::createSymOp) + .def("createSymOp", &createSymOpPython) .def("getKeys", &SymmetryOperationFactoryImpl::getKeys, "Returns all registered symmetry operations") .def("Instance", &SymmetryOperationFactory::Instance, return_value_policy(), "Returns a reference to the SymmetryOperationFactory singleton") diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/CMakeLists.txt index dc670926c537..a6dc06eed663 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/CMakeLists.txt @@ -10,6 +10,8 @@ set ( TEST_PY_FILES RectangularDetectorTest.py ReferenceFrameTest.py UnitCellTest.py + PointGroupTest.py + SymmetryOperationTest.py ) check_tests_valid ( ${CMAKE_CURRENT_SOURCE_DIR} ${TEST_PY_FILES} ) diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/PointGroupTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/PointGroupTest.py new file mode 100644 index 000000000000..358491f5964b --- /dev/null +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/PointGroupTest.py @@ -0,0 +1,47 @@ +import unittest +from mantid.geometry import PointGroup, PointGroupFactoryImpl +from mantid.kernel import V3D + +class PointGroupTest(unittest.TestCase): + + def test_creation(self): + self.assertRaises(RuntimeError, PointGroupFactoryImpl.Instance().createPointGroup, "none") + + PointGroupFactoryImpl.Instance().createPointGroup("m-3m") + + def test_getInfo(self): + pg = PointGroupFactoryImpl.Instance().createPointGroup("m-3m") + self.assertEquals(pg.getName(), "m-3m (Cubic)") + self.assertEquals(pg.getSymbol(), "m-3m") + self.assertEquals(pg.crystalSystem(), PointGroup.CrystalSystem.Cubic) + + 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)) + + 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) + + 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)) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/SymmetryOperationTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/SymmetryOperationTest.py new file mode 100644 index 000000000000..120499f9cb2c --- /dev/null +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/geometry/SymmetryOperationTest.py @@ -0,0 +1,28 @@ +import unittest +from mantid.geometry import SymmetryOperation, SymmetryOperationFactoryImpl +from mantid.kernel import V3D + +class SymmetryOperationTest(unittest.TestCase): + + def test_creation(self): + self.assertRaises(RuntimeError, SymmetryOperationFactoryImpl.Instance().createSymOp, "none") + + SymmetryOperationFactoryImpl.Instance().createSymOp("m [001]") + + def test_getInfo(self): + symOp = SymmetryOperationFactoryImpl.Instance().createSymOp("m [001]") + self.assertEquals(symOp.order(), 2) + self.assertEquals(symOp.identifier(), "m [001]") + + def test_apply(self): + symOp = SymmetryOperationFactoryImpl.Instance().createSymOp("m [001]") + + hkl1 = V3D(1, 1, 1) + hkl2 = symOp.apply(hkl1) + + self.assertEquals(hkl2, V3D(1, 1, -1)) + self.assertEquals(symOp.apply(hkl2), hkl1) + + +if __name__ == '__main__': + unittest.main() \ No newline at end of file