Skip to content

Commit

Permalink
added easy restart feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
khavernathy committed Aug 23, 2017
1 parent dbc1fd6 commit 4a3f161
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ src/gui/build-*
src/gui/*.o
src/gui/gui_mcmd.pro.user.*
src/buildgui

saved_data
saved_data/*
1 change: 1 addition & 0 deletions src/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Constants {
double dist_within_radius; // the radius within which to search from origin
int_fast8_t histogram_option = 1; // output histogram data which can be plotted in VMD
int_fast8_t autocenter = 1; // center all atoms about origin automatically. can opt out of it.
int_fast8_t restart_mode = 0; // option to restart job automatically (by searching for restart.pdb)
int_fast8_t no_zero_option = 0; // option to disallow zero sorbates in the simulation. default off.
int_fast8_t simulated_annealing = 0; // sim. ann.
double sa_target = 0.0; // target temperature for annealing.
Expand Down
8 changes: 8 additions & 0 deletions src/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,10 @@ void readInput(System &system, char* filename) {
system.constants.jobname = lc[1].c_str();
std::cout << "Got job name = " << lc[1].c_str(); printf("\n");

} else if (!strcasecmp(lc[0].c_str(),"restart")) {
system.constants.restart_mode = 1;
std::cout << "Got restart option = " << lc[1].c_str(); printf("\n");

} else if (!strcasecmp(lc[0].c_str(), "mode")) {
system.constants.mode = lc[1].c_str();
std::cout << "Got mode = " << lc[1].c_str(); printf("\n");
Expand Down Expand Up @@ -1580,6 +1584,10 @@ void inputValidation(System &system) {
std::cout << "ERROR: You turned the crystal-builder on but did not specify a (correct) dimension to duplicate. e.g., `crystalbuild_y 2` is acceptable but `crystalbuild_y 0` is not. Leave the option off if you don't want to use it. (i.e. x y z are set to 1 by default).";
exit(EXIT_FAILURE);
}
if (e == ENSEMBLE_UVT && system.stats.count_movables <= 0 && system.constants.sorbate_name.size() ==0) {
std::cout << "ERROR: You specified uVT with a system containing no movable molecules and did not specify a desired sorbate. Try `sorbate_name h2_bssp`, for example.";
exit(EXIT_FAILURE);
}

}
// end input validation function
16 changes: 15 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdlib.h>
#include <time.h>
#include <chrono>
#include <sys/stat.h>
//#include <float.h>

// Windows compilation (c11 instead of c++) doesn't auto-define pi.
Expand Down Expand Up @@ -126,7 +127,20 @@ int main(int argc, char **argv) {
System system;
system.checkpoint("setting up system with main functions...");
readInput(system, argv[1]); // executable takes the input file as only argument.
readInAtoms(system, system.constants.atom_file);
if (system.constants.restart_mode) {
// restarting an old job. Make a new saved_data folder e.g. "saved_data4" then overwrite the input file.
int save_folder_number=1;
struct stat sb;
string folder_name = "saved_data"+to_string(save_folder_number);
while (stat(folder_name.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
save_folder_number++;
folder_name = "saved_data"+to_string(save_folder_number);
}
string command = "mkdir "+folder_name+"; cp * "+folder_name+"; cp restart.pdb "+system.constants.atom_file.c_str();
int whatever=std::system(command.c_str());
printf("RESTARTING previous job from input atoms contained in %s/restart.pdb\n",folder_name.c_str());
}
readInAtoms(system, system.constants.atom_file);
paramOverrideCheck(system);
if (system.constants.autocenter)
centerCoordinates(system);
Expand Down

0 comments on commit 4a3f161

Please sign in to comment.