LCOV - code coverage report
Current view: top level - function - Between.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 29 31 93.5 %
Date: 2026-03-30 11:13:23 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         219 : void Between::registerKeywords(Keywords& keys) {
      68         438 :   keys.add("compulsory","LOWER","the lower boundary for this particular bin");
      69         438 :   keys.add("compulsory","UPPER","the upper boundary for this particular bin");
      70         438 :   keys.add("compulsory","SMEAR","0.5","the ammount to smear the Gaussian for each value in the distribution");
      71         438 :   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         219 :   keys.setValueDescription("a function that is one if the input falls within a particular range and zero otherwise");
      75         219 : }
      76             : 
      77          53 : void Between::read( ActionWithArguments* action ) {
      78          53 :   if( action->getNumberOfArguments()!=1 ) {
      79           0 :     action->error("should only be one argument to between actions");
      80             :   }
      81             : 
      82             :   std::string str_min, str_max, tstr_min, tstr_max;
      83          53 :   bool isPeriodic = action->getPntrToArgument(0)->isPeriodic();
      84          53 :   if( isPeriodic ) {
      85           1 :     action->getPntrToArgument(0)->getDomain( str_min, str_max );
      86             :   }
      87             : 
      88             :   std::string hinput;
      89         106 :   action->parse("SWITCH",hinput);
      90          53 :   if(hinput.length()==0) {
      91             :     std::string low, up, sme;
      92           5 :     action->parse("LOWER",low);
      93           5 :     action->parse("UPPER",up);
      94           5 :     action->parse("SMEAR",sme);
      95          10 :     hinput = "GAUSSIAN LOWER=" + low + " UPPER=" + up + " SMEAR=" + sme;
      96             :   }
      97             :   std::string errors;
      98          53 :   hist.set( hinput, errors );
      99          53 :   if( errors.size()!=0 ) {
     100           0 :     action->error( errors );
     101             :   }
     102          53 :   action->log.printf("  %s \n", hist.description().c_str() );
     103             : 
     104          53 :   if( !isPeriodic ) {
     105             :     hist.isNotPeriodic();
     106             :   } else {
     107             :     double min;
     108           1 :     Tools::convert( str_min, min );
     109             :     double max;
     110           1 :     Tools::convert( str_max, max );
     111           1 :     hist.isPeriodic( min, max );
     112             :   }
     113          53 : }
     114             : 
     115       49226 : void Between::calc( const ActionWithArguments* action, const std::vector<double>& args, std::vector<double>& vals, Matrix<double>& derivatives ) const {
     116             :   plumed_dbg_assert( args.size()==1 );
     117       49226 :   vals[0] = hist.calculate( args[0], derivatives(0,0) );
     118       49226 : }
     119             : 
     120             : }
     121             : }
     122             : 
     123             : 

Generated by: LCOV version 1.16