1

必须删除 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)

有什么建议吗?

4

2 回答 2

3

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

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?”。报价:

由于笨拙的 PDB 格式,这有点复杂。残基 id 是一个包含三个元素的元组:

  • 异质标志:这是“H_”加上异质残基的名称(例如,在葡萄糖分子的情况下为“H_GLC”),或在水分子的情况下为“W”。

要添加评论并恢复:

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())
于 2014-09-08T06:43:49.150 回答
0

我曾经使用过来自http://pelican.rsvs.ulaval.ca/mediawiki/index.php/Manipulating_PDB_files_using_BioPython的代码“ Removing residuals ”

它会遗漏一些杂原子。我想这可能是因为每次调用detach_child时都会发生变化。

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)

如下修改后(只是避免动态修改可迭代),它对我来说很好。(我在这里只使用了结构[0]。)

model = structure[0]
residue_to_remove = []
chain_to_remove = []
for chain in model:
    for residue in chain:
        if residue.id[0] != ' ':
            residue_to_remove.append((chain.id, residue.id))
    if len(chain) == 0:
        chain_to_remove.append(chain.id)

for residue in residue_to_remove:
    model[residue[0]].detach_child(residue[1])

for chain in chain_to_remove:
    model.detach_child(chain)
于 2016-03-18T21:35:45.800 回答