Skip to content

Commit

Permalink
Merge pull request #24 from bpuchala/2.X_array_order
Browse files Browse the repository at this point in the history
2.X array order
  • Loading branch information
bpuchala authored Nov 8, 2023
2 parents e682eaa + a75d888 commit d03b246
Show file tree
Hide file tree
Showing 12 changed files with 263 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.11'

- name: Set up requirements and configuration variables
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.11'

- name: Set up requirements & configuration variables
run: |
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test-linux-cxx-only.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ jobs:
uses: ./.github/workflows/test-linux-dependencies.yml

build:
needs: build-depends
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.11'

- name: Set up requirements & configuration variables
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-linux-dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.11'

- name: Set up requirements & configuration variables
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.11'

- name: Set up requirements & configuration variables
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-macos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.11'

- name: Set up requirements & configuration variables
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
python-version: '3.11'

- name: Set up requirements & configuration variables
run: |
Expand Down
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
309 changes: 202 additions & 107 deletions python/src/xtal.cpp

Large diffs are not rendered by default.

27 changes: 25 additions & 2 deletions python/tests/test_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,32 @@ def test_make_superstructure_1():

def test_make_superstructure_2():
struc = xtal_structures.BCC(r=1)
transformation_matrix = np.array([[0, 1, 1], [1, 0, 1], [1, 1, 0]], dtype=int).T
transformation_matrix = np.array([[0, 1, 1], [2, 0, 1], [1, 1, 0]], dtype=int).T
assert transformation_matrix.flags.f_contiguous
assert transformation_matrix.dtype is np.dtype(np.int64)
xtal.make_superstructure(transformation_matrix, struc)
superstruc = xtal.make_superstructure(transformation_matrix, struc)
assert np.allclose(
superstruc.lattice().column_vector_matrix(),
struc.lattice().column_vector_matrix() @ transformation_matrix,
)

transformation_matrix_b = np.array([[0, 2, 1], [1, 0, 1], [1, 1, 0]], dtype=int)
assert transformation_matrix_b.flags.c_contiguous
assert transformation_matrix.dtype is np.dtype(np.int64)
superstruc_b = xtal.make_superstructure(transformation_matrix_b, struc)
assert np.allclose(
superstruc_b.lattice().column_vector_matrix(),
struc.lattice().column_vector_matrix() @ transformation_matrix_b,
)

assert np.allclose(
transformation_matrix,
transformation_matrix_b,
)
assert np.allclose(
superstruc.lattice().column_vector_matrix(),
superstruc_b.lattice().column_vector_matrix(),
)


def test_make_superstructure_and_rotate():
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 d03b246

Please sign in to comment.