scitbx.matrix¶
Note: this module can be used in isolation (without the rest of scitbx). All external dependencies (other than plain Python) are optional.
The primary purpose of this module is to provide compact implementations of essential matrix/vector algorithms with minimal external dependencies. Optimizations for execution performance are used only if compactness is not affected. The scitbx/math module provides faster C++ alternatives to some algorithms included here.
API documentation¶
- class scitbx.matrix.rec(elems, n)¶
Base rectangle object, used to store 2-dimensional data.
Examples
>>> from scitbx.matrix import rec >>> m = rec((1, 2, 3, 4), (2, 2)) >>> print m.trace() 5 >>> other = rec((1, 1, 1, 1), (2, 2)) >>> print m.dot(other) 10
- accute_angle(other, value_if_undefined=None, deg=False)¶
- angle(other, value_if_undefined=None, deg=False)¶
- as_boost_rational()¶
- as_flex_double_matrix()¶
- as_flex_int_matrix()¶
- as_float()¶
- as_int(rounding=True)¶
- as_list_of_lists()¶
- as_mat3()¶
- as_numpy_array()¶
- as_sym_mat3()¶
- axis_and_angle_as_r3_derivative_wrt_angle(angle, deg=False, second_order=False)¶
- axis_and_angle_as_r3_rotation_matrix(angle, deg=False)¶
- axis_and_angle_as_unit_quaternion(angle, deg=False)¶
- co_factor_matrix_transposed()¶
- cos_angle(other, value_if_undefined=None)¶
- cross(other)¶
- determinant()¶
- dot(other=None)¶
- each_abs()¶
- each_mod_short(period=1)¶
- extract_block(stop, start=(0, 0), step=(1, 1))¶
- inverse()¶
- is_approx_zero(eps)¶
Are all elements zero
- is_col_zero()¶
Is the translation vector zero
- is_r3_identity_matrix()¶
- is_r3_rotation_matrix(rms_tolerance=1e-08)¶
- is_r3_rotation_matrix_rms()¶
- is_square()¶
- is_zero()¶
Are all elements zero
- length()¶
- length_sq()¶
- mathematica_form(label='', one_row_per_line=False, format=None, prefix='', matrix_form=False)¶
- matlab_form(label='', one_row_per_line=False, format=None, prefix='')¶
- max()¶
- max_index()¶
- min()¶
- min_index()¶
- n_columns()¶
- n_rows()¶
- norm_sq()¶
- normalize()¶
- ortho()¶
- outer_product(other=None)¶
- product()¶
- quaternion_inverse()¶
- r3_rotation_matrix_as_unit_quaternion()¶
- r3_rotation_matrix_as_x_y_z_angles(deg=False, alternate_solution=False)¶
Get the rotation angles around the axis x,y,z for rotation r Such that r = Rx*Ry*Rz Those angles are the Tait-Bryan angles form of Euler angles
Note that typically there are two solutions, and this function will return only one. In the case that cos(beta) == 0 there are infinite number of solutions, the function returns the one where gamma = 0
- Parameters:
deg – When False use radians, when True use degrees
alternate_solution – return the alternate solution for the angles
- Returns:
- containing rotation angles in the form
(rotx, roty, rotz)
- Return type:
- resolve_partitions()¶
- rotate(axis, angle, deg=False)¶
- rotate_2d(angle, deg=False)¶
- rotate_around_origin(axis, angle, deg=False)¶
- rotation_angle(eps=1e-06)¶
Assuming it is a rotation matrix, tr(m) = 1+2*cos(alpha)
- round(digits)¶
- rt_for_rotation_around_axis_through(point, angle, deg=False)¶
- sum()¶
- trace()¶
- transpose()¶
- transpose_multiply(other=None)¶
- unit_quaternion_as_axis_and_angle(deg=False)¶
- unit_quaternion_as_r3_rotation_matrix()¶
- unit_quaternion_product(other)¶
- vector_to_001_rotation(sin_angle_is_zero_threshold=1e-10, is_normal_vector_threshold=1e-10)¶
- class scitbx.matrix.col(elems)¶
Class type built on top of rec and col_mixin, allows for single-dimensional vectors. This is especially convenient when working with 3D coordinate data in Python.
Examples
>>> from scitbx.matrix import col >>> vector = col([3, 0, 4]) >>> print abs(vector) 5.0
- class scitbx.matrix.sqr(elems)¶
- class scitbx.matrix.diag(diag_elems)¶
- class scitbx.matrix.identity(n)¶
- class scitbx.matrix.inversion(n)¶
- class scitbx.matrix.sym(elems=None, sym_mat3=None)¶
- class scitbx.matrix.rt(tuple_r_t)¶
Object for representing associated rotation and translation matrices. These will usually be a 3x3 matrix and a 1x3 matrix, internally represented by objects of type
scitbx.matrix.sqr
andscitbx.matrix.col
. Transformations may be applied toscitbx.array_family.flex
arrays using the overloaded multiplication operator.Examples
>>> from scitbx.matrix import rt >>> symop = rt((-1,0,0,0,1,0,0,0,-1), (0,0.5,0)) # P21 symop >>> from scitbx.array_family import flex >>> sites_frac = flex.vec3_double([(0.1,0.1,0.1), (0.1,0.2,0.3)]) >>> sites_symm = symop * sites_frac >>> print list(sites_symm) [(-0.1, 0.6, -0.1), (-0.1, 0.7, -0.3)]
- scitbx.matrix.sum(iterable)¶
The sum of the given sequence of matrices
- scitbx.matrix.cross_product_matrix(vvv)¶
- Matrix associated with vector cross product:
a.cross(b) is equivalent to cross_product_matrix(a) * b
Useful for simplification of equations. Used frequently in robotics and classical mechanics literature.
- scitbx.matrix.rotate_point_around_axis(axis_point_1, axis_point_2, point, angle, deg=False)¶
Rotate a 3D coordinate about a given arbitrary axis by the specified angle.
- Parameters:
axis_point_1 – tuple representing 3D coordinate at one end of the axis
axis_point_2 – tuple representing 3D coordinate at other end of the axis
point – tuple representing 3D coordinate of starting point to rotate
angle – rotation angle (defaults to radians)
deg – Python boolean (default=False), specifies whether the angle is in degrees
- Returns:
Python tuple (len=3) of rotated point
- scitbx.matrix.distance_from_plane(xyz, points)¶
http://mathworld.wolfram.com/Point-PlaneDistance.html Given three points describing a plane and a fourth point outside the plane, return the distance from the fourth point to the plane.
- scitbx.matrix.dihedral_angle(sites, deg=False)¶