Exemplo n.º 1
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
Exemplo n.º 2
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()
			aff_a1 = np.dot(l,rot) + tran
			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()
			aff_a1 = np.dot(l,rot) + tran
			rms = sup.get_rms()
		
			if rms < min_dist[0]:
				min_dist = (rms,rot,tran)

	return min_dist
Exemplo n.º 3
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
y_on_x1 = dot(y, rot) + tran

# same thing
y_on_x2 = sup.get_transformed()
Exemplo n.º 4
0
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
y_on_x1=dot(y, rot)+tran

# same thing
y_on_x2=sup.get_transformed()
Exemplo n.º 5
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