30 "Input Peaks Workspace");
32 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
33 mustBePositive->setLower(1);
36 "Form number for the desired cell");
37 this->
declareProperty(
"Apply",
false,
"Update UB and re-index the peaks");
41 "The number of indexed peaks if apply==true.");
44 "The average HKL indexing error if apply==true.");
46 this->
declareProperty(
"AllowPermutations",
true,
"Allow permutations of conventional cells");
48 "The transformation matrix");
56 std::vector<V3D> miller_ind;
57 std::vector<V3D> q_vectors;
58 std::vector<V3D> q_vectors0;
60 int npeaks = ws->getNumberPeaks();
63 miller_ind.reserve(npeaks);
64 q_vectors.reserve(npeaks);
65 q_vectors0.reserve(npeaks);
67 for (
int i = 0; i < npeaks; i++)
68 q_vectors0.emplace_back(ws->getPeak(i).getQSampleFrame() - modUB * ws->getPeak(i).getIntMNP() * 2 * M_PI);
74 auto nindexed_old =
static_cast<int>(q_vectors.size());
76 bool latErrorsValid =
true;
77 if (nindexed_old < .8 * nindexed_new || .8 * nindexed_old > nindexed_new)
78 latErrorsValid =
false;
82 for (
int row = 0; row < 3; row++)
83 for (
int col = 0; col < 3; col++) {
84 double diff =
fabs(UB[row][col] - newUB1[row][col]);
85 double V = std::max<double>(
fabs(UB[row][col]),
fabs(newUB1[row][col]));
91 if (maxEntry == 0 || maxDiff / maxEntry > .1)
92 latErrorsValid =
false;
95 if (!latErrorsValid) {
96 std::fill(sigabc.begin(), sigabc.end(), 0.);
105 int &num_indexed,
double &average_error) {
108 std::vector<double> sigabc(6);
109 int n_peaks = ws->getNumberPeaks();
111 std::vector<V3D> miller_indices;
112 std::vector<V3D> q_vectors;
114 std::unique_ptr<Geometry::OrientedLattice> o_lattice =
115 std::make_unique<OrientedLattice>(ws->mutableSample().getOrientedLattice());
123 o_lattice->setUB(newUB);
125 DblMatrix modHKL = o_lattice->getModHKL();
129 modHKL = Tref * modHKL;
131 o_lattice->setModHKL(modHKL);
133 for (
int i = 0; i < n_peaks; i++) {
134 IPeak &peak = ws->getPeak(i);
140 for (
int i = 0; i < n_peaks; i++) {
141 IPeak &peak = ws->getPeak(i);
142 V3D hkl = miller_indices[i];
149 o_lattice->setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], sigabc[5]);
151 ws->mutableSample().setOrientedLattice(std::move(o_lattice));
159 throw std::runtime_error(
"Could not read the peaks workspace");
165 bool allowPermutations = this->
getProperty(
"AllowPermutations");
168 throw std::runtime_error(
"ERROR: The stored UB is not a valid orientation matrix");
184 g_log.
notice() <<
"Reduced to Conventional Cell Transformation Matrix = " << T.
str() <<
'\n';
189 double average_error = 0.0;
194 g_log.
notice() <<
"Re-indexed the peaks with the new UB. \n";
195 g_log.
notice() <<
"Now, " << num_indexed <<
" are indexed with average error " << average_error <<
'\n';
#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.
A property class for workspaces.
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
Structure describing a single-crystal peak.
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 getIntMNP() const =0
static int GetIndexedPeaks(const Kernel::DblMatrix &UB, const std::vector< Kernel::V3D > &q_vectors, double required_tolerance, std::vector< Kernel::V3D > &miller_indices, std::vector< Kernel::V3D > &indexed_qs, double &fit_error)
Get lists of indices and Qs for peaks indexed by the specified UB matrix.
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 int NumberIndexed(const Kernel::DblMatrix &UB, const std::vector< Kernel::V3D > &q_vectors, double tolerance)
Calculate the number of Q vectors that are mapped to integer indices by UB.
static double Optimize_UB(Kernel::DblMatrix &UB, const std::vector< Kernel::V3D > &hkl_vectors, const std::vector< Kernel::V3D > &q_vectors, std::vector< double > &sigabc)
Find the UB matrix that most nearly maps hkl to qxyz for 3 or more peaks.
static int CalculateMillerIndices(const Kernel::DblMatrix &UB, const std::vector< Kernel::V3D > &q_vectors, double tolerance, std::vector< Kernel::V3D > &miller_indices, double &ave_error)
Given a UB, get list of Miller indices for specifed Qs and tolerance.
static ConventionalCell GetCellForForm(const Kernel::DblMatrix &UB, size_t form_num, bool allowPermutations=false)
Get the best conventional cell for the form number, using the specified UB, and three related "almost...
Support for a property that holds an array of values.
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.
T Invert()
LU inversion routine.
std::vector< T > getVector() const
std::string str() const
Convert the matrix into a simple linear string expression.
The concrete, templated class for properties.
std::shared_ptr< IPeaksWorkspace > IPeaksWorkspace_sptr
shared pointer to Mantid::API::IPeaksWorkspace
@ InOut
Both an input & output workspace.
@ Input
An input workspace.
@ Output
An output workspace.