This guest post by Rachel Walker (github: @rachelnwalker) is the second of a few posts covering some of the new or improved features in the 2023.09.1 RDKit release.
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
2023.09.1
Using ring system templates in 2D Coordinate Generation
Beginning in the 2023.03.1 release, it is possible to use ring system templates when generating 2D coordinates to improve the depiction of some complicated ring systems and macrocycles. There are currently around 70 pre-existing templates, but you are also able to define and use custom templates. The current templates are sourced from coordgenlibs.
You can use the default ring system templates by setting useRingTemplates to True in rdDepictor.Compute2DCoords
mol = Chem.MolFromSmiles("NC(CCC1CCC2C(C1)C1CCN2NN1)CC(=O)CCC1=CCCC2CCCCC2CCCCC2CCCC(CCCCCCC1)C2")mol_with_templates = Chem.Mol(mol)# use rdkit native coordinate generationrdDepictor.SetPreferCoordGen(False)rdDepictor.Compute2DCoords(mol)# the first time you call this, rdDepictor.Compute2DCoords(mol_with_templates, useRingTemplates=True)Draw.MolsToGridImage([mol, mol_with_templates], subImgSize=(400,400))
Example uses of default templates
Templates can be used for common, complex ring systems that the standard 2D coordinate generation algorithm distorts. They are also useful if you want certain ring systems to be laid out in a specific way (for example, cubane).
Templates by themselves
mols = [Chem.MolFromSmiles("C1=C2CN3CCC45CCN6CCC(OC1)C(C2CC34)C65"), Chem.MolFromSmiles("C1CCC2C(C1)C1CCN2NN1"), Chem.MolFromSmiles("c1cc2nnc1CCNCCNCCCCO2"), Chem.MolFromSmiles("C12C3C4C1C1C2C3C41")]mols_with_templates = [Chem.Mol(m) for m in mols]legends = []allmols = []for m, m_with_t inzip(mols, mols_with_templates): rdDepictor.Compute2DCoords(m, useRingTemplates=False) rdDepictor.Compute2DCoords(m_with_t, useRingTemplates=True) allmols.append(m) allmols.append(m_with_t) legends.append("Without templating") legends.append("With templating")Draw.MolsToGridImage(allmols, legends=legends, molsPerRow=2, subImgSize=(400,400))
Template matches within a larger structure
mols = [Chem.MolFromSmiles("CCC1CN2CC(CC3=CC=CC=C3)C34CCN5CC6=CCOC1C(C23)C6CC45"), Chem.MolFromSmiles("C1CC2C3CCN(NN3)C2CC1C1=CC2=C(C=CC=C2)C=C1"), Chem.MolFromSmiles("CCc1cc2CCNCC(CC3CCCCC3)NCCCCOc1nn2")]mols_with_templates = [Chem.Mol(m) for m in mols]legends = []allmols = []for m, m_with_t inzip(mols, mols_with_templates): rdDepictor.Compute2DCoords(m, useRingTemplates=False) rdDepictor.Compute2DCoords(m_with_t, useRingTemplates=True) allmols.append(m) legends.append("Without templating") allmols.append(m_with_t) legends.append("With templating")Draw.MolsToGridImage(allmols, legends=legends, molsPerRow=2, subImgSize=(400,400))
You can set your own templates using rdDepictor.SetRingSystemTemplates. This will replace all of the default templates, while rdDepictor.AddRingSystemTemplates will add to any templates that are already present (the most recently added templates will be given preference).
Custom templates should be defined in a .smi file, with each line representing a single template using CXSMILES. Templates must be a connected graph (no fragments) and have 2D coordinates defined, and they need to consist of a single ring or fused ring system (spiros are OK).
Example: I made my_templates.smi with a single template:
As of this release, there are several limitations to the templating that we plan on addressing in the future:
Only ring system templates are supported, it would be nice to be able to template some complicated stereochemistry
Template matching only considers the first substructure match, even when other matches would result in better depictions
Quality and quantity of templates could be vastly improved, we still don’t have a wide variety of macrocycles and the existing templates are specific bond order and atom type
How to contribute templates using the molecular_templates repo!
There is a new repository on github that we will use to collect and store templates here https://github.com/rdkit/molecular_templates. You can contribute ring system template(s) by opening a PR and adding your templates in CXSMILES format to the templates.smi file. More details can be found in the README file on Github. Additions or changes to the templates in this repository will automatically be incorporated into the next RDKit release.
You can view all of the current templates (which are sourced from coordgenlibs, Schrödinger’s 2D coordinate generation software) in the gallery: https://github.com/rdkit/molecular_templates/blob/main/gallery.md
Ricardo (github: @ricrogz) set up some awesome Github actions so that we can visualize the template you suggest in your pull request! Here is an example: https://github.com/rdkit/molecular_templates/pull/7