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

Parsing orca output would crash when swapping orbitals #1422

Merged
merged 3 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
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
88 changes: 87 additions & 1 deletion avogadro/quantumio/orca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,26 @@ bool ORCAOutput::read(std::istream& in, Core::Molecule& molecule)
molecule.setVibrationRamanIntensities(m_RamanIntensities);
}

// Do simple bond perception.
// guess bonds and bond orders
molecule.perceiveBondsSimple();
molecule.perceiveBondOrders();

// check 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) {
auto bond = molecule.bond(m_bondOrders[i][0], m_bondOrders[i][1]);
if (bond.isValid() && bond.order() != m_bondOrders[i][2]) {
// if the bond order is different, change it
bond.setOrder(static_cast<unsigned char>(m_bondOrders[i][2]));
}
}
}
}

molecule.setBasisSet(basis);
basis->setMolecule(&molecule);
load(basis);
Expand Down Expand Up @@ -148,6 +164,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 +285,65 @@ 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
Index firstAtom = Core::lexicalCast<Index>(key.substr(2, 3));
Index secondAtom = Core::lexicalCast<Index>(key.substr(9, 3));
double bondOrder = Core::lexicalCast<double>(key.substr(18, 9));

if (bondOrder > 1.6) {
std::vector<int> bond;
bond.push_back(firstAtom);
bond.push_back(secondAtom);
bond.push_back(static_cast<int>(std::round(bondOrder)));
m_bondOrders.push_back(bond);
std::cout << " bond " << firstAtom << " " << secondAtom << " "
<< bondOrder << std::endl;
}

if (key.size() > 54 && key[28] == 'B') {
firstAtom = Core::lexicalCast<Index>(key.substr(30, 3));
secondAtom = Core::lexicalCast<Index>(key.substr(37, 3));
bondOrder = Core::lexicalCast<double>(key.substr(46, 9));

if (bondOrder > 1.6) {
std::vector<int> bond;
bond.push_back(firstAtom);
bond.push_back(secondAtom);
bond.push_back(static_cast<int>(std::round(bondOrder)));
std::cout << " bond " << firstAtom << " " << secondAtom << " "
<< bondOrder << std::endl;
m_bondOrders.push_back(bond);
}
}
if (key.size() > 82 && key[56] == 'B') {
firstAtom = Core::lexicalCast<Index>(key.substr(58, 3));
secondAtom = Core::lexicalCast<Index>(key.substr(65, 3));
bondOrder = Core::lexicalCast<double>(key.substr(74, 9));

if (bondOrder > 1.6) {
std::vector<int> bond;
bond.push_back(firstAtom);
bond.push_back(secondAtom);
bond.push_back(static_cast<int>(std::round(bondOrder)));
std::cout << " bond " << firstAtom << " " << secondAtom << " "
<< bondOrder << std::endl;
m_bondOrders.push_back(bond);
}
}

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 +657,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 +736,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 @@
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 @@
Raman,
Electronic,
NMR,
BondOrders,
NotParsing,
Unrecognized
};
Expand Down
Loading