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
36std::string __str__implementation(const CrystalStructure &self) {
37 std::stringstream ss;
38 ss << "Crystal structure with:\n";
39 ss << "Unit cell:";
40
41 const auto cell = self.cell();
42 ss << " a = " << cell.a();
43 ss << " b = " << cell.b();
44 ss << " c = " << cell.c();
45
46 ss << " alpha = " << cell.alpha();
47 ss << " beta = " << cell.beta();
48 ss << " gamma = " << cell.gamma();
49
50 ss << "\n";
51
52 ss << "Centering: " << self.centering()->getName() << "\n";
53 ss << "Space Group: " << self.spaceGroup()->hmSymbol() << "\n";
54 ss << "Scatterers: " << boost::algorithm::join(getScatterers(self), ", ");
55
56 return ss.str();
57}
58
59std::string __repr__implementation(const CrystalStructure &self) {
60 std::stringstream ss;
61 ss << "CrystalStructure(\"";
62
63 const auto cell = self.cell();
64
65 ss << cell.a() << " ";
66 ss << cell.b() << " ";
67 ss << cell.c() << " ";
68
69 ss << cell.alpha() << " ";
70 ss << cell.beta() << " ";
71 ss << cell.gamma();
72 ss << "\", ";
73
74 ss << "\"" << self.spaceGroup()->hmSymbol() << "\", ";
75 ss << "\"" << boost::algorithm::join(getScatterers(self), "; ") << "\"";
76
77 ss << ")";
78
79 return ss.str();
80}
81} // namespace
82
84 class_<CrystalStructure>("CrystalStructure", no_init)
85 .def(init<const std::string &, const std::string &, const std::string &>(
86 (arg("unitCell"), arg("spaceGroup"), arg("scatterers"))))
87 .def("getUnitCell", &CrystalStructure::cell, arg("self"))
88 .def("getSpaceGroup", &getSpaceGroup, arg("self"))
89 .def("getScatterers", &getScatterers, arg("self"))
90 .def("__str__", &__str__implementation)
91 .def("__repr__", &__repr__implementation);
92}
void export_CrystalStructure()
Three components are required to describe a crystal structure:
CompositeBraggScatterer_sptr getScatterers() const
Return a clone of the internal CompositeBraggScatterer instance.
UnitCell cell() const
Returns the unit cell of the structure.
ReflectionCondition_sptr centering() const
SpaceGroup_const_sptr spaceGroup() const
Returns the space group of the crystal structure.
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