2

我有一个包含几千个结构的 PDB 文件,我想将前十个结构的 α 碳的位置坐标保存到一个 numpy 数组中。我可以使用下面的代码将具有单个结构的 PDB 文件解析为数组,但不能将其扩展到具有许多结构的文件。

from Bio.PDB.PDBParser import PDBParser
import numpy

pdb_filename ='./1fqy.pdb'
parser = PDBParser(PERMISSIVE=1)
structure = parser.get_structure("1fqy", pdb_filename)
model = structure[0]
chain = model["A"]

S1coor = numpy.zeros(shape=(226, 3))
i = 0

for residue1 in chain:
     resnum = residue1.get_id()[1]
     atom1 = residue1['CA']
     S1coor[i] = atom1.get_coord()
     i = i + 1
4

1 回答 1

1
from Bio.PDB.PDBParser import PDBParser
import numpy , tempfile ,os , re

models_re = re.compile("MODEL")
pdb_re = re.compile(r"MODEL(.*?)ENDMDL", re.DOTALL)

def PDB_parse(pdb_file_handle):
    model_pos = []
    models = []
    k = open(pdb_file_handle,"r").read()
    for i in models_re.finditer(k):
        model_pos.append(i.start())
    for i in model_pos:
        models.append(pdb_re.search(k,i).group())
    return models

array_all_structure = []

for i in PDB_parse(pdb_file_handle):
    temp_file = tempfile.NamedTemproaryFile(delete = False)
    temp_file.write(i)
    temp_file.close
    structure = parser.get_structure("1fqy", temp_file.name)
    os.remove(temp_file.name)
    model = structure[0]
    chain = model["A"]
    S1coor = numpy.zeros(shape=(226, 3))
    i = 0
    for residue1 in chain:
       resnum = residue1.get_id()[1]
       atom1 = residue1['CA']
       S1coor[i] = atom1.get_coord()
       i = i + 1
       array_all_structure.append(i)

可能这种链接器会有所帮助,您首先隔离 pdb 文件,然后相应地阅读它们。

于 2013-09-10T06:14:12.090 回答