我正在尝试编写一个 python 函数,该函数将两个列表作为输入:一个包含一些分子 SMILES 代码,另一个包含分子名称。
然后它计算所有分子对之间的 TANIMOTO 系数(我已经有一个函数),并分别返回两个新列表,其中包含 Tanimoto 与任何其他分子不高于某个阈值的所有分子的 SMILES 和名称。
这是我到目前为止所做的,但它给出了错误的结果(我得到的大多数分子几乎相同......):
def TanimotoFilter(molist,namelist,threshold):
# molist is the smiles list
# namelist is the name list (SURPRISE!) is this some global variable name?
# threshold is the tanimoto threshold (SURPRISE AGAIN!)
smilesout=[]
names=[]
tans=[]
exclude=[]
for i in range(1,len(molist)):
if i not in exclude:
smilesout.append(molist[i])
names.append(namelist[i])
for j in range(i,len(molist)):
if i==j:
tans.append('SAME')
else:
tanimoto=tanimoto_calc(molist[i],molist[j])
if tanimoto>threshold:
exclude.append(j)
#print 'breaking for '+str(i)+' '+str(j)
break
else:
tans.append(tanimoto)
return smilesout, names, tans
如果您提出的修改尽可能基本,我将非常感谢,因为此代码适用于生活中几乎没有见过终端的人......它是否充满了使其变慢的循环并不重要.
谢谢你们!