以简单的方式将字符串转换为python中的列表

时间:2014-01-08 08:19:02

标签: python biopython

我有一个pdb文件,我想解析pdb。我正在使用Biopython。我希望每个残留物列表中的N-CA-C-CB坐标列表。我怎样才能实现这一目标?

pdb = "1dly.pdb"
name = pdb[:3]

from Bio import PDB
from ast import literal_eval

p = PDB.PDBParser()
s = p.get_structure(name, pdb)
#print dir(s)
#y = s.get_residues()
z = s.get_atoms()
for x in z:
    print x, x.get_coord()

我希望以这种格式输出:

[[(coordinates of N - residue1), (coordinates of CA - residue1), (coordinates of C - residue1), (coordinates of CB - residue1)], [(coordinates of N - residue2), (coordinates of CA - residue2), (coordinates of C - residue2), (coordinates of CB - residue2)]]

我该怎么做?

1 个答案:

答案 0 :(得分:1)

这应该有效(未经测试,因为我没有要测试的pdb文件)。我在这里使用Generators

# first create a generator that parses your structure, one residue at time

def createDesiredList(structure, desired_atoms):
    residues = structure.get_residues()

    for residue in residues:
        return_list = []
        for atom_id in desired_atoms:
            return_list.append((residue[atom_id].get_coord(), residue))
        yield return_list


# then I copy and paste your code .... 

pdb = "1dly.pdb"
name = pdb[:3]

from Bio import PDB
from ast import literal_eval

p = PDB.PDBParser()
s = p.get_structure(name, pdb)

# then I decide which atoms I desire from every residue...

wish_list = ['N', 'CA', 'C', 'CB']

# and finally I run my generator, putting the results in a list.

your_coords_list = [x for x in createDesiredList(s, wish_list)]