我想添加更多段落但收到错误?我能够打印前三个段落,但我试图添加到更多段落获取错误。有人可以纠正吗?
输入文件:
HETATM10910 C4B NAD A 363 60.856 -58.575 149.282 1.00 40.44 C
HETATM10911 O4B NAD A 363 61.320 -59.488 148.275 1.00 43.48 O
HETATM10912 C3B NAD A 363 60.243 -57.426 148.473 1.00 40.37 C
HETATM10914 C2B NAD A 363 60.167 -57.970 147.054 1.00 40.90 C
HETATM10916 C1B NAD A 363 61.394 -58.766 147.056 1.00 43.29 C
HETATM10954 C4B NAD B 363 41.496 -54.407 140.932 1.00 39.26 C
HETATM10955 O4B NAD B 363 41.936 -54.715 139.568 1.00 41.96 O
HETATM10956 C3B NAD B 363 42.061 -55.476 141.894 1.00 37.13 C
HETATM10958 C2B NAD B 363 42.883 -56.336 140.942 1.00 38.13 C
HETATM10960 C1B NAD B 363 42.233 -56.127 139.593 1.00 42.92 C
我想按照以下方式打印数据:
HETATM 3788 C4B NAI A 302 52.695 15.486 8.535 1.00 57.28 C
HETATM 3789 O4B NAI A 302 52.258 14.631 7.456 1.00 56.26 O
HETATM 3794 C1B NAI A 302 53.348 13.816 7.022 1.00 53.44 C
HETATM 3792 C2B NAI A 302 54.537 14.748 7.190 1.00 50.93 C
HETATM 3789 O4B NAI A 302 52.258 14.631 7.456 1.00 56.26 O
HETATM 3794 C1B NAI A 302 53.348 13.816 7.022 1.00 53.44 C
HETATM 3792 C2B NAI A 302 54.537 14.748 7.190 1.00 50.93 C
HETATM 3790 C3B NAI A 302 54.225 15.525 8.465 1.00 52.99 C
HETATM 3794 C1B NAI A 302 53.348 13.816 7.022 1.00 53.44 C
HETATM 3792 C2B NAI A 302 54.537 14.748 7.190 1.00 50.93 C
HETATM 3790 C3B NAI A 302 54.225 15.525 8.465 1.00 52.99 C
HETATM 3788 C4B NAI A 302 52.695 15.486 8.535 1.00 57.28 C
HETATM 3792 C2B NAI A 302 54.537 14.748 7.190 1.00 50.93 C
HETATM 3790 C3B NAI A 302 54.225 15.525 8.465 1.00 52.99 C
HETATM 3788 C4B NAI A 302 52.695 15.486 8.535 1.00 57.28 C
HETATM 3789 O4B NAI A 302 52.258 14.631 7.456 1.00 56.26 O
HETATM 3790 C3B NAI A 302 54.225 15.525 8.465 1.00 52.99 C
HETATM 3788 C4B NAI A 302 52.695 15.486 8.535 1.00 57.28 C
HETATM 3789 O4B NAI A 302 52.258 14.631 7.456 1.00 56.26 O
HETATM 3794 C1B NAI A 302 53.348 13.816 7.022 1.00 53.44 C
同样的谎言,每个链。链ID可以是A到H. 代码:
import os
import sys
d = {}
chainIDs = ('A', 'B', 'C', 'D',)
atomIDs = ('C4B', 'O4B', 'C1B', 'C2B', 'C3B', 'C4B')
with open('1A7K.pdb') as pdbfile:
for line in map(str.rstrip, pdbfile):
if line[:6] != "HETATM":
continue
chainID = line[21:22]
atomID = line[13:16].strip()
if chainID not in chainIDs:
continue
if atomID not in atomIDs:
continue
try:
d[chainID][atomID] = line
except KeyError:
d[chainID] = {atomID: line}
n = 4
for chain, atoms in d.items():
for atom, line in atoms.items():
for i in range(len(atom)-n+1):
for j in range(n):
print d[chain][atomIDs[i+j]]
print
消息是:
runfile('C:/Users/Desktop/test_python_2.py', wdir='C:/Users/Desktop')
答案 0 :(得分:0)
在您的代码中
for i in range(len(atomIDs)-n+1):
for j in range(len(i)-n+1):
for k in range(len((j))-n+1):
for l in range(n):
您需要i
和j
的长度。这些是整数(从范围获得),并且当您收到状态时,int
个对象没有这样的长度(至少就Python的len
函数而言)。
你究竟想用这些for循环做什么?如果你想打印每个链和原子的每一行,那么下面的东西会起作用吗?
for chain, atoms in d.items():
for atom, line in atoms.items():
print line