All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Analysis.h
Go to the documentation of this file.
1 /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2  Copyright (c) 2013 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-code.org for more information.
6 
7  This file is part of plumed, version 2.0.
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_analysis_Analysis_h
23 #define __PLUMED_analysis_Analysis_h
24 
25 #include "core/ActionPilot.h"
26 #include "core/ActionWithArguments.h"
27 
28 #define PLUMED_ANALYSIS_INIT(ao) Action(ao),Analysis(ao)
29 
30 namespace PLMD {
31 namespace analysis {
32 
33 /**
34 \ingroup INHERIT
35 This is the abstract base class to use for implementing new methods for analyzing the trajectory, within it there
36 is information as to how to go about implementing a new analysis method.
37 
38 */
39 
40 class Analysis :
41  public ActionPilot,
42  public ActionWithArguments
43  {
44 private:
45 /// Are we running only once for the whole trajectory
46  bool single_run;
47 /// Are we treating each block of data separately
48  bool nomemory;
49 /// Are we writing a checkpoint file
50  bool write_chq;
51 /// Are we reusing data stored by another analysis action
53 /// If we are reusing data are we ignoring the reweighting in that data
55 /// The Analysis action that we are reusing data from
57 /// The frequency with which we are performing analysis
58  unsigned freq;
59 /// Number of data point we need to run analysis
60  unsigned ndata;
61 /// The temperature at which we are running the calculation
62  double simtemp;
63 /// The temperature at which we want the histogram
64  double rtemp;
65 /// Do we need the energy (are we reweighting at a different temperature)
66  bool needeng;
67 /// The biases we are using in reweighting and the args we store them separately
68  std::vector<Value*> biases;
69 /// The piece of data we are inserting
70  unsigned idata;
71 /// Tempory vector to store values of arguments
72  std::vector<double> args;
73 /// The data we are going to analyze
74  std::vector<std::vector<double> > data;
75 /// The weights of all the data points
76  std::vector<double> logweights, weights;
77 /// Have we analyzed the data for the first time
79 /// The value of the old normalization constant
80  double norm, old_norm;
81 /// The format to use in output files
82  std::string ofmt;
83 /// The checkpoint file
85 /// Read in data from a file
86  void readDataFromFile( const std::string& filename );
87 /// This retrieves the value of norm from the analysis action.
88 /// It is only used to transfer data from one analysis action to
89 /// another. You should never need to use it. If you think you need it
90 /// you probably need getNormalization()
91  double retrieveNorm() const ;
92 protected:
93 /// This is used to read in output file names for analysis methods. When
94 /// this method is used and the calculation is not restarted old analysis
95 /// files are backed up.
96  void parseOutputFile( const std::string& key, std::string& filename );
97 /// Return the number of arguments (this overwrites the one in ActionWithArguments)
98  unsigned getNumberOfArguments() const;
99 /// Return the number of data points
100  unsigned getNumberOfDataPoints() const;
101 /// Retrieve the ith point
102  void getDataPoint( const unsigned& idata, std::vector<double>& point, double& weight ) const ;
103 /// Returns true if argument i is periodic together with the domain
104  bool getPeriodicityInformation(const unsigned& i, std::string& dmin, std::string& dmax);
105 /// Return the normalization constant
106  double getNormalization() const;
107 /// Are we analyzing each data block separately (if we are not this also returns the old normalization )
108  bool usingMemory() const;
109 /// Convert the stored log weights to proper weights
110  void finalizeWeights( const bool& ignore_weights );
111 /// Overwrite ActionWithArguments getArguments() so that we don't return
112 /// the bias
113  std::vector<Value*> getArguments();
114 /// Return the format to use for numbers in output files
115  std::string getOutputFormat() const ;
116 public:
117  static void registerKeywords( Keywords& keys );
118  Analysis(const ActionOptions&);
119  ~Analysis();
120  void prepare();
121  void calculate();
122  void update();
123  void accumulate();
124  virtual void performAnalysis()=0;
125  void apply(){}
126  void runFinalJobs();
127  void runAnalysis();
128 };
129 
130 inline
132  if( !reusing_data ){
133  plumed_dbg_assert( data.size()==logweights.size() );
134  return data.size();
135  } else {
137  }
138 }
139 
140 inline
141 void Analysis::getDataPoint( const unsigned& idata, std::vector<double>& point, double& weight ) const {
142  if( !reusing_data ){
143  plumed_dbg_assert( idata<weights.size() && point.size()==getNumberOfArguments() );
144  for(unsigned i=0;i<point.size();++i) point[i]=data[idata][i];
145  weight=weights[idata];
146  } else {
147  return mydatastash->getDataPoint( idata, point, weight );
148  }
149 }
150 
151 inline
152 bool Analysis::usingMemory() const {
153  if( !reusing_data ){
154  return !nomemory;
155  } else {
156  return mydatastash->usingMemory();
157  }
158 }
159 
160 inline
163  return nargs - biases.size();
164 }
165 
166 inline
167 double Analysis::retrieveNorm() const {
168  return norm;
169 }
170 
171 inline
172 std::vector<Value*> Analysis::getArguments(){
173  std::vector<Value*> arg_vals( ActionWithArguments::getArguments() );
174  for(unsigned i=0;i<biases.size();++i) arg_vals.erase(arg_vals.end()-1);
175  return arg_vals;
176 }
177 
178 inline
179 std::string Analysis::getOutputFormat() const {
180  return ofmt;
181 }
182 
183 }
184 }
185 
186 #endif
bool reusing_data
Are we reusing data stored by another analysis action.
Definition: Analysis.h:52
void runFinalJobs()
RunFinalJobs This method is called once at the very end of the calculation.
Definition: Analysis.cpp:343
std::vector< Value * > biases
The biases we are using in reweighting and the args we store them separately.
Definition: Analysis.h:68
bool nomemory
Are we treating each block of data separately.
Definition: Analysis.h:48
bool getPeriodicityInformation(const unsigned &i, std::string &dmin, std::string &dmax)
Returns true if argument i is periodic together with the domain.
Definition: Analysis.cpp:337
bool usingMemory() const
Are we analyzing each data block separately (if we are not this also returns the old normalization ) ...
Definition: Analysis.h:152
unsigned idata
The piece of data we are inserting.
Definition: Analysis.h:70
unsigned ndata
Number of data point we need to run analysis.
Definition: Analysis.h:60
void getDataPoint(const unsigned &idata, std::vector< double > &point, double &weight) const
Retrieve the ith point.
Definition: Analysis.h:141
bool ignore_reweight
If we are reusing data are we ignoring the reweighting in that data.
Definition: Analysis.h:54
This is used to create PLMD::Action objects that are run with some set frequency. ...
Definition: ActionPilot.h:39
OFile rfile
The checkpoint file.
Definition: Analysis.h:84
void parseOutputFile(const std::string &key, std::string &filename)
This is used to read in output file names for analysis methods.
Definition: Analysis.cpp:198
void finalizeWeights(const bool &ignore_weights)
Convert the stored log weights to proper weights.
Definition: Analysis.cpp:257
void readDataFromFile(const std::string &filename)
Read in data from a file.
Definition: Analysis.cpp:176
double retrieveNorm() const
This retrieves the value of norm from the analysis action.
Definition: Analysis.h:167
bool firstAnalysisDone
Have we analyzed the data for the first time.
Definition: Analysis.h:78
std::vector< std::vector< double > > data
The data we are going to analyze.
Definition: Analysis.h:74
This is used to create PLMD::Action objects that take the output from some other Action as input...
std::vector< double > args
Tempory vector to store values of arguments.
Definition: Analysis.h:72
std::vector< double > weights
Definition: Analysis.h:76
double getNormalization() const
Return the normalization constant.
Definition: Analysis.cpp:324
void update()
Update.
Definition: Analysis.cpp:329
Analysis * mydatastash
The Analysis action that we are reusing data from.
Definition: Analysis.h:56
double simtemp
The temperature at which we are running the calculation.
Definition: Analysis.h:62
This class holds the keywords and their documentation.
Definition: Keywords.h:36
This class is used to bring the relevant information to the Action constructor.
Definition: Action.h:41
unsigned freq
The frequency with which we are performing analysis.
Definition: Analysis.h:58
std::vector< Value * > & getArguments()
Returns an array of pointers to the arguments.
bool write_chq
Are we writing a checkpoint file.
Definition: Analysis.h:50
std::vector< Value * > getArguments()
Overwrite ActionWithArguments getArguments() so that we don't return the bias.
Definition: Analysis.h:172
unsigned getNumberOfDataPoints() const
Return the number of data points.
Definition: Analysis.h:131
void apply()
Apply an Action.
Definition: Analysis.h:125
This is the abstract base class to use for implementing new methods for analyzing the trajectory...
Definition: Analysis.h:40
void prepare()
Prepare an Action for calculation This can be used by Action if they need some special preparation be...
Definition: Analysis.cpp:207
unsigned getNumberOfArguments() const
Return the number of arguments (this overwrites the one in ActionWithArguments)
Definition: Analysis.h:161
virtual void performAnalysis()=0
Class for output files.
Definition: OFile.h:84
void calculate()
Calculate an Action.
Definition: Analysis.cpp:211
bool single_run
Are we running only once for the whole trajectory.
Definition: Analysis.h:46
Analysis(const ActionOptions &)
Definition: Analysis.cpp:75
double rtemp
The temperature at which we want the histogram.
Definition: Analysis.h:64
bool needeng
Do we need the energy (are we reweighting at a different temperature)
Definition: Analysis.h:66
static void registerKeywords(Keywords &keys)
Definition: Analysis.cpp:55
unsigned getNumberOfArguments() const
Returns the number of arguments.
std::string ofmt
The format to use in output files.
Definition: Analysis.h:82
double norm
The value of the old normalization constant.
Definition: Analysis.h:80
std::vector< double > logweights
The weights of all the data points.
Definition: Analysis.h:76
std::string getOutputFormat() const
Return the format to use for numbers in output files.
Definition: Analysis.h:179