Skip to content

Commit

Permalink
Fix reading formal charges
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Nov 8, 2024
1 parent 0c9b5ec commit e815396
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions avogadro/io/mdlformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,15 @@ bool MdlFormat::readV3000(std::istream& in, Core::Molecule& mol)
newAtom.setPosition3d(pos);
// check for formal charge in the atom block
// CHG=1 for example
if (atomData.size() > 7) {
string chargeData = atomData[7];
if (atomData.size() > 8) {
string chargeData = atomData[8];
if (startsWith(chargeData, "CHG=")) {
int charge = lexicalCast<int>(chargeData.substr(4), ok);
if (!ok) {
appendError("Failed to parse atom charge: " + chargeData);
return false;
}
mol.setFormalCharge(newAtom.index(), charge);
newAtom.setFormalCharge(charge);
}
}
} // end of atom block
Expand Down

0 comments on commit e815396

Please sign in to comment.