Skip to content

Commit

Permalink
Add formal charge support in CJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
aerkiaga committed Mar 12, 2022
1 parent 7d4d91d commit b3705a3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions avogadro/io/cjsonformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ bool CjsonFormat::read(std::istream& file, Molecule& molecule)
}
}

// formal charges
json charges = atoms["charges"];
if (charges.is_array() && charges.size() == atomCount) {
for (size_t i = 0; i < atomCount; ++i) {
molecule.atom(i).setFormalCharge(charges[i]);
}
}

// Check for coordinate sets, and read them in if found, e.g. trajectories.
json coordSets = atoms["coords"]["3dSets"];
if (coordSets.is_array() && coordSets.size()) {
Expand Down Expand Up @@ -754,6 +762,13 @@ bool CjsonFormat::write(std::ostream& file, const Molecule& molecule)
}
root["atoms"]["labels"] = labels;

// formal charges
json charges;
for (size_t i = 0; i < molecule.atomCount(); ++i) {
charges.push_back(molecule.formalCharge(i));
}
root["atoms"]["charges"] = charges;

auto layer = LayerManager::getMoleculeInfo(&molecule)->layer;
if (layer.atomCount()) {
json atomLayer;
Expand Down

0 comments on commit b3705a3

Please sign in to comment.