From 1afc41923eaad02607f758da08770fa4b24fe2fa Mon Sep 17 00:00:00 2001 From: Geoff Hutchison Date: Tue, 15 Oct 2024 21:50:13 -0400 Subject: [PATCH] Fix up partial charges -- need to add after setting bonds Signed-off-by: Geoff Hutchison --- avogadro/io/xyzformat.cpp | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/avogadro/io/xyzformat.cpp b/avogadro/io/xyzformat.cpp index 21378c9715..023fa5ceda 100644 --- a/avogadro/io/xyzformat.cpp +++ b/avogadro/io/xyzformat.cpp @@ -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.) @@ -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 @@ -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;