使用Biopython解析PDB结构

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


文件读取

导入PDBParser读取本地pdb文件

>>> from Bio.PDB import PDBParser
>>> p=PDBParser()
>>> s=p.get_structure("7kn5","7kn5.pdb")
>>> s
<Structure id=7kn5>

get_strucutre()方法有两个参数,第一个参数为id,相当于一个可以自己指定的名字,第二个参数是文件名

结构的表示


一个 Structure 对象的整体布局遵循称为SMCRA(Structure/Model/Chain/Residue/Atom,结构/模型/链/残基/原子)的体系架构:

  • 结构由模型组成
  • 模型由多条链组成
  • 链由残基组成
  • 多个原子构成残基
  • >>> model=s[0]   
    >>> model
    <Model id=0>
    >>> chain=model['A']
    >>> chain 
    <Chain id=A>
    >>> for i in chain:
    ...     print(i)
    ... 
    <Residue GLN het=  resseq=1 icode= >
    <Residue VAL het=  resseq=2 icode= >
    <Residue GLN het=  resseq=3 icode= >
    >>> chain[3]
    <Residue GLN het=  resseq=3 icode= >
    

    笔者这里导入的蛋白是一个只有单链的蛋白,因此chain也只有一条,对于有多条链的蛋白可以用ABCDEF一直索引下去;而每个链由多个氨基酸组成,直接使用下标索引可以找到,这里只列出了遍历结果的小部分。
    注意:chain的下标是从1开始的,不是从0开始的

    对于不同链的描述,其实用PDB也可以看到的

    残基对象的一些其他方法:

    >>> residue.get_resname()       # 返回残基名称,如 "ASN"
    >>> residue.is_disordered()     # 返回1如果该残基含有无序原子
    >>> residue.get_segid()         # 返回其SEGID如"CHN1"
    >>> residue.has_id(name)        # 判断一个残疾是否有某个原子
    

    atom对象包含在chain:

    >>>chain[1]
    <Residue GLN het=  resseq=1 icode= >
    >>> for atom in chain[1]:
    ...     print(atom)
    ... 
    <Atom N>
    <Atom CA>
    <Atom C>
    <Atom CB>
    <Atom O>
    <Atom CG>
    <Atom CD>
    <Atom NE2>
    <Atom OE1>
    

    用文字索引可以指向某个chain的atom:

    >>> atom=residue['CA'] 
    
    >>> for key in atom.__dict__:
    ...     print(key,atom.__dict__[key])
    ... 
    level A
    parent <Residue GLN het=  resseq=1 icode= >
    name CA
    fullname  CA
    coord [20.024 -3.073 -1.719]
    bfactor 86.76
    occupancy 1.0
    altloc
    full_id ('7kn5', 0, 'A', (' ', 1, ' '), ('CA', ' '))
    id CA
    disordered_flag 0
    anisou_array None
    siguij_array None
    sigatm_array None
    serial_number 2
    xtra {}
    element C
    mass 12.0107
    pqr_charge None
    radius None
    _sorting_keys {'N': 0, 'CA': 1, 'C': 2, 'O': 3}
    

    可以看出,atom对象中存储了包括原子名称,原子坐标,B因子,原子质量,altloc标识符和原子名称等数据

    随缘更新后续内容

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Biopython提供了许多可视化序列和结构的工具,包括PDB文件解析器、蛋白质结构可视化、序列比对、序列Logo图等。下面介绍如何使用Biopython可视化PDB文件中的蛋白质序列和结构。 1. 安装Biopython Biopython可以通过pip安装,在命令行中输入以下命令: ``` pip install biopython ``` 2. 下载PDB文件 可以从PDB数据库中下载PDB文件,也可以使用Biopython中的PDB模块下载。这里以下载PDB ID为1TIM的文件为例: ```python from Bio.PDB import PDBList pdbl = PDBList() pdbl.retrieve_pdb_file('1TIM') ``` 3. 解析PDB文件 使用Biopython中的PDB模块解析PDB文件,并提取蛋白质序列和结构信息: ```python from Bio.PDB import PDBParser parser = PDBParser() structure = parser.get_structure('1TIM', '1tim.pdb') # 提取第一个模型的第一个链的序列 chain_id = 'A' chain = structure[0][chain_id] sequence = '' for residue in chain: if residue.get_resname() == 'HOH': # 去除水分子 continue sequence += residue.get_resname() print(f'{chain_id} sequence: {sequence}') # 提取第一个模型的结构信息 model = structure[0] atoms = [] for chain in model: for residue in chain: if residue.get_resname() == 'HOH': # 去除水分子 continue for atom in residue: atoms.append(atom) print(f'{len(atoms)} atoms in the structure') ``` 4. 可视化蛋白质结构 使用Biopython中的PDB模块和Matplotlib模块可视化蛋白质结构: ```python from Bio.PDB import PDBIO, Select from matplotlib import pyplot as plt class ChainSelector(Select): def __init__(self, chain_id): self.chain_id = chain_id def accept_chain(self, chain): if chain.get_id() == self.chain_id: return 1 else: return 0 # 提取第一个模型的第一个链的结构信息 chain_id = 'A' chain = structure[0][chain_id] atoms = [] for residue in chain: if residue.get_resname() == 'HOH': # 去除水分子 continue for atom in residue: atoms.append(atom) # 可视化结构 fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(111, projection='3d') ax.set_title(f'Chain {chain_id}') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') io = PDBIO() io.set_structure(chain) io.save(f'chain_{chain_id}.pdb') pdb_file = f'chain_{chain_id}.pdb' io = PDBIO() io.set_structure(chain) io.save(pdb_file, ChainSelector(chain_id)) from Bio.PDB.PDBIO import Select from Bio.PDB.PDBParser import PDBParser from Bio.PDB.Structure import Structure from Bio.PDB.Residue import Residue from Bio.PDB.Atom import Atom class ChainSelector(Select): def __init__(self, chain_id): self.chain_id = chain_id def accept_chain(self, chain): if chain.get_id() == self.chain_id: return 1 else: return 0 parser = PDBParser() structure = parser.get_structure('1TIM', pdb_file) # 提取第一个模型的第一个链的结构信息 chain_id = 'A' chain = structure[0][chain_id] atoms = [] for residue in chain: if residue.get_resname() == 'HOH': # 去除水分子 continue for atom in residue: atoms.append(atom) # 可视化结构 fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(111, projection='3d') ax.set_title(f'Chain {chain_id}') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') for atom in atoms: ax.scatter(atom.get_coord()[0], atom.get_coord()[1], atom.get_coord()[2]) plt.show() ``` 运行以上代码,即可生成一个3D图形,显示蛋白质的结构

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值