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

colvar::coordnum Class Reference

Colvar component: coordination number between two groups (colvarvalue::type_scalar type, range [0:N1*N2]). More...

#include <colvarcomp.h>

Inheritance diagram for colvar::coordnum:

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

Public Member Functions

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

Static Public Member Functions

template<bool b_gradients>
cvm::real switching_function (cvm::real const &r0, int const &exp_num, int const &exp_den, cvm::atom &A1, cvm::atom &A2)
 Calculate a coordination number through the function (1-x**n)/(1-x**m), x = |A1-A2|/r0.
template<bool b_gradients>
cvm::real switching_function (cvm::rvector const &r0_vec, int const &exp_num, int const &exp_den, cvm::atom &A1, cvm::atom &A2)
 Calculate a coordination number through the function (1-x**n)/(1-x**m), x = |(A1-A2)*(r0_vec)^-|1.

Protected Attributes

cvm::real r0
 "Cutoff" for isotropic calculation (default)
cvm::rvector r0_vec
 "Cutoff vector" for anisotropic calculation
bool b_anisotropic
 Wheter dist/r0 or {dist}*{1/r0_vec} should ne be used.
int en
 Integer exponent of the function numerator.
int ed
 Integer exponent of the function denominator.
bool b_group2_center_only
 If true, group2 will be treated as a single atom (default: loop over all pairs of atoms in group1 and group2).

Detailed Description

Colvar component: coordination number between two groups (colvarvalue::type_scalar type, range [0:N1*N2]).

Definition at line 648 of file colvarcomp.h.


Constructor & Destructor Documentation

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

Constructor.

Definition at line 73 of file colvarcomp_coordnums.C.

References b_anisotropic, b_group2_center_only, ed, en, colvarmodule::fatal_error(), r0, r0_vec, colvarvalue::type(), colvarmodule::rvector::x, colvarmodule::rvector::y, and colvarmodule::rvector::z.

00074   : distance (conf), b_anisotropic (false), b_group2_center_only (false)
00075 { 
00076   function_type = "coordnum";
00077   x.type (colvarvalue::type_scalar);
00078 
00079   // group1 and group2 are already initialized by distance()
00080 
00081   bool const b_scale = get_keyval (conf, "cutoff", r0,
00082                                    cvm::real (4.0 * cvm::unit_angstrom()));
00083 
00084   if (get_keyval (conf, "cutoff3", r0_vec,
00085                   cvm::rvector (4.0, 4.0, 4.0), parse_silent)) {
00086 
00087     if (b_scale)
00088       cvm::fatal_error ("Error: cannot specify \"scale\" and "
00089                         "\"scale3\" at the same time.\n");
00090     b_anisotropic = true;
00091     // remove meaningless negative signs
00092     if (r0_vec.x < 0.0) r0_vec.x *= -1.0;
00093     if (r0_vec.y < 0.0) r0_vec.y *= -1.0;
00094     if (r0_vec.z < 0.0) r0_vec.z *= -1.0;
00095   }
00096 
00097   get_keyval (conf, "expNumer", en, int (6) );
00098   get_keyval (conf, "expDenom", ed, int (12));
00099 
00100   if ( (en%2) || (ed%2) ) {
00101     cvm::fatal_error ("Error: odd exponents provided, can only use even ones.\n");
00102   }
00103 
00104   get_keyval (conf, "group2CenterOnly", b_group2_center_only, false);
00105 }

colvar::coordnum::coordnum  ) 
 

Definition at line 108 of file colvarcomp_coordnums.C.

References colvarvalue::type().

00109   : b_anisotropic (false), b_group2_center_only (false)
00110 {
00111   function_type = "coordnum";
00112   x.type (colvarvalue::type_scalar);
00113 }

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

Definition at line 670 of file colvarcomp.h.

00670 {}


Member Function Documentation

void colvar::coordnum::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::distance.

Definition at line 205 of file colvarcomp_coordnums.C.

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

00206 {
00207   if (!group1.noforce)
00208     group1.apply_colvar_force (force.real_value);
00209 
00210   if (!group2.noforce)
00211     group2.apply_colvar_force (force.real_value);
00212 }

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

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

Reimplemented from colvar::distance.

Definition at line 159 of file colvarcomp_coordnums.C.

References colvarmodule::atom_group::center_of_mass(), colvarmodule::atom::grad, colvarmodule::atom::pos, and colvarmodule::atom_group::set_weighted_gradient().

00160 {
00161   if (b_group2_center_only) {
00162 
00163     // create a fake atom to hold the group2 com coordinates
00164     cvm::atom group2_com_atom (group2[0]);
00165     group2_com_atom.pos = group2.center_of_mass();
00166 
00167     if (b_anisotropic) {
00168       for (cvm::atom_iter ai1 = group1.begin(); ai1 != group1.end(); ai1++)
00169         switching_function<true> (r0_vec, en, ed, *ai1, group2_com_atom);
00170     } else {
00171       for (cvm::atom_iter ai1 = group1.begin(); ai1 != group1.end(); ai1++)
00172         switching_function<true> (r0, en, ed, *ai1, group2_com_atom);
00173     }
00174 
00175     group2.set_weighted_gradient (group2_com_atom.grad);
00176 
00177   } else {
00178 
00179     if (b_anisotropic) {
00180       for (cvm::atom_iter ai1 = group1.begin(); ai1 != group1.end(); ai1++)
00181         for (cvm::atom_iter ai2 = group2.begin(); ai2 != group2.end(); ai2++) {
00182           switching_function<true> (r0_vec, en, ed, *ai1, *ai2);
00183         }
00184     } else {
00185       for (cvm::atom_iter ai1 = group1.begin(); ai1 != group1.end(); ai1++)
00186         for (cvm::atom_iter ai2 = group2.begin(); ai2 != group2.end(); ai2++) {
00187           switching_function<true> (r0, en, ed, *ai1, *ai2);
00188         }
00189     }
00190   }
00191 
00192   //   if (cvm::debug()) {
00193   //     for (size_t i = 0; i < group1.size(); i++) {
00194   //       cvm::log ("atom["+cvm::to_str (group1[i].id+1)+"] gradient: "+
00195   //                 cvm::to_str (group1[i].grad)+"\n");
00196   //     }
00197 
00198   //     for (size_t i = 0; i < group2.size(); i++) {
00199   //       cvm::log ("atom["+cvm::to_str (group2[i].id+1)+"] gradient: "+
00200   //                 cvm::to_str (group2[i].grad)+"\n");
00201   //     }
00202   //   }
00203 }

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

Calculate the variable.

Reimplemented from colvar::distance.

Definition at line 116 of file colvarcomp_coordnums.C.

References colvarmodule::atom_group::center_of_mass(), colvarmodule::atom::pos, colvarmodule::atom_group::read_positions(), colvarvalue::real_value, and colvarmodule::atom_group::reset_atoms_data().

00117 {
00118   x.real_value = 0.0;
00119 
00120   // these are necessary: for each atom, gradients are summed together
00121   // by multiple calls to switching_function()
00122   group1.reset_atoms_data();
00123   group2.reset_atoms_data();
00124 
00125   group1.read_positions();
00126   group2.read_positions();
00127 
00128   if (b_group2_center_only) {
00129 
00130     // create a fake atom to hold the group2 com coordinates
00131     cvm::atom group2_com_atom (group2[0]);
00132     group2_com_atom.pos = group2.center_of_mass();
00133 
00134     if (b_anisotropic) {
00135       for (cvm::atom_iter ai1 = group1.begin(); ai1 != group1.end(); ai1++)
00136         x.real_value += switching_function<false> (r0_vec, en, ed, *ai1, group2_com_atom);
00137     } else {
00138       for (cvm::atom_iter ai1 = group1.begin(); ai1 != group1.end(); ai1++)
00139         x.real_value += switching_function<false> (r0, en, ed, *ai1, group2_com_atom);
00140     }
00141 
00142   } else {
00143 
00144     if (b_anisotropic) {
00145       for (cvm::atom_iter ai1 = group1.begin(); ai1 != group1.end(); ai1++)
00146         for (cvm::atom_iter ai2 = group2.begin(); ai2 != group2.end(); ai2++) {
00147           x.real_value += switching_function<false> (r0_vec, en, ed, *ai1, *ai2);
00148         }
00149     } else {
00150       for (cvm::atom_iter ai1 = group1.begin(); ai1 != group1.end(); ai1++)
00151         for (cvm::atom_iter ai2 = group2.begin(); ai2 != group2.end(); ai2++) {
00152           x.real_value += switching_function<false> (r0, en, ed, *ai1, *ai2);
00153         }
00154     }
00155   }
00156 }

virtual cvm::real colvar::coordnum::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::distance.

virtual cvm::real colvar::coordnum::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::distance.

virtual colvarvalue colvar::coordnum::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::distance.

virtual colvarvalue colvar::coordnum::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::distance.

template<bool calculate_gradients>
cvm::real colvar::coordnum::switching_function cvm::rvector const &  r0_vec,
int const &  exp_num,
int const &  exp_den,
cvm::atom A1,
cvm::atom A2
[static]
 

Calculate a coordination number through the function (1-x**n)/(1-x**m), x = |(A1-A2)*(r0_vec)^-|1.

Parameters:
r0_vec vector of different cutoffs in the three directions
exp_num n exponent
exp_den m exponent
A1 atom
A2 atom

Definition at line 42 of file colvarcomp_coordnums.C.

References colvarmodule::atom::grad, colvarmodule::rvector::norm2(), colvarmodule::atom::pos, colvarmodule::position_distance(), colvarmodule::rvector::x, colvarmodule::rvector::y, and colvarmodule::rvector::z.

00047 {
00048   cvm::rvector const diff = cvm::position_distance (A1.pos, A2.pos);
00049   cvm::rvector const scal_diff (diff.x/r0_vec.x, diff.y/r0_vec.y, diff.z/r0_vec.z);
00050   cvm::real const l2 = scal_diff.norm2();
00051 
00052   // Assume en and ed are even integers, and avoid sqrt in the following
00053   int const en2 = en/2;
00054   int const ed2 = ed/2;
00055 
00056   cvm::real const xn = ::pow (l2, en2);
00057   cvm::real const xd = ::pow (l2, ed2);
00058   cvm::real const func = (1.0-xn)/(1.0-xd);
00059 
00060   if (calculate_gradients) {
00061     cvm::real const dFdl2 = (1.0/(1.0-xd))*(en2*(xn/l2) - func*ed2*(xd/l2))*(-1.0);
00062     cvm::rvector const dl2dx ((2.0/(r0_vec.x*r0_vec.x))*diff.x,
00063                               (2.0/(r0_vec.y*r0_vec.y))*diff.y,
00064                               (2.0/(r0_vec.z*r0_vec.z))*diff.z);
00065     A1.grad += (-1.0)*dFdl2*dl2dx;
00066     A2.grad +=        dFdl2*dl2dx;
00067   }
00068   return func;
00069 }

template<bool calculate_gradients>
cvm::real colvar::coordnum::switching_function cvm::real const &  r0,
int const &  exp_num,
int const &  exp_den,
cvm::atom A1,
cvm::atom A2
[static]
 

Calculate a coordination number through the function (1-x**n)/(1-x**m), x = |A1-A2|/r0.

Parameters:
r0 "cutoff" for the coordination number
exp_num n exponent
exp_den m exponent
A1 atom
A2 atom

Definition at line 13 of file colvarcomp_coordnums.C.

References colvarmodule::atom::grad, colvarmodule::rvector::norm2(), colvarmodule::atom::pos, and colvarmodule::position_distance().

00018 {
00019   cvm::rvector const diff = cvm::position_distance (A1.pos, A2.pos);
00020   cvm::real const l2 = diff.norm2()/(r0*r0);
00021 
00022   // Assume en and ed are even integers, and avoid sqrt in the following
00023   int const en2 = en/2;
00024   int const ed2 = ed/2;
00025 
00026   cvm::real const xn = ::pow (l2, en2);
00027   cvm::real const xd = ::pow (l2, ed2);
00028   cvm::real const func = (1.0-xn)/(1.0-xd);
00029 
00030   if (calculate_gradients) {
00031     cvm::real const dFdl2 = (1.0/(1.0-xd))*(en2*(xn/l2) - func*ed2*(xd/l2))*(-1.0);
00032     cvm::rvector const dl2dx = (2.0/(r0*r0))*diff;
00033     A1.grad += (-1.0)*dFdl2*dl2dx;
00034     A2.grad +=        dFdl2*dl2dx;
00035   }
00036 
00037   return func;
00038 }


Member Data Documentation

bool colvar::coordnum::b_anisotropic [protected]
 

Wheter dist/r0 or {dist}*{1/r0_vec} should ne be used.

Definition at line 658 of file colvarcomp.h.

Referenced by coordnum().

bool colvar::coordnum::b_group2_center_only [protected]
 

If true, group2 will be treated as a single atom (default: loop over all pairs of atoms in group1 and group2).

Definition at line 665 of file colvarcomp.h.

Referenced by coordnum().

int colvar::coordnum::ed [protected]
 

Integer exponent of the function denominator.

Definition at line 662 of file colvarcomp.h.

Referenced by coordnum().

int colvar::coordnum::en [protected]
 

Integer exponent of the function numerator.

Definition at line 660 of file colvarcomp.h.

Referenced by coordnum().

cvm::real colvar::coordnum::r0 [protected]
 

"Cutoff" for isotropic calculation (default)

Definition at line 653 of file colvarcomp.h.

Referenced by coordnum().

cvm::rvector colvar::coordnum::r0_vec [protected]
 

"Cutoff vector" for anisotropic calculation

Definition at line 655 of file colvarcomp.h.

Referenced by coordnum().


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