Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2011-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 : #ifndef __PLUMED_colvar_ColvarShortcut_h 23 : #define __PLUMED_colvar_ColvarShortcut_h 24 : 25 : #include "core/ActionShortcut.h" 26 : 27 : namespace PLMD { 28 : namespace colvar { 29 : 30 : template <class T> 31 : class ColvarShortcut : public ActionShortcut { 32 : public: 33 : static void registerKeywords(Keywords&); 34 : explicit ColvarShortcut(const ActionOptions&); 35 : }; 36 : 37 : template <class T> 38 2020 : void ColvarShortcut<T>::registerKeywords(Keywords& keys ) { 39 2020 : T::registerKeywords( keys ); 40 2020 : keys.remove("NO_ACTION_LOG"); 41 2020 : unsigned nkeys = keys.size(); 42 18925 : for(unsigned i=0; i<nkeys; ++i) { 43 33810 : if( keys.style( keys.get(i), "atoms" ) ) { 44 11670 : keys.reset_style( keys.get(i), "numbered" ); 45 : } 46 : } 47 2020 : keys.addActionNameSuffix("_SCALAR"); 48 2020 : keys.addActionNameSuffix("_VECTOR"); 49 2020 : } 50 : 51 : template <class T> 52 1697 : ColvarShortcut<T>::ColvarShortcut(const ActionOptions&ao): 53 : Action(ao), 54 1697 : ActionShortcut(ao) { 55 : bool scalar=true; 56 1697 : unsigned nkeys = keywords.size(); 57 5064 : if( getName()=="MASS" || getName()=="CHARGE" || getName()=="POSITION" ) { 58 : std::string inpt; 59 306 : parse("ATOMS",inpt); 60 153 : if( inpt.length()>0 ) { 61 114 : readInputLine( getShortcutLabel() + ": " + getName() + "_VECTOR ATOMS=" + inpt + " " + convertInputLineToString() ); 62 : scalar=false; 63 : } 64 : } 65 15908 : for(unsigned i=0; i<nkeys; ++i) { 66 28710 : if( keywords.style( keywords.get(i), "atoms" ) ) { 67 : std::string inpt; 68 10612 : parseNumbered( keywords.get(i), 1, inpt ); 69 5306 : if( inpt.length()>0 ) { 70 288 : readInputLine( getShortcutLabel() + ": " + getName() + "_VECTOR " + keywords.get(i) + "1=" + inpt + " " + convertInputLineToString() ); 71 : scalar=false; 72 : break; 73 : } 74 : } 75 : } 76 1553 : if( scalar ) { 77 3010 : readInputLine( getShortcutLabel() + ": " + getName() + "_SCALAR " + convertInputLineToString() ); 78 : } 79 1703 : } 80 : 81 : } 82 : } 83 : #endif