我想添加到更多的段落,但得到錯誤?我能夠打印前三段,但是當我嘗試添加更多的段落時出現錯誤。任何人都可以請糾正?我想在Python中打印一些預定義的序列
輸入文件:
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')
錯誤提示:「'i'是一個整數值,你不能使用'len'。考慮在範圍(i-n + 1)中使用'j:' – cel
@cel,使用的腳本正在運行但未得到結果? msg是:runfile('C:/Users/Desktop/test_python_2.py',wdir ='C:/ Users/Desktop') – Vish