From 93893d4a406055b70bc50ccdfa0b23521a31f02c Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Sun, 29 Sep 2024 18:10:09 -0400 Subject: [PATCH] Fix XYZ trajectories - prevent final frame with 0,0,0 coords Thanks to brockdyer03 https://discuss.avogadro.cc/t/opening-trajectory-files/5570/11 Signed-off-by: Geoff Hutchison --- avogadro/io/xyzformat.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/avogadro/io/xyzformat.cpp b/avogadro/io/xyzformat.cpp index 3ed855ef94..9c3e391c42 100644 --- a/avogadro/io/xyzformat.cpp +++ b/avogadro/io/xyzformat.cpp @@ -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 positions; positions.reserve(numAtoms); @@ -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 } @@ -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()) {