Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small patch to parsing XYZ trajectories to handle ORCA 6 separators #1705

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

// 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 @@

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 @@

mol.setCoordinate3d(positions, coordSet++);

if (!getline(inStream, buffer)) {
if (getline(inStream, buffer)) {
if (inStream.eof()) {
numAtoms2 = 0;

Check notice on line 167 in avogadro/io/xyzformat.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

avogadro/io/xyzformat.cpp#L167

Variable 'numAtoms2' is assigned a value that is never used.
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
Loading