1 /************************************************************************
2  * Headers for the ABF and histogram biases                             *
3  ************************************************************************/
4 
5 #ifndef COLVARBIAS_ABF_H
6 #define COLVARBIAS_ABF_H
7 
8 #include <vector>
9 #include <list>
10 #include <sstream>
11 #include <iomanip>
12 //#include <cmath>
13 
14 #include "colvarbias.h"
15 #include "colvargrid.h"
16 
17 typedef cvm::real* gradient_t;
18 
19 
20 /// ABF bias
21 class colvarbias_abf : public colvarbias {
22 
23 public:
24 
25   colvarbias_abf (std::string const &conf, char const *key);
26   ~colvarbias_abf ();
27 
28   cvm::real update ();
29 
30 private:
31 
32   /// Filename prefix for human-readable gradient/sample count output
33   std::string	output_prefix;
34 
35   /// Base filename(s) for reading previous gradient data (replaces data from restart file)
36   std::vector<std::string> input_prefix;
37 
38   bool		apply_bias;
39   bool		update_bias;
40   bool		hide_Jacobian;
41   size_t	full_samples;
42   size_t	min_samples;
43   /// frequency for updating output files (default: same as restartFreq?)
44   int		output_freq;
45   /// Write combined files with a history of all output data?
46   bool      b_history_files;
47   size_t    history_freq;
48 
49   /// Cap applied biasing force?
50   bool                    cap_force;
51   std::vector<cvm::real>  max_force;
52 
53   // Internal data and methods
54 
55   std::vector<int>  bin, force_bin;
56   gradient_t	    force;
57 
58   /// n-dim grid of free energy gradients
59   colvar_grid_gradient  *gradients;
60   /// n-dim grid of number of samples
61   colvar_grid_count     *samples;
62 
63   /// Write human-readable FE gradients and sample count
64   void		  write_gradients_samples (const std::string &prefix, bool append = false);
65 
66   /// Read human-readable FE gradients and sample count (if not using restart)
67   void		  read_gradients_samples ();
68 
69   std::istream& read_restart  (std::istream&);
70   std::ostream& write_restart (std::ostream&);
71 };
72 
73 
74 /// Histogram "bias" (does as the name says)
75 class colvarbias_histogram : public colvarbias {
76 
77 public:
78 
79   colvarbias_histogram (std::string const &conf, char const *key);
80   ~colvarbias_histogram ();
81 
82   cvm::real update ();
83 
84 private:
85 
86   /// n-dim histogram
87   colvar_grid_count    *grid;
88   std::vector<int>  bin;
89   std::string	  out_name;
90 
91   int		  output_freq;
92   void		  write_grid ();
93   std::ofstream	  grid_os;  /// Stream for writing grid to disk
94 
95   std::istream& read_restart  (std::istream&);
96   std::ostream& write_restart (std::ostream&);
97 };
98 
99 #endif
100