Skip to content

Commit

Permalink
Merge pull request #1720 from ghutchis/fix-xyz-trajectories
Browse files Browse the repository at this point in the history
Fix XYZ trajectories - prevent final frame with 0,0,0 coords
  • Loading branch information
ghutchis authored Sep 30, 2024
2 parents e7e395f + 93893d4 commit 69d7958
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion avogadro/io/xyzformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol)
getline(inStream, buffer); // Skip the blank
mol.setCoordinate3d(mol.atomPositions3d(), 0);
int coordSet = 1;
bool done = false;
while (numAtoms == numAtoms2) {
Array<Vector3> positions;
positions.reserve(numAtoms);
Expand All @@ -146,6 +147,7 @@ bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol)
getline(inStream, buffer);
if (inStream.eof()) {
numAtoms2 = 0;
done = true;
break; // break this inner loop
}

Expand All @@ -160,7 +162,8 @@ bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol)
positions.push_back(pos);
}

mol.setCoordinate3d(positions, coordSet++);
if (!done)
mol.setCoordinate3d(positions, coordSet++);

if (getline(inStream, buffer)) {
if (inStream.eof()) {
Expand Down

0 comments on commit 69d7958

Please sign in to comment.