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_static(
"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_static(
"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_static(
"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);
338 for (i = 1; i < this->size(); i++) {
339 os <<
" " << (*this)[i];
344 inline int from_simple_string(std::string
const &s)
346 std::stringstream stream(s);
349 while ((i < this->size()) && (stream >> (*
this)[i])) {
352 if (i < this->size()) {
353 return COLVARS_ERROR;
357 while (stream >> input) {
358 if ((i % 100) == 0) {
359 data.reserve(data.size()+100);
361 data.resize(data.size()+1);
389 inline row(T *
const row_data,
size_t const inner_length)
390 : data(row_data), length(inner_length)
392 inline T & operator [] (
size_t const j) {
395 inline T
const & operator [] (
size_t const j)
const {
404 if (v.size() != length) {
406 "incompatible size.\n", COLVARS_BUG_ERROR);
408 for (
size_t i = 0; i < length; i++) data[i] = v[i];
414 std::vector<row> rows;
415 std::vector<T *> pointers;
420 inline void resize(
size_t const ol,
size_t const il)
422 if ((ol > 0) && (il > 0)) {
424 if (data.size() > 0) {
427 std::vector<T> new_data(ol * il);
428 for (i = 0; i < outer_length; i++) {
429 for (j = 0; j < inner_length; j++) {
430 new_data[il*i+j] = data[inner_length*i+j];
433 data.resize(ol * il);
437 data.resize(ol * il);
443 if (data.size() > 0) {
447 rows.reserve(outer_length);
449 pointers.reserve(outer_length);
450 for (i = 0; i < outer_length; i++) {
451 rows.push_back(
row(&(data[0])+inner_length*i, inner_length));
452 pointers.push_back(&(data[0])+inner_length*i);
471 data.assign(data.size(), T(0.0));
474 inline size_t size()
const
481 : outer_length(0), inner_length(0)
486 inline matrix2d(
size_t const ol,
size_t const il)
487 : outer_length(ol), inner_length(il)
489 this->
resize(outer_length, inner_length);
495 : outer_length(m.outer_length), inner_length(m.inner_length)
498 this->
resize(outer_length, inner_length);
520 inline row & operator [] (
size_t const i)
524 inline row
const & operator [] (
size_t const i)
const
532 if ((outer_length != m.outer_length) || (inner_length != m.inner_length)){
534 outer_length = m.outer_length;
535 inner_length = m.inner_length;
536 this->
resize(outer_length, inner_length);
544 if (rows.size() > 0) {
545 return &(pointers[0]);
553 if ((m1.outer_length != m2.outer_length) ||
554 (m1.inner_length != m2.inner_length)) {
556 "matrices of different sizes, "+
564 inline void operator += (matrix2d<T>
const &m)
566 check_sizes(*
this, m);
568 for (i = 0; i < data.size(); i++) {
569 data[i] += m.data[i];
573 inline void operator -= (matrix2d<T>
const &m)
575 check_sizes(*
this, m);
577 for (i = 0; i < data.size(); i++) {
578 data[i] -= m.data[i];
585 for (i = 0; i < data.size(); i++) {
593 for (i = 0; i < data.size(); i++) {
598 inline friend matrix2d<T> operator + (matrix2d<T>
const &m1,
599 matrix2d<T>
const &m2)
602 matrix2d<T> result(m1.outer_length, m1.inner_length);
604 for (i = 0; i < m1.data.size(); i++) {
605 result.data[i] = m1.data[i] + m2.data[i];
610 inline friend matrix2d<T> operator - (matrix2d<T>
const &m1,
611 matrix2d<T>
const &m2)
614 matrix2d<T> result(m1.outer_length, m1.inner_length);
616 for (i = 0; i < m1.data.size(); i++) {
617 result.data[i] = m1.data[i] - m1.data[i];
622 inline friend matrix2d<T> operator * (matrix2d<T>
const &m,
cvm::real a)
624 matrix2d<T> result(m.outer_length, m.inner_length);
626 for (i = 0; i < m.data.size(); i++) {
627 result.data[i] = m.data[i] * a;
632 inline friend matrix2d<T> operator * (
cvm::real a, matrix2d<T>
const &m)
637 inline friend matrix2d<T> operator / (matrix2d<T>
const &m,
cvm::real a)
639 matrix2d<T> result(m.outer_length, m.inner_length);
641 for (i = 0; i < m.data.size(); i++) {
642 result.data[i] = m.data[i] * a;
652 if (m.outer_length != v.size()) {
654 "of incompatible sizes, "+
660 for (i = 0; i < m.inner_length; i++) {
661 for (k = 0; k < m.outer_length; k++) {
662 result[i] += m[k][i] * v[k];
673 std::streamsize
const w = os.width();
674 std::streamsize
const p = os.precision();
679 for (i = 0; i < m.outer_length; i++) {
682 for (j = 0; j < m.inner_length-1; j++) {
685 os << m[i][j] <<
" , ";
689 os << m[i][m.inner_length-1] <<
" )";
696 inline std::string to_simple_string()
const
698 if (this->size() == 0)
return std::string(
"");
699 std::ostringstream os;
700 os.setf(std::ios::scientific, std::ios::floatfield);
705 for (i = 1; i < data.size(); i++) {
706 os <<
" " << data[i];
711 inline int from_simple_string(std::string
const &s)
713 std::stringstream stream(s);
715 while ((i < data.size()) && (stream >> data[i])) {
718 if (i < data.size()) {
719 return COLVARS_ERROR;
734 inline COLVARS_HOST_DEVICE
rvector()
740 inline COLVARS_HOST_DEVICE
void reset()
752 set(v[0], v[1], v[2]);
755 inline COLVARS_HOST_DEVICE rvector(
cvm::real t)
776 return (i == 0) ? x : (i == 1) ? y : (i == 2) ? z : x;
781 return (i == 0) ? x : (i == 1) ? y : (i == 2) ? z : x;
793 inline COLVARS_HOST_DEVICE
void operator += (
cvm::rvector const &v)
800 inline COLVARS_HOST_DEVICE
void operator -= (
cvm::rvector const &v)
807 inline COLVARS_HOST_DEVICE
void operator *= (
cvm::real v)
814 inline COLVARS_HOST_DEVICE
void operator /= (
cvm::real const& v)
821 inline COLVARS_HOST_DEVICE
cvm::real norm2()
const
823 return (x*x + y*y + z*z);
826 inline COLVARS_HOST_DEVICE
cvm::real norm()
const
828#if (defined(__HIP_DEVICE_COMPILE__)) || (defined (__CUDA_ARCH__))
829#define COLVARS_MATH_SQRT ::sqrt
831#define COLVARS_MATH_SQRT cvm::sqrt
833 return COLVARS_MATH_SQRT(this->norm2());
834#undef COLVARS_MATH_SQRT
843 static inline size_t output_width(
size_t real_width)
845 return 3*real_width + 10;
849 static inline COLVARS_HOST_DEVICE
854 -v1.x*v2.z + v2.x*v1.z,
855 v1.x*v2.y - v2.x*v1.y);
866 return cvm::rvector(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z);
871 return cvm::rvector(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z);
878 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
896 std::string to_simple_string()
const;
897 int from_simple_string(std::string
const &s);
907 cvm::real xx, xy, xz, yx, yy, yz, zx, zy, zz;
916 inline COLVARS_HOST_DEVICE
933 inline COLVARS_HOST_DEVICE
void reset()
935 xx = xy = xz = yx = yy = yz = zx = zy = zz = 0.0;
942 ( xx * (yy*zz - zy*yz))
943 - (yx * (xy*zz - zy*xz))
944 + (zx * (xy*yz - yy*xz));
947 inline COLVARS_HOST_DEVICE
cvm::rmatrix transpose()
const
958 m.yx*r.x + m.yy*r.y + m.yz*r.z,
959 m.zx*r.x + m.zy*r.y + m.zz*r.z);
962 inline COLVARS_HOST_DEVICE
rmatrix& operator+=(
const rmatrix& rhs) {
988 : q0(qv[0]), q1(qv[1]), q2(qv[2]), q3(qv[3])
996 : q0(q0i), q1(q1i), q2(q2i), q3(q3i)
1000 : q0(v[0]), q1(v[1]), q2(v[2]), q3(v[3])
1012 q0 = q1 = q2 = q3 = 0.0;
1018 return 4*real_width + 13;
1021 std::string to_simple_string()
const;
1022 int from_simple_string(std::string
const &s);
1041#if !(defined(__NVCC__) || defined(__HIPCC__))
1060#if !(defined(__NVCC__) || defined(__HIPCC__))
1062 "component which is not between 0 and 3.\n");
1081 return q0*q0 + q1*q1 + q2*q2 + q3*q3;
1087#if (defined(__HIP_DEVICE_COMPILE__)) || (defined (__CUDA_ARCH__))
1088#define COLVARS_MATH_SQRT ::sqrt
1090#define COLVARS_MATH_SQRT cvm::sqrt
1092 return COLVARS_MATH_SQRT(this->
norm2());
1093#undef COLVARS_MATH_SQRT
1102 inline COLVARS_HOST_DEVICE
void operator *= (
cvm::real a)
1104 q0 *= a; q1 *= a; q2 *= a; q3 *= a;
1107 inline COLVARS_HOST_DEVICE
void operator /= (
cvm::real a)
1109 q0 /= a; q1 /= a; q2 /= a; q3 /= a;
1112 inline COLVARS_HOST_DEVICE
void set_positive()
1114 if (q0 > 0.0)
return;
1121 inline COLVARS_HOST_DEVICE
void operator += (
cvm::quaternion const &h)
1123 q0+=h.q0; q1+=h.q1; q2+=h.q2; q3+=h.q3;
1125 inline COLVARS_HOST_DEVICE
void operator -= (
cvm::quaternion const &h)
1127 q0-=h.q0; q1-=h.q1; q2-=h.q2; q3-=h.q3;
1155 h.q0*q.q1 + h.q1*q.q0 + h.q2*q.q3 - h.q3*q.q2,
1156 h.q0*q.q2 + h.q2*q.q0 + h.q3*q.q1 - h.q1*q.q3,
1157 h.q0*q.q3 + h.q3*q.q0 + h.q1*q.q2 - h.q2*q.q1);
1198 R.xx = q0*q0 + q1*q1 - q2*q2 - q3*q3;
1199 R.yy = q0*q0 - q1*q1 + q2*q2 - q3*q3;
1200 R.zz = q0*q0 - q1*q1 - q2*q2 + q3*q3;
1202 R.xy = 2.0 * (q1*q2 - q0*q3);
1203 R.xz = 2.0 * (q0*q2 + q1*q3);
1205 R.yx = 2.0 * (q0*q3 + q1*q2);
1206 R.yz = 2.0 * (q2*q3 - q0*q1);
1208 R.zx = 2.0 * (q1*q3 - q0*q2);
1209 R.zy = 2.0 * (q0*q1 + q2*q3);
1248 template <
typename T>
1251 2.0 * ( q0 * C[0][0] - q3 * C[0][1] + q2 * C[0][2] +
1252 q3 * C[1][0] + q0 * C[1][1] - q1 * C[1][2] +
1253 -q2 * C[2][0] + q1 * C[2][1] + q0 * C[2][2]),
1254 2.0 * ( q1 * C[0][0] + q2 * C[0][1] + q3 * C[0][2] +
1255 q2 * C[1][0] - q1 * C[1][1] - q0 * C[1][2] +
1256 q3 * C[2][0] + q0 * C[2][1] - q1 * C[2][2]),
1257 2.0 * (-q2 * C[0][0] + q1 * C[0][1] + q0 * C[0][2] +
1258 q1 * C[1][0] + q2 * C[1][1] + q3 * C[1][2] +
1259 -q0 * C[2][0] + q3 * C[2][1] - q2 * C[2][2]),
1260 2.0 * (-q3 * C[0][0] - q0 * C[0][1] + q1 * C[0][2] +
1261 q0 * C[1][0] - q3 * C[1][1] + q2 * C[1][2] +
1262 q1 * C[2][0] + q2 * C[2][1] + q3 * C[2][2])
1271 return 2.0*iprod*iprod - 1.0;
1279 cvm::real const cos_omega = this->q0*Q2.q0 + this->q1*Q2.q1 +
1280 this->q2*Q2.q2 + this->q3*Q2.q3;
1281#if (defined(__HIP_DEVICE_COMPILE__)) || (defined (__CUDA_ARCH__))
1282#define COLVARS_MATH_ACOS ::acos
1284#define COLVARS_MATH_ACOS cvm::acos
1286 cvm::real const omega = COLVARS_MATH_ACOS( (cos_omega > 1.0) ? 1.0 :
1287 ( (cos_omega < -1.0) ? -1.0 : cos_omega) );
1288#undef COLVARS_MATH_ACOS
1291 if (cos_omega > 0.0)
1292 return omega * omega;
1294 return (PI-omega) * (PI-omega);
1301#if (defined(__HIP_DEVICE_COMPILE__)) || (defined (__CUDA_ARCH__))
1302#define COLVARS_MATH_ACOS ::acos
1303#define COLVARS_MATH_SIN ::sin
1304#define COLVARS_MATH_FABS ::fabs
1306#define COLVARS_MATH_ACOS cvm::acos
1307#define COLVARS_MATH_SIN cvm::sin
1308#define COLVARS_MATH_FABS cvm::fabs
1310 cvm::real const cos_omega = this->q0*Q2.q0 + this->q1*Q2.q1 + this->q2*Q2.q2 + this->q3*Q2.q3;
1311 cvm::real const omega = COLVARS_MATH_ACOS( (cos_omega > 1.0) ? 1.0 :
1312 ( (cos_omega < -1.0) ? -1.0 : cos_omega) );
1313 cvm::real const sin_omega = COLVARS_MATH_SIN(omega);
1315 if (COLVARS_MATH_FABS(sin_omega) < 1.0E-14) {
1319#undef COLVARS_MATH_ACOS
1320#undef COLVARS_MATH_SIN
1321#undef COLVARS_MATH_FABS
1323 grad1((-1.0)*sin_omega*Q2.q0 + cos_omega*(this->q0-cos_omega*Q2.q0)/sin_omega,
1324 (-1.0)*sin_omega*Q2.q1 + cos_omega*(this->q1-cos_omega*Q2.q1)/sin_omega,
1325 (-1.0)*sin_omega*Q2.q2 + cos_omega*(this->q2-cos_omega*Q2.q2)/sin_omega,
1326 (-1.0)*sin_omega*Q2.q3 + cos_omega*(this->q3-cos_omega*Q2.q3)/sin_omega);
1328 if (cos_omega > 0.0) {
1329 return 2.0*omega*grad1;
1331 return -2.0*(PI-omega)*grad1;
1339 cvm::real const cos_omega = this->q0*Q2.q0 + this->q1*Q2.q1 +
1340 this->q2*Q2.q2 + this->q3*Q2.q3;
1341 if (cos_omega < 0.0) Q2 *= -1.0;
1348 cvm::real const prod = this->q0*Q2.q0 + this->q1*Q2.q1 +
1349 this->q2*Q2.q2 + this->q3*Q2.q3;
1356#ifndef COLVARS_LAMMPS
1358int diagonalize_matrix(
cvm::real m[4][4],
1410 const cvm::ag_vector_real_t &pos1,
1411 const cvm::ag_vector_real_t &pos2,
1412 const size_t num_atoms_pos1,
1413 const size_t num_atoms_pos2);
1426 std::vector<atom_pos>
const &pos2);
1427 void calc_optimal_rotation_soa(
1428 cvm::ag_vector_real_t
const &pos1,
1429 cvm::ag_vector_real_t
const &pos2,
1430 const size_t num_atoms_pos1,
1431 const size_t num_atoms_pos2);
1472 while (alpha > 180.0) alpha -= 360;
1473 while (alpha < -180.0) alpha += 360;
1487 (180.0/PI) * 2.0 * (1.0 / (1.0 + (iprod*iprod)/(
q.q0*
q.q0)));
1490 dspindx * ((1.0/
q.q0) * axis.x),
1491 dspindx * ((1.0/
q.q0) * axis.y),
1492 dspindx * ((1.0/
q.q0) * axis.z));
1497 return cvm::quaternion((180.0/PI) * 2.0 * ((-1.0)/iprod), 0.0, 0.0, 0.0);
1507 (180.0/PI) * 2.0 *
cvm::atan2(axis * q_vec,
q.q0);
1510 cvm::real const cos_theta_2 = ( (cos_spin_2 != 0.0) ?
1511 (
q.q0 / cos_spin_2) :
1514 return 2.0 * (cos_theta_2*cos_theta_2) - 1.0;
1528 (4.0 *
q.q0 / (cos_spin_2*cos_spin_2)) *
1529 (1.0 - (iprod*iprod)/(
q.q0*
q.q0) / (1.0 + (iprod*iprod)/(
q.q0*
q.q0)));
1532 (4.0 *
q.q0 / (cos_spin_2*cos_spin_2) *
1533 (iprod/
q.q0) / (1.0 + (iprod*iprod)/(
q.q0*
q.q0)));
1536 d_cos_theta_dqn * axis.x,
1537 d_cos_theta_dqn * axis.y,
1538 d_cos_theta_dqn * axis.z);
1542 (4.0 / (cos_spin_2*cos_spin_2 * iprod));
1545 d_cos_theta_dqn * axis.x,
1546 d_cos_theta_dqn * axis.y,
1547 d_cos_theta_dqn * axis.z);
1565 std::vector<cvm::atom_pos>
const &pos2);
1577#if defined (COLVARS_CUDA) || defined (COLVARS_HIP)
1578namespace colvars_gpu {
1606 int* discontinuous_rotation;
1638 const size_t num_atoms_pos1,
1639 const size_t num_atoms_pos2,
1641 std::unordered_map<std::string, cudaGraphNode_t>& nodes_map);
Definition: colvartypes.h:385
Arbitrary size array (two dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:376
matrix2d(matrix2d< T > const &m)
Copy constructor.
Definition: colvartypes.h:494
T ** c_array()
Return the 2-d C array.
Definition: colvartypes.h:543
void clear()
Deallocation routine.
Definition: colvartypes.h:463
~matrix2d()
Destructor.
Definition: colvartypes.h:504
std::vector< T > const & data_array() const
Return a reference to the data.
Definition: colvartypes.h:515
matrix2d< T > & operator=(matrix2d< T > const &m)
Assignment.
Definition: colvartypes.h:530
matrix2d()
Default constructor.
Definition: colvartypes.h:480
std::vector< T > & data_array()
Return a reference to the data.
Definition: colvartypes.h:509
void resize(size_t const ol, size_t const il)
Allocation routine, used by all constructors.
Definition: colvartypes.h:420
friend std::ostream & operator<<(std::ostream &os, matrix2d< T > const &m)
Formatted output.
Definition: colvartypes.h:670
void reset()
Set all elements to zero.
Definition: colvartypes.h:469
1-dimensional vector of real numbers with four components and a quaternion algebra
Definition: colvartypes.h:980
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:1151
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:1179
COLVARS_HOST_DEVICE cvm::real & operator[](int i)
Access the quaternion as a 4-d array (return a reference)
Definition: colvartypes.h:1030
COLVARS_HOST_DEVICE quaternion(cvm::real q0i, cvm::real q1i, cvm::real q2i, cvm::real q3i)
Constructor component by component.
Definition: colvartypes.h:992
friend std::istream & operator>>(std::istream &is, cvm::quaternion &q)
Formatted input operator.
Definition: colvartypes.cpp:125
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:1187
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:1337
COLVARS_HOST_DEVICE quaternion()
Default constructor.
Definition: colvartypes.h:1004
COLVARS_HOST_DEVICE cvm::quaternion conjugate() const
Return the conjugate quaternion.
Definition: colvartypes.h:1097
COLVARS_HOST_DEVICE cvm::real norm2() const
Square norm of the quaternion.
Definition: colvartypes.h:1079
friend std::ostream & operator<<(std::ostream &os, cvm::quaternion const &q)
Formatted output operator.
Definition: colvartypes.cpp:106
COLVARS_HOST_DEVICE cvm::real norm() const
Norm of the quaternion.
Definition: colvartypes.h:1085
COLVARS_HOST_DEVICE void reset()
Set all components to zero (null quaternion)
Definition: colvartypes.h:1010
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:1277
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:1016
COLVARS_HOST_DEVICE cvm::rvector get_vector() const
Return the vector component.
Definition: colvartypes.h:1131
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:1346
COLVARS_HOST_DEVICE cvm::quaternion dist2_grad(cvm::quaternion const &Q2) const
Definition: colvartypes.h:1299
COLVARS_HOST_DEVICE cvm::rmatrix rotation_matrix() const
Return the 3x3 matrix associated to this quaternion.
Definition: colvartypes.h:1194
COLVARS_HOST_DEVICE quaternion(cvm::real const qv[4])
Constructor component by component.
Definition: colvartypes.h:987
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:1249
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:1268
2-dimensional array of real numbers with three components along each dimension (works with colvarmodu...
Definition: colvartypes.h:903
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:917
COLVARS_HOST_DEVICE rmatrix()
Default constructor.
Definition: colvartypes.h:910
COLVARS_HOST_DEVICE cvm::real determinant() const
Return the determinant.
Definition: colvartypes.h:939
A rotation between two sets of coordinates (for the moment a wrapper for colvarmodule::quaternion)
Definition: colvartypes.h:1368
~rotation()
Destructor.
Definition: colvartypes.cpp:200
cvm::rmatrix C
Correlation matrix C (3, 3)
Definition: colvartypes.h:1371
rotation()
Default constructor.
Definition: colvartypes.cpp:162
cvm::real cos_theta(cvm::rvector const &axis) const
Return the projection of the orientation vector onto a predefined axis.
Definition: colvartypes.h:1503
cvm::real S_eigval[4]
Eigenvalues of S.
Definition: colvartypes.h:1377
cvm::real S_backup[4][4]
Used for debugging gradients.
Definition: colvartypes.h:1383
cvm::rvector rotate(cvm::rvector const &v) const
Return the rotated vector.
Definition: colvartypes.h:1449
int init()
Initialize member data.
Definition: colvartypes.cpp:153
cvm::real S[4][4]
Overlap matrix S (4, 4)
Definition: colvartypes.h:1374
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:1479
cvm::quaternion dcos_theta_dq(cvm::rvector const &axis) const
Return the derivative of the tilt wrt the quaternion.
Definition: colvartypes.h:1518
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:1468
cvm::real S_eigvec[4][4]
Eigenvectors of S.
Definition: colvartypes.h:1380
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:381
static cvm::real crossing_threshold
Threshold for the eigenvalue crossing test.
Definition: colvartypes.h:1554
cvm::quaternion q_old
Previous value of the rotation (used to warn the user when the structure changes too much,...
Definition: colvartypes.h:1561
static bool monitor_crossings
Whether to test for eigenvalue crossing.
Definition: colvartypes.h:1552
bool b_debug_gradients
Perform gradient tests.
Definition: colvartypes.h:1387
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:211
cvm::rmatrix matrix() const
Return the associated 3x3 matrix.
Definition: colvartypes.h:1461
void * jacobi
Pointer to instance of Jacobi solver.
Definition: colvartypes.h:1574
void compute_overlap_matrix()
Compute the overlap matrix S (used by calc_optimal_rotation())
Definition: colvartypes.cpp:231
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:293
void calc_optimal_rotation_impl()
Actual implementation of calc_optimal_rotation (and called by it)
Definition: colvartypes.cpp:431
cvm::rotation inverse() const
Return the inverse of this rotation.
Definition: colvartypes.h:1455
cvm::quaternion q
The rotation itself (implemented as a quaternion)
Definition: colvartypes.h:1390
vector of real numbers with three components
Definition: colvartypes.h:728
COLVARS_HOST_DEVICE void reset()
Set all components to zero.
Definition: colvartypes.h:740
COLVARS_HOST_DEVICE void set(cvm::real value)
Set all components to a scalar.
Definition: colvartypes.h:761
friend COLVARS_HOST_DEVICE cvm::real operator*(cvm::rvector const &v1, cvm::rvector const &v2)
Inner (dot) product.
Definition: colvartypes.h:875
COLVARS_HOST_DEVICE void set(cvm::real x_i, cvm::real y_i, cvm::real z_i)
Assign all components.
Definition: colvartypes.h:767
COLVARS_HOST_DEVICE cvm::real & operator[](int i)
Access cartesian components by index.
Definition: colvartypes.h:775
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:99
static int error_static(std::string const &message, int code=-1)
Definition: colvarmodule.h:770
static real cos(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:155
static real atan2(real const &x, real const &y)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:200
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:143
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2541
Definition: colvartypes.h:1580
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:549
cvm::real * d_S_eigvec
Eigenvectors of S.
Definition: colvartypes.h:1595
cvm::real * d_S_eigval
Eigenvalues of S.
Definition: colvartypes.h:1588
int * max_iteration_reached
Flag for checking if eigendecomposition is failed.
Definition: colvartypes.h:1608
cvm::quaternion * d_q
The rotation itself (implemented as a quaternion)
Definition: colvartypes.h:1603
cvm::real * d_S
Correlation matrix C (3, 3)
Definition: colvartypes.h:1586
unsigned int * tbcount
Used for debugging gradients.
Definition: colvartypes.h:1601
int init()
Initialize member data.
Definition: colvartypes.cpp:520
void after_sync_check() const
Checking after synchronization ( eigendecomposition iterations and max crossing)
Definition: colvartypes.cpp:617
cvm::rmatrix * h_C
Host data for compatibility with CPU buffers.
Definition: colvartypes.h:1612
bool b_initialized
Flag for checking if initialized.
Definition: colvartypes.h:1610
~rotation_gpu()
Destructor.
Definition: colvartypes.cpp:503
cvm::quaternion * d_q_old
Crossing monitor.
Definition: colvartypes.h:1605
rotation_gpu()
Constructor.
Definition: colvartypes.cpp:493
bool initialized() const
Check if the object is initialized.
Definition: colvartypes.h:1622
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