Mantid
Loading...
Searching...
No Matches
CalculatePeaksHKL.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"
14
15using namespace Mantid::Kernel;
16using namespace Mantid::Geometry;
17using namespace Mantid::API;
18using namespace Mantid::DataObjects;
19
20namespace Mantid::Crystal {
21
22// Register the algorithm into the AlgorithmFactory
23DECLARE_ALGORITHM(CalculatePeaksHKL)
24
25
26const std::string CalculatePeaksHKL::name() const { return "CalculatePeaksHKL"; }
27
29int CalculatePeaksHKL::version() const { return 1; }
30
32const std::string CalculatePeaksHKL::category() const { return "Crystal\\Peaks"; }
33
37 this->declareProperty(std::make_unique<WorkspaceProperty<IPeaksWorkspace>>("PeaksWorkspace", "", Direction::InOut),
38 "Input Peaks Workspace");
39
40 this->declareProperty("OverWrite", false, "Overwrite existing miller indices as well as empty ones.");
41
42 this->declareProperty(std::make_unique<PropertyWithValue<int>>("NumIndexed", 0, Direction::Output),
43 "Gets set with the number of indexed peaks.");
44}
45
49 API::IPeaksWorkspace_sptr ws = getProperty("PeaksWorkspace");
50 const bool overwrite = getProperty("OverWrite");
51 const int n_peaks = ws->getNumberPeaks();
52
53 OrientedLattice o_lattice = ws->mutableSample().getOrientedLattice();
54 const Matrix<double> &UB = o_lattice.getUB();
55
56 DblMatrix UB_inverse(UB);
57
58 if (IndexingUtils::CheckUB(UB)) {
59 UB_inverse.Invert();
60 } else {
61 throw std::runtime_error("The UB is not valid");
62 }
63
64 int peaksIndexed = 0;
65 for (int i = 0; i < n_peaks; i++) {
66 IPeak &peak = ws->getPeak(i);
67 if (overwrite || (peak.getHKL().nullVector())) {
68 V3D qlab = peak.getQSampleFrame();
69 V3D hkl = UB_inverse * qlab / (2.0 * M_PI);
70 peak.setHKL(hkl);
71 peak.setIntHKL(hkl);
72 ++peaksIndexed;
73 }
74 }
75 setProperty("NumIndexed", peaksIndexed);
76}
77
78} // 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
A property class for workspaces.
CalculatePeaksHKL : Calculate the HKL value for each peak without any rounding or optimization of the...
const std::string category() const override
Algorithm's category for identification.
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm's properties.
int version() const override
Algorithm's version for identification.
Structure describing a single-crystal peak.
Definition: IPeak.h:26
virtual void setHKL(double H, double K, double L)=0
virtual Mantid::Kernel::V3D getQSampleFrame() const =0
virtual void setIntHKL(const Mantid::Kernel::V3D &HKL)=0
virtual Mantid::Kernel::V3D getHKL() const =0
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.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
Numerical Matrix class.
Definition: Matrix.h:42
T Invert()
LU inversion routine.
Definition: Matrix.cpp:924
The concrete, templated class for properties.
Class for 3D vectors.
Definition: V3D.h:34
bool nullVector(const double tolerance=1e-3) const noexcept
Determine if the point is null.
Definition: V3D.cpp:241
std::shared_ptr< IPeaksWorkspace > IPeaksWorkspace_sptr
shared pointer to Mantid::API::IPeaksWorkspace
STL namespace.
@ InOut
Both an input & output workspace.
Definition: Property.h:55
@ Output
An output workspace.
Definition: Property.h:54