Skip to content

Commit

Permalink
Refs #10281. Added SpaceGroup class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wedel committed Oct 8, 2014
1 parent e293a31 commit 4d1072a
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/Geometry/CMakeLists.txt
Expand Up @@ -14,6 +14,7 @@ set ( SRC_FILES
src/Crystal/ReducedCell.cpp
src/Crystal/ReflectionCondition.cpp
src/Crystal/ScalarUtils.cpp
src/Crystal/SpaceGroup.cpp
src/Crystal/SymmetryOperation.cpp
src/Crystal/SymmetryOperationFactory.cpp
src/Crystal/SymmetryOperationSymbolParser.cpp
Expand Down Expand Up @@ -123,6 +124,7 @@ set ( INC_FILES
inc/MantidGeometry/Crystal/ReducedCell.h
inc/MantidGeometry/Crystal/ReflectionCondition.h
inc/MantidGeometry/Crystal/ScalarUtils.h
inc/MantidGeometry/Crystal/SpaceGroup.h
inc/MantidGeometry/Crystal/SymmetryOperation.h
inc/MantidGeometry/Crystal/SymmetryOperationFactory.h
inc/MantidGeometry/Crystal/SymmetryOperationSymbolParser.h
Expand Down Expand Up @@ -288,6 +290,7 @@ set ( TEST_FILES
RulesUnionTest.h
ScalarUtilsTest.h
ShapeFactoryTest.h
SpaceGroupTest.h
SphereTest.h
SurfaceFactoryTest.h
SurfaceTest.h
Expand Down
@@ -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_ */
58 changes: 58 additions & 0 deletions Code/Mantid/Framework/Geometry/src/Crystal/SpaceGroup.cpp
@@ -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
79 changes: 79 additions & 0 deletions Code/Mantid/Framework/Geometry/test/SpaceGroupTest.h
@@ -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_ */

0 comments on commit 4d1072a

Please sign in to comment.