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

colvar::logmsd Class Reference

Colvar component: 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::logmsd:

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

Public Member Functions

 logmsd (std::string const &conf)
 Constructor.
virtual ~logmsd ()
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.
cvm::real MSD

Detailed Description

Colvar component: 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 934 of file colvarcomp.h.


Constructor & Destructor Documentation

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

Constructor.

Definition at line 657 of file colvarcomp_distances.C.

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

00658   : orientation (conf)
00659 {
00660   b_inverse_gradients = true;
00661   b_Jacobian_derivative = true;
00662   function_type = "logmsd";
00663   x.type (colvarvalue::type_scalar);
00664 
00665   ref_pos_sum2 = 0.0;
00666   for (size_t i = 0; i < ref_pos.size(); i++) {
00667     ref_pos_sum2 += ref_pos[i].norm2();
00668   }
00669 }

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

Definition at line 947 of file colvarcomp.h.

00947 {}


Member Function Documentation

void colvar::logmsd::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 707 of file colvarcomp_distances.C.

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

00708 {
00709   if (!atoms.noforce)
00710     atoms.apply_colvar_force (force.real_value);
00711 }

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

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

Reimplemented from colvar::cvc.

Definition at line 714 of file colvarcomp_distances.C.

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

00715 {
00716   atoms.read_system_forces();
00717   ft.real_value = 0.0;
00718     
00719   // Note: gradient square norm is 4.0 / (N_atoms * E)
00720           
00721   for (size_t ia = 0; ia < atoms.size(); ia++) {
00722     ft.real_value += atoms[ia].grad * atoms[ia].system_force;
00723   }
00724   ft.real_value *= atoms.size() * MSD / 4.0;
00725 }

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

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

Reimplemented from colvar::orientation.

Definition at line 697 of file colvarcomp_distances.C.

References colvarmodule::rotation::dL0_2, MSD, and colvarmodule::real.

00698 {
00699   cvm::real fact = (MSD > 0.0) ? 2.0/(cvm::real (atoms.size()) * MSD) : 0.0;
00700 
00701   for (size_t ia = 0; ia < atoms.size(); ia++) {
00702     atoms[ia].grad = fact * (atoms[ia].pos - atoms_cog - rot.dL0_2[ia]);
00703   }
00704 }

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

Calculate the divergence of the inverse atomic gradients.

Reimplemented from colvar::cvc.

Definition at line 728 of file colvarcomp_distances.C.

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

00729 {
00730   // divergence of the back-rotated target coordinates
00731   cvm::real divergence = 0.0;
00732  
00733   // gradient of the rotation matrix
00734   cvm::matrix2d <cvm::rvector, 3, 3> grad_rot_mat;
00735 
00736   // gradients of products of 2 quaternion components 
00737   cvm::rvector g11, g22, g33, g01, g02, g03, g12, g13, g23;
00738  
00739   for (size_t ia = 0; ia < atoms.size(); ia++) {
00740 
00741     // Gradient of optimal quaternion wrt current Cartesian position
00742     cvm::vector1d< cvm::rvector, 4 >      &dq = rot.dQ0_2[ia];
00743 
00744     g11 = 2.0 * (rot.q)[1]*dq[1];
00745     g22 = 2.0 * (rot.q)[2]*dq[2];
00746     g33 = 2.0 * (rot.q)[3]*dq[3];
00747     g01 = (rot.q)[0]*dq[1] + (rot.q)[1]*dq[0];
00748     g02 = (rot.q)[0]*dq[2] + (rot.q)[2]*dq[0];
00749     g03 = (rot.q)[0]*dq[3] + (rot.q)[3]*dq[0];
00750     g12 = (rot.q)[1]*dq[2] + (rot.q)[2]*dq[1];
00751     g13 = (rot.q)[1]*dq[3] + (rot.q)[3]*dq[1];
00752     g23 = (rot.q)[2]*dq[3] + (rot.q)[3]*dq[2];
00753 
00754     // Gradient of the rotation matrix wrt current Cartesian position
00755     // Note: we are only going to use "diagonal" terms: grad_rot_mat[i][j][i]
00756     grad_rot_mat[0][0] = -2.0 * (g22 + g33); 
00757     grad_rot_mat[1][0] =  2.0 * (g12 + g03); 
00758     grad_rot_mat[2][0] =  2.0 * (g13 - g02); 
00759     grad_rot_mat[0][1] =  2.0 * (g12 - g03); 
00760     grad_rot_mat[1][1] = -2.0 * (g11 + g33); 
00761     grad_rot_mat[2][1] =  2.0 * (g01 + g23); 
00762     grad_rot_mat[0][2] =  2.0 * (g02 + g13); 
00763     grad_rot_mat[1][2] =  2.0 * (g23 - g01); 
00764     grad_rot_mat[2][2] = -2.0 * (g11 + g22); 
00765 
00766     cvm::atom_pos &y = ref_pos[ia]; 
00767 
00768     for (size_t i = 0; i < 3; i++) {
00769       for (size_t j = 0; j < 3; j++) {
00770         divergence += grad_rot_mat[i][j][i] * y[j];
00771       }
00772     }
00773   }
00774 
00775   jd.real_value = (3.0 * atoms.size() - 3.0 - divergence) / 2.0;
00776 }

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

Calculate the variable.

Reimplemented from colvar::orientation.

Definition at line 672 of file colvarcomp_distances.C.

References colvarmodule::rotation::calc_optimal_rotation(), colvarmodule::atom_group::center_of_geometry(), colvarmodule::atom_group::center_of_mass(), colvarmodule::debug(), colvarmodule::rotation::lambda, colvarmodule::log(), MSD, 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().

00673 {
00674   atoms.reset_atoms_data();
00675   atoms.read_positions();
00676 
00677   if (cvm::debug())
00678     cvm::log ("colvar::logmsd: current com: "+
00679               cvm::to_str (atoms.center_of_mass())+"\n");
00680 
00681   atoms_cog = atoms.center_of_geometry();
00682   rot.calc_optimal_rotation (ref_pos, atoms.positions_shifted (-1.0 * atoms_cog));
00683 
00684   cvm::real group_pos_sum2 = 0.0;
00685   for (size_t i = 0; i < atoms.size(); i++) {
00686     group_pos_sum2 += (atoms[i].pos-atoms_cog).norm2();
00687   }
00688 
00689   // value of the MSD (Coutsias et al)
00690   MSD = 1.0/(cvm::real (atoms.size())) *
00691     ( group_pos_sum2 + ref_pos_sum2 - 2.0 * rot.lambda );
00692 
00693   x.real_value = (MSD > 0.0) ? ::log(MSD) : 0.0;
00694 }

virtual cvm::real colvar::logmsd::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::logmsd::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::logmsd::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::logmsd::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::logmsd::MSD [protected]
 

Definition at line 941 of file colvarcomp.h.

Referenced by calc_force_invgrads(), calc_gradients(), and calc_value().

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

Sum of the squares of ref_coords.

Definition at line 940 of file colvarcomp.h.

Referenced by calc_value(), and logmsd().


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