Skip to content

Commit

Permalink
Merge pull request #308 from drroe/amber_restart_noeol
Browse files Browse the repository at this point in the history
Handle cases where input Amber restart does not have EOL
  • Loading branch information
drroe committed Apr 29, 2016
2 parents ed500eb + 92679ff commit 49155e5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/AmbPDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "Trajout_Single.h"
#include "StringRoutines.h"
#include "Traj_AmberRestart.h"
#define VERSION_STRING "V15.00"
#define VERSION_STRING "V16.00"

static void Help(const char* prgname, bool showAdditional) {
mprinterr("\nUsage: %s -p 'Top' -c 'Coords' [Additional Options]\n"
Expand Down
23 changes: 18 additions & 5 deletions src/Traj_AmberRestart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,18 @@ int Traj_AmberRestart::setupTrajin(FileName const& fname, Topology* trajParm)
natom3_ = restartAtoms * 3;
// Calculate the length of coordinate frame in bytes
infile.SetupFrameBuffer( natom3_, 12, 6 );
// Read past restart coords
if ( infile.ReadFrame() ) {
mprinterr("Error: AmberRestart::setupTrajin(): Error reading coordinates.\n");
return TRAJIN_ERR;
// Read past restart coords
int bytesRead = infile.AttemptReadFrame();
//mprintf("DEBUG: %i bytes read, frame size is %zu\n", bytesRead, infile.FrameSize());
if (bytesRead != (int)infile.FrameSize()) {
// See if we are just missing EOL
if (bytesRead + 1 + (int)infile.IsDos() == (int)infile.FrameSize())
mprintf("Warning: File '%s' missing EOL.\n", infile.Filename().full());
else {
mprinterr("Error: Error reading coordinates from Amber restart '%s'.\n",
infile.Filename().full());
return TRAJIN_ERR;
}
}
// Save coordinates
CRD_.resize( natom3_ );
Expand All @@ -249,7 +257,12 @@ int Traj_AmberRestart::setupTrajin(FileName const& fname, Topology* trajParm)
//mprintf("DEBUG: Restart readSize on second read = %i\n",readSize);
// If 0 no box or velo
if (readSize > 0) {
if (readSize == infile.FrameSize()) {
bool velocitiesRead = (readSize == infile.FrameSize());
if (readSize + 1 + (unsigned int)infile.IsDos() == infile.FrameSize()) {
mprintf("Warning: File '%s' missing EOL.\n", infile.Filename().full());
velocitiesRead = true;
}
if (velocitiesRead) {
// If filled framebuffer again, has velocity info.
hasVel = true;
VEL_.resize( natom3_ );
Expand Down

0 comments on commit 49155e5

Please sign in to comment.