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 : #include "core/ActionRegister.h" 23 : #include "core/ActionPilot.h" 24 : #include "core/ActionSet.h" 25 : #include "core/PlumedMain.h" 26 : 27 : namespace PLMD { 28 : namespace generic { 29 : 30 : //+PLUMEDOC GENERIC DEBUG 31 : /* 32 : Set some debug options. 33 : 34 : This action can be used while debugging or optimizing plumed. The example 35 : input below demonstates two useful ways you can use the DEBUG command 36 : 37 : ```plumed 38 : # print detailed (action-by-action) timers at the end of simulation 39 : a: DEBUG DETAILED_TIMERS 40 : # dump every two steps which are the atoms required from the MD code 41 : b: DEBUG logRequestedAtoms STRIDE=2 42 : ``` 43 : 44 : */ 45 : //+ENDPLUMEDOC 46 : class Debug: 47 : public ActionPilot { 48 : OFile ofile; 49 : bool logActivity; 50 : bool logRequestedAtoms; 51 : bool novirial; 52 : bool detailedTimers; 53 : public: 54 : explicit Debug(const ActionOptions&ao); 55 : /// Register all the relevant keywords for the action 56 : static void registerKeywords( Keywords& keys ); 57 140 : void calculate() override {} 58 : void apply() override; 59 : }; 60 : 61 : PLUMED_REGISTER_ACTION(Debug,"DEBUG") 62 : 63 8 : void Debug::registerKeywords( Keywords& keys ) { 64 8 : Action::registerKeywords( keys ); 65 8 : ActionPilot::registerKeywords(keys); 66 8 : keys.add("compulsory","STRIDE","1","the frequency with which this action is to be performed"); 67 8 : keys.addFlag("logActivity",false,"write in the log which actions are inactive and which are inactive"); 68 8 : keys.addFlag("logRequestedAtoms",false,"write in the log which atoms have been requested at a given time"); 69 8 : keys.addFlag("NOVIRIAL",false,"switch off the virial contribution for the entirety of the simulation"); 70 8 : keys.addFlag("DETAILED_TIMERS",false,"switch on detailed timers"); 71 8 : keys.add("optional","FILE","the name of the file on which to output these quantities"); 72 8 : } 73 : 74 6 : Debug::Debug(const ActionOptions&ao): 75 : Action(ao), 76 : ActionPilot(ao), 77 6 : logActivity(false), 78 6 : logRequestedAtoms(false), 79 6 : novirial(false) { 80 6 : parseFlag("logActivity",logActivity); 81 6 : if(logActivity) { 82 2 : log.printf(" logging activity\n"); 83 : } 84 6 : parseFlag("logRequestedAtoms",logRequestedAtoms); 85 6 : if(logRequestedAtoms) { 86 2 : log.printf(" logging requested atoms\n"); 87 : } 88 6 : parseFlag("NOVIRIAL",novirial); 89 6 : if(novirial) { 90 0 : log.printf(" Switching off virial contribution\n"); 91 : } 92 6 : if(novirial) { 93 0 : plumed.novirial=true; 94 : } 95 6 : parseFlag("DETAILED_TIMERS",detailedTimers); 96 6 : if(detailedTimers) { 97 2 : log.printf(" Detailed timing on\n"); 98 2 : plumed.detailedTimers=true; 99 : } 100 6 : ofile.link(*this); 101 : std::string file; 102 12 : parse("FILE",file); 103 6 : if(file.length()>0) { 104 2 : ofile.open(file); 105 2 : log.printf(" on file %s\n",file.c_str()); 106 : } else { 107 4 : log.printf(" on plumed log file\n"); 108 4 : ofile.link(log); 109 : } 110 6 : checkRead(); 111 6 : } 112 : 113 140 : void Debug::apply() { 114 140 : if(logActivity) { 115 10 : const ActionSet&actionSet(plumed.getActionSet()); 116 : int a=0; 117 225 : for(const auto & p : actionSet) { 118 215 : if(dynamic_cast<Debug*>(p.get())) { 119 15 : continue; 120 : } 121 200 : if(p->isActive()) { 122 121 : a++; 123 : } 124 : }; 125 10 : if(a>0) { 126 9 : ofile<<"activity at step "<<getStep()<<": "; 127 207 : for(const auto & p : actionSet) { 128 198 : if(dynamic_cast<Debug*>(p.get())) { 129 13 : continue; 130 : } 131 185 : if(p->isActive()) { 132 121 : ofile.printf("+"); 133 : } else { 134 64 : ofile.printf("-"); 135 : } 136 : }; 137 9 : ofile.printf("\n"); 138 : }; 139 : }; 140 140 : if(logRequestedAtoms) { 141 17 : ofile<<"requested atoms at step "<<getStep()<<": "; 142 : const int* l; 143 : int n; 144 17 : plumed.cmd("createFullList",&n); 145 17 : plumed.cmd("getFullList",&l); 146 213 : for(int i=0; i<n; i++) { 147 196 : ofile.printf(" %d",l[i]); 148 : } 149 17 : ofile.printf("\n"); 150 17 : plumed.cmd("clearFullList"); 151 : } 152 : 153 140 : } 154 : 155 : } 156 : } 157 :