Commit 3508c350 authored by Lynch, Vickie's avatar Lynch, Vickie
Browse files

Refs #22420 fix unit tests

parent efe348e5
......@@ -254,6 +254,18 @@ void PredictSatellitePeaks::exec_peaks() {
int maxOrder = getProperty("MaxOrder");
bool crossTerms = getProperty("CrossTerms");
API::Sample sample = Peaks->mutableSample();
OrientedLattice lattice = sample.getOrientedLattice();
if (getProperty("GetModVectorsFromUB")) {
offsets1 = lattice.getModVec(1);
offsets2 = lattice.getModVec(2);
offsets3 = lattice.getModVec(3);
if (maxOrder == 0)
maxOrder = lattice.getMaxOrder();
}
bool includePeaksInRange = false;
bool includeOrderZero = getProperty("IncludeIntegerHKL");
......@@ -262,10 +274,6 @@ void PredictSatellitePeaks::exec_peaks() {
return;
}
API::Sample sample = Peaks->mutableSample();
OrientedLattice lattice = sample.getOrientedLattice();
const auto instrument = Peaks->getInstrument();
auto outPeaks = boost::dynamic_pointer_cast<IPeaksWorkspace>(
......@@ -341,8 +349,8 @@ void PredictSatellitePeaks::predictOffsets(
Kernel::V3D Qs = goniometer * UB * satelliteHKL * 2.0 * M_PI * m_qConventionFactor;
// Check if Q is non-physical
/*if (Qs[2] <= 0)
continue;*/
if (Qs[2] * m_qConventionFactor <= 0)
continue;
auto peak(Peaks->createPeak(Qs, 1));
......
......@@ -10,15 +10,13 @@
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/Run.h"
#include "MantidCrystal/CalculateUMatrix.h"
#include "MantidCrystal/IndexPeaksWithSatellites.h"
#include "MantidCrystal/FindUBUsingIndexedPeaks.h"
#include "MantidCrystal/LoadIsawPeaks.h"
#include "MantidCrystal/LoadIsawUB.h"
#include "MantidCrystal/PredictSatellitePeaks.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include <cxxtest/TestSuite.h>
using namespace Mantid::Crystal;
......@@ -36,72 +34,63 @@ public:
}
void test_exec() {
Mantid::Geometry::Instrument_sptr inst =
ComponentCreationHelper::createTestInstrumentRectangular2(1, 100, 10.);
inst->setName("SillyInstrument");
PeaksWorkspace_sptr pw(new PeaksWorkspace);
pw->setInstrument(inst);
std::string val = "value";
pw->mutableRun().addProperty("TestProp", val);
Peak p(inst, 1, 3.0, V3D(1, 0, 0)); // HKL=1,0,0
pw->addPeak(p);
Peak p1(inst, 10, 3.0, V3D(2, 0, 0)); // HKL=2,0,0
Peak p2(inst, 20, 3.0, V3D(2, 2, 0)); // HKL=2,2,0
std::string WSName("peaks-fail");
AnalysisDataService::Instance().addOrReplace(WSName, pw);
pw->addPeak(p1);
pw->addPeak(p2);
AnalysisDataService::Instance().addOrReplace(WSName, pw);
CalculateUMatrix alg2;
LoadIsawPeaks alg1;
TS_ASSERT_THROWS_NOTHING(alg1.initialize())
TS_ASSERT(alg1.isInitialized())
alg1.setPropertyValue("Filename", "Modulated.peaks");
alg1.setPropertyValue("OutputWorkspace", "peaks");
TS_ASSERT(alg1.execute());
TS_ASSERT(alg1.isExecuted());
PeaksWorkspace_sptr ws;
TS_ASSERT_THROWS_NOTHING(
ws = boost::dynamic_pointer_cast<PeaksWorkspace>(
AnalysisDataService::Instance().retrieve("peaks")));
TS_ASSERT(ws);
if (!ws)
return;
FindUBUsingIndexedPeaks alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize())
TS_ASSERT(alg2.isInitialized())
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("a", "14.1526"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("b", "19.2903"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("c", "8.5813"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("alpha", "90"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("beta", "105.0738"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("gamma", "90"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("PeaksWorkspace", WSName));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("ToleranceForSatellite", "0.05"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("PeaksWorkspace", "peaks"));
TS_ASSERT_THROWS_NOTHING(alg2.execute(););
TS_ASSERT(alg2.isExecuted());
PredictSatellitePeaks alg3;
TS_ASSERT_THROWS_NOTHING(alg3.initialize());
TS_ASSERT(alg3.isInitialized());
alg3.setProperty("Peaks", WSName);
alg3.setProperty("SatellitePeaks", std::string("SatellitePeaks"));
alg3.setProperty("ModVector1", "0.5,0,.2");
alg3.setProperty("MaxOrder", "1");
TS_ASSERT(alg3.execute());
TS_ASSERT(alg3.isExecuted());
alg3.setPropertyValue("SatellitePeaks", "SatellitePeaks");
PeaksWorkspace_sptr SatellitePeaks = alg3.getProperty("SatellitePeaks");
IndexPeaksWithSatellites alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT(alg.isInitialized());
alg.setProperty("PeaksWorkspace", std::string("SatellitePeaks"));
alg.setProperty("ModVector1", "0.5,0,.2");
alg.setProperty("MaxOrder", "1");
alg.setProperty("PeaksWorkspace", "peaks");
alg.setProperty("ModVector1", "-0.493670,-0.440224,0.388226");
alg.setPropertyValue("Tolerance", "0.1");
alg.setPropertyValue("ToleranceForSatellite", "0.02");
alg.setProperty("MaxOrder", "2");
TS_ASSERT(alg.execute());
TS_ASSERT(alg.isExecuted());
TS_ASSERT_EQUALS(SatellitePeaks->getNumberPeaks(), 5);
PeaksWorkspace_sptr Modulated;
TS_ASSERT_THROWS_NOTHING(
Modulated = boost::dynamic_pointer_cast<PeaksWorkspace>(
AnalysisDataService::Instance().retrieve("peaks")));
TS_ASSERT(Modulated);
TS_ASSERT_EQUALS(Modulated->getNumberPeaks(), 18);
auto &peak0 = Modulated->getPeak(0);
TS_ASSERT_DELTA(peak0.getH(), 1.0, .01);
TS_ASSERT_DELTA(peak0.getK(), -1.0, .01);
TS_ASSERT_DELTA(peak0.getL(), 2.0, .01);
auto &peak0 = SatellitePeaks->getPeak(0);
TS_ASSERT_DELTA(peak0.getH(), 0.5, .0001);
TS_ASSERT_DELTA(peak0.getK(), 0., .0001);
TS_ASSERT_DELTA(peak0.getL(), -0.2, .0001);
auto &peak3 = Modulated->getPeak(3);
TS_ASSERT_DELTA(peak3.getH(), 1.49, .01);
TS_ASSERT_DELTA(peak3.getK(), -0.56, .01);
TS_ASSERT_DELTA(peak3.getL(), 1.61, .01);
auto &peak3 = SatellitePeaks->getPeak(3);
TS_ASSERT_DELTA(peak3.getH(), 2.5, .0001);
TS_ASSERT_DELTA(peak3.getK(), 0., .0001);
TS_ASSERT_DELTA(peak3.getL(), 0.2, .0001);
AnalysisDataService::Instance().remove(WSName);
AnalysisDataService::Instance().remove("peaks");
}
};
......
......@@ -12,8 +12,8 @@
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/Run.h"
#include "MantidCrystal/CalculateUMatrix.h"
#include "MantidCrystal/IndexPeaks.h"
#include "MantidCrystal/LoadIsawUB.h"
#include "MantidCrystal/FindUBUsingIndexedPeaks.h"
#include "MantidCrystal/LoadIsawPeaks.h"
#include "MantidCrystal/PredictSatellitePeaks.h"
#include "MantidDataObjects/PeaksWorkspace.h"
#include "MantidGeometry/Instrument/Goniometer.h"
......@@ -37,93 +37,77 @@ public:
}
void test_exec() {
Mantid::Geometry::Instrument_sptr inst =
ComponentCreationHelper::createTestInstrumentRectangular2(1, 100, 10.);
inst->setName("SillyInstrument");
PeaksWorkspace_sptr pw(new PeaksWorkspace);
pw->setInstrument(inst);
std::string val = "value";
pw->mutableRun().addProperty("TestProp", val);
Peak p(inst, 1, 3.0, V3D(1, 0, 0)); // HKL=1,0,0
pw->addPeak(p);
Peak p1(inst, 10, 3.0, V3D(2, 0, 0)); // HKL=2,0,0
Peak p2(inst, 20, 3.0, V3D(2, 2, 0)); // HKL=2,2,0
std::string WSName("peaks-fail");
AnalysisDataService::Instance().addOrReplace(WSName, pw);
pw->addPeak(p1);
pw->addPeak(p2);
AnalysisDataService::Instance().addOrReplace(WSName, pw);
// Set Goniometer to 180 degrees
Mantid::Geometry::Goniometer gonio;
gonio.makeUniversalGoniometer();
gonio.setRotationAngle(1, 180);
pw->mutableRun().setGoniometer(gonio, false);
CalculateUMatrix alg2;
LoadIsawPeaks alg1;
TS_ASSERT_THROWS_NOTHING(alg1.initialize())
TS_ASSERT(alg1.isInitialized())
alg1.setPropertyValue("Filename", "Modulated.peaks");
alg1.setPropertyValue("OutputWorkspace", "Modulated");
TS_ASSERT(alg1.execute());
TS_ASSERT(alg1.isExecuted());
PeaksWorkspace_sptr ws;
TS_ASSERT_THROWS_NOTHING(
ws = boost::dynamic_pointer_cast<PeaksWorkspace>(
AnalysisDataService::Instance().retrieve("Modulated")));
TS_ASSERT(ws);
if (!ws)
return;
FindUBUsingIndexedPeaks alg2;
TS_ASSERT_THROWS_NOTHING(alg2.initialize())
TS_ASSERT(alg2.isInitialized())
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("a", "14.1526"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("b", "19.2903"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("c", "8.5813"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("alpha", "90"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("beta", "105.0738"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("gamma", "90"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("PeaksWorkspace", WSName));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("ToleranceForSatellite", "0.05"));
TS_ASSERT_THROWS_NOTHING(alg2.setPropertyValue("PeaksWorkspace", "Modulated"));
TS_ASSERT_THROWS_NOTHING(alg2.execute(););
TS_ASSERT(alg2.isExecuted());
PredictSatellitePeaks alg;
TS_ASSERT_THROWS_NOTHING(alg.initialize());
TS_ASSERT(alg.isInitialized());
alg.setProperty("Peaks", WSName);
alg.setProperty("Peaks", "Modulated");
alg.setProperty("SatellitePeaks", std::string("SatellitePeaks"));
alg.setProperty("ModVector1", "0.5,0,.2");
alg.setProperty("MaxOrder", "1");
alg.setProperty("GetModVectorsFromUB", false);
alg.setProperty("GetModVectorsFromUB", true);
TS_ASSERT(alg.execute());
TS_ASSERT(alg.isExecuted());
alg.setPropertyValue("SatellitePeaks", "SatellitePeaks");
PeaksWorkspace_sptr SatellitePeaks = alg.getProperty("SatellitePeaks");
TS_ASSERT(SatellitePeaks);
TS_ASSERT_EQUALS(SatellitePeaks->getNumberPeaks(), 5);
TS_ASSERT_EQUALS(SatellitePeaks->getNumberPeaks(), 37);
auto &peak0 = SatellitePeaks->getPeak(0);
TS_ASSERT_DELTA(peak0.getH(), 0.5, .0001);
TS_ASSERT_DELTA(peak0.getK(), 0.0, .0001);
TS_ASSERT_DELTA(peak0.getL(), -0.2, .0001);
auto &peak0 = SatellitePeaks->getPeak(4);
TS_ASSERT_DELTA(peak0.getH(), 1.49, .01);
TS_ASSERT_DELTA(peak0.getK(), -0.56, .01);
TS_ASSERT_DELTA(peak0.getL(), 1.61, .01);
auto &peak3 = SatellitePeaks->getPeak(3);
TS_ASSERT_DELTA(peak3.getH(), 2.5, .0001);
TS_ASSERT_DELTA(peak3.getK(), 0.0, .0001);
TS_ASSERT_DELTA(peak3.getL(), 0.2, .0001);
auto &peak3 = SatellitePeaks->getPeak(6);
TS_ASSERT_DELTA(peak3.getH(), 1.51, .01);
TS_ASSERT_DELTA(peak3.getK(), -0.44, .01);
TS_ASSERT_DELTA(peak3.getL(), 1.39, .01);
PredictSatellitePeaks alg4;
TS_ASSERT_THROWS_NOTHING(alg4.initialize());
TS_ASSERT(alg4.isInitialized());
alg4.setProperty("Peaks", WSName);
alg4.setProperty("Peaks", "Modulated");
alg4.setProperty("SatellitePeaks", std::string("SatellitePeaks"));
alg4.setProperty("ModVector1", "0.5,0,.2");
alg4.setProperty("MaxOrder", "1");
alg4.setProperty("IncludeAllPeaksInRange", true);
alg4.setProperty("GetModVectorsFromUB", false);
alg4.setProperty("MinDSpacing", "3");
alg4.setProperty("MaxDSpacing", "16");
alg4.setProperty("WavelengthMin", "0.5");
alg4.setProperty("WavelengthMax", "22");
alg4.setProperty("GetModVectorsFromUB", true);
alg4.setProperty("MinDSpacing", "0.5");
alg4.setProperty("MaxDSpacing", "3");
alg4.setProperty("WavelengthMin", "1");
alg4.setProperty("WavelengthMax", "2");
TS_ASSERT(alg4.execute())
TS_ASSERT(alg4.isExecuted());
alg4.setPropertyValue("SatellitePeaks", "SatellitePeaks");
PeaksWorkspace_sptr SatellitePeaks2 = alg4.getProperty("SatellitePeaks");
TS_ASSERT(SatellitePeaks2);
TS_ASSERT_EQUALS(SatellitePeaks2->getNumberPeaks(), 467);
TS_ASSERT_EQUALS(SatellitePeaks2->getNumberPeaks(), 939);
AnalysisDataService::Instance().remove(WSName);
AnalysisDataService::Instance().remove("Modulated");
}
};
......
......@@ -1218,6 +1218,11 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) {
peakWS->getPeak(i).setPeakShape(peakShape);
}
}
// After all columns read set IntHKL
for (int r = 0; r < numberPeaks; r++) {
V3D intHKL = V3D(peakWS->getPeak(r).getH(),peakWS->getPeak(r).getK(),peakWS->getPeak(r).getL());
peakWS->getPeak(r).setIntHKL(intHKL);
}
}
return boost::static_pointer_cast<API::Workspace>(peakWS);
......
......@@ -834,7 +834,7 @@ namespace Mantid {
*
* @param HKL :: vector with integer x,y,z -> h,k,l
*/
void Peak::setIntHKL(const Mantid::Kernel::V3D HKL)
void Peak::setIntHKL(V3D HKL)
{
m_IntHKL = V3D(boost::math::iround(HKL[0]),boost::math::iround(HKL[1]),boost::math::iround(HKL[2]));
}
......
......@@ -89,7 +89,7 @@ public:
MOCK_METHOD1(setL, void(double m_L));
MOCK_METHOD3(setHKL, void(double H, double K, double L));
MOCK_METHOD1(setHKL, void(const Mantid::Kernel::V3D &HKL));
MOCK_METHOD1(setIntHKL, void(const Mantid::Kernel::V3D &HKL));
MOCK_METHOD1(setIntHKL, void(const Mantid::Kernel::V3D HKL));
MOCK_CONST_METHOD0(getQLabFrame, Mantid::Kernel::V3D());
MOCK_CONST_METHOD0(getQSampleFrame, Mantid::Kernel::V3D());
MOCK_METHOD0(findDetector, bool());
......
......@@ -94,9 +94,9 @@ void export_IPeak() {
"Get HKL as a :class:`~mantid.kernel.V3D` object")
.def("getIntHKL", &IPeak::getIntHKL, arg("self"),
"Get HKL as a :class:`~mantid.kernel.V3D` object")
.def("setIntHKL",
(void (IPeak::*)(Mantid::Kernel::V3D)) & IPeak::setIntHKL,
(arg("self"), arg("hkl")), "Set the integer HKL values of this peak")
.def("setIntHKL", &IPeak::setIntHKL,
(arg("self"), arg("hkl")),
"Set the integer HKL for this peak")
.def("setHKL", (void (IPeak::*)(double, double, double)) & IPeak::setHKL,
(arg("self"), arg("h"), arg("k"), arg("l")),
"Set the HKL values of this peak")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment