diff --git a/Code/GraphMol/DistGeomHelpers/Embedder.cpp b/Code/GraphMol/DistGeomHelpers/Embedder.cpp index 255ca7026..3af6c2ab1 100644 --- a/Code/GraphMol/DistGeomHelpers/Embedder.cpp +++ b/Code/GraphMol/DistGeomHelpers/Embedder.cpp @@ -140,24 +140,21 @@ namespace RDKit { void _findChiralSets(const ROMol &mol, DistGeom::VECT_CHIRALSET &chiralCenters) { ROMol::ConstAtomIterator ati; - INT_PAIR_VECT nbrs; + INT_VECT nbrs; ROMol::OEDGE_ITER beg,end; Atom *oatom; for (ati = mol.beginAtoms(); ati != mol.endAtoms(); ati++) { if ((*ati)->getAtomicNum() != 1) { //skip hydrogens - if ((*ati)->hasProp(common_properties::_CIPCode)) { + Atom::ChiralType chiralType=(*ati)->getChiralType(); + if (chiralType==Atom::CHI_TETRAHEDRAL_CW || chiralType==Atom::CHI_TETRAHEDRAL_CCW) { // make a chiral set from the neighbors nbrs.clear(); nbrs.reserve(4); // find the neighbors of this atom and enter them into the - // nbr list along with their CIPRanks + // nbr list boost::tie(beg,end) = mol.getAtomBonds(*ati); while (beg != end) { - oatom = mol[*beg]->getOtherAtom(*ati); - unsigned int rank; - oatom->getProp(common_properties::_CIPRank, rank); - INT_PAIR rAid(rank, oatom->getIdx()); - nbrs.push_back(rAid); + nbrs.push_back(mol[*beg]->getOtherAtomIdx(*ati)); ++beg; } // if we have less than 4 heavy atoms as neighbors, @@ -166,33 +163,26 @@ namespace RDKit { bool includeSelf = false; CHECK_INVARIANT(nbrs.size() >= 3, "Cannot be a chiral center"); - std::sort(nbrs.begin(), nbrs.end()); if (nbrs.size() < 4) { - unsigned int rank; - (*ati)->getProp(common_properties::_CIPRank, rank); - INT_PAIR rAid(rank, (*ati)->getIdx()); - nbrs.insert(nbrs.begin(), rAid); + nbrs.insert(nbrs.begin(), (*ati)->getIdx()); includeSelf = true; } // now create a chiral set and set the upper and lower bound on the volume - std::string cipCode; - (*ati)->getProp(common_properties::_CIPCode, cipCode); - - if (cipCode == "S") { + if (chiralType == Atom::CHI_TETRAHEDRAL_CW) { // postive chiral volume - DistGeom::ChiralSet *cset = new DistGeom::ChiralSet(nbrs[0].second, - nbrs[1].second, - nbrs[2].second, - nbrs[3].second, + DistGeom::ChiralSet *cset = new DistGeom::ChiralSet(nbrs[0], + nbrs[1], + nbrs[2], + nbrs[3], 5.0, 100.0); DistGeom::ChiralSetPtr cptr(cset); chiralCenters.push_back(cptr); } else { - DistGeom::ChiralSet *cset = new DistGeom::ChiralSet(nbrs[0].second, - nbrs[1].second, - nbrs[2].second, - nbrs[3].second, + DistGeom::ChiralSet *cset = new DistGeom::ChiralSet(nbrs[0], + nbrs[1], + nbrs[2], + nbrs[3], -100.0, -5.0); DistGeom::ChiralSetPtr cptr(cset); chiralCenters.push_back(cptr); diff --git a/Regress/Data/chembl_20_chiral.smi.gz b/Regress/Data/chembl_20_chiral.smi.gz new file mode 100644 index 000000000..05172c110 Binary files /dev/null and b/Regress/Data/chembl_20_chiral.smi.gz differ diff --git a/Regress/Scripts/chiral_embed.py b/Regress/Scripts/chiral_embed.py new file mode 100644 index 000000000..fe6512273 --- /dev/null +++ b/Regress/Scripts/chiral_embed.py @@ -0,0 +1,15 @@ +from rdkit import Chem +from rdkit.Chem import AllChem + +suppl = Chem.SmilesMolSupplier('../Data/chembl_20_chiral.smi') +for i,mol in enumerate(suppl): + csmi = Chem.MolToSmiles(mol,True) + for j in range(100): + mh = Chem.AddHs(mol) + AllChem.EmbedMolecule(mh,randomSeed=j+1) + Chem.AssignAtomChiralTagsFromStructure(mh) + nm = Chem.RemoveHs(mh) + smi = Chem.MolToSmiles(nm,True) + if smi!=csmi: + print('%d %d %s:\n%s\n%s'%(i,j,mol.GetProp('_Name'),csmi,smi)) +