LCOV - code coverage report
Current view: top level - gridtools - PairEntropies.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 26 26 100.0 %
Date: 2024-10-18 13:59:31 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           9 :   RDF::registerKeywords( keys ); keys.remove("GROUP"); keys.remove("GROUPA"); keys.remove("GROUPB");
      48           6 :   keys.add("atoms","ATOMS","the atoms that you would like to compute the entropies for");
      49           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");
      50           6 :   keys.needsAction("PAIRENTROPY"); keys.needsAction("INTERPOLATE_GRID");
      51           6 :   keys.needsAction("INTEGRATE_GRID"); keys.needsAction("CUSTOM");
      52           3 :   keys.needsAction("CONCATENATE");
      53           3 : }
      54             : 
      55           1 : PairEntropies::PairEntropies(const ActionOptions&ao):
      56             :   Action(ao),
      57           1 :   ActionShortcut(ao)
      58             : {
      59             :   // Read in the atoms involved
      60           2 :   std::string atoms_str; parse("ATOMS",atoms_str);
      61             :   // Create the x2 value
      62           3 :   std::string maxr, nbins, dens; parse("MAXR",maxr); parse("GRID_BIN",nbins); parse("DENSITY",dens);
      63           2 :   std::string grid_setup = "GRID_MIN=0 GRID_MAX=" + maxr + " GRID_BIN=" + nbins;
      64           1 :   RDF::createX2ReferenceObject( getShortcutLabel(), grid_setup, dens.length()==0, this );
      65             :   // Create the number of input atoms
      66           2 :   std::string pair_str = "GRID_BIN=" + nbins + " MAXR=" + maxr + " " + convertInputLineToString();
      67           1 :   std::vector<std::string> awords=Tools::getWords(atoms_str,"\t\n ,"); Tools::interpretRanges( awords );
      68             :   // Now create all the pairentropy objects
      69          65 :   for(unsigned i=0; i<awords.size(); ++i) {
      70          64 :     std::string ilab, jlab, atoms_str2; Tools::convert( awords[i], ilab );
      71        4160 :     for(unsigned j=0; j<awords.size(); ++j) {
      72        4096 :       if( awords[i]==awords[j] ) continue; Tools::convert( awords[j], jlab );
      73        8000 :       if( atoms_str2.length()==0 ) atoms_str2 = jlab; else atoms_str2 += "," + jlab;
      74             :     }
      75         128 :     readInputLine( getShortcutLabel() + ilab + ": PAIRENTROPY GROUPA=" + ilab + " GROUPB=" + atoms_str2 + " " + pair_str + " REFERENCE=" + getShortcutLabel() );
      76             :   }
      77             :   // And compose a vector containing the values of all the pair entropies
      78           1 :   std::string num, argstr = "ARG=" + getShortcutLabel() + "1";
      79          64 :   for(unsigned i=1; i<awords.size(); ++i) { Tools::convert( i+1, num ); argstr += "," + getShortcutLabel() + num; }
      80           2 :   readInputLine( getShortcutLabel() + ": CONCATENATE " + argstr );
      81           2 : }
      82             : 
      83             : }
      84             : }

Generated by: LCOV version 1.16