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 453 : void Ones::registerKeywords(Keywords& keys) { 46 453 : ActionShortcut::registerKeywords( keys ); 47 906 : keys.add("compulsory","SIZE","the number of ones that you would like to create"); 48 453 : keys.setValueDescription("a vector of ones with the required number of elements"); 49 453 : keys.needsAction("CONSTANT"); 50 453 : } 51 : 52 255 : Ones::Ones(const ActionOptions& ao): 53 : Action(ao), 54 255 : ActionShortcut(ao) { 55 : unsigned size; 56 255 : parse("SIZE",size); 57 255 : if( size<1 ) { 58 0 : error("size should be greater than 0"); 59 : } 60 255 : std::string ones="1"; 61 120919 : for(unsigned i=1; i<size; ++i) { 62 : ones +=",1"; 63 : } 64 510 : readInputLine( getShortcutLabel() + ": CONSTANT NOLOG VALUES=" + ones ); 65 255 : } 66 : 67 : } 68 : }