Skip to content
Snippets Groups Projects
Unverified Commit 0931f865 authored by Simon Heybrock's avatar Simon Heybrock Committed by GitHub
Browse files

Merge pull request #21585 from mantidproject/15552_engg_gui_gsas_model

Engineering Diffraction GUI GSAS model
parents 3ca93cdd 5d955271
No related merge requests found
......@@ -30,6 +30,7 @@ set ( TEST_FILES
test/ALCLatestFileFinderTest.h
test/ALCPeakFittingModelTest.h
test/ALCPeakFittingPresenterTest.h
test/EnggDiffGSASFittingModelTest.h
test/EnggDiffGSASFittingPresenterTest.h
test/EnggDiffFittingModelTest.h
test/EnggDiffFittingPresenterTest.h
......
......@@ -2,6 +2,7 @@ set ( SRC_FILES
EnggDiffFittingModel.cpp
EnggDiffFittingPresenter.cpp
EnggDiffFittingViewQtWidget.cpp
EnggDiffGSASFittingModel.cpp
EnggDiffGSASFittingPresenter.cpp
EnggDiffractionPresenter.cpp
EnggDiffractionViewQtGUI.cpp
......@@ -15,6 +16,7 @@ set ( INC_FILES
EnggDiffFittingPresWorker.h
EnggDiffFittingPresenter.h
EnggDiffFittingViewQtWidget.h
EnggDiffGSASFittingModel.h
EnggDiffGSASFittingPresenter.h
EnggDiffGSASRefinementMethod.h
EnggDiffractionPresWorker.h
......
#include "EnggDiffGSASFittingModel.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Run.h"
using namespace Mantid;
namespace {
std::string stripWSNameFromFilename(const std::string &fullyQualifiedFilename) {
std::vector<std::string> directories;
boost::split(directories, fullyQualifiedFilename, boost::is_any_of("\\/"));
const std::string filename = directories.back();
std::vector<std::string> filenameSegments;
boost::split(filenameSegments, filename, boost::is_any_of("."));
return filenameSegments[0];
}
size_t getBankID(API::MatrixWorkspace_const_sptr ws) {
const static std::string bankIDPropertyName = "bankid";
if (ws->run().hasProperty(bankIDPropertyName)) {
const auto log = dynamic_cast<Kernel::PropertyWithValue<int> *>(
ws->run().getLogData(bankIDPropertyName));
return boost::lexical_cast<size_t>(log->value());
}
throw std::runtime_error("Bank ID was not set in the sample logs.");
}
} // anonymous namespace
namespace MantidQt {
namespace CustomInterfaces {
void EnggDiffGSASFittingModel::addFitResultsToMaps(
const int runNumber, const size_t bank, const double rwp,
const std::string &fittedPeaksWSName,
const std::string &latticeParamsTableName) {
addRwp(runNumber, bank, rwp);
API::AnalysisDataServiceImpl &ADS = API::AnalysisDataService::Instance();
const auto fittedPeaks =
ADS.retrieveWS<API::MatrixWorkspace>(fittedPeaksWSName);
addFittedPeaks(runNumber, bank, fittedPeaks);
const auto latticeParams =
ADS.retrieveWS<API::ITableWorkspace>(latticeParamsTableName);
addLatticeParams(runNumber, bank, latticeParams);
}
void EnggDiffGSASFittingModel::addFittedPeaks(const int runNumber,
const size_t bank,
API::MatrixWorkspace_sptr ws) {
m_fittedPeaksMap.add(runNumber, bank, ws);
}
void EnggDiffGSASFittingModel::addFocusedRun(const int runNumber,
const size_t bank,
API::MatrixWorkspace_sptr ws) {
m_focusedWorkspaceMap.add(runNumber, bank, ws);
}
void EnggDiffGSASFittingModel::addLatticeParams(
const int runNumber, const size_t bank, API::ITableWorkspace_sptr table) {
m_latticeParamsMap.add(runNumber, bank, table);
}
void EnggDiffGSASFittingModel::addRwp(const int runNumber, const size_t bank,
const double rwp) {
m_rwpMap.add(runNumber, bank, rwp);
}
namespace {
std::string generateFittedPeaksWSName(const int runNumber, const size_t bank) {
return std::to_string(runNumber) + "_" + std::to_string(bank) +
"_gsasii_fitted_peaks";
}
std::string generateLatticeParamsName(const int runNumber, const size_t bank) {
return std::to_string(runNumber) + "_" + std::to_string(bank) +
"_lattice_params";
}
}
bool EnggDiffGSASFittingModel::doPawleyRefinement(
const int runNumber, const size_t bank, const std::string &instParamFile,
const std::vector<std::string> &phaseFiles, const std::string &pathToGSASII,
const std::string &GSASIIProjectFile, const double dMin,
const double negativeWeight) {
const auto inputWS = getFocusedWorkspace(runNumber, bank);
if (!inputWS) {
return false;
}
const auto outputWSName = generateFittedPeaksWSName(runNumber, bank);
const auto latticeParamsName = generateLatticeParamsName(runNumber, bank);
const auto rwp = doGSASRefinementAlgorithm(
*inputWS, outputWSName, latticeParamsName, "Pawley refinement",
instParamFile, phaseFiles, pathToGSASII, GSASIIProjectFile, dMin,
negativeWeight);
if (!rwp) {
return false;
}
addFitResultsToMaps(runNumber, bank, *rwp, outputWSName, latticeParamsName);
return true;
}
boost::optional<double> EnggDiffGSASFittingModel::doGSASRefinementAlgorithm(
API::MatrixWorkspace_sptr inputWorkspace,
const std::string &outputWorkspaceName,
const std::string &latticeParamsName, const std::string &refinementMethod,
const std::string &instParamFile,
const std::vector<std::string> &phaseFiles, const std::string &pathToGSASII,
const std::string &GSASIIProjectFile, const double dMin,
const double negativeWeight) {
double rwp = -1;
try {
auto gsasAlg =
API::AlgorithmManager::Instance().create("GSASIIRefineFitPeaks");
gsasAlg->setProperty("RefinementMethod", refinementMethod);
gsasAlg->setProperty("InputWorkspace", inputWorkspace);
gsasAlg->setProperty("OutputWorkspace", outputWorkspaceName);
gsasAlg->setProperty("LatticeParameters", latticeParamsName);
gsasAlg->setProperty("InstrumentFile", instParamFile);
gsasAlg->setProperty("PhaseInfoFiles", phaseFiles);
gsasAlg->setProperty("PathToGSASII", pathToGSASII);
gsasAlg->setProperty("SaveGSASIIProjectFile", GSASIIProjectFile);
gsasAlg->setProperty("PawleyDMin", dMin);
gsasAlg->setProperty("PawleyNegativeWeight", negativeWeight);
gsasAlg->execute();
rwp = gsasAlg->getProperty("Rwp");
} catch (const std::exception) {
return boost::none;
}
return rwp;
}
bool EnggDiffGSASFittingModel::doRietveldRefinement(
const int runNumber, const size_t bank, const std::string &instParamFile,
const std::vector<std::string> &phaseFiles, const std::string &pathToGSASII,
const std::string &GSASIIProjectFile) {
const auto inputWS = getFocusedWorkspace(runNumber, bank);
if (!inputWS) {
return false;
}
const auto outputWSName = generateFittedPeaksWSName(runNumber, bank);
const auto latticeParamsName = generateLatticeParamsName(runNumber, bank);
const auto rwp = doGSASRefinementAlgorithm(
*inputWS, outputWSName, latticeParamsName, "Rietveld refinement",
instParamFile, phaseFiles, pathToGSASII, GSASIIProjectFile,
DEFAULT_PAWLEY_DMIN, DEFAULT_PAWLEY_NEGATIVE_WEIGHT);
if (!rwp) {
return false;
}
addFitResultsToMaps(runNumber, bank, *rwp, outputWSName, latticeParamsName);
return true;
}
boost::optional<API::MatrixWorkspace_sptr>
EnggDiffGSASFittingModel::getFittedPeaks(const int runNumber,
const size_t bank) const {
return getFromRunMapOptional(m_fittedPeaksMap, runNumber, bank);
}
boost::optional<API::MatrixWorkspace_sptr>
EnggDiffGSASFittingModel::getFocusedWorkspace(const int runNumber,
const size_t bank) const {
return getFromRunMapOptional(m_focusedWorkspaceMap, runNumber, bank);
}
boost::optional<API::ITableWorkspace_sptr>
EnggDiffGSASFittingModel::getLatticeParams(const int runNumber,
const size_t bank) const {
return getFromRunMapOptional(m_latticeParamsMap, runNumber, bank);
}
std::vector<std::pair<int, size_t>>
EnggDiffGSASFittingModel::getRunLabels() const {
return m_focusedWorkspaceMap.getRunNumbersAndBankIDs();
}
boost::optional<double>
EnggDiffGSASFittingModel::getRwp(const int runNumber, const size_t bank) const {
return getFromRunMapOptional(m_rwpMap, runNumber, bank);
}
bool EnggDiffGSASFittingModel::hasFittedPeaksForRun(const int runNumber,
const size_t bank) const {
return m_fittedPeaksMap.contains(runNumber, bank);
}
bool EnggDiffGSASFittingModel::hasFocusedRun(const int runNumber,
const size_t bank) const {
return m_focusedWorkspaceMap.contains(runNumber, bank);
}
bool EnggDiffGSASFittingModel::loadFocusedRun(const std::string &filename) {
const auto wsName = stripWSNameFromFilename(filename);
try {
auto loadAlg = API::AlgorithmManager::Instance().create("Load");
loadAlg->setProperty("Filename", filename);
loadAlg->setProperty("OutputWorkspace", wsName);
loadAlg->execute();
} catch (const std::exception) {
return false;
}
API::AnalysisDataServiceImpl &ADS = API::AnalysisDataService::Instance();
const auto ws = ADS.retrieveWS<API::MatrixWorkspace>(wsName);
const auto runNumber = ws->getRunNumber();
const auto bank = getBankID(ws);
m_focusedWorkspaceMap.add(runNumber, bank, ws);
return true;
}
} // CustomInterfaces
} // MantidQt
#ifndef MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_GSASFITTINGMODEL_H_
#define MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_GSASFITTINGMODEL_H_
#include "DllConfig.h"
#include "IEnggDiffGSASFittingModel.h"
#include "RunMap.h"
namespace MantidQt {
namespace CustomInterfaces {
class MANTIDQT_ENGGDIFFRACTION_DLL EnggDiffGSASFittingModel
: public IEnggDiffGSASFittingModel {
public:
bool doPawleyRefinement(const int runNumber, const size_t bank,
const std::string &instParamFile,
const std::vector<std::string> &phaseFiles,
const std::string &pathToGSASII,
const std::string &GSASIIProjectFile,
const double dMin,
const double negativeWeight) override;
bool doRietveldRefinement(const int runNumber, const size_t bank,
const std::string &instParamFile,
const std::vector<std::string> &phaseFiles,
const std::string &pathToGSASII,
const std::string &GSASIIProjectFile) override;
boost::optional<Mantid::API::MatrixWorkspace_sptr>
getFittedPeaks(const int runNumber, const size_t bank) const override;
boost::optional<Mantid::API::MatrixWorkspace_sptr>
getFocusedWorkspace(const int runNumber, const size_t bank) const override;
boost::optional<Mantid::API::ITableWorkspace_sptr>
getLatticeParams(const int runNumber, const size_t bank) const override;
std::vector<std::pair<int, size_t>> getRunLabels() const override;
boost::optional<double> getRwp(const int runNumber,
const size_t bank) const override;
bool hasFittedPeaksForRun(const int runNumber,
const size_t bank) const override;
bool loadFocusedRun(const std::string &filename) override;
protected:
/// The following methods are marked as protected so that they can be exposed
/// by a helper class in the tests
// Add a workspace to the fitted peaks map
void addFittedPeaks(const int runNumber, const size_t bank,
Mantid::API::MatrixWorkspace_sptr ws);
/// Add a workspace to the focused workspace map
void addFocusedRun(const int runNumber, const size_t bank,
Mantid::API::MatrixWorkspace_sptr ws);
/// Add a lattice parameter table to the map
void addLatticeParams(const int runNumber, const size_t bank,
Mantid::API::ITableWorkspace_sptr table);
/// Add an rwp value to the rwp map
void addRwp(const int runNumber, const size_t bank, const double rwp);
/// Get whether a focused run has been loaded with a given runNumber and bank
/// ID.
bool hasFocusedRun(const int runNumber, const size_t bank) const;
private:
static constexpr double DEFAULT_PAWLEY_DMIN = 1;
static constexpr double DEFAULT_PAWLEY_NEGATIVE_WEIGHT = 0;
static const size_t MAX_BANKS = 2;
RunMap<MAX_BANKS, Mantid::API::MatrixWorkspace_sptr> m_fittedPeaksMap;
RunMap<MAX_BANKS, Mantid::API::MatrixWorkspace_sptr> m_focusedWorkspaceMap;
RunMap<MAX_BANKS, Mantid::API::ITableWorkspace_sptr> m_latticeParamsMap;
RunMap<MAX_BANKS, double> m_rwpMap;
/// Add Rwp, fitted peaks workspace and lattice params table to their
/// respective RunMaps
void addFitResultsToMaps(const int runNumber, const size_t bank,
const double rwp,
const std::string &fittedPeaksWSName,
const std::string &latticeParamsTableName);
template <typename T>
boost::optional<T> getFromRunMapOptional(const RunMap<MAX_BANKS, T> &map,
const int runNumber,
const size_t bank) const {
if (map.contains(runNumber, bank)) {
return map.get(runNumber, bank);
}
return boost::none;
}
/// Run GSASIIRefineFitPeaks
/// Note this must be virtual so that it can be mocked out by the helper class
/// in EnggDiffGSASFittingModelTest
/// Returns Rwp of the fit (empty optional if fit was unsuccessful)
virtual boost::optional<double> doGSASRefinementAlgorithm(
Mantid::API::MatrixWorkspace_sptr inputWorkspace,
const std::string &outputWorkspaceName,
const std::string &latticeParamsName, const std::string &refinementMethod,
const std::string &instParamFile,
const std::vector<std::string> &phaseFiles,
const std::string &pathToGSASII, const std::string &GSASIIProjectFile,
const double dMin, const double negativeWeight);
};
} // CustomInterfaces
} // MantidQt
#endif // MANTIDQTCUSTOMINTERFACES_ENGGDIFFRACTION_GSASFITTINGMODEL_H_
#ifndef MANTIDQT_CUSTOMINTERFACES_ENGGDIFFGSASFITTINGMODELTEST_H_
#define MANTIDQT_CUSTOMINTERFACES_ENGGDIFFGSASFITTINGMODELTEST_H_
#include "../EnggDiffraction/EnggDiffGSASFittingModel.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/TableRow.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidTestHelpers/WorkspaceCreationHelper.h"
#include <cxxtest/TestSuite.h>
using namespace Mantid;
using namespace MantidQt::CustomInterfaces;
namespace { // Helpers
template <size_t numColumns, size_t numRows>
API::ITableWorkspace_sptr createDummyTable(
const std::array<std::string, numColumns> &columnHeadings,
const std::array<std::array<double, numColumns>, numRows> tableContents) {
auto table = API::WorkspaceFactory::Instance().createTable();
for (const auto &header : columnHeadings) {
table->addColumn("double", header);
}
for (const auto &row : tableContents) {
API::TableRow newRow = table->appendRow();
for (const auto value : row) {
newRow << value;
}
}
return table;
}
// Helper class with some protected methods exposed
class TestEnggDiffGSASFittingModel : public EnggDiffGSASFittingModel {
public:
bool containsFocusedRun(const int runNumber, const size_t bank) const;
void addFittedPeaksWS(const int runNumber, const size_t bank,
API::MatrixWorkspace_sptr ws);
void addFocusedWorkspace(const int runNumber, const size_t bank,
API::MatrixWorkspace_sptr ws);
void addLatticeParamTable(const int runNumber, const size_t bank,
API::ITableWorkspace_sptr table);
void addRwpValue(const int runNumber, const size_t bank, const double rwp);
private:
inline boost::optional<double> doGSASRefinementAlgorithm(
API::MatrixWorkspace_sptr inputWorkspace,
const std::string &outputWorkspaceName,
const std::string &latticeParamsName, const std::string &refinementMethod,
const std::string &instParamFile,
const std::vector<std::string> &phaseFiles,
const std::string &pathToGSASII, const std::string &GSASIIProjectFile,
const double dMin, const double negativeWeight) override;
};
inline void TestEnggDiffGSASFittingModel::addFittedPeaksWS(
const int runNumber, const size_t bank, API::MatrixWorkspace_sptr ws) {
addFittedPeaks(runNumber, bank, ws);
}
inline void TestEnggDiffGSASFittingModel::addFocusedWorkspace(
const int runNumber, const size_t bank, API::MatrixWorkspace_sptr ws) {
addFocusedRun(runNumber, bank, ws);
}
inline void TestEnggDiffGSASFittingModel::addLatticeParamTable(
const int runNumber, const size_t bank, API::ITableWorkspace_sptr table) {
addLatticeParams(runNumber, bank, table);
}
inline void TestEnggDiffGSASFittingModel::addRwpValue(const int runNumber,
const size_t bank,
const double rwp) {
addRwp(runNumber, bank, rwp);
}
inline bool
TestEnggDiffGSASFittingModel::containsFocusedRun(const int runNumber,
const size_t bank) const {
return hasFocusedRun(runNumber, bank);
}
inline boost::optional<double>
TestEnggDiffGSASFittingModel::doGSASRefinementAlgorithm(
API::MatrixWorkspace_sptr inputWorkspace,
const std::string &outputWorkspaceName,
const std::string &latticeParamsName, const std::string &refinementMethod,
const std::string &instParamFile,
const std::vector<std::string> &phaseFiles, const std::string &pathToGSASII,
const std::string &GSASIIProjectFile, const double dMin,
const double negativeWeight) {
// Mock method - just create some dummy output and ignore all the parameters
// Do some pointless casts to stifle unused parameter warnings
(void)GSASIIProjectFile;
(void)refinementMethod;
(void)dMin;
(void)phaseFiles;
(void)pathToGSASII;
(void)negativeWeight;
(void)inputWorkspace;
(void)instParamFile;
const static std::array<std::string, 3> columnHeadings = {{"a", "b", "c"}};
const static std::array<std::array<double, 3>, 1> targetTableValues = {
{{{1, 2, 3}}}};
const auto latticeParams =
createDummyTable(columnHeadings, targetTableValues);
API::AnalysisDataServiceImpl &ADS = API::AnalysisDataService::Instance();
ADS.add(latticeParamsName, latticeParams);
API::MatrixWorkspace_sptr ws =
WorkspaceCreationHelper::create2DWorkspaceBinned(4, 4, 0.5);
ADS.add(outputWorkspaceName, ws);
return 75;
}
} // Anonymous namespace
class EnggDiffGSASFittingModelTest : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static EnggDiffGSASFittingModelTest *createSuite() {
return new EnggDiffGSASFittingModelTest();
}
static void destroySuite(EnggDiffGSASFittingModelTest *suite) {
delete suite;
}
EnggDiffGSASFittingModelTest() { API::FrameworkManager::Instance(); }
void test_validLoadRun() {
const static std::string inputFilename = "ENGINX_277208_focused_bank_2.nxs";
TestEnggDiffGSASFittingModel model;
bool success = false;
TS_ASSERT_THROWS_NOTHING(success = model.loadFocusedRun(inputFilename));
TS_ASSERT(success);
TS_ASSERT(model.containsFocusedRun(277208, 2));
}
void test_invalidLoadRun() {
const static std::string inputFilename = "ENGINX_277209_focused_bank_2.nxs";
TestEnggDiffGSASFittingModel model;
bool success = false;
TS_ASSERT_THROWS_NOTHING(success = model.loadFocusedRun(inputFilename));
TS_ASSERT(!success);
}
void test_getFocusedRun() {
TestEnggDiffGSASFittingModel model;
API::MatrixWorkspace_sptr ws =
API::WorkspaceFactory::Instance().create("Workspace2D", 1, 10, 10);
model.addFocusedWorkspace(123, 1, ws);
boost::optional<API::MatrixWorkspace_sptr> retrievedWS;
TS_ASSERT_THROWS_NOTHING(retrievedWS = model.getFocusedWorkspace(123, 1));
TS_ASSERT(retrievedWS);
TS_ASSERT_EQUALS(ws, *retrievedWS);
TS_ASSERT_THROWS_NOTHING(retrievedWS = model.getFocusedWorkspace(456, 2));
TS_ASSERT_EQUALS(retrievedWS, boost::none);
}
void test_getRunLabels() {
TestEnggDiffGSASFittingModel model;
for (int i = 1; i < 5; i++) {
API::MatrixWorkspace_sptr ws =
API::WorkspaceFactory::Instance().create("Workspace2D", 1, 10, 10);
model.addFocusedWorkspace(i * 111, i % 2 + 1, ws);
}
std::vector<std::pair<int, size_t>> runLabels;
TS_ASSERT_THROWS_NOTHING(runLabels = model.getRunLabels());
TS_ASSERT_EQUALS(runLabels.size(), 4);
for (int i = 1; i < 5; i++) {
TS_ASSERT_EQUALS(runLabels[i - 1],
std::make_pair(i * 111, size_t(i % 2 + 1)));
}
}
void test_getFittedPeaks() {
TestEnggDiffGSASFittingModel model;
API::MatrixWorkspace_sptr ws =
API::WorkspaceFactory::Instance().create("Workspace2D", 1, 10, 10);
model.addFittedPeaksWS(123, 1, ws);
boost::optional<API::MatrixWorkspace_sptr> retrievedWS;
TS_ASSERT_THROWS_NOTHING(retrievedWS = model.getFittedPeaks(123, 1));
TS_ASSERT(retrievedWS);
TS_ASSERT_EQUALS(ws, *retrievedWS);
TS_ASSERT_THROWS_NOTHING(retrievedWS = model.getFittedPeaks(456, 2));
TS_ASSERT_EQUALS(retrievedWS, boost::none);
}
void test_hasFittedPeaksForRun() {
TestEnggDiffGSASFittingModel model;
API::MatrixWorkspace_sptr ws =
API::WorkspaceFactory::Instance().create("Workspace2D", 1, 10, 10);
model.addFittedPeaksWS(123, 1, ws);
TS_ASSERT(model.hasFittedPeaksForRun(123, 1));
TS_ASSERT(!model.hasFittedPeaksForRun(456, 1));
}
void test_getRwp() {
TestEnggDiffGSASFittingModel model;
const double rwp = 75.5;
model.addRwpValue(123, 1, rwp);
auto retrievedRwp = boost::make_optional<double>(false, double());
TS_ASSERT_THROWS_NOTHING(retrievedRwp = model.getRwp(123, 1));
TS_ASSERT(retrievedRwp);
TS_ASSERT_EQUALS(rwp, *retrievedRwp);
TS_ASSERT_THROWS_NOTHING(retrievedRwp = model.getRwp(456, 2));
TS_ASSERT_EQUALS(retrievedRwp, boost::none);
}
void test_getLatticeParams() {
const std::array<std::string, 3> columnHeadings = {{"a", "b", "c"}};
const std::array<std::array<double, 3>, 1> targetTableValues = {
{{{1, 2, 3}}}};
const auto table = createDummyTable(columnHeadings, targetTableValues);
TestEnggDiffGSASFittingModel model;
TS_ASSERT_THROWS_NOTHING(model.addLatticeParamTable(123, 1, table));
// auto retrievedTable = model.getLatticeParams(123, 1);
boost::optional<API::ITableWorkspace_sptr> retrievedTable;
TS_ASSERT_THROWS_NOTHING(retrievedTable = model.getLatticeParams(123, 1));
TS_ASSERT(retrievedTable);
API::TableRow row = (*retrievedTable)->getRow(0);
const double expectedA = 1;
const double expectedB = 2;
const double expectedC = 3;
auto a = expectedA + 1;
auto b = expectedB + 1;
auto c = expectedC + 1;
TS_ASSERT_THROWS_NOTHING(row >> a >> b >> c);
TS_ASSERT_EQUALS(a, expectedA);
TS_ASSERT_EQUALS(b, expectedB);
TS_ASSERT_EQUALS(c, expectedC);
TS_ASSERT_THROWS_NOTHING(retrievedTable = model.getLatticeParams(456, 2));
TS_ASSERT_EQUALS(retrievedTable, boost::none);
}
void test_pawleyRefinement() {
// Note: due to the reliance on GSAS-II, this cannot test that the algorithm
// is used properly. It tests that, given that the algorithm is used
// properly, results are added to the appropriate maps in the model
TestEnggDiffGSASFittingModel model;
API::MatrixWorkspace_sptr ws =
API::WorkspaceFactory::Instance().create("Workspace2D", 1, 10, 10);
model.addFocusedWorkspace(123, 1, ws);
bool success = false;
TS_ASSERT_THROWS_NOTHING(
success = model.doPawleyRefinement(
123, 1, "", std::vector<std::string>({}), "", "", 0, 0));
TS_ASSERT(success);
const auto rwp = model.getRwp(123, 1);
TS_ASSERT(rwp);
const auto fittedPeaks = model.getFittedPeaks(123, 1);
TS_ASSERT(fittedPeaks);
const auto latticeParams = model.getLatticeParams(123, 1);
TS_ASSERT(latticeParams);
API::AnalysisDataService::Instance().clear();
}
void test_RietveldRefinement() {
// Note: due to the reliance on GSAS-II, this cannot test that the algorithm
// is used properly. It tests that, given that the algorithm is used
// properly, results are added to the appropriate maps in the model
TestEnggDiffGSASFittingModel model;
API::MatrixWorkspace_sptr ws =
API::WorkspaceFactory::Instance().create("Workspace2D", 1, 10, 10);
model.addFocusedWorkspace(123, 1, ws);
bool success = false;
TS_ASSERT_THROWS_NOTHING(
success = model.doRietveldRefinement(
123, 1, "", std::vector<std::string>({}), "", ""));
TS_ASSERT(success);
const auto rwp = model.getRwp(123, 1);
TS_ASSERT(rwp);
const auto fittedPeaks = model.getFittedPeaks(123, 1);
TS_ASSERT(fittedPeaks);
const auto latticeParams = model.getLatticeParams(123, 1);
TS_ASSERT(latticeParams);
API::AnalysisDataService::Instance().clear();
}
};
#endif // MANTIDQT_CUSTOMINTERFACES_ENGGDIFFGSASFITTINGMODELTEST_H_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment