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 : #include "tools/OFile.h" 23 : #include "AnalysisBase.h" 24 : #include "core/ActionRegister.h" 25 : 26 : //+PLUMEDOC ANALYSIS PRINT_DISSIMILARITY_MATRIX 27 : /* 28 : Print the matrix of dissimilarities between a trajectory of atomic configurations. 29 : 30 : \par Examples 31 : 32 : */ 33 : //+ENDPLUMEDOC 34 : 35 : 36 : namespace PLMD { 37 : namespace analysis { 38 : 39 : class PrintDissimilarityMatrix : public AnalysisBase { 40 : private: 41 : std::string fmt; 42 : std::string fname; 43 : public: 44 : static void registerKeywords( Keywords& keys ); 45 : explicit PrintDissimilarityMatrix( const ActionOptions& ao ); 46 : void performAnalysis() override; 47 0 : void performTask( const unsigned&, const unsigned&, MultiValue& ) const override { plumed_error(); } 48 : }; 49 : 50 10435 : PLUMED_REGISTER_ACTION(PrintDissimilarityMatrix,"PRINT_DISSIMILARITY_MATRIX") 51 : 52 9 : void PrintDissimilarityMatrix::registerKeywords( Keywords& keys ) { 53 9 : AnalysisBase::registerKeywords( keys ); 54 18 : keys.add("compulsory","FILE","name of file on which to output the data"); 55 18 : keys.add("optional","FMT","the format to use for the output of numbers"); 56 18 : keys.add("compulsory","STRIDE","0","the frequency with which to perform the required analysis and to output the data. The default value of 0 tells plumed to use all the data"); 57 9 : } 58 : 59 8 : PrintDissimilarityMatrix::PrintDissimilarityMatrix( const ActionOptions& ao ): 60 : Action(ao), 61 : AnalysisBase(ao), 62 8 : fmt("%f") 63 : { 64 8 : if( !dissimilaritiesWereSet() ) error("dissimilarities have not been set in base classes"); 65 : 66 24 : parse("FILE",fname); parse("FMT",fmt); 67 16 : if( !getRestart() ) { OFile ofile; ofile.link(*this); ofile.setBackupString("analysis"); ofile.backupAllFiles(fname); } 68 8 : log.printf(" printing to file named %s with formt %s \n",fname.c_str(), fmt.c_str() ); 69 8 : } 70 : 71 9 : void PrintDissimilarityMatrix::performAnalysis() { 72 9 : std::string ofmt=" "+fmt; 73 18 : OFile ofile; ofile.setBackupString("analysis"); ofile.open(fname); 74 69 : for(unsigned i=0; i<getNumberOfDataPoints(); ++i) { 75 574 : for(unsigned j=0; j<getNumberOfDataPoints(); ++j) ofile.printf(ofmt.c_str(), sqrt( my_input_data->getDissimilarity( i,j ) ) ); 76 60 : ofile.printf("\n"); 77 : } 78 9 : ofile.close(); 79 18 : } 80 : 81 : } 82 : }