From 3d592690aecb2db3f2fe4bf178e710fbebb6f9a6 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Fri, 13 Sep 2024 15:54:42 -0400 Subject: [PATCH] Small patch to parsing XYZ trajectories to handle ORCA 6 separators (#1705) * Small patch to parsing XYZ trajectories to handle ORCA 6 separators Signed-off-by: Geoff Hutchison --- avogadro/io/xyzformat.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/avogadro/io/xyzformat.cpp b/avogadro/io/xyzformat.cpp index 8c042da5e4..3ed855ef94 100644 --- a/avogadro/io/xyzformat.cpp +++ b/avogadro/io/xyzformat.cpp @@ -14,8 +14,7 @@ #include #include -#include -#include +#include #include #include @@ -129,8 +128,13 @@ bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol) // Do we have an animation? size_t numAtoms2; - if (getline(inStream, buffer) && (numAtoms2 = lexicalCast(buffer)) && - numAtoms == numAtoms2) { + // check if the next frame has the same number of atoms + getline(inStream, buffer); // should be the number of atoms + if (buffer.size() == 0 || buffer[0] == '>') { + getline(inStream, buffer); // Orca 6 prints ">" separators + } + + if ((numAtoms2 = lexicalCast(buffer)) && numAtoms == numAtoms2) { getline(inStream, buffer); // Skip the blank mol.setCoordinate3d(mol.atomPositions3d(), 0); int coordSet = 1; @@ -140,6 +144,11 @@ bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol) for (size_t i = 0; i < numAtoms; ++i) { getline(inStream, buffer); + if (inStream.eof()) { + numAtoms2 = 0; + break; // break this inner loop + } + vector tokens(split(buffer, ' ')); if (tokens.size() < 4) { appendError("Not enough tokens in this line: " + buffer); @@ -153,9 +162,21 @@ bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol) mol.setCoordinate3d(positions, coordSet++); - if (!getline(inStream, buffer)) { + if (getline(inStream, buffer)) { + if (inStream.eof()) { + numAtoms2 = 0; + break; // break this inner loop + } + + if (buffer.size() == 0 || buffer[0] == '>') + getline(inStream, buffer); // Orca 6 prints ">" separators + if (inStream.eof()) { + numAtoms2 = 0; + break; // break this inner loop + } + numAtoms2 = lexicalCast(buffer); - if (numAtoms == numAtoms2) + if (numAtoms != numAtoms2) break; }