#include <colvarcomp.h>
Inheritance diagram for colvar::cvc:

Public Member Functions | |
| colvarvalue::Type | type () const |
| Type of that this cvc provides. | |
| cvc (std::string const &conf) | |
| Constructor. | |
| void | parse_group (std::string const &conf, char const *group_key, cvm::atom_group &group, bool optional=false) |
| Within the constructor, make a group parse its own options from the provided configuration string. | |
| cvc () | |
| Default constructor (used when objects are declared within other ones). | |
| virtual | ~cvc () |
| Destructor. | |
| virtual void | calc_value ()=0 |
| Calculate the variable. | |
| virtual void | calc_gradients ()=0 |
| Calculate the atomic gradients, to be reused later in order to apply forces. | |
| virtual void | debug_gradients (cvm::atom_group &group) |
| Calculate finite-difference gradients alongside the analytical ones, for each Cartesian component. | |
| 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 colvarvalue | value () const |
| Return the previously calculated value. | |
| virtual colvarvalue | system_force () const |
| Return the previously calculated system force. | |
| virtual colvarvalue | Jacobian_derivative () const |
| Return the previously calculated divergence of the inverse atomic gradients. | |
| virtual void | apply_force (colvarvalue const &cvforce)=0 |
| 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. | |
| virtual void | wrap (colvarvalue &x) const |
| Wrapp value (for periodic/symmetric cvcs). | |
Public Attributes | |
| std::string | name |
| The name of the object (helps to identify this cvc instance when debugging). | |
| std::string | function_type |
| Description of the type of collective variable. | |
| cvm::real | sup_coeff |
| Coefficient in the polynomial combination (default: 1.0). | |
| int | sup_np |
| Exponent in the polynomial combination (default: 1). | |
| cvm::real | period |
| Period of this cvc value, (default: 0.0, non periodic). | |
| cvm::real | wrap_center |
| If the component is periodic, wrap around this value (default: 0.0). | |
| bool | b_periodic |
| bool | b_inverse_gradients |
| If this flag is false (default), inverse gradients (derivatives of atom coordinates with respect to x) are unavailable; it should be set to true by the constructor of each derived object capable of calculating them. | |
| bool | b_Jacobian_derivative |
| If this flag is false (default), the Jacobian derivative (divergence of the inverse gradients) is unavailable; it should be set to true by the constructor of each derived object capable of calculating it. | |
| bool | b_debug_gradients |
| If true, calc_gradients() will call debug_gradients() for every group needed. | |
| std::vector< cvm::atom_group * > | atom_groups |
| Pointers to all atom groups, to let colvars collect info e.g. atomic gradients. | |
Protected Attributes | |
| colvarvalue | x |
| Cached value. | |
| colvarvalue | x_old |
| Value at the previous step. | |
| colvarvalue | ft |
| Calculated system force (Note: this is calculated from the total atomic forces read from the program, subtracting fromt the "internal" forces of the system the "external" forces from the colvar biases). | |
| colvarvalue | jd |
| Calculated Jacobian derivative (divergence of the inverse gradients): serves to calculate the phase space correction. | |
A object (or an object of a cvc-derived class) specifies how to calculate a collective variable, its gradients and other related physical quantities which do not depend only on the numeric value (the class already serves this purpose).
No restriction is set to what kind of calculation a object performs (usually calculate an analytical function of atomic coordinates). The only constraint is that the value calculated is implemented as a object. This serves to provide a unique way to calculate scalar and non-scalar collective variables, and specify if and how they can be combined together by the parent object.
If you wish to implement a new collective variable component, you should write your own class by inheriting directly from , or one of its derived classes (for instance, is frequently used, because it provides useful data and function members for any colvar based on two atom groups). The steps are:
The cvm::atom and cvm::atom_group classes are available to transparently communicate with the simulation program. However, they are not strictly needed, as long as all the degrees of freedom associated to the cvc are properly evolved by a simple call to e.g. apply_force().
Definition at line 51 of file colvarcomp.h.
|
|
Constructor. At least one constructor which reads a string should be defined for every class inheriting from cvc Definition at line 17 of file colvarcomp.C. References b_debug_gradients, colvar::b_inverse_gradients, colvar::b_periodic, colvarmodule::debug(), colvarmodule::log(), period, sup_coeff, sup_np, and wrap_center. 00018 : sup_coeff (1.0), sup_np (1), 00019 b_periodic (false), 00020 b_debug_gradients (false), 00021 b_inverse_gradients (false), 00022 b_Jacobian_derivative (false) 00023 { 00024 if (cvm::debug()) 00025 cvm::log ("Initializing cvc base object.\n"); 00026 00027 get_keyval (conf, "name", this->name, std::string (""), parse_silent); 00028 00029 get_keyval (conf, "componentCoeff", sup_coeff, 1.0); 00030 get_keyval (conf, "componentExp", sup_np, 1); 00031 00032 get_keyval (conf, "period", period, 0.0); 00033 get_keyval (conf, "wrapAround", wrap_center, 0.0); 00034 00035 get_keyval (conf, "debugGradients", b_debug_gradients, false, parse_silent); 00036 00037 if (cvm::debug()) 00038 cvm::log ("Done initializing cvc base object.\n"); 00039 }
|
|
|
Default constructor (used when objects are declared within other ones).
Definition at line 8 of file colvarcomp.C. 00009 : sup_coeff (1.0), sup_np (1), 00010 b_periodic (false), 00011 b_debug_gradients (false), 00012 b_inverse_gradients (false), 00013 b_Jacobian_derivative (false) 00014 {}
|
|
|
Destructor.
Definition at line 58 of file colvarcomp.C. 00059 {}
|
|
|
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
Implemented in colvar::distance, colvar::distance_vec, colvar::distance_dir, colvar::distance_z, colvar::distance_xy, colvar::distance_inv, colvar::gyration, colvar::inertia, colvar::inertia_z, colvar::eigenvector, colvar::angle, colvar::dihedral, colvar::coordnum, colvar::selfcoordnum, colvar::h_bond, colvar::alpha_angles, colvar::dihedPC, colvar::orientation, colvar::orientation_angle, colvar::tilt, colvar::spin_angle, and colvar::rmsd. |
|
|
Calculate the total force from the system using the inverse atomic gradients.
Reimplemented in colvar::distance, colvar::distance_z, colvar::distance_xy, colvar::gyration, colvar::eigenvector, colvar::angle, colvar::dihedral, and colvar::rmsd. Definition at line 62 of file colvarcomp.C. References colvarmodule::fatal_error(), and function_type. 00063 {
00064 cvm::fatal_error ("Error: calculation of inverse gradients is not implemented "
00065 "for colvar components of type \""+function_type+"\".\n");
00066 }
|
|
|
Calculate the atomic gradients, to be reused later in order to apply forces.
Implemented in colvar::distance, colvar::distance_vec, colvar::distance_dir, colvar::distance_z, colvar::distance_xy, colvar::distance_inv, colvar::gyration, colvar::inertia, colvar::inertia_z, colvar::eigenvector, colvar::angle, colvar::dihedral, colvar::coordnum, colvar::selfcoordnum, colvar::h_bond, colvar::alpha_angles, colvar::dihedPC, colvar::orientation, colvar::orientation_angle, colvar::tilt, colvar::spin_angle, and colvar::rmsd. |
|
|
Calculate the divergence of the inverse atomic gradients.
Reimplemented in colvar::distance, colvar::distance_z, colvar::distance_xy, colvar::gyration, colvar::eigenvector, colvar::angle, colvar::dihedral, and colvar::rmsd. Definition at line 69 of file colvarcomp.C. References colvarmodule::fatal_error(), and function_type. 00070 {
00071 cvm::fatal_error ("Error: calculation of inverse gradients is not implemented "
00072 "for colvar components of type \""+function_type+"\".\n");
00073 }
|
|
|
Calculate the variable.
Implemented in colvar::distance, colvar::distance_vec, colvar::distance_dir, colvar::distance_z, colvar::distance_xy, colvar::distance_inv, colvar::gyration, colvar::inertia, colvar::inertia_z, colvar::eigenvector, colvar::angle, colvar::dihedral, colvar::coordnum, colvar::selfcoordnum, colvar::h_bond, colvar::alpha_angles, colvar::dihedPC, colvar::orientation, colvar::orientation_angle, colvar::tilt, colvar::spin_angle, and colvar::rmsd. Referenced by debug_gradients(). |
|
||||||||||||
|
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 in colvar::distance, colvar::distance_vec, colvar::distance_dir, colvar::distance_z, colvar::distance_xy, colvar::distance_inv, colvar::gyration, colvar::inertia, colvar::inertia_z, colvar::eigenvector, colvar::angle, colvar::dihedral, colvar::coordnum, colvar::selfcoordnum, colvar::h_bond, colvar::alpha_angles, colvar::dihedPC, colvar::orientation, colvar::orientation_angle, colvar::tilt, colvar::spin_angle, and colvar::rmsd. Definition at line 283 of file colvarcomp.h. References colvarmodule::fatal_error(), colvarmodule::real, and type(). 00285 {
00286 if (this->type() == colvarvalue::type_scalar) {
00287 return cvm::real (x1 - x2);
00288 } else {
00289 cvm::fatal_error ("Error: you requested an operation which requires "
00290 "comparison between two non-scalar values.\n");
00291 return 0.0;
00292 }
00293 }
|
|
|
Calculate finite-difference gradients alongside the analytical ones, for each Cartesian component.
Definition at line 76 of file colvarcomp.C. References colvarmodule::atom_group::b_center, colvarmodule::atom_group::b_fit_gradients, colvarmodule::atom_group::b_rotate, colvarmodule::atom_group::calc_apply_roto_translation(), colvarmodule::atom_group::calc_fit_gradients(), calc_value(), colvarmodule::atom_group::fit_gradients, colvarmodule::rotation::inverse(), j, colvarmodule::log(), colvarmodule::atom_group::read_positions(), colvarvalue::real_value, colvarmodule::atom_group::ref_pos_group, colvarmodule::atom_group::rot, colvarmodule::rotation::rotate(), and x. Referenced by colvar::tilt::calc_gradients(), colvar::eigenvector::calc_gradients(), colvar::rmsd::calc_gradients(), colvar::inertia_z::calc_gradients(), colvar::inertia::calc_gradients(), and colvar::gyration::calc_gradients(). 00077 {
00078 // this function should work for any scalar variable:
00079 // the only difference will be the name of the atom group (here, "group")
00080
00081 // collect into a vector for convenience
00082 std::vector<cvm::rvector> gradients (group.size());
00083 for (size_t i = 0; i < group.size(); i++) {
00084 gradients[i] = group[i].grad;
00085 }
00086
00087 cvm::rotation const rot_0 = group.rot;
00088 cvm::rotation const rot_inv = group.rot.inverse();
00089
00090 cvm::real const x_0 = x.real_value;
00091
00092 cvm::log ("gradients = "+cvm::to_str (gradients)+"\n");
00093
00094 // it only makes sense to debug the fit gradients
00095 // when the fitting group is the same as this group
00096 if (group.b_rotate || group.b_center)
00097 if (group.b_fit_gradients && (group.ref_pos_group == NULL)) {
00098 group.calc_fit_gradients();
00099 if (group.b_rotate) {
00100 // fit_gradients are in the original frame, we should print them in the rotated frame
00101 for (size_t j = 0; j < group.fit_gradients.size(); j++) {
00102 group.fit_gradients[j] = rot_0.rotate (group.fit_gradients[j]);
00103 }
00104 }
00105 cvm::log ("fit_gradients = "+cvm::to_str (group.fit_gradients)+"\n");
00106 if (group.b_rotate) {
00107 for (size_t j = 0; j < group.fit_gradients.size(); j++) {
00108 group.fit_gradients[j] = rot_inv.rotate (group.fit_gradients[j]);
00109 }
00110 }
00111 }
00112
00113 for (size_t ia = 0; ia < group.size(); ia++) {
00114
00115 // tests are best conducted in the unrotated (simulation) frame
00116 cvm::rvector const atom_grad = group.b_rotate ?
00117 rot_inv.rotate (group[ia].grad) :
00118 group[ia].grad;
00119
00120 for (size_t id = 0; id < 3; id++) {
00121 // (re)read original positions
00122 group.read_positions();
00123 // change one coordinate
00124 group[ia].pos[id] += cvm::debug_gradients_step_size;
00125 // (re)do the fit (if defined)
00126 if (group.b_center || group.b_rotate) {
00127 group.calc_apply_roto_translation();
00128 }
00129 calc_value();
00130 cvm::real const x_1 = x.real_value;
00131 cvm::log ("Atom "+cvm::to_str (ia)+", component "+cvm::to_str (id)+":\n");
00132 cvm::log ("dx(actual) = "+cvm::to_str (x_1 - x_0,
00133 21, 14)+"\n");
00134 cvm::real const dx_pred = (group.fit_gradients.size() && (group.ref_pos_group == NULL)) ?
00135 (cvm::debug_gradients_step_size * (atom_grad[id] + group.fit_gradients[ia][id])) :
00136 (cvm::debug_gradients_step_size * atom_grad[id]);
00137 cvm::log ("dx(interp) = "+cvm::to_str (dx_pred,
00138 21, 14)+"\n");
00139 cvm::log ("|dx(actual) - dx(interp)|/|dx(actual)| = "+
00140 cvm::to_str (std::fabs (x_1 - x_0 - dx_pred) /
00141 std::fabs (x_1 - x_0),
00142 12, 5)+
00143 ".\n");
00144
00145 }
00146 }
00147 }
|
|
||||||||||||
|
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 in colvar::distance, colvar::distance_vec, colvar::distance_dir, colvar::distance_z, colvar::distance_xy, colvar::distance_inv, colvar::gyration, colvar::inertia, colvar::inertia_z, colvar::eigenvector, colvar::angle, colvar::dihedral, colvar::coordnum, colvar::selfcoordnum, colvar::h_bond, colvar::alpha_angles, colvar::dihedPC, colvar::orientation, colvar::orientation_angle, colvar::tilt, colvar::spin_angle, and colvar::rmsd. Definition at line 265 of file colvarcomp.h. References colvarvalue::dist2(). 00267 {
00268 return x1.dist2 (x2);
00269 }
|
|
||||||||||||
|
Gradient (with respect to x1) of the square distance (can be redefined to transparently implement constraints, symmetries and periodicities).
Reimplemented in colvar::distance, colvar::distance_vec, colvar::distance_dir, colvar::distance_z, colvar::distance_xy, colvar::distance_inv, colvar::gyration, colvar::inertia, colvar::inertia_z, colvar::eigenvector, colvar::angle, colvar::dihedral, colvar::coordnum, colvar::selfcoordnum, colvar::h_bond, colvar::alpha_angles, colvar::dihedPC, colvar::orientation, colvar::orientation_angle, colvar::tilt, colvar::spin_angle, and colvar::rmsd. Definition at line 271 of file colvarcomp.h. References colvarvalue::dist2_grad(). 00273 {
00274 return x1.dist2_grad (x2);
00275 }
|
|
||||||||||||
|
Gradient (with respect to x2) of the square distance (can be redefined to transparently implement constraints, symmetries and periodicities).
Reimplemented in colvar::distance, colvar::distance_vec, colvar::distance_dir, colvar::distance_z, colvar::distance_xy, colvar::distance_inv, colvar::gyration, colvar::inertia, colvar::inertia_z, colvar::eigenvector, colvar::angle, colvar::dihedral, colvar::coordnum, colvar::selfcoordnum, colvar::h_bond, colvar::alpha_angles, colvar::dihedPC, colvar::orientation, colvar::orientation_angle, colvar::tilt, colvar::spin_angle, and colvar::rmsd. Definition at line 277 of file colvarcomp.h. References colvarvalue::dist2_grad(). 00279 {
00280 return x2.dist2_grad (x1);
00281 }
|
|
|
Return the previously calculated divergence of the inverse atomic gradients.
Definition at line 259 of file colvarcomp.h. 00260 {
00261 return jd;
00262 }
|
|
||||||||||||||||||||
|
Within the constructor, make a group parse its own options from the provided configuration string.
Definition at line 42 of file colvarcomp.C. References colvarmodule::fatal_error(), colvarparse::key_lookup(), and colvarmodule::atom_group::parse(). Referenced by colvar::angle::angle(), colvar::dihedral::dihedral(), colvar::distance::distance(), colvar::distance_z::distance_z(), colvar::eigenvector::eigenvector(), colvar::gyration::gyration(), colvar::orientation::orientation(), and colvar::rmsd::rmsd(). 00046 {
00047 if (key_lookup (conf, group_key)) {
00048 group.parse (conf, group_key);
00049 } else {
00050 if (! optional) {
00051 cvm::fatal_error ("Error: definition for atom group \""+
00052 std::string (group_key)+"\" not found.\n");
00053 }
00054 }
00055 }
|
|
|
Return the previously calculated system force.
Definition at line 254 of file colvarcomp.h. 00255 {
00256 return ft;
00257 }
|
|
|
Type of that this cvc provides.
Definition at line 244 of file colvarcomp.h. References colvarvalue::type(), and x. Referenced by compare().
|
|
|
Return the previously calculated value.
Definition at line 249 of file colvarcomp.h. 00250 {
00251 return x;
00252 }
|
|
|
Wrapp value (for periodic/symmetric cvcs).
Reimplemented in colvar::distance_z, colvar::dihedral, and colvar::spin_angle. Definition at line 295 of file colvarcomp.h. 00296 {
00297 return;
00298 }
|
|
|
Pointers to all atom groups, to let colvars collect info e.g. atomic gradients.
Definition at line 220 of file colvarcomp.h. |
|
|
If true, calc_gradients() will call debug_gradients() for every group needed.
Definition at line 130 of file colvarcomp.h. Referenced by cvc(). |
|
|
If this flag is false (default), inverse gradients (derivatives of atom coordinates with respect to x) are unavailable; it should be set to true by the constructor of each derived object capable of calculating them.
Definition at line 114 of file colvarcomp.h. |
|
|
If this flag is false (default), the Jacobian derivative (divergence of the inverse gradients) is unavailable; it should be set to true by the constructor of each derived object capable of calculating it.
Definition at line 120 of file colvarcomp.h. |
|
|
Definition at line 85 of file colvarcomp.h. |
|
|
Calculated system force (Note: this is calculated from the total atomic forces read from the program, subtracting fromt the "internal" forces of the system the "external" forces from the colvar biases).
Definition at line 234 of file colvarcomp.h. |
|
|
Description of the type of collective variable. Normally this string is set by the parent object within its constructor, when all objects are initialized; therefore the main "config string" constructor does not need to define it. If a is initialized and/or a different constructor is used, this variable definition should be set within the constructor. Definition at line 68 of file colvarcomp.h. Referenced by calc_force_invgrads(), and calc_Jacobian_derivative(). |
|
|
Calculated Jacobian derivative (divergence of the inverse gradients): serves to calculate the phase space correction.
Definition at line 238 of file colvarcomp.h. |
|
|
The name of the object (helps to identify this cvc instance when debugging).
Definition at line 58 of file colvarcomp.h. |
|
|
Period of this cvc value, (default: 0.0, non periodic).
Definition at line 80 of file colvarcomp.h. Referenced by cvc(). |
|
|
Coefficient in the polynomial combination (default: 1.0).
Definition at line 75 of file colvarcomp.h. Referenced by cvc(). |
|
|
Exponent in the polynomial combination (default: 1).
Definition at line 77 of file colvarcomp.h. Referenced by cvc(). |
|
|
If the component is periodic, wrap around this value (default: 0.0).
Definition at line 83 of file colvarcomp.h. Referenced by cvc(). |
|
|
Cached value.
Definition at line 225 of file colvarcomp.h. Referenced by debug_gradients(), and type(). |
|
|
Value at the previous step.
Definition at line 228 of file colvarcomp.h. |
1.3.9.1