如何在pymol命令行中启用python循环?



这里说脚本应该在pymol命令行中使用。阅读本文后,我想使用循环输出许多距离。但是我收到错误消息:

File "<string>", line 1
for i in range(resi_total_n):
^
SyntaxError: unexpected EOF while parsing

我的代码是:

from pymol import cmd
mol_name='name'
resi=10 # the target residue number
resi_total_n=500 # the total residue number
f=open('dist.txt','w')
resi_n=0
for i in range(resi_total_n):
resi_n += 1
dst=cmd.distance('tmp',mol_name+'///'+str(resi)+'/ca',mol_name+'///'+str(resi_n)+'/ca') #the alpha carbon
f.write("%8.3fn"%dst)
f.close()

在这里我找到了答案:

在尝试编程时,最好坚持使用Python。救 以下内容作为 Pymol 内部 script.py 和使用run script.py或 只是发出pymol script.py

不需要将脚本作为单独的文件运行。您可以将所有 for 循环放在一行上,例如,

运行此代码时:

for c in chains:
print c

您会收到此错误:

File "toplevel", line 1
for c in chains:
^
SyntaxError: unexpected EOF while parsing

但如果你写:

for c in chains: print(c)

给出输出

A
B
C
D

最新更新