8.6.2. Trajectory rotation — MDAnalysis.transformations.rotate
Rotates the coordinates by a given angle arround an axis formed by a direction and a point.
- class MDAnalysis.transformations.rotate.rotateby(angle, direction, point=None, ag=None, weights=None, wrap=False, max_threads=1, parallelizable=True)[source]
Rotates the trajectory by a given angle on a given axis. The axis is defined by the user, combining the direction vector and a point. This point can be the center of geometry or the center of mass of a user defined AtomGroup, or an array defining custom coordinates.
Note
max_threads
is set to 1 for this transformation with which it performs better.Examples
e.g. rotate the coordinates by 90 degrees on a axis formed by the [0,0,1] vector and the center of geometry of a given AtomGroup:
from MDAnalysis import transformations ts = u.trajectory.ts angle = 90 ag = u.atoms d = [0,0,1] rotated = transformations.rotate.rotateby(angle, direction=d, ag=ag)(ts)
e.g. rotate the coordinates by a custom axis:
from MDAnalysis import transformations ts = u.trajectory.ts angle = 90 p = [1,2,3] d = [0,0,1] rotated = transformations.rotate.rotateby(angle, direction=d, point=p)(ts)
- Parameters:
angle (float) – rotation angle in degrees
direction (array-like) – vector that will define the direction of a custom axis of rotation from the provided point. Expected shapes are (3, ) or (1, 3).
ag (AtomGroup, optional) – use the weighted center of an AtomGroup as the point from where the rotation axis will be defined. If no AtomGroup is given, the point argument becomes mandatory
point (array-like, optional) – list of the coordinates of the point from where a custom axis of rotation will be defined. Expected shapes are (3, ) or (1, 3). If no point is given, the ag argument becomes mandatory.
weights ({“mass”,
None
} or array_like, optional) – define the weights of the atoms when calculating the center of the AtomGroup. With"mass"
uses masses as weights; withNone
weigh each atom equally. If a float array of the same length as ag is provided, use each element of the array_like as a weight for the corresponding atom in ag. Default is None.wrap (bool, optional) – If True, all the atoms from the given AtomGroup will be moved to the unit cell before calculating the center of mass or geometry. Default is False, no changes to the atom coordinates are done before calculating the center of the AtomGroup.
- Return type:
Warning
Wrapping/unwrapping the trajectory or performing PBC corrections may not be possible after rotating the trajectory.
Changed in version 2.0.0: The transformation was changed from a function/closure to a class with
__call__
.Changed in version 2.0.0: The transformation was changed to inherit from the base class for limiting threads and checking if it can be used in parallel analysis.