f=open('something.txt'.'r')
lines=f.readlines()
for read in range(0,len(lines)):
c=lines[read]
d=lines[read]
if c[0:4]=='ATOM':
AX1=float(c[32:38])
AY1=float(c[40:46])
AZ1=float(c[48:54])
A1=c[77]
if d[0:6]=='HETATM':
HX1=float(d[32:38])
HY1=float(d[40:46])
HZ1=float(d[48:54])
H1=d[77]
distance=math.sqrt((HX1-AX1)**2+(HY1-AY1)**2+(HZ1-AZ1)**2)
print 'Distance b/w ',A1,' and ',H1,'',distance
文件會像:
ATOM 1 N ALA A 4 15.660 74.786 38.080 1.00 29.54 N
ATOM 2 CA ALA A 4 15.546 74.666 39.526 1.00 27.64 C
ATOM 3 C ALA A 4 16.833 74.137 40.145 1.00 25.88 C
ATOM 4 O ALA A 4 17.852 73.890 39.500 1.00 24.05 O
.
.
.
ATOM 6048 OXT ALA A 780 21.816 67.407 16.290 1.00 13.41 O
HETATM 6050 C1 GLC A2002 5.415 71.753 22.098 1.00 21.40 C
HETATM 6051 C2 GLC A2002 3.948 71.252 22.308 1.00 21.24 C
HETATM 6052 C3 GLC A2002 3.065 71.966 21.254 1.00 20.81 C
HETATM 6053 C4 GLC A2002 3.266 73.512 21.425 1.00 20.10 C
HETATM 6054 C5 GLC A2002 4.737 73.893 21.253 1.00 21.47 C
HETATM 6055 C6 GLC A2002 4.967 75.396 21.466 1.00 22.53 C
HETATM 6056 O1 GLC A2002 6.224 71.231 23.190 1.00 22.04 O
HETATM 6057 O2 GLC A2002 3.902 69.831 22.018 1.00 21.46 O
HETATM 6058 O3 GLC A2002 1.682 71.659 21.493 1.00 21.68 O
HETATM 6059 O4 GLC A2002 2.509 74.212 20.404 1.00 17.87 O
HETATM 6060 O5 GLC A2002 5.516 73.179 22.244 1.00 21.76 O
HETATM 6061 O6 GLC A2002 6.361 75.746 21.230 1.00 24.18 O
我要計算使用上述公式的值。它應該將ATOM-1與所有的HETATM和ATOM-2相比較,以便與所有的HETATM進行比較。
但我得到的結果只有最後一個原子,而HETATM
結果
Distance b/w O and C 17.9335824921
Distance b/w O and C 19.2422912617
Distance b/w O and C 19.925505715
Distance b/w O and C 20.1926162247
Distance b/w O and C 18.9312388924
Distance b/w O and C 19.3521031932
Distance b/w O and O 17.4740790888
Distance b/w O and O 18.963047118
Distance b/w O and O 21.2256606258
Distance b/w O and O 20.8804518629
Distance b/w O and O 18.2881409662
Distance b/w O and O 18.2427943583
這纔是真正的代碼? 'open('something.txt'。'r')'無效。 –
你經歷所有的原子一行行你打任何HETATM之前,所以你開始HETATM之前的最後一個ATOM的數據被保存,和你比較的是ATOM所有HETATM。 – Ryan