Skip to content

Commit

Permalink
Small patch to parsing XYZ trajectories to handle ORCA 6 separators (#…
Browse files Browse the repository at this point in the history
…1705)

* Small patch to parsing XYZ trajectories to handle ORCA 6 separators

Signed-off-by: Geoff Hutchison <geoff.hutchison@gmail.com>
  • Loading branch information
ghutchis authored Sep 13, 2024
1 parent d8af562 commit 3d59269
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions avogadro/io/xyzformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
#include <nlohmann/json.hpp>

#include <iomanip>
#include <istream>
#include <ostream>
#include <iostream>
#include <sstream>
#include <string>

Expand Down Expand Up @@ -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<int>(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<int>(buffer)) && numAtoms == numAtoms2) {
getline(inStream, buffer); // Skip the blank
mol.setCoordinate3d(mol.atomPositions3d(), 0);
int coordSet = 1;
Expand All @@ -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<string> tokens(split(buffer, ' '));
if (tokens.size() < 4) {
appendError("Not enough tokens in this line: " + buffer);
Expand All @@ -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<int>(buffer);
if (numAtoms == numAtoms2)
if (numAtoms != numAtoms2)
break;
}

Expand Down

0 comments on commit 3d59269

Please sign in to comment.