示例#1
0
 def calculate_results(self):
   ref_crds = []
   crds = []
   for ref_residue, residue in zip(self.ref_soup.residues(), self.soup.residues()):
     if residue.type not in data.solvent_res_types:
       if residue.has_atom('CA'):
         ref_crds.append(ref_residue.atom('CA').pos.copy())
         crds.append(residue.atom('CA').pos.copy())
   center = v3.get_center(crds)
   crds = [c - center for c in crds]
   ref_center = v3.get_center(ref_crds)
   ref_crds = [c - ref_center for c in ref_crds]
   rmsd_val, transform_ref_to_this = rmsd.calc_rmsd_rot(ref_crds, crds)
   ref_crds = [v3.transform(transform_ref_to_this, c) for c in ref_crds]
   return [v3.distance(crd, ref_crd) for crd, ref_crd in zip(crds, ref_crds)]
def rmsd_of_soups(
    soup1, soup2, segments1=[], segments2=[],
    atom_types=['CA'], transform_pdb1=None):
  """
  Returns the RMSD between two PDB structures and optionally
  writes the best transformed structure of pdb1 in transform_pdb.

  By default, it chooses the CA atoms in the soup.

  Args:
    segments1 (list): list of pairs of residue names in pdb1,
                     such as ['A:1','A:3'], interpreted as the
                     two ends of a fragment in soup that we want
                     the atom index of
    segments2 (list): same as above but for pdb2
    atom_types (list): list of atom_types in the residues that
                       we want to generate the indices from.
  """
  atoms1 = get_superposable_atoms(soup1, segments1, atom_types)
  atoms2 = get_superposable_atoms(soup2, segments2, atom_types)

  crds1 = [a.pos for a in atoms1]
  crds2 = [a.pos for a in atoms2]

  center1 = v3.get_center(crds1)
  center2 = v3.get_center(crds2)

  soup1.transform(v3.translation(-center1))
  soup2.transform(v3.translation(-center2))

  rmsd, transform_1_to_2 = calc_rmsd_rot(crds1, crds2)

  if not transform_pdb1:
    return rmsd

  soup1.transform(transform_1_to_2)

  soup1.transform(v3.translation(center2))
  soup2.transform(v3.translation(center2))

  soup1.write_pdb(transform_pdb1)
  return sum_rmsd(crds1, crds2)