PyRosetta加载pose对象

在PyRosetta中,pose 是一个非常重要的对象,代表了蛋白质的构象和结构信息,它为蛋白质结构建模和分析提供了丰富的功能和工具。

### 1. 加载包
from pyrosetta import *
init()
#dir(pyrosetta) # 查看pyrosetta包中的函数

### 2. 加载pose对象

## 查看Pose对象文档
# help(Pose)
# ?Pose

## 2.1 从序列构建
# pose = pose_from_sequence("AAAAAAAA")
# print(my_peptide)

## 2.2 从rcsb数据库下载,生成 clean pdb
pose = pyrosetta.toolbox.pose_from_rcsb("5tj3") 

## 2.3 本地加载
# 加载结构数据,先从https://www.rcsb.org下载好
# pose = pose_from_pdb("inputs/5tj3.pdb")
#pose = pyrosetta.pose_from_file("inputs/5tj3.cif")
pose = pyrosetta.pose_from_file("inputs/5tj3.pdb")

### 3. 生成和加载clean sequence(只有氨基酸序列)
from pyrosetta.toolbox import cleanATOM
cleanATOM("inputs/5tj3.pdb")  # 生成5tj3.clean.pdb文件
pose_clean = pose_from_pdb("inputs/5tj3.clean.pdb")


### 4. 比较cleanATOM前后序列的差异
print(pose_clean.sequence())
print(pose.sequence())

print(pose.annotated_sequence())
print(pose_clean.annotated_sequence())

print(pose.total_residue())
print(pose_clean.total_residue())

### 5. 查看氨基酸残基信息,pose中的编号从1开始
resid = 24
res_24 = pose.residue(resid)

print(res_24)
print(res_24.name())
print(res_24.is_charged())
print(res_24.atom_is_backbone(res_24.atom_index("CA")))

## 二面角
print("phi:", pose.phi(resid))
print("psi:", pose.psi(resid))
print("chi1:", pose.chi(1, resid))


## 锌原子信息
zn_resid = pose.pdb_info().pdb2pose('A', 601)
print("zn_resid: ",zn_resid)
res_zn = pose.residue(zn_resid) 
res_zn.is_metal()

## 查看pdb文件中的氨基酸编号
print(pose.pdb_info().number(24))
print(pose.pdb_info().chain(24))

## pdb,pose中编码转换
print(pose.pdb_info().pose2pdb(24))
print(pose.pdb_info().pdb2pose('A', 24))  # A链的24号氨基酸

### 6. 查看原子,化学键信息
## AtomID类
# help(AtomID)
resid = 28
res_28 = pose.residue(resid)

N28 = AtomID(res_28.atom_index("N"), resid)
CA28 = AtomID(res_28.atom_index("CA"), resid)
C28 = AtomID(res_28.atom_index("C"), resid)
print(res_28)
print(N28)
print(CA28)
print(C28)

## conformation类
conformation = pose.conformation()
#print(conformation)
#help(conformation)

## 键长
print("bond_length:")
print(pose.conformation().bond_length(N28, CA28))
print(pose.conformation().bond_length(CA28, C28))

## 从坐标计算键长
print("calculate from coordinates:")
N_xyz = res_28.xyz("N")
CA_xyz = res_28.xyz("CA")
C_xyz = res_28.xyz("C")
N_CA_vector = CA_xyz - N_xyz
CA_C_vector = CA_xyz - C_xyz
#print(N_xyz)
#print(N_CA_vector)

print(N_CA_vector.norm())
print(CA_C_vector.norm())

print("bond_angle:")
angle = pose.conformation().bond_angle(N28, CA28, C28)
import math
angle = angle*180/math.pi
print(angle)

### 7. 设定和查看键角
# 从序列构建pose对象
my_peptide = pose_from_sequence("AAAAAAAA")
# my_peptide = pyrosetta.pose_from_sequence('A'*8)
print(my_peptide)

orig_phi = my_peptide.phi(2)
orig_psi = my_peptide.psi(2)
print("original phi:", orig_phi)
print("original psi:", orig_psi)

# print the xyz coordinates of the CB atom of residue 2 here BEFORE setting
### BEGIN SOLUTION
print("xyz coordinates:", my_peptide.residue(2).xyz("CB"))

my_peptide.set_phi(2, -60)
my_peptide.set_psi(2, -43)

print("new phi:", my_peptide.phi(2))
print("new psi:", my_peptide.psi(2))

### 8. 查看打分函数
scorefxn = pyrosetta.get_fa_scorefxn()
print(scorefxn)
print(scorefxn(pose))
print(pose.size())

pose.set_psi(3, pose.psi(3) + 87)
pose.set_phi(3, pose.phi(3) + 19)
print(scorefxn(pose))

## 打分越低,结构越稳定

参考:

https://github.com/RosettaCommons/PyRosetta.notebooks/tree/master/notebooks

https://rosettacommons.github.io/PyRosetta.notebooks/

https://www.pyrosetta.org/documentation/pymol_mover-tutorial#h.lbu45b5iaayd

你可能感兴趣的:(生物信息学,python)