Skip to content

Commit

Permalink
Add Lattice to SymInfo. Addresses #23 in part.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpuchala committed Nov 8, 2023
1 parent 9558eaf commit 1387d53
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
3 changes: 3 additions & 0 deletions include/casm/crystallography/SymInfo.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ enum class symmetry_type {
struct SymInfo {
SymInfo(SymOp const &op, xtal::Lattice const &lat);

/// The lattice used for coordinates
xtal::Lattice lattice;

/// One of: identity_op, mirror_op, glide_op, rotation_op, screw_op,
/// inversion_op, rotoinversion_op, or invalid_op
symmetry_type op_type;
Expand Down
16 changes: 16 additions & 0 deletions python/tests/test_syminfo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import numpy as np

import libcasm.xtal as xtal
import libcasm.xtal.prims as xtal_prims


def test_SymInfo_constructor():
lattice = xtal.Lattice(np.eye(3))
op = xtal.SymOp(np.eye(3), np.zeros((3, 1)), False)
syminfo = xtal.SymInfo(op, lattice)
assert syminfo.op_type() == "identity"


def test_SymInfo_to_dict():
xtal_prim = xtal_prims.BCC(r=1.0, occ_dof=["A"])
factor_group = xtal.make_factor_group(xtal_prim)
symgroup_info = []
for op in factor_group:
syminfo = xtal.SymInfo(op, xtal_prim.lattice())
symgroup_info.append(
{
"info": syminfo.to_dict(),
"op": op.to_dict(),
}
)
assert len(symgroup_info) == 48
17 changes: 9 additions & 8 deletions src/casm/crystallography/SymInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ namespace CASM {
namespace xtal {

SymInfo::SymInfo(SymOp const &op, xtal::Lattice const &lat)
: axis(lat),
screw_glide_shift(lat),
location(lat),
: lattice(lat),
axis(lattice),
screw_glide_shift(lattice),
location(lattice),
time_reversal(op.is_time_reversal_active) {
auto matrix = op.matrix;
auto tau = op.translation;
Expand All @@ -23,7 +24,7 @@ SymInfo::SymInfo(SymOp const &op, xtal::Lattice const &lat)
op_type = symmetry_type::identity_op;
_axis = Eigen::Vector3d::Zero();
_location = Eigen::Vector3d::Zero();
_set(_axis, _screw_glide_shift, _location, lat);
_set(_axis, _screw_glide_shift, _location, lattice);
return;
}

Expand All @@ -33,7 +34,7 @@ SymInfo::SymInfo(SymOp const &op, xtal::Lattice const &lat)
op_type = symmetry_type::inversion_op;
_axis = Eigen::Vector3d::Zero();
_location = tau / 2.;
_set(_axis, _screw_glide_shift, _location, lat);
_set(_axis, _screw_glide_shift, _location, lattice);
return;
}

Expand Down Expand Up @@ -81,7 +82,7 @@ SymInfo::SymInfo(SymOp const &op, xtal::Lattice const &lat)
if (det < 0) {
if (almost_equal(angle, 180.)) {
// shift is component of tau perpendicular to axis
xtal::Coordinate coord(tau - tau.dot(_axis) * _axis, lat, CART);
xtal::Coordinate coord(tau - tau.dot(_axis) * _axis, lattice, CART);
_screw_glide_shift = coord.cart();

// location is 1/2 of component of tau parallel to axis:
Expand All @@ -102,7 +103,7 @@ SymInfo::SymInfo(SymOp const &op, xtal::Lattice const &lat)
}
} else {
// shift is component of tau parallel to axis
xtal::Coordinate coord(tau.dot(_axis) * _axis, lat, CART);
xtal::Coordinate coord(tau.dot(_axis) * _axis, lattice, CART);
_screw_glide_shift = coord.cart();

// Can only solve 2d location problem
Expand All @@ -121,7 +122,7 @@ SymInfo::SymInfo(SymOp const &op, xtal::Lattice const &lat)
op_type = coord.is_lattice_shift() ? symmetry_type::rotation_op
: symmetry_type::screw_op;
}
_set(_axis, _screw_glide_shift, _location, lat);
_set(_axis, _screw_glide_shift, _location, lattice);
return;
}

Expand Down

0 comments on commit 1387d53

Please sign in to comment.