1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2    Copyright (c) 2012-2021 The plumed team
3    (see the PEOPLE file at the root of the distribution for a list of names)
4 
5    See http://www.plumed.org for more information.
6 
7    This file is part of plumed, version 2.
8 
9    plumed is free software: you can redistribute it and/or modify
10    it under the terms of the GNU Lesser General Public License as published by
11    the Free Software Foundation, either version 3 of the License, or
12    (at your option) any later version.
13 
14    plumed is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU Lesser General Public License for more details.
18 
19    You should have received a copy of the GNU Lesser General Public License
20    along with plumed.  If not, see <http://www.gnu.org/licenses/>.
21 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 #ifndef __PLUMED_tools_BiasRepresentation_h
23 #define __PLUMED_tools_BiasRepresentation_h
24 
25 #include "Exception.h"
26 #include <memory>
27 #include <vector>
28 
29 namespace PLMD {
30 
31 class Value;
32 class Grid;
33 class IFile;
34 class KernelFunctions;
35 class Communicator;
36 
37 //+PLUMEDOC INTERNAL biasrepresentation
38 /*
39 
40 */
41 //+ENDPLUMEDOC
42 
43 /// this class implements a general purpose class that aims to
44 /// provide a Grid/list
45 /// transparently add gaussians to a bias
46 
47 class BiasRepresentation {
48 public:
49   /// create a bias representation from a list of pointer to values
50   BiasRepresentation(const std::vector<Value*> & tmpvalues, Communicator &cc  );
51   /// create a bias using explicit sigma in input (needed for histogram building)
52   BiasRepresentation(const std::vector<Value*> & tmpvalues, Communicator &cc,  const std::vector<double> & sigma);
53   /// create a bias containing a grid representation
54   BiasRepresentation(const std::vector<Value*> & tmpvalues, Communicator &cc, const std::vector<std::string> &  gmin, const std::vector<std::string> & gmax,
55                      const std::vector<unsigned> & nbin, bool doInt, double lowI_, double uppI_);
56   /// create a histogram with grid representation and sigmas in input
57   BiasRepresentation(const std::vector<Value*> & tmpvalues, Communicator &cc, const std::vector<std::string> & gmin, const std::vector<std::string> & gmax, const std::vector<unsigned> & nbin, const std::vector<double> & sigma);
58   /// retrieve the number of dimension of the representation
59   unsigned 	getNumberOfDimensions();
60   /// add the grid to the representation
61   void 		addGrid(const std::vector<std::string> & gmin, const std::vector<std::string> & gmax, const std::vector<unsigned> & nbin );
62   /// push a kernel on the representation (includes widths and height)
63   void 		pushKernel( IFile * ff);
64   /// set the flag that rescales the free energy to the bias
65   void 		setRescaledToBias(bool rescaled);
66   /// check if the representation is rescaled to the bias
67   const bool & 	isRescaledToBias();
68   /// check if the sigma values are already provided (in case of a histogram representation with input sigmas)
69   bool  	hasSigmaInInput();
70   /// get the names of the variables
71   std::vector<std::string> getNames();
72   /// get the pointer to the values
73   const std::vector<Value*> & getPtrToValues();
74   /// get the number of kernels contained in the representation
75   int 		getNumberOfKernels();
76   /// get the name of the i-th value
77   const std::string & getName(unsigned i);
78   /// get a pointer to a specific value
79   Value* 	getPtrToValue(unsigned i);
80   /// get the pointer to the grid
81   Grid* 	getGridPtr();
82   /// get a new histogram point from a file
83   std::unique_ptr<KernelFunctions> readFromPoint(IFile *ifile);
84   /// get an automatic min/max from the set so to know how to configure the grid
85   void getMinMaxBin(std::vector<double> &vmin, std::vector<double> &vmax, std::vector<unsigned> &vbin);
86   /// clear the representation (grid included)
87   void clear();
88 private:
89   int ndim;
90   bool hasgrid;
91   bool rescaledToBias;
92   bool doInt_;
93   double lowI_;
94   double uppI_;
95   std::vector<Value*> values;
96   std::vector<std::string> names;
97   std::vector<std::unique_ptr<KernelFunctions>> hills;
98   std::vector<double> biasf;
99   std::vector<double> histosigma;
100   Communicator& mycomm;
101   std::unique_ptr<Grid> BiasGrid_;
102 };
103 
104 }
105 
106 #endif
107