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.

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')

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()
../../../../_images/d0bf3b0909195357c886e692952b9209f2bb62f2b3d1d091c5821721eeef4d27.png

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()
../../../../_images/075e953c612de1661539773c08338c35b718cd61c529a1be4852701d337342c1.png

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