Pos
Provides functions for interacting with the positions of atoms in molecular structures.
This module offers utilities for analyzing and manipulating the spatial coordinates of atoms within an MDAnalysis Universe. Currently, it includes functionality to calculate the center of mass of a selected group of atoms.
get_com(atoms)
¶
Compute the center of mass for a group of atoms.
The center of mass (COM) is the average position of all the parts of the
system, weighted by their masses. For a collection of atoms, it is calculated
as the weighted average of their coordinates, where the weights are the masses
of the atoms. This function leverages the built-in center of mass calculation
provided by MDAnalysis for an AtomGroup
.
PARAMETER | DESCRIPTION |
---|---|
atoms
|
An MDAnalysis
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NDArray[float64]
|
A NumPy array of shape (3,) containing the x, y, and z coordinates of |
NDArray[float64]
|
the center of mass of the provided |
NDArray[float64]
|
coordinates will be the same as the units of the atomic coordinates |
NDArray[float64]
|
within the MDAnalysis Universe (typically Angstroms). |
Examples:
Calculating the center of mass of all atoms in a loaded structure:
import MDAnalysis as mda
from simlify.structure.io import load_mda
from simlify.structure.pos import get_com
# Load a molecular structure
try:
universe = load_mda("protein.pdb")
all_atoms = universe.atoms
# Calculate the center of mass of all atoms
center_of_mass = get_com(all_atoms)
print(f"Center of mass of all atoms: {center_of_mass}")
except FileNotFoundError as e:
print(f"Error: {e}")
Calculating the center of mass of a specific selection of atoms (e.g., protein):
import MDAnalysis as mda
from simlify.structure.io import load_mda
from simlify.structure.pos import get_com
# Load a molecular structure
try:
universe = load_mda("complex.gro", "traj.xtc")
protein = universe.select_atoms("protein")
# Calculate the center of mass of the protein atoms
protein_com = get_com(protein)
print(f"Center of mass of the protein: {protein_com}")
except FileNotFoundError as e:
print(f"Error: {e}")