Skip to content

Commit

Permalink
Ensure partial charges are read and retained
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Nov 25, 2023
1 parent 609884b commit e2980fa
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions avogadro/io/cjsonformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,6 @@ bool CjsonFormat::deserialize(std::istream& file, Molecule& molecule,
}
}

// Partial charges are optional, but if present should be loaded.
json partialCharges = atoms["partialCharges"];
if (partialCharges.is_object()) {
// keys are types, values are arrays of charges
for (auto& kv : partialCharges.items()) {
MatrixX charges(atomCount, 1);
if (isNumericArray(kv.value()) && kv.value().size() == atomCount) {
for (size_t i = 0; i < kv.value().size(); ++i) {
charges(i, 0) = kv.value()[i];
}
molecule.setPartialCharges(kv.key(), charges);
}
}
}

// Bonds are optional, but if present should be loaded.
json bonds = jsonRoot["bonds"];
if (bonds.is_object() && isNumericArray(bonds["connections"]["index"])) {
Expand Down Expand Up @@ -609,6 +594,21 @@ bool CjsonFormat::deserialize(std::istream& file, Molecule& molecule,
}
}

// Partial charges are optional, but if present should be loaded.
json partialCharges = atoms["partialCharges"];
if (partialCharges.is_object()) {
// keys are types, values are arrays of charges
for (auto& kv : partialCharges.items()) {
MatrixX charges(atomCount, 1);
if (isNumericArray(kv.value()) && kv.value().size() == atomCount) {
for (size_t i = 0; i < kv.value().size(); ++i) {
charges(i, 0) = kv.value()[i];
}
molecule.setPartialCharges(kv.key(), charges);
}
}
}

if (jsonRoot.find("layer") != jsonRoot.end()) {
auto names = LayerManager::getMoleculeInfo(&molecule);
json visible = jsonRoot["layer"]["visible"];
Expand Down

0 comments on commit e2980fa

Please sign in to comment.