Skip to content

Commit

Permalink
Removing stereoatoms requires removing CIS/Trans stereo flags (rdkit#…
Browse files Browse the repository at this point in the history
…6901)

* Removing stereoatoms requires removing CIS/Trans stereo flags

* Added test when removing nbrs of cis/trans bonds

---------

Co-authored-by: Brian Kelley <bkelley@relaytx.com>
  • Loading branch information
bp-kelley and Brian Kelley authored Nov 21, 2023
1 parent ab7b8dd commit ee8c35a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Code/GraphMol/MMPA/MMPA_UnitTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <iostream>
#include <RDGeneral/RDLog.h>
#include <RDGeneral/utils.h>
#include <GraphMol/Chirality.h>
#include "../RDKitBase.h"
#include "../FileParsers/FileParsers.h" //MOL single molecule !
#include "../FileParsers/MolSupplier.h" //SDF
Expand Down Expand Up @@ -690,6 +691,14 @@ std::endl;
//====================================================================================================
//====================================================================================================

void testGithub6900 () {
RDKit::Chirality::setUseLegacyStereoPerception(false);
//auto mol = "CN1CCCN=C1/C=C/c1cccs1"_smiles;
auto mol = "N/C=C/C"_smiles;
std::vector<std::pair<ROMOL_SPTR, ROMOL_SPTR>> res;
RDKit::MMPA::fragmentMol(*mol, res, 3);
RDKit::Chirality::setUseLegacyStereoPerception(true);
}
int main() {
BOOST_LOG(rdInfoLog)
<< "*******************************************************\n";
Expand All @@ -703,14 +712,15 @@ int main() {
#else
setpriority(PRIO_PROCESS, getpid(), -20);
#endif

testGithub6900();
T0 = nanoClock();
t0 = nanoClock();

testCase_1();
// /*
test2();
test3();

// test4();
// */
// debugTest1("C[*:1].O=C(NCCO)c1c([*:1])n([O-])c2ccccc2[n+]1=O");
Expand Down
12 changes: 12 additions & 0 deletions Code/GraphMol/RWMol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ void RWMol::removeBond(unsigned int aid1, unsigned int aid2) {
}
if (std::find(obnd->getStereoAtoms().begin(), obnd->getStereoAtoms().end(),
aid2) != obnd->getStereoAtoms().end()) {
// github #6900 if we remove stereo atoms we need to remove
// the CIS and or TRANS since this requires stereo atoms
if (obnd->getStereo() == Bond::BondStereo::STEREOCIS ||
obnd->getStereo() == Bond::BondStereo::STEREOTRANS ) {
obnd->setStereo(Bond::BondStereo::STEREONONE);
}
obnd->getStereoAtoms().clear();
}
}
Expand All @@ -484,6 +490,12 @@ void RWMol::removeBond(unsigned int aid1, unsigned int aid2) {
}
if (std::find(obnd->getStereoAtoms().begin(), obnd->getStereoAtoms().end(),
aid1) != obnd->getStereoAtoms().end()) {
// github #6900 if we remove stereo atoms we need to remove
// the CIS and or TRANS since this requires stereo atoms
if (obnd->getStereo() == Bond::BondStereo::STEREOCIS ||
obnd->getStereo() == Bond::BondStereo::STEREOTRANS ) {
obnd->setStereo(Bond::BondStereo::STEREONONE);
}
obnd->getStereoAtoms().clear();
}
}
Expand Down
20 changes: 20 additions & 0 deletions Code/GraphMol/catch_chirality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,26 @@ TEST_CASE("ring stereo finding is overly aggressive", "[chirality][bug]") {
Chirality::findPotentialStereo(*mol, cleanIt, flagPossible);
CHECK(stereoInfo.size() == 2);
}
SECTION("Removal of stereoatoms requires removing CIS/TRANS when using legacy stereo") {
UseLegacyStereoPerceptionFixture reset_stereo_perception;
Chirality::setUseLegacyStereoPerception(false);

{
auto mol = "N/C=C/C"_smiles;
CHECK(mol->getBondWithIdx(1)->getStereo() == Bond::BondStereo::STEREOTRANS);
auto rwmol = dynamic_cast<RWMol*>(mol.get());
rwmol->removeBond(0,1);
CHECK(mol->getBondWithIdx(0)->getStereo() == Bond::BondStereo::STEREONONE);
}
{
auto mol = "N/C=C/C"_smiles;
CHECK(mol->getBondWithIdx(1)->getStereo() == Bond::BondStereo::STEREOTRANS);
auto rwmol = dynamic_cast<RWMol*>(mol.get());
rwmol->removeBond(2,3);
CHECK(mol->getBondWithIdx(1)->getStereo() == Bond::BondStereo::STEREONONE);
}

}
}

TEST_CASE(
Expand Down

0 comments on commit ee8c35a

Please sign in to comment.