Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2012-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 : #include "core/ActionShortcut.h" 23 : #include "core/ActionRegister.h" 24 : 25 : namespace PLMD { 26 : namespace generic { 27 : 28 : //+PLUMEDOC COLVAR ONES 29 : /* 30 : Create a constant vector with all elements equal to one 31 : 32 : \par Examples 33 : 34 : */ 35 : //+ENDPLUMEDOC 36 : 37 : class Ones : public ActionShortcut { 38 : public: 39 : static void registerKeywords(Keywords& keys); 40 : explicit Ones(const ActionOptions&); 41 : }; 42 : 43 : PLUMED_REGISTER_ACTION(Ones,"ONES") 44 : 45 451 : void Ones::registerKeywords(Keywords& keys) { 46 451 : ActionShortcut::registerKeywords( keys ); 47 902 : keys.add("compulsory","SIZE","the number of ones that you would like to create"); 48 902 : keys.setValueDescription("scalar/vector","a vector of ones with the required number of elements"); 49 451 : keys.needsAction("CONSTANT"); 50 451 : } 51 : 52 255 : Ones::Ones(const ActionOptions& ao): 53 : Action(ao), 54 255 : ActionShortcut(ao) 55 : { 56 510 : unsigned size; parse("SIZE",size); if( size<1 ) error("size should be greater than 0"); 57 120919 : std::string ones="1"; for(unsigned i=1; i<size; ++i) ones +=",1"; 58 510 : readInputLine( getShortcutLabel() + ": CONSTANT NOLOG VALUES=" + ones ); 59 255 : } 60 : 61 : } 62 : }