Rotate#

Rotating atomic coordinates by rotation matrices or transformations.

The function molsysmt.structure.rotate() applies proper 3D rotations to the atomic coordinates of a molecular system using rotation matrices or spatial transformation objects.

Added in version 1.0.0.

Basic usage#

Let’s show how to rotate Met-enkephalin by 90 degrees around the \(z\)-axis using a \(3\times 3\) rotation matrix:

import molsysmt as msm
import numpy as np
molsys = msm.convert(msm.systems['Met-enkephalin']['met_enkephalin.h5msm'])
molsys = msm.structure.center(molsys, selection='all')

We inspect the initial 3D orientation of the peptide:

msm.view(molsys)

We define an active 90-degree counterclockwise rotation matrix around the \(z\)-axis (\(R_z(\pi/2)\)) and apply it using molsysmt.structure.rotate():

rotation_matrix = [
    [0.0, -1.0, 0.0],
    [1.0,  0.0, 0.0],
    [0.0,  0.0, 1.0]
]
molsys_rotated = msm.structure.rotate(molsys, rotation=rotation_matrix)

Visualizing the rotated system in 3D confirms the new spatial orientation:

msm.view(molsys_rotated)

Rotating around a specific center#

By default, rotation is performed around the coordinate origin [0, 0, 0]. Setting rotation_center allows rotating coordinates around a specific anchor point (e.g. the centroid of a residue or backbone atoms):

ca_center = msm.structure.get_center(molsys, selection='atom_name=="CA"')
molsys_ca_rot = msm.structure.rotate(molsys, rotation=rotation_matrix, rotation_center=ca_center)

Rotating using SciPy Rotation objects#

molsysmt.structure.rotate() natively accepts SciPy Rotation instances (such as Euler angles, rotation vectors, or quaternions):

from scipy.spatial.transform import Rotation

rot_euler = Rotation.from_euler('y', 45, degrees=True)
molsys_euler = msm.structure.rotate(molsys, rotation=rot_euler)