예제 #1
0
    def test_superpose(self):
        # create a few test sets with random data points, including degenerate
        # situations. (e.g. one point, two points, linear points)
        references = [  # a list of 2-tuples: (points, degenerate)
            (numpy.random.normal(0, 5, (n, 3)), False) for n in xrange(4, 40)
        ] + [
            #(numpy.array([[0,0,1]], float), True),
            #(numpy.array([[0,0,0],[0,0,1]], float), True),
            #(numpy.array([[0,0,0],[0,0,1],[0,0,2]], float), True),
            #(numpy.array([[0,0,0],[0,0,1],[0,0,2],[0,0,4]], float), True),
            #(numpy.random.normal(0, 5, (3, 3)), True)
        ]

        # Do a random transformation on the points
        randomized = []
        for points, degenerate in references:
            #points[:] -= points.mean(axis=0)
            axis = random_unit(3)
            angle = numpy.random.uniform(0, numpy.pi * 2)
            transformation = Complete()
            transformation.set_rotation_properties(angle, axis, False)
            transformation.t[:] = numpy.random.normal(0, 5, 3)
            randomized.append(
                (numpy.array([transformation.vector_apply(p)
                              for p in points]), transformation))

        for (ref_points, degenerate), (tr_points,
                                       transf) in zip(references, randomized):
            check_transf = superpose(ref_points, tr_points)
            # check whether the rotation matrix is orthogonal
            self.assertArraysAlmostEqual(
                numpy.dot(check_transf.r, check_transf.r.transpose()),
                numpy.identity(3, float), 1e-5)
            # first check whether check_transf brings the tr_points back to the ref_points
            check_points = numpy.dot(
                tr_points, check_transf.r.transpose()) + check_transf.t
            self.assertArraysAlmostEqual(ref_points,
                                         check_points,
                                         1e-5,
                                         doabs=True)
            if not degenerate:
                # if the set of points is not degenerate, check whether transf and check_transf
                # are each other inverses
                tmp = Complete()
                tmp.apply_before(transf)
                tmp.apply_before(check_transf)
                self.assertArraysAlmostEqual(
                    numpy.dot(transf.r, check_transf.r),
                    numpy.identity(3, float), 1e-5)
                self.assertArrayAlmostZero(tmp.t, 1e-5)

        # Add some distortion to the transformed points
        randomized = []
        for tr_points, transf in randomized:
            tr_points[:] += numpy.random.normal(0, 1.0, len(tr_points))

        # Do a blind test
        for (ref_points, degenerate), (tr_points,
                                       transf) in zip(references, randomized):
            superpose(ref_points, tr_points)
예제 #2
0
    def test_superpose(self):
        # create a few test sets with random data points, including degenerate
        # situations. (e.g. one point, two points, linear points)
        references = [ # a list of 2-tuples: (points, degenerate)
            (numpy.random.normal(0, 5, (n, 3)), False) for n in xrange(4, 40)
        ] + [
            #(numpy.array([[0,0,1]], float), True),
            #(numpy.array([[0,0,0],[0,0,1]], float), True),
            #(numpy.array([[0,0,0],[0,0,1],[0,0,2]], float), True),
            #(numpy.array([[0,0,0],[0,0,1],[0,0,2],[0,0,4]], float), True),
            #(numpy.random.normal(0, 5, (3, 3)), True)
        ]

        # Do a random transformation on the points
        randomized = []
        for points, degenerate in references:
            #points[:] -= points.mean(axis=0)
            axis = random_unit(3)
            angle = numpy.random.uniform(0, numpy.pi*2)
            transformation = Complete()
            transformation.set_rotation_properties(angle, axis, False)
            transformation.t[:] = numpy.random.normal(0, 5, 3)
            randomized.append((
                numpy.array([transformation.vector_apply(p) for p in points]),
                transformation
            ))

        for (ref_points, degenerate), (tr_points, transf) in zip(references, randomized):
            check_transf = superpose(ref_points, tr_points)
            # check whether the rotation matrix is orthogonal
            self.assertArraysAlmostEqual(numpy.dot(check_transf.r, check_transf.r.transpose()), numpy.identity(3, float), 1e-5)
            # first check whether check_transf brings the tr_points back to the ref_points
            check_points = numpy.dot(tr_points, check_transf.r.transpose()) + check_transf.t
            self.assertArraysAlmostEqual(ref_points, check_points, 1e-5, doabs=True)
            if not degenerate:
                # if the set of points is not degenerate, check whether transf and check_transf
                # are each other inverses
                tmp = Complete()
                tmp.apply_before(transf)
                tmp.apply_before(check_transf)
                self.assertArraysAlmostEqual(numpy.dot(transf.r, check_transf.r), numpy.identity(3, float), 1e-5)
                self.assertArrayAlmostZero(tmp.t, 1e-5)


        # Add some distortion to the transformed points
        randomized = []
        for tr_points, transf in randomized:
            tr_points[:] += numpy.random.normal(0, 1.0, len(tr_points))

        # Do a blind test
        for (ref_points, degenerate), (tr_points, transf) in zip(references, randomized):
            superpose(ref_points, tr_points)
예제 #3
0
    def do_test(self, coordinates, masses, expected_is):
        reference = MolecularDescriptorTV1(coordinates, masses)
        self.assert_(reference.inversion_symmetric == expected_is)

        for counter in xrange(3):
            transformation = Complete()
            transformation.set_rotation_properties(
                random.uniform(0, 2 * math.pi),
                numpy.random.uniform(-1, 1, (3, )),
                False,
            )
            transformation.t = numpy.random.uniform(-5, 5, (3, ))
            new_coordinates = numpy.array([
                transformation.vector_apply(coordinate)
                for coordinate in coordinates
            ], float)
            new_descriptor = MolecularDescriptorTV1(new_coordinates, masses)
            self.assert_(reference.compare_structure(new_descriptor))
            self.assert_(not reference.compare_global_rotation(new_descriptor))
            self.assert_(
                not reference.compare_global_translation(new_descriptor))
예제 #4
0
    def do_test(self, coordinates, masses, expected_is):
        reference = MolecularDescriptorTV1(coordinates, masses)
        self.assert_(reference.inversion_symmetric == expected_is)

        for counter in xrange(3):
            transformation = Complete()
            transformation.set_rotation_properties(
                random.uniform(0, 2*math.pi),
                numpy.random.uniform(-1, 1, (3,)),
                False,
            )
            transformation.t = numpy.random.uniform(-5, 5, (3,))
            new_coordinates = numpy.array([
                transformation.vector_apply(coordinate)
                for coordinate
                in coordinates
            ], float)
            new_descriptor = MolecularDescriptorTV1(new_coordinates, masses)
            self.assert_(reference.compare_structure(new_descriptor))
            self.assert_(not reference.compare_global_rotation(new_descriptor))
            self.assert_(not reference.compare_global_translation(new_descriptor))