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 "CLTool.h" 23 : #include "core/CLToolRegister.h" 24 : #include "tools/Tools.h" 25 : #include "core/ActionRegister.h" 26 : #include <cstdio> 27 : #include <string> 28 : #include <iostream> 29 : 30 : namespace PLMD { 31 : namespace cltools { 32 : 33 : //+PLUMEDOC TOOLS gentemplate 34 : /* 35 : gentemplate is a tool that you can use to construct template inputs for the various actions 36 : 37 : The templates generated by this tool are primarily for use with Toni Giorgino's VMD GUI. It may be 38 : useful however to use this tool as a quick aid memoir. 39 : 40 : \par Examples 41 : 42 : The following generates template input for the action DISTANCE. 43 : \verbatim 44 : plumed gentemplate --action DISTANCE 45 : \endverbatim 46 : 47 : 48 : */ 49 : //+ENDPLUMEDOC 50 : 51 : class GenTemplate: 52 : public CLTool { 53 : public: 54 : static void registerKeywords( Keywords& keys ); 55 : explicit GenTemplate(const CLToolOptions& co ); 56 : int main(FILE* in, FILE*out,Communicator& pc) override; 57 4 : std::string description()const override { 58 4 : return "print out a template input for a particular action"; 59 : } 60 : }; 61 : 62 16330 : PLUMED_REGISTER_CLTOOL(GenTemplate,"gentemplate") 63 : 64 5442 : void GenTemplate::registerKeywords( Keywords& keys ) { 65 5442 : CLTool::registerKeywords( keys ); 66 10884 : keys.add("optional","--action","print the template for this particular action"); 67 10884 : keys.addFlag("--list",false,"print a list of the available actions"); 68 10884 : keys.addFlag("--include-optional",false,"also print optional modifiers"); 69 5442 : } 70 : 71 4 : GenTemplate::GenTemplate(const CLToolOptions& co ): 72 4 : CLTool(co) { 73 4 : inputdata=commandline; 74 4 : } 75 : 76 0 : int GenTemplate::main(FILE* in, FILE*out,Communicator& pc) { 77 : 78 : std::string action; 79 0 : bool list_templates=false; 80 0 : parseFlag("--list",list_templates); 81 : 82 0 : if(list_templates) { 83 0 : std::cerr<<actionRegister()<<"\n"; 84 : return 0; 85 0 : } else if(parse("--action",action)) { 86 : bool include_optional; 87 0 : parseFlag("--include-optional",include_optional); 88 0 : if( !actionRegister().printTemplate(action,include_optional) ) { 89 0 : error("there is no registered action named " + action); 90 : return 1; 91 : } 92 : } else { 93 : return 1; 94 : } 95 : 96 : 97 : 98 0 : return 0; 99 : } 100 : } 101 : 102 : } // End of namespace