13#include "colvar_gpu_support.h"
17#include <unordered_map>
21#include "math_eigen_impl.h"
56 for (i = 0; i < size(); i++) {
70 if (data.size() > 0) {
97 data.assign(data.size(), T(0.0));
100 inline size_t size()
const
105 inline void resize(
size_t const n)
115 inline T & operator [] (
size_t const i) {
119 inline T
const & operator [] (
size_t const i)
const {
123 inline static void check_sizes(vector1d<T>
const &v1, vector1d<T>
const &v2)
125 if (v1.size() != v2.size()) {
126 cvm::error(
"Error: trying to perform an operation between vectors of different sizes, "+
131 inline void operator += (vector1d<T>
const &v)
133 check_sizes(*
this, v);
135 for (i = 0; i < this->size(); i++) {
140 inline void operator -= (vector1d<T>
const &v)
142 check_sizes(*
this, v);
144 for (i = 0; i < this->size(); i++) {
152 for (i = 0; i < this->size(); i++) {
160 for (i = 0; i < this->size(); i++) {
165 inline friend vector1d<T> operator + (vector1d<T>
const &v1,
166 vector1d<T>
const &v2)
168 check_sizes(v1.size(), v2.size());
169 vector1d<T> result(v1.size());
171 for (i = 0; i < v1.size(); i++) {
172 result[i] = v1[i] + v2[i];
177 inline friend vector1d<T> operator - (vector1d<T>
const &v1,
178 vector1d<T>
const &v2)
180 check_sizes(v1.size(), v2.size());
181 vector1d<T> result(v1.size());
183 for (i = 0; i < v1.size(); i++) {
184 result[i] = v1[i] - v2[i];
189 inline friend vector1d<T> operator * (vector1d<T>
const &v,
cvm::real a)
191 vector1d<T> result(v.size());
193 for (i = 0; i < v.size(); i++) {
194 result[i] = v[i] * a;
199 inline friend vector1d<T> operator * (
cvm::real a, vector1d<T>
const &v)
204 inline friend vector1d<T> operator / (vector1d<T>
const &v,
cvm::real a)
206 vector1d<T> result(v.size());
208 for (i = 0; i < v.size(); i++) {
209 result[i] = v[i] / a;
217 check_sizes(v1.size(), v2.size());
220 for (i = 0; i < v1.size(); i++) {
221 prod += v1[i] * v2[i];
231 for (i = 0; i < this->size(); i++) {
232 result += (*this)[i] * (*this)[i];
246 for (i = 0; i < this->size(); i++) {
247 result += (*this)[i];
255 if ((i2 < i1) || (i2 >= this->size())) {
256 cvm::error(
"Error: trying to slice a vector using incorrect boundaries.\n");
260 for (i = 0; i < (i2 - i1); i++) {
261 result[i] = (*this)[i1+i];
270 if ((i2 < i1) || (i2 >= this->size())) {
271 cvm::error(
"Error: trying to slice a vector using incorrect boundaries.\n");
274 for (i = 0; i < (i2 - i1); i++) {
275 (*this)[i1+i] = v[i];
283 return real_width*(this->size()) + 3*(this->size()-1) + 4;
286 inline friend std::istream & operator >> (std::istream &is,
289 if (v.size() == 0)
return is;
290 std::streampos
const start_pos = is.tellg();
292 if ( !(is >> sep) || !(sep ==
'(') ) {
294 is.seekg(start_pos, std::ios::beg);
295 is.setstate(std::ios::failbit);
299 while ( (is >> v[count]) &&
300 (count < (v.size()-1) ? ((is >> sep) && (sep ==
',')) :
true) ) {
301 if (++count == v.size())
break;
303 if (count < v.size()) {
305 is.seekg(start_pos, std::ios::beg);
306 is.setstate(std::ios::failbit);
311 inline friend std::ostream & operator << (std::ostream &os,
314 std::streamsize
const w = os.width();
315 std::streamsize
const p = os.precision();
320 for (i = 0; i < v.size()-1; i++) {
321 os.width(w); os.precision(p);
324 os.width(w); os.precision(p);
325 os << v[v.size()-1] <<
" )";
329 inline std::string to_simple_string()
const
331 if (this->size() == 0)
return std::string(
"");
332 std::ostringstream os;
333 os.setf(std::ios::scientific, std::ios::floatfield);
337 for (i = 1; i < this->size(); i++) {
338 os <<
" " << (*this)[i];
343 inline int from_simple_string(std::string
const &s)
345 std::stringstream stream(s);
348 while ((stream >> (*
this)[i]) && (i < this->size())) {
351 if (i < this->size()) {
352 return COLVARS_ERROR;
356 while (stream >> input) {
357 if ((i % 100) == 0) {
358 data.reserve(data.size()+100);
360 data.resize(data.size()+1);
388 inline row(T *
const row_data,
size_t const inner_length)
389 : data(row_data), length(inner_length)
391 inline T & operator [] (
size_t const j) {
394 inline T
const & operator [] (
size_t const j)
const {
403 if (v.size() != length) {
404 return cvm::error(
"Error: setting a matrix row from a vector of "
405 "incompatible size.\n", COLVARS_BUG_ERROR);
407 for (
size_t i = 0; i < length; i++) data[i] = v[i];
413 std::vector<row> rows;
414 std::vector<T *> pointers;
419 inline void resize(
size_t const ol,
size_t const il)
421 if ((ol > 0) && (il > 0)) {
423 if (data.size() > 0) {
426 std::vector<T> new_data(ol * il);
427 for (i = 0; i < outer_length; i++) {
428 for (j = 0; j < inner_length; j++) {
429 new_data[il*i+j] = data[inner_length*i+j];
432 data.resize(ol * il);
436 data.resize(ol * il);
442 if (data.size() > 0) {
446 rows.reserve(outer_length);
448 pointers.reserve(outer_length);
449 for (i = 0; i < outer_length; i++) {
450 rows.push_back(
row(&(data[0])+inner_length*i, inner_length));
451 pointers.push_back(&(data[0])+inner_length*i);
470 data.assign(data.size(), T(0.0));
473 inline size_t size()
const
480 : outer_length(0), inner_length(0)
485 inline matrix2d(
size_t const ol,
size_t const il)
486 : outer_length(ol), inner_length(il)
488 this->
resize(outer_length, inner_length);
494 : outer_length(m.outer_length), inner_length(m.inner_length)
497 this->
resize(outer_length, inner_length);
519 inline row & operator [] (
size_t const i)
523 inline row
const & operator [] (
size_t const i)
const
531 if ((outer_length != m.outer_length) || (inner_length != m.inner_length)){
533 outer_length = m.outer_length;
534 inner_length = m.inner_length;
535 this->
resize(outer_length, inner_length);
543 if (rows.size() > 0) {
544 return &(pointers[0]);
552 if ((m1.outer_length != m2.outer_length) ||
553 (m1.inner_length != m2.inner_length)) {
554 cvm::error(
"Error: trying to perform an operation between "
555 "matrices of different sizes, "+
563 inline void operator += (matrix2d<T>
const &m)
565 check_sizes(*
this, m);
567 for (i = 0; i < data.size(); i++) {
568 data[i] += m.data[i];
572 inline void operator -= (matrix2d<T>
const &m)
574 check_sizes(*
this, m);
576 for (i = 0; i < data.size(); i++) {
577 data[i] -= m.data[i];
584 for (i = 0; i < data.size(); i++) {
592 for (i = 0; i < data.size(); i++) {
597 inline friend matrix2d<T> operator + (matrix2d<T>
const &m1,
598 matrix2d<T>
const &m2)
601 matrix2d<T> result(m1.outer_length, m1.inner_length);
603 for (i = 0; i < m1.data.size(); i++) {
604 result.data[i] = m1.data[i] + m2.data[i];
609 inline friend matrix2d<T> operator - (matrix2d<T>
const &m1,
610 matrix2d<T>
const &m2)
613 matrix2d<T> result(m1.outer_length, m1.inner_length);
615 for (i = 0; i < m1.data.size(); i++) {
616 result.data[i] = m1.data[i] - m1.data[i];
621 inline friend matrix2d<T> operator * (matrix2d<T>
const &m,
cvm::real a)
623 matrix2d<T> result(m.outer_length, m.inner_length);
625 for (i = 0; i < m.data.size(); i++) {
626 result.data[i] = m.data[i] * a;
631 inline friend matrix2d<T> operator * (
cvm::real a, matrix2d<T>
const &m)
636 inline friend matrix2d<T> operator / (matrix2d<T>
const &m,
cvm::real a)
638 matrix2d<T> result(m.outer_length, m.inner_length);
640 for (i = 0; i < m.data.size(); i++) {
641 result.data[i] = m.data[i] * a;
651 if (m.outer_length != v.size()) {
652 cvm::error(
"Error: trying to multiply a vector and a matrix "
653 "of incompatible sizes, "+
659 for (i = 0; i < m.inner_length; i++) {
660 for (k = 0; k < m.outer_length; k++) {
661 result[i] += m[k][i] * v[k];
672 std::streamsize
const w = os.width();
673 std::streamsize
const p = os.precision();
678 for (i = 0; i < m.outer_length; i++) {
681 for (j = 0; j < m.inner_length-1; j++) {
684 os << m[i][j] <<
" , ";
688 os << m[i][m.inner_length-1] <<
" )";
695 inline std::string to_simple_string()
const
697 if (this->size() == 0)
return std::string(
"");
698 std::ostringstream os;
699 os.setf(std::ios::scientific, std::ios::floatfield);
703 for (i = 1; i < data.size(); i++) {
704 os <<
" " << data[i];
709 inline int from_simple_string(std::string
const &s)
711 std::stringstream stream(s);
713 while ((i < data.size()) && (stream >> data[i])) {
716 if (i < data.size()) {
717 return COLVARS_ERROR;
732 inline COLVARS_HOST_DEVICE
rvector()
738 inline COLVARS_HOST_DEVICE
void reset()
750 set(v[0], v[1], v[2]);
753 inline COLVARS_HOST_DEVICE rvector(
cvm::real t)
774 return (i == 0) ? x : (i == 1) ? y : (i == 2) ? z : x;
779 return (i == 0) ? x : (i == 1) ? y : (i == 2) ? z : x;
791 inline COLVARS_HOST_DEVICE
void operator += (
cvm::rvector const &v)
798 inline COLVARS_HOST_DEVICE
void operator -= (
cvm::rvector const &v)
805 inline COLVARS_HOST_DEVICE
void operator *= (
cvm::real v)
812 inline COLVARS_HOST_DEVICE
void operator /= (
cvm::real const& v)
819 inline COLVARS_HOST_DEVICE
cvm::real norm2()
const
821 return (x*x + y*y + z*z);
824 inline COLVARS_HOST_DEVICE
cvm::real norm()
const
826#if (!defined(__HIP_DEVICE_COMPILE__)) || (!defined (__CUDA_ARCH__))
827#define COLVARS_MATH_SQRT ::sqrt
829#define COLVARS_MATH_SQRT cvm::sqrt
831 return COLVARS_MATH_SQRT(this->norm2());
832#undef COLVARS_MATH_SQRT
841 static inline size_t output_width(
size_t real_width)
843 return 3*real_width + 10;
847 static inline COLVARS_HOST_DEVICE
852 -v1.x*v2.z + v2.x*v1.z,
853 v1.x*v2.y - v2.x*v1.y);
864 return cvm::rvector(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
869 return cvm::rvector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
876 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
894 std::string to_simple_string()
const;
895 int from_simple_string(std::string
const &s);
905 cvm::real xx, xy, xz, yx, yy, yz, zx, zy, zz;
914 inline COLVARS_HOST_DEVICE
931 inline COLVARS_HOST_DEVICE
void reset()
933 xx = xy = xz = yx = yy = yz = zx = zy = zz = 0.0;
940 ( xx * (yy*zz - zy*yz))
941 - (yx * (xy*zz - zy*xz))
942 + (zx * (xy*yz - yy*xz));
945 inline COLVARS_HOST_DEVICE
cvm::rmatrix transpose()
const
956 m.yx*r.x + m.yy*r.y + m.yz*r.z,
957 m.zx*r.x + m.zy*r.y + m.zz*r.z);
960 inline COLVARS_HOST_DEVICE
rmatrix& operator+=(
const rmatrix& rhs) {
986 : q0(qv[0]), q1(qv[1]), q2(qv[2]), q3(qv[3])
994 : q0(q0i), q1(q1i), q2(q2i), q3(q3i)
998 : q0(v[0]), q1(v[1]), q2(v[2]), q3(v[3])
1010 q0 = q1 = q2 = q3 = 0.0;
1016 return 4*real_width + 13;
1019 std::string to_simple_string()
const;
1020 int from_simple_string(std::string
const &s);
1039#if !(defined(__NVCC__) || defined(__HIPCC__))
1040 cvm::error(
"Error: incorrect quaternion component.\n");
1058#if !(defined(__NVCC__) || defined(__HIPCC__))
1059 cvm::error(
"Error: trying to access a quaternion "
1060 "component which is not between 0 and 3.\n");
1079 return q0*q0 + q1*q1 + q2*q2 + q3*q3;
1085#if (!defined(__HIP_DEVICE_COMPILE__)) || (!defined (__CUDA_ARCH__))
1086#define COLVARS_MATH_SQRT ::sqrt
1088#define COLVARS_MATH_SQRT cvm::sqrt
1090 return COLVARS_MATH_SQRT(this->
norm2());
1091#undef COLVARS_MATH_SQRT
1100 inline COLVARS_HOST_DEVICE
void operator *= (
cvm::real a)
1102 q0 *= a; q1 *= a; q2 *= a; q3 *= a;
1105 inline COLVARS_HOST_DEVICE
void operator /= (
cvm::real a)
1107 q0 /= a; q1 /= a; q2 /= a; q3 /= a;
1110 inline COLVARS_HOST_DEVICE
void set_positive()
1112 if (q0 > 0.0)
return;
1119 inline COLVARS_HOST_DEVICE
void operator += (
cvm::quaternion const &h)
1121 q0+=h.q0; q1+=h.q1; q2+=h.q2; q3+=h.q3;
1123 inline COLVARS_HOST_DEVICE
void operator -= (
cvm::quaternion const &h)
1125 q0-=h.q0; q1-=h.q1; q2-=h.q2; q3-=h.q3;
1153 h.q0*q.q1 + h.q1*q.q0 + h.q2*q.q3 - h.q3*q.q2,
1154 h.q0*q.q2 + h.q2*q.q0 + h.q3*q.q1 - h.q1*q.q3,
1155 h.q0*q.q3 + h.q3*q.q0 + h.q1*q.q2 - h.q2*q.q1);
1196 R.xx = q0*q0 + q1*q1 - q2*q2 - q3*q3;
1197 R.yy = q0*q0 - q1*q1 + q2*q2 - q3*q3;
1198 R.zz = q0*q0 - q1*q1 - q2*q2 + q3*q3;
1200 R.xy = 2.0 * (q1*q2 - q0*q3);
1201 R.xz = 2.0 * (q0*q2 + q1*q3);
1203 R.yx = 2.0 * (q0*q3 + q1*q2);
1204 R.yz = 2.0 * (q2*q3 - q0*q1);
1206 R.zx = 2.0 * (q1*q3 - q0*q2);
1207 R.zy = 2.0 * (q0*q1 + q2*q3);
1246 template <
typename T>
1249 2.0 * ( q0 * C[0][0] - q3 * C[0][1] + q2 * C[0][2] +
1250 q3 * C[1][0] + q0 * C[1][1] - q1 * C[1][2] +
1251 -q2 * C[2][0] + q1 * C[2][1] + q0 * C[2][2]),
1252 2.0 * ( q1 * C[0][0] + q2 * C[0][1] + q3 * C[0][2] +
1253 q2 * C[1][0] - q1 * C[1][1] - q0 * C[1][2] +
1254 q3 * C[2][0] + q0 * C[2][1] - q1 * C[2][2]),
1255 2.0 * (-q2 * C[0][0] + q1 * C[0][1] + q0 * C[0][2] +
1256 q1 * C[1][0] + q2 * C[1][1] + q3 * C[1][2] +
1257 -q0 * C[2][0] + q3 * C[2][1] - q2 * C[2][2]),
1258 2.0 * (-q3 * C[0][0] - q0 * C[0][1] + q1 * C[0][2] +
1259 q0 * C[1][0] - q3 * C[1][1] + q2 * C[1][2] +
1260 q1 * C[2][0] + q2 * C[2][1] + q3 * C[2][2])
1269 return 2.0*iprod*iprod - 1.0;
1277 cvm::real const cos_omega = this->q0*Q2.q0 + this->q1*Q2.q1 +
1278 this->q2*Q2.q2 + this->q3*Q2.q3;
1279#if (!defined(__HIP_DEVICE_COMPILE__)) || (!defined (__CUDA_ARCH__))
1280#define COLVARS_MATH_ACOS ::acos
1282#define COLVARS_MATH_ACOS cvm::acos
1284 cvm::real const omega = COLVARS_MATH_ACOS( (cos_omega > 1.0) ? 1.0 :
1285 ( (cos_omega < -1.0) ? -1.0 : cos_omega) );
1286#undef COLVARS_MATH_ACOS
1289 if (cos_omega > 0.0)
1290 return omega * omega;
1292 return (PI-omega) * (PI-omega);
1299#if (!defined(__HIP_DEVICE_COMPILE__)) || (!defined (__CUDA_ARCH__))
1300#define COLVARS_MATH_ACOS ::acos
1301#define COLVARS_MATH_SIN ::sin
1302#define COLVARS_MATH_FABS ::fabs
1304#define COLVARS_MATH_ACOS cvm::acos
1305#define COLVARS_MATH_SIN cvm::sin
1306#define COLVARS_MATH_FABS cvm::fabs
1308 cvm::real const cos_omega = this->q0*Q2.q0 + this->q1*Q2.q1 + this->q2*Q2.q2 + this->q3*Q2.q3;
1309 cvm::real const omega = COLVARS_MATH_ACOS( (cos_omega > 1.0) ? 1.0 :
1310 ( (cos_omega < -1.0) ? -1.0 : cos_omega) );
1311 cvm::real const sin_omega = COLVARS_MATH_SIN(omega);
1313 if (COLVARS_MATH_FABS(sin_omega) < 1.0E-14) {
1317#undef COLVARS_MATH_ACOS
1318#undef COLVARS_MATH_SIN
1319#undef COLVARS_MATH_FABS
1321 grad1((-1.0)*sin_omega*Q2.q0 + cos_omega*(this->q0-cos_omega*Q2.q0)/sin_omega,
1322 (-1.0)*sin_omega*Q2.q1 + cos_omega*(this->q1-cos_omega*Q2.q1)/sin_omega,
1323 (-1.0)*sin_omega*Q2.q2 + cos_omega*(this->q2-cos_omega*Q2.q2)/sin_omega,
1324 (-1.0)*sin_omega*Q2.q3 + cos_omega*(this->q3-cos_omega*Q2.q3)/sin_omega);
1326 if (cos_omega > 0.0) {
1327 return 2.0*omega*grad1;
1329 return -2.0*(PI-omega)*grad1;
1337 cvm::real const cos_omega = this->q0*Q2.q0 + this->q1*Q2.q1 +
1338 this->q2*Q2.q2 + this->q3*Q2.q3;
1339 if (cos_omega < 0.0) Q2 *= -1.0;
1346 cvm::real const prod = this->q0*Q2.q0 + this->q1*Q2.q1 +
1347 this->q2*Q2.q2 + this->q3*Q2.q3;
1354#ifndef COLVARS_LAMMPS
1356int diagonalize_matrix(
cvm::real m[4][4],
1408 const cvm::ag_vector_real_t &pos1,
1409 const cvm::ag_vector_real_t &pos2,
1410 const size_t num_atoms_pos1,
1411 const size_t num_atoms_pos2);
1424 std::vector<atom_pos>
const &pos2);
1425 void calc_optimal_rotation_soa(
1426 cvm::ag_vector_real_t
const &pos1,
1427 cvm::ag_vector_real_t
const &pos2,
1428 const size_t num_atoms_pos1,
1429 const size_t num_atoms_pos2);
1470 while (alpha > 180.0) alpha -= 360;
1471 while (alpha < -180.0) alpha += 360;
1485 (180.0/PI) * 2.0 * (1.0 / (1.0 + (iprod*iprod)/(
q.q0*
q.q0)));
1488 dspindx * ((1.0/
q.q0) * axis.x),
1489 dspindx * ((1.0/
q.q0) * axis.y),
1490 dspindx * ((1.0/
q.q0) * axis.z));
1495 return cvm::quaternion((180.0/PI) * 2.0 * ((-1.0)/iprod), 0.0, 0.0, 0.0);
1505 (180.0/PI) * 2.0 *
cvm::atan2(axis * q_vec,
q.q0);
1508 cvm::real const cos_theta_2 = ( (cos_spin_2 != 0.0) ?
1509 (
q.q0 / cos_spin_2) :
1512 return 2.0 * (cos_theta_2*cos_theta_2) - 1.0;
1526 (4.0 *
q.q0 / (cos_spin_2*cos_spin_2)) *
1527 (1.0 - (iprod*iprod)/(
q.q0*
q.q0) / (1.0 + (iprod*iprod)/(
q.q0*
q.q0)));
1530 (4.0 *
q.q0 / (cos_spin_2*cos_spin_2) *
1531 (iprod/
q.q0) / (1.0 + (iprod*iprod)/(
q.q0*
q.q0)));
1534 d_cos_theta_dqn * axis.x,
1535 d_cos_theta_dqn * axis.y,
1536 d_cos_theta_dqn * axis.z);
1540 (4.0 / (cos_spin_2*cos_spin_2 * iprod));
1543 d_cos_theta_dqn * axis.x,
1544 d_cos_theta_dqn * axis.y,
1545 d_cos_theta_dqn * axis.z);
1563 std::vector<cvm::atom_pos>
const &pos2);
1575#if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
1576namespace colvars_gpu {
1604 int* discontinuous_rotation;
1636 const size_t num_atoms_pos1,
1637 const size_t num_atoms_pos2,
1639 std::unordered_map<std::string, cudaGraphNode_t>& nodes_map);
Definition: colvartypes.h:384
Arbitrary size array (two dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:375
matrix2d(matrix2d< T > const &m)
Copy constructor.
Definition: colvartypes.h:493
T ** c_array()
Return the 2-d C array.
Definition: colvartypes.h:542
void clear()
Deallocation routine.
Definition: colvartypes.h:462
~matrix2d()
Destructor.
Definition: colvartypes.h:503
std::vector< T > const & data_array() const
Return a reference to the data.
Definition: colvartypes.h:514
matrix2d< T > & operator=(matrix2d< T > const &m)
Assignment.
Definition: colvartypes.h:529
matrix2d()
Default constructor.
Definition: colvartypes.h:479
std::vector< T > & data_array()
Return a reference to the data.
Definition: colvartypes.h:508
void resize(size_t const ol, size_t const il)
Allocation routine, used by all constructors.
Definition: colvartypes.h:419
friend std::ostream & operator<<(std::ostream &os, matrix2d< T > const &m)
Formatted output.
Definition: colvartypes.h:669
void reset()
Set all elements to zero.
Definition: colvartypes.h:468
1-dimensional vector of real numbers with four components and a quaternion algebra
Definition: colvartypes.h:978
friend COLVARS_HOST_DEVICE cvm::quaternion operator*(cvm::quaternion const &h, cvm::quaternion const &q)
Provides the quaternion product. NOTE: for the inner product use: h.inner (q);
Definition: colvartypes.h:1149
COLVARS_HOST_DEVICE cvm::rvector rotate(cvm::rvector const &v) const
Rotate v through this quaternion (put it in the rotated reference frame)
Definition: colvartypes.h:1177
COLVARS_HOST_DEVICE cvm::real & operator[](int i)
Access the quaternion as a 4-d array (return a reference)
Definition: colvartypes.h:1028
COLVARS_HOST_DEVICE quaternion(cvm::real q0i, cvm::real q1i, cvm::real q2i, cvm::real q3i)
Constructor component by component.
Definition: colvartypes.h:990
friend std::istream & operator>>(std::istream &is, cvm::quaternion &q)
Formatted input operator.
Definition: colvartypes.cpp:129
COLVARS_HOST_DEVICE cvm::quaternion rotate(cvm::quaternion const &Q2) const
Rotate Q2 through this quaternion (put it in the rotated reference frame)
Definition: colvartypes.h:1185
COLVARS_HOST_DEVICE void match(cvm::quaternion &Q2) const
Choose the closest between Q2 and -Q2 and save it back. Not required for dist2() and dist2_grad()
Definition: colvartypes.h:1335
COLVARS_HOST_DEVICE quaternion()
Default constructor.
Definition: colvartypes.h:1002
COLVARS_HOST_DEVICE cvm::quaternion conjugate() const
Return the conjugate quaternion.
Definition: colvartypes.h:1095
COLVARS_HOST_DEVICE cvm::real norm2() const
Square norm of the quaternion.
Definition: colvartypes.h:1077
friend std::ostream & operator<<(std::ostream &os, cvm::quaternion const &q)
Formatted output operator.
Definition: colvartypes.cpp:110
COLVARS_HOST_DEVICE cvm::real norm() const
Norm of the quaternion.
Definition: colvartypes.h:1083
COLVARS_HOST_DEVICE void reset()
Set all components to zero (null quaternion)
Definition: colvartypes.h:1008
COLVARS_HOST_DEVICE cvm::real dist2(cvm::quaternion const &Q2) const
Square distance from another quaternion on the 4-dimensional unit sphere: returns the square of the a...
Definition: colvartypes.h:1275
static size_t output_width(size_t real_width)
Tell the number of characters required to print a quaternion, given that of a real number.
Definition: colvartypes.h:1014
COLVARS_HOST_DEVICE cvm::rvector get_vector() const
Return the vector component.
Definition: colvartypes.h:1129
COLVARS_HOST_DEVICE cvm::real inner(cvm::quaternion const &Q2) const
Inner product (as a 4-d vector) with Q2; requires match() if the largest overlap is looked for.
Definition: colvartypes.h:1344
COLVARS_HOST_DEVICE cvm::quaternion dist2_grad(cvm::quaternion const &Q2) const
Definition: colvartypes.h:1297
COLVARS_HOST_DEVICE cvm::rmatrix rotation_matrix() const
Return the 3x3 matrix associated to this quaternion.
Definition: colvartypes.h:1192
COLVARS_HOST_DEVICE quaternion(cvm::real const qv[4])
Constructor component by component.
Definition: colvartypes.h:985
COLVARS_HOST_DEVICE T derivative_element_wise_product_sum(const cvm::real(&C)[3][3]) const
Calculate the sums of element-wise products of a given matrix with respect to dR/dq0,...
Definition: colvartypes.h:1247
COLVARS_HOST_DEVICE cvm::real cosine(cvm::quaternion const &q) const
Return the cosine between the orientation frame associated to this quaternion and another.
Definition: colvartypes.h:1266
2-dimensional array of real numbers with three components along each dimension (works with colvarmodu...
Definition: colvartypes.h:901
COLVARS_HOST_DEVICE rmatrix(cvm::real xxi, cvm::real xyi, cvm::real xzi, cvm::real yxi, cvm::real yyi, cvm::real yzi, cvm::real zxi, cvm::real zyi, cvm::real zzi)
Constructor component by component.
Definition: colvartypes.h:915
COLVARS_HOST_DEVICE rmatrix()
Default constructor.
Definition: colvartypes.h:908
COLVARS_HOST_DEVICE cvm::real determinant() const
Return the determinant.
Definition: colvartypes.h:937
A rotation between two sets of coordinates (for the moment a wrapper for colvarmodule::quaternion)
Definition: colvartypes.h:1366
~rotation()
Destructor.
Definition: colvartypes.cpp:204
cvm::rmatrix C
Correlation matrix C (3, 3)
Definition: colvartypes.h:1369
rotation()
Default constructor.
Definition: colvartypes.cpp:166
cvm::real cos_theta(cvm::rvector const &axis) const
Return the projection of the orientation vector onto a predefined axis.
Definition: colvartypes.h:1501
cvm::real S_eigval[4]
Eigenvalues of S.
Definition: colvartypes.h:1375
cvm::real S_backup[4][4]
Used for debugging gradients.
Definition: colvartypes.h:1381
cvm::rvector rotate(cvm::rvector const &v) const
Return the rotated vector.
Definition: colvartypes.h:1447
int init()
Initialize member data.
Definition: colvartypes.cpp:157
cvm::real S[4][4]
Overlap matrix S (4, 4)
Definition: colvartypes.h:1372
cvm::quaternion dspin_angle_dq(cvm::rvector const &axis) const
Return the derivative of the spin angle with respect to the quaternion.
Definition: colvartypes.h:1477
cvm::quaternion dcos_theta_dq(cvm::rvector const &axis) const
Return the derivative of the tilt wrt the quaternion.
Definition: colvartypes.h:1516
cvm::real spin_angle(cvm::rvector const &axis) const
Return the spin angle (in degrees) with respect to the provided axis (which MUST be normalized)
Definition: colvartypes.h:1466
cvm::real S_eigvec[4][4]
Eigenvectors of S.
Definition: colvartypes.h:1378
void calc_optimal_rotation(std::vector< atom_pos > const &pos1, std::vector< atom_pos > const &pos2)
Calculate the optimal rotation and store the corresponding eigenvalue and eigenvector in the argument...
Definition: colvartypes.cpp:385
static cvm::real crossing_threshold
Threshold for the eigenvalue crossing test.
Definition: colvartypes.h:1552
cvm::quaternion q_old
Previous value of the rotation (used to warn the user when the structure changes too much,...
Definition: colvartypes.h:1559
static bool monitor_crossings
Whether to test for eigenvalue crossing.
Definition: colvartypes.h:1550
bool b_debug_gradients
Perform gradient tests.
Definition: colvartypes.h:1385
void build_correlation_matrix(std::vector< cvm::atom_pos > const &pos1, std::vector< cvm::atom_pos > const &pos2)
Build the correlation matrix C (used by calc_optimal_rotation())
Definition: colvartypes.cpp:215
cvm::rmatrix matrix() const
Return the associated 3x3 matrix.
Definition: colvartypes.h:1459
void * jacobi
Pointer to instance of Jacobi solver.
Definition: colvartypes.h:1572
void compute_overlap_matrix()
Compute the overlap matrix S (used by calc_optimal_rotation())
Definition: colvartypes.cpp:235
void debug_gradients(cvm::rotation &rot, const cvm::ag_vector_real_t &pos1, const cvm::ag_vector_real_t &pos2, const size_t num_atoms_pos1, const size_t num_atoms_pos2)
Function for debugging gradients.
Definition: colvartypes.cpp:297
void calc_optimal_rotation_impl()
Actual implementation of calc_optimal_rotation (and called by it)
Definition: colvartypes.cpp:435
cvm::rotation inverse() const
Return the inverse of this rotation.
Definition: colvartypes.h:1453
cvm::quaternion q
The rotation itself (implemented as a quaternion)
Definition: colvartypes.h:1388
vector of real numbers with three components
Definition: colvartypes.h:726
COLVARS_HOST_DEVICE void reset()
Set all components to zero.
Definition: colvartypes.h:738
COLVARS_HOST_DEVICE void set(cvm::real value)
Set all components to a scalar.
Definition: colvartypes.h:759
friend COLVARS_HOST_DEVICE cvm::real operator*(cvm::rvector const &v1, cvm::rvector const &v2)
Inner (dot) product.
Definition: colvartypes.h:873
COLVARS_HOST_DEVICE void set(cvm::real x_i, cvm::real y_i, cvm::real z_i)
Assign all components.
Definition: colvartypes.h:765
COLVARS_HOST_DEVICE cvm::real & operator[](int i)
Access cartesian components by index.
Definition: colvartypes.h:773
Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:36
void reset()
Set all elements to zero.
Definition: colvartypes.h:95
size_t output_width(size_t real_width) const
Formatted output.
Definition: colvartypes.h:281
cvm::real norm2() const
Squared norm.
Definition: colvartypes.h:227
void sliceassign(size_t const i1, size_t const i2, vector1d< T > const &v)
Assign a vector to a slice of this vector.
Definition: colvartypes.h:267
std::vector< T > & data_array()
Return a reference to the data.
Definition: colvartypes.h:78
vector1d & operator=(const vector1d &)=default
Explicit Copy assignement.
vector1d(const vector1d &)=default
Explicit Copy constructor.
vector1d(size_t const n, T const *t)
Constructor from C array.
Definition: colvartypes.h:51
vector1d(size_t const n=0)
Default constructor.
Definition: colvartypes.h:44
T * c_array()
Return a pointer to the data location.
Definition: colvartypes.h:68
vector1d< T > const slice(size_t const i1, size_t const i2) const
Slicing.
Definition: colvartypes.h:253
std::vector< T > const & data_array() const
Return a reference to the data.
Definition: colvartypes.h:84
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:98
static real cos(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:148
static int error(std::string const &message, int code=-1)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:2181
static real atan2(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:193
static size_t const cv_prec
Number of digits to represent a collective variables value(s)
Definition: colvarmodule.h:708
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:136
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2536
Definition: colvartypes.h:1578
int add_optimal_rotation_nodes(cvm::real *const d_pos1, cvm::real *const d_pos2, const size_t num_atoms_pos1, const size_t num_atoms_pos2, cudaGraph_t &graph, std::unordered_map< std::string, cudaGraphNode_t > &nodes_map)
Calculate the optimal rotation and store the corresponding eigenvalue and eigenvector in the argument...
Definition: colvartypes.cpp:553
cvm::real * d_S_eigvec
Eigenvectors of S.
Definition: colvartypes.h:1593
cvm::real * d_S_eigval
Eigenvalues of S.
Definition: colvartypes.h:1586
int * max_iteration_reached
Flag for checking if eigendecomposition is failed.
Definition: colvartypes.h:1606
cvm::quaternion * d_q
The rotation itself (implemented as a quaternion)
Definition: colvartypes.h:1601
cvm::real * d_S
Correlation matrix C (3, 3)
Definition: colvartypes.h:1584
unsigned int * tbcount
Used for debugging gradients.
Definition: colvartypes.h:1599
int init()
Initialize member data.
Definition: colvartypes.cpp:524
void after_sync_check() const
Checking after synchronization ( eigendecomposition iterations and max crossing)
Definition: colvartypes.cpp:621
cvm::rmatrix * h_C
Host data for compatibility with CPU buffers.
Definition: colvartypes.h:1610
bool b_initialized
Flag for checking if initialized.
Definition: colvartypes.h:1608
~rotation_gpu()
Destructor.
Definition: colvartypes.cpp:507
cvm::quaternion * d_q_old
Crossing monitor.
Definition: colvartypes.h:1603
rotation_gpu()
Constructor.
Definition: colvartypes.cpp:497
bool initialized() const
Check if the object is initialized.
Definition: colvartypes.h:1620
Store the information of a group of atoms in a structure-of-arrays (SoA) style.
Definition: colvaratoms.h:52
Collective variables main module.
Definition: colvar_rotation_derivative.h:622
Helper class for calculating the derivative of rotation.
Definition: colvar_rotation_derivative.h:42