biopython PDB:如何通过atom引用atom列表';s序列号

biopython PDB:如何通过atom引用atom列表';s序列号,python,biopython,Python,Biopython,我在和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_c

我在和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()”函数的东西(它不是那样工作的):

当然,我可以这样做

for i in atomList:
    if atomList[i].get_serial_number() == 23:
        atomList[i].set_coord(newCoord)
但我更愿意避免这个额外的循环。一定有更方便的方法

提前谢谢
弗雷德

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

atomList[23].set_coord(newCoord)

您可以将PDB放入dict中,根据原子序列号创建密钥:

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>, ...}

因为列表索引(从[0:len(atomList)-1]开始)不等于pdb文件中给定的序列号,有时是不连续的。它不应该不一致。它应该是从0到。。。或从1。。。;没道理!想象一下,pdb文件中的原子数[4,5,6,23,24,25,…]不是连续的。事实上,这并不罕见。你见过pdb文件的内容吗?无论如何,这些原子将在列表变量中用[0,1,2,3,4,5,…]索引。好的,明白了!很快就会回来的!
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)))