LCOV - code coverage report
Current view: top level - gridtools - Gradient.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 48 48 100.0 %
Date: 2024-10-18 13:59:31 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2016-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 "core/ActionShortcut.h"
      23             : #include "core/ActionRegister.h"
      24             : 
      25             : //+PLUMEDOC MCOLVAR GRADIENT
      26             : /*
      27             : Calculate the gradient of an input grid
      28             : 
      29             : \par Examples
      30             : 
      31             : */
      32             : //+ENDPLUMEDOC
      33             : 
      34             : namespace PLMD {
      35             : namespace gridtools {
      36             : 
      37             : class Gradient : public ActionShortcut {
      38             : public:
      39             :   static void registerKeywords(Keywords& keys);
      40             :   explicit Gradient(const ActionOptions&);
      41             : };
      42             : 
      43             : PLUMED_REGISTER_ACTION(Gradient,"GRADIENT")
      44             : 
      45           9 : void Gradient::registerKeywords( Keywords& keys ) {
      46           9 :   ActionShortcut::registerKeywords( keys );
      47          18 :   keys.add("compulsory","ORIGIN","we will use the position of this atom as the origin in our calculation");
      48          18 :   keys.add("compulsory","NBINS","number of bins to use in each direction for the calculation of the gradient");
      49          18 :   keys.add("compulsory","DIR","xyz","the directions in which we are calculating the graident.  Should be x, y, z, xy, xz, yz or xyz");
      50          18 :   keys.add("compulsory","SIGMA","the width of the function to be used for kernel density estimation");
      51          18 :   keys.add("compulsory","KERNEL","gaussian-bin","the type of kernel function to be used in the grids");
      52          18 :   keys.add("compulsory","ATOMS","calculate the gradient of these atoms");
      53          18 :   keys.setValueDescription("scalar","the desired gradient");
      54          27 :   keys.needsAction("DISTANCES"); keys.needsAction("KDE"); keys.needsAction("INTERPOLATE_GRID");
      55          27 :   keys.needsAction("CUSTOM"); keys.needsAction("SUM_GRID"); keys.needsAction("COMBINE");
      56           9 : }
      57             : 
      58           7 : Gradient::Gradient(const ActionOptions&ao):
      59             :   Action(ao),
      60           7 :   ActionShortcut(ao)
      61             : {
      62          14 :   std::string atom_str; parse("ATOMS",atom_str);
      63          14 :   std::string dir; parse("DIR",dir);
      64          14 :   std::string origin_str; parse("ORIGIN",origin_str);
      65          14 :   std::string nbin_str; parse("NBINS",nbin_str);
      66          14 :   std::string band_str; parse("SIGMA",band_str);
      67           7 :   std::string kernel_str; parse("KERNEL",kernel_str);
      68             :   // First get positions of all atoms relative to origin
      69          14 :   readInputLine( getShortcutLabel() + "_dist: DISTANCES ORIGIN=" + origin_str + " ATOMS=" + atom_str + " COMPONENTS");
      70             :   // Now constrcut the histograms
      71          22 :   if( dir=="x" || dir=="xy" || dir=="xz" || dir=="xyz" ) {
      72           8 :     readInputLine( getShortcutLabel() + "_xhisto: KDE ARG=" + getShortcutLabel() + "_dist.x GRID_BIN=" + nbin_str + " KERNEL=" + kernel_str + " BANDWIDTH=" + band_str );
      73           8 :     std::string thislab = getShortcutLabel() + "_xgrad"; if( dir=="x" ) thislab = getShortcutLabel();
      74           8 :     readInputLine( thislab + "_shift: INTERPOLATE_GRID ARG=" + getShortcutLabel() + "_xhisto INTERPOLATION_TYPE=ceiling MIDPOINTS");
      75           8 :     readInputLine( thislab + "_x2: CUSTOM ARG=" + getShortcutLabel() + "_xhisto," + thislab + "_shift FUNC=(x-y)*(x-y) PERIODIC=NO");
      76           8 :     readInputLine( thislab + ": SUM_GRID ARG=" + thislab + "_x2 PERIODIC=NO");
      77             :   }
      78          22 :   if( dir=="y" || dir=="xy" || dir=="yz" || dir=="xyz" ) {
      79           8 :     readInputLine( getShortcutLabel() + "_yhisto: KDE ARG=" + getShortcutLabel() + "_dist.y GRID_BIN=" + nbin_str + " KERNEL=" + kernel_str + " BANDWIDTH=" + band_str );
      80           8 :     std::string thislab = getShortcutLabel() + "_ygrad"; if( dir=="y" ) thislab = getShortcutLabel();
      81           8 :     readInputLine( thislab + "_shift: INTERPOLATE_GRID ARG=" + getShortcutLabel() + "_yhisto INTERPOLATION_TYPE=ceiling MIDPOINTS");
      82           8 :     readInputLine( thislab + "_x2: CUSTOM ARG=" + getShortcutLabel() + "_yhisto," + thislab + "_shift FUNC=(x-y)*(x-y) PERIODIC=NO");
      83           8 :     readInputLine( thislab + ": SUM_GRID ARG=" + thislab + "_x2 PERIODIC=NO");
      84             :   }
      85          22 :   if( dir=="z" || dir=="yz" || dir=="xz" || dir=="xyz" ) {
      86           8 :     readInputLine( getShortcutLabel() + "_zhisto: KDE ARG=" + getShortcutLabel() + "_dist.z GRID_BIN=" + nbin_str + " KERNEL=" + kernel_str + " BANDWIDTH=" + band_str );
      87           8 :     std::string thislab = getShortcutLabel() + "_zgrad"; if( dir=="z" ) thislab = getShortcutLabel();
      88           8 :     readInputLine( thislab + "_shift: INTERPOLATE_GRID ARG=" + getShortcutLabel() + "_zhisto INTERPOLATION_TYPE=ceiling MIDPOINTS");
      89           8 :     readInputLine( thislab + "_x2: CUSTOM ARG=" + getShortcutLabel() + "_zhisto," + thislab + "_shift FUNC=(x-y)*(x-y) PERIODIC=NO");
      90           8 :     readInputLine( thislab + ": SUM_GRID ARG=" + thislab + "_x2 PERIODIC=NO");
      91             :   }
      92           7 :   if( dir=="xy" ) {
      93           2 :     readInputLine( getShortcutLabel() + ": COMBINE ARG=" + getShortcutLabel() + "_xgrad," + getShortcutLabel() + "_ygrad PERIODIC=NO");
      94           6 :   } else if( dir=="xz" ) {
      95           2 :     readInputLine( getShortcutLabel() + ": COMBINE ARG=" + getShortcutLabel() + "_xgrad," + getShortcutLabel() + "_zgrad PERIODIC=NO");
      96           5 :   } else if( dir=="yz" ) {
      97           2 :     readInputLine( getShortcutLabel() + ": COMBINE ARG=" + getShortcutLabel() + "_ygrad," + getShortcutLabel() + "_zgrad PERIODIC=NO");
      98           4 :   } else if( dir=="xyz" ) {
      99           2 :     readInputLine( getShortcutLabel() + ": COMBINE ARG=" + getShortcutLabel() + "_xgrad," + getShortcutLabel() + "_ygrad," + getShortcutLabel() + "_zgrad PERIODIC=NO");
     100             :   }
     101           7 : }
     102             : 
     103             : 
     104             : 
     105             : }
     106             : }

Generated by: LCOV version 1.16