Collective Variables Module - Developer Documentation
|
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set to be a scalar number, and can be treated as such in all operations (this is done by most colvar::cvc implementations). More...
#include <colvarvalue.h>
Public Types | |
enum | Type { type_notset , type_scalar , type_3vector , type_unit3vector , type_unit3vectorderiv , type_quaternion , type_quaternionderiv , type_vector , type_all } |
Possible types of value. More... | |
Public Member Functions | |
size_t | size () const |
Number of dimensions of this variable. | |
colvarvalue () | |
Default constructor: this class defaults to a scalar number and always behaves like it unless you change its type. | |
colvarvalue (Type const &vti) | |
colvarvalue (cvm::real const &x) | |
Copy constructor from real base type. | |
colvarvalue (cvm::rvector const &v, Type vti=type_3vector) | |
Copy constructor from rvector base type (Note: this sets by default a type type_3vector , if you want a type_unit3vector you must set it explicitly) | |
colvarvalue (cvm::quaternion const &q, Type vti=type_quaternion) | |
Copy constructor from quaternion base type. | |
colvarvalue (cvm::vector1d< cvm::real > const &v, Type vti=type_vector) | |
Copy constructor from vector1d base type. | |
colvarvalue (colvarvalue const &x) | |
Copy constructor from another colvarvalue. | |
void | reset () |
Set to the null value for the data type currently defined. | |
void | apply_constraints () |
If the variable has constraints (e.g. unitvector or quaternion), transform it to satisfy them; this function needs to be called only when the colvarvalue is calculated outside of colvar::cvc objects. | |
Type | type () const |
Get the current type. | |
void | type (Type const &vti) |
Set the type explicitly. | |
void | type (colvarvalue const &x) |
Set the type after another colvarvalue. | |
void | is_derivative () |
cvm::real | norm2 () const |
Square norm of this colvarvalue. | |
cvm::real | norm () const |
Norm of this colvarvalue. | |
cvm::real | sum () const |
Sum of the components of this colvarvalue (if more than one dimension) | |
colvarvalue | ones () const |
Return a colvarvalue object of the same type and all components set to 1. | |
cvm::real | dist2 (colvarvalue const &x2) const |
Square distance between this colvarvalue and another. | |
colvarvalue | dist2_grad (colvarvalue const &x2) const |
Derivative with respect to this colvarvalue of the square distance. | |
colvarvalue & | operator= (colvarvalue const &x) |
Assignment operator (type of x is checked) | |
void | operator+= (colvarvalue const &x) |
void | operator-= (colvarvalue const &x) |
void | operator*= (cvm::real const &a) |
void | operator/= (cvm::real const &a) |
operator cvm::real () const | |
operator cvm::rvector () const | |
operator cvm::quaternion () const | |
cvm::vector1d< cvm::real > const | as_vector () const |
bool | is_scalar () const |
Whether this variable is a real number. | |
void | add_elem (colvarvalue const &x) |
colvarvalue const | get_elem (int const i_begin, int const i_end, Type const vt) const |
Get a single colvarvalue out of elements of the vector. | |
colvarvalue const | get_elem (int const icv) const |
Get a single colvarvalue out of elements of the vector. | |
void | set_elem (int const icv, colvarvalue const &x) |
void | set_elem (int const i_begin, int const i_end, colvarvalue const &x) |
Set elements of the vector from a single colvarvalue. | |
void | set_random () |
Make each element a random number in N(0,1) | |
void | set_ones (cvm::real assigned_value=1.0) |
Make each element equal to the given argument. | |
cvm::real | operator[] (int const i) const |
Get a scalar number out of an element of the vector. | |
cvm::real & | operator[] (int const i) |
Use an element of the vector as a scalar number. | |
void | undef_op () const |
Undefined operation. | |
size_t | output_width (size_t const &real_width) const |
std::string | to_simple_string () const |
Formats value as a script-friendly string (space separated list) | |
int | from_simple_string (std::string const &s) |
Parses value from a script-friendly string (space separated list) | |
Static Public Member Functions | |
static bool | type_checking () |
Whether or not the type check is enforced. | |
static std::string const | type_desc (Type t) |
Runtime description of value types. | |
static std::string const | type_keyword (Type t) |
User keywords for specifying value types in the configuration. | |
static size_t | num_dimensions (Type t) |
Number of dimensions for each supported type (used to allocate vector1d_value) | |
static colvarvalue const | interpolate (colvarvalue const &x1, colvarvalue const &x2, cvm::real const lambda=0.5) |
static int | check_types (colvarvalue const &x1, colvarvalue const &x2) |
Ensure that the two types are the same within a binary operator. | |
static int | check_types_assign (Type const &vt1, Type const &vt2) |
Ensure that the two types are the same within an assignment, or that the left side is type_notset. | |
static void | inner_opt (colvarvalue const &x, std::vector< colvarvalue >::iterator &xv, std::vector< colvarvalue >::iterator const &xv_end, std::vector< cvm::real >::iterator &result) |
Optimized routine for the inner product of one collective variable with an array. | |
static void | inner_opt (colvarvalue const &x, std::list< colvarvalue >::iterator &xv, std::list< colvarvalue >::iterator const &xv_end, std::vector< cvm::real >::iterator &result) |
Optimized routine for the inner product of one collective variable with an array. | |
static void | p2leg_opt (colvarvalue const &x, std::vector< colvarvalue >::iterator &xv, std::vector< colvarvalue >::iterator const &xv_end, std::vector< cvm::real >::iterator &result) |
Optimized routine for the second order Legendre polynomial, (3cos^2(w)-1)/2, of one collective variable with an array. | |
static void | p2leg_opt (colvarvalue const &x, std::list< colvarvalue >::iterator &xv, std::list< colvarvalue >::iterator const &xv_end, std::vector< cvm::real >::iterator &result) |
Optimized routine for the second order Legendre polynomial of one collective variable with an array. | |
Public Attributes | |
Type | value_type |
Current type of this colvarvalue object. | |
cvm::real | real_value |
Real data member. | |
cvm::rvector | rvector_value |
3-dimensional vector data member | |
cvm::quaternion | quaternion_value |
Quaternion data member. | |
cvm::vector1d< cvm::real > | vector1d_value |
Generic vector data member. | |
std::vector< Type > | elem_types |
If vector1d_value is a concatenation of colvarvalues, keep track of the individual types. | |
std::vector< int > | elem_indices |
If vector1d_value is a concatenation of colvarvalues, these mark the initial components of each colvarvalue. | |
std::vector< int > | elem_sizes |
If vector1d_value is a concatenation of colvarvalues, these mark how many components for each colvarvalue. | |
Friends | |
colvarvalue | operator+ (colvarvalue const &x1, colvarvalue const &x2) |
colvarvalue | operator- (colvarvalue const &x1, colvarvalue const &x2) |
colvarvalue | operator* (colvarvalue const &x, cvm::real const &a) |
colvarvalue | operator* (cvm::real const &a, colvarvalue const &x) |
colvarvalue | operator/ (colvarvalue const &x, cvm::real const &a) |
cvm::real | operator* (colvarvalue const &x1, colvarvalue const &x2) |
Inner product. | |
std::ostream & | operator<< (std::ostream &os, colvarvalue const &x) |
Formatted output operator. | |
cvm::memory_stream & | operator<< (cvm::memory_stream &os, colvarvalue const &x) |
Unformatted output operator. | |
std::istream & | operator>> (std::istream &is, colvarvalue &x) |
Formatted input operator. | |
cvm::memory_stream & | operator>> (cvm::memory_stream &is, colvarvalue &x) |
Unformatted input operator. | |
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set to be a scalar number, and can be treated as such in all operations (this is done by most colvar::cvc implementations).
colvarvalue allows colvar to be treat different data types. By default, a colvarvalue variable is a scalar number. To use it as another type, declare and initialize it as colvarvalue x(colvarvalue::type_xxx)
, use x.type (colvarvalue::type_xxx)
at a later stage, or if unset, assign the type with x = y;
, provided y is correctly set.
All operators (either unary or binary) on a colvarvalue object performs one or more checks on the Type, except when reading from a stream, when there is no way to detect the Type. To use is >> x;
x MUST already have a type correcly set up for properly parsing the stream. No problem of course with the output streams: os << x;
Note on performance: to avoid type checks in a long array of colvarvalue objects, use one of the existing "_opt" functions or implement a new one
enum colvarvalue::Type |
Possible types of value.
These three cover most possibilities of data type one can devise. If you need to implement a new colvar with a very complex data type, it's better to put an allocatable class here
Enumerator | |
---|---|
type_notset | Undefined type. |
type_scalar | Scalar number, implemented as colvarmodule::real (default) |
type_3vector | 3-dimensional vector, implemented as colvarmodule::rvector |
type_unit3vector | 3-dimensional unit vector, implemented as colvarmodule::rvector |
type_unit3vectorderiv | 3-dimensional vector that is a derivative of a unitvector |
type_quaternion | 4-dimensional unit vector representing a rotation, implemented as colvarmodule::quaternion |
type_quaternionderiv | 4-dimensional vector that is a derivative of a quaternion |
type_vector | vector (arbitrary dimension) |
type_all | Needed to iterate through enum. |
colvarvalue::colvarvalue | ( | Type const & | vti | ) |
Constructor from a type flag (note: type_vector also needs the vector length to be set)
[in] | vti | Value of the Type enum |
void colvarvalue::add_elem | ( | colvarvalue const & | x | ) |
Add an element to the vector (requires that type_vector is already set). This is only needed to use this object as a vector of "complex" colvar values. To use it instead as a plain n-dimensional vector, access vector1d_value directly.
|
static |
Return the midpoint between x1 and x2, optionally weighted by lambda (which must be between 0.0 and 1.0)
void colvarvalue::is_derivative | ( | ) |
Make the type a derivative of the original type (so that its constraints do not apply)
size_t colvarvalue::output_width | ( | size_t const & | real_width | ) | const |
Give the number of characters required to output this colvarvalue, given the current type assigned and the number of characters for a real number
void colvarvalue::set_elem | ( | int const | icv, |
colvarvalue const & | x | ||
) |
Set elements of the vector from a single colvarvalue (uses the rank of x to compute the length)