Mantid
Loading...
Searching...
No Matches
CrystalStructure.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9#include <boost/algorithm/string/join.hpp>
10#include <boost/python/class.hpp>
11#include <boost/python/make_constructor.hpp>
12#include <boost/python/register_ptr_to_python.hpp>
13
14using namespace Mantid::Geometry;
15using namespace Mantid::Kernel;
16using namespace boost::python;
17
18namespace {
19SpaceGroup_sptr getSpaceGroup(const CrystalStructure &self) {
20 return std::const_pointer_cast<SpaceGroup>(self.spaceGroup());
21}
22
23std::vector<std::string> getScatterers(const CrystalStructure &self) {
24 auto scatterers = self.getScatterers();
25
26 std::vector<std::string> scattererStrings;
27 scattererStrings.reserve(scatterers->nScatterers());
28
29 for (size_t i = 0; i < scatterers->nScatterers(); ++i) {
30 scattererStrings.emplace_back(getIsotropicAtomBraggScattererString(scatterers->getScatterer(i)));
31 }
32
33 return scattererStrings;
34}
35
36UnitCell getCell(const CrystalStructure &self) { return self.cell(); }
37
38std::string __str__implementation(const CrystalStructure &self) {
39 std::stringstream ss;
40 ss << "Crystal structure with:\n";
41 ss << "Unit cell:";
42
43 const auto cell = self.cell();
44 ss << " a = " << cell.a();
45 ss << " b = " << cell.b();
46 ss << " c = " << cell.c();
47
48 ss << " alpha = " << cell.alpha();
49 ss << " beta = " << cell.beta();
50 ss << " gamma = " << cell.gamma();
51
52 ss << "\n";
53
54 ss << "Centering: " << self.centering()->getName() << "\n";
55 ss << "Space Group: " << self.spaceGroup()->hmSymbol() << "\n";
56 ss << "Scatterers: " << boost::algorithm::join(getScatterers(self), ", ");
57
58 return ss.str();
59}
60
61std::string __repr__implementation(const CrystalStructure &self) {
62 std::stringstream ss;
63 ss << "CrystalStructure(\"";
64
65 const auto cell = self.cell();
66
67 ss << cell.a() << " ";
68 ss << cell.b() << " ";
69 ss << cell.c() << " ";
70
71 ss << cell.alpha() << " ";
72 ss << cell.beta() << " ";
73 ss << cell.gamma();
74 ss << "\", ";
75
76 ss << "\"" << self.spaceGroup()->hmSymbol() << "\", ";
77 ss << "\"" << boost::algorithm::join(getScatterers(self), "; ") << "\"";
78
79 ss << ")";
80
81 return ss.str();
82}
83} // namespace
84
86 class_<CrystalStructure>("CrystalStructure", no_init)
87 .def(init<const std::string &, const std::string &, const std::string &>(
88 (arg("unitCell"), arg("spaceGroup"), arg("scatterers"))))
89 .def("getUnitCell", &getCell, arg("self"))
90 .def("getSpaceGroup", &getSpaceGroup, arg("self"))
91 .def("getScatterers", &getScatterers, arg("self"))
92 .def("__str__", &__str__implementation)
93 .def("__repr__", &__repr__implementation);
94}
void export_CrystalStructure()
Three components are required to describe a crystal structure:
CompositeBraggScatterer_sptr getScatterers() const
Return a clone of the internal CompositeBraggScatterer instance.
ReflectionCondition_sptr centering() const
SpaceGroup_const_sptr spaceGroup() const
Returns the space group of the crystal structure.
UnitCell const & cell() const &
Class to implement unit cell of crystals.
Definition UnitCell.h:44
double a(int nd) const
Get lattice parameter a1-a3 as function of index (0-2)
Definition UnitCell.cpp:94
MANTID_GEOMETRY_DLL std::string getIsotropicAtomBraggScattererString(const BraggScatterer_sptr &scatterer)
std::shared_ptr< SpaceGroup > SpaceGroup_sptr
Definition SpaceGroup.h:81