traj_to_com_traj

A module containing the tool to compute a center of mass trajectory for a given selection.

Summary

Functions:

traj2com

Reads trajectory files, computes the center of mass trajectory with traj_to_com_traj() and writes it to a file or to stdout.

traj_to_com_traj

Function that computes the center of mass trajectory for a given selection.

Reference

traj2com(
trajectory_files: list[str],
output: str | None = None,
mode: FileWritingMode | str = 'w',
md_format: MDEngineFormat | str = MDEngineFormat.PQ,
selection: SelectionCompatible = None,
use_full_atom_info: bool = False,
group: PositiveInt | None = None,
by_residue: bool = False,
restart_file: str | None = None,
moldescriptor_file: str | None = None,
continuous: bool = False,
molecule_types: Sequence[str | int] | None = None,
) → None[source]

Reads trajectory files, computes the center of mass trajectory with traj_to_com_traj() and writes it to a file or to stdout.

The format of the trajectory is inferred from the file extension (xyz, vel, force or charge) and the result is written in the same format. A vel trajectory therefore gives the velocities of the centers of mass, a force trajectory their forces and a charge trajectory their charges.

For by_residue, the molecules are defined by a restart file together with the moldescriptor file, as for the other analyses: the restart file gives the molecule of every atom and the moldescriptor file the molecule types. The molecule types may contain the WATER_TYPE and AMMONIA_TYPE lines of PQ.

Parameters:
  • trajectory_files (list of str) – The xyz trajectory file(s) to read.

  • output (str, optional) – The output file. If not specified, the output is printed to stdout.

  • mode (FileWritingMode | str, optional) – The writing mode, by default “w”. The following modes are available: - “w”: write - “a”: append - “o”: overwrite

  • md_format (MDEngineFormat | str, optional) – The format of the input trajectory. The default is MDEngineFormat.PQ.

  • selection (SelectionCompatible, optional) – The atoms that define the centers of mass, as a selection string (see Selection). If None, all atoms are selected.

  • use_full_atom_info (bool, optional) – Whether the selection uses the full atom information (atom type names and elements) or the elements only, by default False.

  • group (PositiveInt, optional) – The number of consecutive atoms for each center of mass. If neither group nor by_residue is given, the center of mass of all selected atoms is computed.

  • by_residue (bool, optional) – Compute the center of mass of every molecule, by default False. Needs restart_file and moldescriptor_file. Cannot be combined with group.

  • restart_file (str, optional) – The restart file that defines the molecules of the system.

  • moldescriptor_file (str, optional) – The moldescriptor file with the molecule types, needs restart_file.

  • continuous (bool, optional) – Follow the centers over the periodic boundary instead of folding them back into the cell, see traj_to_com_traj(). By default False.

  • molecule_types (Sequence[str | int], optional) – With by_residue, only the molecules of these types get a center of mass, see traj_to_com_traj(). In addition to the names and numbers of the mol types, the keywords water and ammonia (any case) select the mol types that the moldescriptor file names with its WATER_TYPE and AMMONIA_TYPE lines.

Raises:

PQValueError – If moldescriptor_file is given without restart_file, if the selection contains no atoms or for the errors of traj_to_com_traj().

traj_to_com_traj(
trajectory: Trajectory,
selection=None,
group=None,
by_residue: bool = False,
topology: Topology | None = None,
continuous: bool = False,
molecule_types: Sequence[str | int] | None = None,
) → Trajectory[source]

Function that computes the center of mass trajectory for a given selection.

The velocities, forces and charges of the frames, if they have them, are combined as well: a center of mass has the mass weighted mean of the velocities of its atoms, the sum of their forces and the sum of their charges. A trajectory that only has velocities (a vel file) gives a trajectory of center of mass velocities, which can be used for the velocity autocorrelation function.

With the group parameter, the trajectory will be group according to the given group. For example if group = 2, the trajectory will be grouped in pairs of 2 and the center of mass of each pair will be computed.

With by_residue, the atoms are grouped by the residues (molecules) of the topology, i.e. by the molecules defined in the moldescriptor file. This works for molecules of different sizes and types. The center of mass of a molecule is computed from its selected atoms; molecules without a selected atom are left out. The result has one atom per molecule, ordered by the residue number and named by the residue name of the molecule (e.g. the name given in the moldescriptor file). It carries no residues itself. A molecule has to be smaller than half of the box in every direction; an error is raised for molecules whose atoms spread over half of the box or more around the first atom (larger molecules in which this is not visible, such as a pair of atoms farther apart than half the box, cannot be detected). A warning is logged if selected atoms have a placeholder mass (elements X, Q, Cav, Sup), because they dominate the center of mass of their molecule.

Parameters:
  • trajectory (Trajectory) – The trajectory to compute the center of mass trajectory for.

  • selection (Atom | int | slice | Np1DIntArray, optional) – The selection to compute the center of mass trajectory for. If None, the selection is all atoms.

  • group (int, optional) – The group to compute the center of mass trajectory for. If None, the group is all atoms.

  • by_residue (bool, optional) – If True, the centers of mass of the residues of the topology are computed instead of the ones of groups of consecutive atoms. Cannot be combined with group. By default False.

  • topology (Topology, optional) – The topology with the residues to use with by_residue. If None, the topology of the trajectory is used. It has to contain residues, e.g. by reading a restart file together with the moldescriptor file.

  • continuous (bool, optional) – If True, the positions of the centers of mass follow their way over the periodic boundary from frame to frame instead of being folded back into the cell, so that they can be used for the mean square displacement. Every frame is placed at the image of the center that is closest to the previous frame (in fractional coordinates, so a cell that changes in size is handled), so a center must not move farther than half of the box between two frames. The first frame is folded into the cell. Has no effect in a vacuum cell. By default False.

  • molecule_types (Sequence[str | int], optional) – With by_residue, only the molecules of these types get a center of mass, e.g. ["TIP3P-Water"] or [1]. A type is given by the name of the mol type in the moldescriptor file or by its number (the id of the residue). Combined with the selection, the center of a molecule is computed from the selected atoms of the molecules of these types. By default None (all molecules).

Returns:

The center of mass trajectory.

Return type:

Trajectory

Raises:
  • PQValueError – If group and by_residue are combined, if by_residue is used with a topology without residues or if the number of atoms of the topology and of a frame differ.

  • AtomicSystemError – With by_residue, if a molecule spans half of the box or more.

  • AtomicSystemMassError – If a selected atom has no mass.

  • PQValueError – If continuous is used for a trajectory without positions, if molecule_types is used without by_residue, or if a molecule type does not exist in the topology.