LCOV - code coverage report
Current view: top level - isdb - Select.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 21 21 100.0 %
Date: 2024-10-18 14:00:25 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           4 :   keys.use("ARG");
      84           8 :   keys.add("compulsory","SELECTOR","name of the variable used to select");
      85           4 :   keys.setValueDescription("the value of the selected argument");
      86           4 : }
      87             : 
      88           2 : Select::Select(const ActionOptions&ao):
      89           2 :   Action(ao), Function(ao)
      90             : {
      91             :   // name of selector
      92           2 :   parse("SELECTOR", selector_);
      93             : 
      94           2 :   addValueWithDerivatives(); setNotPeriodic();
      95           2 :   checkRead();
      96             : 
      97           2 :   log.printf("  select based on %s\n",selector_.c_str());
      98           4 :   log << " Bibliography" << plumed.cite("Bonomi, Camilloni, Bioinformatics, 33, 3999 (2017)") << "\n";
      99             : 
     100           2 : }
     101             : 
     102           8 : void Select::calculate()
     103             : {
     104           8 :   unsigned iselect = static_cast<unsigned>(plumed.passMap[selector_]);
     105             : 
     106             :   // check if iselect is smaller than the number of arguments
     107           8 :   if(iselect>=getNumberOfArguments()) error("the value of the SELECTOR is greater than the number of arguments!");
     108             : 
     109             :   // put all the derivatives to zero
     110          24 :   for(unsigned i=0; i<getNumberOfArguments(); ++i) setDerivative(i, 0.0);
     111             : 
     112             :   // set value and derivative for selected argument
     113           8 :   setValue(getArgument(iselect));
     114           8 :   setDerivative(iselect, 1.0);
     115           8 : }
     116             : 
     117             : }
     118             : }
     119             : 

Generated by: LCOV version 1.16