schrodinger.structutils.transform module¶
Manipulate atom coordinates with matrix operations.
Provides array methods to translate and rotate atoms in a structure.Structure. The coin of the realm is a four by four numpy array. The first 3x3 is a rotation matrix, the last 3x1 is translation matrix, and the 4th row is a spectator row.
All angles are in radians.
- [[ 1. 0. 0. 0.]
[ 0. 1. 0. 0.] [ 0. 0. 1. 0.] [ 0. 0. 0. 1.]] # spectator row
The elements in the last row are spectators and don’t contribute to atomic coordinate changes.
Copyright Schrodinger, LLC. All rights reserved.
- schrodinger.structutils.transform.get_vector_magnitude(a)¶
Returns magnitute of a specified vector (numpy array)
- schrodinger.structutils.transform.get_normalized_vector(vector)¶
Returns normalized version of the specified vector (numpy array)
- schrodinger.structutils.transform.get_angle_between_vectors(a, b)¶
Return angle between 2 vectors
- schrodinger.structutils.transform.translate_structure(st, x=0.0, y=0.0, z=0.0, atom_index_list=None)¶
Translates the atom coordinates along Cartesian x, y, and z axes.
st (structure.Structure)
- x (float)
Distance, in angstroms, along positive x to translate.
- y (float)
Distance, in angstroms, along positive y to translate.
- z (float)
Distance, in angstroms, along positive z to translate.
- atom_index_list (list)
Integer indexes for the atoms to transform. If the list is not specified then all atoms in the structure are transformed. If the list is empty, none of the atoms are transformed.
- schrodinger.structutils.transform.rotate_structure(st, x_angle=0, y_angle=0, z_angle=0, rot_center=None, atom_index_list=None)¶
Rotates the structure about x axis, then y axis, then z axis.
st (structure.Structure)
- x_angle (float)
Angle, in radians, about x to right-hand rotate.
- y_angle (float)
Angle, in radians, about y to right-hand rotate.
- z_angle (float)
Angle, in radians, about z to right-hand rotate.
- rot_center (list)
Cartesian coordinates (x, y, z) for the center of rotation. By default, rotation happens about the origin (0, 0, 0)
- atom_index_list (list)
Integer indexes for the atoms to transform. If the list is not specified then all atoms in the structure are transformed. If the list is empty, none of the atoms are transformed.
- schrodinger.structutils.transform.transform_atom_coordinates(coords, matrix)¶
Transforms the specified atom coordinates using a 4x4 transformation matrix.
- Parameters
coords (numpy.array) – Coordinate array (x, y, z)
matrix (numpy.array) – 4x4 numpy array representation of transformation matrix.
- Returns
Transformed coordinates
- Return type
numpy.array
- schrodinger.structutils.transform.transform_structure(st, matrix, atom_index_list=None)¶
Transforms atom coordinates of the structure using a 4x4 transformation matrix. An optional list of atom numbers defining a subset of atoms for transformation may be specified.
st (structure.Structure)
- matrix (numpy.array)
4x4 numpy array representation of transformation matrix.
- atom_index_list (list)
Integer indexes for the atoms to transform. If the list is not specified then all atoms in the structure are transformed. If the list is empty, none of the atoms are transformed.
- schrodinger.structutils.transform.get_centroid(st, atom_list: list = None)¶
Returns the structure’s centroid. If specified, this can be limited to a subset of atoms.
NOTE: Periodic boundary conditions (PBC) are NOT honored.
- Parameters
st (structure.Structure) – structure
atom_list (list(int)) – 1-based atom indices
- Returns
centroid given as 4-element array [x, y, z, 0.0]
- Return type
numpy.array(float)
See schrodinger/geometry/centroid.h
- schrodinger.structutils.transform.translate_atom_to_origin(struct, atom, origin=None)¶
Translate the structure so the given atom is at the origin
- Parameters
struct (structure.Structure) – Structure that will modified
atom (structure._StructureAtom) – The atom that will be at the origin after translation
origin (list) – The point the atom should end up at. If not given, will be the origin
- schrodinger.structutils.transform.translate_center_to_origin(st, origin=None)¶
Translates the structure’s center to the origin. The difference between this function and
translate_centroid_to_origin
is that the centroid is the average of all atoms, whereas the center is the middle of the atoms. The centroid can be very far from the center for structures with a high percent of the atoms located in one region of space and a few atoms very far away.- Parameters
st (
structure.Structure
) – Structure that will modifiedorgin – Coordinates of the new origin
- schrodinger.structutils.transform.translate_centroid_to_origin(st, atom_list=None)¶
Translates the structure’s centroid to the origin.
- Parameters
atom_list (list(int)) – A list of 1-based atom indices. If provided, the centroid of the atoms in this list will be translated to the origin.
- schrodinger.structutils.transform.translate_to_origin(st, atom_list=None)¶
Translates the structure’s centroid to the origin.
- Parameters
atom_list (list(int)) – A list of 1-based atom indices. If provided, the centroid of the atoms in this list will be translated to the origin.
- schrodinger.structutils.transform.get_translation_matrix(trans)¶
Returns a 4x4 numpy array representing a translation matrix from a 3-element list.
- trans (list)
3-element list (x,y,z).
- schrodinger.structutils.transform.get_rotation_matrix(axis, angle)¶
Returns a 4x4 numpy array representing a right-handed rotation matrix about the specified axis running through the origin by some angle
- axis (vector)
Normalized (unit) vector for the axis around which to rotate. Can be one of predefined axis: X_AXIS, Y_AXIS, Z_AXIS, or arbitrary axis.
- angle (float)
Angle, in radians, about which to rotate the structure about the axis.
- schrodinger.structutils.transform.get_rotation_matrix_from_eulers(phi, theta, psi)¶
Returns a 4x4 numpy array representing a rotation matrix generated from a list of Euler angles. The angles of rotation (phi, theta and psi) are applied in order, and are defined as:
- phi
Angle to rotate by about Z axis [0 to 2pi in radians]
- theta
Angle to rotate by about X’ axis [0 to 2pi in radians]
- psi
Angle to rotate by about Z’ axis [0 to 2pi in radians]
- schrodinger.structutils.transform.get_coords_array_from_list(coords_list)¶
Returns coordinates as a 4-element numpy array: (x,y,z,0.0).
- coords_list (list or array)
3 elements: x, y, z.
- schrodinger.structutils.transform.get_alignment_matrix(a_vector, b_vector)¶
Returns a Numpy 4x4 rotation matrix that will align a_vector onto b_vector.
a_vector (array) numpy array of vector coordinates (x, y, z)
b_vector (array) numpy array of vector coordinates (x, y, z)
- schrodinger.structutils.transform.get_reflection_matrix(reflect_axis, axis_origin=None)¶
Returns a 4x4 Numpy matrix which will reflect all points through a mirror plane (defined by a unit vector normal to that plane and a point in the plane).
reflect_axis (array, len 3) Normalized (unit) vector defining the mirror plane
axis_origin (array, len 3) point which lies in the mirror plane, if None, origin will be used