Mantid
Loading...
Searching...
No Matches
ShowPossibleCells.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"
16
17namespace Mantid::Crystal {
18// Register the algorithm into the AlgorithmFactory
19DECLARE_ALGORITHM(ShowPossibleCells)
20
21using namespace Mantid::Kernel;
22using namespace Mantid::API;
23using namespace Mantid::DataObjects;
24using namespace Mantid::Geometry;
25
29 this->declareProperty(std::make_unique<WorkspaceProperty<IPeaksWorkspace>>("PeaksWorkspace", "", Direction::InOut),
30 "Input Peaks Workspace");
31
32 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
33 mustBePositive->setLower(0.0);
34
35 this->declareProperty(
36 std::make_unique<PropertyWithValue<double>>("MaxScalarError", 0.2, mustBePositive, Direction::Input),
37 "Max Scalar Error (0.2)");
38
39 this->declareProperty("BestOnly", true, "Show at most one for each Bravais Lattice");
40
41 this->declareProperty(std::make_unique<PropertyWithValue<int>>("NumberOfCells", 0, Direction::Output),
42 "Gets set with the number of possible cells.");
43
44 this->declareProperty("AllowPermutations", true, "Allow permutations of conventional cells");
45}
46
50 IPeaksWorkspace_const_sptr ws = this->getProperty("PeaksWorkspace");
51 if (!ws) {
52 throw std::runtime_error("Could not read the peaks workspace");
53 }
54
55 OrientedLattice o_lattice = ws->sample().getOrientedLattice();
56 const Matrix<double> &UB = o_lattice.getUB();
57
58 if (!IndexingUtils::CheckUB(UB)) {
59 throw std::runtime_error("ERROR: The stored UB is not a valid orientation matrix");
60 }
61
62 double max_scalar_error = this->getProperty("MaxScalarError");
63 bool best_only = this->getProperty("BestOnly");
64 bool allowPermutations = this->getProperty("AllowPermutations");
65
66 std::vector<ConventionalCell> list = ScalarUtils::GetCells(UB, best_only, allowPermutations);
67
68 ScalarUtils::RemoveHighErrorForms(list, max_scalar_error);
69
70 size_t num_cells = list.size();
71
72 // now tell the user the number of possible conventional cells:
73 g_log.notice() << "Num Cells : " << num_cells << '\n';
74
75 for (size_t i = 0; i < num_cells; i++) {
76 DblMatrix newUB = list[i].GetNewUB();
77 std::string message = list[i].GetDescription() + " Lat Par:" + IndexingUtils::GetLatticeParameterString(newUB);
78
79 g_log.notice(std::string(message));
80 }
81
82 this->setProperty("NumberOfCells", static_cast<int>(num_cells));
83}
84
85} // namespace Mantid::Crystal
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
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 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.
Class to implement UB matrix.
const Kernel::DblMatrix & getUB() const
Get the UB matrix.
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 void RemoveHighErrorForms(std::vector< ConventionalCell > &list, double level)
Remove cells from list that have scalar errors above the specified level.
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
The concrete, templated class for properties.
std::shared_ptr< const IPeaksWorkspace > IPeaksWorkspace_const_sptr
shared pointer to Mantid::API::IPeaksWorkspace (const version)
@ InOut
Both an input & output workspace.
Definition: Property.h:55
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54