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