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 : #include "Colvar.h" 23 : #include "ActionRegister.h" 24 : #include "core/PlumedMain.h" 25 : #include "core/Atoms.h" 26 : 27 : #include <string> 28 : #include <cmath> 29 : 30 : namespace PLMD { 31 : namespace colvar { 32 : 33 : //+PLUMEDOC COLVAR EXTRACV 34 : /* 35 : Allow PLUMED to use collective variables computed in the MD engine. 36 : 37 : This feature requires the MD engine to use special instructions to pass to PLUMED the value of 38 : some pre-computed collective variable. Check the documentation of the MD code to find out which 39 : collective variables can be computed and passed to PLUMED. These variables can then be accessed by 40 : name using the EXTRACV action. 41 : 42 : \par Examples 43 : 44 : This example takes the lambda variable pre-computed in GROMACS and apply to it a restraint to keep 45 : it close to the value 3. 46 : \plumedfile 47 : l: EXTRACV NAME=lambda 48 : RESTRAINT ARG=l KAPPA=10 AT=3 49 : \endplumedfile 50 : 51 : 52 : */ 53 : //+ENDPLUMEDOC 54 : 55 : 56 6 : class ExtraCV : public Colvar { 57 : std::string name; 58 : public: 59 : explicit ExtraCV(const ActionOptions&); 60 : // active methods: 61 : void prepare(); 62 : virtual void calculate(); 63 : unsigned getNumberOfDerivatives(); 64 : static void registerKeywords( Keywords& keys ); 65 : }; 66 : 67 : 68 : using namespace std; 69 : 70 : 71 7360 : PLUMED_REGISTER_ACTION(ExtraCV,"EXTRACV") 72 : 73 2 : ExtraCV::ExtraCV(const ActionOptions&ao): 74 2 : PLUMED_COLVAR_INIT(ao) 75 : { 76 2 : addValueWithDerivatives(); setNotPeriodic(); 77 2 : getPntrToValue()->resizeDerivatives(1); 78 4 : parse("NAME",name); 79 2 : log<<" name: "<<name<<"\n"; 80 2 : isExtraCV=true; 81 : setExtraCV(name); 82 2 : } 83 : 84 3 : void ExtraCV::registerKeywords( Keywords& keys ) { 85 3 : Action::registerKeywords( keys ); 86 3 : ActionAtomistic::registerKeywords( keys ); 87 3 : ActionWithValue::registerKeywords( keys ); 88 6 : keys.remove("NUMERICAL_DERIVATIVES"); 89 12 : keys.add("compulsory","NAME","name of the CV as computed by the MD engine"); 90 3 : } 91 : 92 4 : unsigned ExtraCV::getNumberOfDerivatives() { 93 4 : return 1; 94 : } 95 : 96 40 : void ExtraCV::prepare() { 97 : /// \todo: notify Atoms that this is requested 98 40 : } 99 : 100 : // calculator 101 40 : void ExtraCV::calculate() { 102 80 : double value=plumed.getAtoms().getExtraCV(name); 103 40 : setValue( value ); 104 40 : getPntrToComponent(0)->addDerivative(0,1.0); 105 40 : } 106 : 107 : } 108 5517 : } 109 : 110 : 111 :