Skip to content

Commit

Permalink
Merge pull request #27 from Omegaice/checkpoint_test
Browse files Browse the repository at this point in the history
Checkpoint test
  • Loading branch information
Omegaice committed Feb 26, 2015
2 parents c898f1d + 2d6b2ee commit 63480a7
Show file tree
Hide file tree
Showing 10 changed files with 754 additions and 137 deletions.
60 changes: 19 additions & 41 deletions protomol/module/CheckpointModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,39 @@ using namespace std;
using namespace ProtoMol;

void CheckpointModule::init(ProtoMolApp *app) {
OutputFactory &f = app->outputFactory;
f.registerExemplar(new OutputCheckpoint());
OutputFactory &f = app->outputFactory;
f.registerExemplar(new OutputCheckpoint());
}

void CheckpointModule::configure(ProtoMolApp *app) {
Configuration &config = app->config;

if (!(enabled = config.valid("Checkpoint"))) return;

config["CheckpointPosBase"] = "";
config["CheckpointVelBase"] = "";

if( config.valid("gromacstprfile") ) {
const string temp = config["gromacstprfile"];
config["CheckpointPosBase"] = temp.substr(0, temp.rfind('.')+1);
config["CheckpointVelBase"] = temp.substr(0, temp.rfind('.')+1);
}else{
const string temp = config["posfile"];
config["CheckpointPosBase"] = temp.substr(0, temp.rfind('.') + 1);

if (!config.valid("velfile")) {
config["CheckpointVelBase"] = config["CheckpointPosBase"];
} else {
const string tempv = config["velfile"];
config["CheckpointVelBase"] = tempv.substr(0, tempv.rfind('.') + 1);
}
}
}

void CheckpointModule::read(ProtoMolApp *app) {
if (!enabled) return;
if( !enabled ) { return; }

Configuration &config = app->config;
Configuration &config = app->config;

std::cout << "Reading Checkpoint Base Data" << std::endl;
std::cout << "Reading Checkpoint Base Data" << std::endl;

CheckpointConfigReader confReader;
if (confReader.open(config["Checkpoint"], ios::in)){
confReader.readBase(config, Random::Instance());
}
CheckpointConfigReader confReader;
if( confReader.open(config["Checkpoint"], ios::in)) {
confReader.readBase(config, Random::Instance());
}
}

void CheckpointModule::postBuild(ProtoMolApp *app) {
if (!enabled) return;
if( !enabled ) { return; }

Configuration &config = app->config;
Configuration &config = app->config;

std::cout << "Reading Checkpoint Integrator Data" << std::endl;
// Load integrator data
CheckpointConfigReader confReader;
if (confReader.open(config["Checkpoint"], ios::in)){
confReader.readIntegrator(app->integrator);
}
std::cout << "Reading Checkpoint Integrator Data" << std::endl;
// Load integrator data
CheckpointConfigReader confReader;
if( confReader.open(config["Checkpoint"], ios::in)) {
confReader.readIntegrator(app->integrator);
}
}

string CheckpointModule::WithoutExt(const string &path){
return path.substr(0, path.rfind(".") + 1);
string CheckpointModule::WithoutExt(const string &path) {
return path.substr(0, path.rfind(".") + 1);
}
190 changes: 94 additions & 96 deletions protomol/output/OutputCheckpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,143 +28,141 @@ using namespace ProtoMol;

const string OutputCheckpoint::keyword("Checkpoint");

OutputCheckpoint::OutputCheckpoint(const string &name, int freq, int start,
const string &posbase, const string &velbase)
: Output(freq), current(start), name(name), posBase(posbase), velBase(velbase) {
}

OutputCheckpoint::OutputCheckpoint(const string &name, int freq, int start, const string &posbase, const string &velbase)
: Output(freq), current(start), name(name), posBase(posbase), velBase(velbase) {}

void OutputCheckpoint::doInitialize() {
posBase = app->config["CheckpointPosBase"].get<std::string>();
velBase = app->config["CheckpointVelBase"].get<std::string>();
posBase = app->config["CheckpointPosBase"].get<std::string>();
velBase = app->config["CheckpointVelBase"].get<std::string>();
}


void OutputCheckpoint::doIt(long step) {
cout << "Checkpointing: Step " << step << ". . ." << flush;
cout << "Checkpointing: Step " << step << ". . ." << flush;

WritePositions(step);
WriteVelocities(step);
WriteConfig(step);
WritePositions(step);
WriteVelocities(step);
WriteConfig(step);

// Remove old checkpoint fil
SystemUtilities::unlink(Append(Append(posBase, current - 1), ".pos"));
SystemUtilities::unlink(Append(Append(velBase, current - 1), ".vel"));
// Remove old checkpoint fil
SystemUtilities::unlink(Append(Append(posBase, current - 1), ".pos"));
SystemUtilities::unlink(Append(Append(velBase, current - 1), ".vel"));

current += 1;
current += 1;

cout << "done" << endl;
cout << "done" << endl;
}


void OutputCheckpoint::doRun(long step) {
const long firstStep = toLong(app->config["firststep"]);
const long finalStep = firstStep + toLong(app->config["numsteps"]);

if (step != firstStep && step != finalStep) {
if (getOutputFreq() > 0 && (step % getOutputFreq()) == 0){
doIt(step);
}
}
const long firstStep = toLong(app->config["firststep"]);
const long finalStep = firstStep + toLong(app->config["numsteps"]);

if( step != firstStep && step != finalStep ) {
if( getOutputFreq() > 0 && ( step % getOutputFreq()) == 0 ) {
doIt(step);
}
}
}


Output *OutputCheckpoint::doMake(const vector<Value> &values) const {
return new OutputCheckpoint(values[0], toInt(values[1]), values[2], values[3], values[4]);
return new OutputCheckpoint(values[0], toInt(values[1]), values[2], values[3], values[4]);
}


bool OutputCheckpoint::isIdDefined(const Configuration *config) const {
return config->valid(getId());
return config->valid(getId());
}


void OutputCheckpoint::getParameters(vector<Parameter> &parameter) const {
parameter.push_back
(Parameter(getId(), Value(name, ConstraintValueType::NotEmpty())));

parameter.push_back
(Parameter(getId() + "Freq",
Value(outputFreq, ConstraintValueType::Positive()),
Text("output frequency")));

parameter.push_back
(Parameter(keyword + "Start",
Value(current, ConstraintValueType::NotNegative())));

parameter.push_back
(Parameter(keyword + "PosBase",
Value(posBase, ConstraintValueType::NoConstraints())));

parameter.push_back
(Parameter(keyword + "VelBase",
Value(velBase, ConstraintValueType::NoConstraints())));
parameter.push_back(Parameter(getId(), Value(name, ConstraintValueType::NotEmpty())));
parameter.push_back(Parameter(getId() + "Freq", Value(outputFreq, ConstraintValueType::Positive()), Text("output frequency")));
parameter.push_back(Parameter(getId() + "Start", Value(current, ConstraintValueType::NotNegative())));
parameter.push_back(Parameter(getId() + "PosBase", Value(posBase, ConstraintValueType::NoConstraints())));
parameter.push_back(Parameter(getId() + "VelBase", Value(velBase, ConstraintValueType::NoConstraints())));
}


bool OutputCheckpoint::adjustWithDefaultParameters(vector<Value> &values, const Configuration *config) const {
if (!checkParameterTypes(values)) return false;

if (config->valid(InputOutputfreq::keyword) && !values[1].valid()){
values[1] = (*config)[InputOutputfreq::keyword];
}

if (!values[0].valid()) values[0] = name;
if (!values[2].valid()) values[2] = 0;
if (!values[3].valid()) values[3] = "";
if (!values[4].valid()) values[4] = "";

return checkParameters(values);
if( !checkParameterTypes(values)) { return false; }

if( config->valid(InputOutputfreq::keyword) && !values[1].valid()) {
values[1] = ( *config )[InputOutputfreq::keyword];
}

if( !values[0].valid()) { values[0] = name; }
if( !values[2].valid()) { values[2] = 0; }

if( !values[3].valid()) {
if( config->valid("gromacstprfile") ) {
const std::string temp = (*config)["gromacstprfile"];
values[3] = temp.substr(0, temp.rfind('.') + 1);
} else {
const std::string temp = (*config)["posfile"];
values[3] = temp.substr(0, temp.rfind('.') + 1);
}
}

if( !values[4].valid()) {
if( config->valid("gromacstprfile") ) {
const std::string temp = (*config)["gromacstprfile"];
values[4] = temp.substr(0, temp.rfind('.') + 1);
} else {
if( !config->valid("velfile")) {
values[4] = values[3];
} else {
const std::string temp = (*config)["velfile"];
values[4] = temp.substr(0, temp.rfind('.') + 1);
}
}
}

return checkParameters(values);
}


void OutputCheckpoint::WritePositions(long step) {
string posFile = Append(Append(posBase, current), ".pos");
string posFile = Append(Append(posBase, current), ".pos");

XYZWriter posWriter;
if (!posWriter.open(posFile)){
THROWS("Can't open " << getId() << " '" << posFile + "'.");
}
XYZWriter posWriter;
if( !posWriter.open(posFile)) {
THROWS("Can't open " << getId() << " '" << posFile + "'.");
}

const Vector3DBlock *pos = &app->positions;
posWriter.setComment("Time : " + toString(app->outputCache.getTime()) +
", step : " + toString(step) + ".");
const Vector3DBlock *pos = &app->positions;
posWriter.setComment("Time : " + toString(app->outputCache.getTime()) +
", step : " + toString(step) + ".");

if (!posWriter.write(*pos, app->topology->atoms, app->topology->atomTypes)){
THROWS("Could not write " << getId() << " '" << posFile << "'.");
}
if( !posWriter.write(*pos, app->topology->atoms, app->topology->atomTypes)) {
THROWS("Could not write " << getId() << " '" << posFile << "'.");
}
}


void OutputCheckpoint::WriteVelocities(long step) {
string velFile = Append(Append(velBase, current), ".vel");
string velFile = Append(Append(velBase, current), ".vel");

XYZWriter velWriter;
if (!velWriter.open(velFile))
THROWS("Can't open " << getId() << " '" << velFile << "'.");
XYZWriter velWriter;
if( !velWriter.open(velFile)) {
THROWS("Can't open " << getId() << " '" << velFile << "'.");
}

velWriter.setComment("Time : " + toString(app->outputCache.getTime()) +
", step : " + toString(step) + ".");
velWriter.setComment("Time : " + toString(app->outputCache.getTime()) +
", step : " + toString(step) + ".");

if (!velWriter.write(*&app->velocities, app->topology->atoms,
app->topology->atomTypes))
THROWS("Could not write " << getId() << " '" << velFile << "'.");
if( !velWriter.write(*&app->velocities, app->topology->atoms,
app->topology->atomTypes)) {
THROWS("Could not write " << getId() << " '" << velFile << "'.");
}
}


void OutputCheckpoint::WriteConfig(long step) {
string confFile = name + ".tmp";
string confFile = name + ".tmp";

CheckpointConfigWriter confWriter;
if (!confWriter.open(confFile)){
THROWS("Can't open " << getId() << " '" << confFile << "'.");
}
CheckpointConfigWriter confWriter;
if( !confWriter.open(confFile)) {
THROWS("Can't open " << getId() << " '" << confFile << "'.");
}

if (!confWriter.write(current, step, Random::Instance(), app->integrator)){
THROWS("Could not write " << getId() << " '" << confFile << "'.");
}
if( !confWriter.write(current, step, Random::Instance(), app->integrator)) {
THROWS("Could not write " << getId() << " '" << confFile << "'.");
}

confWriter.close();
confWriter.close();

SystemUtilities::rename(confFile, name);
SystemUtilities::rename(confFile, name);
}
72 changes: 72 additions & 0 deletions test/tests/data/penta-alanine_Checkpoint.point
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
!Checkpoint File!
#ID
0
#Step
10
#Random
1507082917 2109459629 891096348 1657614066 2120453301 159806110 1518592645 460145811 1384610930 2077110158 676412771 1002351362 1973908046 880456280 468840002 764461769 1216987305 1506732020 214254731 174372383 1669346122 517894716 1814612071 1984914822 434400325 105366658 967507942 1508946573 639977699 1370895878 582032630 1371449059 1271381107 517894716
#Integrator
62
8.3899998664856 -46.9000005722046 27.8699994087219
8.43999981880188 -46.4799976348877 26.8600010871887
7.46999979019165 -46.6499996185303 26.3599991798401
9.16000008583069 -47.0499992370605 26.2400007247925
8.73000025749207 -45.0600004196167 26.8700003623962
7.87999987602234 -44.1699981689453 26.8099999427795
10.0100004673004 -44.8000001907349 27.0799994468689
10.5200004577637 -45.6199979782104 27.2900009155273
10.4499995708466 -43.4299993515015 27.5200009346008
9.55999970436096 -42.979998588562 28.1200003623962
11.690000295639 -43.5300016403198 28.4299993515015
11.3199996948242 -44.1699981689453 29.2600011825562
12.4699997901917 -44.0100002288818 27.8699994087219
11.92999958992 -42.5500011444092 28.970000743866
10.6700003147125 -42.519998550415 26.2700009346008
11.0800004005432 -42.9400014877319 25.2099990844727
10.3999996185303 -41.2099981307983 26.4499998092651
10.1900005340576 -40.9999990463257 27.4499988555908
10.8700001239777 -40.149998664856 25.4900002479553
11.4400005340576 -40.5499982833862 24.6199989318848
9.58999991416931 -39.449999332428 24.9699997901917
9.12999987602234 -38.989999294281 25.7500004768372
9.90000009536743 -38.6199998855591 24.3199992179871
8.9300000667572 -40.0500011444092 24.4199991226196
11.7999994754791 -39.1499996185303 26.2199997901917
11.6600000858307 -38.9100003242493 27.4000000953674
12.7400004863739 -38.6700010299683 25.3600001335144
12.6600003242493 -39.0400004386902 24.4000005722046
13.4500002861023 -37.409999370575 25.6900000572205
12.9100000858307 -36.9300007820129 26.4299988746643
14.7599995136261 -37.6900005340576 26.340000629425
15.3699994087219 -38.1800007820129 25.699999332428
15.3199994564056 -36.7300009727478 26.6000008583069
14.7200000286102 -38.2399988174438 27.2900009155273
13.5699999332428 -36.5000009536743 24.3899989128113
13.1599998474121 -36.800000667572 23.2800006866455
14.0199995040894 -35.2600002288818 24.5199990272522
14.210000038147 -34.8699998855591 25.4699993133545
14.3799996376038 -34.3700003623962 23.4200000762939
14.4400000572205 -34.9600005149841 22.5300002098083
13.2599997520447 -33.3200001716614 23.2500004768372
13.2099997997284 -32.5699996948242 24.0499997138977
13.3599996566772 -32.7699995040894 22.3099994659424
12.3000001907349 -33.840000629425 23.2399988174438
15.7599997520447 -33.7599992752075 23.5800004005432
16.3999998569489 -33.9199995994568 24.6499991416931
16.3300001621246 -33.2299995422363 22.5200009346008
15.900000333786 -33.0599999427795 21.6100001335144
17.7499997615814 -32.8999996185303 22.5500011444092
18.2500004768372 -33.7800002098083 22.8800010681152
18.2599997520447 -32.5799989700317 21.1999988555908
17.8699994087219 -31.6400003433228 20.7999992370605
19.3299996852875 -32.6399993896484 21.2100005149841
17.8900003433228 -33.2999992370605 20.4999995231628
18.1500005722046 -31.7700004577637 23.5199999809265
17.3699998855591 -30.9899997711182 24.0599989891052
19.4700002670288 -31.6300010681152 23.7899994850159
20.0399994850159 -32.279999256134 23.2100009918213
20.0399994850159 -30.3999996185303 24.4700002670288
19.650000333786 -29.4799995422363 24.1000008583069
19.889999628067 -30.5100011825562 25.5399990081787
21.1700010299683 -30.3600001335144 24.2799997329712
0.378629040343828 5
Loading

0 comments on commit 63480a7

Please sign in to comment.