deepfold.utils.rigid_utils.Rotation

class deepfold.utils.rigid_utils.Rotation(rot_mats: Tensor | None = None, quats: Tensor | None = None, normalize_quats: bool = True)[source]

A 3D rotation. Depending on how the object is initialized, the rotation is represented by either a rotation matrix or a quaternion, though both formats are made available by helper functions. To simplify gradient computation, the underlying format of the rotation cannot be changed in-place. Like Rigid, the class is designed to mimic the behavior of a torch Tensor, almost as if each Rotation object were a tensor of rotations, in one format or another.

__init__(rot_mats: Tensor | None = None, quats: Tensor | None = None, normalize_quats: bool = True)[source]
Parameters:
  • rot_mats – A [*, 3, 3] rotation matrix tensor. Mutually exclusive with quats

  • quats – A [*, 4] quaternion. Mutually exclusive with rot_mats. If normalize_quats is not True, must be a unit quaternion

  • normalize_quats – If quats is specified, whether to normalize quats

Methods

__init__([rot_mats, quats, normalize_quats])

apply(pts)

Apply the current Rotation as a rotation matrix to a set of 3D coordinates.

cat(rs, dim)

Concatenates rotations along one of the batch dimensions.

compose_q(r[, normalize_quats])

Compose the quaternions of the current Rotation object with those of another.

compose_q_update_vec(q_update_vec[, ...])

Returns a new quaternion Rotation after updating the current object's underlying rotation with a quaternion update, formatted as a [*, 3] tensor whose final three columns represent x, y, z such that (1, x, y, z) is the desired (not necessarily unit) quaternion update.

compose_r(r)

Compose the rotation matrices of the current Rotation object with those of another.

cuda()

Analogous to the cuda() method of torch Tensors

detach()

Returns a copy of the Rotation whose underlying Tensor has been detached from its torch graph.

get_cur_rot()

Return the underlying rotation in its current form

get_quats()

Returns the underlying rotation as a quaternion tensor.

get_rot_mats()

Returns the underlying rotation as a rotation matrix tensor.

identity(shape[, dtype, device, ...])

Returns an identity Rotation.

invert()

Returns the inverse of the current Rotation.

invert_apply(pts)

The inverse of the apply() method.

map_tensor_fn(fn)

Apply a Tensor -> Tensor function to underlying rotation tensors, mapping over the rotation dimension(s).

to(device, dtype)

Analogous to the to() method of torch Tensors

unsqueeze(dim)

Analogous to torch.unsqueeze.

Attributes

device

The device of the underlying rotation

dtype

Returns the dtype of the underlying rotation.

requires_grad

Returns the requires_grad property of the underlying rotation

shape

Returns the virtual shape of the rotation object.