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
34
40
43
46
50 declareProperty(std::make_unique<Kernel::PropertyWithValue<std::string>>("Position", "[0, 0, 0]"),
51 "Position of the scatterer");
52
53 IValidator_sptr unitCellStringValidator = std::make_shared<UnitCellStringValidator>();
54 declareProperty(std::make_unique<Kernel::PropertyWithValue<std::string>>("UnitCell", "1.0 1.0 1.0 90.0 90.0 90.0",
55 unitCellStringValidator),
56 "Unit cell.");
57 exposePropertyToComposite("UnitCell");
58
60}
61
62V3D BraggScattererInCrystalStructure::getPositionFromString(const std::string &positionString) const {
63 std::vector<std::string> numberParts = getTokenizedPositionString(positionString);
64
65 mu::Parser parser;
66
68 for (size_t i = 0; i < numberParts.size(); ++i) {
69 parser.SetExpr(numberParts[i]);
70 position[i] = parser.Eval();
71 }
72
73 return position;
74}
75
86void BraggScattererInCrystalStructure::afterPropertySet(const std::string &propertyName) {
87 if (propertyName == "Position") {
88 std::string position = getProperty("Position");
89
91 } else if (propertyName == "UnitCell") {
92 setCell(strToUnitCell(getProperty("UnitCell")));
93 }
94
95 afterScattererPropertySet(propertyName);
96}
97
99IValidator_sptr UnitCellStringValidator::clone() const { return std::make_shared<UnitCellStringValidator>(*this); }
100
102std::string UnitCellStringValidator::checkValidity(const std::string &unitCellString) const {
103 boost::regex unitCellRegex("((\\d+(\\.\\d+){0,1}\\s+){2}|(\\d+(\\.\\d+){0,1}"
104 "\\s+){5})(\\d+(\\.\\d+){0,1}\\s*)");
105
106 if (!boost::regex_match(unitCellString, unitCellRegex)) {
107 return "Unit cell string is invalid: " + unitCellString;
108 }
109
110 return "";
111}
112
114std::vector<std::string> getTokenizedPositionString(const std::string &position) {
115 std::string positionStringClean = position;
116 positionStringClean.erase(
117 std::remove_if(positionStringClean.begin(), positionStringClean.end(), boost::is_any_of("[]")),
118 positionStringClean.end());
119
120 std::vector<std::string> numberParts;
121 boost::split(numberParts, positionStringClean, boost::is_any_of(","));
122
123 if (numberParts.size() != 3) {
124 throw std::invalid_argument("Cannot parse '" + position + "' as a position.");
125 }
126
127 return numberParts;
128}
129
130} // 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.
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