Loading...
Searching...
No Matches
dimer Namespace Reference

Classes

class  Dimer
 Dimer method. More...
class  SphereRotation

Typedefs

using Index_t

Functions

Eigen::MatrixXd rigid_motion_basis (const gpr::Coord &R, bool rotations=true)
 Build an orthonormal basis for rigid-body translations and rotations.
double project_out_rot_trans_with_feedback (const gpr::Coord &R, Eigen::VectorXd &step)
 Project rigid-body motion out of a Cartesian optimization step.

Typedef Documentation

◆ Index_t

using gpr::Index_t

Definition at line 17 of file Macros.h.

Function Documentation

◆ project_out_rot_trans_with_feedback()

double dimer::project_out_rot_trans_with_feedback ( const gpr::Coord & R,
Eigen::VectorXd & step )

Project rigid-body motion out of a Cartesian optimization step.

Parameters
RCurrent atomic coordinates defining the rigid-motion basis.
stepThe 3N-dimensional optimization step, modified in place.
Returns
L2 norm of the rigid-motion component removed from the step.

Definition at line 116 of file Dimer.cpp.

118{
119 const Eigen::MatrixXd basis = rigid_motion_basis(R);
120 if (basis.rows() != step.size())
121 throw std::invalid_argument(
122 "rigid projection position/step dimensions");
123 const Eigen::VectorXd removed = basis * (basis.transpose() * step);
124 step -= removed;
125 return removed.norm();
126}
Eigen::MatrixXd rigid_motion_basis(const gpr::Coord &R, bool rotations)
Build an orthonormal basis for rigid-body translations and rotations.
Definition Dimer.cpp:30

◆ rigid_motion_basis()

Eigen::MatrixXd dimer::rigid_motion_basis ( const gpr::Coord & R,
bool rotations = true )

Build an orthonormal basis for rigid-body translations and rotations.

This function constructs a basis for the 3 translational and 3 rotational degrees of freedom. It then orthonormalizes that basis with classical Gram-Schmidt, dropping any vector whose residual norm is at most 1e-9 (linear molecules lose one rotation). Periodic systems use translations only.

Parameters
RThe current atomic coordinates, used to define the rotational basis.
rotationsInclude rotational directions for non-periodic systems.
Returns
Orthonormal rigid-motion directions as columns. Orthonormal Cartesian symmetry directions as contiguous columns. Periodic systems request translations only; linear molecules lose one rotation.

Definition at line 30 of file Dimer.cpp.

31{
32 const gpr::Index_t num_atoms = R.cols() / 3;
33 const gpr::Index_t dof = num_atoms * 3;
34
35 if (num_atoms == 0 || R.rows() != 1 || R.cols() % 3 != 0) {
36 return Eigen::MatrixXd(R.cols(), 0);
37 }
38
39 // 1. Calculate the Center of Mass (COM)
40 gpr::vector3_reg com(0.0, 0.0, 0.0);
41 for (Index_t i = 0; i < num_atoms; ++i) {
42 com += gpr::coord::at(R, 0, i);
43 }
44 com /= static_cast<double>(num_atoms);
45
46 // 2. Construct the 6 basis vectors for translation and rotation
47 std::vector<Eigen::VectorXd> basis;
48 basis.reserve(6);
49
50 // Translational basis vectors
51 for (int i = 0; i < 3; ++i) {
52 Eigen::VectorXd t = Eigen::VectorXd::Zero(dof);
53 for (Index_t j = 0; j < num_atoms; ++j) {
54 t(3 * j + i) = 1.0;
55 }
56 basis.push_back(t);
57 }
58
59 // Rotational basis vectors (using coordinates relative to COM)
60 Eigen::VectorXd r_x = Eigen::VectorXd::Zero(dof);
61 Eigen::VectorXd r_y = Eigen::VectorXd::Zero(dof);
62 Eigen::VectorXd r_z = Eigen::VectorXd::Zero(dof);
63
64 for (Index_t i = 0; i < num_atoms; ++i) {
65 gpr::vector3_reg pos = gpr::coord::at(R, 0, i) - com;
66 // Rotation around x-axis: dR = a * (i x R) = a * (0, -z, y)
67 r_x(3 * i + 1) = -pos(2);
68 r_x(3 * i + 2) = pos(1);
69 // Rotation around y-axis: dR = a * (j x R) = a * (z, 0, -x)
70 r_y(3 * i + 0) = pos(2);
71 r_y(3 * i + 2) = -pos(0);
72 // Rotation around z-axis: dR = a * (k x R) = a * (-y, x, 0)
73 r_z(3 * i + 0) = -pos(1);
74 r_z(3 * i + 1) = pos(0);
75 }
76 if (rotations) {
77 basis.push_back(r_x);
78 basis.push_back(r_y);
79 basis.push_back(r_z);
80 }
81
82 // 3. Orthonormalize the basis using Gram-Schmidt. The quotient of
83 // configuration space by rigid motions is singular on the linear
84 // stratum: rotation about the molecular axis fixes the geometry, its
85 // generator vanishes and the rigid subspace drops to rank five. The
86 // rank is read from the generators themselves: a generator below the
87 // roundoff of the cross products that built it (machine epsilon times
88 // the extent of the geometry about its centre) is the zero generator.
89 double extent = 0.0;
90 for (Index_t i = 0; i < num_atoms; ++i)
91 extent += (gpr::coord::at(R, 0, i) - com).squaredNorm();
92 const double resolution = std::numeric_limits<double>::epsilon() *
93 static_cast<double>(dof) *
94 std::max(std::sqrt(extent), 1.0);
95 std::vector<Eigen::VectorXd> ortho_basis;
96 ortho_basis.reserve(6);
97
98 for (auto& v: basis) {
99 Eigen::VectorXd u = v;
100 for (int pass = 0; pass < 2; ++pass)
101 for (const auto& ou: ortho_basis) {
102 u -= u.dot(ou) * ou;
103 }
104 if (u.norm() > resolution) {
105 u.normalize();
106 ortho_basis.push_back(u);
107 }
108 }
109
110 Eigen::MatrixXd result(dof, static_cast<Eigen::Index>(ortho_basis.size()));
111 for (Eigen::Index i = 0; i < result.cols(); ++i)
112 result.col(i) = ortho_basis[static_cast<std::size_t>(i)];
113 return result;
114}
Eigen::Vector3d at(const FieldMatrixd &mat, Index_t i)
Eigen::Vector3d vector3_reg
Definition Macros.h:36
uint32_t Index_t
Definition Macros.h:17