Skip to content
Snippets Groups Projects
Commit 78c6be94 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #19349 Expose methods on PointGroup

parent ab1c98f5
No related branches found
No related tags found
No related merge requests found
...@@ -96,6 +96,8 @@ MANTID_GEOMETRY_DLL ...@@ -96,6 +96,8 @@ MANTID_GEOMETRY_DLL
PointGroup::LatticeSystem PointGroup::LatticeSystem
getLatticeSystemFromString(const std::string &latticeSystem); getLatticeSystemFromString(const std::string &latticeSystem);
MANTID_GEOMETRY_DLL std::ostream &operator<<(std::ostream& stream, const PointGroup& self);
/// This is necessary to make the map work with older compilers. Can be removed /// This is necessary to make the map work with older compilers. Can be removed
/// when GCC 4.4 is not used anymore. /// when GCC 4.4 is not used anymore.
struct MANTID_GEOMETRY_DLL CrystalSystemComparator { struct MANTID_GEOMETRY_DLL CrystalSystemComparator {
......
...@@ -320,5 +320,17 @@ operator()(const PointGroup::CrystalSystem &lhs, ...@@ -320,5 +320,17 @@ operator()(const PointGroup::CrystalSystem &lhs,
return static_cast<int>(lhs) < static_cast<int>(rhs); return static_cast<int>(lhs) < static_cast<int>(rhs);
} }
/// Returns a streamed representation of the PointGroup object
std::ostream &operator<<(std::ostream& stream, const PointGroup& self) {
stream << "Point group with\n"
<< "Lattice system: "
<< getLatticeSystemAsString(self.latticeSystem()) << "\n"
<< "Crystal system: "
<< getCrystalSystemAsString(self.crystalSystem()) << "\n"
<< "Symbol: "
<< self.getSymbol();
return stream;
}
} // namespace Mantid } // namespace Mantid
} // namespace Geometry } // namespace Geometry
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "MantidPythonInterface/kernel/Converters/PyObjectToV3D.h" #include "MantidPythonInterface/kernel/Converters/PyObjectToV3D.h"
#include <boost/python/class.hpp> #include <boost/python/class.hpp>
#include <boost/python/self.hpp>
#include <boost/python/operators.hpp>
#include <boost/python/enum.hpp> #include <boost/python/enum.hpp>
#include <boost/python/scope.hpp> #include <boost/python/scope.hpp>
#include <boost/python/list.hpp> #include <boost/python/list.hpp>
...@@ -40,6 +42,15 @@ boost::python::list getEquivalents(PointGroup &self, const object &hkl) { ...@@ -40,6 +42,15 @@ boost::python::list getEquivalents(PointGroup &self, const object &hkl) {
Mantid::Kernel::V3D getReflectionFamily(PointGroup &self, const object &hkl) { Mantid::Kernel::V3D getReflectionFamily(PointGroup &self, const object &hkl) {
return self.getReflectionFamily(Converters::PyObjectToV3D(hkl)()); return self.getReflectionFamily(Converters::PyObjectToV3D(hkl)());
} }
std::string __repr__implementation(const PointGroup &self) {
std::stringstream ss;
ss << "PointGroupFactory.createPointGroup(\"";
ss << self.getSymbol();
ss << "\")";
return ss.str();
}
} }
void export_PointGroup() { void export_PointGroup() {
...@@ -79,5 +90,7 @@ void export_PointGroup() { ...@@ -79,5 +90,7 @@ void export_PointGroup() {
"HKL.") "HKL.")
.def("getReflectionFamily", &getReflectionFamily, .def("getReflectionFamily", &getReflectionFamily,
(arg("self"), arg("hkl")), (arg("self"), arg("hkl")),
"Returns the same HKL for all symmetry equivalents."); "Returns the same HKL for all symmetry equivalents.")
.def(str(self))
.def("__repr__", &__repr__implementation);
} }
...@@ -53,6 +53,21 @@ class PointGroupTest(unittest.TestCase): ...@@ -53,6 +53,21 @@ class PointGroupTest(unittest.TestCase):
self.assertEquals(pg_rhombohedral.getLatticeSystem(), PointGroup.LatticeSystem.Rhombohedral) self.assertEquals(pg_rhombohedral.getLatticeSystem(), PointGroup.LatticeSystem.Rhombohedral)
self.assertEquals(pg_hexagonal.getLatticeSystem(), PointGroup.LatticeSystem.Hexagonal) self.assertEquals(pg_hexagonal.getLatticeSystem(), PointGroup.LatticeSystem.Hexagonal)
def test_to_string(self):
pg = PointGroupFactory.createPointGroup("m-3m")
expected_str = "Point group with\nLattice system: Cubic"\
"\nCrystal system: Cubic\nSymbol: m-3m"
expected_repr = "PointGroupFactory.createPointGroup(\"m-3m\")"
self.assertEqual(expected_str, str(pg))
self.assertEqual(expected_repr, pg.__repr__())
newPg = eval(pg.__repr__())
self.assertEqual(pg.getHMSymbol(), newPg.getHMSymbol())
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment