Skip to content
Snippets Groups Projects
Commit 38dca77a authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

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
parent a3fc7f33
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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);
......
......@@ -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";
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment