Skip to content

Commit

Permalink
Merge pull request OpenChemistry#1276 from ghutchis/fix-gamess-coordi…
Browse files Browse the repository at this point in the history
…nates

Update GAMESS coordinates to store the final version
  • Loading branch information
ghutchis authored Apr 29, 2023
2 parents be65c67 + ea47c45 commit b4af62d
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions avogadro/quantumio/gamessus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,23 @@ bool GAMESSUSOutput::read(std::istream& in, Core::Molecule& molecule)
{
// Read the log file line by line, most sections are terminated by an empty
// line, so they should be retained.
bool atomsRead(false);
string buffer;
while (getline(in, buffer)) {
if (Core::contains(buffer, "COORDINATES (BOHR)")) {
if (atomsRead)
continue;
atomsRead = true;
readAtomBlock(in, molecule, false);
} else if (Core::contains(buffer, "COORDINATES OF ALL ATOMS ARE (ANGS)")) {
if (atomsRead)
continue;
atomsRead = true;
readAtomBlock(in, molecule, true);
} else if (Core::contains(buffer, "ATOMIC BASIS SET")) {
readBasisSet(in);
} else if (Core::contains(buffer, "CHARGE OF MOLECULE")) {
vector<string> parts = Core::split(buffer, '=');
if (parts.size() == 2)
molecule.setData("totalCharge", Core::lexicalCast<int>(parts[1]));
molecule.setData("totalCharge", Core::lexicalCast<int>(parts[1]));
} else if (Core::contains(buffer, "SPIN MULTIPLICITY")) {
vector<string> parts = Core::split(buffer, '=');
if (parts.size() == 2)
molecule.setData("totalSpinMultiplicity", Core::lexicalCast<int>(parts[1]));
molecule.setData("totalSpinMultiplicity",
Core::lexicalCast<int>(parts[1]));
} else if (Core::contains(buffer, "NUMBER OF ELECTRONS")) {
vector<string> parts = Core::split(buffer, '=');
if (parts.size() == 2)
Expand All @@ -90,11 +84,6 @@ bool GAMESSUSOutput::read(std::istream& in, Core::Molecule& molecule)
readEigenvectors(in);
}
}
if (!atomsRead) {
appendError("Could not find any atomic coordinates! Are you sure this is a "
"GAMESS-US output file?");
return false;
}

// f functions and beyond need to be reordered
reorderMOs();
Expand All @@ -117,10 +106,14 @@ void GAMESSUSOutput::readAtomBlock(std::istream& in, Core::Molecule& molecule,
// We read the atom block in until it terminates with a blank line.
double coordFactor = angs ? 1.0 : BOHR_TO_ANGSTROM_D;
string buffer;

bool atomsExist = molecule.atomCount() > 0;
Index index = 0;
//@TODO - store all the coordinates
while (getline(in, buffer)) {
if (Core::contains(buffer, "CHARGE") || Core::contains(buffer, "------"))
continue;
else if (buffer == "\n") // Our work here is done.
else if (buffer.length() == 0 || buffer == "\n") // Our work here is done.
return;
vector<string> parts = Core::split(buffer, ' ');
if (parts.size() != 5) {
Expand All @@ -142,8 +135,15 @@ void GAMESSUSOutput::readAtomBlock(std::istream& in, Core::Molecule& molecule,
pos.z() = Core::lexicalCast<Real>(parts[4], ok) * coordFactor;
if (!ok)
appendError("Failed to cast to double for position: " + parts[4]);
Atom atom = molecule.addAtom(atomicNumber);
atom.setPosition3d(pos);

Atom atom;
if (!atomsExist) {
atom = molecule.addAtom(atomicNumber, pos);
} else {
atom = molecule.atom(index);
atom.setPosition3d(pos);
index++;
}
}
}

Expand Down

0 comments on commit b4af62d

Please sign in to comment.