From 48e1a4ba1986986dd2dbbd3dc95b81e2a728ca58 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Sun, 8 Sep 2024 11:15:31 -0400 Subject: [PATCH 1/2] Small patch to parsing XYZ trajectories to handle ORCA 6 separators Signed-off-by: Geoff Hutchison --- avogadro/io/xyzformat.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/avogadro/io/xyzformat.cpp b/avogadro/io/xyzformat.cpp index 8c042da5e4..64a3988f2b 100644 --- a/avogadro/io/xyzformat.cpp +++ b/avogadro/io/xyzformat.cpp @@ -129,8 +129,12 @@ 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[0] == '<') + getline(inStream, buffer); // Orca 6 prints ">" separators instead + + if ((numAtoms2 = lexicalCast(buffer)) && numAtoms == numAtoms2) { getline(inStream, buffer); // Skip the blank mol.setCoordinate3d(mol.atomPositions3d(), 0); int coordSet = 1; From 2b50616acc3f5826613a169c226f52b350ffe870 Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Fri, 13 Sep 2024 15:53:57 -0400 Subject: [PATCH 2/2] Fixup to read all of Orca trajectory Signed-off-by: Geoff Hutchison --- avogadro/io/xyzformat.cpp | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/avogadro/io/xyzformat.cpp b/avogadro/io/xyzformat.cpp index 64a3988f2b..3ed855ef94 100644 --- a/avogadro/io/xyzformat.cpp +++ b/avogadro/io/xyzformat.cpp @@ -14,8 +14,7 @@ #include #include -#include -#include +#include #include #include @@ -131,8 +130,9 @@ bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol) size_t numAtoms2; // check if the next frame has the same number of atoms getline(inStream, buffer); // should be the number of atoms - if (buffer[0] == '<') - getline(inStream, buffer); // Orca 6 prints ">" separators instead + 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 @@ -144,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); @@ -157,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; }