Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #10281. Added SpaceGroup class.
- Loading branch information
Michael Wedel
committed
Oct 8, 2014
1 parent
e293a31
commit 4d1072a
Showing
4 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/SpaceGroup.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#ifndef MANTID_GEOMETRY_SPACEGROUP_H_ | ||
#define MANTID_GEOMETRY_SPACEGROUP_H_ | ||
|
||
#include "MantidGeometry/DllConfig.h" | ||
#include "MantidGeometry/Crystal/Group.h" | ||
#include "MantidGeometry/Crystal/SymmetryOperation.h" | ||
#include "MantidKernel/V3D.h" | ||
|
||
#include <set> | ||
|
||
namespace Mantid | ||
{ | ||
namespace Geometry | ||
{ | ||
|
||
/** SpaceGroup : | ||
A class for representing space groups, inheriting from Group. | ||
SpaceGroup-objects represent a space group, which is a set | ||
of symmetry operations. Along with storing the operations themselves, | ||
which is realized through inheriting from Group, SpaceGroup also | ||
stores a number (space group number according to the International | ||
Tables for Crystallography A) and a Hermann-Mauguin-symbol. | ||
SpaceGroup may for example be used to generate all equivalent positions | ||
within the unit cell: | ||
SpaceGroup_const_sptr someGroup; | ||
V3D position(0.13, 0.54, 0.38); | ||
std::vector<V3D> equivalents = someGroup->getEquivalentPositions(position); | ||
The class should not be instantiated directly, see SpaceGroupFactory instead. | ||
@author Michael Wedel, Paul Scherrer Institut - SINQ | ||
@date 03/10/2014 | ||
Copyright © 2014 PSI-MSS | ||
This file is part of Mantid. | ||
Mantid is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 3 of the License, or | ||
(at your option) any later version. | ||
Mantid is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
File change history is stored at: <https://github.com/mantidproject/mantid> | ||
Code Documentation is available at: <http://doxygen.mantidproject.org> | ||
*/ | ||
class MANTID_GEOMETRY_DLL SpaceGroup : public Group | ||
{ | ||
public: | ||
SpaceGroup(size_t itNumber, const std::string &hmSymbol, const Group &group); | ||
|
||
SpaceGroup(const SpaceGroup &other); | ||
SpaceGroup &operator =(const SpaceGroup &other); | ||
|
||
virtual ~SpaceGroup() { } | ||
|
||
size_t number() const; | ||
std::string hmSymbol() const; | ||
|
||
template<typename T> | ||
std::vector<T> getEquivalentPositions(const T &position) const | ||
{ | ||
const std::vector<SymmetryOperation> &symmetryOperations = getSymmetryOperations(); | ||
|
||
std::set<T> equivalents; | ||
for(auto it = symmetryOperations.begin(); it != symmetryOperations.end(); ++it) { | ||
equivalents.insert(Geometry::getWrappedVector((*it) * position)); | ||
} | ||
|
||
return std::vector<T>(equivalents.begin(), equivalents.end()); | ||
} | ||
|
||
protected: | ||
size_t m_number; | ||
std::string m_hmSymbol; | ||
}; | ||
|
||
typedef boost::shared_ptr<SpaceGroup> SpaceGroup_sptr; | ||
typedef boost::shared_ptr<const SpaceGroup> SpaceGroup_const_sptr; | ||
|
||
} // namespace Geometry | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_GEOMETRY_SPACEGROUP_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "MantidGeometry/Crystal/SpaceGroup.h" | ||
|
||
namespace Mantid | ||
{ | ||
namespace Geometry | ||
{ | ||
|
||
/** | ||
* Constructor | ||
* | ||
* This constructor creates a space group with the symmetry operations contained | ||
* in the Group-parameter and assigns the given number and symbol. | ||
* | ||
* @param itNumber :: Space group number according to International Tables for Crystallography A | ||
* @param hmSymbol :: Herman-Mauguin symbol for the space group | ||
* @param group :: Group that contains all symmetry operations (including centering). | ||
*/ | ||
SpaceGroup::SpaceGroup(size_t itNumber, const std::string &hmSymbol, const Group &group) : | ||
Group(group), | ||
m_number(itNumber), | ||
m_hmSymbol(hmSymbol) | ||
{ | ||
} | ||
|
||
/// Copy constructor | ||
SpaceGroup::SpaceGroup(const SpaceGroup &other) : | ||
Group(other), | ||
m_number(other.m_number), | ||
m_hmSymbol(other.m_hmSymbol) | ||
{ | ||
|
||
} | ||
|
||
/// Assignment operator, utilizes Group's assignment operator | ||
SpaceGroup &SpaceGroup::operator =(const SpaceGroup &other) | ||
{ | ||
Group::operator =(other); | ||
|
||
m_number = other.m_number; | ||
m_hmSymbol = other.m_hmSymbol; | ||
|
||
return *this; | ||
} | ||
|
||
/// Returns the stored space group number | ||
size_t SpaceGroup::number() const | ||
{ | ||
return m_number; | ||
} | ||
|
||
/// Returns the stored Hermann-Mauguin symbol | ||
std::string SpaceGroup::hmSymbol() const | ||
{ | ||
return m_hmSymbol; | ||
} | ||
|
||
} // namespace Geometry | ||
} // namespace Mantid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#ifndef MANTID_GEOMETRY_SPACEGROUPTEST_H_ | ||
#define MANTID_GEOMETRY_SPACEGROUPTEST_H_ | ||
|
||
#include <cxxtest/TestSuite.h> | ||
|
||
#include "MantidGeometry/Crystal/SpaceGroup.h" | ||
#include "MantidGeometry/Crystal/SymmetryOperationFactory.h" | ||
#include "MantidGeometry/Crystal/CyclicGroup.h" | ||
#include "MantidKernel/V3D.h" | ||
|
||
#include <unordered_set> | ||
|
||
using namespace Mantid::Geometry; | ||
using Mantid::Kernel::V3D; | ||
|
||
class SpaceGroupTest : public CxxTest::TestSuite | ||
{ | ||
public: | ||
// This pair of boilerplate methods prevent the suite being created statically | ||
// This means the constructor isn't called when running other tests | ||
static SpaceGroupTest *createSuite() { return new SpaceGroupTest(); } | ||
static void destroySuite( SpaceGroupTest *suite ) { delete suite; } | ||
|
||
|
||
void testConstruction() | ||
{ | ||
Group_const_sptr inversion = GroupFactory::create<CyclicGroup>("-x,-y,-z"); | ||
SpaceGroup p1bar(2, "P-1", *inversion); | ||
|
||
TS_ASSERT_EQUALS(p1bar.number(), 2); | ||
TS_ASSERT_EQUALS(p1bar.hmSymbol(), "P-1"); | ||
TS_ASSERT_EQUALS(p1bar.order(), 2); | ||
TS_ASSERT_EQUALS(p1bar.getSymmetryOperations().size(), 2); | ||
} | ||
|
||
void testNumber() | ||
{ | ||
TestableSpaceGroup empty; | ||
TS_ASSERT_EQUALS(empty.number(), 0); | ||
|
||
empty.m_number = 2; | ||
TS_ASSERT_EQUALS(empty.number(), 2); | ||
} | ||
|
||
void testSymbol() | ||
{ | ||
TestableSpaceGroup empty; | ||
TS_ASSERT_EQUALS(empty.hmSymbol(), ""); | ||
|
||
empty.m_hmSymbol = "Test"; | ||
TS_ASSERT_EQUALS(empty.hmSymbol(), "Test"); | ||
} | ||
|
||
void testAssignmentOperator() | ||
{ | ||
Group_const_sptr inversion = GroupFactory::create<CyclicGroup>("-x,-y,-z"); | ||
SpaceGroup p1bar(2, "P-1", *inversion); | ||
|
||
SpaceGroup other = p1bar; | ||
|
||
TS_ASSERT_EQUALS(other.number(), p1bar.number()); | ||
TS_ASSERT_EQUALS(other.hmSymbol(), p1bar.hmSymbol()); | ||
TS_ASSERT_EQUALS(other.order(), p1bar.order()); | ||
} | ||
|
||
private: | ||
class TestableSpaceGroup : public SpaceGroup { | ||
friend class SpaceGroupTest; | ||
public: | ||
TestableSpaceGroup() : | ||
SpaceGroup(0, "", Group()) | ||
{ } | ||
|
||
~TestableSpaceGroup() { } | ||
}; | ||
}; | ||
|
||
|
||
#endif /* MANTID_GEOMETRY_SPACEGROUPTEST_H_ */ |