Center#
Centering a molecular system around coordinate origin or reference points.
The function molsysmt.structure.center() translates a molecular system so that its center of geometry (or center of mass) coincides with a specified target point (such as the coordinate origin [0.0, 0.0, 0.0] nm).
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.center().
Basic usage#
Let’s show how to center a pentalanine trajectory around the coordinate origin:
import molsysmt as msm
import numpy as np
import matplotlib.pyplot as plt
molsys = msm.convert(msm.systems['pentalanine']['traj_pentalanine.h5'], to_form='molsysmt.MolSys')
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 compute the geometric center before centering and plot its coordinate trajectories across simulation frames:
center_before = msm.structure.get_center(molsys)
time = msm.get(molsys, element='system', time=True)
plt.figure(figsize=(6, 4))
plt.plot(center_before[:, 0, 0], label='x')
plt.plot(center_before[:, 0, 1], label='y')
plt.plot(center_before[:, 0, 2], label='z')
plt.xlabel('Structure index')
plt.ylabel('Center position [nm]')
plt.legend()
plt.show()
Now we center the molecular system using molsysmt.structure.center():
molsys_centered = msm.structure.center(molsys)
center_after = msm.structure.get_center(molsys_centered)
We verify that the distance of the geometric center from the origin is now zero across all frames:
dist_before = np.linalg.norm(center_before[:, 0, :], axis=1)
dist_after = np.linalg.norm(center_after[:, 0, :], axis=1)
plt.figure(figsize=(6, 4))
plt.plot(dist_before, label='Before centering', color='coral')
plt.plot(dist_after, label='After centering', color='teal')
plt.xlabel('Structure index')
plt.ylabel('Distance to origin [nm]')
plt.legend()
plt.show()
Centering on a sub-selection or custom point#
We can center the whole system based on the center of a specific sub-selection (such as only C-alpha atoms) using center_of_selection, or relocate it to custom coordinates using center_coordinates:
molsys_ca_centered = msm.structure.center(molsys, selection='all', center_of_selection='atom_name=="CA"')
ca_center = msm.structure.get_center(molsys_ca_centered, selection='atom_name=="CA"')
print('CA center at frame 0:', ca_center[0])
CA center at frame 0: [[0.0 0.0 -1.1102230246251566e-17]] nanometer
molsys_custom = msm.structure.center(molsys, center_coordinates='[1.0, 1.0, 1.0] nm')
custom_center = msm.structure.get_center(molsys_custom)
print('System center at custom coordinates:', custom_center[0])
System center at custom coordinates: [[0.9999999999999993 1.0000000000000007 1.0000000000000009]] nanometer
See also
Related Tools & References
Convert: Convert molecular systems between different forms with
molsysmt.basic.convert().Get center: Compute the geometric center or center of mass with
molsysmt.structure.get_center().Get: Query atomic coordinates and system attributes with
molsysmt.basic.get().Translate: Translate molecular coordinates by a displacement vector with
molsysmt.structure.translate().Rotate: Rotate molecular coordinates with
molsysmt.structure.rotate().