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

colvar::distance_z Class Reference

Colvar component: projection of the distance vector along an axis (colvarvalue::type_scalar type, range (-*:*)). More...

#include <colvarcomp.h>

Inheritance diagram for colvar::distance_z:

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

Public Member Functions

 distance_z (std::string const &conf)
 distance_z ()
virtual ~distance_z ()
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::atom_group main
 Main atom group.
cvm::atom_group ref1
 Reference atom group.
cvm::atom_group ref2
 Optional, second ref atom group.
bool b_1site_force
cvm::rvector axis
 Vector on which the distance vector is projected.
cvm::real axis_norm
 Norm of the axis.
cvm::rvector dist_v
 Vector distance, cached to be recycled.
bool fixed_axis
 Flag: using a fixed axis vector?

Detailed Description

Colvar component: projection of the distance vector along an axis (colvarvalue::type_scalar type, range (-*:*)).

Definition at line 385 of file colvarcomp.h.


Constructor & Destructor Documentation

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

Definition at line 131 of file colvarcomp_distances.C.

References axis, b_1site_force, colvarmodule::fatal_error(), fixed_axis, colvarparse::key_lookup(), colvarmodule::log(), colvarmodule::rvector::norm2(), colvar::cvc::parse_group(), ref1, ref2, colvarvalue::type(), and colvarmodule::rvector::unit().

00132   : cvc (conf)
00133 {
00134   function_type = "distance_z";
00135   b_inverse_gradients = true;
00136   b_Jacobian_derivative = true;
00137   x.type (colvarvalue::type_scalar);
00138 
00139   parse_group (conf, "main", main);
00140   parse_group (conf, "ref", ref1);
00141   // this group is optional
00142   parse_group (conf, "ref2", ref2, true);
00143  
00144   if (ref2.size()) {
00145     cvm::log ("Using axis joining the centers of mass of groups \"ref\" and \"ref2\"");
00146     fixed_axis = false;
00147     if (key_lookup (conf, "axis"))
00148       cvm::log ("Warning: explicit axis definition will be ignored!");
00149   } else {
00150     if (get_keyval (conf, "axis", axis, cvm::rvector (0.0, 0.0, 1.0))) {
00151       if (axis.norm2() == 0.0)
00152         cvm::fatal_error ("Axis vector is zero!");
00153       axis = axis.unit();
00154     }
00155     fixed_axis = true;
00156   }
00157 
00158   if (get_keyval (conf, "oneSiteSystemForce", b_1site_force, false)) {
00159     cvm::log ("Computing system force on group \"main\" only");
00160   }
00161 }

colvar::distance_z::distance_z  ) 
 

Definition at line 163 of file colvarcomp_distances.C.

References colvarvalue::type().

00164 {
00165   function_type = "distance_z";
00166   b_inverse_gradients = true;
00167   b_Jacobian_derivative = true;
00168   x.type (colvarvalue::type_scalar);
00169 }

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

Definition at line 409 of file colvarcomp.h.

00409 {}


Member Function Documentation

void colvar::distance_z::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

Implements colvar::cvc.

Reimplemented in colvar::distance_xy.

Definition at line 226 of file colvarcomp_distances.C.

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

00227 {
00228   if (!ref1.noforce)
00229     ref1.apply_colvar_force (force.real_value);
00230 
00231   if (ref2.size() && !ref2.noforce)
00232     ref2.apply_colvar_force (force.real_value);
00233 
00234   if (!main.noforce)
00235     main.apply_colvar_force (force.real_value);
00236 }

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

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

Reimplemented from colvar::cvc.

Reimplemented in colvar::distance_xy.

Definition at line 209 of file colvarcomp_distances.C.

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

00210 {
00211   main.read_system_forces();
00212 
00213   if (fixed_axis && !b_1site_force) {
00214     ref1.read_system_forces();
00215     ft.real_value = 0.5 * ((main.system_force() - ref1.system_force()) * axis);
00216   } else {
00217     ft.real_value = main.system_force() * axis;
00218   }
00219 }

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

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

Implements colvar::cvc.

Reimplemented in colvar::distance_xy.

Definition at line 195 of file colvarcomp_distances.C.

References axis, axis_norm, colvarmodule::atom_group::center_of_mass(), colvarvalue::real_value, ref1, ref2, and colvarmodule::atom_group::set_weighted_gradient().

00196 {
00197   if (fixed_axis) {
00198     ref1.set_weighted_gradient (-1.0 * axis);
00199     main.set_weighted_gradient (       axis);
00200   } else {
00201     ref1.set_weighted_gradient ( 1.0 / axis_norm * (
00202       cvm::position_distance (ref2.center_of_mass(), main.center_of_mass()) - x.real_value * axis ));
00203     ref2.set_weighted_gradient ( 1.0 / axis_norm * (
00204       cvm::position_distance (main.center_of_mass(), ref1.center_of_mass()) + x.real_value * axis ));
00205     main.set_weighted_gradient ( axis );
00206   }
00207 }

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

Calculate the divergence of the inverse atomic gradients.

Reimplemented from colvar::cvc.

Reimplemented in colvar::distance_xy.

Definition at line 221 of file colvarcomp_distances.C.

References colvarvalue::real_value.

00222 {
00223   jd.real_value = 0.0;
00224 }

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

Calculate the variable.

Implements colvar::cvc.

Reimplemented in colvar::distance_xy.

Definition at line 171 of file colvarcomp_distances.C.

References axis, axis_norm, colvarmodule::atom_group::center_of_mass(), dist_v, colvarmodule::rvector::norm(), colvarmodule::position_distance(), colvarmodule::atom_group::read_positions(), colvarvalue::real_value, ref1, ref2, colvarmodule::atom_group::reset_atoms_data(), and colvarmodule::rvector::unit().

00172 {
00173   main.reset_atoms_data();
00174   ref1.reset_atoms_data();
00175 
00176   main.read_positions();
00177   ref1.read_positions();
00178 
00179   if (fixed_axis) {
00180     dist_v = cvm::position_distance (ref1.center_of_mass(),
00181                                      main.center_of_mass());
00182   } else {
00183     ref2.reset_atoms_data();
00184     ref2.read_positions();
00185 
00186     dist_v = cvm::position_distance (0.5 * (ref1.center_of_mass() + ref2.center_of_mass()),
00187                                      main.center_of_mass());
00188     axis = cvm::position_distance (ref1.center_of_mass(), ref2.center_of_mass());
00189     axis_norm = axis.norm();
00190     axis = axis.unit();
00191   }
00192   x.real_value = axis * dist_v;
00193 }

virtual cvm::real colvar::distance_z::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::cvc.

Reimplemented in colvar::distance_xy.

virtual cvm::real colvar::distance_z::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::cvc.

Reimplemented in colvar::distance_xy.

virtual colvarvalue colvar::distance_z::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::cvc.

Reimplemented in colvar::distance_xy.

virtual colvarvalue colvar::distance_z::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::cvc.

Reimplemented in colvar::distance_xy.


Member Data Documentation

cvm::rvector colvar::distance_z::axis [protected]
 

Vector on which the distance vector is projected.

Definition at line 399 of file colvarcomp.h.

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

cvm::real colvar::distance_z::axis_norm [protected]
 

Norm of the axis.

Definition at line 401 of file colvarcomp.h.

Referenced by calc_gradients(), and calc_value().

bool colvar::distance_z::b_1site_force [protected]
 

Compute system force on one site only to avoid unwanted coupling to other colvars (see e.g. Ciccotti et al., 2005)

Definition at line 397 of file colvarcomp.h.

Referenced by distance_z().

cvm::rvector colvar::distance_z::dist_v [protected]
 

Vector distance, cached to be recycled.

Definition at line 403 of file colvarcomp.h.

Referenced by calc_value().

bool colvar::distance_z::fixed_axis [protected]
 

Flag: using a fixed axis vector?

Definition at line 405 of file colvarcomp.h.

Referenced by calc_force_invgrads(), and distance_z().

cvm::atom_group colvar::distance_z::main [protected]
 

Main atom group.

Definition at line 390 of file colvarcomp.h.

cvm::atom_group colvar::distance_z::ref1 [protected]
 

Reference atom group.

Definition at line 392 of file colvarcomp.h.

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

cvm::atom_group colvar::distance_z::ref2 [protected]
 

Optional, second ref atom group.

Definition at line 394 of file colvarcomp.h.

Referenced by apply_force(), calc_gradients(), calc_value(), and distance_z().


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