Center
Module for centering molecular structures.
center_structure(u)
¶
Centers an MDAnalysis Universe object by shifting its center of mass to the origin.
Calculates the center of mass of all atoms in the provided MDAnalysis Universe and then subtracts this center of mass from the coordinates of each atom, effectively placing the system's center of mass at the coordinates (0.0, 0.0, 0.0).
PARAMETER | DESCRIPTION |
---|---|
u
|
The MDAnalysis Universe object representing the molecular system to be centered.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Universe
|
The same MDAnalysis Universe object, but with the coordinates of all |
Universe
|
atoms shifted so that the center of mass is at the origin. |
run_center_structure(path_topo, path_coords=None, path_output=None, kwargs_universe=dict(), kwargs_writer=dict(), overwrite=False)
¶
Loads a molecular structure, centers it by its center of mass, and optionally saves the centered structure to a new file.
This function orchestrates the process of reading a molecular structure
using MDAnalysis, centering it using the
[center_structure
][simlify.structure.center.center_structure]
function, and then writing the centered coordinates to a specified output file.
PARAMETER | DESCRIPTION |
---|---|
path_topo
|
The path to the topology file of the molecular system. Common file formats include PDB, GRO, and TPR.
TYPE:
|
path_coords
|
The path to the coordinate file(s) of the molecular system.
This can be a single file path (e.g., a trajectory file like TRR or XTC),
a list of file paths, or |
path_output
|
The path to the output file where the centered structure
will be saved. If this argument is
TYPE:
|
kwargs_universe
|
A dictionary of keyword arguments that will be passed
to the [ |
kwargs_writer
|
A dictionary of keyword arguments that will be passed
to the [ |
overwrite
|
A boolean flag indicating whether to overwrite the output file
if it already exists. If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Universe
|
The MDAnalysis Universe object representing the molecular system after |
Universe
|
it has been centered by its center of mass. |
Examples:
Centering a PDB file and saving the result:
from simlify.structure.center import run_center_structure
centered_universe = run_center_structure(
path_topo="input.pdb",
path_output="centered.pdb",
overwrite=True,
)
print(f"Centered universe has {centered_universe.atoms.n_atoms} atoms.")
Centering a topology and trajectory file without saving:
from simlify.structure.center import run_center_structure
centered_universe = run_center_structure(
path_topo="topol.gro",
path_coords="traj.xtc",
)
print(
f"Center of mass of the centered universe: {centered_universe.atoms.center_of_mass()}"
)
Passing additional arguments to the MDAnalysis Universe constructor: