biopython PDB:如何通过原子的序列号引用原子列表

1 投票
2 回答
1416 浏览
提问于 2025-04-18 07:36

我在使用biopython的时候遇到了一些困难。我成功地从一个结构对象中获取了所有原子的列表,还能获取和设置坐标,以及提取序列号:

from Bio import PDB

pdb = "file.pdb"
name = "file"
p = PDB.PDBParser()
struct_in = p.get_structure(name, pdb)

for atom in PDB.Selection.unfold_entities(struct_in, target_level='A'):
    atom.set_coord(np.array((1,2,3)))
    atom.transform(unity3,(2,-2,1))
    print atom.get_serial_number()

但是,我无法通过序列号来引用某个特定的原子(比如索引23),以便更改它的坐标。我在寻找类似于下面第二行的虚构“get_atom_by_index()”函数(但实际上并不能这样用):

atomList = PDB.Selection.unfold_entities(struct_in, target_level='A')
atomList.get_atom_by_index(23).set_coord(newCoord)

当然,我可以做一些类似这样的事情:

for i in atomList:
    if atomList[i].get_serial_number() == 23:
        atomList[i].set_coord(newCoord)

但我更希望能避免这个额外的循环。一定有更方便的方法可以做到这一点!

提前感谢你们!

弗雷德

2 个回答

0

你可以把PDB放进一个字典里,字典的键是原子的序列号:

selection = PDB.Selection.unfold_entities(struct_in, target_level='A')
serial_numbers = [atom.serial_number for atom in selection]

selection_dict = dict(zip(serial_numbers, selection))

# selection_dict is now something like:
# {1: <Atom N>, 2: <Atom CA>, 3: <Atom C>, ...}

现在你可以直接用这些键来访问字典,而不需要一个一个循环去找:

selection_dict[23].set_coord(np.array((1,2,3)))
0

如果你知道具体的索引号,那为什么不直接这样做呢:

atomList[23].set_coord(newCoord)

撰写回答