Collective Variables Module - Developer Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Attributes | Static Protected Attributes | Friends | List of all members
colvarmodule Class Reference

Collective variables module (main class) More...

#include <colvarmodule.h>

Collaboration diagram for colvarmodule:
Collaboration graph
[legend]

Classes

class  atom
 Stores numeric id, mass and all mutable data for an atom, mostly used by a cvc. More...
 
class  atom_group
 Group of atom objects, mostly used by a cvc object to gather all atomic data. More...
 
class  matrix2d
 Arbitrary size array (two dimensions) suitable for linear algebra operations (i.e. for floating point numbers it can be used with library functions) More...
 
class  quaternion
 1-dimensional vector of real numbers with four components and a quaternion algebra More...
 
class  rmatrix
 2-dimensional array of real numbers with three components along each dimension (works with colvarmodule::rvector) More...
 
class  rotation
 A rotation between two sets of coordinates (for the moment a wrapper for colvarmodule::quaternion) More...
 
class  rvector
 vector of real numbers with three components More...
 
class  vector1d
 Arbitrary size array (one dimensions) suitable for linear algebra operations (i.e. for floating point numbers it can be used with library functions) More...
 

Public Types

typedef double real
 Defining an abstract real number allows to switch precision.
 
typedef int residue_id
 Residue identifier.
 
typedef rvector atom_pos
 Atom position (different type name from rvector, to make possible future PBC-transparent implementations)
 
typedef std::vector< atom >
::iterator 
atom_iter
 
typedef std::vector< atom >
::const_iterator 
atom_const_iter
 
typedef std::ofstream ofstream
 

Public Member Functions

std::vector< colvar * > * variables ()
 Array of collective variables.
 
std::vector< colvar * > * variables_active ()
 Collective variables with the active flag on.
 
std::vector< colvar * > * variables_active_smp ()
 
std::vector< int > * variables_active_smp_items ()
 Indexes of the items to calculate for each colvar.
 
std::vector< colvarbias * > * biases_active ()
 Array of active collective variable biases.
 
size_t size () const
 How many objects are configured yet?
 
 colvarmodule (colvarproxy *proxy)
 Constructor. More...
 
 ~colvarmodule ()
 Destructor.
 
int reset ()
 Actual function called by the destructor.
 
int read_config_file (char const *config_file_name)
 Open a config file, load its contents, and pass it to config_string()
 
int read_config_string (std::string const &conf)
 Parse a config string assuming it is a complete configuration (i.e. calling all parse functions)
 
int parse_config (std::string &conf)
 Parse a "clean" config string (no comments)
 
int parse_global_params (std::string const &conf)
 Parse the few module's global parameters.
 
int parse_colvars (std::string const &conf)
 Parse and initialize collective variables.
 
int parse_biases (std::string const &conf)
 Parse and initialize collective variable biases. More...
 
int append_new_config (std::string const &conf)
 Add new configuration during parsing (e.g. to implement back-compatibility); cannot be nested, i.e. conf should not contain anything that triggers another call.
 
int setup ()
 
int setup_input ()
 (Re)initialize and (re)read the input state file calling read_restart()
 
int setup_output ()
 (Re)initialize the output trajectory and state file (does not write it yet)
 
std::istream & read_restart (std::istream &is)
 Read the input restart file.
 
std::ostream & write_restart (std::ostream &os)
 Write the output restart file.
 
int open_traj_file (std::string const &file_name)
 Open a trajectory file if requested (and leave it open)
 
int close_traj_file ()
 Close it.
 
std::ostream & write_traj (std::ostream &os)
 Write in the trajectory file.
 
std::ostream & write_traj_label (std::ostream &os)
 Write explanatory labels in the trajectory file.
 
int write_traj_files ()
 Write all trajectory files.
 
int write_restart_files ()
 Write all restart files.
 
int write_output_files ()
 Write all FINAL output files.
 
int change_configuration (std::string const &bias_name, std::string const &conf)
 
std::string read_colvar (std::string const &name)
 Read a colvar value.
 
real energy_difference (std::string const &bias_name, std::string const &conf)
 
int bias_bin_num (std::string const &bias_name)
 Give the total number of bins for a given bias.
 
int bias_current_bin (std::string const &bias_name)
 Calculate the bin index for a given bias.
 
int bias_bin_count (std::string const &bias_name, size_t bin_index)
 
int bias_share (std::string const &bias_name)
 
int calc ()
 Main worker function.
 
int calc_colvars ()
 Calculate collective variables.
 
int calc_biases ()
 Calculate biases.
 
int update_colvar_forces ()
 Integrate bias and restraint forces, send colvar forces to atoms.
 
int analyze ()
 Perform analysis.
 
int read_traj (char const *traj_filename, long traj_read_begin, long traj_read_end)
 Read a collective variable trajectory (post-processing only, not called at runtime)
 
int read_index_file (char const *filename)
 Read a Gromacs .ndx file.
 
int calc_scripted_forces ()
 Calculate the energy and forces of scripted biases.
 

Static Public Member Functions

static void set_error_bits (int code)
 
static bool get_error_bit (int code)
 
static int get_error ()
 
static void clear_error ()
 
static long step_relative ()
 Return the current step number from the beginning of this run.
 
static long step_absolute ()
 
static std::string & output_prefix ()
 Accessor for the above.
 
static bool debug ()
 Whether debug output should be enabled (compile-time option)
 
static std::istream & getline (std::istream &is, std::string &line)
 
static int num_biases_feature (int feature_id)
 Return how many biases have this feature enabled.
 
static int num_biases_type (std::string const &type)
 Return how many biases are defined with this type.
 
static int backup_file (char const *filename)
 Backup a file before writing it.
 
static colvarbiasbias_by_name (std::string const &name)
 Look up a bias by name; returns NULL if not found.
 
static colvarcolvar_by_name (std::string const &name)
 Look up a colvar by name; returns NULL if not found.
 
template<typename T >
static std::string to_str (T const &x, size_t const &width=0, size_t const &prec=0)
 Quick conversion of an object to a string.
 
template<typename T >
static std::string to_str (std::vector< T > const &x, size_t const &width=0, size_t const &prec=0)
 Quick conversion of a vector of objects to a string.
 
static std::string wrap_string (std::string const &s, size_t const &nchars)
 Reduce the number of characters in a string.
 
static real unit_angstrom ()
 Value of the unit for atomic coordinates with respect to angstroms (used by some variables for hard-coded default values)
 
static real boltzmann ()
 Boltmann constant.
 
static real temperature ()
 Temperature of the simulation (K)
 
static real dt ()
 Time step of MD integrator (fs)
 
static void request_total_force ()
 Request calculation of total force from MD engine.
 
static void log (std::string const &message)
 Print a message to the main log.
 
static void fatal_error (std::string const &message)
 Print a message to the main log and exit with error code.
 
static void error (std::string const &message, int code=COLVARS_ERROR)
 Print a message to the main log and set global error code.
 
static void exit (std::string const &message)
 Print a message to the main log and exit normally.
 
static bool replica_enabled ()
 
static int replica_index ()
 
static int replica_num ()
 
static void replica_comm_barrier ()
 
static int replica_comm_recv (char *msg_data, int buf_len, int src_rep)
 
static int replica_comm_send (char *msg_data, int msg_len, int dest_rep)
 
static rvector position_distance (atom_pos const &pos1, atom_pos const &pos2)
 Get the distance between two atomic positions with pbcs handled correctly.
 
static real position_dist2 (atom_pos const &pos1, atom_pos const &pos2)
 Get the square distance between two positions (with periodic boundary conditions handled transparently) More...
 
static void select_closest_image (atom_pos &pos, atom_pos const &ref_pos)
 Get the closest periodic image to a reference position. More...
 
static void select_closest_images (std::vector< atom_pos > &pos, atom_pos const &ref_pos)
 Perform select_closest_image() on a set of atomic positions. More...
 
static int load_atoms (char const *filename, atom_group &atoms, std::string const &pdb_field, double const pdb_field_value=0.0)
 Create atoms from a file. More...
 
static int load_coords (char const *filename, std::vector< atom_pos > &pos, const std::vector< int > &indices, std::string const &pdb_field, double const pdb_field_value=0.0)
 Load the coordinates for a group of atoms from a file (PDB or XYZ)
 
static int load_coords_xyz (char const *filename, std::vector< atom_pos > &pos, const std::vector< int > &indices)
 Load the coordinates for a group of atoms from an XYZ file.
 
static real rand_gaussian (void)
 Pseudo-random number with Gaussian distribution.
 
static size_t & depth ()
 Get the current object depth in the hierarchy.
 
static void increase_depth ()
 Increase the depth (number of indentations in the output)
 
static void decrease_depth ()
 Decrease the depth (number of indentations in the output)
 
static bool scripted_forces ()
 
static colvarmodulemain ()
 Accessor for the above.
 

Public Attributes

bool it_restart_from_state_file
 
std::vector< colvarbias * > biases
 Array of collective variable biases.
 
real total_bias_energy
 Energy of built-in and scripted biases, summed per time-step.
 
std::list< std::string > index_group_names
 Names of groups from a Gromacs .ndx file to be read at startup.
 
std::list< std::vector< int > > index_groups
 Groups from a Gromacs .ndx file read at startup.
 
std::string restart_out_name
 Output restart file name.
 

Static Public Attributes

static long it = 0
 Current step number.
 
static long it_restart = 0
 Starting step number for this run.
 
static real debug_gradients_step_size = 1.0e-07
 Finite difference step size (if there is no dynamics, or if gradients need to be tested independently from the size of dt)
 
static size_t const it_width = 12
 Number of characters to represent a time step.
 
static size_t const cv_prec = 14
 Number of digits to represent a collective variables value(s)
 
static size_t const cv_width = 21
 Number of characters to represent a collective variables value(s)
 
static size_t const en_prec = 14
 Number of digits to represent the collective variables energy.
 
static size_t const en_width = 21
 Number of characters to represent the collective variables energy.
 
static const char *const line_marker
 Line separator in the log output. More...
 
static size_t cv_traj_freq = 0
 Frequency for collective variables trajectory output.
 
static bool b_analysis = false
 True if only analysis is performed and not a run.
 
static size_t restart_out_freq = 0
 Frequency for saving output restarts.
 
static bool use_scripted_forces = false
 Use scripted colvars forces?
 
static bool scripting_after_biases = true
 Wait for all biases before calculating scripted forces?
 
static colvarproxyproxy = NULL
 Pointer to the proxy object, used to retrieve atomic data from the hosting program; it is static in order to be accessible from static functions in the colvarmodule class.
 

Protected Attributes

std::ifstream config_s
 Configuration file.
 
colvarparseparse
 Configuration file parser object.
 
std::string cv_traj_name
 Name of the trajectory file.
 
colvarmodule::ofstream cv_traj_os
 Collective variables output trajectory file.
 
bool cv_traj_append
 Appending to the existing trajectory file?
 
colvarmodule::ofstream restart_out_os
 Output restart file.
 

Static Protected Attributes

static int errorCode = 0
 

Friends

class colvarproxy
 
class colvarscript
 
class atom
 
class atom_group
 

Detailed Description

Collective variables module (main class)

Class to control the collective variables calculation. An object (usually one) of this class is spawned from the MD program, containing all i/o routines and general interface.

At initialization, the colvarmodule object creates a proxy object to provide a transparent interface between the MD program and the child objects

Constructor & Destructor Documentation

colvarmodule::colvarmodule ( colvarproxy proxy)

Constructor.

Parameters
config_nameConfiguration file name
restart_name(optional) Restart file name

Member Function Documentation

int colvarmodule::change_configuration ( std::string const &  bias_name,
std::string const &  conf 
)

Load new configuration for the given bias - currently works for harmonic (force constant and/or centers)

cvm::real colvarmodule::energy_difference ( std::string const &  bias_name,
std::string const &  conf 
)

Calculate change in energy from using alt. config. for the given bias - currently works for harmonic (force constant and/or centers)

std::istream & colvarmodule::getline ( std::istream &  is,
std::string &  line 
)
static

Allow reading from Windows text files using using std::getline (which can still be used when the text is produced by Colvars itself)

int cvm::load_atoms ( char const *  filename,
cvm::atom_group atoms,
std::string const &  pdb_field,
double const  pdb_field_value = 0.0 
)
static

Create atoms from a file.

Parameters
filenamename of the file (usually a PDB)
atomsarray of the atoms to be allocated
pdb_field(optiona) if "filename" is a PDB file, use this field to determine which are the atoms to be set
int colvarmodule::parse_biases ( std::string const &  conf)

Parse and initialize collective variable biases.

initialize ABF instances

initialize adaptive linear biases

initialize harmonic restraints

initialize harmonic walls restraints

initialize histograms

initialize histogram restraints

initialize linear restraints

initialize metadynamics instances

cvm::real cvm::position_dist2 ( cvm::atom_pos const &  pos1,
cvm::atom_pos const &  pos2 
)
inlinestatic

Get the square distance between two positions (with periodic boundary conditions handled transparently)

Note: in the case of periodic boundary conditions, this provides an analytical square distance (while taking the square of position_distance() would produce leads to a cusp)

void cvm::select_closest_image ( atom_pos pos,
atom_pos const &  ref_pos 
)
inlinestatic

Get the closest periodic image to a reference position.

Parameters
posThe position to look for the closest periodic image
ref_pos(optional) The reference position
void cvm::select_closest_images ( std::vector< atom_pos > &  pos,
atom_pos const &  ref_pos 
)
inlinestatic

Perform select_closest_image() on a set of atomic positions.

After that, distance vectors can then be calculated directly, without using position_distance()

int colvarmodule::setup ( )

(Re)initialize internal data (currently used by LAMMPS) Also calls setup() member functions of colvars and biases

static long colvarmodule::step_absolute ( )
inlinestatic

Return the current step number from the beginning of the whole calculation

std::vector< colvar * > * colvarmodule::variables_active_smp ( )

Collective variables to be calculated on different threads; colvars with multple items (e.g. multiple active CVCs) are duplicated

Member Data Documentation

int colvarmodule::errorCode = 0
staticprotected

Module-wide error state see constants at the top of this file

bool colvarmodule::it_restart_from_state_file

If true, get it_restart from the state file; if set to false, the MD program is providing it

const char *const colvarmodule::line_marker
static
Initial value:
= (const char *)
"----------------------------------------------------------------------\n"

Line separator in the log output.


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