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

Public Member Functions | |
| eigenvector (std::string const &conf) | |
| Constructor. | |
| virtual | ~eigenvector () |
| 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 | atoms |
| Atom group. | |
| std::vector< cvm::atom_pos > | ref_pos |
| Reference coordinates. | |
| std::vector< cvm::rvector > | eigenvec |
| Eigenvector (of a normal or essential mode). | |
| cvm::real | eigenvec_invnorm2 |
| Inverse square norm of the eigenvector. | |
Definition at line 515 of file colvarcomp.h.
|
|
Constructor.
Definition at line 780 of file colvarcomp_distances.C. References atoms, eigenvec, eigenvec_invnorm2, colvarmodule::fatal_error(), colvarmodule::load_coords(), colvarmodule::log(), colvarmodule::rvector::norm2(), colvar::cvc::parse_group(), ref_pos, colvarmodule::rotation::request_group1_gradients(), colvarmodule::rotation::request_group2_gradients(), colvarmodule::atom_group::rot, and colvarvalue::type(). 00781 : cvc (conf) 00782 { 00783 b_inverse_gradients = true; 00784 b_Jacobian_derivative = true; 00785 function_type = "eigenvector"; 00786 x.type (colvarvalue::type_scalar); 00787 00788 parse_group (conf, "atoms", atoms); 00789 00790 if (get_keyval (conf, "refPositions", ref_pos, ref_pos)) { 00791 cvm::log ("Using reference positions from input file.\n"); 00792 if (ref_pos.size() != atoms.size()) { 00793 cvm::fatal_error ("Error: reference positions do not " 00794 "match the number of atom indexes.\n"); 00795 } 00796 } 00797 00798 { 00799 std::string file_name; 00800 if (get_keyval (conf, "refPositionsFile", file_name)) { 00801 00802 std::string file_col; 00803 get_keyval (conf, "refPositionsCol", file_col, std::string ("O")); 00804 00805 double file_col_value; 00806 bool found = get_keyval (conf, "refPositionsColValue", file_col_value, 0.0); 00807 if (found && !file_col_value) 00808 cvm::fatal_error ("Error: refPositionsColValue, " 00809 "if provided, must be non-zero.\n"); 00810 00811 ref_pos.resize (atoms.size()); 00812 cvm::load_coords (file_name.c_str(), ref_pos, file_col, file_col_value); 00813 } 00814 } 00815 00816 // now load the eigenvector 00817 if (get_keyval (conf, "vector", eigenvec, eigenvec)) { 00818 cvm::log ("Using reference positions from input file.\n"); 00819 if (eigenvec.size() != atoms.size()) { 00820 cvm::fatal_error ("Error: reference positions do not " 00821 "match the number of atom indexes.\n"); 00822 } 00823 } 00824 00825 { 00826 std::string file_name; 00827 if (get_keyval (conf, "vectorFile", file_name)) { 00828 00829 std::string file_col; 00830 get_keyval (conf, "vectorCol", file_col, std::string ("O")); 00831 00832 double file_col_value; 00833 bool found = get_keyval (conf, "vectorColValue", file_col_value, 0.0); 00834 if (found && !file_col_value) 00835 cvm::fatal_error ("Error: eigenvectorColValue, " 00836 "if provided, must be non-zero.\n"); 00837 00838 eigenvec.resize (atoms.size()); 00839 cvm::load_coords (file_name.c_str(), eigenvec, file_col, file_col_value); 00840 } 00841 } 00842 00843 if (!ref_pos.size() || !eigenvec.size()) { 00844 cvm::fatal_error ("Error: must define both reference " 00845 "coordinates and eigenvector.\n"); 00846 } 00847 00848 cvm::rvector center (0.0, 0.0, 0.0); 00849 eigenvec_invnorm2 = 0.0; 00850 00851 for (size_t i = 0; i < atoms.size(); i++) { 00852 center += eigenvec[i]; 00853 } 00854 00855 cvm::log ("Subtracting sum of eigenvector components: " + cvm::to_str (center) + "\n"); 00856 00857 for (size_t i = 0; i < atoms.size(); i++) { 00858 eigenvec[i] = eigenvec[i] - center; 00859 eigenvec_invnorm2 += eigenvec[i].norm2(); 00860 } 00861 eigenvec_invnorm2 = 1.0 / eigenvec_invnorm2; 00862 00863 // request derivatives of optimal rotation wrt 2nd group 00864 // for Jacobian 00865 atoms.rot.request_group1_gradients(atoms.size()); 00866 atoms.rot.request_group2_gradients(atoms.size()); 00867 }
|
|
|
Definition at line 536 of file colvarcomp.h. 00536 {}
|
|
|
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
Implements colvar::cvc. Definition at line 893 of file colvarcomp_distances.C. References colvarmodule::atom_group::apply_colvar_force(), atoms, colvarmodule::atom_group::noforce, and colvarvalue::real_value. 00894 {
00895 if (!atoms.noforce)
00896 atoms.apply_colvar_force (force.real_value);
00897 }
|
|
|
Calculate the total force from the system using the inverse atomic gradients.
Reimplemented from colvar::cvc. Definition at line 900 of file colvarcomp_distances.C. References atoms, eigenvec_invnorm2, colvarmodule::atom_group::read_system_forces(), colvarvalue::real_value, and colvarmodule::atom_group::system_force(). 00901 {
00902 atoms.read_system_forces();
00903 ft.real_value = 0.0;
00904
00905 for (size_t ia = 0; ia < atoms.size(); ia++) {
00906 ft.real_value += eigenvec_invnorm2 * atoms[ia].grad *
00907 atoms[ia].system_force;
00908 }
00909 }
|
|
|
Calculate the atomic gradients, to be reused later in order to apply forces.
Implements colvar::cvc. Definition at line 882 of file colvarcomp_distances.C. References atoms, and eigenvec. 00883 {
00884 for (size_t i = 0; i < atoms.size(); i++) {
00885 atoms[i].grad = eigenvec[i];
00886 }
00887
00888 // WARNING: either the gradient must be rotated, or the automatic
00889 // rotation of forces within the atom group should be disabled.
00890 }
|
|
|
Calculate the divergence of the inverse atomic gradients.
Reimplemented from colvar::cvc. Definition at line 912 of file colvarcomp_distances.C. References colvarmodule::atom_pos, atoms, colvarmodule::rotation::dQ0_1, eigenvec, eigenvec_invnorm2, j, colvarmodule::rotation::q, colvarvalue::real_value, and colvarmodule::atom_group::rot. 00913 {
00914 // gradient of the rotation matrix
00915 cvm::matrix2d <cvm::rvector, 3, 3> grad_rot_mat;
00916 cvm::quaternion &quat0 = atoms.rot.q;
00917
00918 // gradients of products of 2 quaternion components
00919 cvm::rvector g11, g22, g33, g01, g02, g03, g12, g13, g23;
00920
00921 cvm::atom_pos x_relative;
00922 cvm::real sum = 0.0;
00923
00924 for (size_t ia = 0; ia < atoms.size(); ia++) {
00925
00926 // Gradient of optimal quaternion wrt current Cartesian position
00927 // trick: d(R^-1)/dx = d(R^t)/dx = (dR/dx)^t
00928 // we can just transpose the derivatives of the direct matrix
00929 cvm::vector1d< cvm::rvector, 4 > &dq_1 = atoms.rot.dQ0_1[ia];
00930
00931 g11 = 2.0 * quat0[1]*dq_1[1];
00932 g22 = 2.0 * quat0[2]*dq_1[2];
00933 g33 = 2.0 * quat0[3]*dq_1[3];
00934 g01 = quat0[0]*dq_1[1] + quat0[1]*dq_1[0];
00935 g02 = quat0[0]*dq_1[2] + quat0[2]*dq_1[0];
00936 g03 = quat0[0]*dq_1[3] + quat0[3]*dq_1[0];
00937 g12 = quat0[1]*dq_1[2] + quat0[2]*dq_1[1];
00938 g13 = quat0[1]*dq_1[3] + quat0[3]*dq_1[1];
00939 g23 = quat0[2]*dq_1[3] + quat0[3]*dq_1[2];
00940
00941 // Gradient of the inverse rotation matrix wrt current Cartesian position
00942 // (transpose of the gradient of the direct rotation)
00943 grad_rot_mat[0][0] = -2.0 * (g22 + g33);
00944 grad_rot_mat[0][1] = 2.0 * (g12 + g03);
00945 grad_rot_mat[0][2] = 2.0 * (g13 - g02);
00946 grad_rot_mat[1][0] = 2.0 * (g12 - g03);
00947 grad_rot_mat[1][1] = -2.0 * (g11 + g33);
00948 grad_rot_mat[1][2] = 2.0 * (g01 + g23);
00949 grad_rot_mat[2][0] = 2.0 * (g02 + g13);
00950 grad_rot_mat[2][1] = 2.0 * (g23 - g01);
00951 grad_rot_mat[2][2] = -2.0 * (g11 + g22);
00952
00953 for (size_t i = 0; i < 3; i++) {
00954 for (size_t j = 0; j < 3; j++) {
00955 sum += grad_rot_mat[i][j][i] * eigenvec[ia][j];
00956 }
00957 }
00958 }
00959
00960 jd.real_value = sum * sqrt (eigenvec_invnorm2);
00961 }
|
|
|
Calculate the variable.
Implements colvar::cvc. Definition at line 870 of file colvarcomp_distances.C. References atoms, eigenvec, colvarmodule::atom_group::read_positions(), colvarvalue::real_value, ref_pos, and colvarmodule::atom_group::reset_atoms_data(). 00871 {
00872 atoms.reset_atoms_data();
00873 atoms.read_positions();
00874
00875 x.real_value = 0.0;
00876 for (size_t i = 0; i < atoms.size(); i++) {
00877 x.real_value += (atoms[i].pos - ref_pos[i]) * eigenvec[i];
00878 }
00879 }
|
|
||||||||||||
|
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. |
|
||||||||||||
|
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. |
|
||||||||||||
|
Gradient (with respect to x1) of the square distance (can be redefined to transparently implement constraints, symmetries and periodicities).
Reimplemented from colvar::cvc. |
|
||||||||||||
|
Gradient (with respect to x2) of the square distance (can be redefined to transparently implement constraints, symmetries and periodicities).
Reimplemented from colvar::cvc. |
|
|
Atom group.
Definition at line 521 of file colvarcomp.h. Referenced by apply_force(), calc_force_invgrads(), calc_gradients(), calc_Jacobian_derivative(), calc_value(), and eigenvector(). |
|
|
Eigenvector (of a normal or essential mode).
Definition at line 527 of file colvarcomp.h. Referenced by calc_gradients(), calc_Jacobian_derivative(), calc_value(), and eigenvector(). |
|
|
Inverse square norm of the eigenvector.
Definition at line 530 of file colvarcomp.h. Referenced by calc_force_invgrads(), calc_Jacobian_derivative(), and eigenvector(). |
|
|
Reference coordinates.
Definition at line 524 of file colvarcomp.h. Referenced by calc_value(), and eigenvector(). |
1.3.9.1