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

colvar::rmsd Class Reference

Colvar component: root mean square deviation (RMSD) of a group with respect to a set of reference coordinates; uses to calculate the rotation matrix (colvarvalue::type_scalar type, range [0:*)). More...

#include <colvarcomp.h>

Inheritance diagram for colvar::rmsd:

colvar::orientation colvar::cvc colvarparse List of all members.

Public Member Functions

 rmsd (std::string const &conf)
 Constructor.
virtual ~rmsd ()
virtual void calc_value ()
 Calculate the variable.
virtual void calc_gradients ()
 Calculate the atomic gradients, to be reused later in order to apply forces.
virtual void calc_force_invgrads ()
 Calculate the total force from the system using the inverse atomic gradients.
virtual void calc_Jacobian_derivative ()
 Calculate the divergence of the inverse atomic gradients.
virtual void apply_force (colvarvalue const &force)
 Apply the collective variable force, by communicating the atomic forces to the simulation program (Note: the member is not altered by this function).
virtual cvm::real dist2 (colvarvalue const &x1, colvarvalue const &x2) const
 Square distance between x1 and x2 (can be redefined to transparently implement constraints, symmetries and periodicities).
virtual colvarvalue dist2_lgrad (colvarvalue const &x1, colvarvalue const &x2) const
 Gradient (with respect to x1) of the square distance (can be redefined to transparently implement constraints, symmetries and periodicities).
virtual colvarvalue dist2_rgrad (colvarvalue const &x1, colvarvalue const &x2) const
 Gradient (with respect to x2) of the square distance (can be redefined to transparently implement constraints, symmetries and periodicities).
virtual cvm::real compare (colvarvalue const &x1, colvarvalue const &x2) const
 Return a positive number if x2>x1, zero if x2==x1, negative otherwise (can be redefined to transparently implement constraints, symmetries and periodicities) Note: it only works with scalar variables, otherwise raises an error.

Protected Attributes

cvm::real ref_pos_sum2
 Sum of the squares of ref_coords.

Detailed Description

Colvar component: root mean square deviation (RMSD) of a group with respect to a set of reference coordinates; uses to calculate the rotation matrix (colvarvalue::type_scalar type, range [0:*)).

Definition at line 901 of file colvarcomp.h.


Constructor & Destructor Documentation

colvar::rmsd::rmsd std::string const &  conf  ) 
 

Constructor.

Definition at line 534 of file colvarcomp_distances.C.

References colvarvalue::norm2(), ref_pos_sum2, and colvarvalue::type().

00535   : orientation (conf)
00536 {
00537   // TODO: refuse to start if hideJacobian is on
00538 
00539   b_inverse_gradients = true;
00540   b_Jacobian_derivative = true;
00541   function_type = "rmsd";
00542   x.type (colvarvalue::type_scalar);
00543 
00544   ref_pos_sum2 = 0.0;
00545   for (size_t i = 0; i < ref_pos.size(); i++) {
00546     ref_pos_sum2 += ref_pos[i].norm2();
00547   }
00548 }

virtual colvar::rmsd::~rmsd  )  [inline, virtual]
 

Definition at line 913 of file colvarcomp.h.

00913 {}


Member Function Documentation

void colvar::rmsd::apply_force colvarvalue const &  force  )  [virtual]
 

Apply the collective variable force, by communicating the atomic forces to the simulation program (Note: the member is not altered by this function).

Note: multiple calls to this function within the same simulation step will add the forces altogether

Parameters:
cvforce The collective variable force, usually coming from the biases and eventually manipulated by the parent object

Reimplemented from colvar::orientation.

Definition at line 585 of file colvarcomp_distances.C.

References colvarmodule::atom_group::apply_colvar_force(), colvarmodule::atom_group::noforce, and colvarvalue::real_value.

00586 {
00587   if (!atoms.noforce)
00588     atoms.apply_colvar_force (force.real_value);
00589 }

void colvar::rmsd::calc_force_invgrads  )  [virtual]
 

Calculate the total force from the system using the inverse atomic gradients.

Reimplemented from colvar::cvc.

Definition at line 592 of file colvarcomp_distances.C.

References colvarmodule::atom_group::read_system_forces(), colvarvalue::real_value, and colvarmodule::atom_group::system_force().

00593 {
00594   atoms.read_system_forces();
00595   ft.real_value = 0.0;
00596     
00597   // Note: gradient square norm is 1/N_atoms
00598           
00599   for (size_t ia = 0; ia < atoms.size(); ia++) {
00600     ft.real_value += atoms[ia].grad * atoms[ia].system_force;
00601   }
00602   ft.real_value *= atoms.size();
00603 }

void colvar::rmsd::calc_gradients  )  [virtual]
 

Calculate the atomic gradients, to be reused later in order to apply forces.

Reimplemented from colvar::orientation.

Definition at line 572 of file colvarcomp_distances.C.

References colvarmodule::rotation::q, colvarmodule::real, colvarvalue::real_value, and colvarmodule::quaternion::rotate().

00573 {
00574   cvm::real const drmsddx2 = (x.real_value > 0.0) ?
00575     0.5 / (x.real_value * cvm::real (atoms.size())) :
00576     0.0;
00577 
00578   for (size_t ia = 0; ia < atoms.size(); ia++) {
00579     atoms[ia].grad  = (drmsddx2 * 2.0 * (atoms[ia].pos - atoms_cog -
00580                                          rot.q.rotate (ref_pos[ia])));
00581   }
00582 }

void colvar::rmsd::calc_Jacobian_derivative  )  [virtual]
 

Calculate the divergence of the inverse atomic gradients.

Reimplemented from colvar::cvc.

Definition at line 606 of file colvarcomp_distances.C.

References colvarmodule::atom_pos, colvarmodule::rotation::dQ0_2, j, colvarmodule::rotation::q, and colvarvalue::real_value.

00607 {
00608   // divergence of the back-rotated target coordinates
00609   cvm::real divergence = 0.0;
00610  
00611   // gradient of the rotation matrix
00612   cvm::matrix2d <cvm::rvector, 3, 3> grad_rot_mat;
00613 
00614   // gradients of products of 2 quaternion components 
00615   cvm::rvector g11, g22, g33, g01, g02, g03, g12, g13, g23;
00616 
00617   for (size_t ia = 0; ia < atoms.size(); ia++) {
00618 
00619     // Gradient of optimal quaternion wrt current Cartesian position
00620     cvm::vector1d< cvm::rvector, 4 >      &dq = rot.dQ0_2[ia];
00621 
00622     g11 = 2.0 * (rot.q)[1]*dq[1];
00623     g22 = 2.0 * (rot.q)[2]*dq[2];
00624     g33 = 2.0 * (rot.q)[3]*dq[3];
00625     g01 = (rot.q)[0]*dq[1] + (rot.q)[1]*dq[0];
00626     g02 = (rot.q)[0]*dq[2] + (rot.q)[2]*dq[0];
00627     g03 = (rot.q)[0]*dq[3] + (rot.q)[3]*dq[0];
00628     g12 = (rot.q)[1]*dq[2] + (rot.q)[2]*dq[1];
00629     g13 = (rot.q)[1]*dq[3] + (rot.q)[3]*dq[1];
00630     g23 = (rot.q)[2]*dq[3] + (rot.q)[3]*dq[2];
00631 
00632     // Gradient of the rotation matrix wrt current Cartesian position
00633     grad_rot_mat[0][0] = -2.0 * (g22 + g33); 
00634     grad_rot_mat[1][0] =  2.0 * (g12 + g03); 
00635     grad_rot_mat[2][0] =  2.0 * (g13 - g02); 
00636     grad_rot_mat[0][1] =  2.0 * (g12 - g03); 
00637     grad_rot_mat[1][1] = -2.0 * (g11 + g33); 
00638     grad_rot_mat[2][1] =  2.0 * (g01 + g23); 
00639     grad_rot_mat[0][2] =  2.0 * (g02 + g13); 
00640     grad_rot_mat[1][2] =  2.0 * (g23 - g01); 
00641     grad_rot_mat[2][2] = -2.0 * (g11 + g22); 
00642 
00643     cvm::atom_pos &y = ref_pos[ia]; 
00644 
00645     for (size_t i = 0; i < 3; i++) {
00646       for (size_t j = 0; j < 3; j++) {
00647         divergence += grad_rot_mat[i][j][i] * y[j];
00648       }
00649     }
00650   }
00651 
00652   jd.real_value = x.real_value > 0.0 ? (3.0 * atoms.size() - 4.0 - divergence) / x.real_value : 0.0;
00653 }

void colvar::rmsd::calc_value  )  [virtual]
 

Calculate the variable.

Reimplemented from colvar::orientation.

Definition at line 551 of file colvarcomp_distances.C.

References colvarmodule::rotation::calc_optimal_rotation(), colvarmodule::atom_group::center_of_geometry(), colvarmodule::rotation::lambda, colvarmodule::atom_group::positions_shifted(), colvarmodule::atom_group::read_positions(), colvarmodule::real, colvarvalue::real_value, ref_pos_sum2, and colvarmodule::atom_group::reset_atoms_data().

00552 {
00553   atoms.reset_atoms_data();
00554   atoms.read_positions();
00555 
00556   atoms_cog = atoms.center_of_geometry();
00557   rot.calc_optimal_rotation (ref_pos, atoms.positions_shifted (-1.0 * atoms_cog));
00558 
00559   cvm::real group_pos_sum2 = 0.0;
00560   for (size_t i = 0; i < atoms.size(); i++) {
00561     group_pos_sum2 += (atoms[i].pos - atoms_cog).norm2();
00562   }
00563 
00564   // value of the RMSD (Coutsias et al)
00565   cvm::real const MSD = 1.0/(cvm::real (atoms.size())) *
00566     ( group_pos_sum2 + ref_pos_sum2 - 2.0 * rot.lambda );
00567 
00568   x.real_value = (MSD > 0.0) ? ::sqrt (MSD) : 0.0;
00569 }

virtual cvm::real colvar::rmsd::compare colvarvalue const &  x1,
colvarvalue const &  x2
const [virtual]
 

Return a positive number if x2>x1, zero if x2==x1, negative otherwise (can be redefined to transparently implement constraints, symmetries and periodicities) Note: it only works with scalar variables, otherwise raises an error.

Reimplemented from colvar::orientation.

virtual cvm::real colvar::rmsd::dist2 colvarvalue const &  x1,
colvarvalue const &  x2
const [virtual]
 

Square distance between x1 and x2 (can be redefined to transparently implement constraints, symmetries and periodicities).

colvar::cvc::dist2() and the related functions are declared as "const" functions, but not "static", because additional parameters defining the metrics (e.g. the periodicity) may be specific to each colvar::cvc object.

If symmetries or periodicities are present, the colvar::cvc::dist2() should be redefined to return the "closest distance" value and colvar::cvc::dist2_lgrad(), colvar::cvc::dist2_rgrad() to return its gradients.

If constraints are present (and not already implemented by any of the types), the colvar::cvc::dist2_lgrad() and colvar::cvc::dist2_rgrad() functions should be redefined to provide a gradient which is compatible with the constraint, i.e. already deprived of its component normal to the constraint hypersurface.

Finally, another useful application, if you are performing very many operations with these functions, could be to override the member functions and access directly its member data. For instance: to define dist2(x1,x2) as (x2.real_value-x1.real_value)*(x2.real_value-x1.real_value) in case of a scalar type.

Reimplemented from colvar::orientation.

virtual colvarvalue colvar::rmsd::dist2_lgrad colvarvalue const &  x1,
colvarvalue const &  x2
const [virtual]
 

Gradient (with respect to x1) of the square distance (can be redefined to transparently implement constraints, symmetries and periodicities).

Reimplemented from colvar::orientation.

virtual colvarvalue colvar::rmsd::dist2_rgrad colvarvalue const &  x1,
colvarvalue const &  x2
const [virtual]
 

Gradient (with respect to x2) of the square distance (can be redefined to transparently implement constraints, symmetries and periodicities).

Reimplemented from colvar::orientation.


Member Data Documentation

cvm::real colvar::rmsd::ref_pos_sum2 [protected]
 

Sum of the squares of ref_coords.

Definition at line 907 of file colvarcomp.h.

Referenced by calc_value(), and rmsd().


The documentation for this class was generated from the following files:
Generated on Mon Nov 23 04:59:32 2009 for NAMD by  doxygen 1.3.9.1