【发布时间】:2015-03-16 07:44:21
【问题描述】:
我想知道如何使用biopython 库将多个 pdb 写入单个 pdb 文件。对于读取多个pdb,例如NMR结构,documentation中有内容,但对于写作,我没有找到。有人对此有想法吗?
【问题讨论】:
标签: biopython
我想知道如何使用biopython 库将多个 pdb 写入单个 pdb 文件。对于读取多个pdb,例如NMR结构,documentation中有内容,但对于写作,我没有找到。有人对此有想法吗?
【问题讨论】:
标签: biopython
是的,你可以。它记录在here。
图片您有一个结构对象列表,我们将其命名为structures。您可能想尝试:
from bio import PDB
pdb_io = PDB.PDBIO()
target_file = 'all_struc.pdb'
with pdb_file as open_file:
for struct in structures:
pdb_io.set_structure(struct[0])
pdb_io.save(open_file)
这是解决此问题的最简单方法。一些重要的事情:
请注意,NMR 结构包含多个实体。您可能想选择一个。希望对您有所帮助。
【讨论】:
Mithrado 的解决方案实际上可能无法实现您想要的。使用他的代码,您确实可以将所有结构写入一个文件。但是,它以其他软件可能无法读取的方式这样做。它在每个结构之后添加一个“END”行。许多软件会在此时停止读取文件,因为这是指定 PDB 文件格式的方式。
一个更好但仍不完美的解决方案是从一个结构中删除一个链并将其作为不同的链添加到第二个结构中。你可以这样做:
# Get a list of the chains in a structure
chains = list(structure2.get_chains())
# Rename the chain (in my case, I rename from 'A' to 'B')
chains[0].id = 'B'
# Detach this chain from structure2
chains[0].detach_parent()
# Add it onto structure1
structure1[0].add(chains[0])
请注意,您必须小心,您要添加的链的名称在 structure1 中尚不存在。
在我看来,Biopython 库在许多方面结构不佳或不直观,这只是一个例子。如果可以,请使用其他东西。
【讨论】:
受 Nate 解决方案的启发,但将多个模型添加到一个结构,而不是多个链到一个模型:
ms = PDB.Structure.Structure("master")
i=0
for structure in structures:
for model in list(structure):
new_model=model.copy()
new_model.id=i
new_model.serial_num=i+1
i=i+1
ms.add(new_model)
pdb_io = PDB.PDBIO()
pdb_io.set_structure(ms)
pdb_io.save("all.pdb")
【讨论】: