def setUp(self):
        self.x = array([[51.65, -1.90, 50.07], [50.40, -1.23, 50.65],
                        [50.68, -0.04, 51.54], [50.22, -0.02, 52.85]])

        self.y = array([[51.30, -2.99, 46.54], [51.09, -1.88, 47.58],
                        [52.36, -1.20, 48.03], [52.71, -1.18, 49.38]])

        self.sup = QCPSuperimposer()
        self.sup.set(self.x, self.y)
Exemple #2
0
    def align(self, structure, transform=True):
        """Align the input structure onto the reference structure.

        Parameters
        ----------
        transform: bool, optional
            If True (default), apply the rotation/translation that minimizes
            the RMSD between the two structures to the input structure. If
            False, the structure is not modified but the optimal RMSD will
            still be calculated.
        """
        self.rms = None  # clear before aligning

        coord = self.get_guide_coord_from_structure(structure)

        if len(coord) < self.window_size * 2:
            n_atoms = len(coord)
            msg = (f"Too few atoms in the mobile structure ({n_atoms}). "
                   "Try reducing the window_size parameter.")
            raise PDBException(msg)

        # Run CEAlign
        # CEAlign returns the best N paths, where each path is a pair of lists
        # with aligned atom indices. Paths are not guaranteed to be unique.
        paths = run_cealign(self.refcoord, coord, self.window_size,
                            self.max_gap)
        unique_paths = {(tuple(pA), tuple(pB)) for pA, pB in paths}

        # Iterate over unique paths and find the one that gives the lowest
        # corresponding RMSD. Use QCP to align the molecules.
        best_rmsd, best_u = 1e6, None
        for u_path in unique_paths:
            idxA, idxB = u_path

            coordsA = np.array([self.refcoord[i] for i in idxA])
            coordsB = np.array([coord[i] for i in idxB])

            aln = QCPSuperimposer()
            aln.set(coordsA, coordsB)
            aln.run()
            if aln.rms < best_rmsd:
                best_rmsd = aln.rms
                best_u = (aln.rot, aln.tran)

        if best_u is None:
            raise RuntimeError("Failed to find a suitable alignment.")

        if transform:
            # Transform all atoms
            rotmtx, trvec = best_u
            for chain in structure.get_chains():
                for resid in chain.get_unpacked_list():
                    for atom in resid.get_unpacked_list():
                        atom.transform(rotmtx, trvec)

        self.rms = best_rmsd
 def calc_rmsd(self, source_atoms, target_atoms):
     from math import sqrt
     import numpy as np
     from Bio.PDB.QCPSuperimposer import QCPSuperimposer
     if len(source_atoms) != len(target_atoms):
         return -1
     source_arr = []
     for atom in source_atoms:
         xyz = [atom.coord[0], atom.coord[1], atom.coord[2]]
         source_arr.append(xyz)
     source_arr = np.array(source_arr)
     target_arr = []
     for atom in target_atoms:
         xyz = [atom.coord[0], atom.coord[1], atom.coord[2]]
         target_arr.append(xyz)
     target_arr = np.array(target_arr)
     sup = QCPSuperimposer()
     sup.set(source_arr, target_arr)
     sup.run()
     return sup.get_rms()
Exemple #4
0
        "Install NumPy if you want to use Bio.QCPSuperimposer.")

from Bio import BiopythonExperimentalWarning
with warnings.catch_warnings():
    warnings.simplefilter('ignore', BiopythonExperimentalWarning)
    from Bio.PDB.QCPSuperimposer import QCPSuperimposer

# start with two coordinate sets (Nx3 arrays - Float0)

x = array([[51.65, -1.90, 50.07], [50.40, -1.23, 50.65], [50.68, -0.04, 51.54],
           [50.22, -0.02, 52.85]], 'f')

y = array([[51.30, -2.99, 46.54], [51.09, -1.88, 47.58], [52.36, -1.20, 48.03],
           [52.71, -1.18, 49.38]], 'f')

sup = QCPSuperimposer()

# set the coords
# y will be rotated and translated on x
sup.set(x, y)

# do the qcp fit
sup.run()

# get the rmsd
rms = sup.get_rms()

# get rotation (right multiplying!) and the translation
rot, tran = sup.get_rotran()

# rotate y on x manually