Fix some chirality issues in SMARTS writing/parsing (Issues #2565 & #2568) (#2570)

* forward doIsomericSmiles

* added test for #2565

* fix for my snippet

* update test with Greg's comments

* add braces for readability to MolMatchFinalCheckFunctor

* small refactors: abstract label checking, while/size, final check

* merge loops reading order of bonds -- all tests pass

* fix chiral-lead fragments, allow frags w. degree < 3

* add new test, update old

* add test, update old

* fix (inocuous) bug with ranks assignment in MolToSmarts

* start SMARTS with first non-chiral atom

* use smart pointers in test

* reenable doIsomericSmiles

* update patch for #2594

* remove faulty fragments matching

* review tests, remove wrong flip
This commit is contained in:
Ric
2019-10-03 09:33:46 -04:00
committed by Greg Landrum
parent b87c629e10
commit bb3bdb01ea
6 changed files with 319 additions and 71 deletions

View File

@@ -1090,8 +1090,22 @@ void canonicalizeFragment(ROMol &mol, int atomIdx,
continue;
}
INT_LIST trueOrder = atomTraversalBondOrder[(*atomIt)->getIdx()];
// Test if the atom is in current fragment
if (trueOrder.size() > 0) {
// Check if the atom can be chiral, and if chirality needs inversion
if (trueOrder.size() >= 3) {
// We have to make sure that trueOrder contains all the bonds, even if
// they won't be written to the SMARTS
if (trueOrder.size() < (*atomIt)->getDegree()) {
for (const auto &bndItr :
boost::make_iterator_range(mol.getAtomBonds(*atomIt))) {
int bndIdx = mol[bndItr]->getIdx();
if (std::find(trueOrder.begin(), trueOrder.end(), bndIdx) ==
trueOrder.end()) {
trueOrder.push_back(bndIdx);
break;
}
}
}
int nSwaps = (*atomIt)->getPerturbationOrder(trueOrder);
if (chiralAtomNeedsTagInversion(
mol, *atomIt,
@@ -1165,7 +1179,7 @@ void canonicalizeFragment(ROMol &mol, int atomIdx,
common_properties::_ringStereoAtoms);
BOOST_FOREACH (int nbrV, ringStereoAtoms) {
int nbrIdx = abs(nbrV) - 1;
// Adjust the chiraliy flag of the ring stereo atoms according to
// Adjust the chirality flag of the ring stereo atoms according to
// the first one
if (!ringStereoChemAdjusted[nbrIdx] &&
atomVisitOrders[nbrIdx] >