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