Skip to content

Commit

Permalink
Refs #10702. Adding unit cell to PoldiPeakCollection
Browse files Browse the repository at this point in the history
This will make InitialCell and CrystalSystem of PoldiFitPeaks2D obsolete, as PoldiIndexKnownCompounds now stores the cell and point group.
  • Loading branch information
Michael Wedel committed Apr 23, 2015
1 parent 0521e7c commit 6c8f861
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 9 deletions.
Expand Up @@ -151,6 +151,10 @@ class MANTID_SINQ_DLL PoldiIndexKnownCompounds : public API::Algorithm {
PoldiPeakCollection_sptr
getIntensitySortedPeakCollection(const PoldiPeakCollection_sptr &peaks) const;

void assignCrystalStructureParameters(
PoldiPeakCollection_sptr &indexedPeaks,
const PoldiPeakCollection_sptr &phasePeaks) const;

PoldiPeakCollection_sptr m_measuredPeaks;
std::vector<PoldiPeakCollection_sptr> m_expectedPhases;
std::vector<std::string> m_phaseNames;
Expand Down
Expand Up @@ -46,7 +46,10 @@ typedef boost::shared_ptr<PoldiPeakCollection> PoldiPeakCollection_sptr;

class MANTID_SINQ_DLL PoldiPeakCollection {
public:
enum IntensityType { Maximum, Integral };
enum IntensityType {
Maximum,
Integral
};

PoldiPeakCollection(IntensityType intensityType = Maximum);
PoldiPeakCollection(const DataObjects::TableWorkspace_sptr &workspace);
Expand All @@ -72,6 +75,9 @@ class MANTID_SINQ_DLL PoldiPeakCollection {
void setPointGroup(const Geometry::PointGroup_sptr &pointGroup);
Geometry::PointGroup_sptr pointGroup() const;

void setUnitCell(const Geometry::UnitCell &unitCell);
Geometry::UnitCell unitCell() const;

DataObjects::TableWorkspace_sptr asTableWorkspace();

protected:
Expand All @@ -93,6 +99,7 @@ class MANTID_SINQ_DLL PoldiPeakCollection {
std::string
getProfileFunctionNameFromLog(const API::LogManager_sptr &tableLog);
std::string getPointGroupStringFromLog(const API::LogManager_sptr &tableLog);
std::string getUnitCellStringFromLog(const API::LogManager_sptr &tableLog);

std::string getStringValueFromLog(const API::LogManager_sptr &logManager,
std::string valueName);
Expand All @@ -105,11 +112,15 @@ class MANTID_SINQ_DLL PoldiPeakCollection {
Geometry::PointGroup_sptr
pointGroupFromString(const std::string &pointGroupString) const;

Geometry::UnitCell
unitCellFromString(const std::string &unitCellString) const;

std::vector<PoldiPeak_sptr> m_peaks;
IntensityType m_intensityType;
std::string m_profileFunctionName;

Geometry::PointGroup_sptr m_pointGroup;
Geometry::UnitCell m_unitCell;
};
}
}
Expand Down
11 changes: 11 additions & 0 deletions Code/Mantid/Framework/SINQ/src/PoldiIndexKnownCompounds.cpp
Expand Up @@ -747,6 +747,14 @@ PoldiIndexKnownCompounds::getIntensitySortedPeakCollection(
return sortedPeaks;
}

void PoldiIndexKnownCompounds::assignCrystalStructureParameters(
PoldiPeakCollection_sptr &indexedPeaks,
const PoldiPeakCollection_sptr &phasePeaks) const {

indexedPeaks->setPointGroup(phasePeaks->pointGroup());
indexedPeaks->setUnitCell(phasePeaks->unitCell());
}

/** Initialize the algorithm's properties.
*/
void PoldiIndexKnownCompounds::init() {
Expand Down Expand Up @@ -836,6 +844,9 @@ void PoldiIndexKnownCompounds::exec() {
for (size_t i = 0; i < m_indexedPeaks.size(); ++i) {
PoldiPeakCollection_sptr intensitySorted =
getIntensitySortedPeakCollection(m_indexedPeaks[i]);

assignCrystalStructureParameters(intensitySorted, m_expectedPhases[i]);

ITableWorkspace_sptr tableWs = intensitySorted->asTableWorkspace();
AnalysisDataService::Instance().addOrReplace("Indexed_" + m_phaseNames[i],
tableWs);
Expand Down
Expand Up @@ -3,6 +3,7 @@
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/LogManager.h"
#include "MantidGeometry/Crystal/PointGroupFactory.h"

#include "boost/format.hpp"
#include "boost/algorithm/string/join.hpp"

Expand All @@ -19,11 +20,11 @@ using namespace Mantid::Kernel;

PoldiPeakCollection::PoldiPeakCollection(IntensityType intensityType)
: m_peaks(), m_intensityType(intensityType), m_profileFunctionName(),
m_pointGroup() {}
m_pointGroup(), m_unitCell() {}

PoldiPeakCollection::PoldiPeakCollection(const TableWorkspace_sptr &workspace)
: m_peaks(), m_intensityType(Maximum), m_profileFunctionName(),
m_pointGroup() {
m_pointGroup(), m_unitCell() {
if (workspace) {
constructFromTableWorkspace(workspace);
}
Expand All @@ -42,6 +43,8 @@ PoldiPeakCollection::PoldiPeakCollection(
m_pointGroup =
pointGroupFromString(pointGroupToString(crystalStructure->pointGroup()));

m_unitCell = crystalStructure->cell();

std::vector<V3D> uniqueHKL = crystalStructure->getUniqueHKLs(
dMin, dMax, Geometry::CrystalStructure::UseStructureFactor);
std::vector<double> dValues = crystalStructure->getDValues(uniqueHKL);
Expand Down Expand Up @@ -104,6 +107,12 @@ void PoldiPeakCollection::setPointGroup(const PointGroup_sptr &pointGroup) {

PointGroup_sptr PoldiPeakCollection::pointGroup() const { return m_pointGroup; }

void PoldiPeakCollection::setUnitCell(const UnitCell &unitCell) {
m_unitCell = unitCell;
}

UnitCell PoldiPeakCollection::unitCell() const { return m_unitCell; }

TableWorkspace_sptr PoldiPeakCollection::asTableWorkspace() {
TableWorkspace_sptr peaks = boost::dynamic_pointer_cast<TableWorkspace>(
WorkspaceFactory::Instance().createTable());
Expand Down Expand Up @@ -131,6 +140,8 @@ void PoldiPeakCollection::dataToTableLog(const TableWorkspace_sptr &table) {
m_profileFunctionName);
tableLog->addProperty<std::string>("PointGroup",
pointGroupToString(m_pointGroup));
tableLog->addProperty<std::string>("UnitCell",
Geometry::unitCellToStr(m_unitCell));
}

void PoldiPeakCollection::peaksToTable(const TableWorkspace_sptr &table) {
Expand Down Expand Up @@ -217,6 +228,7 @@ void PoldiPeakCollection::recoverDataFromLog(
m_intensityType = intensityTypeFromString(getIntensityTypeFromLog(tableLog));
m_profileFunctionName = getProfileFunctionNameFromLog(tableLog);
m_pointGroup = pointGroupFromString(getPointGroupStringFromLog(tableLog));
m_unitCell = unitCellFromString(getUnitCellStringFromLog(tableLog));
}

std::string
Expand All @@ -234,6 +246,11 @@ std::string PoldiPeakCollection::getPointGroupStringFromLog(
return getStringValueFromLog(tableLog, "PointGroup");
}

std::string
PoldiPeakCollection::getUnitCellStringFromLog(const LogManager_sptr &tableLog) {
return getStringValueFromLog(tableLog, "UnitCell");
}

std::string
PoldiPeakCollection::getStringValueFromLog(const LogManager_sptr &logManager,
std::string valueName) {
Expand Down Expand Up @@ -286,5 +303,19 @@ PointGroup_sptr PoldiPeakCollection::pointGroupFromString(

return PointGroup_sptr();
}

UnitCell PoldiPeakCollection::unitCellFromString(
const std::string &unitCellString) const {
UnitCell cell;

try {
cell = strToUnitCell(unitCellString);
}
catch (std::runtime_error) {
// do nothing
}

return cell;
}
}
}
Expand Up @@ -76,6 +76,13 @@ class PoldiIndexKnownCompoundsTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(tableSi->getName(), "Indexed_Si");
TS_ASSERT_EQUALS(tableSi->rowCount(), 4);

// Make sure unit cell and point group is carried over from compound ws
ITableWorkspace_sptr si = AnalysisDataService::Instance().retrieveWS<ITableWorkspace>("Si");
TS_ASSERT_EQUALS(tableSi->getLogs()->getProperty("PointGroup")->value(),
si->getLogs()->getProperty("PointGroup")->value());
TS_ASSERT_EQUALS(tableSi->getLogs()->getProperty("UnitCell")->value(),
si->getLogs()->getProperty("UnitCell")->value());

Workspace_sptr unindexed = group->getItem(1);
TS_ASSERT(unindexed);

Expand Down
32 changes: 26 additions & 6 deletions Code/Mantid/Framework/SINQ/test/PoldiPeakCollectionTest.h
Expand Up @@ -194,18 +194,37 @@ class PoldiPeakCollectionTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(peaks.pointGroup()->getName(), m3m->getName());
}

void testUnitCell()
{
PoldiPeakCollection peaks;

UnitCell defaultCell;
TS_ASSERT_EQUALS(unitCellToStr(peaks.unitCell()), unitCellToStr(defaultCell));

UnitCell cell(1, 2, 3, 90, 91, 92);
peaks.setUnitCell(cell);

UnitCell newCell = peaks.unitCell();
TS_ASSERT_EQUALS(unitCellToStr(newCell), unitCellToStr(cell));
}

void testUnitCellFromLogs()
{
TableWorkspace_sptr newDummy(m_dummyData->clone());

UnitCell cell(1, 2, 3, 90, 91, 92);
newDummy->logs()->addProperty<std::string>("UnitCell", unitCellToStr(cell));

PoldiPeakCollection collection(newDummy);
TS_ASSERT_EQUALS(unitCellToStr(collection.unitCell()), unitCellToStr(cell));
}

void testPointGroupStringConversion()
{
TestablePoldiPeakCollection peaks;
PointGroup_sptr m3m = PointGroupFactory::Instance().createPointGroup("m-3m");

TS_ASSERT(peaks.pointGroupFromString(peaks.pointGroupToString(m3m)));

std::cout << m3m->getName() << std::endl;

std::vector<PointGroup_sptr> pgs = getAllPointGroups();
std::cout << "Size: " << pgs.size() << std::endl;

TS_ASSERT_EQUALS(m3m->getName(), peaks.pointGroupFromString(peaks.pointGroupToString(m3m))->getName());
}

Expand Down Expand Up @@ -276,6 +295,7 @@ class PoldiPeakCollectionTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(clone->getProfileFunctionName(), peaks->getProfileFunctionName());
TS_ASSERT_EQUALS(clone->intensityType(), peaks->intensityType());
TS_ASSERT_EQUALS(clone->peakCount(), peaks->peakCount());
TS_ASSERT_EQUALS(unitCellToStr(clone->unitCell()), unitCellToStr(peaks->unitCell()));

for(size_t i = 0; i < clone->peakCount(); ++i) {
PoldiPeak_sptr clonePeak = clone->peak(i);
Expand Down

0 comments on commit 6c8f861

Please sign in to comment.