Mantid
Loading...
Searching...
No Matches
SymmetryOperationSymbolParser.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 +
10
11#include <boost/algorithm/string.hpp>
12#include <sstream>
13
14namespace Mantid::Geometry {
15
19 for (size_t i = 0; i < matrix.numRows(); ++i) {
20 if (!isValidMatrixRow(matrix[i], matrix.numCols())) {
21 std::ostringstream error;
22 error << "Matrix row " << i << " is invalid. Elements: [" << matrix[i][0] << ", " << matrix[i][1] << ", "
23 << matrix[i][2] << "]";
24 throw Kernel::Exception::ParseError(error.str(), "", 0);
25 }
26 }
27}
28
50 MatrixVectorPair<int, V3R> pair = parseMatrixVectorPair<int>(identifier);
51
52 verifyMatrix(pair.getMatrix());
53
54 return pair;
55}
56
60 return getNormalizedIdentifier(data.getMatrix(), data.getVector());
61}
62
86 if (matrix.numCols() != 3 || matrix.numRows() != 3) {
87 throw std::runtime_error("Matrix is not a 3x3 matrix.");
88 }
89
90 std::vector<std::string> symbols{"x", "y", "z"};
91 std::vector<std::string> components;
92
93 for (size_t r = 0; r < 3; ++r) {
94 std::ostringstream currentComponent;
95
96 for (size_t c = 0; c < 3; ++c) {
97 if (matrix[r][c] != 0) {
98 if (matrix[r][c] < 0) {
99 currentComponent << "-";
100 } else {
101 if (!currentComponent.str().empty()) {
102 currentComponent << "+";
103 }
104 }
105
106 currentComponent << symbols[c];
107 }
108 }
109
110 if (vector[r] != 0) {
111 if (vector[r] > 0) {
112 currentComponent << "+";
113 }
114
115 if (vector[r].denominator() != 1) {
116 currentComponent << vector[r];
117 } else {
118 currentComponent << vector[r].numerator();
119 }
120 }
121
122 components.emplace_back(currentComponent.str());
123 }
124
125 return boost::join(components, ",");
126}
127
130bool SymmetryOperationSymbolParser::isValidMatrixRow(const int *element, size_t columnNumber) {
131 int nulls = 0;
132 for (size_t i = 0; i < columnNumber; ++i) {
133 if (abs(element[i]) > 1) {
134 return false;
135 } else if (element[i] == 0) {
136 ++nulls;
137 }
138 }
139
140 return nulls > 0 && nulls < 3;
141}
142
143} // namespace Mantid::Geometry
double error
Definition: IndexPeaks.cpp:133
const VectorType & getVector() const
Returns a const reference to the stored vector.
const Kernel::Matrix< MatrixNumericType > & getMatrix() const
Returns a const reference to the internally stored matrix.
static void verifyMatrix(const Kernel::IntMatrix &matrix)
Verify that the matrix does not contain elements with abs(element) > 1 and has an acceptable number o...
static bool isValidMatrixRow(const int *element, size_t columnNumber)
Checks if there are either 1 or 2 zeros in a given matrix row and all non-zero elements are 1 or -1.
static std::string getNormalizedIdentifier(const MatrixVectorPair< int, V3R > &data)
Returns a Jones faithful representation of the symmetry operation characterized by the supplied matri...
static MatrixVectorPair< int, V3R > parseIdentifier(const std::string &identifier)
Tries to parse the given symbol.
Records the filename, the description of failure and the line on which it happened.
Definition: Exception.h:115
size_t numRows() const
Return the number of rows in the matrix.
Definition: Matrix.h:144
size_t numCols() const
Return the number of columns in the matrix.
Definition: Matrix.h:147