Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2012-2019 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_analysis_Analysis_h
23 : #define __PLUMED_analysis_Analysis_h
24 :
25 : #include "vesselbase/ActionWithAveraging.h"
26 :
27 : #define PLUMED_ANALYSIS_INIT(ao) Action(ao),Analysis(ao)
28 :
29 : namespace PLMD {
30 :
31 : class ReferenceConfiguration;
32 :
33 : namespace analysis {
34 :
35 : /**
36 : \ingroup INHERIT
37 : This is the abstract base class to use for implementing new methods for analyzing the trajectory, within it there
38 : is information as to how to go about implementing a new analysis method.
39 :
40 : */
41 :
42 : class Analysis : public vesselbase::ActionWithAveraging {
43 : private:
44 : /// Are we treating each block of data separately
45 : bool nomemory;
46 : /// Are we writing a checkpoint file
47 : bool write_chq;
48 : /// Are we reusing data stored by another analysis action
49 : bool reusing_data;
50 : /// If we are reusing data are we ignoring the reweighting in that data
51 : bool ignore_reweight;
52 : /// The Analysis action that we are reusing data from
53 : Analysis* mydatastash;
54 : /// The frequency with which we are performing analysis
55 : unsigned freq;
56 : /// Number of data point we need to run analysis
57 : unsigned ndata;
58 : /// The temperature at which we are running the calculation
59 : double simtemp;
60 : /// The temperature at which we want the histogram
61 : double rtemp;
62 : /// Do we need the energy (are we reweighting at a different temperature)
63 : bool needeng;
64 : /// The piece of data we are inserting
65 : unsigned idata;
66 : /// The weights of all the data points
67 : std::vector<double> logweights;
68 : /// Have we analyzed the data for the first time
69 : // bool firstAnalysisDone;
70 : /// The value of the old normalization constant
71 : // double norm, old_norm;
72 : /// The format to use in output files
73 : std::string ofmt;
74 : /// Tempory vector to store values of arguments
75 : std::vector<double> current_args;
76 : /// The type of metric we are using to measure distances
77 : std::string metricname;
78 : /// The checkpoint file
79 : OFile rfile;
80 : /// Read in data from a file
81 : void readDataFromFile( const std::string& filename );
82 : /// Get the metric if we are using malonobius distance and flexible hill
83 : std::vector<double> getMetric() const ;
84 : protected:
85 : /// List of argument names
86 : std::vector<std::string> argument_names;
87 : /// This is used to read in output file names for analysis methods. When
88 : /// this method is used and the calculation is not restarted old analysis
89 : /// files are backed up.
90 : void parseOutputFile( const std::string& key, std::string& filename );
91 : /// The data we are going to analyze
92 : std::vector<ReferenceConfiguration*> data;
93 : /// Get the name of the metric we are using to measure distances
94 : std::string getMetricName() const ;
95 : /// Return the number of data points
96 : unsigned getNumberOfDataPoints() const;
97 : /// Return the weight of the ith point
98 : double getWeight( const unsigned& idata ) const ;
99 : /// Retrieve the ith point
100 : void getDataPoint( const unsigned& idata, std::vector<double>& point, double& weight ) const ;
101 : /// Returns true if argument i is periodic together with the domain
102 : bool getPeriodicityInformation(const unsigned& i, std::string& dmin, std::string& dmax);
103 : /// Are we analyzing each data block separately (if we are not this also returns the old normalization )
104 : bool usingMemory() const;
105 : /// Return the format to use for numbers in output files
106 : std::string getOutputFormat() const ;
107 : /// Finalize the weights without using the log sums
108 : // void finalizeWeightsNoLogSums( const double& onorm );
109 : public:
110 : static void registerKeywords( Keywords& keys );
111 : explicit Analysis(const ActionOptions&);
112 : ~Analysis();
113 1294 : void calculate() {}
114 1294 : void apply() {}
115 : void accumulate();
116 : void performOperations( const bool& from_update );
117 : virtual void performAnalysis()=0;
118 : void runFinalJobs();
119 : void runAnalysis();
120 0 : bool isPeriodic() { plumed_error(); return false; }
121 : /// Convert the stored log weights to proper weights
122 : virtual void finalizeWeights( const bool& ignore_weights );
123 : };
124 :
125 : inline
126 : std::string Analysis::getMetricName() const {
127 : return metricname;
128 : }
129 :
130 : inline
131 0 : unsigned Analysis::getNumberOfDataPoints() const {
132 3684 : if( !reusing_data ) {
133 : plumed_dbg_assert( data.size()==logweights.size() );
134 3684 : return data.size();
135 : } else {
136 0 : return mydatastash->getNumberOfDataPoints();
137 : }
138 : }
139 :
140 : inline
141 : bool Analysis::usingMemory() const {
142 : if( !reusing_data ) {
143 : return !nomemory;
144 : } else {
145 : return mydatastash->usingMemory();
146 : }
147 : }
148 :
149 : inline
150 : std::string Analysis::getOutputFormat() const {
151 : return ofmt;
152 : }
153 :
154 : }
155 : }
156 :
157 : #endif
|