def test_drms(self): """ Test drms measure """ m = IMP.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) drms = atom.get_drms(xyzs1, xyzs2) # Molecule with itself self.assertAlmostEqual(drms, 0) R = IMP.algebra.get_random_rotation_3d() v = IMP.algebra.get_random_vector_in( IMP.algebra.get_unit_bounding_box_3d()) T = IMP.algebra.Transformation3D(R, v) for x in xyzs2: core.transform(x, T) drms = atom.get_drms(xyzs1, xyzs2) # Same thing after transformation self.assertAlmostEqual(drms, 0) # for x in xyzs2: R = IMP.algebra.get_random_rotation_3d() T = IMP.algebra.Transformation3D(R, v) core.transform(x, T) drms = atom.get_drms(xyzs1, xyzs2) self.assertTrue(drms > 0)
def test__rigid_bodies_drmsd_Q(self): """ Test drmsd_Q measure""" m = IMP.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) R = IMP.algebra.get_random_rotation_3d() v = IMP.algebra.get_random_vector_in( IMP.algebra.get_unit_bounding_box_3d()) T = IMP.algebra.Transformation3D(R, v) for x in xyzs2: core.transform(x, T) thresholds = [10, 20, 30, 40, 60] for threshold in thresholds: # for x in xyzs2: R = IMP.algebra.get_random_rotation_3d() T = IMP.algebra.Transformation3D(R, v) core.transform(x, T) # test that the function is correctly implemented drmsd = 0. npairs = 0. for i in range(0, len(xyzs1) - 1): for j in range(i + 1, len(xyzs2)): dist0 = IMP.core.get_distance(xyzs1[i], xyzs1[j]) dist1 = IMP.core.get_distance(xyzs2[i], xyzs2[j]) if dist0 <= threshold or dist1 <= threshold: drmsd += (dist0 - dist1)**2 npairs += 1. drmsd = math.sqrt(drmsd / npairs) drmsd_target = atom.get_drmsd_Q(xyzs1, xyzs2, threshold) self.assertAlmostEqual(drmsd, drmsd_target) drmsd_Q = atom.get_drmsd_Q(xyzs1, xyzs2, 1000000.0) drmsd = atom.get_drmsd(xyzs1, xyzs2) self.assertAlmostEqual(drmsd, drmsd_Q)
def test__rigid_bodies_drmsd(self): """ Test drmsd measure""" m = IMP.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) drmsd = atom.get_drmsd(xyzs1, xyzs2) # Molecule with itself self.assertAlmostEqual(drmsd, 0) R = IMP.algebra.get_random_rotation_3d() v = IMP.algebra.get_random_vector_in( IMP.algebra.get_unit_bounding_box_3d()) T = IMP.algebra.Transformation3D(R, v) for x in xyzs2: core.transform(x, T) drmsd = atom.get_drmsd(xyzs1, xyzs2) # Same thing after transformation self.assertAlmostEqual(drmsd, 0) # for x in xyzs2: R = IMP.algebra.get_random_rotation_3d() T = IMP.algebra.Transformation3D(R, v) core.transform(x, T) # test that the function is correctly implemented drmsd = 0. npairs = 0. for i in range(0, len(xyzs1) - 1): for j in range(i + 1, len(xyzs2)): dist0 = IMP.core.get_distance(xyzs1[i], xyzs1[j]) dist1 = IMP.core.get_distance(xyzs2[i], xyzs2[j]) drmsd += (dist0 - dist1)**2 npairs += 1. drmsd1 = math.sqrt(drmsd / npairs) drmsd2 = atom.get_drmsd(xyzs1, xyzs2) self.assertAlmostEqual(drmsd1, drmsd2)
def test__rigid_bodies_drms(self): """ Test drms measure taking into account rigid bodies""" m = IMP.kernel.Model() sel = atom.CAlphaPDBSelector() prot1 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) prot2 = atom.read_pdb(self.open_input_file("mini.pdb"), m, sel) hchains1 = atom.get_by_type(prot1, atom.CHAIN_TYPE) hchains2 = atom.get_by_type(prot2, atom.CHAIN_TYPE) xyzs1 = core.XYZs(atom.get_leaves(prot1)) xyzs2 = core.XYZs(atom.get_leaves(prot2)) x = 0 ranges = [] for h in hchains1: ls1 = (atom.get_leaves(h)) y = x + len(ls1) ranges.append((x, y)) x = y drms = atom.get_drms(xyzs1, xyzs2) rb_drms = atom.get_rigid_bodies_drms(xyzs1, xyzs2, ranges) self.assertAlmostEqual(rb_drms, 0) self.assertAlmostEqual( drms, rb_drms, delta=1e-3, msg="rb_drms != drms") # Same thing after transformation of each of the chains for h in hchains2: R = alg.get_random_rotation_3d() v = alg.get_random_vector_in(alg.get_unit_bounding_box_3d()) T = alg.Transformation3D(R, v) ls = atom.get_leaves(h) for l in ls: core.transform(l.get_as_xyz(), T) drms = atom.get_drms(xyzs1, xyzs2) rb_drms = atom.get_rigid_bodies_drms(xyzs1, xyzs2, ranges) self.assertAlmostEqual(drms, rb_drms, delta=0.3, msg="rb_drms != drms")