Mantid
Loading...
Searching...
No Matches
CountReflections.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
10#include "MantidAPI/Sample.h"
12
14
18
20
21namespace Mantid::Crystal {
22
24
25using namespace Mantid::API;
26using namespace Mantid::DataObjects;
27using namespace Mantid::Geometry;
28using namespace Mantid::Kernel;
29
30// Register the algorithm into the AlgorithmFactory
31DECLARE_ALGORITHM(CountReflections)
32
33//----------------------------------------------------------------------------------------------
34
35
36const std::string CountReflections::name() const { return "CountReflections"; }
37
39int CountReflections::version() const { return 1; }
40
42const std::string CountReflections::category() const { return "Crystal\\Peaks"; }
43
45const std::string CountReflections::summary() const {
46 return "Calculates statistics for a PeaksWorkspace based on symmetry and "
47 "counting reflections.";
48}
49
50//----------------------------------------------------------------------------------------------
54 declareProperty(std::make_unique<WorkspaceProperty<PeaksWorkspace>>("InputWorkspace", "", Direction::Input),
55 "A workspace with peaks to calculate statistics for. Sample "
56 "with valid UB-matrix is required.");
57
58 auto centeringSymbols = getAllReflectionConditionSymbols();
59 declareProperty("LatticeCentering", centeringSymbols[0], std::make_shared<StringListValidator>(centeringSymbols),
60 "Lattice centering of the cell.");
61
62 auto pointGroups = PointGroupFactory::Instance().getAllPointGroupSymbols();
63 declareProperty("PointGroup", "1", std::make_shared<StringListValidator>(pointGroups),
64 "Point group symmetry for completeness and redundancy calculations.");
65
66 declareProperty(std::make_unique<PropertyWithValue<double>>("MinDSpacing", 1.0, Direction::Input),
67 "Minimum d-spacing for completeness calculation.");
68
69 declareProperty(std::make_unique<PropertyWithValue<double>>("MaxDSpacing", 100.0, Direction::Input),
70 "Maximum d-spacing for completeness calculation.");
71
72 declareProperty(std::make_unique<PropertyWithValue<int>>("UniqueReflections", 0, Direction::Output),
73 "Number of unique reflections in data set.");
74
75 declareProperty(std::make_unique<PropertyWithValue<double>>("Completeness", 0.0, Direction::Output),
76 "Completeness of the data set as a fraction between 0 and 1.");
77
78 declareProperty(std::make_unique<PropertyWithValue<double>>("Redundancy", 0.0, Direction::Output),
79 "Average redundancy in data set, depending on point group.");
80
81 declareProperty(std::make_unique<PropertyWithValue<double>>("MultiplyObserved", 0.0, Direction::Output),
82 "Fraction of reflections with more than one observation.");
83
84 declareProperty(std::make_unique<WorkspaceProperty<PeaksWorkspace>>("MissingReflectionsWorkspace", "",
86 "Reflections in specified d-range that are missing in input workspace.");
87}
88
89//----------------------------------------------------------------------------------------------
93 double dMin = getProperty("MinDSpacing");
94 double dMax = getProperty("MaxDSpacing");
95
96 PointGroup_sptr pointGroup = PointGroupFactory::Instance().createPointGroup(getProperty("PointGroup"));
97
99
100 PeaksWorkspace_sptr inputPeaksWorkspace = getProperty("InputWorkspace");
101
102 UnitCell cell = inputPeaksWorkspace->sample().getOrientedLattice();
103
104 PeakStatisticsTools::UniqueReflectionCollection reflections(cell, std::make_pair(dMin, dMax), pointGroup, centering);
105
106 auto peaks = inputPeaksWorkspace->getPeaks();
107 reflections.addObservations(peaks);
108
109 auto possibleUniqueReflections = static_cast<double>(reflections.getUniqueReflectionCount());
110
111 size_t observedUniqueReflections = reflections.getObservedUniqueReflectionCount();
112
113 auto observedUniqueReflectionsD = static_cast<double>(observedUniqueReflections);
114
115 size_t totalReflections = reflections.getObservedReflectionCount();
116
117 if (peaks.size() > totalReflections) {
118 g_log.information() << "There are " << (peaks.size() - totalReflections)
119 << " peaks in the input workspace that fall outside "
120 "the resolution limit and are not considered for "
121 "the calculations."
122 << std::endl;
123 }
124
125 auto multiplyObservedReflections = static_cast<double>(reflections.getObservedUniqueReflectionCount(1));
126
127 setProperty("UniqueReflections", static_cast<int>(observedUniqueReflections));
128 setProperty("Completeness", observedUniqueReflectionsD / possibleUniqueReflections);
129 setProperty("Redundancy", static_cast<double>(totalReflections) / observedUniqueReflectionsD);
130 setProperty("MultiplyObserved", multiplyObservedReflections / observedUniqueReflectionsD);
131
132 PeaksWorkspace_sptr outputWorkspace = getPeaksWorkspace(inputPeaksWorkspace, reflections, pointGroup);
133
134 if (outputWorkspace) {
135 setProperty("MissingReflectionsWorkspace", outputWorkspace);
136 }
137}
138
157 const PointGroup_sptr &pointGroup) const {
158 std::string outputWorkspaceName = getPropertyValue("MissingReflectionsWorkspace");
159
160 if (outputWorkspaceName.empty()) {
161 return PeaksWorkspace_sptr();
162 }
163
164 PeaksWorkspace_sptr rawOutputPeaksWorkspace = getProperty("MissingReflectionsWorkspace");
165
166 PeaksWorkspace_sptr outputPeaksWorkspace = std::dynamic_pointer_cast<PeaksWorkspace>(rawOutputPeaksWorkspace);
167
168 if (outputPeaksWorkspace != templateWorkspace) {
169 outputPeaksWorkspace = templateWorkspace->clone();
170 }
171
172 const auto &missingPeaks = reflections.getUnobservedUniqueReflections();
173
174 std::vector<Peak> peaks;
175 peaks.reserve(missingPeaks.size() * pointGroup->order());
176
177 for (const auto &reflection : missingPeaks) {
178 auto hkls = pointGroup->getEquivalents(reflection);
179
180 for (const auto &hkl : hkls) {
181 Peak peak;
182 peak.setHKL(hkl);
183
184 peaks.emplace_back(peak);
185 }
186 }
187
188 outputPeaksWorkspace->getPeaks().swap(peaks);
189
190 return outputPeaksWorkspace;
191}
192
193} // 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
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
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.
int version() const override
Algorithm's version for identification.
DataObjects::PeaksWorkspace_sptr getPeaksWorkspace(const DataObjects::PeaksWorkspace_sptr &templateWorkspace, const PeakStatisticsTools::UniqueReflectionCollection &reflections, const Geometry::PointGroup_sptr &pointGroup) const
CountReflections::getPeaksWorkspace.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
const std::string category() const override
Algorithm's category for identification.
void init() override
Initialize the algorithm's properties.
void exec() override
Execute the algorithm.
This class computes all possible unique reflections within the specified d-limits,...
std::vector< Kernel::V3D > getUnobservedUniqueReflections() const
List of unobserved unique reflections in resolution range.
size_t getObservedReflectionCount() const
Number of observed reflections.
void addObservations(const std::vector< DataObjects::Peak > &peaks)
Assigns the supplied peaks to the proper UniqueReflection.
size_t getUniqueReflectionCount() const
Total number of unique reflections (theoretically possible).
size_t getObservedUniqueReflectionCount(size_t moreThan=0) const
Number of unique reflections that have more observations than the supplied number (default is 0 - giv...
void setHKL(double H, double K, double L) override
Set all three H,K,L indices of the peak.
Definition: BasePeak.cpp:132
Structure describing a single-crystal peak.
Definition: Peak.h:34
Class to implement unit cell of crystals.
Definition: UnitCell.h:44
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
The concrete, templated class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
std::shared_ptr< ReflectionCondition > ReflectionCondition_sptr
Shared pointer to a ReflectionCondition.
MANTID_GEOMETRY_DLL ReflectionCondition_sptr getReflectionConditionBySymbol(const std::string &symbol)
Returns the ReflectionCondition for the specified centering symbol, see getAllReflectionConditionSymb...
std::shared_ptr< PointGroup > PointGroup_sptr
Shared pointer to a PointGroup.
Definition: PointGroup.h:67
MANTID_GEOMETRY_DLL std::vector< std::string > getAllReflectionConditionSymbols()
Returns all centering symbols.
STL namespace.
Describes the direction (within an algorithm) of a Property.
Definition: Property.h:50
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54