LCOV - code coverage report
Current view: top level - gridtools - PairEntropies.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 40 40 100.0 %
Date: 2025-04-08 21:11:17 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-2017 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 "RDF.h"
      23             : #include "core/ActionRegister.h"
      24             : #include "core/ActionShortcut.h"
      25             : 
      26             : //+PLUMEDOC MCOLVAR PAIRENTROPIES
      27             : /*
      28             : Calculate the KL entropy from the RDF around each of the atoms
      29             : 
      30             : \par Examples
      31             : 
      32             : */
      33             : //+ENDPLUMEDOC
      34             : 
      35             : namespace PLMD {
      36             : namespace gridtools {
      37             : 
      38             : class PairEntropies : public ActionShortcut {
      39             : public:
      40             :   static void registerKeywords( Keywords& keys );
      41             :   explicit PairEntropies(const ActionOptions&ao);
      42             : };
      43             : 
      44             : PLUMED_REGISTER_ACTION(PairEntropies,"PAIRENTROPIES")
      45             : 
      46           3 : void PairEntropies::registerKeywords( Keywords& keys ) {
      47           3 :   RDF::registerKeywords( keys );
      48           3 :   keys.remove("GROUP");
      49           3 :   keys.remove("GROUPA");
      50           3 :   keys.remove("GROUPB");
      51           6 :   keys.remove("ATOMS");
      52           3 :   keys.add("atoms","ATOMS","the atoms that you would like to compute the entropies for");
      53           6 :   keys.setValueDescription("vector","the a vector containing the KL-entropy that is computed from the radial distribution function around each of the atoms in the input");
      54           3 :   keys.needsAction("PAIRENTROPY");
      55           3 :   keys.needsAction("INTERPOLATE_GRID");
      56           3 :   keys.needsAction("INTEGRATE_GRID");
      57           3 :   keys.needsAction("CUSTOM");
      58           3 :   keys.needsAction("CONCATENATE");
      59           3 : }
      60             : 
      61           1 : PairEntropies::PairEntropies(const ActionOptions&ao):
      62             :   Action(ao),
      63           1 :   ActionShortcut(ao) {
      64             :   // Read in the atoms involved
      65             :   std::string atoms_str;
      66           2 :   parse("ATOMS",atoms_str);
      67             :   // Create the x2 value
      68             :   std::string maxr, nbins, dens;
      69           1 :   parse("MAXR",maxr);
      70           1 :   parse("GRID_BIN",nbins);
      71           1 :   parse("DENSITY",dens);
      72           2 :   std::string grid_setup = "GRID_MIN=0 GRID_MAX=" + maxr + " GRID_BIN=" + nbins;
      73           1 :   RDF::createX2ReferenceObject( getShortcutLabel(), grid_setup, dens.length()==0, this );
      74             :   // Create the number of input atoms
      75           2 :   std::string pair_str = "GRID_BIN=" + nbins + " MAXR=" + maxr + " " + convertInputLineToString();
      76           1 :   std::vector<std::string> awords=Tools::getWords(atoms_str,"\t\n ,");
      77           1 :   Tools::interpretRanges( awords );
      78             :   // Now create all the pairentropy objects
      79          65 :   for(unsigned i=0; i<awords.size(); ++i) {
      80             :     std::string ilab, jlab, atoms_str2;
      81          64 :     Tools::convert( awords[i], ilab );
      82        4160 :     for(unsigned j=0; j<awords.size(); ++j) {
      83        4096 :       if( awords[i]==awords[j] ) {
      84          64 :         continue;
      85             :       }
      86        4032 :       Tools::convert( awords[j], jlab );
      87        4032 :       if( atoms_str2.length()==0 ) {
      88             :         atoms_str2 = jlab;
      89             :       } else {
      90        7936 :         atoms_str2 += "," + jlab;
      91             :       }
      92             :     }
      93         128 :     readInputLine( getShortcutLabel() + ilab + ": PAIRENTROPY GROUPA=" + ilab + " GROUPB=" + atoms_str2 + " " + pair_str + " REFERENCE=" + getShortcutLabel() );
      94             :   }
      95             :   // And compose a vector containing the values of all the pair entropies
      96           1 :   std::string num, argstr = "ARG=" + getShortcutLabel() + "1";
      97          64 :   for(unsigned i=1; i<awords.size(); ++i) {
      98          63 :     Tools::convert( i+1, num );
      99         126 :     argstr += "," + getShortcutLabel() + num;
     100             :   }
     101           2 :   readInputLine( getShortcutLabel() + ": CONCATENATE " + argstr );
     102           2 : }
     103             : 
     104             : }
     105             : }

Generated by: LCOV version 1.16