Mantid
Loading...
Searching...
No Matches
BraggScattererInCrystalStructure.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include <stdexcept>
9
12#include <boost/algorithm/string.hpp>
13#include <boost/regex.hpp>
14#include <memory>
15
16#ifdef _MSC_VER
17#pragma warning(push)
18#pragma warning(disable : 4005)
19#endif
20
21#include <muParser.h>
22
23#ifdef _MSC_VER
24#pragma warning(pop)
25#endif
26
27namespace Mantid::Geometry {
28
29using namespace Kernel;
30
33 : BraggScatterer(), m_position(), m_cell(UnitCell(1, 1, 1, 90, 90, 90)) {}
34
39}
40
43
46
49
53 declareProperty(std::make_unique<Kernel::PropertyWithValue<std::string>>("Position", "[0, 0, 0]"),
54 "Position of the scatterer");
55
56 IValidator_sptr unitCellStringValidator = std::make_shared<UnitCellStringValidator>();
57 declareProperty(std::make_unique<Kernel::PropertyWithValue<std::string>>("UnitCell", "1.0 1.0 1.0 90.0 90.0 90.0",
58 unitCellStringValidator),
59 "Unit cell.");
60 exposePropertyToComposite("UnitCell");
61
63}
64
65V3D BraggScattererInCrystalStructure::getPositionFromString(const std::string &positionString) const {
66 std::vector<std::string> numberParts = getTokenizedPositionString(positionString);
67
68 mu::Parser parser;
69
71 for (size_t i = 0; i < numberParts.size(); ++i) {
72 parser.SetExpr(numberParts[i]);
73 position[i] = parser.Eval();
74 }
75
76 return position;
77}
78
89void BraggScattererInCrystalStructure::afterPropertySet(const std::string &propertyName) {
90 if (propertyName == "Position") {
91 std::string position = getProperty("Position");
92
94 } else if (propertyName == "UnitCell") {
95 setCell(strToUnitCell(getProperty("UnitCell")));
96 }
97
98 afterScattererPropertySet(propertyName);
99}
100
102IValidator_sptr UnitCellStringValidator::clone() const { return std::make_shared<UnitCellStringValidator>(*this); }
103
105std::string UnitCellStringValidator::checkValidity(const std::string &unitCellString) const {
106 boost::regex unitCellRegex("((\\d+(\\.\\d+){0,1}\\s+){2}|(\\d+(\\.\\d+){0,1}"
107 "\\s+){5})(\\d+(\\.\\d+){0,1}\\s*)");
108
109 if (!boost::regex_match(unitCellString, unitCellRegex)) {
110 return "Unit cell string is invalid: " + unitCellString;
111 }
112
113 return "";
114}
115
117std::vector<std::string> getTokenizedPositionString(const std::string &position) {
118 std::string positionStringClean = position;
119 positionStringClean.erase(
120 std::remove_if(positionStringClean.begin(), positionStringClean.end(), boost::is_any_of("[]")),
121 positionStringClean.end());
122
123 std::vector<std::string> numberParts;
124 boost::split(numberParts, positionStringClean, boost::is_any_of(","));
125
126 if (numberParts.size() != 3) {
127 throw std::invalid_argument("Cannot parse '" + position + "' as a position.");
128 }
129
130 return numberParts;
131}
132
133} // namespace Mantid::Geometry
double position
Definition: GetAllEi.cpp:154
void(ComponentInfo::* setPosition)(const size_t, const Mantid::Kernel::V3D &)
void afterPropertySet(const std::string &propertyName) override
Additional property processing.
virtual void setCell(const UnitCell &cell)
Assigns a unit cell, which may be required for certain calculations.
void declareProperties() override
Declares basic properties, should not be overridden by subclasses, use declareScattererProperties ins...
Kernel::V3D getPositionFromString(const std::string &positionString) const
virtual void declareScattererProperties()
This method should be implemented by subclasses for declaring additional properties.
virtual void afterScattererPropertySet(const std::string &)
This method should be re-implemented by subclasses for additional parameter processing.
UnitCell getCell() const
Returns the cell which is currently set.
Kernel::V3D getPosition() const
Returns the position of the scatterer.
virtual void setPosition(const Kernel::V3D &position)
Sets the position of the scatterer to the supplied coordinates - vector is wrapped to [0,...
BraggScatterer is a general interface for representing scatterers in the unit cell of a periodic stru...
void exposePropertyToComposite(const std::string &propertyName)
Exposes the property with the supplied name to BraggScattererComposite.
std::string checkValidity(const std::string &unitCellString) const override
Check if the string is valid input for Geometry::strToUnitCell.
Kernel::IValidator_sptr clone() const override
Return a clone of the validator.
Class to implement unit cell of crystals.
Definition: UnitCell.h:44
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void declareProperty(std::unique_ptr< Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
The concrete, templated class for properties.
Class for 3D vectors.
Definition: V3D.h:34
MANTID_GEOMETRY_DLL UnitCell strToUnitCell(const std::string &unitCellString)
Definition: UnitCell.cpp:896
MANTID_GEOMETRY_DLL std::vector< std::string > getTokenizedPositionString(const std::string &position)
Returns components of comma-separated position string, cleaned from [ and ].
MANTID_GEOMETRY_DLL V3R getWrappedVector(const V3R &vector)
Wraps a V3R to the interval (0, 1].
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26