Skip to content

Commit

Permalink
Fix rotateby documentation (#2903)
Browse files Browse the repository at this point in the history
* Fixes #2901
* Changes made in this Pull Request:
    - Added call to rotateby (instead of rotate)
    - Removed () from atom group
  • Loading branch information
RMeli authored and lilyminium committed Jan 24, 2021
1 parent 6eb715a commit bc95e31
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions package/MDAnalysis/transformations/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,39 @@

def rotateby(angle, direction, point=None, ag=None, weights=None, wrap=False):
'''
Rotates the trajectory by a given angle on a given axis. The axis is defined by
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
of geometry or the center of mass of a user defined AtomGroup, or an array defining
custom coordinates.
Examples
--------
e.g. rotate the coordinates by 90 degrees on a axis formed by the [0,0,1] vector and
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:
.. code-block:: python
from MDAnalysis import transformations
ts = u.trajectory.ts
angle = 90
ag = u.atoms()
ag = u.atoms
d = [0,0,1]
rotated = MDAnalysis.transformations.rotate(angle, direction=d, ag=ag)(ts)
rotated = transformations.rotate.rotateby(angle, direction=d, ag=ag)(ts)
e.g. rotate the coordinates by a custom axis:
.. code-block:: python
from MDAnalysis import transformations
ts = u.trajectory.ts
angle = 90
p = [1,2,3]
d = [0,0,1]
rotated = MDAnalysis.transformations.rotate(angle, direction=d, point=point)(ts)
rotated = transformations.rotate.rotateby(angle, direction=d, point=p)(ts)
Parameters
----------
angle: float
Expand Down Expand Up @@ -100,7 +104,7 @@ def rotateby(angle, direction, point=None, ag=None, weights=None, wrap=False):
Returns
-------
MDAnalysis.coordinates.base.Timestep
Warning
-------
Wrapping/unwrapping the trajectory or performing PBC corrections may not be possible
Expand Down Expand Up @@ -138,7 +142,7 @@ def rotateby(angle, direction, point=None, ag=None, weights=None, wrap=False):
center_method = partial(atoms.center, weights, pbc=wrap)
else:
raise ValueError('A point or an AtomGroup must be specified')

def wrapped(ts):
if point is None:
position = center_method()
Expand All @@ -149,8 +153,8 @@ def wrapped(ts):
translation = matrix[:3, 3]
ts.positions= np.dot(ts.positions, rotation)
ts.positions += translation

return ts

return wrapped

0 comments on commit bc95e31

Please sign in to comment.