LCOV - code coverage report
Current view: top level - gridtools - KDEGridTools.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 38 54 70.4 %
Date: 2026-11-05 10:19:04 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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 "KDEGridTools.h"
      23             : 
      24             : namespace PLMD {
      25             : namespace gridtools {
      26             : 
      27             : template <>
      28          15 : void KDEGridTools<DiagonalKernelParams,DiscreteKernel>::readBandwidthAndHeight( const DiscreteKernel& params, ActionWithArguments* action ) {
      29          15 :   std::size_t nargs = action->getNumberOfArguments();
      30          15 :   KDEGridTools<DiagonalKernelParams,DiscreteKernel>::readHeightKeyword( false, nargs, std::vector<std::string>(), action );
      31          15 : }
      32             : 
      33             : template <>
      34          65 : void KDEGridTools<DiagonalKernelParams,RegularKernel<DiagonalKernelParams>>::readBandwidthAndHeight( const RegularKernel<DiagonalKernelParams>& params, ActionWithArguments* action ) {
      35          65 :   std::vector<Value*> bwargs;
      36          65 :   std::vector<std::string> bw;
      37          65 :   std::size_t nargs = action->getNumberOfArguments();
      38          65 :   readBandwidth( nargs, action, bw );
      39             :   std::string volstr;
      40         128 :   action->parse("VOLUMES",volstr);
      41          64 :   if( volstr.length()>0 ) {
      42          18 :     if( !params.canusevol ) {
      43           0 :       action->error("cannot use normalized kernels with selected kernel type");
      44             :     }
      45             :     // Check if we are using Gaussian kernels
      46          18 :     KDEHelper<DiagonalKernelParams,RegularKernel<DiagonalKernelParams>,KDEGridTools<DiagonalKernelParams,RegularKernel<DiagonalKernelParams>>>::readKernelParameters( volstr, action, "_volumes", false );
      47          18 :     convertHeightsToVolumes(nargs, bw, volstr, action);
      48             :   } else {
      49          46 :     KDEGridTools<DiagonalKernelParams,RegularKernel<DiagonalKernelParams>>::readHeightKeyword( params.canusevol, nargs, bw, action );
      50             :   }
      51         129 : }
      52             : 
      53             : template <>
      54          18 : void KDEGridTools<DiagonalKernelParams,HistogramBeadKernel>::readBandwidthAndHeight( const HistogramBeadKernel& params, ActionWithArguments* action ) {
      55          18 :   std::vector<std::string> bw;
      56          18 :   std::size_t nargs = action->getNumberOfArguments();
      57          18 :   readBandwidth( nargs, action, bw );
      58          18 :   KDEGridTools<DiagonalKernelParams,HistogramBeadKernel>::readHeightKeyword( false, nargs, bw, action );
      59          18 : }
      60             : 
      61             : template <>
      62           1 : void KDEGridTools<NonDiagonalKernelParams,RegularKernel<NonDiagonalKernelParams>>::readBandwidthAndHeight( const RegularKernel<NonDiagonalKernelParams>& params, ActionWithArguments* action ) {
      63           1 :   std::vector<Value*> bwargs;
      64           1 :   std::vector<std::string> bw;
      65           1 :   std::size_t nargs = action->getNumberOfArguments();
      66           1 :   readBandwidthKeyword( nargs, action, bw, bwargs );
      67           1 :   if( nargs>1 && bw.size()==1 ) {
      68           0 :     if( bwargs[0]->getRank()!=2 || bwargs[0]->getShape()[0]!=nargs || bwargs[0]->getShape()[1]!=nargs  ) {
      69           0 :       action->error("invalid input for bandwidth parameter");
      70             :     }
      71             :     std::string str_i, str_j;
      72           0 :     bw.resize( nargs*nargs );
      73           0 :     for(unsigned i=0; i<nargs; ++i) {
      74           0 :       Tools::convert( i+1, str_i );
      75           0 :       for(unsigned j=0; j<nargs; ++j) {
      76           0 :         Tools::convert( j+1, str_j );
      77           0 :         action->plumed.readInputWords( Tools::getWords(action->getLabel() + "_scalar_bw" + str_i + "_" + str_j + ": SELECT_COMPONENTS ARG=" + bwargs[0]->getName() + " COMPONENTS=" + str_i + "." + str_j ), false );
      78           0 :         bw[i*nargs+j] = action->getLabel() + "_bw" + str_i + "_" + str_j;
      79           0 :         action->plumed.readInputWords( Tools::getWords( bw[i*nargs+j] + ": CUSTOM ARG=" + action->getLabel() + "_bwones," + action->getLabel() + "_scalar_bw" + str_i + "_" + str_j + " FUNC=x*y PERIODIC=NO"), false );
      80             :       }
      81             :     }
      82           1 :   } else if( bw.size()==nargs*nargs ) {
      83             :     std::string str_i, str_j;
      84           3 :     for(unsigned i=0; i<nargs; ++i) {
      85           2 :       Tools::convert( i+1, str_i );
      86           6 :       for(unsigned j=0; j<nargs; ++j) {
      87           4 :         Tools::convert( j+1, str_j );
      88          12 :         KDEHelper<NonDiagonalKernelParams,RegularKernel<NonDiagonalKernelParams>,KDEGridTools<NonDiagonalKernelParams,RegularKernel<NonDiagonalKernelParams>>>::readKernelParameters( bw[i*nargs+j], action, "_bw" + str_i + "_" + str_j, true );
      89             :       }
      90             :     }
      91             :   } else {
      92           0 :     action->error("wrong number of arguments specified in input to bandwidth parameter");
      93             :   }
      94             :   std::string volstr;
      95           2 :   action->parse("VOLUMES",volstr);
      96           1 :   if( volstr.length()>0 ) {
      97           0 :     if( !params.canusevol ) {
      98           0 :       action->error("cannot use normalized kernels with selected kernel type");
      99             :     }
     100             :     // Check if we are using Gaussian kernels
     101           0 :     KDEHelper<NonDiagonalKernelParams,RegularKernel<NonDiagonalKernelParams>,KDEGridTools<DiagonalKernelParams,RegularKernel<DiagonalKernelParams>>>::readKernelParameters( volstr, action, "_volumes", false );
     102           0 :     convertHeightsToVolumes(nargs, bw, volstr, action);
     103             :   } else {
     104           1 :     KDEGridTools<NonDiagonalKernelParams,RegularKernel<NonDiagonalKernelParams>>::readHeightKeyword( params.canusevol, nargs, bw, action );
     105             :   }
     106           2 : }
     107             : 
     108             : }
     109             : }

Generated by: LCOV version 1.16