Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

colvarmodule::rotation Class Reference

A rotation between two sets of coordinates (for the moment a wrapper for colvarmodule::quaternion). More...

#include <colvartypes.h>

List of all members.

Public Member Functions

void request_group1_gradients (size_t const &n)
 Allocate space for the derivatives of the rotation.
void request_group2_gradients (size_t const &n)
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 arguments l0 and q0; if the gradients have been previously requested, calculate them as well.
 rotation ()
 Default constructor.
 rotation (cvm::quaternion const &qi)
 Constructor after a quaternion.
 rotation (cvm::real const &angle, cvm::rvector const &axis)
 Constructor after an axis of rotation and an angle (in radians).
 ~rotation ()
 Destructor.
cvm::rvector rotate (cvm::rvector const &v) const
 Return the rotated vector.
cvm::rotation inverse () const
 Return the inverse of this rotation.
cvm::rmatrix matrix () const
 Return the associated 3x3 matrix.
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).
cvm::quaternion dspin_angle_dq (cvm::rvector const &axis) const
 Return the derivative of the spin angle with respect to the quaternion.
cvm::real cos_theta (cvm::rvector const &axis) const
 Return the projection of the orientation vector onto a predefined axis.
cvm::quaternion dcos_theta_dq (cvm::rvector const &axis) const
 Return the derivative of the tilt wrt the quaternion.

Public Attributes

cvm::quaternion q
 The rotation itself (implemented as a quaternion).
cvm::real lambda
 Eigenvalue corresponding to the optimal rotation.
bool b_debug_gradients
 Perform gradient tests.
std::vector< cvm::atom_pospos1
 Positions to superimpose: the rotation should brings pos1 into pos2.
std::vector< cvm::atom_pospos2
 Positions to superimpose: the rotation should brings pos1 into pos2.
std::vector< cvm::matrix2d<
cvm::rvector, 4, 4 > > 
dS_1
 Derivatives of S.
std::vector< cvm::matrix2d<
cvm::rvector, 4, 4 > > 
dS_2
 Derivatives of S.
std::vector< cvm::rvectordL0_1
 Derivatives of leading eigenvalue.
std::vector< cvm::rvectordL0_2
 Derivatives of leading eigenvalue.
std::vector< cvm::vector1d<
cvm::rvector, 4 > > 
dQ0_1
 Derivatives of leading eigenvector.
std::vector< cvm::vector1d<
cvm::rvector, 4 > > 
dQ0_2
 Derivatives of leading eigenvector.

Static Public Attributes

cvm::real crossing_threshold = 1.0E-04
 Threshold for the eigenvalue crossing test.

Protected Member Functions

void build_matrix (std::vector< cvm::atom_pos > const &pos1, std::vector< cvm::atom_pos > const &pos2, cvm::matrix2d< real, 4, 4 > &S)
 Build the overlap matrix S (used by calc_optimal_rotation()).
void diagonalize_matrix (cvm::matrix2d< cvm::real, 4, 4 > &S, cvm::real S_eigval[4], cvm::matrix2d< cvm::real, 4, 4 > &S_eigvec)
 Diagonalize the overlap matrix S (used by calc_optimal_rotation()).

Protected Attributes

cvm::quaternion q_old
 Previous value of the rotation (used to warn the user when the structure changes too much, and there may be an eigenvalue crossing).


Detailed Description

A rotation between two sets of coordinates (for the moment a wrapper for colvarmodule::quaternion).

Definition at line 899 of file colvartypes.h.


Constructor & Destructor Documentation

colvarmodule::rotation::rotation  )  [inline]
 

Default constructor.

Definition at line 952 of file colvartypes.h.

00953     : b_debug_gradients (false)
00954   {}

colvarmodule::rotation::rotation cvm::quaternion const &  qi  )  [inline]
 

Constructor after a quaternion.

Definition at line 957 of file colvartypes.h.

00958     : b_debug_gradients (false)
00959   {
00960     q = qi;
00961   }

colvarmodule::rotation::rotation cvm::real const &  angle,
cvm::rvector const &  axis
[inline]
 

Constructor after an axis of rotation and an angle (in radians).

Definition at line 964 of file colvartypes.h.

References colvarmodule::rvector::unit(), colvarmodule::rvector::x, colvarmodule::rvector::y, and colvarmodule::rvector::z.

00965     : b_debug_gradients (false)
00966   {
00967     cvm::rvector const axis_n = axis.unit();
00968     cvm::real const sina = std::sin (angle/2.0);
00969     q = cvm::quaternion (std::cos (angle/2.0),
00970                          sina * axis_n.x, sina * axis_n.y, sina * axis_n.z);
00971   }

colvarmodule::rotation::~rotation  )  [inline]
 

Destructor.

Definition at line 974 of file colvartypes.h.

00975   {}


Member Function Documentation

void colvarmodule::rotation::build_matrix std::vector< cvm::atom_pos > const &  pos1,
std::vector< cvm::atom_pos > const &  pos2,
cvm::matrix2d< real, 4, 4 > &  S
[protected]
 

Build the overlap matrix S (used by calc_optimal_rotation()).

void colvarmodule::rotation::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 arguments l0 and q0; if the gradients have been previously requested, calculate them as well.

The method to derive the optimal rotation is defined in: Coutsias EA, Seok C, Dill KA. Using quaternions to calculate RMSD. J Comput Chem. 25(15):1849-57 (2004) DOI: 10.1002/jcc.20110 PubMed: 15376254

Referenced by colvar::spin_angle::calc_gradients(), colvar::tilt::calc_gradients(), colvar::spin_angle::calc_value(), colvar::tilt::calc_value(), colvar::orientation_angle::calc_value(), colvar::orientation::calc_value(), colvar::logmsd::calc_value(), colvar::rmsd::calc_value(), and colvarmodule::atom_group::read_positions().

cvm::real colvarmodule::rotation::cos_theta cvm::rvector const &  axis  )  const [inline]
 

Return the projection of the orientation vector onto a predefined axis.

Definition at line 1035 of file colvartypes.h.

References colvarmodule::quaternion::get_vector(), PI, and colvarmodule::quaternion::q0.

Referenced by colvar::tilt::calc_gradients(), and colvar::tilt::calc_value().

01036   {
01037     cvm::rvector const q_vec = q.get_vector();
01038     cvm::real const alpha = 
01039       (180.0/PI) * 2.0 * std::atan2 (axis * q_vec, q.q0);
01040 
01041     cvm::real const cos_spin_2 = std::cos (alpha * (PI/180.0) * 0.5);
01042     cvm::real const cos_theta_2 = ( (cos_spin_2 != 0.0) ? 
01043                                     (q.q0 / cos_spin_2) :
01044                                     (0.0) );
01045     // cos(2t) = 2*cos(t)^2 - 1
01046     return 2.0 * (cos_theta_2*cos_theta_2) - 1.0;
01047   }

cvm::quaternion colvarmodule::rotation::dcos_theta_dq cvm::rvector const &  axis  )  const [inline]
 

Return the derivative of the tilt wrt the quaternion.

Definition at line 1050 of file colvartypes.h.

References colvarmodule::quaternion::get_vector(), colvarmodule::quaternion::q0, colvarmodule::rvector::x, colvarmodule::rvector::y, and colvarmodule::rvector::z.

Referenced by colvar::tilt::calc_gradients().

01051   {
01052     cvm::rvector const q_vec = q.get_vector();
01053     cvm::real const iprod = axis * q_vec;
01054 
01055     cvm::real const cos_spin_2 = std::cos (std::atan2 (iprod, q.q0));
01056 
01057     if (q.q0 != 0.0)  {
01058 
01059       cvm::real const d_cos_theta_dq0 = 
01060         (4.0 * q.q0 / (cos_spin_2*cos_spin_2)) *
01061         (1.0 - (iprod*iprod)/(q.q0*q.q0) / (1.0 + (iprod*iprod)/(q.q0*q.q0)));
01062 
01063       cvm::real const d_cos_theta_dqn =
01064         (4.0 * q.q0 / (cos_spin_2*cos_spin_2) *
01065          (iprod/q.q0) / (1.0 + (iprod*iprod)/(q.q0*q.q0)));
01066 
01067       return cvm::quaternion (d_cos_theta_dq0, 
01068                               d_cos_theta_dqn * axis.x,
01069                               d_cos_theta_dqn * axis.y,
01070                               d_cos_theta_dqn * axis.z);
01071     } else {
01072 
01073       cvm::real const d_cos_theta_dqn =
01074         (4.0 / (cos_spin_2*cos_spin_2 * iprod));
01075 
01076       return cvm::quaternion (0.0,
01077                               d_cos_theta_dqn * axis.x,
01078                               d_cos_theta_dqn * axis.y,
01079                               d_cos_theta_dqn * axis.z);
01080     }
01081   }

void colvarmodule::rotation::diagonalize_matrix cvm::matrix2d< cvm::real, 4, 4 > &  S,
cvm::real  S_eigval[4],
cvm::matrix2d< cvm::real, 4, 4 > &  S_eigvec
[protected]
 

Diagonalize the overlap matrix S (used by calc_optimal_rotation()).

cvm::quaternion colvarmodule::rotation::dspin_angle_dq cvm::rvector const &  axis  )  const [inline]
 

Return the derivative of the spin angle with respect to the quaternion.

Definition at line 1009 of file colvartypes.h.

References colvarmodule::quaternion::get_vector(), PI, colvarmodule::quaternion::q0, colvarmodule::rvector::x, colvarmodule::rvector::y, and colvarmodule::rvector::z.

Referenced by colvar::spin_angle::calc_gradients().

01010   {
01011     cvm::rvector const q_vec = q.get_vector();
01012     cvm::real const iprod = axis * q_vec;
01013 
01014     if (q.q0 != 0.0) {
01015 
01016       // cvm::real const x = iprod/q.q0;
01017       
01018       cvm::real const dspindx = (180.0/PI) * 2.0 * (1.0 / (1.0 + (iprod*iprod)/(q.q0*q.q0)));
01019 
01020       return 
01021         cvm::quaternion ( dspindx * (iprod * (-1.0) / (q.q0*q.q0)), 
01022                           dspindx * ((1.0/q.q0) * axis.x),
01023                           dspindx * ((1.0/q.q0) * axis.y),
01024                           dspindx * ((1.0/q.q0) * axis.z));
01025     } else {
01026       // (1/(1+x^2)) ~ (1/x)^2
01027       return
01028         cvm::quaternion ((180.0/PI) * 2.0 * ((-1.0)/iprod), 0.0, 0.0, 0.0);
01029       // XX TODO: What if iprod == 0? XX
01030     }
01031   }

cvm::rotation colvarmodule::rotation::inverse  )  const [inline]
 

Return the inverse of this rotation.

Definition at line 984 of file colvartypes.h.

Referenced by colvarmodule::atom_group::apply_colvar_force(), colvarmodule::atom_group::apply_force(), and colvarmodule::atom_group::apply_forces().

00985   {
00986     return cvm::rotation (this->q.conjugate());
00987   }

cvm::rmatrix colvarmodule::rotation::matrix  )  const [inline]
 

Return the associated 3x3 matrix.

Definition at line 990 of file colvartypes.h.

References colvarmodule::quaternion::rotation_matrix().

00991   {
00992     return q.rotation_matrix();
00993   }

void colvarmodule::rotation::request_group1_gradients size_t const &  n  )  [inline]
 

Allocate space for the derivatives of the rotation.

Definition at line 924 of file colvartypes.h.

Referenced by colvar::eigenvector::eigenvector().

00925   {
00926     dS_1.resize  (n, cvm::matrix2d<cvm::rvector, 4, 4>());
00927     dL0_1.resize (n, cvm::rvector (0.0, 0.0, 0.0));
00928     dQ0_1.resize (n, cvm::vector1d<cvm::rvector, 4>());
00929   }

void colvarmodule::rotation::request_group2_gradients size_t const &  n  )  [inline]
 

Definition at line 931 of file colvartypes.h.

Referenced by colvar::eigenvector::eigenvector(), and colvar::orientation::orientation().

00932   {
00933     dS_2.resize  (n, cvm::matrix2d<cvm::rvector, 4, 4>());
00934     dL0_2.resize (n, cvm::rvector (0.0, 0.0, 0.0));
00935     dQ0_2.resize (n, cvm::vector1d<cvm::rvector, 4>());
00936   }

cvm::rvector colvarmodule::rotation::rotate cvm::rvector const &  v  )  const [inline]
 

Return the rotated vector.

Definition at line 978 of file colvartypes.h.

References colvarmodule::quaternion::rotate().

Referenced by colvarmodule::atom_group::apply_colvar_force(), colvarmodule::atom_group::apply_force(), colvarmodule::atom_group::apply_forces(), colvarmodule::atom_group::apply_rotation(), colvar::calc(), colvarmodule::atom_group::read_positions(), colvarmodule::atom_group::read_system_forces(), and colvarmodule::atom_group::read_velocities().

00979   {
00980     return q.rotate (v);
00981   }

cvm::real colvarmodule::rotation::spin_angle cvm::rvector const &  axis  )  const [inline]
 

Return the spin angle (in degrees) with respect to the provided axis (which MUST be normalized).

Definition at line 998 of file colvartypes.h.

References colvarmodule::quaternion::get_vector(), and colvarmodule::quaternion::q0.

Referenced by colvar::spin_angle::calc_gradients(), and colvar::spin_angle::calc_value().

00999   {
01000     cvm::rvector const q_vec = q.get_vector();
01001     cvm::real alpha = (180.0/PI) * 2.0 * std::atan2 (axis * q_vec, q.q0);
01002     while (alpha >  180.0) alpha -= 360;
01003     while (alpha < -180.0) alpha += 360;
01004     return alpha;
01005   }


Member Data Documentation

bool colvarmodule::rotation::b_debug_gradients
 

Perform gradient tests.

Definition at line 910 of file colvartypes.h.

Referenced by colvar::orientation::orientation().

cvm::real colvarmodule::rotation::crossing_threshold = 1.0E-04 [static]
 

Threshold for the eigenvalue crossing test.

Definition at line 733 of file colvarmodule.C.

std::vector< cvm::rvector > colvarmodule::rotation::dL0_1
 

Derivatives of leading eigenvalue.

Definition at line 919 of file colvartypes.h.

std::vector< cvm::rvector > colvarmodule::rotation::dL0_2
 

Derivatives of leading eigenvalue.

Definition at line 919 of file colvartypes.h.

Referenced by colvar::logmsd::calc_gradients().

std::vector< cvm::vector1d<cvm::rvector, 4> > colvarmodule::rotation::dQ0_1
 

Derivatives of leading eigenvector.

Definition at line 921 of file colvartypes.h.

Referenced by colvar::eigenvector::calc_Jacobian_derivative().

std::vector< cvm::vector1d<cvm::rvector, 4> > colvarmodule::rotation::dQ0_2
 

Derivatives of leading eigenvector.

Definition at line 921 of file colvartypes.h.

Referenced by colvar::orientation::apply_force(), colvar::spin_angle::calc_gradients(), colvar::tilt::calc_gradients(), colvar::orientation_angle::calc_gradients(), colvar::logmsd::calc_Jacobian_derivative(), and colvar::rmsd::calc_Jacobian_derivative().

std::vector< cvm::matrix2d<cvm::rvector, 4, 4> > colvarmodule::rotation::dS_1
 

Derivatives of S.

Definition at line 917 of file colvartypes.h.

std::vector< cvm::matrix2d<cvm::rvector, 4, 4> > colvarmodule::rotation::dS_2
 

Derivatives of S.

Definition at line 917 of file colvartypes.h.

cvm::real colvarmodule::rotation::lambda
 

Eigenvalue corresponding to the optimal rotation.

Definition at line 907 of file colvartypes.h.

Referenced by colvar::logmsd::calc_value(), and colvar::rmsd::calc_value().

std::vector< cvm::atom_pos > colvarmodule::rotation::pos1
 

Positions to superimpose: the rotation should brings pos1 into pos2.

Definition at line 914 of file colvartypes.h.

std::vector< cvm::atom_pos > colvarmodule::rotation::pos2
 

Positions to superimpose: the rotation should brings pos1 into pos2.

Definition at line 914 of file colvartypes.h.

cvm::quaternion colvarmodule::rotation::q
 

The rotation itself (implemented as a quaternion).

Definition at line 904 of file colvartypes.h.

Referenced by colvar::orientation_angle::calc_gradients(), colvar::rmsd::calc_gradients(), colvar::eigenvector::calc_Jacobian_derivative(), colvar::logmsd::calc_Jacobian_derivative(), colvar::rmsd::calc_Jacobian_derivative(), colvar::orientation_angle::calc_value(), and colvar::orientation::calc_value().

cvm::quaternion colvarmodule::rotation::q_old [protected]
 

Previous value of the rotation (used to warn the user when the structure changes too much, and there may be an eigenvalue crossing).

Definition at line 1091 of file colvartypes.h.


The documentation for this class was generated from the following files:
Generated on Fri May 25 04:07:20 2012 for NAMD by  doxygen 1.3.9.1