LCOV - code coverage report
Current view: top level - function - Between.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 26 26 100.0 %
Date: 2024-10-18 14:00:25 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2011-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 "Between.h"
      23             : #include "FunctionShortcut.h"
      24             : #include "FunctionOfVector.h"
      25             : #include "FunctionOfMatrix.h"
      26             : #include "core/ActionRegister.h"
      27             : 
      28             : #include <cmath>
      29             : 
      30             : namespace PLMD {
      31             : namespace function {
      32             : 
      33             : //+PLUMEDOC FUNCTION BETWEEN
      34             : /*
      35             : Use a switching function to determine how many of the input variables are within a certain range.
      36             : 
      37             : \par Examples
      38             : 
      39             : */
      40             : //+ENDPLUMEDOC
      41             : 
      42             : //+PLUMEDOC FUNCTION BETWEEN_VECTOR
      43             : /*
      44             : Use a switching function to determine how many of the input components are within a certain range
      45             : 
      46             : \par Examples
      47             : 
      48             : */
      49             : //+ENDPLUMEDOC
      50             : 
      51             : //+PLUMEDOC COLVAR BETWEEN_MATRIX
      52             : /*
      53             : Transform all the elements of a matrix using a switching function that is oen when the input value is within a particular range
      54             : 
      55             : \par Examples
      56             : 
      57             : */
      58             : //+ENDPLUMEDOC
      59             : 
      60             : typedef FunctionShortcut<Between> BetweenShortcut;
      61             : PLUMED_REGISTER_ACTION(BetweenShortcut,"BETWEEN")
      62             : typedef FunctionOfVector<Between> VectorBetween;
      63             : PLUMED_REGISTER_ACTION(VectorBetween,"BETWEEN_VECTOR")
      64             : typedef FunctionOfMatrix<Between> MatrixBetween;
      65             : PLUMED_REGISTER_ACTION(MatrixBetween,"BETWEEN_MATRIX")
      66             : 
      67         213 : void Between::registerKeywords(Keywords& keys) {
      68         426 :   keys.add("compulsory","LOWER","the lower boundary for this particular bin");
      69         426 :   keys.add("compulsory","UPPER","the upper boundary for this particular bin");
      70         426 :   keys.add("compulsory","SMEAR","0.5","the ammount to smear the Gaussian for each value in the distribution");
      71         426 :   keys.add("optional","SWITCH","This keyword is used if you want to employ an alternative to the continuous function defined above. "
      72             :            "The following provides information on the \\ref histogrambead that are available. "
      73             :            "When this keyword is present you no longer need the LOWER, UPPER, SMEAR and KERNEL keywords.");
      74         213 :   keys.setValueDescription("a function that is one if the input falls within a particular range and zero otherwise");
      75         213 : }
      76             : 
      77          53 : void Between::read( ActionWithArguments* action ) {
      78          53 :   if( action->getNumberOfArguments()!=1 ) action->error("should only be one argument to between actions");
      79             : 
      80             :   std::string str_min, str_max, tstr_min, tstr_max;
      81          53 :   bool isPeriodic = action->getPntrToArgument(0)->isPeriodic();
      82          53 :   if( isPeriodic ) action->getPntrToArgument(0)->getDomain( str_min, str_max );
      83             : 
      84         106 :   std::string hinput; action->parse("SWITCH",hinput);
      85          53 :   if(hinput.length()==0) {
      86             :     std::string low, up, sme;
      87          15 :     action->parse("LOWER",low); action->parse("UPPER",up); action->parse("SMEAR",sme);
      88          10 :     hinput = "GAUSSIAN LOWER=" + low + " UPPER=" + up + " SMEAR=" + sme;
      89             :   }
      90          53 :   std::string errors; hist.set( hinput, errors );
      91          53 :   if( errors.size()!=0 ) action->error( errors );
      92          53 :   action->log.printf("  %s \n", hist.description().c_str() );
      93             : 
      94          53 :   if( !isPeriodic ) hist.isNotPeriodic();
      95             :   else {
      96           1 :     double min; Tools::convert( str_min, min );
      97           1 :     double max; Tools::convert( str_max, max );
      98           1 :     hist.isPeriodic( min, max );
      99             :   }
     100          53 : }
     101             : 
     102       49226 : void Between::calc( const ActionWithArguments* action, const std::vector<double>& args, std::vector<double>& vals, Matrix<double>& derivatives ) const {
     103       49226 :   plumed_dbg_assert( args.size()==1 ); vals[0] = hist.calculate( args[0], derivatives(0,0) );
     104       49226 : }
     105             : 
     106             : }
     107             : }
     108             : 
     109             : 

Generated by: LCOV version 1.16