Skip to content

Commit

Permalink
Fix up partial charges -- need to add after setting bonds
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Oct 16, 2024
1 parent 6703321 commit 1afc419
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions avogadro/io/xyzformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol)
// we can safely assume species and pos are present
if (tokens[i] == "charge") {
chargeColumn = column;
std::cout << " found charges " << chargeColumn << std::endl;
} else if (tokens[i] == "force" || tokens[i] == "forces") {
forceColumn = column;
} // TODO other properties (velocity, spin, selection, etc.)
Expand Down Expand Up @@ -169,18 +168,6 @@ bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol)
return false;
}

// set the charges
if (!charges.empty()) {
MatrixX chargesMatrix = MatrixX::Zero(mol.atomCount(), 1);
for (size_t i = 0; i < charges.size(); ++i) {
chargesMatrix(i, 0) = charges[i];
}
mol.setPartialCharges("From File", chargesMatrix);

std::cout << "Charges set " << charges.size() << " " << mol.atomCount()
<< std::endl;
}

// Do we have an animation?
size_t numAtoms2;
// check if the next frame has the same number of atoms
Expand Down Expand Up @@ -249,10 +236,14 @@ bool XyzFormat::read(std::istream& inStream, Core::Molecule& mol)
mol.perceiveBondOrders();
}

// check partial charge types
auto types = mol.partialChargeTypes();
for (const auto& type : types) {
std::cout << "Partial charge type: " << type << std::endl;
// have to set the charges after creating bonds
// (since modifying bonds invalidates the partial charges)
if (!charges.empty()) {
MatrixX chargesMatrix = MatrixX::Zero(mol.atomCount(), 1);
for (size_t i = 0; i < charges.size(); ++i) {
chargesMatrix(i, 0) = charges[i];
}
mol.setPartialCharges("From File", chargesMatrix);
}

return true;
Expand Down

0 comments on commit 1afc419

Please sign in to comment.