Skip to content

Commit

Permalink
Merge pull request #1799 from ghutchis/orca-nmr
Browse files Browse the repository at this point in the history
Parse NMR spectra from Orca
  • Loading branch information
ghutchis authored Nov 19, 2024
2 parents 519658f + 8b97f41 commit 344e18b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
44 changes: 41 additions & 3 deletions avogadro/quantumio/orca.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,26 @@ bool ORCAOutput::read(std::istream& in, Core::Molecule& molecule)
electronicData(i, 1) = m_electronicIntensities[i];
}
molecule.setSpectra("Electronic", electronicData);
std::cout << "UV/Vis data found." << electronicData.rows() << std::endl;
if (m_electronicRotations.size() == m_electronicTransitions.size()) {
MatrixX electronicRotations(m_electronicTransitions.size(), 2);
for (size_t i = 0; i < m_electronicTransitions.size(); ++i) {
electronicRotations(i, 0) = m_electronicTransitions[i];
electronicRotations(i, 1) = m_electronicRotations[i];
}
molecule.setSpectra("CircularDichroism", electronicRotations);
std::cout << "CircularDichroism data found." << electronicRotations.rows()
<< std::endl;
}
}

if (m_nmrShifts.size() > 0) {
MatrixX nmrData(m_nmrShifts.size(), 2);
// nmr_shifts has an entry for every atom even if not computed
for (size_t i = 0; i < m_nmrShifts.size(); ++i) {
nmrData(i, 0) = m_nmrShifts[i];
nmrData(i, 1) = 1.0;
}
molecule.setSpectra("NMR", nmrData);
}

// guess bonds and bond orders
molecule.perceiveBondsSimple();
molecule.perceiveBondOrders();
Expand Down Expand Up @@ -281,6 +288,11 @@ void ORCAOutput::processLine(std::istream& in, GaussianSet* basis)
getline(in, key); // skip blank line
getline(in, key); // skip column titles
getline(in, key); // skip ------------
} else if (Core::contains(key, "CHEMICAL SHIELDING SUMMARY (ppm)")) {
m_currentMode = NMR;
for (int i = 0; i < 4; ++i) {
getline(in, key); // skip header
}
} else {

vector<vector<double>> columns;
Expand Down Expand Up @@ -618,6 +630,32 @@ void ORCAOutput::processLine(std::istream& in, GaussianSet* basis)
}
m_currentMode = NotParsing;
}
case NMR: {
if (key.empty())
break;
list = Core::split(key, ' ');
// default to filling m_nmrShifts with zeros
m_nmrShifts.resize(m_atomNums.size(), 0.0);
while (!key.empty()) {
// should have 4 columns
if (list.size() != 4) {
break;
}

// e.g. 1 C 0.0000 0.0000 0.0000 0.0000
int atomIndex = Core::lexicalCast<int>(list[0]);
double shift = Core::lexicalCast<double>(list[2]);
// ignore the anisotropy for now
m_nmrShifts[atomIndex] = shift;

getline(in, key);
key = Core::trimmed(key);
list = Core::split(key, ' ');
}

m_currentMode = NotParsing;
break;
}
case GTO: {
// // should start at the first newGTO
if (key.empty())
Expand Down
2 changes: 2 additions & 0 deletions avogadro/quantumio/orca.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class AVOGADROQUANTUMIO_EXPORT ORCAOutput : public Io::FileFormat
Core::Array<double> m_electronicTransitions; // in eV
Core::Array<double> m_electronicIntensities;
Core::Array<double> m_electronicRotations; // for CD

Core::Array<double> m_nmrShifts; // for NMR (in ppm)
};

} // namespace QuantumIO
Expand Down

0 comments on commit 344e18b

Please sign in to comment.