# How to find the largest cyclic substructure with RDKit?

I have a bunch of structures and of each I would like to find the largest cyclic substructure. I'm not a chemist, so I don't know if there is a common terminology for this. I hope, I made it clear what I'm looking for.

Example:

Each structure on the top (1,2,3) as input should return the bottom structure (4).

There is the rdkit.Chem.MCS module which will return the maximum common substructure of a set of molecules. But that's not what I'm looking for.

Any ideas? And hints where or which module to look at...? Which term to search for?

I'm aware that there is a RDKit mailing list, however, I'm asking here first, because of the possibility to easily attach images. If nobody can help me here, I will try there. Maybe it already goes into "heavier" programming which then would be more a topic for StackOverflow.

• Not that this question is off-topic for CSE, but the rules of thumb are heavy_programming → SO; heavy_programming + chemistryMMSE. If you think MMSE could be a better place for your question, we can migrate it there. Apr 29 at 15:34
• @andselisk well, then the question is: does this require "heavy programming" or is it just a "simple" existing module or function which I haven't found yet? Apr 29 at 15:36
• Yeah it's definitely on-topic but you might have better luck at Matter Modeling eventually. No harm letting it sit here for a couple of days (there is some overlap between the user base anyway) but if you don't get any answers we can migrate it. Apr 29 at 15:37
• @theozh Sorry, I'm afraid I cannot answer this. I used RDkit once for something I already forgot what it was. Apr 29 at 15:38
• @theozh Contributions to RDKit's mailing list -- both questions, answers, and comments -- are retained in searchable archives. They may be accessed by anyone, regardless if you already are a subscriber, or not. One of the threads potentially relevant to your question is this one. Or, is your question to identify the largest «contiguous set of rings» in these structures? Apr 29 at 16:34

## 1 Answer

In the RDKit Cookbook is an example how to find the indices of ring systems.

RDKit Cookbook Example

Having the indices, it is simple to find the largest ring.

from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole
IPythonConsole.molSize = (400, 300)
IPythonConsole.drawOptions.addAtomIndices = True

m = Chem.MolFromSmiles('C1=CC2C(C=C1)=c1ccccc1=C2C1C=C(c2ccccc2)c2cccc3c4ccccc4nc1c23')
m


# the cook book example
def GetRingSystems(mol, includeSpiro=False):
ri = mol.GetRingInfo()
systems = []
for ring in ri.AtomRings():
ringAts = set(ring)
nSystems = []
for system in systems:
nInCommon = len(ringAts.intersection(system))
if nInCommon and (includeSpiro or nInCommon>1):
ringAts = ringAts.union(system)
else:
nSystems.append(system)
nSystems.append(ringAts)
systems = nSystems
return systems

ringSys = GetRingSystems(m)
ringSys

[{16, 17, 18, 19, 20, 21},
{13, 14, 15, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}]


Highlighting the largest ring for proof.

highlightAtoms = max(ringSys, key=len)
Draw.MolToImage(m, size=(400,300), highlightAtoms=highlightAtoms)


• I have some difficulties to replicate your work. May you have a look into the chat in «The Periodic Table» here, please? Maybe it is only a minor detail missing. May 1 at 17:28
• @Buttonwood It could be the RDKit version. Here is my configuration if that helps: Windows 10, Python 3.7.10, Jupyter 6.3.0, RDKit 2021.03.1 (from conda-forge) May 2 at 5:52
• @rapelpy , Great! That's what I was looking for. I guess I wouldn't have found this without your help. Thank you very much! Works fine for me. I have: Win10, Anaconda, Python 3.6.12, RDKit 2020.09.01 May 2 at 18:35
• @rapelpy , Ah, l was too excited about finding/marking the largest ring system. But, well, now I still have to find a way to get the structure (i.e. SMILES) from these largest ensemble of rings. I need to dig into the RDKit documentation. I hope there will be another cookbook example for this task. May 2 at 18:41