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.
API documentation
Follow this link for a detailed description of the input arguments, raised errors, and returned objects of this function: molsysmt.structure.rotate().
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')
Note
Demo Systems Catalog
This tutorial uses demonstration datasets provided by MolSysMT. To explore the full catalog of bundled systems, forms, and file paths, visit the Demo Systems guide.
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)
See also
Related Tools & References
Convert: Convert molecular systems between different forms with
molsysmt.basic.convert().Center: Center a molecular system around coordinate origin or reference points with
molsysmt.structure.center().View: Render molecular systems interactively with
molsysmt.basic.view().Get center: Calculate centroid positions with
molsysmt.structure.get_center().Translate: Translate molecular coordinates by a displacement vector with
molsysmt.structure.translate().Flip: Reflect coordinates across a plane with
molsysmt.structure.flip().Align principal axes: Orient principal inertia axes along target Cartesian directions with
molsysmt.structure.align_principal_axes().