Skip to content

Commit

Permalink
Ensure energies for each frame is reserved
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Nov 22, 2024
1 parent 28f510b commit 6aa00f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
6 changes: 3 additions & 3 deletions avogadro/io/xyzformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ using Core::trimmed;
using std::isalpha;
#endif

bool findEnergy(std::string buffer, double energyValue)
bool findEnergy(const std::string& buffer, double& energyValue)
{
// Check for energy in the comment line
// orca uses E -680.044112849966 (with spaces)
// xtb uses energy: -680.044112849966
// Open Babel uses Energy: -680.044112849966
std::size_t energyStart = buffer.find("energy:");
std::size_t offset = 7;
std::vector<double> energies;
if (energyStart == std::string::npos) {
energyStart = buffer.find("Energy:");
}
if (energyStart == std::string::npos) {
energyStart = buffer.find(" E ");
offset = 3;
}

if (energyStart != std::string::npos) {
// find the next whitespace or end of the string
std::size_t energyEnd = buffer.find_first_of(" \t", energyStart + offset);
Expand All @@ -62,7 +62,7 @@ bool findEnergy(std::string buffer, double energyValue)
energyValue = lexicalCast<double>(energy);
return true;
}
return false; // didn't find an energy
return false;
}

bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol)
Expand Down
15 changes: 12 additions & 3 deletions avogadro/quantumio/orca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,16 @@ bool ORCAOutput::read(std::istream& in, Core::Molecule& molecule)
molecule.setSpectra("NMR", nmrData);
}

// this should be the final coordinate set (e.g. the optimized geometry)
molecule.setCoordinate3d(molecule.atomPositions3d(), 0);
if (m_coordSets.size() > 1) {
for (unsigned int i = 1; i < m_coordSets.size(); i++) {
for (unsigned int i = 0; i < m_coordSets.size(); i++) {
Array<Vector3> positions;
positions.reserve(molecule.atomCount());
for (size_t j = 0; j < molecule.atomCount(); ++j) {
positions.push_back(m_atomPos[j] * BOHR_TO_ANGSTROM);
positions.push_back(m_coordSets[i][j] * BOHR_TO_ANGSTROM);
}
molecule.setCoordinate3d(positions, i);
molecule.setCoordinate3d(positions, i + 1);
}
}

Expand Down Expand Up @@ -145,6 +146,9 @@ bool ORCAOutput::read(std::istream& in, Core::Molecule& molecule)
molecule.setData("totalCharge", m_charge);
molecule.setData("totalSpinMultiplicity", m_spin);
molecule.setData("dipoleMoment", m_dipoleMoment);
molecule.setData("totalEnergy", m_totalEnergy);
if (m_energies.size() > 1)
molecule.setData("energies", m_energies);

return true;
}
Expand Down Expand Up @@ -213,6 +217,11 @@ void ORCAOutput::processLine(std::istream& in, GaussianSet* basis)
list = Core::split(key, ' ');
if (list.size() > 3)
m_spin = Core::lexicalCast<int>(list[3]);
} else if (Core::contains(key, "FINAL SINGLE POINT ENERGY")) {
list = Core::split(key, ' ');
if (list.size() > 4)
m_totalEnergy = Core::lexicalCast<double>(list[4]);
m_energies.push_back(m_totalEnergy);
} else if (Core::contains(key, "TOTAL NUMBER OF BASIS SET")) {
m_currentMode = NotParsing; // no longer reading GTOs
} else if (Core::contains(key, "NUMBER OF CARTESIAN GAUSSIAN BASIS")) {
Expand Down
1 change: 1 addition & 0 deletions avogadro/quantumio/orca.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class AVOGADROQUANTUMIO_EXPORT ORCAOutput : public Io::FileFormat
int m_homo;
int m_charge;
int m_spin;
double m_totalEnergy;

int m_currentAtom;
unsigned int m_numBasisFunctions;
Expand Down

1 comment on commit 6aa00f3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERROR: clang-format-diff detected formatting issues. See the artifact for a patch or run clang-format on your branch.

Please sign in to comment.