-
Notifications
You must be signed in to change notification settings - Fork 121
/
ShowPossibleCells.cpp
87 lines (67 loc) · 2.93 KB
/
ShowPossibleCells.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "MantidCrystal/ShowPossibleCells.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidGeometry/Crystal/IndexingUtils.h"
#include "MantidGeometry/Crystal/ScalarUtils.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidKernel/BoundedValidator.h"
#include "MantidAPI/Sample.h"
namespace Mantid {
namespace Crystal {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ShowPossibleCells)
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::DataObjects;
using namespace Mantid::Geometry;
/** Initialize the algorithm's properties.
*/
void ShowPossibleCells::init() {
this->declareProperty(make_unique<WorkspaceProperty<PeaksWorkspace>>(
"PeaksWorkspace", "", Direction::InOut),
"Input Peaks Workspace");
auto mustBePositive = boost::make_shared<BoundedValidator<double>>();
mustBePositive->setLower(0.0);
this->declareProperty(
make_unique<PropertyWithValue<double>>("MaxScalarError", 0.2,
mustBePositive, Direction::Input),
"Max Scalar Error (0.2)");
this->declareProperty("BestOnly", true,
"Show at most one for each Bravais Lattice");
this->declareProperty(make_unique<PropertyWithValue<int>>("NumberOfCells", 0,
Direction::Output),
"Gets set with the number of possible cells.");
this->declareProperty("AllowPermutations", true,
"Allow permutations of conventional cells");
}
/** Execute the algorithm.
*/
void ShowPossibleCells::exec() {
PeaksWorkspace_const_sptr ws = this->getProperty("PeaksWorkspace");
if (!ws) {
throw std::runtime_error("Could not read the peaks workspace");
}
OrientedLattice o_lattice = ws->sample().getOrientedLattice();
const Matrix<double> &UB = o_lattice.getUB();
if (!IndexingUtils::CheckUB(UB)) {
throw std::runtime_error(
"ERROR: The stored UB is not a valid orientation matrix");
}
double max_scalar_error = this->getProperty("MaxScalarError");
bool best_only = this->getProperty("BestOnly");
bool allowPermutations = this->getProperty("AllowPermutations");
std::vector<ConventionalCell> list =
ScalarUtils::GetCells(UB, best_only, allowPermutations);
ScalarUtils::RemoveHighErrorForms(list, max_scalar_error);
size_t num_cells = list.size();
// now tell the user the number of possible conventional cells:
g_log.notice() << "Num Cells : " << num_cells << '\n';
for (size_t i = 0; i < num_cells; i++) {
DblMatrix newUB = list[i].GetNewUB();
std::string message = list[i].GetDescription() + " Lat Par:" +
IndexingUtils::GetLatticeParameterString(newUB);
g_log.notice(std::string(message));
}
this->setProperty("NumberOfCells", static_cast<int>(num_cells));
}
} // namespace Mantid
} // namespace Crystal