AffineTransformation#
- class biotite.structure.AffineTransformation(center_translation, rotation, target_translation)[source]#
Bases:
objectAn affine transformation, consisting of translations and a rotation.
- Parameters:
- center_translationndarray, shape=(3,) or shape=(m,3), dtype=float
The translation vector for moving the centroid into the origin.
- rotationndarray, shape=(3,3) or shape=(m,3,3), dtype=float
The rotation matrix.
- target_translationndarray, shape=(m,3), dtype=float
The translation vector for moving the structure onto the fixed one.
- Attributes:
- center_translation, rotation, target_translationndarray
Same as the parameters. The dimensions are always expanded to (m,3) or (m,3,3), respectively.
- apply(atoms)#
Apply this transformation on the given structure.
- Parameters:
- atomsAtomArray or AtomArrayStack or ndarray, shape(n,), dtype=float or ndarray, shape(m,n), dtype=float
The structure to apply the transformation on.
- Returns:
- transformedAtomArray or AtomArrayStack or ndarray, shape(n,), dtype=float or ndarray, shape(m,n), dtype=float
A copy of the atoms structure, with transformations applied. Only coordinates are returned, if coordinates were given in atoms.
Examples
>>> coord = np.arange(15).reshape(5,3) >>> print(coord) [[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11] [12 13 14]] >>> # Rotates 90 degrees around the z-axis >>> transform = AffineTransformation( ... center_translation=np.array([0,0,0]), ... rotation=np.array([ ... [0, -1, 0], ... [1, 0, 0], ... [0, 0, 1] ... ]), ... target_translation=np.array([0,0,0]) ... ) >>> print(transform.apply(coord)) [[ -1. 0. 2.] [ -4. 3. 5.] [ -7. 6. 8.] [-10. 9. 11.] [-13. 12. 14.]]
- as_matrix()#
Get the translations and rotation as a combined 4x4 transformation matrix.
Multiplying this matrix with coordinates in the form (x, y, z, 1) will apply the same transformation as
apply()to coordinates in the form (x, y, z).- Returns:
- transformation_matrixndarray, shape=(m,4,4), dtype=float
The transformation matrix. m is the number of models in the transformation.
Examples
>>> coord = np.arange(15).reshape(5,3) >>> print(coord) [[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11] [12 13 14]] >>> # Rotates 90 degrees around the z-axis >>> transform = AffineTransformation( ... center_translation=np.array([0,0,0]), ... rotation=np.array([ ... [0, -1, 0], ... [1, 0, 0], ... [0, 0, 1] ... ]), ... target_translation=np.array([0,0,0]) ... ) >>> print(transform.apply(coord)) [[ -1. 0. 2.] [ -4. 3. 5.] [ -7. 6. 8.] [-10. 9. 11.] [-13. 12. 14.]] >>> # Use a 4x4 matrix for transformation as alternative >>> coord_4 = np.concatenate([coord, np.ones((len(coord), 1))], axis=-1) >>> print(coord_4) [[ 0. 1. 2. 1.] [ 3. 4. 5. 1.] [ 6. 7. 8. 1.] [ 9. 10. 11. 1.] [12. 13. 14. 1.]] >>> print((transform.as_matrix()[0] @ coord_4.T).T) [[ -1. 0. 2. 1.] [ -4. 3. 5. 1.] [ -7. 6. 8. 1.] [-10. 9. 11. 1.] [-13. 12. 14. 1.]]
Gallery#
Searching for structural homologs in a protein structure database