LCOV - code coverage report
Current view: top level - isdb - Select.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 20 20 100.0 %
Date: 2024-10-18 13:59:31 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       2             :    Copyright (c) 2017-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             : 
      24             : */
      25             : #include "function/Function.h"
      26             : #include "core/ActionRegister.h"
      27             : #include "core/PlumedMain.h"
      28             : 
      29             : namespace PLMD {
      30             : namespace isdb {
      31             : 
      32             : //+PLUMEDOC ISDB_FUNCTION SELECT
      33             : /*
      34             : Selects an argument based on the value of a SELECTOR.
      35             : 
      36             : You should read the documentation for \ref SELECTOR to understand this action better.
      37             : 
      38             : \par Examples
      39             : 
      40             : In this example we use a simulated-tempering like approach activated by the \ref RESCALE action.
      41             : For each value of the scale parameter, we perform an independent Parallel Bias Metadynamics
      42             : simulation (see \ref PBMETAD). At each moment of the simulation, only one of the \ref PBMETAD
      43             : actions is activated, based on the current value of the associated \ref SELECTOR.
      44             : The \ref SELECT action can then be used to print out the value of the (active) \ref PBMETAD bias potential.
      45             : 
      46             : \plumedfile
      47             : ene:  ENERGY
      48             : d: DISTANCE ATOMS=1,2
      49             : 
      50             : SELECTOR NAME=GAMMA VALUE=0
      51             : 
      52             : pbmetad0: PBMETAD ARG=d SELECTOR=GAMMA SELECTOR_ID=0 SIGMA=0.1 PACE=500 HEIGHT=1 BIASFACTOR=8 FILE=HILLS.0
      53             : pbmetad1: PBMETAD ARG=d SELECTOR=GAMMA SELECTOR_ID=1 SIGMA=0.1 PACE=500 HEIGHT=1 BIASFACTOR=8 FILE=HILLS.1
      54             : 
      55             : RESCALE ...
      56             : LABEL=res ARG=ene,pbmetad0.bias,pbmetad1.bias TEMP=300
      57             : SELECTOR=GAMMA MAX_RESCALE=1.2 NOT_RESCALED=2 NBIN=2
      58             : W0=1000 BIASFACTOR=100.0 BSTRIDE=2000 BFILE=bias.dat
      59             : ...
      60             : 
      61             : pbactive: SELECT ARG=pbmetad0.bias,pbmetad1.bias SELECTOR=GAMMA
      62             : 
      63             : PRINT ARG=pbactive STRIDE=100 FILE=COLVAR
      64             : \endplumedfile
      65             : 
      66             : */
      67             : //+ENDPLUMEDOC
      68             : 
      69             : class Select : public function::Function
      70             : {
      71             :   std::string selector_;
      72             : 
      73             : public:
      74             :   explicit Select(const ActionOptions&);
      75             :   void calculate();
      76             :   static void registerKeywords(Keywords& keys);
      77             : };
      78             : 
      79             : PLUMED_REGISTER_ACTION(Select,"SELECT")
      80             : 
      81           4 : void Select::registerKeywords(Keywords& keys) {
      82           4 :   Function::registerKeywords(keys);
      83           8 :   keys.add("compulsory","SELECTOR","name of the variable used to select");
      84           8 :   keys.setValueDescription("scalar","the value of the selected argument");
      85           4 : }
      86             : 
      87           2 : Select::Select(const ActionOptions&ao):
      88           2 :   Action(ao), Function(ao)
      89             : {
      90             :   // name of selector
      91           2 :   parse("SELECTOR", selector_);
      92             : 
      93           2 :   addValueWithDerivatives(); setNotPeriodic();
      94           2 :   checkRead();
      95             : 
      96           2 :   log.printf("  select based on %s\n",selector_.c_str());
      97           4 :   log << " Bibliography" << plumed.cite("Bonomi, Camilloni, Bioinformatics, 33, 3999 (2017)") << "\n";
      98             : 
      99           2 : }
     100             : 
     101           8 : void Select::calculate()
     102             : {
     103           8 :   unsigned iselect = static_cast<unsigned>(plumed.passMap[selector_]);
     104             : 
     105             :   // check if iselect is smaller than the number of arguments
     106           8 :   if(iselect>=getNumberOfArguments()) error("the value of the SELECTOR is greater than the number of arguments!");
     107             : 
     108             :   // put all the derivatives to zero
     109          24 :   for(unsigned i=0; i<getNumberOfArguments(); ++i) setDerivative(i, 0.0);
     110             : 
     111             :   // set value and derivative for selected argument
     112           8 :   setValue(getArgument(iselect));
     113           8 :   setDerivative(iselect, 1.0);
     114           8 : }
     115             : 
     116             : }
     117             : }
     118             : 

Generated by: LCOV version 1.16