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