Esempio n. 1
0
    def test_get_add_sums(self):

        sum_list = []

        for dummy in range(100):
            overfit_obj = overfit.Overfit()
            overfit_obj1 = overfit.Overfit()
            part_list = []
            for point1, point2 in zip(self.points1, self.points2):
                if random.choice([True, False]):
                    sums = overfit_obj.get_sums()
                    overfit_obj = overfit.Overfit()
                    overfit_obj.add_sums(sums)

                    part_list.append(overfit_obj1.get_sums())
                    overfit_obj1 = overfit.Overfit()

                overfit_obj.add_point(point1, point2)
                overfit_obj1.add_point(point1, point2)

            part_list.append(overfit_obj1.get_sums())
            sum_list.append(overfit_obj.get_sums())
            assert_sums_equal(self, sum_list[-1],
                              functools.reduce(operator.add, part_list))

        for sums1, sums2 in zip(sum_list, sum_list[1:]):
            assert_sums_equal(self, sums1, sums2)
Esempio n. 2
0
    def test_add_mer(self):
        for dummy in range(10):
            overfit_obj1 = overfit.Overfit()
            overfit_obj2 = overfit.Overfit()

            for dummy in range(100):
                struct = random.choice(self.structs)
                mer = random.choice(list(struct))

                overfit_obj1.add_mer(mer, mer)

                for point in mer.representation:
                    overfit_obj2.add_point(point, point)

                sums1 = overfit_obj1.get_sums()
                sums2 = overfit_obj2.get_sums()

                assert_sums_equal(self, sums1, sums2)
Esempio n. 3
0
    def test_add_struct(self):
        for dummy in range(10):
            overfit_obj1 = overfit.Overfit()
            overfit_obj2 = overfit.Overfit()

            for dummy in range(100):
                struct1, struct2 = random.sample(self.structs, 2)

                seg_len = random.randint(5, 20)

                try:
                    start1 = random.choice(list(struct1[0:-seg_len]))
                    start2 = random.choice(list(struct2[0:-seg_len]))

                    sub1 = struct1[start1.ind:start1.ind + seg_len]
                    sub2 = struct2[start2.ind:start2.ind + seg_len]
                except:
                    continue

                will_fail = False

                for mer1, mer2 in zip(*map(list, [sub1, sub2])):
                    if len(mer1.indicators) == len(mer2.indicators):
                        overfit_obj2.add_mer(mer1, mer2)
                    else:
                        self.assertRaises(TypeError, overfit_obj2.add_mer,
                                          mer1, mer2)
                        will_fail = True

                if will_fail:
                    self.assertRaises(TypeError, overfit_obj1.add_structure,
                                      sub1, sub2)
                    break

                overfit_obj1.add_structure(sub1, sub2)

                sums1 = overfit_obj1.get_sums()
                sums2 = overfit_obj2.get_sums()

                assert_sums_equal(self, sums1, sums2)
Esempio n. 4
0
    def test_geom_center(self):
        for dummy in range(10):
            n_points = random.randint(3, 50)
            point_list1 = [
                self.points1[n] for n in random.sample(range(100), n_points)
            ]
            point_list2 = [
                self.points2[n] for n in random.sample(range(100), n_points)
            ]

            overfit_obj = overfit.Overfit()
            overfit_obj.add(point_list1, point_list2)

            dummy_rmsd, mat = overfit_obj.overfit()

            center1, center2 = [[
                sum(map(operator.itemgetter(pos), plist)) / n_points
                for pos in range(3)
            ] for plist in (point_list1, point_list2)]

            map(functools.partial(self.assertAlmostEqual, places=4), center1,
                mat.transform(*center2))
Esempio n. 5
0
    def test_identity(self):
        for dummy in range(10):
            point_list = [
                self.points1[n]
                for n in random.sample(range(100), random.randint(3, 50))
            ]

            overfit_obj = overfit.Overfit()
            overfit_obj.add(point_list, point_list)

            rmsd, mat = overfit_obj.overfit()

            self.assertAlmostEqual(rmsd, 0, places=3)

            one = geometry.TRTMatrix()
            map(self.assertAlmostEqual,
                itertools.chain(*mat.rotation_matrix.tolist()),
                itertools.chain(*one.rotation_matrix.tolist()))
            map(self.assertAlmostEqual,
                mat.prerotational_translation_vector.tolist(),
                one.prerotational_translation_vector.tolist())
            map(self.assertAlmostEqual, mat.translation_vector.tolist(),
                one.translation_vector.tolist())
Esempio n. 6
0
    def test_rmsd(self):
        for dummy in range(10):
            n_points = random.randint(3, 50)
            point_list1 = [
                self.points1[n] for n in random.sample(range(100), n_points)
            ]
            point_list2 = [
                self.points2[n] for n in random.sample(range(100), n_points)
            ]

            overfit_obj = overfit.Overfit()
            overfit_obj.add(point_list1, point_list2)

            rmsd, mat = overfit_obj.overfit()

            rmsd1, mat1 = overfit.overfit(point_list1, point_list2)

            self.assertAlmostEqual(rmsd, rmsd1)
            map(self.assertAlmostEqual,
                itertools.chain(*mat.rotation_matrix.tolist()),
                itertools.chain(*mat1.rotation_matrix.tolist()))
            map(self.assertAlmostEqual, mat.prerotational_translation_vector,
                mat1.prerotational_translation_vector)
            map(self.assertAlmostEqual, mat.translation_vector,
                mat1.translation_vector)

            sqr = lambda x: x**2
            dist2 = lambda point1, point2: sum(
                [sqr(c1 - c2) for c1, c2 in zip(point1, point2)])

            myrmsd = math.sqrt(
                sum(
                    map(dist2, point_list1,
                        [mat.transform(*p) for p in point_list2])) / n_points)

            self.assertAlmostEqual(rmsd, myrmsd, places=3)
Esempio n. 7
0
    def test_zero(self):
        overfit_obj = overfit.Overfit()

        sums = overfit_obj.get_sums()

        assert_sums_equal(self, sums, overfit.t_overfit_sums())
Esempio n. 8
0
 def test_init(self):
     overfit.Overfit()