Example #1
0
    def align_with_plane(self, axis=2, round_decimals=14):
        a = self.cell[1]

        if axis == 0:
            p1 = np.array([0, 1, 0])
            p2 = np.array([0, 0, 1])
        elif axis == 1:
            p1 = np.array([0, 0, 1])
            p2 = np.array([1, 0, 0])
        elif axis == 2:
            p1 = np.array([1, 0, 0])
            p2 = np.array([0, 1, 0])
        else:
            raise ValueError('Axis must be an integer in (0,1,2)')

        if np.linalg.norm(np.cross(p1, a)) < 1E-10:
            return
        c = unit_vector(np.cross(p1, a))
        # print c
        # A vector perpendicular to the plane
        vector_plane = unit_vector(np.cross(p1, p2))
        v1_u = unit_vector(vector_plane)
        v2_u = unit_vector(c)
        proj = np.dot(v1_u, v2_u)
        # print 'Projection', proj
        av = np.arccos(proj)
        # import math
        # print 'Angle=', math.degrees(av)
        rotation_matrix = rotation_matrix_around_axis_angle(p1, -av)
        cell = np.dot(rotation_matrix, self.cell.T).T.round(round_decimals)
        # print '-->',cell[1], vector_plane
        # print 'PROJECTION', np.dot(cell[1], vector_plane)
        if np.abs(np.dot(cell[1], vector_plane)) > 1E-10:
            # print 'Failed projection', np.dot(cell[1], vector_plane)
            # print cell
            rotation_matrix = rotation_matrix_around_axis_angle(p1, av)
            cell = np.dot(rotation_matrix, self.cell.T).T.round(round_decimals)
            if np.dot(cell[1], vector_plane) > 1E-10:
                # print 'Failed projection', np.dot(cell[1], vector_plane)
                # print cell
                pass
        self._cell = cell
Example #2
0
    def align_with_plane(self, axis=2, round_decimals=14):
        a = self.cell[1]

        if axis == 0:
            p1 = np.array([0, 1, 0])
            p2 = np.array([0, 0, 1])
        elif axis == 1:
            p1 = np.array([0, 0, 1])
            p2 = np.array([1, 0, 0])
        elif axis == 2:
            p1 = np.array([1, 0, 0])
            p2 = np.array([0, 1, 0])
        else:
            raise ValueError('Axis must be an integer in (0,1,2)')

        if np.linalg.norm(np.cross(p1, a)) < 1E-10:
            return
        c = unit_vector(np.cross(p1, a))
        # print c
        # A vector perpendicular to the plane
        vector_plane = unit_vector(np.cross(p1, p2))
        v1_u = unit_vector(vector_plane)
        v2_u = unit_vector(c)
        proj = np.dot(v1_u, v2_u)
        # print 'Projection', proj
        av = np.arccos(proj)
        # import math
        # print 'Angle=', math.degrees(av)
        rotation_matrix = rotation_matrix_around_axis_angle(p1, -av)
        cell = np.dot(rotation_matrix, self.cell.T).T.round(round_decimals)
        # print '-->',cell[1], vector_plane
        # print 'PROJECTION', np.dot(cell[1], vector_plane)
        if np.abs(np.dot(cell[1], vector_plane)) > 1E-10:
            # print 'Failed projection', np.dot(cell[1], vector_plane)
            # print cell
            rotation_matrix = rotation_matrix_around_axis_angle(p1, av)
            cell = np.dot(rotation_matrix, self.cell.T).T.round(round_decimals)
            if np.dot(cell[1], vector_plane) > 1E-10:
                # print 'Failed projection', np.dot(cell[1], vector_plane)
                # print cell
                pass
        self._cell = cell
Example #3
0
 def align_with_axis(self, axis=0, round_decimals=14):
     a = self.cell[0]
     if axis == 0:
         b = np.array([1, 0, 0])
     elif axis == 1:
         b = np.array([0, 1, 0])
     elif axis == 2:
         b = np.array([0, 0, 1])
     else:
         raise ValueError('Axis must be an integer in (0,1,2)')
     if np.linalg.norm(np.cross(a, b)) < 1E-10:
         return
     c = unit_vector(np.cross(a, b))
     av = angle_vector(a, b)
     rotation_matrix = rotation_matrix_around_axis_angle(c, av)
     self._cell = np.dot(rotation_matrix, self.cell.T).T.round(round_decimals)
Example #4
0
 def align_with_axis(self, axis=0, round_decimals=14):
     a = self.cell[0]
     if axis == 0:
         b = np.array([1, 0, 0])
     elif axis == 1:
         b = np.array([0, 1, 0])
     elif axis == 2:
         b = np.array([0, 0, 1])
     else:
         raise ValueError('Axis must be an integer in (0,1,2)')
     if np.linalg.norm(np.cross(a, b)) < 1E-10:
         return
     c = unit_vector(np.cross(a, b))
     av = angle_vector(a, b)
     rotation_matrix = rotation_matrix_around_axis_angle(c, av)
     self._cell = np.dot(rotation_matrix, self.cell.T).T.round(round_decimals)