Mantid
Loading...
Searching...
No Matches
SelectCellOfType.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 "MantidAPI/Sample.h"
18
19namespace Mantid::Crystal {
20// Register the algorithm into the AlgorithmFactory
21DECLARE_ALGORITHM(SelectCellOfType)
22
23using namespace Mantid::Kernel;
24using namespace Mantid::API;
25using namespace Mantid::DataObjects;
26using namespace Mantid::Geometry;
27
31 this->declareProperty(std::make_unique<WorkspaceProperty<IPeaksWorkspace>>("PeaksWorkspace", "", Direction::InOut),
32 "Input Peaks Workspace");
33
34 std::vector<std::string> type_list;
35 type_list.emplace_back(ReducedCell::CUBIC());
36 type_list.emplace_back(ReducedCell::HEXAGONAL());
37 type_list.emplace_back(ReducedCell::RHOMBOHEDRAL());
38 type_list.emplace_back(ReducedCell::TETRAGONAL());
39 type_list.emplace_back(ReducedCell::ORTHORHOMBIC());
40 type_list.emplace_back(ReducedCell::MONOCLINIC());
41 type_list.emplace_back(ReducedCell::TRICLINIC());
42
43 declareProperty("CellType", type_list[0], std::make_shared<Kernel::StringListValidator>(type_list),
44 "The conventional cell type to use");
45
46 std::vector<std::string> centering_list;
47 centering_list.emplace_back(ReducedCell::F_CENTERED());
48 centering_list.emplace_back(ReducedCell::I_CENTERED());
49 centering_list.emplace_back(ReducedCell::C_CENTERED());
50 centering_list.emplace_back(ReducedCell::P_CENTERED());
51 centering_list.emplace_back(ReducedCell::R_CENTERED());
52
53 declareProperty("Centering", centering_list[3], std::make_shared<Kernel::StringListValidator>(centering_list),
54 "The centering for the conventional cell");
55
56 this->declareProperty("Apply", false, "Update UB and re-index the peaks");
57 this->declareProperty("Tolerance", 0.12, "Indexing Tolerance");
58
59 this->declareProperty(std::make_unique<PropertyWithValue<int>>("NumIndexed", 0, Direction::Output),
60 "The number of indexed peaks if apply==true.");
61
62 this->declareProperty(std::make_unique<PropertyWithValue<double>>("AverageError", 0.0, Direction::Output),
63 "The average HKL indexing error if apply==true.");
64
65 this->declareProperty("AllowPermutations", true, "Allow permutations of conventional cells");
66
67 this->declareProperty(std::make_unique<ArrayProperty<double>>("TransformationMatrix", Direction::Output),
68 "The transformation matrix");
69}
70
74 IPeaksWorkspace_sptr ws = this->getProperty("PeaksWorkspace");
75 if (!ws) {
76 throw std::runtime_error("Could not read the peaks workspace");
77 }
78
79 // copy current lattice
80 Matrix<double> UB = ws->sample().getOrientedLattice().getUB();
81
82 if (!IndexingUtils::CheckUB(UB)) {
83 throw std::runtime_error("ERROR: The stored UB is not a valid orientation matrix");
84 }
85
86 std::string cell_type = this->getProperty("CellType");
87 std::string centering = this->getProperty("Centering");
88 bool apply = this->getProperty("Apply");
89 double tolerance = this->getProperty("Tolerance");
90 bool allowPermutations = this->getProperty("AllowPermutations");
91
92 std::vector<ConventionalCell> list = ScalarUtils::GetCells(UB, cell_type, centering, allowPermutations);
93
95
96 DblMatrix newUB = info.GetNewUB();
97
98 std::string message = info.GetDescription() + " Lat Par:" + IndexingUtils::GetLatticeParameterString(newUB);
99
100 g_log.notice(std::string(message));
101
102 DblMatrix T = info.GetHKL_Tran();
103 g_log.notice() << "Reduced to Conventional Cell Transformation Matrix = " << T.str() << '\n';
104 this->setProperty("TransformationMatrix", T.getVector());
105
106 if (apply) {
107 int num_indexed;
108 double average_error = 0.0;
109
110 SelectCellWithForm::ApplyTransform(newUB, ws, tolerance, num_indexed, average_error);
111
112 // Tell the user what happened.
113 g_log.notice() << "Re-indexed the peaks with the new UB. \n";
114 g_log.notice() << "Now, " << num_indexed << " are indexed with average error " << average_error << '\n';
115
116 // Save output properties
117 this->setProperty("NumIndexed", num_indexed);
118 this->setProperty("AverageError", average_error);
119 }
120}
121
122} // namespace Mantid::Crystal
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
double tolerance
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Kernel::Logger & g_log
Definition: Algorithm.h:451
A property class for workspaces.
void exec() override
Run the algorithm.
void init() override
Initialise the properties.
static void ApplyTransform(Kernel::Matrix< double > &newUB, API::IPeaksWorkspace_sptr &ws, double tolerance, int &num_indexed, double &average_error)
Instances of this class represent information about a selected conventional cell based on a specified...
std::string GetDescription() const
get string listing form number, error, cell type and centering
Kernel::DblMatrix GetNewUB() const
get the transformed orientation matrix for the conventional cell
Kernel::DblMatrix GetHKL_Tran() const
get the transform to change HKL to new conventional cell HKL
static std::string GetLatticeParameterString(const Kernel::DblMatrix &UB)
Get a formatted string listing the lattice parameters and cell volume.
static bool CheckUB(const Kernel::DblMatrix &UB)
Check that the specified UB is reasonable for an orientation matrix.
static const std::string HEXAGONAL()
Definition: ReducedCell.h:53
static const std::string MONOCLINIC()
Definition: ReducedCell.h:57
static const std::string RHOMBOHEDRAL()
Definition: ReducedCell.h:54
static const std::string CUBIC()
Definition: ReducedCell.h:52
static const std::string F_CENTERED()
Definition: ReducedCell.h:61
static const std::string TRICLINIC()
Definition: ReducedCell.h:58
static const std::string R_CENTERED()
Definition: ReducedCell.h:65
static const std::string TETRAGONAL()
Definition: ReducedCell.h:55
static const std::string ORTHORHOMBIC()
Definition: ReducedCell.h:56
static const std::string P_CENTERED()
Definition: ReducedCell.h:64
static const std::string I_CENTERED()
Definition: ReducedCell.h:62
static const std::string C_CENTERED()
Definition: ReducedCell.h:63
static std::vector< ConventionalCell > GetCells(const Kernel::DblMatrix &UB, bool best_only, bool allowPermutations=false)
Get list of all possible conventional cells for UB, regardless of errors, using this UB,...
Definition: ScalarUtils.cpp:91
static ConventionalCell GetCellBestError(const std::vector< ConventionalCell > &list, bool use_triclinic)
Get the cell from the list with the smallest error, possibly excluding triclinic cells.
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
Definition: Logger.cpp:95
Numerical Matrix class.
Definition: Matrix.h:42
std::vector< T > getVector() const
Definition: Matrix.cpp:77
std::string str() const
Convert the matrix into a simple linear string expression.
Definition: Matrix.cpp:1564
The concrete, templated class for properties.
std::shared_ptr< IPeaksWorkspace > IPeaksWorkspace_sptr
shared pointer to Mantid::API::IPeaksWorkspace
@ InOut
Both an input & output workspace.
Definition: Property.h:55
@ Output
An output workspace.
Definition: Property.h:54