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.add("atoms","ATOMS","the atoms that you would like to compute the entropies for"); 52 3 : keys.setValueDescription("the a vector containing the KL-entropy that is computed from the radial distribution function around each of the atoms in the input"); 53 3 : keys.needsAction("PAIRENTROPY"); 54 3 : keys.needsAction("INTERPOLATE_GRID"); 55 3 : keys.needsAction("INTEGRATE_GRID"); 56 3 : keys.needsAction("CUSTOM"); 57 3 : keys.needsAction("CONCATENATE"); 58 3 : } 59 : 60 1 : PairEntropies::PairEntropies(const ActionOptions&ao): 61 : Action(ao), 62 1 : ActionShortcut(ao) { 63 : // Read in the atoms involved 64 : std::string atoms_str; 65 2 : parse("ATOMS",atoms_str); 66 : // Create the x2 value 67 : std::string maxr, nbins, dens; 68 1 : parse("MAXR",maxr); 69 1 : parse("GRID_BIN",nbins); 70 1 : parse("DENSITY",dens); 71 2 : std::string grid_setup = "GRID_MIN=0 GRID_MAX=" + maxr + " GRID_BIN=" + nbins; 72 1 : RDF::createX2ReferenceObject( getShortcutLabel(), grid_setup, dens.length()==0, this ); 73 : // Create the number of input atoms 74 2 : std::string pair_str = "GRID_BIN=" + nbins + " MAXR=" + maxr + " " + convertInputLineToString(); 75 1 : std::vector<std::string> awords=Tools::getWords(atoms_str,"\t\n ,"); 76 1 : Tools::interpretRanges( awords ); 77 : // Now create all the pairentropy objects 78 65 : for(unsigned i=0; i<awords.size(); ++i) { 79 : std::string ilab, jlab, atoms_str2; 80 64 : Tools::convert( awords[i], ilab ); 81 4160 : for(unsigned j=0; j<awords.size(); ++j) { 82 4096 : if( awords[i]==awords[j] ) { 83 64 : continue; 84 : } 85 4032 : Tools::convert( awords[j], jlab ); 86 4032 : if( atoms_str2.length()==0 ) { 87 : atoms_str2 = jlab; 88 : } else { 89 7936 : atoms_str2 += "," + jlab; 90 : } 91 : } 92 128 : readInputLine( getShortcutLabel() + ilab + ": PAIRENTROPY GROUPA=" + ilab + " GROUPB=" + atoms_str2 + " " + pair_str + " REFERENCE=" + getShortcutLabel() ); 93 : } 94 : // And compose a vector containing the values of all the pair entropies 95 1 : std::string num, argstr = "ARG=" + getShortcutLabel() + "1"; 96 64 : for(unsigned i=1; i<awords.size(); ++i) { 97 63 : Tools::convert( i+1, num ); 98 126 : argstr += "," + getShortcutLabel() + num; 99 : } 100 2 : readInputLine( getShortcutLabel() + ": CONCATENATE " + argstr ); 101 2 : } 102 : 103 : } 104 : }