version 1.20 | version 1.21 |
---|
| |
/// -*- c++ -*- | // -*- c++ -*- |
| |
#ifndef COLVARMODULE_H | #ifndef COLVARMODULE_H |
#define COLVARMODULE_H | #define COLVARMODULE_H |
| |
#ifndef COLVARS_VERSION | #ifndef COLVARS_VERSION |
#define COLVARS_VERSION "2015-09-16" | #define COLVARS_VERSION "2016-10-06" |
#endif | #endif |
| |
#ifndef COLVARS_DEBUG | #ifndef COLVARS_DEBUG |
#define COLVARS_DEBUG false | #define COLVARS_DEBUG false |
#endif | #endif |
| |
| /*! \mainpage Main page |
| */ |
| |
/// \file colvarmodule.h | /// \file colvarmodule.h |
/// \brief Collective variables main module | /// \brief Collective variables main module |
/// | /// |
| |
/// shared between all object instances) to be accessed from other | /// shared between all object instances) to be accessed from other |
/// objects. | /// objects. |
| |
// Internal method return codes | |
#define COLVARS_NOT_IMPLEMENTED -2 | |
#define COLVARS_ERROR -1 | |
#define COLVARS_OK 0 | #define COLVARS_OK 0 |
| #define COLVARS_ERROR 1 |
// On error, values of the colvars module error register | #define COLVARS_NOT_IMPLEMENTED (1<<1) |
#define GENERAL_ERROR 1 | #define INPUT_ERROR (1<<2) // out of bounds or inconsistent input |
#define FILE_ERROR (1<<1) | |
#define MEMORY_ERROR (1<<2) | |
#define BUG_ERROR (1<<3) // Inconsistent state indicating bug | #define BUG_ERROR (1<<3) // Inconsistent state indicating bug |
#define INPUT_ERROR (1<<4) // out of bounds or inconsistent input | #define FILE_ERROR (1<<4) |
#define DELETE_COLVARS (1<<5) // Instruct the caller to delete cvm | #define MEMORY_ERROR (1<<5) |
#define FATAL_ERROR (1<<6) // Should be set, or not, together with other bits | #define FATAL_ERROR (1<<6) // Should be set, or not, together with other bits |
| #define DELETE_COLVARS (1<<7) // Instruct the caller to delete cvm |
| #define COLVARS_NO_SUCH_FRAME (1<<8) // Cannot load the requested frame |
| |
#include <iostream> | #include <iostream> |
#include <iomanip> | #include <iomanip> |
| |
| |
/// Module-wide error state | /// Module-wide error state |
/// see constants at the top of this file | /// see constants at the top of this file |
| protected: |
| |
static int errorCode; | static int errorCode; |
static inline void set_error_bits(int code) | |
{ | public: |
errorCode |= code; | |
} | static void set_error_bits(int code); |
| |
| static bool get_error_bit(int code); |
| |
static inline int get_error() | static inline int get_error() |
{ | { |
return errorCode; | return errorCode; |
} | } |
static inline void clear_error() | |
{ | static void clear_error(); |
errorCode = 0; | |
} | |
| |
/// Current step number | /// Current step number |
static long it; | static long it; |
| |
/// Prefix for all output files for this run | /// Prefix for all output files for this run |
static std::string output_prefix; | static std::string output_prefix; |
| |
/// input restart file name (determined from input_prefix) | |
static std::string restart_in_name; | |
| |
| |
/// Array of collective variables | /// Array of collective variables |
static std::vector<colvar *> colvars; | static std::vector<colvar *> colvars; |
| |
} | } |
*/ | */ |
| |
| /// Collective variables to be calculated on different threads; |
| /// colvars with multple items (e.g. multiple active CVCs) are duplicated |
| std::vector<colvar *> colvars_smp; |
| /// Indexes of the items to calculate for each colvar |
| std::vector<int> colvars_smp_items; |
| |
/// Array of collective variable biases | /// Array of collective variable biases |
static std::vector<colvarbias *> biases; | static std::vector<colvarbias *> biases; |
/// \brief Number of ABF biases initialized (in normal conditions | /// \brief Number of ABF biases initialized (in normal conditions |
| |
return COLVARS_DEBUG; | return COLVARS_DEBUG; |
} | } |
| |
| /// \brief How many objects are configured yet? |
| inline size_t const size() const |
| { |
| return colvars.size() + biases.size(); |
| } |
| |
/// \brief Constructor \param config_name Configuration file name | /// \brief Constructor \param config_name Configuration file name |
/// \param restart_name (optional) Restart file name | /// \param restart_name (optional) Restart file name |
| |
/// on error, delete new bias | /// on error, delete new bias |
bool check_new_bias(std::string &conf, char const *key); | bool check_new_bias(std::string &conf, char const *key); |
| |
| private: |
| /// Useful wrapper to interrupt parsing if any error occurs |
| int catch_input_errors(int result); |
| |
| public: |
| |
// "Setup" functions (change internal data based on related data | // "Setup" functions (change internal data based on related data |
// from the proxy that may change during program execution) | // from the proxy that may change during program execution) |
// No additional parsing is done within these functions | // No additional parsing is done within these functions |
| |
/// Write explanatory labels in the trajectory file | /// Write explanatory labels in the trajectory file |
std::ostream & write_traj_label(std::ostream &os); | std::ostream & write_traj_label(std::ostream &os); |
| |
| /// Write all trajectory files |
| int write_traj_files(); |
| /// Write all restart files |
| int write_restart_files(); |
/// Write all FINAL output files | /// Write all FINAL output files |
int write_output_files(); | int write_output_files(); |
/// Backup a file before writing it | /// Backup a file before writing it |
| |
//// Share among replicas. | //// Share among replicas. |
int bias_share(std::string const &bias_name); | int bias_share(std::string const &bias_name); |
| |
/// Calculate collective variables and biases | /// Main worker function |
int calc(); | int calc(); |
| |
| /// Calculate collective variables |
| int calc_colvars(); |
| |
| /// Calculate biases |
| int calc_biases(); |
| |
| /// Integrate bias and restraint forces, send colvar forces to atoms |
| int update_colvar_forces(); |
| |
/// Perform analysis | /// Perform analysis |
int analyze(); | int analyze(); |
| |
/// \brief Read a collective variable trajectory (post-processing | /// \brief Read a collective variable trajectory (post-processing |
/// only, not called at runtime) | /// only, not called at runtime) |
int read_traj(char const *traj_filename, | int read_traj(char const *traj_filename, |
| |
/// \brief Time step of MD integrator (fs) | /// \brief Time step of MD integrator (fs) |
static real dt(); | static real dt(); |
| |
/// Request calculation of system force from MD engine | /// Request calculation of total force from MD engine |
static void request_system_force(); | static void request_total_force(); |
| |
/// Print a message to the main log | /// Print a message to the main log |
static void log(std::string const &message); | static void log(std::string const &message); |
| |
static void fatal_error(std::string const &message); | static void fatal_error(std::string const &message); |
| |
/// Print a message to the main log and set global error code | /// Print a message to the main log and set global error code |
static void error(std::string const &message, int code = GENERAL_ERROR); | static void error(std::string const &message, int code = COLVARS_ERROR); |
| |
/// Print a message to the main log and exit normally | /// Print a message to the main log and exit normally |
static void exit(std::string const &message); | static void exit(std::string const &message); |
| |
/// \param pdb_field (optiona) if "filename" is a PDB file, use this | /// \param pdb_field (optiona) if "filename" is a PDB file, use this |
/// field to determine which are the atoms to be set | /// field to determine which are the atoms to be set |
static int load_atoms(char const *filename, | static int load_atoms(char const *filename, |
std::vector<atom> &atoms, | atom_group &atoms, |
std::string const &pdb_field, | std::string const &pdb_field, |
double const pdb_field_value = 0.0); | double const pdb_field_value = 0.0); |
| |
| |
/// Output restart file | /// Output restart file |
colvarmodule::ofstream restart_out_os; | colvarmodule::ofstream restart_out_os; |
| |
/// \brief Counter for the current depth in the object hierarchy (useg e.g. in output | protected: |
static size_t depth; | |
| |
/// Use scripted colvars forces? | /// Counter for the current depth in the object hierarchy (useg e.g. in output) |
static bool use_scripted_forces; | static size_t depth_s; |
| |
| /// Thread-specific depth |
| static std::vector<size_t> depth_v; |
| |
public: | public: |
| |
/// \brief Pointer to the proxy object, used to retrieve atomic data | /// Get the current object depth in the hierarchy |
/// from the hosting program; it is static in order to be accessible | static size_t & depth(); |
/// from static functions in the colvarmodule class | |
static colvarproxy *proxy; | |
| |
/// Increase the depth (number of indentations in the output) | /// Increase the depth (number of indentations in the output) |
static void increase_depth(); | static void increase_depth(); |
| |
/// Decrease the depth (number of indentations in the output) | /// Decrease the depth (number of indentations in the output) |
static void decrease_depth(); | static void decrease_depth(); |
| |
static inline bool scripted_forces() { return use_scripted_forces; } | static inline bool scripted_forces() |
| { |
| return use_scripted_forces; |
| } |
| |
| /// Use scripted colvars forces? |
| static bool use_scripted_forces; |
| |
| /// Wait for all biases before calculating scripted forces? |
| static bool scripting_after_biases; |
| |
| /// Calculate the energy and forces of scripted biases |
| int calc_scripted_forces(); |
| |
| /// \brief 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 |
| static colvarproxy *proxy; |
}; | }; |
| |
| |
| |
} | } |
| |
| |
inline void cvm::request_system_force() | inline void cvm::request_total_force() |
{ | { |
proxy->request_system_force(true); | proxy->request_total_force(true); |
} | } |
| |
inline void cvm::select_closest_image(atom_pos &pos, | inline void cvm::select_closest_image(atom_pos &pos, |