22using namespace Geometry;
24using namespace Kernel;
30 auto mustBePositive = std::make_shared<BoundedValidator<double>>();
31 mustBePositive->setLower(0.0);
33 auto reasonable_angle = std::make_shared<BoundedValidator<double>>();
34 reasonable_angle->setLower(5.0);
35 reasonable_angle->setUpper(175.0);
39 "Input Peaks Workspace");
42 "Lattice parameter a");
45 "Lattice parameter b");
48 "Lattice parameter c");
52 "Lattice parameter alpha");
56 "Lattice parameter beta");
60 "Lattice parameter gamma");
63 "Index of the peaks in the table workspace to be used. If no "
64 "index are provided, all will be used.");
66 declareProperty(
"dTolerance", 0.01,
"Tolerance for peak positions in d-spacing");
68 std::vector<int> extents(6, 0);
77 "A comma separated list of min, max for each of H, K and L,\n"
78 "Specifies the search extents applied for H K L values "
79 "associated with the peaks.");
89 size_t npeaks = peakCandidates.size();
90 for (std::size_t p = 0; p < npeaks; p++) {
91 for (std::size_t q = 0; q < npeaks; q++) {
96 peakCandidates[p].clean(peakCandidates[q], unitcell,
109 bool all_collinear =
true;
110 size_t npeaks = peakCandidates.size();
111 for (std::size_t i = 0; i < npeaks; i++) {
112 for (std::size_t j = i; j < npeaks; j++) {
113 double anglerad = peakCandidates[i].angle(peakCandidates[j]);
114 if (anglerad > 2.0 * M_PI / 180.0 && anglerad < 178.0 * M_PI / 180.0) {
115 all_collinear =
false;
122 throw std::runtime_error(
"Angles between all pairs of peaks are too small");
132 std::vector<int> peakindices =
getProperty(
"PeakIndices");
137 std::size_t npeaks = peakindices.size();
138 if (npeaks >
size_t(ws->getNumberPeaks())) {
139 throw std::runtime_error(
"Cannot have more peaks indices than actual peaks");
141 if (npeaks == 1 || ws->getNumberPeaks() < 2) {
142 throw std::runtime_error(
"At least 2 peaks are required for this algorithm to work");
146 npeaks = ws->getNumberPeaks();
147 peakindices.reserve(npeaks);
148 for (
int i = 1; i <= int(npeaks); i++)
150 peakindices.emplace_back(i);
153 "in the workspace for the calculation.");
164 std::vector<int> extents =
getProperty(
"SearchExtents");
165 if (extents.size() != 6) {
166 std::stringstream stream;
167 stream <<
"Expected 6 elements for the extents. Got: " << extents.size();
168 throw std::runtime_error(stream.str());
174 std::vector<PeakCandidate> peaks;
176 for (std::size_t i = 0; i < npeaks; i++) {
177 int row = peakindices[i] - 1;
179 throw std::runtime_error(
"Cannot have a peak index < 0.");
181 IPeak &peak = ws->getPeak(row);
183 peaks.emplace_back(Qs[0], Qs[1], Qs[2]);
185 assert(peaks.size() >= 2);
193 for (
int h = extents[0];
h < extents[1];
h++) {
194 for (
int k = extents[2]; k < extents[3]; k++) {
195 for (
int l = extents[4]; l < extents[5]; l++) {
196 double dspacing = unitcell.
d(
h, k, l);
197 for (std::size_t p = 0; p < npeaks; p++) {
198 double dSpacingPeaks = peaks[p].getdSpacing();
199 if (std::abs(dspacing - dSpacingPeaks) < dtol)
200 peaks[p].addHKL(
h, k, l);
227 for (std::size_t i = 0; i < npeaks; i++) {
230 row = peakindices[i] - 1;
231 IPeak &peak = ws->getPeak(row);
232 const V3D hkl = peaks[i].getHKL();
234 std::stringstream stream;
235 stream <<
"Peak Index: " << row <<
" HKL: " << hkl;
237 }
catch (std::logic_error &) {
238 std::stringstream msg;
239 msg <<
"Peak Index: " << row + 1 <<
" cannot be assigned a single HKL set.";
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Helper class for reporting progress from algorithms.
A property class for workspaces.
void validateNotColinear(const std::vector< PeakCandidate > &peakCandidates) const
Check that not all peaks are colinear and throw if they are not.
void init() override
Initialisation method.
void exec() override
Executes the algorithm.
void cullHKLs(std::vector< PeakCandidate > &peakCandidates, Mantid::Geometry::UnitCell &unitcell)
Culling method to direct the removal of hkl values off peaks where they cannot sit.
Structure describing a single-crystal peak.
virtual void setHKL(double H, double K, double L)=0
virtual Mantid::Kernel::V3D getQSampleFrame() const =0
Class to implement unit cell of crystals.
double d(double h, double k, double l) const
Return d-spacing ( ) for a given h,k,l coordinate.
Support for a property that holds an array of values.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
The concrete, templated class for properties.
std::shared_ptr< PeaksWorkspace > PeaksWorkspace_sptr
Typedef for a shared pointer to a peaks workspace.
static constexpr double h
Planck constant in J*s.
@ InOut
Both an input & output workspace.
@ Input
An input workspace.