Esempio n. 1
0
def cal_rmsd_ca(decoy_name, native):
    decoy_list = read_pdb(decoy_name)
    native_list = read_pdb(native)
    ca1 = []
    ca2 = []
    if len(decoy_list) != len(native_list):
        num1 = decoy_list[0].id[1]
        num2 = native_list[0].id[1]
        if num1 != num2:
            max_num = max([num1, num2])
            length_seq = len(decoy_list[max_num:])
        else:
            length_seq = len(native_list)
    else:
        length_seq = len(native_list)
    #print(length_seq)
    #print("************",len(decoy_list), len(native_list), native, decoy_name)
    for i in range(length_seq):
        if decoy_list[i] and native_list[i]:
            ca1.append(decoy_list[i]['CA'].coord)
            ca2.append(native_list[i]['CA'].coord)
    x = np.array(ca1)
    y = np.array(ca2)
    sup = SVD.SVDSuperimposer()
    sup.set(x, y)
    sup.run()
    rms = sup.get_rms()
    return rms
Esempio n. 2
0
def cal_rmsd_ca_new(decoy_name, native):
    decoy_list = read_pdb(decoy_name)
    native_list = read_pdb(native)
    ca_num_decoy = [i.id[1] for i in decoy_list]
    ca_num_native = [i.id[1] for i in native_list]
    ca_num = [i for i in ca_num_decoy if i in ca_num_native]
    ca1 = []
    ca2 = []
    for i in decoy_list:
        if i.id[1] in ca_num:
            ca1.append(i['CA'].coord)
    for j in native_list:
        if j.id[1] in ca_num:
            ca2.append(j['CA'].coord)
    x = np.array(ca1)
    y = np.array(ca2)
    sup = SVD.SVDSuperimposer()
    sup.set(x, y)
    sup.run()
    rms = sup.get_rms()
    return rms
Esempio n. 3
0
except ImportError:
    from Bio import MissingPythonDependencyError
    raise MissingPythonDependencyError(
        "Install NumPy if you want to use Bio.SVDSuperimposer.")

from Bio.SVDSuperimposer import *

# 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 = SVDSuperimposer()

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

# do the lsq 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
Esempio n. 4
0
from Bio.SVDSuperimposer import *

# 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=SVDSuperimposer()

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

# do the lsq 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
Esempio n. 5
0
def superimpose(a1, a2):

    sup = SVDSuperimposer()

    a1 = np.asarray(a1)
    a2 = np.asarray(a2)

    if len(a1) <= 7:

        min_dist = (1.0E6, 'foo', 'bar')

        for l in itertools.permutations(a1):

            p = np.asarray(l)
            sup.set(a2, p)
            sup.run()
            rot, tran = sup.get_rotran()
            rms = sup.get_rms()

            if rms < min_dist[0]:
                min_dist = (rms, rot, tran)

    else:

        a1, a2 = match_vectors(a1, a2, 6)
        min_dist = (1.0E6, 'foo', 'bar')

        for l in itertools.permutations(a1):

            p = np.asarray(l)
            sup.set(a2, p)
            sup.run()
            rot, tran = sup.get_rotran()
            rms = sup.get_rms()

            if rms < min_dist[0]:
                min_dist = (rms, rot, tran)

    return min_dist
Esempio n. 6
0
def mag_superimpose(a1, a2):

    sup = SVDSuperimposer()

    a1 = np.asarray(a1)
    a2 = np.asarray(a2)
    mags = [norm(v) for v in a2]

    if len(a1) <= 7:

        min_dist = (1.0E6, 'foo', 'bar')

        for l in itertools.permutations(a1):

            p = np.array([m * v / norm(v) for m, v in zip(mags, l)])
            sup.set(a2, p)
            sup.run()
            rot, tran = sup.get_rotran()
            rms = sup.get_rms()

            if rms < min_dist[0]:
                min_dist = (rms, rot, tran)

    else:

        a1, a2 = match_vectors(a1, a2, 6)
        mags = [norm(v) for v in a2]

        min_dist = (1.0E6, 'foo', 'bar')

        for l in itertools.permutations(a1):

            p = np.array([m * v / norm(v) for m, v in zip(mags, l)])
            sup.set(a2, p)
            sup.run()
            rot, tran = sup.get_rotran()
            rms = sup.get_rms()

            if rms < min_dist[0]:
                min_dist = (rms, rot, tran)

    return min_dist
Esempio n. 7
0
def _get_alignments(seq_u, atom_u, seq_b, atom_b):
    """
    Get alignment between two chains.

    Does structural and sequence alignment.
    """
    fasta_u = _tmp_fasta(seq_u)
    fasta_b = _tmp_fasta(seq_b)

    # Only use small word size for small sequences.
    # TODO. This is a bit brittle.
    word_size = 2 if len(seq_u) < 10 and len(seq_b) < 10 else 3

    blastp_cline = app.NcbiblastpCommandline(
        subject=fasta_u, query=fasta_b,
        outfmt="'10 qstart qend sstart send qseq sseq ppos evalue'",
        num_alignments=1, word_size=word_size, culling_limit=1, evalue=0.1)
    out, err = blastp_cline()

    # The trailing token is empty.
    alignments = [x for x in out.split('\n') if x]
    b2r, u2r = {}, {}
    b2u, u2b = {}, {}
    aligned_pos_b, aligned_pos_u = [], []
    all_ppos = []
    if len(out) == 0:
        # No hits found.
        return 0.0, float('inf'), (None, None)

    warned = False
    if len(alignments) > 1:
        logging.warning("More than one alignment found.")
    for i, curr in enumerate(alignments):
        start_b, end_b, start_u, end_u, align_b, align_u, ppos, evalue = \
            curr.split(',')
        start_b, end_b = int(start_b), int(end_b)
        start_u, end_u = int(start_u), int(end_u)
#        logging.info('Alignment {:} (score {:}) from {:} to {:} on bound, '
#                     '{:} to {:} on unbound.'.format(
#                         i, evalue, start_b, end_b, start_u, end_u))
        idx_b, idx_u = start_b - 1, start_u - 1
        assert len(align_u) == len(align_b)
        align_size = len(align_u)
        for k in range(align_size):
            if align_b[k] != '-' and align_u[k] != '-':
                if idx_b not in b2u and idx_u not in u2b:
                    b2u[idx_b] = idx_u
                    u2b[idx_u] = idx_b
                    aligned_pos_b.append(idx_b)
                    aligned_pos_u.append(idx_u)
                else:
                    if not warned:
                        logging.warning('ignoring double prediction {:} bound '
                                        'to {:} unbound'.format(idx_u, idx_b))
                        logging.warning('not showing future warnings for this '
                                        'alignment')
                        warned = True
            if align_u[k] != '-':
                idx_u += 1
            if align_b[k] != '-':
                idx_b += 1
        all_ppos.append((align_size, float(ppos)))

    idx_u, idx_b = 0, 0
    idx_r = 1
    u2r, b2r = {}, {}

    while idx_u != len(seq_u) or idx_b != len(seq_b):
        if idx_u in u2b and idx_b in b2u:
            u2r[idx_u] = idx_r
            b2r[idx_b] = idx_r
            idx_u += 1
            idx_b += 1
        elif idx_u not in u2b and idx_u != len(seq_u):
            u2r[idx_u] = idx_r
            idx_u += 1
        elif idx_b not in b2u and idx_b != len(seq_b):
            b2r[idx_b] = idx_r
            idx_b += 1
        idx_r += 1

    total = 0
    total_ppos = 0
    for align_size, ppos in all_ppos:
        total_ppos += ppos * align_size
        total += align_size
    total_ppos /= total

    sup = svd.SVDSuperimposer()
    sup.set(atom_u[aligned_pos_u], atom_b[aligned_pos_b])
    return total_ppos, sup.get_init_rms(), (b2r, u2r)
Esempio n. 8
0
    def superposeAndsave(self, ResAtmCont, ResCont, ResContIDs_list,
                         FreeProteinsHypContResSelect_dict, ChainCont,
                         LigAtmCont):
        '''
        This method superpose the ligand-free proteins on the reference
        complexed protein, based on the selection of the backbone atoms
        of contacting residues in the reference structure. It compute:
        - binding site RMSD.
        - residues chemical group RMSD.
        - contacting residues backbone RMSD.
        - CA-CB(reference)/CA'-CB'(alternate) vectors angle.
        It also superpose the reference and the equivalent contacting residues
        side chains. The experimental contact is saved with each contacting
        residue, so when the last is moved in the superposition, the
        contact is also moved.
        '''

        ## Save the contacting residue with the ligand contacting atom
        #self.get_contacting_ref_resid(self.ref_struc, LigAtmCont, ResCont, ChainCont)

        ## Results file...
        rmsd_file_name = 'clusters_rmsd_%s.out' % ResCont.resname
        rmsd_file = open(rmsd_file_name, 'a+')

        ResCont_backbone = []
        for res in ResContIDs_list:
            if res.resname == 'GLY':
                ResCont_backbone.append(res['C'])
                ResCont_backbone.append(res['CA'])
                ResCont_backbone.append(res['N'])
            else:
                ResCont_backbone.append(res['C'])
                ResCont_backbone.append(res['CA'])
                ResCont_backbone.append(res['N'])
                ResCont_backbone.append(res['CB'])

        log_file.write('\n')

        nchain = 0
        for chain in FreeProteinsHypContResSelect_dict.keys():
            nchain += 1
            if nchain > 3:
                break
            hyp_cont_res_backbone = FreeProteinsHypContResSelect_dict[chain]
            struc_id = chain[:4]
            chain_id = chain[-1]

            ## Superposing structures according to all contacting residues...
            print '==> SUPERPOSING', chain, 'ON %s_%s' % (self.ref_struc.id,
                                                          ChainCont.id)
            log_file.write('==> SUPERPOSING ' + chain + ' ON ' +
                           self.ref_struc.id + '_' + ChainCont.id + '\n')

            if len(ResCont_backbone) != len(hyp_cont_res_backbone):
                print 'ERROR!!: Fixed and moving atom lists differ in size.\n'
                log_file.write(
                    'ERROR!!: Fixed and moving atom lists differ in size. Chain ignored...\n'
                )
                continue

            super_imposer = Superimposer()
            super_imposer.set_atoms(ResCont_backbone, hyp_cont_res_backbone)

            for query_struc in self.lig_free_struc_list:
                if query_struc.id == struc_id:

                    ## Reference vs. Equivalent Binding Sites RMSD
                    super_imposer.apply(query_struc.get_atoms())
                    binding_site_rmsd = super_imposer.rms
                    print 'Binding site contacting residues backbone RMSD = %.2f A' % binding_site_rmsd

                    ## Save aligned structures
                    #self._save_structure(chain, query_struc)

                    ## Compute the RMSD between the contacting residue and the equivalent in the ligand-
                    ## free proteins.
                    ## 'EquivResCont' : Equivalent principal contacting residue in ligand-free proteins
                    ## 'ref_cont_res_coords'   : Reference contacting residue coordinates in the
                    ##                           complexed protein
                    ## 'EquivResCont_coords' : Equivalent principal contacting residue coordinates in
                    ##                           ligand-free proteins
                    ## 'ref_cont_res_backbone, EquivResCont_backbone' : Reference and equivalent
                    ##                                                    backbone residue coordinates
                    EquivResCont = query_struc[0][chain[-1]][ResCont.id[1]]

                    ref_res_group_atoms_coords = self._get_ref_group_atoms_coords(
                        ResCont)
                    equiv_right_group_atoms_coords, equiv_inv_group_atoms_coords = self._get_equiv_group_atoms_coords(
                        EquivResCont)

                    ref_cont_res_backbone = self._get_backbone_coordinates(
                        ResCont)
                    EquivResCont_backbone = self._get_backbone_coordinates(
                        EquivResCont)

                    ## REFERENCE vs. EQUIVALENT RMSD GROUP RMSD...
                    group_rmsd = SVDSuperimposer()

                    ## Right order RMSD
                    group_rmsd.set(ref_res_group_atoms_coords,
                                   equiv_right_group_atoms_coords)
                    right_group_rmsd = group_rmsd.get_init_rms()
                    #print "Right order group RMSD\t\t\t\t\b= %.2f A" % right_group_rmsd

                    ## Inverse order RMSD
                    group_rmsd.set(ref_res_group_atoms_coords,
                                   equiv_inv_group_atoms_coords)
                    inv_group_rmsd = group_rmsd.get_init_rms()
                    #print "Inverse order group RMSD \t\t\t\b= %.2f A" % inv_group_rmsd

                    if ResCont.resname == 'ARG':
                        ## Superpose reference and equivalent guanidine group and get the correspondent
                        ## right RMSD
                        correct_group_rmsd = self._superpose_guanidine(
                            query_struc, ResCont, EquivResCont,
                            right_group_rmsd, inv_group_rmsd)
                    else:
                        correct_group_rmsd = self._minimum(
                            right_group_rmsd, inv_group_rmsd)

                        print "Minimal group RMSD\t\t\t\t\b= %.2f A" % correct_group_rmsd

                    ## Reference vs. Equivalent Residues Backbones RMSD
                    cont_res_backbone_rmsd = SVDSuperimposer()
                    cont_res_backbone_rmsd.set(ref_cont_res_backbone,
                                               EquivResCont_backbone)
                    residues_backbone_rmsd = cont_res_backbone_rmsd.get_init_rms(
                    )
                    print "Contacting residues backbone RMSD \t\t\b= %.2f A" % residues_backbone_rmsd

                    ## Angle between the CA-CB vectors in the reference and alternate structures
                    ref_equiv_CACB_vectors_angle = self.compute_CB_CA_vectors_angle(
                        ResCont, EquivResCont)

                    ## Distance between the reference/equivalent protein's residue contacting atom and ligand atom...
                    #exp_distance = ResAtmCont - LigAtmCont
                    #theor_distance = EquivResCont[ResAtmCont.id] - LigAtmCont

                    ## Write the the equivalent contacting residue with the experimental contact
                    #self.get_contacting_equiv_resid(self.ref_struc, query_struc, LigAtmCont, ResCont, EquivResCont, chain[-1], ChainCont)

                    ## Write the RMSD, angles and distances values
                    rmsd_values_string = '%s\t%s\t%s\t%s\t%s\t%i\t%i\t%.2f\t%.2f\t%.2f\t%.2f' % (self.ref_struc.id, ChainCont.id, query_struc.id,\
                    chain_id, ResCont.resname, ResCont.id[1], len(ResContIDs_list), binding_site_rmsd, correct_group_rmsd, residues_backbone_rmsd,\
                    ref_equiv_CACB_vectors_angle)

                    rmsd_file.write(rmsd_values_string + '\n')

        log_file.write('\n\n')
        rmsd_file.close()
        return