示例#1
0
def test_transformation_matrix():
    [[assert_true(np.allclose(
        Rz(angle=angle), transformation_matrix(angle=angle, axis=axis)))
        for angle in np.linspace(0.0, 2 * np.pi, np.pi / 4)]
        for Rmat, axis in zip((Rx, Ry, Rz), ('x', 'y', 'z'))]
    assert_true(np.allclose(
        transformation_matrix(angle=np.pi/2, rot_point=Point([1.0, 1.0])),
        np.array([[0.0, -1.0, 2.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]])))
示例#2
0
def test_transformation_matrix():
    [[
        assert_true(
            np.allclose(Rz(angle=angle),
                        transformation_matrix(angle=angle, axis=axis)))
        for angle in np.linspace(0.0, 2 * np.pi, np.pi / 4)
    ] for Rmat, axis in zip((Rx, Ry, Rz), ('x', 'y', 'z'))]
    assert_true(
        np.allclose(
            transformation_matrix(angle=np.pi / 2, rot_point=Point([1.0,
                                                                    1.0])),
            np.array([[0.0, -1.0, 2.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]])))
示例#3
0
    def rotate(self, angle=None, axis=None, anchor_point=None,
               rot_point=None, from_vector=None, to_vector=None,
               degrees=False, transform_matrix=None, verbose=False, **kwargs):
        """Rotate `Molecule` position vectors.

        Parameters
        ----------
        angle : float
        axis : :class:`~sknano.core.math.Vector`, optional
        anchor_point : :class:`~sknano.core.math.Point`, optional
        rot_point : :class:`~sknano.core.math.Point`, optional
        from_vector, to_vector : :class:`~sknano.core.math.Vector`, optional
        degrees : bool, optional
        transform_matrix : :class:`~numpy:numpy.ndarray`

        """
        if transform_matrix is None:
            transform_matrix = \
                transformation_matrix(angle=angle, axis=axis,
                                      anchor_point=anchor_point,
                                      rot_point=rot_point,
                                      from_vector=from_vector,
                                      to_vector=to_vector, degrees=degrees,
                                      verbose=verbose, **kwargs)
        [molecule.rotate(transform_matrix=transform_matrix)
         for molecule in self]
示例#4
0
    def rotate(self, angle=None, axis=None, anchor_point=None,
               rot_point=None, from_vector=None, to_vector=None,
               degrees=False, transform_matrix=None, verbose=False, **kwargs):
        """Rotate `GeometricRegion` :attr:`~GeometricRegion.points` and \
            :attr:`~GeometricRegion.vectors`.

        Parameters
        ----------
        angle : float
        axis : :class:`~sknano.core.math.Vector`, optional
        anchor_point : :class:`~sknano.core.math.Point`, optional
        rot_point : :class:`~sknano.core.math.Point`, optional
        from_vector, to_vector : :class:`~sknano.core.math.Vector`, optional
        degrees : bool, optional
        transform_matrix : :class:`~numpy:numpy.ndarray`


        See Also
        --------
        sknano.core.math.rotate

        """
        if transform_matrix is None:
            transform_matrix = \
                transformation_matrix(angle=angle, axis=axis,
                                      anchor_point=anchor_point,
                                      rot_point=rot_point,
                                      from_vector=from_vector,
                                      to_vector=to_vector, degrees=degrees,
                                      verbose=verbose, **kwargs)

        self.points.rotate(transform_matrix=transform_matrix)
        self.vectors.rotate(transform_matrix=transform_matrix)
示例#5
0
def test8():
    a = np.sqrt(3) * aCC
    latt = Crystal3DLattice(a=a,
                            b=a,
                            c=2 * r_CC_vdw,
                            alpha=90,
                            beta=90,
                            gamma=120)
    print(latt)
    a1 = latt.a1
    a2 = latt.a2
    a3 = latt.a3

    xfrm = transformation_matrix(angle=-np.pi / 6)

    rotangle = -np.pi / 6
    for v in (a1, a2, a3):
        v.rotate(angle=rotangle)

    latt.rotate(angle=rotangle, axis='z')
    print(latt)

    assert_equal(latt.a1, a1)
    assert_equal(latt.a2, a2)
    assert_equal(latt.a3, a3)

    assert_true(np.allclose(latt.orientation_matrix, xfrm))
示例#6
0
    def rotate(self,
               angle=None,
               axis=None,
               anchor_point=None,
               rot_point=None,
               from_vector=None,
               to_vector=None,
               degrees=False,
               transform_matrix=None,
               verbose=False,
               **kwargs):
        """Rotate `GeometricRegion` :attr:`~GeometricRegion.points` and \
            :attr:`~GeometricRegion.vectors`.

        Parameters
        ----------
        angle : float
        axis : :class:`~sknano.core.math.Vector`, optional
        anchor_point : :class:`~sknano.core.math.Point`, optional
        rot_point : :class:`~sknano.core.math.Point`, optional
        from_vector, to_vector : :class:`~sknano.core.math.Vector`, optional
        degrees : bool, optional
        transform_matrix : :class:`~numpy:numpy.ndarray`


        See Also
        --------
        sknano.core.math.rotate

        """
        if transform_matrix is None:
            transform_matrix = \
                transformation_matrix(angle=angle, axis=axis,
                                      anchor_point=anchor_point,
                                      rot_point=rot_point,
                                      from_vector=from_vector,
                                      to_vector=to_vector, degrees=degrees,
                                      verbose=verbose, **kwargs)

        self.points.rotate(transform_matrix=transform_matrix)
        self.vectors.rotate(transform_matrix=transform_matrix)
def test4():
    a = np.sqrt(3) * aCC
    latt = Crystal2DLattice(a=a, b=a, gamma=60)
    a1 = latt.a1
    a2 = latt.a2

    rotated_a1 = a1.copy()
    rotated_a2 = a2.copy()
    xfrm = transformation_matrix(angle=-np.pi / 6)
    rotated_a1.rotate(transform_matrix=xfrm)
    rotated_a2.rotate(transform_matrix=xfrm)

    latt.rotate(angle=-np.pi / 6)

    assert_equal(latt.a1, rotated_a1)
    assert_equal(latt.a2, rotated_a2)
    assert_true(np.allclose(latt.orientation_matrix, xfrm))

    rotated_latt = Crystal2DLattice(a1=rotated_a1, a2=rotated_a2)
    assert_equal(rotated_a1, rotated_latt.a1)
    assert_equal(rotated_a2, rotated_latt.a2)
    assert_true(np.allclose(latt.orientation_matrix,
                            rotated_latt.orientation_matrix))
def test8():
    a = np.sqrt(3) * aCC
    latt = Crystal3DLattice(a=a, b=a, c=2 * r_CC_vdw,
                            alpha=90, beta=90, gamma=120)
    print(latt)
    a1 = latt.a1
    a2 = latt.a2
    a3 = latt.a3

    xfrm = transformation_matrix(angle=-np.pi / 6)

    rotangle = -np.pi / 6
    for v in (a1, a2, a3):
        v.rotate(angle=rotangle)

    latt.rotate(angle=rotangle, axis='z')
    print(latt)

    assert_equal(latt.a1, a1)
    assert_equal(latt.a2, a2)
    assert_equal(latt.a3, a3)

    assert_true(np.allclose(latt.orientation_matrix, xfrm))
示例#9
0
def test4():
    a = np.sqrt(3) * aCC
    latt = Crystal2DLattice(a=a, b=a, gamma=60)
    a1 = latt.a1
    a2 = latt.a2

    rotated_a1 = a1.copy()
    rotated_a2 = a2.copy()
    xfrm = transformation_matrix(angle=-np.pi / 6)
    rotated_a1.rotate(transform_matrix=xfrm)
    rotated_a2.rotate(transform_matrix=xfrm)

    latt.rotate(angle=-np.pi / 6)

    assert_equal(latt.a1, rotated_a1)
    assert_equal(latt.a2, rotated_a2)
    assert_true(np.allclose(latt.orientation_matrix, xfrm))

    rotated_latt = Crystal2DLattice(a1=rotated_a1, a2=rotated_a2)
    assert_equal(rotated_a1, rotated_latt.a1)
    assert_equal(rotated_a2, rotated_latt.a2)
    assert_true(
        np.allclose(latt.orientation_matrix, rotated_latt.orientation_matrix))
示例#10
0
    def rotate(self,
               angle=None,
               axis=None,
               anchor_point=None,
               rot_point=None,
               from_vector=None,
               to_vector=None,
               degrees=False,
               transform_matrix=None,
               verbose=False,
               **kwargs):
        """Rotate `Molecule` position vectors.

        Parameters
        ----------
        angle : float
        axis : :class:`~sknano.core.math.Vector`, optional
        anchor_point : :class:`~sknano.core.math.Point`, optional
        rot_point : :class:`~sknano.core.math.Point`, optional
        from_vector, to_vector : :class:`~sknano.core.math.Vector`, optional
        degrees : bool, optional
        transform_matrix : :class:`~numpy:numpy.ndarray`

        """
        if transform_matrix is None:
            transform_matrix = \
                transformation_matrix(angle=angle, axis=axis,
                                      anchor_point=anchor_point,
                                      rot_point=rot_point,
                                      from_vector=from_vector,
                                      to_vector=to_vector, degrees=degrees,
                                      verbose=verbose, **kwargs)
        [
            molecule.rotate(transform_matrix=transform_matrix)
            for molecule in self
        ]