Coordinate Transformations

from LLC_Membranes.llclib import transform

This library contains functions for transforming coordinates by translating, rotating, and rescaling them, as well as more elementary functions for generating rotation matrices.

Functions

transform.rotateplane(plane, angle=0)

Calculate a rotation matrix to rotate a plane in 3 dimensions

Parameters:
  • plane (numpy.ndarray) – coordinates of 3 points defining a plane
  • angle (float) – desired angle between xy plane (optional, default = 0 i.e. in plane)
Returns:

4 x 4 rotation matrix

Return type:

numpy.ndarray

transform.rotateplane_coords(xyz, plane, angle=0)

Rotate coordinates about a plane

Parameters:
  • xyz (numpy.ndarray) – (n, 3) array of xyz coordinates of all positions to be rotated
  • plane (numpy.ndarray) – coordinates of 3 points defining a plane
  • angle (float) – desired angle between xy plane (optional, default = 0 i.e. in plane)
Returns:

rotated coordinates

Return type:

numpy.ndarray

transform.rotate_x(theta)

Generate rotation matrix for rotating about the x-axis

Param:theta: angle by which to rotate
Returns:Rotation matrix to rotate input vector about x-axis

:rtype numpy.ndarray

transform.rotate_z(theta)

Generate rotation matrix for rotating about the z-axis

Param:theta: angle by which to rotate
Returns:Rotation matrix to rotate input vector about z-axis

:rtype numpy.ndarray

transform.translate(xyz, before, after)

Translate coordinates based on a reference position

Parameters:
  • xyz (numpy.ndarray) – coordinates of set of points to be translated (n, 3)
  • before (numpy.ndarray) – reference coordinate location before (3)
  • after (numpy.ndarray) – reference coordinate location after (3)
Returns:

translated points with respect to reference coordinate before/after locations [npts, 3]

Return type:

numpy.ndarray

transform.rotate_vector(xyz, v1, v2)

Rotate coordinates based on a reference vector to a second vector

Parameters:
  • xyz (numpy.ndarray) – xyz coordinates of object to be rotated
  • v1 (numpy.ndarray) – original vector
  • v2 (numpy.ndarray) – direction you want v1 to be pointing in
Returns:

rotated coordinates

Return type:

numpy.ndarray

transform.rotate_coords_x(pos, angle)

Rotate a set of coordinates about the x-axis

Parameters:
  • pos (numpy.ndarray) – (n, 3) xyz coordinates to be rotated
  • angle (float) – angle to rotate them by w.r.t origin
Returns:

array of rotated coordinates

Return type:

numpy.ndarray

transform.rotate_coords_z(pos, angle)

Rotate a set of coordinates about the z-axis

Parameters:
  • pos (numpy.ndarray) – (n, 3) xyz coordinates to be rotated
  • angle (float) – angle to rotate them by w.r.t origin
Returns:

array of rotated coordinates

Return type:

numpy.ndarray

transform.Rvect2vect(A, B)

Find rotation matrix so that when applied to A, its orientation matches B . :param A: 3D vector to be rotated :param B: 3D vector to rotate to

Returns:rotation matrix for rotate A to B
transform.rotate_coords(xyz, R)

Given a rotation matrix, rotate all points in an array

Parameters:
  • xyz (numpy.ndarray) – n x 3 xyz coordinates of all positions to be rotated
  • R (numpy.ndarray) – 4x4 rotation matrix
Returns:

rotated coordinates

Return type:

numpy.ndarray

transform.random_orientation(xyz, alignment_vector, placement)

Randomly orient a vector and then place its tail at a specific point. Can be used to randomly rotate a molecule and place it somewhere.

Parameters:
  • xyz (numpy.ndarray) – 3D coordinates
  • alignment_vector (numpy.ndarray) – A 3D reference vector to rotate about
  • placement (numpy.ndarray) – 3D point at which to place vector tail.
Returns:

coordinates of oriented and translated group of coordinates

Return type:

numpy.ndarray

transform.rescale(coords, dims)

Rescale coordinates so that cell dimensions are constant over the simulation

Parameters:
  • coords (numpy.ndarray) – coordinates to rescale (nframes, natoms, 3)
  • dims (numpy.ndarray) – unitcell vectors (nframes, 3, 3) as the unitcellvectors trajectory attribute output by mdtraj.load
Returns:

rescaled coordinates and average length

Return type:

numpy.ndarray

transform.monoclinic_to_cubic(xyz, theta=60)

Convert monoclinic cell to cubic cell

Parameters:
  • xyz (numpy.ndarray) – (nframes, natoms, 3) coordinate array
  • theta (float) – angle between x and y vectors of unit cell
Returns:

Coordinates shifted into a cubic unit cell

Return type:

numpy.ndarray