51 n += n.transpose().eval();
53 n(0, 0) = sxx + syy + szz;
54 n(1, 1) = sxx - syy - szz;
55 n(2, 2) = -sxx + syy - szz;
56 n(3, 3) = -sxx - syy + szz;
58 Eigen::SelfAdjointEigenSolver<Matrix4d> es(n);
59 Eigen::Vector4d maxv = es.eigenvectors().col(3);
61 double aa = maxv[0] * maxv[0];
62 double bb = maxv[1] * maxv[1];
63 double cc = maxv[2] * maxv[2];
64 double dd = maxv[3] * maxv[3];
65 double ab = maxv[0] * maxv[1];
66 double ac = maxv[0] * maxv[2];
67 double ad = maxv[0] * maxv[3];
68 double bc = maxv[1] * maxv[2];
69 double bd = maxv[1] * maxv[3];
70 double cd = maxv[2] * maxv[3];
72 R(0, 0) = aa + bb - cc - dd;
73 R(0, 1) = 2 * (bc - ad);
74 R(0, 2) = 2 * (bd + ac);
75 R(1, 0) = 2 * (bc + ad);
76 R(1, 1) = aa - bb + cc - dd;
77 R(1, 2) = 2 * (cd - ab);
78 R(2, 0) = 2 * (bd - ac);
79 R(2, 1) = 2 * (cd + ab);
80 R(2, 2) = aa - bb - cc + dd;
86 const double max_diff) {
91 Eigen::VectorXd c1(3);
92 Eigen::VectorXd c2(3);
94 c1[0] = r1.col(0).sum();
95 c1[1] = r1.col(1).sum();
96 c1[2] = r1.col(2).sum();
97 c2[0] = r2.col(0).sum();
98 c2[1] = r2.col(1).sum();
99 c2[2] = r2.col(2).sum();
103 for (
int i = 0; i < r1.rows(); i++) {
118 for (
int i = 0; i < r1.rows(); i++) {
119 double diff = (r2.row(i) - r1.row(i)).norm();
120 if (diff > max_diff) {
135 long nAtoms = positions.rows();
136 long dof = nAtoms * 3;
139 Eigen::Vector3d com = Eigen::Vector3d::Zero();
140 for (
long i = 0; i < nAtoms; ++i) {
141 com(0) += positions(i, 0);
142 com(1) += positions(i, 1);
143 com(2) += positions(i, 2);
145 com /=
static_cast<double>(nAtoms);
148 std::vector<Eigen::VectorXd> basis;
152 for (
int d = 0; d < 3; ++d) {
153 Eigen::VectorXd t = Eigen::VectorXd::Zero(dof);
154 for (
long j = 0; j < nAtoms; ++j) {
161 Eigen::VectorXd rx = Eigen::VectorXd::Zero(dof);
162 Eigen::VectorXd ry = Eigen::VectorXd::Zero(dof);
163 Eigen::VectorXd rz = Eigen::VectorXd::Zero(dof);
165 for (
long i = 0; i < nAtoms; ++i) {
166 double x = positions(i, 0) - com(0);
167 double y = positions(i, 1) - com(1);
168 double z = positions(i, 2) - com(2);
184 std::vector<Eigen::VectorXd> ortho;
187 for (
auto &v : basis) {
188 Eigen::VectorXd u = v;
189 for (
const auto &e : ortho) {
193 if (u.norm() > 1e-9) {
200 for (
const auto &e : ortho) {
201 step -= step.dot(e) * e;
206 std::shared_ptr<Matter> m2) {
210 if (m2->numberOfFixedAtoms() > 0) {
215 long n = r1_passed.size();
218 Eigen::VectorXd step(n);
219 Eigen::Map<const Eigen::VectorXd> r1_flat(r1_passed.data(), n);
220 Eigen::Map<const Eigen::VectorXd> r2_flat(r2.data(), n);
221 step = r2_flat - r1_flat;
227 Eigen::VectorXd result = r1_flat + step;
229 Eigen::Map<Eigen::VectorXd>(resultMat.data(), n) = result;
231 m2->setPositions(resultMat);
235 std::shared_ptr<Matter> m2) {
246 Eigen::VectorXd disp(3);
249 disp[0] = r12.col(0).sum();
250 disp[1] = r12.col(1).sum();
251 disp[2] = r12.col(2).sum();
254 for (
int i = 0; i < r1.rows(); i++) {
272 for (Eigen::Index i = 0; i < v1.rows(); ++i) {
285 for (
long i = 0; i + 3 <= n; i += 3) {
304 for (
int i = 0; i < v1.rows(); i++) {
305 double norm = v1.row(i).norm();
306 if (norm >= cutoff) {
318 if (max > maxMotion) {
319 v2 *= maxMotion / max;
329 if (max > maxMotion) {
330 v2 *= maxMotion / max;
340 if (max > maxMotion) {
341 v2 *= maxMotion / max;
351 if (max > maxMotion) {
352 v2 *= maxMotion / max;
376 const AtomMatrix &r2,
int left,
int right,
double tolerance) {
377 return std::fabs((m1.
pbc(r1.row(left) - r2.row(right))).norm()) < tolerance &&
382bool identicalAugment(
int left,
const std::vector<std::vector<int>> &adj,
383 std::vector<int> &matchRight, std::vector<char> &seen) {
384 for (
int right : adj[
static_cast<size_t>(left)]) {
385 if (seen[
static_cast<size_t>(right)] != 0) {
388 seen[
static_cast<size_t>(right)] = 1;
389 const int taken = matchRight[
static_cast<size_t>(right)];
390 if (taken < 0 || identicalAugment(taken, adj, matchRight, seen)) {
391 matchRight[
static_cast<size_t>(right)] = left;
403 const double distanceDifference) {
406 if (r1.rows() != r2.rows()) {
409 const int nAtoms =
static_cast<int>(r1.rows());
410 const double tolerance = distanceDifference;
412 bool indexAligned =
true;
413 for (
int i = 0; i < nAtoms; i++) {
414 if (!pairInside(m1, m2, r1, r2, i, i, tolerance)) {
415 indexAligned =
false;
423 std::vector<std::vector<int>> adj(
static_cast<size_t>(nAtoms));
424 for (
int left = 0; left < nAtoms; left++) {
425 for (
int right = 0; right < nAtoms; right++) {
426 if (pairInside(m1, m2, r1, r2, left, right, tolerance)) {
427 adj[
static_cast<size_t>(left)].push_back(right);
432 std::vector<int> matchRight(
static_cast<size_t>(nAtoms), -1);
434 for (
int left = 0; left < nAtoms; left++) {
435 std::vector<char> seen(
static_cast<size_t>(nAtoms), 0);
436 if (identicalAugment(left, adj, matchRight, seen)) {
440 return matched == nAtoms;
444 const double distanceDifference) {
448 double tolerance = distanceDifference;
451 if (r1.rows() != r2.rows()) {
456 std::vector<std::set<atom, by_atom>> rdf1(r1.rows());
457 std::vector<std::set<atom, by_atom>> rdf2(r2.rows());
459 for (
int i2 = 0; i2 < r2.rows(); i2++) {
461 for (
int j2 = 0; j2 < r2.rows(); j2++) {
472 for (
int i1 = 0; i1 < r1.rows(); i1++) {
473 if (matches == i1 - 2) {
476 for (
int j1 = 0; j1 < r1.rows(); j1++) {
485 for (
int x = 0; x < r2.rows(); x++) {
486 auto it2 = rdf2[x].begin();
487 auto it = rdf1[i1].begin();
490 for (; it != rdf1[i1].end() && it2 != rdf2[x].end(); ++it, ++it2) {
493 if (std::fabs(k1.
r - k2.
r) < tolerance && k1.
z == k2.
z) {
500 if (
static_cast<size_t>(counter) == rdf1[i1].size() &&
501 it2 == rdf2[x].end()) {
509 return matches >= r1.rows();
513 if (minDistance <= 0)
519 double cut = minDistance;
520 double pushAparts = 500;
522 for (
int count = 0; count < pushAparts; count++) {
524 for (
int i = 0; i < r1.rows(); i++) {
525 for (
int j = i + 1; j < r1.rows(); j++) {
530 delta.row(0) = r1.row(i) - r1.row(j);
531 delta = m1->pbc(delta);
544 for (
int axis = 0; axis <= 2; axis++) {
545 const double component = f * delta(0, axis) / d;
546 Force(i, axis) += component;
547 Force(j, axis) -= component;
555 m1->setPositions(r1);
558 r1 = m1->getPositions();
Eigen::Matrix< double, 3, 3, eOnStorageOrder > RotationMatrix
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Eigen::Matrix< double, 4, 4, eOnStorageOrder > Matrix4d
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
#define EONC_LOG_INFO(...)
const AtomMatrix & getPositions() const
void setPositions(const AtomMatrix &pos)
AtomMatrix pbc(const AtomMatrix &diff) const
double distance(long index1, long index2) const
long getAtomicNr(long int atom) const
double norm(const Eigen::MatrixBase< A > &x)
sqrt of the correctly rounded squared norm; IEEE sqrt is itself correctly rounded,...
double orderedNorm(const Eigen::MatrixBase< A > &x)
sqrt of orderedDot(x, x): reproducible, not correctly rounded.
RotationMatrix rotationExtract(const AtomMatrix r1, const AtomMatrix r2)
AtomMatrix maxAtomMotionApplied(const AtomMatrix v1, double maxMotion)
long numAtomsMoved(const AtomMatrix v1, double cutoff)
double maxAtomMotion(const AtomMatrix v1)
void pushApart(std::shared_ptr< Matter > m1, double minDistance)
bool rotationMatch(const Matter &m1, const Matter &m2, const double max_diff)
VectorXd maxMotionAppliedV(const VectorXd v1, double maxMotion)
void projectOutRotTrans(Eigen::VectorXd &step, const AtomMatrix &positions)
bool identical(const Matter &m1, const Matter &m2, const double distanceDifference)
VectorXd maxAtomMotionAppliedV(const VectorXd v1, double maxMotion)
double maxAtomMotionV(const VectorXd v1)
bool sortedR(const Matter &m1, const Matter &m2, const double distanceDifference)
void rotationRemove(const AtomMatrix r1, std::shared_ptr< Matter > m2)
AtomMatrix maxMotionApplied(const AtomMatrix v1, double maxMotion)
void translationRemove(Matter &m1, const AtomMatrix r1)
bool operator()(atom const &a, atom const &b) const