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

Update GAMESS coordinates to store the final version #1276

Merged
merged 2 commits into from Apr 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 17 additions & 17 deletions avogadro/quantumio/gamessus.cpp
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