Files
lammps/lib/colvars/colvarproxy_io.h
Giacomo Fiorin cba479bf6e Update Colvars library to version 2025-04-18
The following is a list of pull requests relevant to LAMMPS in the Colvars repository since 2024-08-06:

- 752 New tool poisson_integrator_conv
  https://github.com/Colvars/colvars/pull/752 (@jhenin)

- 733 Custom grids for all biases
  https://github.com/Colvars/colvars/pull/733 (@giacomofiorin, @jhenin)

- 776 Avoid error in acos and asin with fast-math
  https://github.com/Colvars/colvars/pull/776 (@jhenin)

- 773 fix: fix the clang build test failure of OPES
  https://github.com/Colvars/colvars/pull/773 (@HanatoK)

- 768 fix: clamp the input values of asin and acos in case of fast math on aarch64
  https://github.com/Colvars/colvars/pull/768 (@HanatoK)

- 761 Add debug code for the Jacobi failure
  https://github.com/Colvars/colvars/pull/761 (@HanatoK)

- 759 min_image fix; Saves long runs from crashes;
  https://github.com/Colvars/colvars/pull/759 (@PolyachenkoYA)

- 757 Fix MSVC OpenMP issue
  https://github.com/Colvars/colvars/pull/757 (@HanatoK)

- 755 Fix indentation of 'Init CVC' message in standard output
  https://github.com/Colvars/colvars/pull/755 (@jhenin)

- 750 Optimize and simplify the calculation of dihedral gradients
  https://github.com/Colvars/colvars/pull/750 (@HanatoK)

- 749 Add references to new Colvars paper
  https://github.com/Colvars/colvars/pull/749 (@jhenin, @giacomofiorin)

- 740 Report the specific C++ standard at init time, stop warning about C++97/03
  https://github.com/Colvars/colvars/pull/740 (@giacomofiorin)

- 731 Improve detection of hard/mathematical boundaries
  https://github.com/Colvars/colvars/pull/731 (@giacomofiorin)

- 729 Optimize the fit gradients
  https://github.com/Colvars/colvars/pull/729 (@HanatoK, @jhenin)

- 728 Fix undefined behavior when getting the current working directory from std::filesystem
  https://github.com/Colvars/colvars/pull/728 (@giacomofiorin)

- 727 Add patchversion scripting command
  https://github.com/Colvars/colvars/pull/727 (@giacomofiorin)

- 724 Fix gradients and metric functions of distanceDir
  https://github.com/Colvars/colvars/pull/724 (@giacomofiorin)

- 715 Add missing rotation in orientation component
  https://github.com/Colvars/colvars/pull/715 (@giacomofiorin)

- 713 fix: try to solve #87 for non-scala components
  https://github.com/Colvars/colvars/pull/713 (@HanatoK)

- 709 Implementation of OPES in Colvars
  https://github.com/Colvars/colvars/pull/709 (@HanatoK, @giacomofiorin, @jhenin)

- 706 BUGFIX for Segmentation fault in colvarbias_meta::calc_energy() with useGrids off
  https://github.com/Colvars/colvars/pull/706 (@alphataubio)

- 570 enable use of CVs defined by PyTorch neural network models
  https://github.com/Colvars/colvars/pull/570 (@zwpku, @giacomofiorin, @HanatoK, @jhenin)

Authors: @alphataubio, @EzryStIago, @giacomofiorin, @HanatoK, @jhenin, @PolyachenkoYA, @zwpku
2025-04-30 15:32:30 -04:00

195 lines
6.4 KiB
C++

// -*- c++ -*-
// This file is part of the Collective Variables module (Colvars).
// The original version of Colvars and its updates are located at:
// https://github.com/Colvars/colvars
// Please update all Colvars source files before making any changes.
// If you wish to distribute your changes, please submit them to the
// Colvars repository at GitHub.
#ifndef COLVARPROXY_IO_H
#define COLVARPROXY_IO_H
#include <iosfwd>
#include <list>
#include <map>
#include <string>
/// Methods for data input/output
class colvarproxy_io {
public:
/// Constructor
colvarproxy_io();
/// Destructor
virtual ~colvarproxy_io();
/// Ensure that we're on the main thread (derived class will do actual check)
virtual bool io_available();
/// \brief Save the current frame number in the argument given
// Returns error code
virtual int get_frame(long int &);
/// \brief Set the current frame number (as well as colvarmodule::it)
// Returns error code
virtual int set_frame(long int);
/// Get the current working directory of this process
std::string get_current_work_dir() const;
/// Join two paths using the operating system's path separation
std::string join_paths(std::string const &path1, std::string const &path2) const;
/// \brief Rename the given file, before overwriting it
virtual int backup_file(char const *filename);
/// \brief Rename the given file, before overwriting it
inline int backup_file(std::string const &filename)
{
return backup_file(filename.c_str());
}
/// Remove the given file (on Windows only, rename to filename.old)
virtual int remove_file(char const *filename);
/// Remove the given file (on Windows only, rename to filename.old)
inline int remove_file(std::string const &filename)
{
return remove_file(filename.c_str());
}
/// Rename the given file
virtual int rename_file(char const *filename, char const *newfilename);
/// Rename the given file
inline int rename_file(std::string const &filename,
std::string const &newfilename)
{
return rename_file(filename.c_str(), newfilename.c_str());
}
/// Prefix of the input state file to be read next
inline std::string const & input_prefix() const
{
return input_prefix_str;
}
/// Initialize input_prefix (NOTE: it will be erased after state file is read)
virtual int set_input_prefix(std::string const &prefix);
/// Default prefix to be used for all output files (final configuration)
inline std::string const & output_prefix() const
{
return output_prefix_str;
}
/// Set default output prefix
virtual int set_output_prefix(std::string const &prefix);
/// Prefix of the restart (checkpoint) file to be written next
inline std::string const & restart_output_prefix() const
{
return restart_output_prefix_str;
}
/// Set default restart state file prefix
virtual int set_restart_output_prefix(std::string const &prefix);
/// Default restart frequency (as set by the simulation engine)
inline int default_restart_frequency() const
{
return restart_frequency_engine;
}
/// Communicate/set the restart frequency of the simulation engine
virtual int set_default_restart_frequency(int freq);
// The input stream functions below are not virtual, because they currently
// rely on the fact that either std::ifstream or std::istringstream is used
/// Returns a reference to given input stream, creating it if needed
/// \param input_name File name (later only a handle)
/// \param description Purpose of the file
/// \param error_on_fail Raise error when failing to open (allow testing)
std::istream & input_stream(std::string const &input_name,
std::string const description = "file/channel",
bool error_on_fail = true);
/// Returns a reference to given input stream, creating it if needed
/// \param input_name Identifier of the input stream
/// \param content Set this string as the stream's buffer
/// \param description Purpose of the stream
std::istream & input_stream_from_string(std::string const &input_name,
std::string const &content,
std::string const description = "string");
/// Check if the file/channel is open (without opening it if not)
bool input_stream_exists(std::string const &input_name);
/// Closes the given input stream
int close_input_stream(std::string const &input_name);
/// Closes all input streams
int close_input_streams();
/// Same as close_input_stream(), but also removes the corresponding entry from memory
int delete_input_stream(std::string const &input_name);
/// List all input streams that were opened at some point
std::list<std::string> list_input_stream_names() const;
/// Returns a reference to the named output file/channel (open it if needed)
/// \param output_name File name or identifier
/// \param description Purpose of the file
virtual std::ostream &output_stream(std::string const &output_name,
std::string const description);
/// Check if the file/channel is open (without opening it if not)
virtual bool output_stream_exists(std::string const &output_name);
/// Flushes the given output file/channel
virtual int flush_output_stream(std::string const &output_name);
/// Flushes all output files/channels
virtual int flush_output_streams();
/// Closes the given output file/channel
virtual int close_output_stream(std::string const &output_name);
/// Close all open files/channels to prevent data loss
virtual int close_output_streams();
protected:
/// Prefix of the input state file to be read next
std::string input_prefix_str;
/// Default prefix to be used for all output files (final configuration)
std::string output_prefix_str;
/// Prefix of the restart (checkpoint) file to be written next
std::string restart_output_prefix_str;
/// How often the simulation engine will write its own restart
int restart_frequency_engine;
/// Container of input files/channels indexed by path name
std::map<std::string, std::istream *> input_streams_;
/// Object whose reference is returned when read errors occur
std::istream *input_stream_error_;
/// Currently open output files/channels
std::map<std::string, std::ostream *> output_streams_;
/// Object whose reference is returned when write errors occur
std::ostream *output_stream_error_;
};
#endif