摩根分子指纹(Morgan Fingerprints),是一种圆形指纹,也属于拓扑型指纹,是通过对标准的摩根算法进行改造后得到。可以大致等同于扩展连通性指纹(Extended-Connectivity Fingerprints,ECFPs)。
这类指纹有诸多优点,例如计算速度快、没有经过预定义(可以表示无穷多种不同的分子特征)、可以包含手性信息、指纹中的每个元素代表一种特定子结构、可以方便地进行分析和解释、可以根据不同的需要进行相应的修改等。这类指纹设计的最初目的是用于搜索与活性相关的分子特征,而非子结构搜索。此外也可以用于相似性搜索、聚类、虚拟筛选等方向。指纹的生成过程大致分为以下几个步骤:
更多内容可以参考ChemAxon的介绍,还有ECFPs的文章。
ECFPs可以捕捉到精确的子结构细节,相对应的,功能基指纹(Functional class fingerprints,FCFPs)则更为泛化,可以将同一类功能基作为一种特征结构。在rdkit中两种特征都可以通过GetMorganFingerprint实现。
>>> from rdkit import Chem
>>> from rdkit import DataStructs
>>> from rdkit.Chem import AllChem
>>> from rdkit.Chem import Draw
>>> m1 = Chem.MolFromSmiles('ClC1=COCNC1')
>>> m2 = Chem.MolFromSmiles('BrC1=COCNC1')
>>> Draw.MolsToGridImage([m1, m2], subImgSize=(150, 150), legends=['ClC1CNCOC1', 'BrC1CNCOC1'])
>>> fp1 = AllChem.GetMorganFingerprint(m1, 2)
>>> fp2 = AllChem.GetMorganFingerprint(m2, 2)
>>> DataStructs.DiceSimilarity(fp1, fp2)
0.7
>>> print(fp1.GetLength())
4294967295
>>> print(fp1.GetNonzeroElements())
{39328034: 1, 211414882: 1, 362715007: 1, 2626911012: 1, 2968968094: 2, ...}
>>> fp1 = AllChem.GetMorganFingerprintAsBitVect(m1, 2, nBits=1024)
>>> fp2 = AllChem.GetMorganFingerprintAsBitVect(m2, 2, nBits=1024)
>>> DataStructs.DiceSimilarity(fp1, fp2)
0.6842105263157895
>>> ffp1 = AllChem.GetMorganFingerprintAsBitVect(m1, 2, nBits=10, useFeatures=True)
>>> ffp2 = AllChem.GetMorganFingerprintAsBitVect(m2, 2, nBits=10, useFeatures=True)
>>> DataStructs.DiceSimilarity(ffp1, ffp2)
1.0
>>> print(ffp1.GetNumBits())
10
>>> print(ffp1.ToBitString())
1111101111
>>> m2 = Chem.MolFromSmiles('BrC1=CCCCC1')
>>> m3 = Chem.MolFromSmiles('BrC1CCCCC1')
>>> Draw.MolsToGridImage([m1, m2, m3], subImgSize=(200, 150))
>>> fp1 = AllChem.GetMorganFingerprint(m1, 2, invariants=[1]*m1.GetNumAtoms())
>>> fp2 = AllChem.GetMorganFingerprint(m2, 2, invariants=[1]*m2.GetNumAtoms())
>>> fp3 = AllChem.GetMorganFingerprint(m3, 2, invariants=[1]*m3.GetNumAtoms())
>>> fp1 == fp2
True
>>> fp1 == fp3
False
>>> fp1 = AllChem.GetMorganFingerprint(m1, 2, invariants=[1]*m1.GetNumAtoms(), useBondTypes=False)
>>> fp3 = AllChem.GetMorganFingerprint(m1, 2, invariants=[1]*m3.GetNumAtoms(), useBondTypes=False)
>>> fp1 == fp3
True
>>> info = {}
>>> fp_explain = AllChem.GetMorganFingerprint(m1, 2, bitInfo=info)
>>> info
{39328034: ((1, 1),),
211414882: ((5, 2),),
362715007: ((6, 1),),
397705891: ((4, 1),),
718785834: ((1, 2),),
1016841875: ((0, 0),),
1078999752: ((3, 1),),
1289643292: ((5, 1),),
2132511834: ((5, 0),),
2626911012: ((4, 2),),
2968968094: ((4, 0), (6, 0)),
...}
>>> amap = {}
>>> env = Chem.FindAtomEnvironmentOfRadiusN(m1, 2, 5)
>>> submol=Chem.PathToSubmol(m1, env, atomMap=amap)
>>> print(amap)
{1: 4, 3: 0, 4: 1, 5: 2, 6: 3}
>>> print(list(env))
[4, 5, 3, 6]
>>> Chem.MolToSmiles(submol)
'CCNCO'
>>> Chem.MolToSmiles(submol, rootedAtAtom=amap[5], canonical=False)
'N(CO)CC'
>>> atoms=set()
>>> for bidx in env:
>>> atoms.add(m1.GetBondWithIdx(bidx).GetBeginAtomIdx())
>>> atoms.add(m1.GetBondWithIdx(bidx).GetEndAtomIdx())
>>> Chem.MolFragmentToSmiles(m1, atomsToUse=list(atoms), bondsToUse=env, rootedAtAtom=5)
'N(CC)CO'
查看211414882代表的子结构
>>> Draw.DrawMorganBit(m1, 211414882, info)
>>> mol = Chem.MolFromSmiles('c1ccccc1CC1CC1')
>>> bi = {}
>>> fp = AllChem.GetMorganFingerprintAsBitVect(mol, radius=2, bitInfo=bi)
>>> Draw.DrawMorganBit(mol, 872, bi)