Skip to content

Commit

Permalink
Refs #10282. Checkpointing work
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Oct 24, 2014
1 parent be1467a commit 7a22002
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
Expand Up @@ -9,6 +9,9 @@
#include <complex>
#include <boost/shared_ptr.hpp>

#include "MantidKernel/PropertyManager.h"
#include "MantidKernel/TypedValidator.h"

namespace Mantid
{
namespace Geometry
Expand Down Expand Up @@ -65,27 +68,30 @@ class IScatterer;

typedef boost::shared_ptr<IScatterer> IScatterer_sptr;

class MANTID_GEOMETRY_DLL IScatterer
class MANTID_GEOMETRY_DLL IScatterer : public Kernel::PropertyManager
{
public:
IScatterer(const Kernel::V3D &position = Kernel::V3D(0.0, 0.0, 0.0));
virtual ~IScatterer() { }

void initialize();

virtual IScatterer_sptr clone() const = 0;

virtual void setPosition(const Kernel::V3D &position);
Kernel::V3D getPosition() const;
std::vector<Kernel::V3D> getEquivalentPositions() const;

virtual void setCell(const UnitCell &cell);
UnitCell getCell() const;

virtual void setSpaceGroup(const SpaceGroup_const_sptr &spaceGroup);
SpaceGroup_const_sptr getSpaceGroup() const;

virtual StructureFactor calculateStructureFactor(const Kernel::V3D &hkl) const = 0;

protected:
virtual void setPosition(const Kernel::V3D &position);
virtual void setCell(const UnitCell &cell);
virtual void setSpaceGroup(const SpaceGroup_const_sptr &spaceGroup);

virtual void declareProperties() { }

void recalculateEquivalentPositions();

Kernel::V3D m_position;
Expand All @@ -95,6 +101,13 @@ class MANTID_GEOMETRY_DLL IScatterer
SpaceGroup_const_sptr m_spaceGroup;
};

class MANTID_GEOMETRY_DLL UnitCellStringValidator : public Kernel::TypedValidator<std::string>
{
protected:
Kernel::IValidator_sptr clone() const;
virtual std::string checkValidity(const std::string &unitCellString) const;
};

} // namespace Geometry
} // namespace Mantid

Expand Down
37 changes: 37 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Crystal/IScatterer.cpp
@@ -1,20 +1,41 @@
#include "MantidGeometry/Crystal/IScatterer.h"
#include <stdexcept>

#include <boost/regex.hpp>
#include <boost/make_shared.hpp>
#include "MantidKernel/ListValidator.h"
#include "MantidGeometry/Crystal/SpaceGroupFactory.h"

namespace Mantid
{
namespace Geometry
{

using namespace Kernel;

/// Default constructor, vector is wrapped to interval [0, 1).
IScatterer::IScatterer(const Kernel::V3D &position) :
PropertyManager(),
m_position(getWrappedVector(position)),
m_cell(),
m_spaceGroup()
{
recalculateEquivalentPositions();
}

void IScatterer::initialize()
{
declareProperty(new Kernel::PropertyWithValue<V3D>("Position", V3D(0.0, 0.0, 0.0)), "Position of the scatterer");

IValidator_sptr unitCellStringValidator = boost::make_shared<UnitCellStringValidator>();
declareProperty(new Kernel::PropertyWithValue<std::string>("UnitCell", "1.0 1.0 1.0 90.0 90.0 90.0", unitCellStringValidator), "Unit cell.");

IValidator_sptr spaceGroupValidator = boost::make_shared<ListValidator<std::string> >(SpaceGroupFactory::Instance().subscribedSpaceGroupSymbols());
declareProperty(new Kernel::PropertyWithValue<std::string>("SpaceGroup", "P 1", spaceGroupValidator), "Space group.");

declareProperties();
}

/// Sets the position of the scatterer to the supplied coordinates - vector is wrapped to [0, 1) and equivalent positions are recalculated.
void IScatterer::setPosition(const Kernel::V3D &position)
{
Expand Down Expand Up @@ -73,6 +94,22 @@ void IScatterer::recalculateEquivalentPositions()
}
}

IValidator_sptr UnitCellStringValidator::clone() const
{
return boost::make_shared<UnitCellStringValidator>(*this);
}

std::string UnitCellStringValidator::checkValidity(const std::string &unitCellString) const
{
boost::regex unitCellRegex("((\\d+\\.\\d+\\s+){2}|(\\d+\\.\\d+\\s+){5})(\\d+\\.\\d+\\s*)");

if(!boost::regex_match(unitCellString, unitCellRegex)) {
return "Unit cell string is invalid.";
}

return "";
}



} // namespace Geometry
Expand Down
17 changes: 17 additions & 0 deletions Code/Mantid/Framework/Geometry/test/IScattererTest.h
Expand Up @@ -98,6 +98,23 @@ class IScattererTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(scatterer.getEquivalentPositions().front(), specialPosition);
}

void testUnitCellStringValidator()
{
IValidator_sptr validator = boost::make_shared<UnitCellStringValidator>();

// non-working examples
TS_ASSERT_DIFFERS(validator->isValid("1.0"), "");
TS_ASSERT_DIFFERS(validator->isValid("1.0 1.0"), "");
TS_ASSERT_DIFFERS(validator->isValid("1.0 1.0 1.0 1.0"), "");
TS_ASSERT_DIFFERS(validator->isValid("1.0 1.0 1.0 1.0 1.0"), "");
TS_ASSERT_DIFFERS(validator->isValid("1.0.3 1.0 1.0"), "");

// Working examples
TS_ASSERT_EQUALS(validator->isValid("1.0 1.0 1.0"), "");
TS_ASSERT_EQUALS(validator->isValid("1.0 1.0 1.0 90.0 90.0 90.0"), "");
TS_ASSERT_EQUALS(validator->isValid("1.0 1.0 1.0 90.0 90.0 90.0 "), "");
}

private:
class MockIScatterer : public IScatterer
{
Expand Down

0 comments on commit 7a22002

Please sign in to comment.