LCOV - code coverage report
Current view: top level - vesselbase - Between.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 33 34 97.1 %
Date: 2026-03-30 13:16:06 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2013-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             : 
      23             : #include "Between.h"
      24             : #include "VesselRegister.h"
      25             : 
      26             : namespace PLMD {
      27             : namespace vesselbase {
      28             : 
      29       13850 : PLUMED_REGISTER_VESSEL(Between,"BETWEEN")
      30             : 
      31          65 : void Between::registerKeywords( Keywords& keys ) {
      32          65 :   FunctionVessel::registerKeywords( keys );
      33          65 :   HistogramBead::registerKeywords( keys );
      34         130 :   keys.addFlag("NORM",false,"calculate the fraction of values rather than the number");
      35          65 : }
      36             : 
      37        4595 : void Between::reserveKeyword( Keywords& keys ) {
      38        9190 :   keys.reserve("vessel","BETWEEN","calculate the number of values that are within a certain range. "
      39             :                "These quantities are calculated using kernel density estimation as described on "
      40             :                "\\ref histogrambead.");
      41        9190 :   keys.addOutputComponent("between","BETWEEN","the number/fraction of values within a certain range. This is calculated using one of the "
      42             :                           "formula described in the description of the keyword so as to make it continuous. "
      43             :                           "You can calculate this quantity multiple times using different parameters.");
      44        4595 : }
      45             : 
      46          65 : Between::Between( const VesselOptions& da ) :
      47          65 :   FunctionVessel(da) {
      48          65 :   usetol=true;
      49          65 :   bool isPeriodic=getAction()->isPeriodic();
      50             :   double min, max;
      51             :   std::string str_min, str_max;
      52          65 :   if( isPeriodic ) {
      53           1 :     getAction()->retrieveDomain( str_min, str_max );
      54           1 :     Tools::convert(str_min,min);
      55           1 :     Tools::convert(str_max,max);
      56             :   }
      57             : 
      58         130 :   parseFlag("NORM",norm);
      59             :   std::string errormsg;
      60             : 
      61          65 :   hist.set( getAllInput(),errormsg );
      62          65 :   if( !isPeriodic ) {
      63             :     hist.isNotPeriodic();
      64             :   } else {
      65           1 :     hist.isPeriodic( min, max );
      66             :   }
      67          65 :   if( errormsg.size()!=0 ) {
      68           0 :     error( errormsg );
      69             :   }
      70          65 : }
      71             : 
      72          65 : std::string Between::value_descriptor() {
      73          65 :   if(norm) {
      74           2 :     return "the fraction of values " + hist.description();
      75             :   }
      76         128 :   return "the number of values " + hist.description();
      77             : }
      78             : 
      79        8224 : double Between::calcTransform( const double& val, double& dv ) const {
      80        8224 :   double f = hist.calculate(val, dv);
      81        8224 :   return f;
      82             : }
      83             : 
      84          60 : double Between::getCutoff() {
      85          60 :   return std::numeric_limits<double>::max();
      86             : }
      87             : 
      88             : }
      89             : }

Generated by: LCOV version 1.16