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

Make sure Gaussian fchk orbitals are read with eV energies #1958

Merged
merged 1 commit into from
Feb 1, 2025
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
22 changes: 11 additions & 11 deletions avogadro/quantumio/gaussianfchk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ using Core::Rhf;
using Core::Rohf;
using Core::Uhf;

// https://physics.nist.gov/cgi-bin/cuu/Value?hrev
const double hartreeToEV = 27.211386245981;

GaussianFchk::GaussianFchk() : m_scftype(Rhf) {}

GaussianFchk::~GaussianFchk() {}
Expand Down Expand Up @@ -158,17 +161,14 @@ void GaussianFchk::processLine(std::istream& in)
m_csp = readArrayD(in, Core::lexicalCast<int>(list[2]), 16);
} else if (key == "Alpha Orbital Energies") {
if (m_scftype == Rhf) {
m_orbitalEnergy = readArrayD(in, Core::lexicalCast<int>(list[2]), 16);
// cout << "MO energies, n = " << m_orbitalEnergy.size() << endl;
m_orbitalEnergy =
readArrayD(in, Core::lexicalCast<int>(list[2]), 16, hartreeToEV);
} else if (m_scftype == Uhf) {
m_alphaOrbitalEnergy =
readArrayD(in, Core::lexicalCast<int>(list[2]), 16);
// cout << "Alpha MO energies, n = " << m_alphaOrbitalEnergy.size() <<
// endl;
readArrayD(in, Core::lexicalCast<int>(list[2]), 16, hartreeToEV);
}
} else if (key == "Beta Orbital Energies") {
if (m_scftype != Uhf) {
// cout << "UHF detected. Reassigning Alpha properties." << endl;
m_scftype = Uhf;
m_alphaOrbitalEnergy = m_orbitalEnergy;
m_orbitalEnergy = vector<double>();
Expand All @@ -177,8 +177,8 @@ void GaussianFchk::processLine(std::istream& in)
m_MOcoeffs = vector<double>();
}

m_betaOrbitalEnergy = readArrayD(in, Core::lexicalCast<int>(list[2]), 16);
// cout << "Beta MO energies, n = " << m_betaOrbitalEnergy.size() << endl;
m_betaOrbitalEnergy =
readArrayD(in, Core::lexicalCast<int>(list[2]), 16, hartreeToEV);
} else if (key == "Alpha MO coefficients" && list.size() > 2) {
if (m_scftype == Rhf) {
m_MOcoeffs = readArrayD(in, Core::lexicalCast<int>(list[2]), 16);
Expand Down Expand Up @@ -379,7 +379,7 @@ vector<int> GaussianFchk::readArrayI(std::istream& in, unsigned int n)
}

vector<double> GaussianFchk::readArrayD(std::istream& in, unsigned int n,
int width)
int width, double factor)
{
vector<double> tmp;
tmp.reserve(n);
Expand All @@ -402,7 +402,7 @@ vector<double> GaussianFchk::readArrayD(std::istream& in, unsigned int n,
<< tmp.size() << " of " << n << endl;
return tmp;
}
tmp.push_back(Core::lexicalCast<double>(i, ok));
tmp.push_back(Core::lexicalCast<double>(i, ok) * factor);
if (!ok) {
cout << "Warning: problem converting string to integer: " << i
<< " in GaussianFchk::readArrayD.\n";
Expand All @@ -420,7 +420,7 @@ vector<double> GaussianFchk::readArrayD(std::istream& in, unsigned int n,
<< tmp.size() << " of " << n << endl;
return tmp;
}
tmp.push_back(Core::lexicalCast<double>(substring, ok));
tmp.push_back(Core::lexicalCast<double>(substring, ok) * factor);
if (!ok) {
cout << "Warning: problem converting string to double: " << substring
<< " in GaussianFchk::readArrayD.\n";
Expand Down
2 changes: 1 addition & 1 deletion avogadro/quantumio/gaussianfchk.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class AVOGADROQUANTUMIO_EXPORT GaussianFchk : public Io::FileFormat
void load(Core::GaussianSet* basis);
std::vector<int> readArrayI(std::istream& in, unsigned int n);
std::vector<double> readArrayD(std::istream& in, unsigned int n,
int width = 0);
int width = 0, double factor = 1.0);
bool readDensityMatrix(std::istream& in, unsigned int n, int width = 0);
bool readSpinDensityMatrix(std::istream& in, unsigned int n, int width = 0);

Expand Down
Loading