momentum
A module containing the Momentum class. The Momentum class is used to calculate the norm of the total linear momentum of a selection of atoms for every frame of a velocity trajectory. It can be used to check a simulation for center of mass drift.
Summary
Classes:
A class for calculating the norm of the total linear momentum of a selection of atoms for every frame of a velocity trajectory. |
Reference
- class Momentum(
- traj: Trajectory | TrajectoryReader,
- selection: SelectionCompatible = None,
- use_full_atom_info: bool | None = False,
- scale: PositiveReal | None = None,
Bases:
objectA class for calculating the norm of the total linear momentum of a selection of atoms for every frame of a velocity trajectory.
For every frame the total linear momentum
P = sum_i m_i * v_iis accumulated in float64 over all selected atoms and the norm|P|is multiplied by a scaling factor. With velocities in Angstrom/s (PQ velocity trajectories) the default scaling factor of 1e-15 converts the momentum norm from amu*Angstrom/s to amu*Angstrom/fs.Note that the velocities are parsed from file in single precision by the TrajectoryReader, so reported norms below roughly
1e-7 * sum_i m_i * |v_i| * scaleare parsing noise, not physical center of mass drift. The legacyequipartition.jltool parses the velocities in double precision and therefore resolves correspondingly smaller drift for momentum-conserving trajectories.The Momentum class can be initialized with either a trajectory object or via a TrajectoryReader object. If a trajectory object is given, it is assumed to have a constant topology over all frames! The main difference between the two is that the TrajectoryReader object allows for lazy loading of the trajectory, meaning that the trajectory is only loaded frame by frame when needed. This can be useful for large trajectories that do not fit into memory.
When initialized with a TrajectoryReader of a velocity trajectory, the frames are streamed through the raw fast-path reader (
RawTrajectoryReader) without building an AtomicSystem per frame. The computed momentum norms are bit-identical to the AtomicSystem based stream.- Parameters:
traj (Trajectory | TrajectoryReader) – The velocity trajectory to analyze. If a TrajectoryReader is provided, the trajectory is read frame by frame via a frame_generator.
selection (SelectionCompatible, optional) – The selection of atoms to include in the total momentum, by default None (all atoms).
use_full_atom_info (bool | None, optional) – Whether to use the full atom information of the trajectory for the selection or not, by default None (False).
scale (PositiveReal | None, optional) – The scaling factor applied to the momentum norm before output, by default None (1e-15, which converts amu*Angstrom/s to amu*Angstrom/fs).
- Raises:
MomentumError – If the trajectory is empty.
MomentumError – If the selection does not select any atoms.
MomentumError – If the mass of an atom of the selection is unknown.
- run() Np1DNumberArray[source]
Runs the momentum analysis.
For every frame of the trajectory the total linear momentum of the selected atoms is accumulated in float64 and the scaled norm of the momentum vector is stored.
This method will display a progress bar by default. This can be disabled by setting with_progress_bar to False.
- Returns:
The scaled norms of the total linear momentum, one value per frame.
- Return type:
- Raises:
MomentumError – If a frame does not contain velocity information for all atoms of the topology.
- logger = <CustomLogger PQAnalysis.Momentum (INFO)>
- property n_frames: int
The number of analyzed frames after calling run().
- Type:
int