Skip to content

Commit

Permalink
Merge pull request #1502 from ghutchis/assign-charges-table
Browse files Browse the repository at this point in the history
If no partial charges are assigned, set them
  • Loading branch information
ghutchis committed Dec 5, 2023
2 parents 7dce487 + 66f230b commit f276a10
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions avogadro/qtplugins/propertytables/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ avogadro_plugin(PropertyTables
PropertyTables
"propertytables.cpp;propertymodel.cpp;propertyview.cpp"
)

target_link_libraries(PropertyTables PRIVATE Avogadro::Calc)
23 changes: 23 additions & 0 deletions avogadro/qtplugins/propertytables/propertymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "propertymodel.h"

#include <avogadro/calc/chargemanager.h>
#include <avogadro/core/atom.h>
#include <avogadro/core/bond.h>
#include <avogadro/core/elements.h>
Expand Down Expand Up @@ -135,6 +136,28 @@ QString partialCharge(Molecule* molecule, int atom)
auto first = types.cbegin();
MatrixX charges = molecule->partialCharges((*first));
charge = charges(atom, 0);
} else {
// find something
const auto options =
Calc::ChargeManager::instance().identifiersForMolecule(*molecule);
if (options.size() > 0) {
// look for GFN2 or AM1BCC, then MMFF94 then Gasteiger
std::string type;
if (options.find("GFN2") != options.end())
type = "GFN2";
else if (options.find("am1bcc") != options.end())
type = "am1bcc";
else if (options.find("mmff94") != options.end())
type = "mmff94";
else if (options.find("gasteiger") != options.end())
type = "gasteiger";
else
type = *options.begin();

MatrixX charges =
Calc::ChargeManager::instance().partialCharges(type, *molecule);
charge = charges(atom, 0);
}
}
return QString("%L1").arg(charge, 0, 'f', 3);
}
Expand Down

0 comments on commit f276a10

Please sign in to comment.