def test_translated(self): """Translating a molecule should not affect its rmsd.""" global tolerance, num_test for idx in xrange(num_test): translation_vector = [random.random() * 10.0 + 5.0 for i in xrange(3)] some_methane = methane_sample() before = self.rmsd(some_methane, some_methane) after = self.rmsd(some_methane, cm.translate(some_methane, translation_vector)) assert abs(before - after) < tolerance, "translating the molecule affected its rmsd. before = %s, rmsd = %s, idx = %s" % (before, after, idx)
def test_known_translated(self): """RMSD for a specific case should evaluate as I expect.""" global tolerance, num_test for idx in xrange(num_test): first_mol = randomize_mol(np.array([0.0, 0.0, -1.0, 0.0, 0.0, 1.0])) second_mol = randomize_mol(np.array([0.0, 0.0, -2.0, 0.0, 0.0, 3.0])) translation_vector = np.array([random.random() * 10.0 + 5.0 for i in xrange(3)]) rmsd = self.rmsd(first_mol, cm.translate(second_mol, translation_vector)) expected = 1.5 assert abs(rmsd - expected) < tolerance, "rmsd was not as expected: %s != %s" % (rmsd, 1.0)
def rmsd(self, x, y): x = cm.translate(x, -cm.center_of_geometry(x)) y = cm.translate(y, -cm.center_of_geometry(y)) rot = cm.rmsd_rotation(x, y) y = cm.transform(y, rot) return cm.flat_rmsd(x, y)
def randomize_mol(mol): """Randomly move a molecule around.""" translation_vector = np.array([random.random() * 10.0 + 5.0 for i in xrange(3)]) (rot_alpha, rot_beta, rot_gamma) = [random.random() * 2 * math.pi for i in xrange(3)] return cm.translate(cm.rotate_euler(mol, rot_alpha, rot_beta, rot_gamma), translation_vector)