@@ -539,11 +539,12 @@ def parse_pdb(filename, **kwargs):
539539
540540def parse_pdb_lines (lines , parse_hetatom = False , ignore_het_h = True ):
541541 # indices of residues observed in the structure
542- res = [
543- (l [22 :26 ], l [17 :20 ])
544- for l in lines
545- if l [:4 ] == "ATOM" and l [12 :16 ].strip () == "CA"
546- ]
542+ res , pdb_idx = [],[]
543+ for l in lines :
544+ if l [:4 ] == "ATOM" and l [12 :16 ].strip () == "CA" :
545+ res .append ((l [22 :26 ], l [17 :20 ]))
546+ # chain letter, res num
547+ pdb_idx .append ((l [21 :22 ].strip (), int (l [22 :26 ].strip ())))
547548 seq = [util .aa2num [r [1 ]] if r [1 ] in util .aa2num .keys () else 20 for r in res ]
548549 pdb_idx = [
549550 (l [21 :22 ].strip (), int (l [22 :26 ].strip ()))
@@ -562,16 +563,17 @@ def parse_pdb_lines(lines, parse_hetatom=False, ignore_het_h=True):
562563 " " + l [12 :16 ].strip ().ljust (3 ),
563564 l [17 :20 ],
564565 )
565- idx = pdb_idx .index ((chain , resNo ))
566- # for i_atm, tgtatm in enumerate(util.aa2long[util.aa2num[aa]]):
567- for i_atm , tgtatm in enumerate (
568- util .aa2long [util .aa2num [aa ]][:14 ]
569- ): # Nate's proposed change
570- if (
571- tgtatm is not None and tgtatm .strip () == atom .strip ()
572- ): # ignore whitespace
573- xyz [idx , i_atm , :] = [float (l [30 :38 ]), float (l [38 :46 ]), float (l [46 :54 ])]
574- break
566+ if (chain ,resNo ) in pdb_idx :
567+ idx = pdb_idx .index ((chain , resNo ))
568+ # for i_atm, tgtatm in enumerate(util.aa2long[util.aa2num[aa]]):
569+ for i_atm , tgtatm in enumerate (
570+ util .aa2long [util .aa2num [aa ]][:14 ]
571+ ):
572+ if (
573+ tgtatm is not None and tgtatm .strip () == atom .strip ()
574+ ): # ignore whitespace
575+ xyz [idx , i_atm , :] = [float (l [30 :38 ]), float (l [38 :46 ]), float (l [46 :54 ])]
576+ break
575577
576578 # save atom mask
577579 mask = np .logical_not (np .isnan (xyz [..., 0 ]))
0 commit comments