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 : The following input creates and outputs a constant vector with 10 elements that are all equal to one 33 : 34 : ```plumed 35 : ones: ONES SIZE=10 36 : PRINT ARG=ones FILE=onesfile 37 : ``` 38 : 39 : Notice that the ONES action is a shortcut to [CONSTANT](CONSTANT.md). 40 : 41 : This action is used extensively when calculating coordination numbers in inputs similar to this one: 42 : 43 : ```plumed 44 : c1: CONTACT_MATRIX GROUP=1-7 SWITCH={RATIONAL R_0=2.6 NN=6 MM=12} 45 : ones: ONES SIZE=7 46 : cc: MATRIX_VECTOR_PRODUCT ARG=c1,ones 47 : PRINT ARG=cc FILE=colvar 48 : ``` 49 : 50 : For more information on why this is useful see [CONTACT_MATRIX](CONTACT_MATRIX.md) 51 : 52 : */ 53 : //+ENDPLUMEDOC 54 : 55 : class Ones : public ActionShortcut { 56 : public: 57 : static void registerKeywords(Keywords& keys); 58 : explicit Ones(const ActionOptions&); 59 : }; 60 : 61 : PLUMED_REGISTER_ACTION(Ones,"ONES") 62 : 63 451 : void Ones::registerKeywords(Keywords& keys) { 64 451 : ActionShortcut::registerKeywords( keys ); 65 451 : keys.add("compulsory","SIZE","the number of ones that you would like to create"); 66 902 : keys.setValueDescription("scalar/vector","a vector of ones with the required number of elements"); 67 451 : keys.needsAction("CONSTANT"); 68 451 : } 69 : 70 255 : Ones::Ones(const ActionOptions& ao): 71 : Action(ao), 72 255 : ActionShortcut(ao) { 73 : unsigned size; 74 255 : parse("SIZE",size); 75 255 : if( size<1 ) { 76 0 : error("size should be greater than 0"); 77 : } 78 255 : std::string ones="1"; 79 120919 : for(unsigned i=1; i<size; ++i) { 80 : ones +=",1"; 81 : } 82 510 : readInputLine( getShortcutLabel() + ": CONSTANT NOLOG VALUES=" + ones ); 83 255 : } 84 : 85 : } 86 : }