LCOV - code coverage report
Current view: top level - colvar - PropertyMap.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 29 33 87.9 %
Date: 2025-03-25 09:33:27 Functions: 2 4 50.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2012-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 "PathMSDBase.h"
      23             : #include "core/PlumedMain.h"
      24             : 
      25             : namespace PLMD {
      26             : namespace colvar {
      27             : 
      28             : //+PLUMEDOC COLVAR PROPERTYMAP
      29             : /*
      30             : Calculate generic property maps.
      31             : 
      32             : This colvar calculates the property maps according that is discussed in the paper by Spiwok in the bibligraphy below.
      33             : The idea is to calculate properties like as $X$ and $Y$ as follows:
      34             : 
      35             : $$
      36             : \begin{align}
      37             : X & = \frac{\sum_i X_i*\exp(-\lambda D_i(x))}{\sum_i  \exp(-\lambda D_i(x))} \\
      38             : Y & = \frac{\sum_i Y_i*\exp(-\lambda D_i(x))}{\sum_i  \exp(-\lambda D_i(x))} \\
      39             : & \cdots\\
      40             : zzz & =-\frac{1}{\lambda}\log(\sum_i  \exp(-\lambda D_i(x)))
      41             : \end{align}
      42             : $$
      43             : 
      44             : The example input below shows how this works:
      45             : 
      46             : ```plumed
      47             : #SETTINGS INPUTFILES=regtest/basic/rt40/allv.pdb
      48             : p3: PROPERTYMAP REFERENCE=regtest/basic/rt40/allv.pdb PROPERTY=X,Y LAMBDA=69087 NEIGH_SIZE=8 NEIGH_STRIDE=4
      49             : PRINT ARG=p3.X,p3.Y,p3.zzz STRIDE=1 FILE=colvar FMT=%8.4f
      50             : ```
      51             : 
      52             : In this case the input line instructs plumed to look for two properties X and Y with attached values in the REMARK
      53             : line of the reference pdb.  The parameters $X_i$ and $Y_i$ are provided in the input pdb and
      54             : $D_i(x)$  is the mean squared displacement after optimal alignment calculated on the pdb frames you input (see Kearsley).
      55             : The `NEIGH_STRIDE=4 NEIGH_SIZE=8` control the neighbor list parameter (optional but
      56             : recommended for performance) and states that the neighbor list will be calculated every 4
      57             : steps and consider only the closest 8 member to the actual md snapshots.
      58             : 
      59             : 
      60             : When running with periodic boundary conditions, the atoms should be
      61             : in the proper periodic image. This is done automatically since PLUMED 2.5,
      62             : by considering the ordered list of atoms and rebuilding molecules using a procedure
      63             : that is equivalent to that done in [WHOLEMOLECULES](WHOLEMOLECULES.md) . Notice that
      64             : rebuilding is local to this action. This is different from [WHOLEMOLECULES](WHOLEMOLECULES.md)
      65             : which actually modifies the coordinates stored in PLUMED.  If you want to recover the old behavior you should use the NOPBC flag.
      66             : In that case you need to take care that atoms are in the correct
      67             : periodic image.
      68             : 
      69             : The implementation of this collective variable and of [PATHMSD](PATHMSD.md)
      70             : is shared, as well as most input options.
      71             : 
      72             : */
      73             : //+ENDPLUMEDOC
      74             : 
      75             : class PropertyMap : public PathMSDBase {
      76             : public:
      77             :   explicit PropertyMap(const ActionOptions&);
      78             :   static void registerKeywords(Keywords& keys);
      79             :   std::string getOutputComponentDescription( const std::string& cname, const Keywords& keys ) const override ;
      80             : };
      81             : 
      82             : PLUMED_REGISTER_ACTION(PropertyMap,"PROPERTYMAP")
      83             : 
      84          13 : void PropertyMap::registerKeywords(Keywords& keys) {
      85          13 :   PathMSDBase::registerKeywords(keys);
      86          13 :   keys.add("compulsory","PROPERTY","the property to be used in the indexing: this goes in the REMARK field of the reference");
      87          26 :   keys.addOutputComponent("zzz","default","scalar","the minimum distance from the reference points");
      88          13 :   ActionWithValue::useCustomisableComponents(keys);
      89          13 :   keys.addDOI("10.1063/1.3660208");
      90          13 : }
      91             : 
      92          11 : PropertyMap::PropertyMap(const ActionOptions&ao):
      93             :   Action(ao),
      94          11 :   PathMSDBase(ao) {
      95             :   // this is the only additional keyword needed
      96          11 :   parseVector("PROPERTY",labels);
      97          11 :   checkRead();
      98          11 :   log<<"  Bibliography "
      99          22 :      <<plumed.cite("Spiwok V, Kralova B  J. Chem. Phys. 135,  224504 (2011)")
     100          22 :      <<"\n";
     101          11 :   if(labels.size()==0) {
     102             :     const std::size_t buflen=500;
     103             :     char buf[buflen];
     104             :     std::snprintf(buf,buflen,"Need to specify PROPERTY with this action\n");
     105           0 :     plumed_merror(buf);
     106             :   } else {
     107          33 :     for(unsigned i=0; i<labels.size(); i++) {
     108          22 :       log<<" found custom propety to be found in the REMARK line: "<<labels[i].c_str()<<"\n";
     109          44 :       addComponentWithDerivatives(labels[i]);
     110          22 :       componentIsNotPeriodic(labels[i]);
     111             :     }
     112             :     // add distance anyhow
     113          22 :     addComponentWithDerivatives("zzz");
     114          11 :     componentIsNotPeriodic("zzz");
     115             :     //reparse the REMARK field and pick the index
     116         473 :     for(unsigned i=0; i<pdbv.size(); i++) {
     117             :       // now look for X=1.34555 Y=5.6677
     118             :       std::vector<double> labelvals;
     119        1386 :       for(unsigned j=0; j<labels.size(); j++) {
     120         924 :         std::vector<double> val(1);
     121         924 :         if( pdbv[i].getArgumentValue(labels[j],val) ) {
     122         924 :           labelvals.push_back(val[0]);
     123             :         } else {
     124             :           const std::size_t buflen=500;
     125             :           char buf[buflen];
     126             :           std::snprintf(buf,buflen,"PROPERTY LABEL \" %s \" NOT FOUND IN REMARK FOR FRAME %u \n",labels[j].c_str(),i);
     127           0 :           plumed_merror(buf);
     128             :         };
     129             :       }
     130         462 :       indexvec.push_back(labelvals);
     131             :     }
     132             :   }
     133          11 :   requestAtoms(pdbv[0].getAtomNumbers());
     134             : 
     135          11 : }
     136             : 
     137           0 : std::string PropertyMap::getOutputComponentDescription( const std::string& cname, const Keywords& keys ) const {
     138           0 :   return "the projection of the instanenous position in CV space on the coordinate " + cname + " that is defined in the reference file";
     139             : }
     140             : 
     141             : }
     142             : }
     143             : 
     144             : 

Generated by: LCOV version 1.16