3522568d49
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 10m17s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 11m50s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 12m4s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 12m59s
Build Packages / build:rpm (rocky8) (push) Successful in 12m59s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 13m13s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 13m53s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 10m6s
Build Packages / build:rpm (rocky9) (push) Successful in 11m56s
Build Packages / Generate python client (push) Successful in 13s
Build Packages / Create release (push) Skipped
Build Packages / XDS test (neggia plugin) (push) Successful in 8m25s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 10m45s
Build Packages / XDS test (durin plugin) (push) Successful in 9m36s
Build Packages / Build documentation (push) Successful in 34s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 9m54s
Build Packages / DIALS test (push) Successful in 11m51s
Build Packages / Unit tests (push) Successful in 57m27s
97 lines
3.1 KiB
C++
97 lines
3.1 KiB
C++
// SPDX-FileCopyrightText: 2025 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
#include "MultiLatticeSearch.h"
|
|
|
|
#include <Eigen/Dense>
|
|
|
|
namespace {
|
|
// Direct lattice vectors as matrix columns: M = [a | b | c]
|
|
Eigen::Matrix3d LatticeMatrix(const CrystalLattice &latt) {
|
|
const Coord a = latt.Vec0();
|
|
const Coord b = latt.Vec1();
|
|
const Coord c = latt.Vec2();
|
|
|
|
Eigen::Matrix3d M;
|
|
M.col(0) = Eigen::Vector3d(a.x, a.y, a.z);
|
|
M.col(1) = Eigen::Vector3d(b.x, b.y, b.z);
|
|
M.col(2) = Eigen::Vector3d(c.x, c.y, c.z);
|
|
return M;
|
|
}
|
|
|
|
// Proper rotation mapping reference -> target (target = R * reference).
|
|
// R = Mtarget * Mref^-1, projected to the nearest rotation via SVD.
|
|
Eigen::Matrix3d RotationRefToTarget(const CrystalLattice &reference, const CrystalLattice &target) {
|
|
Eigen::Matrix3d R = LatticeMatrix(target) * LatticeMatrix(reference).inverse();
|
|
|
|
Eigen::JacobiSVD<Eigen::Matrix3d> svd(R, Eigen::ComputeFullU | Eigen::ComputeFullV);
|
|
R = svd.matrixU() * svd.matrixV().transpose();
|
|
if (R.determinant() < 0.0) {
|
|
Eigen::Matrix3d U = svd.matrixU();
|
|
U.col(2) *= -1.0;
|
|
R = U * svd.matrixV().transpose();
|
|
}
|
|
return R;
|
|
}
|
|
}
|
|
|
|
CrystalLattice Transform(const CrystalLattice &in_latt, int i) {
|
|
CrystalLattice latt = in_latt;
|
|
switch (i) {
|
|
case 0:
|
|
break;
|
|
case 1:
|
|
latt.FlipSign(0);
|
|
latt.FlipSign(1);
|
|
break;
|
|
case 2:
|
|
latt.FlipSign(0);
|
|
latt.FlipSign(2);
|
|
break;
|
|
case 3:
|
|
latt.FlipSign(1);
|
|
latt.FlipSign(2);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return latt;
|
|
}
|
|
|
|
std::vector<MultiLatticeSearchResult> MultiLatticeSearch(const std::vector<CrystalLattice> &lattices,
|
|
float dist_tolerance,
|
|
float angle_tolerance_deg) {
|
|
std::vector<MultiLatticeSearchResult> ret;
|
|
if (lattices.empty())
|
|
return ret;
|
|
|
|
const CrystalLattice &reference = lattices[0];
|
|
const UnitCell ref_cell = reference.GetUnitCell();
|
|
|
|
for (size_t i = 1; i < lattices.size(); i++) {
|
|
bool found = false;
|
|
for (int flip = 0; flip < 4; flip++) {
|
|
const CrystalLattice latt = Transform(lattices[i], flip);
|
|
|
|
if (!latt.GetUnitCell().is_close(ref_cell, dist_tolerance, angle_tolerance_deg))
|
|
continue;
|
|
|
|
const Eigen::Matrix3d R = RotationRefToTarget(reference, latt);
|
|
|
|
const Eigen::AngleAxisd aa(R);
|
|
const Eigen::Vector3d rod = aa.angle() * aa.axis();
|
|
const Coord rotation_vector(static_cast<float>(rod.x()),
|
|
static_cast<float>(rod.y()),
|
|
static_cast<float>(rod.z()));
|
|
|
|
if (found)
|
|
continue;
|
|
ret.push_back({rotation_vector});
|
|
found = true;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|