Skip to content

Commit

Permalink
Parsing orca output would crash when swapping orbitals
Browse files Browse the repository at this point in the history
Probably just masks the underlying problem, but I need more examples
https://discuss.avogadro.cc/t/cant-open-a-out-file-in-1-98-0/

Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Oct 28, 2023
1 parent 21faabd commit 7bca87b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
39 changes: 38 additions & 1 deletion avogadro/quantumio/orca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,22 @@ bool ORCAOutput::read(std::istream& in, Core::Molecule& molecule)
molecule.setVibrationRamanIntensities(m_RamanIntensities);
}

// Do simple bond perception.
// for now, do simple bond perception
molecule.perceiveBondsSimple();
molecule.perceiveBondOrders();

// add bonds from calculated bond orders
if (m_bondOrders.size() > 0) {
for (unsigned int i = 0; i < m_bondOrders.size(); i++) {
// m_bondOrders[i][0] is the first atom
// m_bondOrders[i][1] is the second atom
// m_bondOrders[i][2] is the bond order
if (m_bondOrders[i].size() > 2)
molecule.addBond(m_bondOrders[i][0], m_bondOrders[i][1],
static_cast<unsigned char>(m_bondOrders[i][2]));
}
}

molecule.setBasisSet(basis);
basis->setMolecule(&molecule);
load(basis);
Expand Down Expand Up @@ -148,6 +160,9 @@ void ORCAOutput::processLine(std::istream& in, GaussianSet* basis)
} else if (Core::contains(key, "Number of Electrons")) {
list = Core::split(key, ' ');
m_electrons = Core::lexicalCast<int>(list[5]);
} else if (Core::contains(key, "Mayer bond orders")) {
m_currentMode = BondOrders;
// starts at the next line
} else if (Core::contains(key, "ORBITAL ENERGIES")) {
m_currentMode = OrbitalEnergies;
getline(in, key); // skip ------------
Expand Down Expand Up @@ -266,6 +281,20 @@ void ORCAOutput::processLine(std::istream& in, GaussianSet* basis)
m_currentMode = NotParsing;
break;
}
case BondOrders: {
if (key.empty())
break;

m_bondOrders.clear();
while (key[0] == "B") {
// @todo .. parse the bonds based on character position
// e.g. B( 0-Ru, 1-C ) : 0.4881 B( 0-Ru, 4-C ) : 0.6050
getline(in, key);
key = Core::trimmed(key);
}

m_currentMode = NotParsing;
}
case OrbitalEnergies: {
// should start at the first orbital
if (!m_readBeta)
Expand Down Expand Up @@ -579,10 +608,14 @@ void ORCAOutput::processLine(std::istream& in, GaussianSet* basis)
while (idx < orcaOrbitals.size()) {
if (Core::contains(orcaOrbitals.at(idx), "pz")) {
for (unsigned int i = 0; i < numColumns; i++) {
if (idx + 1 >= columns[i].size())
break;
std::swap(columns[i].at(idx), columns[i].at(idx + 1));
}
idx++;
for (unsigned int i = 0; i < numColumns; i++) {
if (idx + 1 >= columns[i].size())
break;
std::swap(columns[i].at(idx), columns[i].at(idx + 1));
}
idx++;
Expand Down Expand Up @@ -654,10 +687,14 @@ void ORCAOutput::processLine(std::istream& in, GaussianSet* basis)
while (idx < orcaOrbitals.size()) {
if (Core::contains(orcaOrbitals.at(idx), "pz")) {
for (unsigned int i = 0; i < numColumns; i++) {
if (idx + 1 >= columns[i].size())
break;
std::swap(columns[i].at(idx), columns[i].at(idx + 1));
}
idx++;
for (unsigned int i = 0; i < numColumns; i++) {
if (idx + 1 >= columns[i].size())
break;
std::swap(columns[i].at(idx), columns[i].at(idx + 1));
}
idx++;
Expand Down
3 changes: 3 additions & 0 deletions avogadro/quantumio/orca.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class AVOGADROQUANTUMIO_EXPORT ORCAOutput : public Io::FileFormat
std::vector<int> m_atomNums;
std::vector<Eigen::Vector3d> m_atomPos;

std::vector<std::vector<int>> m_bondOrders;

Check notice on line 65 in avogadro/quantumio/orca.h

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

avogadro/quantumio/orca.h#L65

class member 'ORCAOutput::m_bondOrders' is never used.

std::vector<int> shellFunctions;
std::vector<Core::GaussianSet::orbital> shellTypes;
std::vector<std::vector<int>> m_orcaNumShells;
Expand All @@ -83,6 +85,7 @@ class AVOGADROQUANTUMIO_EXPORT ORCAOutput : public Io::FileFormat
Raman,
Electronic,
NMR,
BondOrders,
NotParsing,
Unrecognized
};
Expand Down

0 comments on commit 7bca87b

Please sign in to comment.