Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/11432_fix_trigonal_point_groups'
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Mar 31, 2015
2 parents 2cf6eda + d9e1776 commit 3573c13
Show file tree
Hide file tree
Showing 18 changed files with 623 additions and 471 deletions.
10 changes: 10 additions & 0 deletions Code/Mantid/Framework/Geometry/inc/MantidGeometry/Crystal/Group.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ namespace Geometry {
*/
class MANTID_GEOMETRY_DLL Group {
public:
enum CoordinateSystem {
Orthogonal,
Hexagonal
};

Group();
Group(const std::string &symmetryOperationString);
Group(const std::vector<SymmetryOperation> &symmetryOperations);
Expand All @@ -118,6 +123,7 @@ class MANTID_GEOMETRY_DLL Group {
virtual ~Group() {}

size_t order() const;
CoordinateSystem getCoordinateSystem() const;
std::vector<SymmetryOperation> getSymmetryOperations() const;

Group operator*(const Group &other) const;
Expand All @@ -131,8 +137,12 @@ class MANTID_GEOMETRY_DLL Group {
void setSymmetryOperations(
const std::vector<SymmetryOperation> &symmetryOperations);

CoordinateSystem getCoordinateSystemFromOperations(
const std::vector<SymmetryOperation> &symmetryOperations) const;

std::vector<SymmetryOperation> m_allOperations;
std::set<SymmetryOperation> m_operationSet;
CoordinateSystem m_axisSystem;
};

typedef boost::shared_ptr<Group> Group_sptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "MantidGeometry/DllConfig.h"
#include "MantidKernel/SingletonHolder.h"
#include "MantidGeometry/Crystal/PointGroup.h"
#include "MantidGeometry/Crystal/SpaceGroup.h"
#include "MantidKernel/RegistrationHelper.h"

#include <boost/regex.hpp>
Expand Down Expand Up @@ -81,7 +82,9 @@ class MANTID_GEOMETRY_DLL PointGroupFactoryImpl {
public:
PointGroup_sptr createPointGroup(const std::string &hmSymbol);
PointGroup_sptr
createPointGroupFromSpaceGroupSymbol(const std::string &spaceGroupSymbol);
createPointGroupFromSpaceGroup(const SpaceGroup_const_sptr &spaceGroup);
PointGroup_sptr
createPointGroupFromSpaceGroup(const SpaceGroup &spaceGroup);

bool isSubscribed(const std::string &hmSymbol) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,10 @@ void CrystalStructure::setPointGroupFromSpaceGroup(
if (spaceGroup) {
try {
m_pointGroup =
PointGroupFactory::Instance().createPointGroupFromSpaceGroupSymbol(
spaceGroup->hmSymbol());
} catch (...) {
PointGroupFactory::Instance().createPointGroupFromSpaceGroup(
spaceGroup);
}
catch (...) {
// do nothing - point group will be null
}
}
Expand Down
28 changes: 24 additions & 4 deletions Code/Mantid/Framework/Geometry/src/Crystal/Group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,46 @@ namespace Mantid {
namespace Geometry {

/// Default constructor. Creates a group with one symmetry operation (identity).
Group::Group() : m_allOperations(), m_operationSet() {
Group::Group() : m_allOperations(), m_operationSet(), m_axisSystem() {
std::vector<SymmetryOperation> operation(1);
setSymmetryOperations(operation);
}

/// Uses SymmetryOperationFactory to create a vector of symmetry operations from
/// the string.
Group::Group(const std::string &symmetryOperationString)
: m_allOperations(), m_operationSet() {
: m_allOperations(), m_operationSet(), m_axisSystem() {
setSymmetryOperations(SymmetryOperationFactory::Instance().createSymOps(
symmetryOperationString));
}

/// Constructs a group from the symmetry operations in the vector, duplicates
/// are removed.
Group::Group(const std::vector<SymmetryOperation> &symmetryOperations)
: m_allOperations(), m_operationSet() {
: m_allOperations(), m_operationSet(), m_axisSystem() {
setSymmetryOperations(symmetryOperations);
}

/// Copy constructor.
Group::Group(const Group &other)
: m_allOperations(other.m_allOperations),
m_operationSet(other.m_operationSet) {}
m_operationSet(other.m_operationSet), m_axisSystem(other.m_axisSystem) {}

/// Assignment operator.
Group &Group::operator=(const Group &other) {
m_allOperations = other.m_allOperations;
m_operationSet = other.m_operationSet;
m_axisSystem = other.m_axisSystem;

return *this;
}

/// Returns the order of the group, which is the number of symmetry operations.
size_t Group::order() const { return m_allOperations.size(); }

/// Returns the axis system of the group (either orthogonal or hexagonal).
Group::CoordinateSystem Group::getCoordinateSystem() const { return m_axisSystem; }

/// Returns a vector with all symmetry operations.
std::vector<SymmetryOperation> Group::getSymmetryOperations() const {
return m_allOperations;
Expand Down Expand Up @@ -105,6 +109,22 @@ void Group::setSymmetryOperations(
symmetryOperations.end());
m_allOperations = std::vector<SymmetryOperation>(m_operationSet.begin(),
m_operationSet.end());
m_axisSystem = getCoordinateSystemFromOperations(m_allOperations);
}

/// Returns the axis system based on the given symmetry operations. Hexagonal
/// systems have 4 non-zero elements in the matrix, orthogonal have 6.
Group::CoordinateSystem Group::getCoordinateSystemFromOperations(
const std::vector<SymmetryOperation> &symmetryOperations) const {
for (auto op = symmetryOperations.begin(); op != symmetryOperations.end();
++op) {
std::vector<int> matrix = (*op).matrix();
if (std::count(matrix.begin(), matrix.end(), 0) == 5) {
return Group::Hexagonal;
}
}

return Group::Orthogonal;
}

/// Convenience operator* for directly multiplying groups using shared pointers.
Expand Down
49 changes: 37 additions & 12 deletions Code/Mantid/Framework/Geometry/src/Crystal/PointGroupFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "MantidGeometry/Crystal/PointGroupFactory.h"
#include "MantidGeometry/Crystal/SpaceGroup.h"

#include "MantidKernel/LibraryManager.h"
#include <boost/algorithm/string.hpp>
Expand All @@ -18,10 +19,35 @@ PointGroupFactoryImpl::createPointGroup(const std::string &hmSymbol) {
return constructFromPrototype(getPrototype(hmSymbol));
}

PointGroup_sptr PointGroupFactoryImpl::createPointGroupFromSpaceGroupSymbol(
const std::string &spaceGroupSymbol) {
return createPointGroup(
pointGroupSymbolFromSpaceGroupSymbol(spaceGroupSymbol));
PointGroup_sptr PointGroupFactoryImpl::createPointGroupFromSpaceGroup(
const SpaceGroup_const_sptr &spaceGroup) {
return createPointGroupFromSpaceGroup(*spaceGroup);
}

PointGroup_sptr PointGroupFactoryImpl::createPointGroupFromSpaceGroup(
const SpaceGroup &spaceGroup) {
std::string pointGroupSymbol =
pointGroupSymbolFromSpaceGroupSymbol(spaceGroup.hmSymbol());

try {
PointGroup_sptr pointGroup = createPointGroup(pointGroupSymbol);

// If the crystal system is trigonal, we need to do more.
if (pointGroup->crystalSystem() == PointGroup::Trigonal) {
throw std::invalid_argument(
"Trigonal space groups need to be processed differently.");
}

return pointGroup;
}
catch (std::invalid_argument) {
if (spaceGroup.getCoordinateSystem() !=
Group::CoordinateSystem::Hexagonal) {
pointGroupSymbol.append(" r");
}

return createPointGroup(pointGroupSymbol);
}
}

bool PointGroupFactoryImpl::isSubscribed(const std::string &hmSymbol) const {
Expand Down Expand Up @@ -187,20 +213,20 @@ DECLARE_POINTGROUP("-42m", "y,-x,-z; x,-y,-z", "Tetragonal")
DECLARE_POINTGROUP("-4m2", "y,-x,-z; y,x,-z", "Tetragonal")
DECLARE_POINTGROUP("4/mmm", "-y,x,z; x,y,-z; x,-y,-z", "Tetragonal")

DECLARE_POINTGROUP("3 h", "-y,x-y,z", "Trigonal - Hexagonal")
DECLARE_POINTGROUP("-3 h", "y,y-x,-z", "Trigonal - Hexagonal")
DECLARE_POINTGROUP("3", "-y,x-y,z", "Trigonal - Hexagonal")
DECLARE_POINTGROUP("-3", "y,y-x,-z", "Trigonal - Hexagonal")
DECLARE_POINTGROUP("321", "-y,x-y,z; x-y,-y,-z", "Trigonal - Hexagonal")
DECLARE_POINTGROUP("312", "-y,x-y,z; x,x-y,-z", "Trigonal - Hexagonal")
DECLARE_POINTGROUP("3m1", "-y,x-y,z; y-x,y,z", "Trigonal - Hexagonal")
DECLARE_POINTGROUP("31m", "-y,x-y,z; -x,y-x,z", "Trigonal - Hexagonal")
DECLARE_POINTGROUP("-3m1", "y,y-x,-z; x-y,-y,-z", "Trigonal - Hexagonal")
DECLARE_POINTGROUP("-31m", "y,y-x,-z; x,x-y,-z", "Trigonal - Hexagonal")

DECLARE_POINTGROUP("3", "z,x,y", "Trigonal - Rhombohedral")
DECLARE_POINTGROUP("-3", "-z,-x,-y", "Trigonal - Rhombohedral")
DECLARE_POINTGROUP("32", "z,x,y; -y,-x,-z", "Trigonal - Rhombohedral")
DECLARE_POINTGROUP("3m", "z,x,y; y,x,z", "Trigonal - Rhombohedral")
DECLARE_POINTGROUP("-3m", "-z,-x,-y; y,x,z", "Trigonal - Rhombohedral")
DECLARE_POINTGROUP("3 r", "z,x,y", "Trigonal - Rhombohedral")
DECLARE_POINTGROUP("-3 r", "-z,-x,-y", "Trigonal - Rhombohedral")
DECLARE_POINTGROUP("32 r", "z,x,y; -y,-x,-z", "Trigonal - Rhombohedral")
DECLARE_POINTGROUP("3m r", "z,x,y; y,x,z", "Trigonal - Rhombohedral")
DECLARE_POINTGROUP("-3m r", "-z,-x,-y; y,x,z", "Trigonal - Rhombohedral")

DECLARE_POINTGROUP("6", "x-y,x,z", "Hexagonal")
DECLARE_POINTGROUP("-6", "y-x,-x,-z", "Hexagonal")
Expand All @@ -211,7 +237,6 @@ DECLARE_POINTGROUP("-62m", "y-x,-x,-z; x-y,-y,-z", "Hexagonal")
DECLARE_POINTGROUP("-6m2", "y-x,-x,-z; y-x,y,z", "Hexagonal")
DECLARE_POINTGROUP("6/mmm", "x-y,x,z; x-y,-y,-z; -x,-y,-z", "Hexagonal")


DECLARE_POINTGROUP("23", "z,x,y; -x,-y,z; x,-y,-z", "Cubic")
DECLARE_POINTGROUP("m-3", "-z,-x,-y; -x,-y,z; x,-y,-z", "Cubic")
DECLARE_POINTGROUP("432", "z,x,y; -y,x,z; x,-y,-z", "Cubic")
Expand Down
Loading

0 comments on commit 3573c13

Please sign in to comment.