The above solution with !r4 doesn't work because for sssr reasons these atoms are considered to be in a 4 membered ring also if the 4 membered ring is "exo" to the central 6 membered one. AFAIK there is no good way to do a general ring size filter in an atom definition using SMARTS. Below is a quite ugly, but working solution
def GetSubstructMatches_filtered(mol,pattern): matches = mol.GetSubstructMatches(pattern) filtered_matches = [] for match in matches: if Chem.MolFragmentToSmiles(mol, atomsToUse=match).count("2") == 0: filtered_matches.append(match) return tuple(filtered_matches) m1 = Chem.MolFromSmiles("c1ccc2cc3c(ccc4c5ccccc5c5cc6c7cc8c(cc7c6cc5c34)c3cccnc38)cc2c1") m2 = Chem.MolFromSmiles("b1cccc2c1c1c(c3ccc4ccc4c3c3c4c5cc[nH]c5c4c13)c1ncc3ccccc3c21") m3 = Chem.MolFromSmiles("b1ccbc2c1c1ccoc1c1c2c2ccsc2c2[nH]c3ncc4c(c3c21)=c1ncccc1=4") p = Chem.MolFromSmarts("[*;R2]~1~[*;R2]~[*;R2]~[*;R2]~[*;R2]~[*;R2]~1") for m, expected_value in zip([m1,m2,m3],[1,2,2]): print(len(GetSubstructMatches_filtered(m,p)) == expected_value) how does it work? the function GetSubstructMatches_filtered checks if there is more than one ring in the substructure (by converting to substruct to SMILES using atom indices from the GetSubstructMatches result and searching for "2" in the string) and rejects it if so. wim On Tue, Jun 7, 2022 at 8:52 PM Geoffrey Hutchison <geoff.hutchi...@gmail.com> wrote: > Nevermind, x3 won't exclude the fused 4-atom rings from your first > example. I'll let you know if I think of some other way. :-) > > > I think you'd want something like this, perhaps - to exclude atoms in ring > size 4? > > [*;R2!r4]~1~[*;R2!r4]~[*;R2!r4]~[*;R2!r4]~[*;R2!r4]~[*;R2!r4]~1 > > I also don't know if you're trying to ensure that each of the atoms are > aromatic, in which case, you'd want something like: > > [a;R2!r4]~1~[a;R2!r4]~[a;R2!r4]~[a;R2!r4]~[a;R2!r4]~[a;R2!r4]~1 > > Hope that helps, > -Geoff > _______________________________________________ > Rdkit-discuss mailing list > Rdkit-discuss@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/rdkit-discuss >
_______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss