Collective Variables Module - Developer Documentation
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
colvar_grid< T > Class Template Reference

Grid of values of a function of several collective variables. More...

#include <colvargrid.h>

Inheritance diagram for colvar_grid< T >:
Inheritance graph
[legend]
Collaboration diagram for colvar_grid< T >:
Collaboration graph
[legend]

Public Member Functions

size_t number_of_colvars () const
 Return the number of colvars.
 
size_t number_of_points (int const icv=-1) const
 
std::vector< int > const & sizes () const
 Get the sizes in each direction.
 
void set_sizes (std::vector< int > const &new_sizes)
 Set the sizes in each direction.
 
size_t multiplicity () const
 Return the multiplicity of the type used.
 
void request_actual_value (bool b=true)
 Request grid to use actual values of extended coords.
 
int setup (std::vector< int > const &nx_i, T const &t=T(), size_t const &mult_i=1)
 Allocate data.
 
int setup ()
 Allocate data (allow initialization also after construction)
 
void reset (T const &t=T())
 Reset data (in case the grid is being reused)
 
 colvar_grid ()
 Default constructor.
 
virtual ~colvar_grid ()
 Destructor.
 
 colvar_grid (colvar_grid< T > const &g)
 "Almost copy-constructor": only copies configuration parameters from another grid, but doesn't reallocate stuff; setup() must be called after that;
 
 colvar_grid (std::vector< int > const &nx_i, T const &t=T(), size_t mult_i=1)
 Constructor from explicit grid sizes. More...
 
 colvar_grid (std::vector< colvar *> const &colvars, T const &t=T(), size_t mult_i=1, bool margin=false)
 Constructor from a vector of colvars.
 
int init_from_colvars (std::vector< colvar *> const &colvars, T const &t=T(), size_t mult_i=1, bool margin=false)
 
int init_from_boundaries (T const &t=T(), size_t const &mult_i=1)
 
void wrap (std::vector< int > &ix) const
 
int current_bin_scalar (int const i) const
 Report the bin corresponding to the current value of variable i.
 
int current_bin_scalar_bound (int const i) const
 Report the bin corresponding to the current value of variable i and assign first or last bin if out of boundaries.
 
int current_bin_scalar (int const i, int const iv) const
 Report the bin corresponding to the current value of item iv in variable i.
 
int value_to_bin_scalar (colvarvalue const &value, const int i) const
 Use the lower boundary and the width to report which bin the provided value is in.
 
int value_to_bin_scalar_bound (colvarvalue const &value, const int i) const
 Use the lower boundary and the width to report which bin the provided value is in and assign first or last bin if out of boundaries.
 
int value_to_bin_scalar (colvarvalue const &value, colvarvalue const &new_offset, cvm::real const &new_width) const
 Same as the standard version, but uses another grid definition.
 
colvarvalue bin_to_value_scalar (int const &i_bin, int const i) const
 Use the two boundaries and the width to report the central value corresponding to a bin index.
 
colvarvalue bin_to_value_scalar (int const &i_bin, colvarvalue const &new_offset, cvm::real const &new_width) const
 Same as the standard version, but uses different parameters.
 
void set_value (std::vector< int > const &ix, T const &t, size_t const &imult=0)
 Set the value at the point with index ix.
 
void delta_grid (colvar_grid< T > const &other_grid)
 Get the change from this to other_grid and store the result in this. this_grid := other_grid - this_grid Grids must have the same dimensions.
 
void copy_grid (colvar_grid< T > const &other_grid)
 Copy data from another grid of the same type, AND identical definition (boundaries, widths) Added for shared ABF.
 
void raw_data_out (T *out_data) const
 Extract the grid data as they are represented in memory. Put the results in "out_data".
 
void raw_data_in (const T *in_data)
 Input the data as they are represented in memory.
 
size_t raw_data_num () const
 Size of the data as they are represented in memory.
 
T const & value (std::vector< int > const &ix, size_t const &imult=0) const
 Get the binned value indexed by ix, or the first of them if the multiplicity is larger than 1.
 
void add_constant (T const &t)
 Add a constant to all elements (fast loop)
 
void multiply_constant (cvm::real const &a)
 Multiply all elements by a scalar constant (fast loop)
 
void remove_zeros (cvm::real const &a)
 Assign all zero elements a scalar constant (fast loop)
 
std::vector< int > const get_colvars_index (std::vector< colvarvalue > const &values) const
 Get the bin indices corresponding to the provided values of the colvars.
 
std::vector< int > const get_colvars_index () const
 Get the bin indices corresponding to the current values of the colvars.
 
std::vector< int > const get_colvars_index_bound () const
 Get the bin indices corresponding to the provided values of the colvars and assign first or last bin if out of boundaries.
 
cvm::real bin_distance_from_boundaries (std::vector< colvarvalue > const &values, bool skip_hard_boundaries=false)
 Get the minimal distance (in number of bins) from the boundaries; a negative number is returned if the given point is off-grid.
 
void map_grid (colvar_grid< T > const &other_grid)
 Add data from another grid of the same type. More...
 
void add_grid (colvar_grid< T > const &other_grid, cvm::real scale_factor=1.0)
 Add data from another grid of the same type, AND identical definition (boundaries, widths)
 
virtual T value_output (std::vector< int > const &ix, size_t const &imult=0)
 Return the value suitable for output purposes (so that it may be rescaled or manipulated without changing it permanently)
 
virtual void value_input (std::vector< int > const &ix, T const &t, size_t const &imult=0, bool add=false)
 Get the value from a formatted output and transform it into the internal representation (the two may be different, e.g. when using colvar_grid_count)
 
std::vector< int > const new_index () const
 Get the index corresponding to the "first" bin, to be used as the initial value for an index in looping.
 
bool index_ok (std::vector< int > const &ix) const
 Check that the index is within range in each of the dimensions.
 
void incr (std::vector< int > &ix) const
 Increment the index, in a way that will make it loop over the whole nd-dimensional array.
 
std::ostream & write_params (std::ostream &os)
 Write the grid parameters (number of colvars, boundaries, width and number of points)
 
int parse_params (std::string const &conf, colvarparse::Parse_Mode const parse_mode=colvarparse::parse_normal)
 Read a grid definition from a config string.
 
void check_consistency ()
 Check that the grid information inside (boundaries, widths, ...) is consistent with the current setting of the colvars.
 
void check_consistency (colvar_grid< T > const &other_grid)
 Check that the grid information inside (boundaries, widths, ...) is consistent with that of another grid.
 
std::istream & read_restart (std::istream &is)
 Read grid entry in restart file.
 
std::ostream & write_restart (std::ostream &os)
 Write grid entry in restart file.
 
std::ostream & write_raw (std::ostream &os, size_t const buf_size=3)
 Write the grid data without labels, as they are represented in memory. More...
 
std::istream & read_raw (std::istream &is)
 Read data written by colvar_grid::write_raw()
 
void write_multicol (std::ostream &os)
 Write the grid in a format which is both human readable and suitable for visualization e.g. with gnuplot.
 
std::istream & read_multicol (std::istream &is, bool add=false)
 Read a grid written by colvar_grid::write_multicol() Adding data if add is true, replacing if false.
 
std::ostream & write_opendx (std::ostream &os)
 Write the grid data without labels, as they are represented in memory.
 
- Public Member Functions inherited from colvarparse
 colvarparse (const std::string &conf)
 Constructor that stores the object's config string.
 
void init ()
 Set the object ready to parse a new configuration string.
 
void init (const std::string &conf)
 Set a new config string for this object.
 
const std::string & get_config ()
 
int check_keywords (std::string &conf, char const *key)
 Check that all the keywords within "conf" are in the list of allowed keywords; this will invoke strip_values() first and then loop over all words.
 
void clear_keyword_registry ()
 Use this after parsing a config string (note that check_keywords() calls it already)
 
bool get_keyval (std::string const &conf, char const *key, int &value, int const &def_value=(int) 0, Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, size_t &value, size_t const &def_value=(size_t) 0, Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, long &value, long const &def_value=0, Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, std::string &value, std::string const &def_value=std::string(""), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, cvm::real &value, cvm::real const &def_value=(cvm::real) 0.0, Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, cvm::rvector &value, cvm::rvector const &def_value=cvm::rvector(), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, cvm::quaternion &value, cvm::quaternion const &def_value=cvm::quaternion(), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, colvarvalue &value, colvarvalue const &def_value=colvarvalue(colvarvalue::type_notset), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, bool &value, bool const &def_value=false, Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, std::vector< int > &values, std::vector< int > const &def_values=std::vector< int >(0,(int) 0), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, std::vector< size_t > &values, std::vector< size_t > const &def_values=std::vector< size_t >(0,(size_t) 0), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, std::vector< long > &values, std::vector< long > const &def_values=std::vector< long >(0,(long) 0), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, std::vector< std::string > &values, std::vector< std::string > const &def_values=std::vector< std::string >(0, std::string("")), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, std::vector< cvm::real > &values, std::vector< cvm::real > const &def_values=std::vector< cvm::real >(0,(cvm::real) 0.0), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, std::vector< cvm::rvector > &values, std::vector< cvm::rvector > const &def_values=std::vector< cvm::rvector >(0, cvm::rvector()), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, std::vector< cvm::quaternion > &values, std::vector< cvm::quaternion > const &def_values=std::vector< cvm::quaternion >(0, cvm::quaternion()), Parse_Mode const parse_mode=parse_normal)
 
bool get_keyval (std::string const &conf, char const *key, std::vector< colvarvalue > &values, std::vector< colvarvalue > const &def_values=std::vector< colvarvalue >(0, colvarvalue(colvarvalue::type_notset)), Parse_Mode const parse_mode=parse_normal)
 
bool key_lookup (std::string const &conf, char const *key, std::string *data=NULL, size_t *save_pos=NULL)
 Low-level function for parsing configuration strings; automatically adds the requested keyword to the list of valid ones. More...
 
bool brace_check (std::string const &conf, size_t const start_pos=0)
 Check if the content of the file has matching braces.
 

Public Attributes

std::vector< colvarvaluelower_boundaries
 Lower boundaries of the colvars in this grid.
 
std::vector< colvarvalueupper_boundaries
 Upper boundaries of the colvars in this grid.
 
std::vector< bool > periodic
 Whether some colvars are periodic.
 
std::vector< bool > hard_lower_boundaries
 Whether some colvars have hard lower boundaries.
 
std::vector< bool > hard_upper_boundaries
 Whether some colvars have hard upper boundaries.
 
std::vector< cvm::realwidths
 Widths of the colvars in this grid.
 
bool has_parent_data
 True if this is a count grid related to another grid of data.
 
bool has_data
 Whether this grid has been filled with data or is still empty.
 

Protected Member Functions

size_t address (std::vector< int > const &ix) const
 Get the low-level index corresponding to an index.
 
- Protected Member Functions inherited from colvarparse
template<typename TYPE >
bool _get_keyval_scalar_ (std::string const &conf, char const *key, TYPE &value, TYPE const &def_value, Parse_Mode const parse_mode)
 
bool _get_keyval_scalar_string_ (std::string const &conf, char const *key, std::string &value, std::string const &def_value, Parse_Mode const parse_mode)
 
template<typename TYPE >
bool _get_keyval_vector_ (std::string const &conf, char const *key, std::vector< TYPE > &values, std::vector< TYPE > const &def_values, Parse_Mode const parse_mode)
 

Protected Attributes

size_t nd
 Number of dimensions.
 
std::vector< int > nx
 Number of points along each dimension.
 
std::vector< int > nxc
 Cumulative number of points along each dimension.
 
size_t mult
 Multiplicity of each datum (allow the binning of non-scalar types such as atomic gradients)
 
size_t nt
 Total number of grid points.
 
std::vector< T > data
 Low-level array of values.
 
std::vector< size_t > new_data
 Newly read data (used for count grids, when adding several grids read from disk)
 
std::vector< colvar * > cv
 Colvars collected in this grid.
 
std::vector< bool > actual_value
 Do we request actual value (for extended-system colvars)?
 

Additional Inherited Members

- Public Types inherited from colvarparse
enum  Parse_Mode { parse_normal, parse_silent }
 How a keyword is parsed in a string. More...
 
- Static Public Member Functions inherited from colvarparse
static std::string to_lower_cppstr (std::string const &in)
 Return a lowercased copy of the string.
 
static std::istream & getline_nocomments (std::istream &is, std::string &s)
 Works as std::getline() but also removes everything between a comment character and the following newline.
 
- Static Public Attributes inherited from colvarparse
static const char *const white_space = " \t"
 Accepted white space delimiters, used in key_lookup()
 

Detailed Description

template<class T>
class colvar_grid< T >

Grid of values of a function of several collective variables.

Parameters
TThe data type

Only scalar colvars supported so far: vector colvars are treated as arrays

Constructor & Destructor Documentation

◆ colvar_grid()

template<class T>
colvar_grid< T >::colvar_grid ( std::vector< int > const &  nx_i,
T const &  t = T(),
size_t  mult_i = 1 
)
inline

Constructor from explicit grid sizes.

Parameters
nx_iNumber of grid points along each dimension
tInitial value for the function at each point (optional)
mult_iMultiplicity of each value

Member Function Documentation

◆ map_grid()

template<class T>
void colvar_grid< T >::map_grid ( colvar_grid< T > const &  other_grid)
inline

Add data from another grid of the same type.

Note: this function maps other_grid inside this one regardless of whether it fits or not.

◆ number_of_points()

template<class T>
size_t colvar_grid< T >::number_of_points ( int const  icv = -1) const
inline

Return the number of points in the i-th direction, if provided, or the total number

◆ wrap()

template<class T>
void colvar_grid< T >::wrap ( std::vector< int > &  ix) const
inline

Wrap an index vector around periodic boundary conditions also checks validity of non-periodic indices

◆ write_raw()

template<class T>
std::ostream& colvar_grid< T >::write_raw ( std::ostream &  os,
size_t const  buf_size = 3 
)
inline

Write the grid data without labels, as they are represented in memory.

Parameters
buf_sizeNumber of values per line

The documentation for this class was generated from the following file: