python - 从 PDB 中去除杂原子

标签 python biopython protein-database

必须删除 pdb 文件中的杂原子。这是代码,但它不适用于我的测试 PDB 1C4R。

for model in structure:
    for chain in model:
        for reisdue in chain:
            id = residue.id
            if id[0] != ' ':
                chain.detach_child(id)
        if len(chain) == 0:
            model.detach_child(chain.id)

有什么建议吗?

最佳答案

杂原子不应该是链的一部分。但是您可以通过以下方式知道残基是否是杂原子:

pdb = PDBParser().get_structure("1C4R", "1C4R.pdb")

for residue in pdb.get_residues():
    tags = residue.get_full_id()

    # tags contains a tuple with (Structure ID, Model ID, Chain ID, (Residue ID))
    # Residue ID is a tuple with (*Hetero Field*, Residue ID, Insertion Code)

    # Thus you're interested in the Hetero Field, that is empty if the residue
    # is not a hetero atom or have some flag if it is (W for waters, H, etc.)

    if tags[3][0] != " ":
        # The residue is a heteroatom
    else:
        # It is not

您还可以通过以下方式获取残基的 id(没有前三个字段):

tags = residue.id

# or het_flag,_ ,_ = residue.id

if tags[0] != " ":
    # The residue is a heteroatom
else:
    # It is not

我正在添加相关文档的链接:http://biopython.org/DIST/docs/cookbook/biopdb_faq.pdf

主题在第8页,“什么是残基id?”。引用:

This is a bit more complicated, due to the clumsy PDB format. A residue id is a tuple with three elements:

  • The hetero-flag: this is ’H_’ plus the name of the hetero-residue (eg. ’H_GLC’ in the case of a glucose molecule), or ’W’ in the case of a water molecule.

要添加评论并恢复:

from Bio.PDB import PDBParser, PDBIO, Select

class NonHetSelect(Select):
    def accept_residue(self, residue):
        return 1 if residue.id[0] == " " else 0

pdb = PDBParser().get_structure("1C4R", "1C4R.pdb")
io = PDBIO()
io.set_structure(pdb)
io.save("non_het.pdb", NonHetSelect())

关于python - 从 PDB 中去除杂原子,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25718201/

相关文章:

python - Biopython 1.60 中的 Bio.Entrez 和蛋白质问题

linux - 如何删除与另一个文件中的元素匹配的行

python:按子列表中的项目对列表列表进行排序

python - 如何在 tkinter 中进行碰撞?

python - 计算字符串 Python3.6 中子字符串实例的最快方法

python - 使用 Biopython 库删除 PDB 中的残留物

python - pserve 在 docker 容器内不工作

python - 在python数组中排序日期

python - BioPython 中系统发育树的子树