Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2015-2023 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_AnalysisBase_h 23 : #define __PLUMED_analysis_AnalysisBase_h 24 : 25 : #include "core/ActionPilot.h" 26 : #include "core/ActionAtomistic.h" 27 : #include "core/ActionWithArguments.h" 28 : #include "core/ActionWithValue.h" 29 : #include "vesselbase/ActionWithVessel.h" 30 : #include "DataCollectionObject.h" 31 : 32 : namespace PLMD { 33 : 34 : class ReferenceConfiguration; 35 : 36 : namespace analysis { 37 : 38 : /** 39 : \ingroup INHERIT 40 : This is the abstract base class to use for implementing new methods for analyzing the trajectory. You can find 41 : \ref AddingAnAnalysis "information" on how to use it to implement new analysis methods here. 42 : 43 : */ 44 : 45 : class AnalysisBase : 46 : public ActionPilot, 47 : public ActionWithValue, 48 : public ActionAtomistic, 49 : public ActionWithArguments, 50 : public vesselbase::ActionWithVessel { 51 : friend class ReselectLandmarks; 52 : friend class ReadDissimilarityMatrix; 53 : protected: 54 : /// The Analysis action that we are reusing data from 55 : AnalysisBase* my_input_data; 56 : public: 57 : static void registerKeywords( Keywords& keys ); 58 : explicit AnalysisBase(const ActionOptions&); 59 : /// These are required because we inherit from both ActionAtomistic and ActionWithArguments 60 : void lockRequests() override; 61 : void unlockRequests() override; 62 : /// Return the number of data points 63 : virtual unsigned getNumberOfDataPoints() const ; 64 : /// Return the index of the data point in the base class 65 : virtual unsigned getDataPointIndexInBase( const unsigned& idata ) const ; 66 : /// Return the weight of the ith point 67 : virtual double getWeight( const unsigned& idata ); 68 : /// Get the name of the metric that is being used 69 : virtual std::string getMetricName() const ; 70 : /// Are we using memory in this calculation this affects the weights of points 71 : virtual bool usingMemory() const ; 72 : /// Return the normalisation constant for the calculation 73 : virtual double getNormalization() const ; 74 : /// Ensures that dissimilarities were set somewhere 75 : virtual bool dissimilaritiesWereSet() const ; 76 : /// Get the information on how dissimilarities were calculated for output PDB 77 : virtual std::string getDissimilarityInstruction() const ; 78 : /// Get the squared dissimilarity between two reference configurations 79 : virtual double getDissimilarity( const unsigned& i, const unsigned& j ); 80 : /// Get the indices of the atoms that have been stored 81 : virtual const std::vector<AtomNumber>& getAtomIndexes() const ; 82 : /// Overwrite getArguments so we get arguments from underlying class 83 : virtual std::vector<Value*> getArgumentList(); 84 : /// Get the list of argument names in the base 85 : std::vector<std::string> getArgumentNames(); 86 : /// Get a reference configuration (in dimensionality reduction this returns the projection) 87 : virtual DataCollectionObject& getStoredData( const unsigned& idata, const bool& calcdist ); 88 : /// This actually performs the analysis 89 : virtual void performAnalysis()=0; 90 : /// These overwrite things from inherited classes (this is a bit of a fudge) 91 0 : bool isPeriodic() override { 92 0 : plumed_error(); 93 : } 94 0 : unsigned getNumberOfDerivatives() override { 95 0 : plumed_error(); 96 : } 97 0 : void calculateNumericalDerivatives( ActionWithValue* a=NULL ) override { 98 0 : plumed_error(); 99 : } 100 : /// Calculate and apply do nothing all analysis is done during update step 101 7546 : void calculate() override {} 102 7546 : void apply() override {} 103 : /// This will call the analysis to be performed 104 : void update() override; 105 : /// This calls the analysis to be performed in the final step of the calculation 106 : /// i.e. when use_all_data is true 107 : void runFinalJobs() override; 108 : }; 109 : 110 : inline 111 7546 : void AnalysisBase::lockRequests() { 112 : ActionAtomistic::lockRequests(); 113 : ActionWithArguments::lockRequests(); 114 7546 : } 115 : 116 : inline 117 7546 : void AnalysisBase::unlockRequests() { 118 : ActionAtomistic::unlockRequests(); 119 : ActionWithArguments::unlockRequests(); 120 7546 : } 121 : 122 : inline 123 360092 : unsigned AnalysisBase::getNumberOfDataPoints() const { 124 360137 : return my_input_data->getNumberOfDataPoints(); 125 : } 126 : 127 : inline 128 375002 : unsigned AnalysisBase::getDataPointIndexInBase( const unsigned& idata ) const { 129 500004 : return my_input_data->getDataPointIndexInBase( idata ); 130 : } 131 : 132 : inline 133 0 : std::string AnalysisBase::getMetricName() const { 134 0 : return my_input_data->getMetricName(); 135 : } 136 : 137 : inline 138 40113999 : double AnalysisBase::getWeight( const unsigned& idata ) { 139 40113999 : return my_input_data->getWeight( idata ); 140 : } 141 : 142 : inline 143 0 : bool AnalysisBase::usingMemory() const { 144 0 : return my_input_data->usingMemory(); 145 : } 146 : 147 : inline 148 0 : double AnalysisBase::getNormalization() const { 149 0 : return my_input_data->getNormalization(); 150 : } 151 : 152 : inline 153 848 : bool AnalysisBase::dissimilaritiesWereSet() const { 154 877 : return my_input_data->dissimilaritiesWereSet(); 155 : } 156 : 157 : inline 158 659376 : double AnalysisBase::getDissimilarity( const unsigned& i, const unsigned& j ) { 159 721705 : return my_input_data->getDissimilarity( i, j ); 160 : } 161 : 162 : inline 163 22 : std::vector<Value*> AnalysisBase::getArgumentList() { 164 24 : return my_input_data->getArgumentList(); 165 : } 166 : 167 : inline 168 522156 : DataCollectionObject& AnalysisBase::getStoredData( const unsigned& idata, const bool& calcdist ) { 169 526340 : return my_input_data->getStoredData( idata, calcdist ); 170 : } 171 : 172 : inline 173 14 : const std::vector<AtomNumber>& AnalysisBase::getAtomIndexes() const { 174 14 : return my_input_data->getAtomIndexes(); 175 : } 176 : 177 : inline 178 841 : std::string AnalysisBase::getDissimilarityInstruction() const { 179 841 : return my_input_data->getDissimilarityInstruction(); 180 : } 181 : 182 : } 183 : } 184 : 185 : #endif