58 if (!targetMolForHighlights || !trimHs || targetMolWasTrimmed) {
59 return targetMolForHighlights;
66 int numMolAtoms = targetMolForHighlights->getNumAtoms();
67 std::vector<int> storedAtomMapNums(numMolAtoms);
68 std::vector<std::pair<int, int>> oldBondEnds(
69 targetMolForHighlights->getNumBonds(), std::make_pair(-1, -1));
70 auto atoms = targetMolForHighlights->atoms();
74 std::transform(atoms.begin(), atoms.end(), storedAtomMapNums.begin(),
76 auto res = atom->getAtomMapNum();
77 atom->setAtomMapNum(0);
80 for (
const auto &pair :
rgroups) {
81 auto &combinedMol = pair.second->combinedMol;
82 std::vector<int> bondIndices;
85 std::for_each(bondIndices.begin(), bondIndices.end(),
86 [
this, &oldBondEnds](
const auto &bondIdx) {
88 targetMolForHighlights->getBondWithIdx(bondIdx);
89 const auto beginAtom = bond->getBeginAtom();
90 const auto endAtom = bond->getEndAtom();
91 oldBondEnds[bondIdx].first = beginAtom->getIdx();
92 oldBondEnds[bondIdx].second = endAtom->getIdx();
93 beginAtom->setAtomMapNum(beginAtom->getIdx() + 1);
94 endAtom->setAtomMapNum(endAtom->getIdx() + 1);
99 std::vector<int> oldToNewAtomIndices(numMolAtoms, -1);
103 for (
auto atom : targetMolForHighlights->atoms()) {
104 auto atomMapNum = atom->getAtomMapNum();
107 oldToNewAtomIndices[atomMapNum] = atom->getIdx();
108 atom->setAtomMapNum(storedAtomMapNums.at(atomMapNum));
112 for (
const auto &pair :
rgroups) {
113 auto &combinedMol = pair.second->combinedMol;
114 std::vector<int> atomIndices;
118 atomIndices.begin(), atomIndices.end(), atomIndices.begin(),
119 [&oldToNewAtomIndices](
auto &atomIdx) {
120 auto newAtomIdx = oldToNewAtomIndices.at(atomIdx);
121 CHECK_INVARIANT(newAtomIdx != -1,
"newAtomIdx must be >=0");
126 std::vector<int> bondIndices;
130 bondIndices.begin(), bondIndices.end(), bondIndices.begin(),
131 [
this, &oldBondEnds, &oldToNewAtomIndices](
auto &bondIdx) {
132 const auto &oldPair = oldBondEnds.at(bondIdx);
133 CHECK_INVARIANT(oldPair.first != -1 && oldPair.second != -1,
134 "oldPair members must be >=0");
135 const auto newBeginAtomIdx =
136 oldToNewAtomIndices.at(oldPair.first);
137 const auto newEndAtomIdx = oldToNewAtomIndices.at(oldPair.second);
138 CHECK_INVARIANT(newBeginAtomIdx != -1 && newEndAtomIdx != -1,
139 "newBeginAtomIdx and newEndAtomIdx must be >=0");
140 const auto bond = targetMolForHighlights->getBondBetweenAtoms(
141 newBeginAtomIdx, newEndAtomIdx);
142 CHECK_INVARIANT(bond,
"bond must not be null");
143 return bond->getIdx();
148 targetMolWasTrimmed =
true;
149 return targetMolForHighlights;