2016-02-29 87 views
0

对于以下代码,执行代码时,出现以下列出的错误。我想知道是否有人可以告诉我如何将CA原子添加到tag_atoms/tagged_atoms列表中,我将用它来对齐,并突出显示代码被写入的方式中的任何潜在缺陷,新来的Python,所以任何见解将是巨大的和非常有益的尝试创建CA原子列表时,执行以下代码时出现以下错误“关键错误CA”

def loadPDB(pdb_name): 

    folder = pdb_name[1:3] 
    pdbl = PDB.PDBList() 
    pdbl.retrieve_pdb_file(pdb_name) 
    parser = PDB.PDBParser(PERMISSIVE=1) 
    structure = parser.get_structure(
     pdb_name, folder + "/pdb" + pdb_name + ".ent") 

    return structure 

def alignCoordinates(taggedProtein, potentialTag): 
    for model in taggedProtein: 
     firstModel = model 
     break 
    for chain in firstModel: 
     firstChain = chain 
     break 

    for firstChain in firstModel: 
     tagged_atoms = [] 
     tag_atoms = [] 

     for residue in firstChain: 
      tagged_res = residue 

     for tagged_res in firstChain: 
      tagged_atoms.append(firstChain['CA']) 

    for model in potentialTag: 
     firstTagModel = model 
     break 

    for chain in firstTagModel: 
     firstTagChain = chain 
     break 

    for residue in firstTagChain: 
     tag_res = residue 

     for tag_res in firstTagChain: 
      tag_atoms.append(firstTagChain['CA']) 

    super_imposer = Bio.PDB.Superimposer() 
    print repr(tagged_atoms) 
    print repr(tag_atoms) 
    super_imposer.set_atoms(tagged_atoms, tag_atoms) 
    super_imposer.apply(tag_model.get_atoms()) 

    print super_imposer.rms 

    io = Bio.PDB.PDBIO() 
    io.set_structure(tag_model) 
    io.save("Aligned.PDB") 

def main(): 

    pdb1 = "2lyz" 
    pdb2 = "4abn" 

    potentialTag = loadPDB(pdb1) 
    taggedProtein = loadPDB(pdb2) 

    alignCoordinates(taggedProtein, potentialTag) 

main() 

这是下面的错误信息:

Structure exists: '/Users/Azi_Ts/Desktop/ly/pdb2lyz.ent' 
Structure exists: '/Users/Azi_Ts/Desktop/ab/pdb4abn.ent' 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:87:   PDBConstructionWarning: WARNING: Chain A is discontinuous at line 13957. 
    PDBConstructionWarning) 
/Library/Python/2.7/site-packages/Bio/PDB/StructureBuilder.py:87: PDBConstructionWarning: WARNING: Chain B is discontinuous at line 14185. 
    PDBConstructionWarning) 

Traceback (most recent call last): 
    File "alignPDB.py", line 76, in <module> 
    main() 
    File "alignPDB.py", line 74, in main 
    alignCoordinates(taggedProtein, potentialTag) 
    File "alignPDB.py", line 39, in alignCoordinates 
    tagged_atoms.append(firstChain['CA']) 
    File "/Library/Python/2.7/site-packages/Bio/PDB/Chain.py", line 70, in __getitem__ 
    return Entity.__getitem__(self, id) 
    File "/Library/Python/2.7/site-packages/Bio/PDB/Entity.py", line 38, in __getitem__ 
    return self.child_dict[id] 
KeyError: 'CA' 

回答

0

要获取所有CA原子,你只需要做到:

ca_atoms = [atom for atom in taggedProtein.get_atoms() if atom.name=="CA"] 

记住结构加载,taggedProteinpotentialTag,有三种方法,可能是这里有用:get_chains()get_residues()get_atoms()。使用这三个,你可以摆脱你在def alignCoordinates()中的每一个for循环。

相关问题