
Chemical structure can represent as graph atoms as nodes, bonds as edges. And some compound fingerprints based on the graph. These algorithm extract fragment from molecule given radius of center atom.
To get atom environment of RadiusN, FindAtomEnvironmentOfRadiusN method or rdkit is useful.
It can get fragment from molecule with given radius of specific atom.
So I would like to show how to do it. At first import libraries.
from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import AllChem
AllChem.SetPreferCoordGen(True)
Then define sample molecule and getSubmolRadN.
def getSubmolRadN(mol, radius):
atoms=mol.GetAtoms()
submols=[]
for atom in atoms:
env=Chem.FindAtomEnvironmentOfRadiusN(mol, radius, atom.GetIdx())
amap={}
submol=Chem.PathToSubmol(mol, env, atomMap=amap)
subsmi=Chem.MolToSmiles(submol, rootedAtAtom=amap[atom.GetIdx()], canonical=False)
submols.append(Chem.MolFromSmiles(subsmi, sanitize=False))
return submols
mol = Chem.MolFromSmiles('n1c(N3CCN(C(=O)C)CC3)c(C#N)cc2cc(OC)ccc12')
mol
FindAtomEnvironmentOfRadiusN can get env around atom of radius N and then, call to PathToSubmol with env to get submol of the env. After that to keep query atom as atom index 0, I call MolFromSmiles with rootedAtAtom option.
Now ready, let’s check the submols.
submols = getSubmolRadN(mol, 1)
Draw.MolsToGridImage(submols, highlightAtomLists=[[0] for _ in range(len(submols))], molsPerRow=5)

submols = getSubmolRadN(mol, 3)
Draw.MolsToGridImage(submols, highlightAtomLists=[[0] for _ in range(len(submols))], molsPerRow=5)

It seems work.
Here is a whole code of the post.
Submols are rdkit mol object so I can use the object any tasks.
Also as reader knows that current RDKit has cool method such as DrawMorganBits, DrawMorganEnv etc. It is useful to check bit information of molecule. Details are provided in original document.
Thank you so much,