【发布时间】:2013-10-19 12:03:52
【问题描述】:
我已经计算了两个原子之间的距离并保存在 out.txt 文件中。生成的out文件是这样的。
N_TYR_A0002 O_CYS_A0037 6.12
O_CYS_A0037 N_TYR_A0002 6.12
N_ALA_A0001 O_TYR_A0002 5.34
O_TYR_A0002 N_ALA_A0001 5.34
我的输出文件有重复,表示相同的原子和相同的距离。
如何删除多余的行。
我用这个程序计算距离(所有到所有原子)
from __future__ import division
from string import *
from numpy import *
def eudistance(c1,c2):
x_dist = (c1[0] - c2[0])**2
y_dist = (c1[1] - c2[1])**2
z_dist = (c1[2] - c2[2])**2
return math.sqrt (x_dist + y_dist + z_dist)
infile = open('file.pdb', 'r')
text = infile.read().split('\n')
infile.close()
text.remove('')
pdbid = []
#define the pdbid
spfcord = []
for g in pdbid:
ratom = g[0]
ratm1 = ratom.split('_')
ratm2 = ratm1[0]
if ratm2 in allatoms:
spfcord.append(g)
#print spfcord[:10]
outfile1 = open('pairdistance.txt', 'w')
for m in spfcord:
name1 = m[0]
cord1 = m[1]
for n in spfcord:
if n != '':
name2 = n[0]
cord2 = n[1]
dist = euDist(cord1, cord2)
if 7 > dist > 2:
#print name1, '\t', name2, '\t', dist
distances = name1 + '\t ' + name2 + '\t ' + str(dist)
#print distances
outfile1.write(distances)
outfile1.write('\n')
outfile1.close()
【问题讨论】:
-
请显示生成此输出的代码。
-
如果要在out.txt生成之后删除重复项,请参考stackoverflow.com/questions/15830290/…(它将保留顺序)。我想您可能想要做的是修改生成 out.txt 的逻辑以省略重复项。
-
我看到了那个代码。但问题是我的第一列和第二列是变量和交换。所以每次都要换新线。我将在这里添加我的代码
-
这是一个如何删除前后重复的问题吗?即您不想显示 A->B 和 B->A,但每条边只有一个长度?还是只是将输出列表唯一化? (由上面的链接解决方案涵盖)
-
这不是反向重复或冗余行的情况。我对所有人进行了距离计算。所以我的输出就是这样。我想删除重复的计算。