示例#1
0
def test_rotate_z(z: np.ndarray) -> None:

    for deg, rad in [(0, 0), (45, np.pi / 4), (90, np.pi / 2)]:
        v_deg = utils.rotate(np.array([1, 0, 0]), deg, z, units="deg")
        v_rad = utils.rotate(np.array([1, 0, 0]), rad, z, units="rad")

        assert np.allclose(v_deg, v_rad)
        assert np.allclose(v_deg, np.array([np.cos(rad), np.sin(rad), 0]))
示例#2
0
def test_molecule_rotate_z(mol: molecule.Molecule) -> None:

    z_axis = np.array([0, 0, 1])

    for angle in [0, 45, 90]:

        rotated = np.zeros((len(mol), 3))
        for i, coord in enumerate(mol.coordinates):
            rotated[i] = utils.rotate(coord, angle, z_axis, units="deg")

        mol.rotate(angle, z_axis, units="deg")

        assert np.allclose(mol.coordinates, rotated)

        # Reset
        mol.rotate(-angle, z_axis, units="deg")
示例#3
0
def test_molecule_rotate(mol: molecule.Molecule) -> None:

    axis = np.random.rand(3)

    for angle in np.random.rand(10) * 180:

        rotated = np.zeros((len(mol), 3))
        for i, coord in enumerate(mol.coordinates):
            rotated[i] = utils.rotate(coord, angle, axis, units="deg")

        mol.rotate(angle, axis, units="deg")

        assert np.allclose(mol.coordinates, rotated)

        # Reset
        mol.rotate(-angle, axis, units="deg")
示例#4
0
    def rotate(self,
               angle: float,
               axis: np.ndarray,
               units: str = "rad") -> None:
        """
        Rotate molecule.

        Parameters
        ----------
        angle: float
            Rotation angle
        axis: np.ndarray
            Axis of rotation (in 3D)
        units: {"rad", "deg"}
            Units of the angle (radians `rad` or degrees `deg`)
        """
        self.coordinates = utils.rotate(self.coordinates, angle, axis, units)
示例#5
0
def test_rotate_invalid():

    with pytest.raises(ValueError):
        utils.rotate(np.array([1, 0, 0]), 0, np.array([0, 0, 1]), units="none")