Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2012-2020 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/ActionSetup.h" 23 : #include "core/ActionRegister.h" 24 : #include "core/PlumedMain.h" 25 : #include "tools/Exception.h" 26 : 27 : using namespace std; 28 : 29 : namespace PLMD { 30 : namespace setup { 31 : 32 : //+PLUMEDOC GENERIC RESTART 33 : /* 34 : Activate restart. 35 : 36 : This is a Setup directive and, as such, should appear 37 : at the beginning of the input file. It influences the way 38 : PLUMED treat files open for writing (see also \ref Files). 39 : 40 : Notice that it is also possible to enable or disable restart on a per-action 41 : basis using the RESTART keyword on a single action. In this case, 42 : the keyword should be assigned a value. RESTART=AUTO means that global 43 : settings are used, RESTART=YES or RESTART=NO respectively enable 44 : and disable restart for that single action. 45 : 46 : \attention 47 : This directive can have also other side effects, e.g. on \ref METAD 48 : and \ref PBMETAD and on some analysis action. 49 : 50 : \par Examples 51 : 52 : Using the following input: 53 : \plumedfile 54 : d: DISTANCE ATOMS=1,2 55 : PRINT ARG=d FILE=out 56 : \endplumedfile 57 : a new 'out' file will be created. If an old one is on the way, it will be automatically backed up. 58 : 59 : On the other hand, using the following input: 60 : \plumedfile 61 : RESTART 62 : d: DISTANCE ATOMS=1,2 63 : PRINT ARG=d FILE=out 64 : \endplumedfile 65 : the file 'out' will be appended. 66 : 67 : In the following case, file out1 will be backed up and file out2 will be concatenated 68 : \plumedfile 69 : RESTART 70 : d1: DISTANCE ATOMS=1,2 71 : d2: DISTANCE ATOMS=1,2 72 : PRINT ARG=d1 FILE=out1 RESTART=NO 73 : PRINT ARG=d2 FILE=out2 74 : \endplumedfile 75 : 76 : In the following case, file out will backed up even if the MD code thinks that we 77 : are restarting. Notice that not all the MD code send to PLUMED information about restarts. 78 : If you are not sure, always put `RESTART` when you are restarting and nothing when you aren't 79 : \plumedfile 80 : RESTART NO 81 : d1: DISTANCE ATOMS=1,2 82 : PRINT ARG=d1 FILE=out1 83 : \endplumedfile 84 : 85 : 86 : 87 : 88 : 89 : */ 90 : //+ENDPLUMEDOC 91 : 92 78 : class Restart : 93 : public virtual ActionSetup 94 : { 95 : public: 96 : static void registerKeywords( Keywords& keys ); 97 : explicit Restart(const ActionOptions&ao); 98 : }; 99 : 100 7434 : PLUMED_REGISTER_ACTION(Restart,"RESTART") 101 : 102 40 : void Restart::registerKeywords( Keywords& keys ) { 103 40 : ActionSetup::registerKeywords(keys); 104 120 : keys.addFlag("NO",false,"switch off restart - can be used to override the behavior of the MD engine"); 105 40 : } 106 : 107 39 : Restart::Restart(const ActionOptions&ao): 108 : Action(ao), 109 39 : ActionSetup(ao) 110 : { 111 39 : bool no=false; 112 78 : parseFlag("NO",no); 113 39 : bool md=plumed.getRestart(); 114 39 : log<<" MD code "<<(md?"did":"didn't")<<" require restart\n"; 115 39 : if(no) { 116 0 : if(md) log<<" Switching off restart\n"; 117 0 : plumed.setRestart(false); 118 0 : log<<" Not restarting simulation: files will be backed up\n"; 119 : } else { 120 39 : if(!md) log<<" Switching on restart\n"; 121 39 : plumed.setRestart(true); 122 39 : log<<" Restarting simulation: files will be appended\n"; 123 : } 124 39 : } 125 : 126 : } 127 5517 : }