mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
* fixes #3967 * modernize test Co-authored-by: greg landrum <greg.landrum@gmail.com>
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -8,6 +8,8 @@
|
||||
#- Eclipse files
|
||||
/.project
|
||||
/.pydevproject
|
||||
/.cproject
|
||||
/.settings/
|
||||
|
||||
#- CLion files
|
||||
/cmake-build-*
|
||||
|
||||
@@ -350,10 +350,25 @@ void canonicalizeDoubleBond(Bond *dblBond, UINT_VECT &bondVisitOrders,
|
||||
// If we're not looking at the bonds used to determine the
|
||||
// stereochemistry, we need to flip the setting on the other bond:
|
||||
const INT_VECT &stereoAtoms = dblBond->getStereoAtoms();
|
||||
|
||||
auto isClosingRingBond = [](Bond *bond) {
|
||||
if (bond == nullptr) {
|
||||
return false;
|
||||
}
|
||||
auto beginIdx = bond->getBeginAtomIdx();
|
||||
auto endIdx = bond->getEndAtomIdx();
|
||||
return beginIdx > endIdx &&
|
||||
beginIdx - endIdx > 1 &&
|
||||
bond->hasProp(common_properties::_TraversalRingClosureBond);
|
||||
};
|
||||
|
||||
auto isFlipped = false;
|
||||
|
||||
if (atom1->getDegree() == 3 &&
|
||||
std::find(stereoAtoms.begin(), stereoAtoms.end(),
|
||||
static_cast<int>(atom1ControllingBond->getOtherAtomIdx(
|
||||
atom1->getIdx()))) == stereoAtoms.end()) {
|
||||
isFlipped = true;
|
||||
atom2Dir = (atom2Dir == Bond::ENDUPRIGHT) ? Bond::ENDDOWNRIGHT
|
||||
: Bond::ENDUPRIGHT;
|
||||
}
|
||||
@@ -363,6 +378,17 @@ void canonicalizeDoubleBond(Bond *dblBond, UINT_VECT &bondVisitOrders,
|
||||
std::find(stereoAtoms.begin(), stereoAtoms.end(),
|
||||
static_cast<int>(firstFromAtom2->getOtherAtomIdx(
|
||||
atom2->getIdx()))) == stereoAtoms.end()) {
|
||||
isFlipped = true;
|
||||
atom2Dir = (atom2Dir == Bond::ENDUPRIGHT) ? Bond::ENDDOWNRIGHT
|
||||
: Bond::ENDUPRIGHT;
|
||||
}
|
||||
|
||||
if (!isFlipped &&
|
||||
(isClosingRingBond(dblBond) ||
|
||||
(isClosingRingBond(secondFromAtom1) &&
|
||||
!secondFromAtom1->getIsAromatic() &&
|
||||
secondFromAtom1->getBondDir() != Bond::NONE))
|
||||
) {
|
||||
atom2Dir = (atom2Dir == Bond::ENDUPRIGHT) ? Bond::ENDDOWNRIGHT
|
||||
: Bond::ENDUPRIGHT;
|
||||
}
|
||||
|
||||
@@ -4339,6 +4339,27 @@ void testOSSFuzzFailures() {
|
||||
BOOST_LOG(rdInfoLog) << "done" << std::endl;
|
||||
}
|
||||
|
||||
void testGithub3967() {
|
||||
BOOST_LOG(rdInfoLog) << "-------------------------------------" << std::endl;
|
||||
BOOST_LOG(rdInfoLog) << "Testing Github Issue 3967: Double bond stereo gets "
|
||||
"flipped by SMILES reader/writer"
|
||||
<< std::endl;
|
||||
|
||||
{
|
||||
auto mol = "C=c1s/c2n(c1=O)CCCCCCC\\N=2"_smiles;
|
||||
TEST_ASSERT(mol);
|
||||
auto smi = MolToSmiles(*mol);
|
||||
TEST_ASSERT(smi == "C=c1s/c2n(c1=O)CCCCCCC\\N=2");
|
||||
}
|
||||
{
|
||||
auto mol = "C1=C\\C/C=C2C3=C/C/C=C\\C=C/C\\3C\\2\\C=C/1"_smiles;
|
||||
TEST_ASSERT(mol);
|
||||
auto smi = MolToSmiles(*mol);
|
||||
TEST_ASSERT(smi == "C1=C\\C/C=C2C3=C/C/C=C\\C=C/C\\3C\\2\\C=C/1");
|
||||
}
|
||||
BOOST_LOG(rdInfoLog) << "\tdone" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
@@ -4417,6 +4438,7 @@ int main(int argc, char *argv[]) {
|
||||
testdoRandomSmileGeneration();
|
||||
testGithub1028();
|
||||
testGithub3139();
|
||||
testGithub3967();
|
||||
#endif
|
||||
testOSSFuzzFailures();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user