def align_centroids_using_pca(ref_frames, ref_frames_reference): """ Align the centroids of 2 sets of rigid bodyes using PCA using their reference frames. returns the best rmsd and the ref_frames to get it. """ if(len(ref_frames) != len(ref_frames_reference)): raise ValueError("The number of reference frames must be the same") Ts1 = [r.get_transformation_to() for r in ref_frames] vs1 = [T.get_translation() for T in Ts1] Ts2 = [r.get_transformation_to() for r in ref_frames_reference] vs2 = [T.get_translation() for T in Ts2] # align with PCA pc1 = alg.get_principal_components(vs1) pc2 = alg.get_principal_components(vs2) pcTs = alg.get_alignments_from_first_to_second(pc1, pc2) best_refs = [] best_rmsd = 1e5 for j, pcT in enumerate(pcTs): new_Ts1 = [alg.compose(pcT, T) for T in Ts1] new_vs1 = [T.get_translation() for T in new_Ts1] r = atom.get_rmsd(new_vs1, vs2) if(r < best_rmsd): best_rmsd = r best_refs = [alg.ReferenceFrame3D(T) for T in new_Ts1] return best_rmsd, best_refs
def test_relative_position_mover(self, ): """ Test the RelativePositionMover """ log.info("test RelativePositionMover") fn_rec1 = self.get_input_file_name("1suvA_xlinked.pdb") fn_rec2 = self.get_input_file_name("1suvC_xlinked.pdb") fn_lig = self.get_input_file_name("1suvE_xlinked.pdb") fn_tr1 = \ self.get_input_file_name("transforms-1suvA-1suvE_reduced.txt") fn_tr2 = \ self.get_input_file_name("transforms-1suvC-1suvE_filtered.txt") m = IMP.kernel.Model() sel = atom.ATOMPDBSelector() h_rec1 = atom.read_pdb(fn_rec1, m, sel) rb_rec1 = atom.create_rigid_body(h_rec1) rec1_coords = [core.XYZ(l).get_coordinates() for l in atom.get_leaves(h_rec1)] h_rec2 = atom.read_pdb(fn_rec2, m, sel) rb_rec2 = atom.create_rigid_body(h_rec2) rec2_coords = [core.XYZ(l).get_coordinates() for l in atom.get_leaves(h_rec2)] h_ligand = atom.read_pdb(fn_lig, m, sel) rb_lig = atom.create_rigid_body(h_ligand) Ts = get_relative_transforms(fn_tr1) Tis1 = [] for i, T in enumerate(Ts): V = get_internal_transform3(T, rb_rec1, rb_lig) Tis1.append(V) docked_refs1 = get_docked_reference_frames(Ts, rb_lig) Ts = get_relative_transforms(fn_tr2) Tis2 = [] for i, T in enumerate(Ts): V = get_internal_transform3(T, rb_rec2, rb_lig) Tis2.append(V) docked_refs2 = get_docked_reference_frames(Ts, rb_lig) mv = em2d.RelativePositionMover(rb_lig, 10, 20) mv.add_internal_transformations(rb_rec1, Tis1) mv.add_internal_transformations(rb_rec2, Tis2) for i in range(2): # prob_random = 0 ref_before = rb_lig.get_reference_frame() ps = mv.propose() #_move(prob_random) ref_after = rb_lig.get_reference_frame() found = False current_coords = [core.XYZ(l).get_coordinates() for l in atom.get_leaves(h_ligand)] # check all possible reference frames where the ligand could be for r in itertools.chain(docked_refs1, docked_refs2): rb_lig.set_reference_frame(r) docked_coords = [core.XYZ(l) for l in atom.get_leaves(h_ligand)] rmsd = atom.get_rmsd(current_coords, docked_coords) if rmsd < 0.1: found = True self.assertTrue(found, msg= "the proposed move is not " \ "in the relative solutions") mv.accept()
def get_rmsd(hierarchy1, hierarchy2): xyz1 = [core.XYZ(l) for l in atom.get_leaves(hierarchy1)] xyz2 = [core.XYZ(l) for l in atom.get_leaves(hierarchy2)] return atom.get_rmsd(xyz1, xyz2)