Exemple #1
0
def matchAlign(mobile, target, **kwargs):
    """Superpose *mobile* onto *target* based on best matching pair of chains.
    
    .. versionadded:: 0.7.1

    This function makes use of :func:`matchChains` for matching chains.
  
    This function returns a tuple that contains the following items:
      
      * *mobile* after it is superposed,
      * Matching chain from *mobile* as a :class:`~prody.atomic.AtomMap` 
        instance, 
      * Matching chain from *target* as a :class:`~prody.atomic.AtomMap` 
        instance,
      * Percent sequence identity of the match,
      * Percent sequence overlap of the match.
     
    """
    
    match = matchChains(mobile, target, **kwargs)
    if not match:
        return
    match = match[0]
    LOGGER.info('RMSD before alignment (A): {0:.2f}'
                .format(prody.calcRMSD(match[0], match[1])))
    prody.calcTransformation(match[0], match[1]).apply(mobile)
    LOGGER.info('RMSD after alignment  (A): {0:.2f}'
                .format(prody.calcRMSD(match[0], match[1])))
    return (mobile,) + match
    def doPy(self):
        print "calculating ...."
        import prody
        """
        -----
        pip install prody
        or
        http://prody.csb.pitt.edu/index.html
        ------
        RMSF[i]=sqrt(ave((x[i]-average_x[i])**2))
        delta2=(x[i]-average_x[i])**2
        
        B-factor=8*pi**2*RMSF**2/3
        Ref: Willis & Pryor, Thermal vibrations in crystallography, Cambridge Univ. Press, 1975
        unit: Angstrom**2
        """
        
        tmpcoord=[]
        nframes=len(self.coordinates)
        ave_coordinate=np.average(self.coordinates,axis=0)
        
        rmsf=np.zeros(len(self.coordinates[0]))

        for j in range(nframes):
            t=prody.calcTransformation(ave_coordinate,self.coordinates[j])
            for i in range(self.natoms):
                delta2=(self.coordinates[j][i].dot(t.getRotation())-ave_coordinate[i])
                rmsf[i]+=delta2.dot(delta2)

                
        self.cal_bfactor=np.sqrt(rmsf/nframes)**2*8*np.pi**2/3
        print "done!!"
        return np.sqrt(rmsf/nframes)**2*8*np.pi**2/3
def orient(pdb, selection='all'):
    act = pdb.select(selection)
    adj = prody.calcCenter(act)
    oldcoords = act.getCoords()
    newcoords = np.subtract(oldcoords, adj)
    nncoords = varimax(newcoords)
    trans = prody.calcTransformation(oldcoords, nncoords)
    trans.apply(pdb)
    return pdb
Exemple #4
0
def compare_pdb_files(file1, file2):
    """Returns the RMSD between two PDB files of the same protein.

    Args:
        file1 (str): Path to first PDB file.
        file2 (str): Path to second PDB file. Must be the same protein as in file1.

    Returns:
        float: Root Mean Squared Deviation (RMSD) between the two structures.
    """
    s1 = pr.parsePDB(file1)
    s2 = pr.parsePDB(file2)
    transformation = pr.calcTransformation(s1, s2)
    s1_aligned = transformation.apply(s1)
    return pr.calcRMSD(s1_aligned, s2)
Exemple #5
0
def rmsd(a, b):
    """Return the RMSD between two sets of coordinates."""
    t = pr.calcTransformation(a, b)
    return pr.calcRMSD(t.apply(a), b)
Exemple #6
0
 def compute_transformation(self):
     self.transformation = prody.calcTransformation(self.mobile, self.target)
Exemple #7
0
 def _do_align(self):
     self._transformation = prody.calcTransformation(self._prediction, self._native)
     self._transformation.apply(self._prediction)
     rmsd = prody.calcRMSD(self._native, self._prediction)
     self._align_results = RMSDAlignmentResult(rmsd)
Exemple #8
0
def calcS2(model_list, S2_records, S2_type, fit, fit_range):
    """Returns a dictonary with the average S2 values:
    S2_calced[residue] = value"""

    # fitting models
    reference = model_list[0]

    if fit and not PDB_model.is_fitted:
        print("Start FITTING")
        for i in range(1, len(model_list)):
            mobile = model_list[i]
            matches = prody.matchChains(reference, mobile)
            match = matches[0]
            ref_chain = match[0]
            mob_chain = match[1]

            if fit_range:
                weights = np.zeros((len(ref_chain), 1), dtype=np.int)

                fit_start, fit_end = fit_range.split('-')

                for i in range(int(fit_start) - 1, int(fit_end) - 1):
                    weights[i] = 1

            else:
                weights = np.ones((len(ref_chain), 1), dtype=np.int)

            t = prody.calcTransformation(mob_chain, ref_chain, weights)
            t.apply(mobile)

        PDB_model.is_fitted = True

    # get NH vectors from models (model_data[] -> vectors{resnum : vector})
    model_data = []
    s2_pairs = {'N': 'H', 'CA': 'HA'}

    for model in model_list:
        current_Resindex = 1
        has_first, has_second = False, False
        vectors = {}

        for atom in model:
            # why not .getResnum() ???
            atom_res = atom.getResindex() + 1

            if atom_res != current_Resindex:
                current_Resindex = atom_res
                has_first, has_second = False, False

            if atom_res == current_Resindex:
                if atom.getName() == S2_type:
                    has_second = True
                    N_coords = Vec_3D(atom.getCoords())

                elif atom.getName() == s2_pairs[S2_type]:
                    has_first = True
                    H_coords = Vec_3D(atom.getCoords())

                if has_first and has_second:
                    has_first, has_second = False, False
                    vectors[atom_res] = Vec_3D(N_coords - H_coords).normalize()

        model_data.append(vectors)

    S2_calced = {}

    # iterating over STR records
    for resnum in [int(s2rec.resnum) for s2rec in S2_records]:

        x2, y2, z2, xy, xz, yz = 0, 0, 0, 0, 0, 0

        # iterating over PDB models
        for m in model_data:

            # coordinates in model at a given resnum
            x, y, z = m[resnum].v[0], m[resnum].v[1], m[resnum].v[2]

            x2 += x**2
            y2 += y**2
            z2 += z**2
            xy += x * y
            xz += x * z
            yz += y * z

        x2 /= len(model_data)
        y2 /= len(model_data)
        z2 /= len(model_data)
        xy /= len(model_data)
        xz /= len(model_data)
        yz /= len(model_data)

        # S2 calcuation
        s2 = 3 / 2.0 * (x2**2 + y2**2 + z2**2 + 2 * xy**2 + 2 * xz**2 +
                        2 * yz**2) - 0.5

        S2_calced[resnum] = s2

    return S2_calced
def s2_values(
    model_data, calculate_on_models, s2_records, s2_type, fit, fit_range
):
    """Returns a dictionary with the average S2 values:
    s2_calced[residue] = value"""
    if fit:
        reference = model_data.atomgroup[:]

        model_data.atomgroup.setACSIndex(0)
        prody.alignCoordsets(model_data.atomgroup.calpha)

        if fit_range:
            for model_num in calculate_on_models:
                model_data.atomgroup.setACSIndex(model_num)

                mobile = model_data.atomgroup[:]
                matches = prody.matchChains(reference, mobile)
                match = matches[0]
                ref_chain = match[0]
                mob_chain = match[1]

                weights = np.zeros((len(ref_chain), 1), dtype=np.int)

                fit_start, fit_end = fit_range.split("-")

                for i in range(int(fit_start) - 1, int(fit_end) - 1):
                    weights[i] = 1

                t = prody.calcTransformation(mob_chain, ref_chain, weights)
                t.apply(mobile)

    # get NH vectors from models (model_data[] -> vectors{resnum : vector})
    vector_data = []
    s2_pairs = {"N": "H", "CA": "HA"}
    h_coords = None
    n_coords = None

    for model_num in calculate_on_models:
        model_data.atomgroup.setACSIndex(model_num)
        current_resindex = 1
        has_first, has_second = False, False
        vectors = {}

        for atom in model_data.atomgroup:
            atom_res = atom.getResnum()

            if atom_res != current_resindex:
                current_resindex = atom_res
                has_first, has_second = False, False

            if atom_res == current_resindex:
                if atom.getName() == s2_type:
                    has_second = True
                    n_coords = Vec3D(atom.getCoords())

                elif atom.getName() == s2_pairs[s2_type]:
                    has_first = True
                    h_coords = Vec3D(atom.getCoords())

                if has_first and has_second:
                    has_first, has_second = False, False
                    vectors[atom_res] = Vec3D(
                        n_coords - h_coords
                    ).normalize()

        vector_data.append(vectors)

    s2_calced = {}

    # iterating over STR records
    for resnum in [int(s2rec.resnum) for s2rec in s2_records]:

        x2, y2, z2, xy, xz, yz = 0, 0, 0, 0, 0, 0

        # iterating over PDB models
        for m in vector_data:

            # coordinates in model at a given resnum
            x, y, z = m[resnum].v[0], m[resnum].v[1], m[resnum].v[2]

            x2 += x ** 2
            y2 += y ** 2
            z2 += z ** 2
            xy += x * y
            xz += x * z
            yz += y * z

        x2 /= len(vector_data)
        y2 /= len(vector_data)
        z2 /= len(vector_data)
        xy /= len(vector_data)
        xz /= len(vector_data)
        yz /= len(vector_data)

        s2 = (
            3
            / 2.0
            * (
                x2 ** 2
                + y2 ** 2
                + z2 ** 2
                + 2 * xy ** 2
                + 2 * xz ** 2
                + 2 * yz ** 2
            )
            - 0.5
        )

        s2_calced[resnum] = s2

    return s2_calced
Exemple #10
0
 def _do_align(self):
     self._transformation = prody.calcTransformation(
         self._prediction, self._native)
     self._transformation.apply(self._prediction)
     rmsd = prody.calcRMSD(self._native, self._prediction)
     self._align_results = RMSDAlignmentResult(rmsd)