16#include "colvartypes.h"
221 cvm::error(
"Error: trying to use a variable of type \""+
234 cvm::error(
"Error: trying to use a variable of type \""+
246 cvm::error(
"Error: trying to use a variable of type \""+
347 std::vector<colvarvalue>::iterator &xv,
348 std::vector<colvarvalue>::iterator
const &xv_end,
349 std::vector<cvm::real>::iterator &result);
354 std::list<colvarvalue>::iterator &xv,
355 std::list<colvarvalue>::iterator
const &xv_end,
356 std::vector<cvm::real>::iterator &result);
362 std::vector<colvarvalue>::iterator &xv,
363 std::vector<colvarvalue>::iterator
const &xv_end,
364 std::vector<cvm::real>::iterator &result);
369 std::list<colvarvalue>::iterator &xv,
370 std::list<colvarvalue>::iterator
const &xv_end,
371 std::vector<cvm::real>::iterator &result);
402 cvm::error(
"Error: trying to access a colvar value "
403 "that is not initialized.\n", COLVARS_BUG_ERROR);
425 cvm::error(
"Error: trying to access a colvar value "
426 "that is not initialized.\n", COLVARS_BUG_ERROR);
461 cvm::error(
"Trying to perform an operation between two colvar "
462 "values with different types, \""+
467 return COLVARS_ERROR;
473 cvm::error(
"Trying to perform an operation between two vector colvar "
474 "values with different sizes, "+
479 return COLVARS_ERROR;
505 cvm::error(
"Trying to assign a colvar value with type \""+
508 return COLVARS_ERROR;
521 switch (this->
type()) {
549inline void colvarvalue::operator += (
colvarvalue const &x)
553 switch (this->
type()) {
576inline void colvarvalue::operator -= (
colvarvalue const &x)
603inline void colvarvalue::operator *= (
cvm::real const &a)
618 this->vector1d_value *= a;
627inline void colvarvalue::operator /= (
cvm::real const &a)
640 this->vector1d_value /= a;
682 return (this->rvector_value).norm2();
685 return (this->quaternion_value).norm2();
710 return (this->real_value);
715 (this->rvector_value).z;
721 return (this->vector1d_value).sum();
733 switch (this->
type()) {
1-dimensional vector of real numbers with four components and a quaternion algebra
Definition: colvartypes.h:958
cvm::real dist2(cvm::quaternion const &Q2) const
Square distance from another quaternion on the 4-dimensional unit sphere: returns the square of the a...
Definition: colvartypes.h:1239
vector of real numbers with three components
Definition: colvartypes.h:727
Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e....
Definition: colvartypes.h:37
cvm::real norm2() const
Squared norm.
Definition: colvartypes.h:228
double real
Defining an abstract real number allows to switch precision.
Definition: colvarmodule.h:95
static int error(std::string const &message, int code=-1)
Print a message to the main log and set global error code.
Definition: colvarmodule.cpp:2032
static real sqrt(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:133
static real acos(real const &x)
Reimplemented to work around MS compiler issues.
Definition: colvarmodule.h:157
static std::string to_str(char const *s)
Convert to string for output purposes.
Definition: colvarmodule.cpp:2378
Value of a collective variable: this is a metatype which can be set at runtime. By default it is set ...
Definition: colvarvalue.h:43
int from_simple_string(std::string const &s)
Parses value from a script-friendly string (space separated list)
Definition: colvarvalue.cpp:696
Type
Possible types of value.
Definition: colvarvalue.h:52
@ type_notset
Undefined type.
Definition: colvarvalue.h:54
@ type_3vector
3-dimensional vector, implemented as colvarmodule::rvector
Definition: colvarvalue.h:58
@ type_vector
vector (arbitrary dimension)
Definition: colvarvalue.h:68
@ type_unit3vectorderiv
3-dimensional vector that is a derivative of a unitvector
Definition: colvarvalue.h:62
@ type_quaternionderiv
4-dimensional vector that is a derivative of a quaternion
Definition: colvarvalue.h:66
@ type_quaternion
4-dimensional unit vector representing a rotation, implemented as colvarmodule::quaternion
Definition: colvarvalue.h:64
@ type_unit3vector
3-dimensional unit vector, implemented as colvarmodule::rvector
Definition: colvarvalue.h:60
@ type_all
Needed to iterate through enum.
Definition: colvarvalue.h:70
@ type_scalar
Scalar number, implemented as colvarmodule::real (default)
Definition: colvarvalue.h:56
cvm::real dist2(colvarvalue const &x2) const
Square distance between this colvarvalue and another.
Definition: colvarvalue.h:729
cvm::quaternion quaternion_value
Quaternion data member.
Definition: colvarvalue.h:83
std::vector< int > elem_sizes
If vector1d_value is a concatenation of colvarvalues, these mark how many components for each colvarv...
Definition: colvarvalue.h:98
colvarvalue()
Default constructor: this class defaults to a scalar number and always behaves like it unless you cha...
Definition: colvarvalue.cpp:18
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.
Definition: colvarvalue.cpp:330
cvm::real real_value
Real data member.
Definition: colvarvalue.h:77
Type type() const
Get the current type.
Definition: colvarvalue.h:157
colvarvalue & operator=(colvarvalue const &x)
Assignment operator (type of x is checked)
Definition: colvarvalue.h:516
void read_from_stream_template_(IST &is)
Generic stream reading function (formatted and not)
Definition: colvarvalue.cpp:774
void apply_constraints()
If the variable has constraints (e.g. unitvector or quaternion), transform it to satisfy them; this f...
Definition: colvarvalue.cpp:226
cvm::real norm() const
Norm of this colvarvalue.
Definition: colvarvalue.h:176
cvm::real operator[](int const i) const
Get a scalar number out of an element of the vector.
Definition: colvarvalue.h:397
void is_derivative()
Definition: colvarvalue.cpp:290
void set_ones(cvm::real assigned_value=1.0)
Make each element equal to the given argument.
Definition: colvarvalue.cpp:409
void reset()
Set to the null value for the data type currently defined.
Definition: colvarvalue.cpp:201
static std::string const type_desc(Type t)
Runtime description of value types.
Definition: colvarvalue.cpp:107
colvarvalue ones() const
Return a colvarvalue object of the same type and all components set to 1.
std::vector< Type > elem_types
If vector1d_value is a concatenation of colvarvalues, keep track of the individual types.
Definition: colvarvalue.h:90
static colvarvalue const interpolate(colvarvalue const &x1, colvarvalue const &x2, cvm::real const lambda=0.5)
Definition: colvarvalue.cpp:627
void set_elem(int const icv, colvarvalue const &x)
Definition: colvarvalue.cpp:364
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.
Definition: colvarvalue.cpp:845
size_t size() const
Number of dimensions of this variable.
Definition: colvarvalue.h:376
static bool type_checking()
Whether or not the type check is enforced.
Definition: colvarvalue.h:101
static size_t num_dimensions(Type t)
Number of dimensions for each supported type (used to allocate vector1d_value)
Definition: colvarvalue.cpp:179
static std::string const type_keyword(Type t)
User keywords for specifying value types in the configuration.
Definition: colvarvalue.cpp:132
size_t output_width(size_t const &real_width) const
Definition: colvarvalue.cpp:823
void set_random()
Make each element a random number in N(0,1)
Definition: colvarvalue.cpp:375
friend std::istream & operator>>(std::istream &is, colvarvalue &x)
Formatted input operator.
Definition: colvarvalue.cpp:810
std::vector< int > elem_indices
If vector1d_value is a concatenation of colvarvalues, these mark the initial components of each colva...
Definition: colvarvalue.h:94
void write_to_stream_template_(OST &os) const
Generic stream writing function (formatted and not)
Definition: colvarvalue.cpp:724
bool is_scalar() const
Whether this variable is a real number.
Definition: colvarvalue.h:258
void undef_op() const
Undefined operation.
Definition: colvarvalue.cpp:443
cvm::vector1d< cvm::real > vector1d_value
Generic vector data member.
Definition: colvarvalue.h:86
friend std::ostream & operator<<(std::ostream &os, colvarvalue const &x)
Formatted output operator.
Definition: colvarvalue.cpp:750
cvm::real sum() const
Sum of the components of this colvarvalue (if more than one dimension)
Definition: colvarvalue.h:706
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.
Definition: colvarvalue.h:486
Type value_type
Current type of this colvarvalue object.
Definition: colvarvalue.h:74
static int check_types(colvarvalue const &x1, colvarvalue const &x2)
Ensure that the two types are the same within a binary operator.
Definition: colvarvalue.h:443
colvarvalue dist2_grad(colvarvalue const &x2) const
Derivative with respect to this colvarvalue of the square distance.
Definition: colvarvalue.cpp:594
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 variab...
Definition: colvarvalue.cpp:927
static size_t num_df(Type t)
Number of degrees of freedom for each supported type.
Definition: colvarvalue.cpp:156
void add_elem(colvarvalue const &x)
Definition: colvarvalue.cpp:314
std::string to_simple_string() const
Formats value as a script-friendly string (space separated list)
Definition: colvarvalue.cpp:669
cvm::rvector rvector_value
3-dimensional vector data member
Definition: colvarvalue.h:80
cvm::real norm2() const
Square norm of this colvarvalue.
Definition: colvarvalue.h:674
Definition: colvars_memstream.h:30
Collective variables main module.