From 38dca77a8f102cfb94e75618a14456afb6bb74e5 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Tue, 21 Apr 2015 20:49:20 +0200 Subject: [PATCH] Implemented possibility to pass restart flag from MD Added a new cmd "setRestart" that allow setting restart from MD engine. This setting can be overridden by PLUMED using: RESTART or RESTART OFF to respectively switch on or off restart from PLUMED input. Notice that this would break compatibility in the sense that it would turn on restart automatically without the user specifying it. I increased the APIversion to 3 so that MD engines can check if PLUMED support this keyword before using it. This fixes #100 --- developer-doc/mdTemplate.txt | 6 +++++- src/core/PlumedMain.cpp | 10 ++++++++-- src/setup/Restart.cpp | 16 ++++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/developer-doc/mdTemplate.txt b/developer-doc/mdTemplate.txt index 709bd4171..747cc3eb9 100644 --- a/developer-doc/mdTemplate.txt +++ b/developer-doc/mdTemplate.txt @@ -199,7 +199,11 @@ plumed_cmd(plumedmain,"setLog",fplog); // Pass the file plumed_cmd(plumedmain,"setLogFile",fplog); // Pass the file on which to write out the plumed log (to be created) plumed_cmd(plumedmain,"setTimestep",&delta_t); // Pass a pointer to the molecular dynamics timestep to plumed -plumed_cmd(plumedmain,"setKbT",&kbT); // Tell to PLUMED the value of kbT - ONLY VALID IF API VERSION > 1 +// This is valid only if API VERSION > 1 +plumed_cmd(plumedmain,"setKbT",&kbT); // Pointer to a real containing the value of kbT + +// This is valid only if API VERSION > 2 +plumed_cmd(plumedmain,"setRestart",&res); // Pointer to an integer saying if we are restarting (zero means no, one means yes) // Calls to do the actual initialization (all the above commands must appear before this call) plumed_cmd(plumedmain,"init",NULL); // Do all the initialization of plumed diff --git a/src/core/PlumedMain.cpp b/src/core/PlumedMain.cpp index 18ebee0b2..e93e70401 100644 --- a/src/core/PlumedMain.cpp +++ b/src/core/PlumedMain.cpp @@ -47,7 +47,7 @@ using namespace std; -enum { SETBOX, SETPOSITIONS, SETMASSES, SETCHARGES, SETPOSITIONSX, SETPOSITIONSY, SETPOSITIONSZ, SETVIRIAL, SETENERGY, SETFORCES, SETFORCESX, SETFORCESY, SETFORCESZ, CALC, PREPAREDEPENDENCIES, SHAREDATA, PREPARECALC, PERFORMCALC, SETSTEP, SETSTEPLONG, SETATOMSNLOCAL, SETATOMSGATINDEX, SETATOMSFGATINDEX, SETATOMSCONTIGUOUS, CREATEFULLLIST, GETFULLLIST, CLEARFULLLIST, READ, CLEAR, GETAPIVERSION, INIT, SETREALPRECISION, SETMDLENGTHUNITS, SETMDENERGYUNITS, SETMDTIMEUNITS, SETNATURALUNITS, SETNOVIRIAL, SETPLUMEDDAT, SETMPICOMM, SETMPIFCOMM, SETMPIMULTISIMCOMM, SETNATOMS, SETTIMESTEP, SETMDENGINE, SETLOG, SETLOGFILE, SETSTOPFLAG, GETEXCHANGESFLAG, SETEXCHANGESSEED, SETNUMBEROFREPLICAS, GETEXCHANGESLIST, RUNFINALJOBS, ISENERGYNEEDED, GETBIAS, SETKBT }; +enum { SETBOX, SETPOSITIONS, SETMASSES, SETCHARGES, SETPOSITIONSX, SETPOSITIONSY, SETPOSITIONSZ, SETVIRIAL, SETENERGY, SETFORCES, SETFORCESX, SETFORCESY, SETFORCESZ, CALC, PREPAREDEPENDENCIES, SHAREDATA, PREPARECALC, PERFORMCALC, SETSTEP, SETSTEPLONG, SETATOMSNLOCAL, SETATOMSGATINDEX, SETATOMSFGATINDEX, SETATOMSCONTIGUOUS, CREATEFULLLIST, GETFULLLIST, CLEARFULLLIST, READ, CLEAR, GETAPIVERSION, INIT, SETREALPRECISION, SETMDLENGTHUNITS, SETMDENERGYUNITS, SETMDTIMEUNITS, SETNATURALUNITS, SETNOVIRIAL, SETPLUMEDDAT, SETMPICOMM, SETMPIFCOMM, SETMPIMULTISIMCOMM, SETNATOMS, SETTIMESTEP, SETMDENGINE, SETLOG, SETLOGFILE, SETSTOPFLAG, GETEXCHANGESFLAG, SETEXCHANGESSEED, SETNUMBEROFREPLICAS, GETEXCHANGESLIST, RUNFINALJOBS, ISENERGYNEEDED, GETBIAS, SETKBT, SETRESTART }; namespace PLMD{ @@ -134,6 +134,7 @@ PlumedMain::PlumedMain(): word_map["isEnergyNeeded"]=ISENERGYNEEDED; word_map["getBias"]=GETBIAS; word_map["setKbT"]=SETKBT; + word_map["setRestart"]=SETRESTART; } PlumedMain::~PlumedMain(){ @@ -300,7 +301,7 @@ void PlumedMain::cmd(const std::string & word,void*val){ break; case GETAPIVERSION: CHECK_NULL(val,word); - *(static_cast<int*>(val))=2; + *(static_cast<int*>(val))=3; break; // commands which can be used only before initialization: case INIT: @@ -375,6 +376,11 @@ void PlumedMain::cmd(const std::string & word,void*val){ CHECK_NULL(val,word); atoms.setKbT(val); break; + case SETRESTART: /* ADDED WITH API==3 */ + CHECK_NOTINIT(initialized,word); + CHECK_NULL(val,word); + if(*static_cast<int*>(val)!=0) restart=true; + break; case SETMDENGINE: CHECK_NOTINIT(initialized,word); CHECK_NULL(val,word); diff --git a/src/setup/Restart.cpp b/src/setup/Restart.cpp index f640627de..a8efa8d1f 100644 --- a/src/setup/Restart.cpp +++ b/src/setup/Restart.cpp @@ -95,14 +95,26 @@ PLUMED_REGISTER_ACTION(Restart,"RESTART") void Restart::registerKeywords( Keywords& keys ){ ActionSetup::registerKeywords(keys); + keys.addFlag("NO",false,"switch off restart - can be used to override the behavior of the MD engine"); } Restart::Restart(const ActionOptions&ao): Action(ao), ActionSetup(ao) { - plumed.setRestart(true); - log<<"Restarting simulation: files will be appended\n"; + bool no=false; + parseFlag("NO",no); + bool md=plumed.getRestart(); + log<<" MD code "<<(md?"did":"didn't")<<" require restart\n"; + if(no){ + if(md) log<<" Switching off restart\n"; + plumed.setRestart(false); + log<<" Not restarting simulation: files will be backed up\n"; + } else { + if(!md) log<<" Switching on restart\n"; + plumed.setRestart(true); + log<<" Restarting simulation: files will be appended\n"; + } } } -- GitLab