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

colvar::distance_dir Class Reference

Colvar component: distance unit vector (direction) between centers of mass of two groups (colvarvalue::type_unitvector type, range [-1:1]x[-1:1]x[-1:1]). More...

#include <colvarcomp.h>

Inheritance diagram for colvar::distance_dir:

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

Public Member Functions

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

Detailed Description

Colvar component: distance unit vector (direction) between centers of mass of two groups (colvarvalue::type_unitvector type, range [-1:1]x[-1:1]x[-1:1]).

Definition at line 378 of file colvarcomp.h.


Constructor & Destructor Documentation

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

Definition at line 474 of file colvarcomp_distances.C.

References colvarvalue::type().

00475   : distance (conf)
00476 {
00477   function_type = "distance_dir";
00478   x.type (colvarvalue::type_unitvector);
00479 }

colvar::distance_dir::distance_dir  ) 
 

Definition at line 482 of file colvarcomp_distances.C.

References colvarvalue::type().

00483   : distance()
00484 {
00485   function_type = "distance_dir";
00486   x.type (colvarvalue::type_unitvector);
00487 }

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

Definition at line 384 of file colvarcomp.h.

00384 {}


Member Function Documentation

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

References colvarmodule::atom_group::apply_force(), colvarmodule::atom_group::noforce, and colvarvalue::rvector_value.

00517 {
00518   // remove the radial force component
00519   cvm::real const iprod = force.rvector_value * x.rvector_value;
00520   cvm::rvector const force_tang = force.rvector_value - iprod * x.rvector_value;
00521 
00522   if (!group1.noforce)
00523     group1.apply_force (-1.0 * force_tang);
00524 
00525   if (!group2.noforce)
00526     group2.apply_force (       force_tang);
00527 }

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

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

Reimplemented from colvar::distance.

Definition at line 508 of file colvarcomp_distances.C.

00509 {
00510   // gradients are computed on the fly within apply_force()
00511   // Note: could be a problem if a future bias relies on gradient
00512   // calculations...
00513 }

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

Calculate the variable.

Reimplemented from colvar::distance.

Definition at line 490 of file colvarcomp_distances.C.

References colvarmodule::atom_group::center_of_mass(), colvarmodule::position_distance(), colvarmodule::atom_group::read_positions(), colvarmodule::atom_group::reset_atoms_data(), colvarvalue::rvector_value, and colvarmodule::rvector::unit().

00491 {
00492   group1.reset_atoms_data();
00493   group2.reset_atoms_data();
00494 
00495   group1.read_positions();
00496   group2.read_positions();
00497 
00498   if (b_no_PBC) {
00499     dist_v = group2.center_of_mass() - group1.center_of_mass();
00500   } else {
00501     dist_v = cvm::position_distance (group1.center_of_mass(),
00502                                      group2.center_of_mass());
00503   }
00504   x.rvector_value = dist_v.unit();
00505 }

cvm::real colvar::distance_dir::compare colvarvalue const &  x1,
colvarvalue const &  x2
const [inline, 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.

Definition at line 1339 of file colvarcomp.h.

References colvarmodule::fatal_error().

01341 {
01342   cvm::fatal_error ("Error: cannot compare() two distance directions.\n");
01343   return 0.0;
01344 }

cvm::real colvar::distance_dir::dist2 colvarvalue const &  x1,
colvarvalue const &  x2
const [inline, 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.

Definition at line 1321 of file colvarcomp.h.

References colvarvalue::norm2(), and colvarvalue::rvector_value.

01323 {
01324   return (x1.rvector_value - x2.rvector_value).norm2();
01325 }

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

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

Reimplemented from colvar::distance.

Definition at line 1327 of file colvarcomp.h.

References colvarvalue::rvector_value.

01329 {
01330   return colvarvalue ((x1.rvector_value - x2.rvector_value), colvarvalue::type_unitvector);
01331 }

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

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

Reimplemented from colvar::distance.

Definition at line 1333 of file colvarcomp.h.

References colvarvalue::rvector_value.

01335 {
01336   return colvarvalue ((x2.rvector_value - x1.rvector_value), colvarvalue::type_unitvector);
01337 }


The documentation for this class was generated from the following files:
Generated on Sun Feb 12 04:08:00 2012 for NAMD by  doxygen 1.3.9.1