import pymol2
with pymol2.PyMOL() as pymol:
pymol.cmd.load("1A8O.pdb")
for atom in pymol.cmd.get_model("all").atom:
residue = atom.resi # 获取原子所属的残基序号,字符串类型,因为可能有插入码
res_name = atom.resn # 获取原子所属的残基名称,如ALA, GLY等
print(atom, residue, res_name)
此外,pymol还有很多python API的用法:PyMOL API-only Function Reference
例如:将所选结构中的obj的名字一个一个打印出来
seleobjs = cmd.get_ object_ list('(sele)')
for obj in seleobjs: print obj
使用Pymol运行python脚本中pymol操作的运行方法:
1.打开终端,输入:pymol pml文件/py文件
2.打开GUI>直接将 pml/py script 拖拽进 pymol window
3.打开GUI > pymol的工作路径改为脚本所在的文件夹,在GUI的命令行中输入@script.pml 或者 run script.py
4.打开GUI> file > RUN Script…