LCOV - code coverage report
Current view: top level - analysis - PrintDissimilarityMatrix.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 31 34 91.2 %
Date: 2026-03-30 13:16:06 Functions: 6 8 75.0 %

          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 {
      48           0 :     plumed_error();
      49             :   }
      50             : };
      51             : 
      52       13801 : PLUMED_REGISTER_ACTION(PrintDissimilarityMatrix,"PRINT_DISSIMILARITY_MATRIX")
      53             : 
      54          12 : void PrintDissimilarityMatrix::registerKeywords( Keywords& keys ) {
      55          12 :   AnalysisBase::registerKeywords( keys );
      56          24 :   keys.add("compulsory","FILE","name of file on which to output the data");
      57          24 :   keys.add("optional","FMT","the format to use for the output of numbers");
      58          24 :   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");
      59          12 : }
      60             : 
      61           8 : PrintDissimilarityMatrix::PrintDissimilarityMatrix( const ActionOptions& ao ):
      62             :   Action(ao),
      63             :   AnalysisBase(ao),
      64           8 :   fmt("%f") {
      65           8 :   if( !dissimilaritiesWereSet() ) {
      66           0 :     error("dissimilarities have not been set in base classes");
      67             :   }
      68             : 
      69           8 :   parse("FILE",fname);
      70          16 :   parse("FMT",fmt);
      71           8 :   if( !getRestart() ) {
      72           8 :     OFile ofile;
      73           8 :     ofile.link(*this);
      74           8 :     ofile.setBackupString("analysis");
      75           8 :     ofile.backupAllFiles(fname);
      76           8 :   }
      77           8 :   log.printf("  printing to file named %s with formt %s \n",fname.c_str(), fmt.c_str() );
      78           8 : }
      79             : 
      80           9 : void PrintDissimilarityMatrix::performAnalysis() {
      81           9 :   std::string ofmt=" "+fmt;
      82           9 :   OFile ofile;
      83           9 :   ofile.setBackupString("analysis");
      84           9 :   ofile.open(fname);
      85          69 :   for(unsigned i=0; i<getNumberOfDataPoints(); ++i) {
      86         574 :     for(unsigned j=0; j<getNumberOfDataPoints(); ++j) {
      87         514 :       ofile.printf(ofmt.c_str(), sqrt( my_input_data->getDissimilarity( i,j ) ) );
      88             :     }
      89          60 :     ofile.printf("\n");
      90             :   }
      91           9 :   ofile.close();
      92          18 : }
      93             : 
      94             : }
      95             : }

Generated by: LCOV version 1.16