LCOV - code coverage report
Current view: top level - setup - Restart.cpp (source / functions) Hit Total Coverage
Test: plumed test coverage Lines: 18 18 100.0 %
Date: 2024-10-18 14:00:25 Functions: 2 3 66.7 %

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

Generated by: LCOV version 1.16