如何在 pymol 命令行中启用 python 循环?
How to enable python loop in pymol command line?
Here said the script should be used within the pymol commandline. I would like to output many distances using a loop after reading this。但我收到错误消息:
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.3f\n"%dst)
f.close()
Here 我找到了答案:
尝试编程时,最好坚持 Python。救球
以下为 script.py 并在 Pymol 中使用 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
Here said the script should be used within the pymol commandline. I would like to output many distances using a loop after reading this。但我收到错误消息:
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.3f\n"%dst)
f.close()
Here 我找到了答案:
尝试编程时,最好坚持 Python。救球
以下为 script.py 并在 Pymol 中使用 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