# 使用特征工厂再来构建指纹工厂signature,factory用于设置指纹参数 # 构建指纹工厂 : SigFactory( featFactory, # 特征工厂 useCounts=False, # 默认False。False不考虑指纹频数,并生成SparseBitVect minPointCount=2, # 默认为2.生成指纹时包括的最少的药效团数量。 maxPointCount=3, # 默认为3。生成指纹时包括的最多的药效团数量。 ...) sigFactory = SigFactory(featFactory, minPointCount=2, maxPointCount=3) # 对拓扑距离进行分段 sigFactory.SetBins([(0, 2), (2, 5), (5, 8)]) # 每次修改参数后,都要初始化一下 sigFactory.Init() # 计算指纹的长度 print('指纹长度=', sigFactory.GetSigSize()) # 指纹长度= 2988 # # 4.2 生成2D药效团指纹 # 指纹工厂中的参数设置完毕,接下来就可以生成2D指纹了。 # 计算2D药效团指纹 : Gen2DFingerprint( mol, # 要计算指纹的mol对象 sigFactory, # 设置了参数的指纹工厂 bitinfo # 获取指纹id及对应的原子 ) mol = Chem.MolFromSmiles('OCC(=O)CCCN') fp = Generate.Gen2DFingerprint(mol, sigFactory) print(len(fp)) # 2988 print(fp.GetNumOnBits()) # 23
import search2d from time import time import sys fdefName = 'data/minimalFeatures.fdef' featFactory = ChemicalFeatures.BuildFeatureFactory(fdefName) from rdkit.Chem.Pharm2D.SigFactory import SigFactory sigFactory = SigFactory(featFactory, minPointCount=2, maxPointCount=3, trianglePruneBins=False) sigFactory.SetBins([(0, 2), (2, 5), (5, 8)]) sigFactory.Init() sigFactory.GetSigSize() def similarityMeasure(fps, neg, mol2): fps2 = Generate.Gen2DFingerprint(mol2, sigFactory) similarityPos = DataStructs.FingerprintSimilarity( fps, fps2, metric=DataStructs.TanimotoSimilarity) similarityNeg = DataStructs.FingerprintSimilarity( neg, fps2, metric=DataStructs.TanimotoSimilarity) # if similarityPos>=0.75: print Chem.MolToSmiles(mol2), similarityPos, similarityNeg return similarityPos, similarityPos - similarityNeg