molgri.molecules.parsers

Parse files and energies - wrap MDAnalysis functions.

The parsers module deals with input. This can be a trajectory or single-frame topology file (FileParser), specifically a Pseudotrajectory file (PtParser) or energy write-out (XVGParser).

The result of file parsing is immediately transformed into a ParsedMolecule or a sequence of ParsedMolecule objects -> ParsedTrajectory. Similarly, energies are stored in the ParsedEnergy object that can be connected to ParsedTrajectory. Those are the objects that other modules should access.

Classes

FileParser(path_topology[, path_trajectory, ...])

This module serves to load topology or trajectory information and output it in a standard format of a ParsedMolecule or a generator of ParsedMolecules (one per frame).

ParsedEnergy(energies, labels, unit)

ParsedMolecule(atoms[, box])

Wraps the behaviour of AtomGroup and Box implemented by MDAnalysis and provides the necessary rotation and translation functions.

ParsedTrajectory(name, molecule_generator, ...)

PtParser(m1_path, m2_path, path_topology[, ...])

A parser specifically for Pseudotrajectories written with the molgri.writers module.

XVGParser(path_xvg)

class molgri.molecules.parsers.ParsedMolecule(atoms: AtomGroup, box=None)

Wraps the behaviour of AtomGroup and Box implemented by MDAnalysis and provides the necessary rotation and translation functions.

Args:

atoms: an AtomGroup that makes up the molecule box: the box in which the molecule is simulated

__init__(atoms: AtomGroup, box=None)

Wraps the behaviour of AtomGroup and Box implemented by MDAnalysis and provides the necessary rotation and translation functions.

Args:

atoms: an AtomGroup that makes up the molecule box: the box in which the molecule is simulated

get_atoms() AtomGroup
get_center_of_mass() ndarray[Any, dtype[ScalarType]]
get_positions() ndarray[Any, dtype[ScalarType]]
get_box()
rotate_about_origin(rotational_obj: Rotation, inverse: bool = False)
rotate_about_body(rotational_obj: Rotation, inverse: bool = False)
translate(vector: ndarray)
rotate_to(position: ndarray[Any, dtype[ScalarType]])
  1. rotate around origin to get to a rotational position described by position

  2. rescale radially to original length of position vector

Args:

position: 3D coordinates of a point on a sphere, end position of COM

translate_to_origin()

Translates the object so that the COM is at origin. Does not change the orientation.

translate_radially(distance_change: float)

Moves the object away from the origin in radial direction for the amount specified by distance_change (or towards the origin if a negative distance_change is given). If the object is at origin, translate in z-direction of the internal coordinate system.

Args:

distance_change: the change in length of the vector origin-object

class molgri.molecules.parsers.FileParser(path_topology: str, path_trajectory: str | None = None, path_energy: str | None = None)

This module serves to load topology or trajectory information and output it in a standard format of a ParsedMolecule or a generator of ParsedMolecules (one per frame). No properties should be accessed directly, all work in other modules should be based on attributes and methods of ParsedMolecule.

Args:

path_topology: a full path to the structure file (.gro, .xtc, .xyz ….) that should be read path_trajectory: a full path to the trajectory file (.xtc, .xyz ….) that should be read

__init__(path_topology: str, path_trajectory: str | None = None, path_energy: str | None = None)

This module serves to load topology or trajectory information and output it in a standard format of a ParsedMolecule or a generator of ParsedMolecules (one per frame). No properties should be accessed directly, all work in other modules should be based on attributes and methods of ParsedMolecule.

Args:

path_topology: a full path to the structure file (.gro, .xtc, .xyz ….) that should be read path_trajectory: a full path to the trajectory file (.xtc, .xyz ….) that should be read

get_dt()

Time in ps between trajectory frames (assuming constant time step)

get_file_path_trajectory()
get_file_path_topology()
get_topology_file_name()
get_trajectory_file_name()
get_parsed_trajectory(default_atom_selection=None)
as_parsed_molecule() ParsedMolecule

Method to use if you want to parse only a single molecule, eg. if only a topology file was provided.

Returns:

a parsed molecule from current or only frame

generate_frame_as_molecule(atom_selection=None) Generator[ParsedMolecule, None, None]

Method to use if you want to parse an entire trajectory and generate a ParsedMolecule for each frame.

Returns:

a generator yielding each frame individually

class molgri.molecules.parsers.PtParser(m1_path: str, m2_path: str, path_topology: str, path_trajectory: str | None = None, path_energy: str | None = None)

A parser specifically for Pseudotrajectories written with the molgri.writers module. Useful to test the behaviour of writers or to analyse the resulting pseudo-trajectories.

Args:

m1_path: full path to the topology of the central molecule m2_path: full path to the topology of the rotating molecule path_topology: full path to the topology of the combined system path_trajectory: full path to the trajectory of the combined system

__init__(m1_path: str, m2_path: str, path_topology: str, path_trajectory: str | None = None, path_energy: str | None = None)

A parser specifically for Pseudotrajectories written with the molgri.writers module. Useful to test the behaviour of writers or to analyse the resulting pseudo-trajectories.

Args:

m1_path: full path to the topology of the central molecule m2_path: full path to the topology of the rotating molecule path_topology: full path to the topology of the combined system path_trajectory: full path to the trajectory of the combined system

generate_frame_as_double_molecule() Generator[Tuple[ParsedMolecule, ParsedMolecule], None, None]

Differently to FileParser, this generator always yields a pair of molecules: central, rotating (for each frame).

Yields:

(central molecule, rotating molecule) at each frame of PT

get_parsed_trajectory()
generate_r_molecule() Generator[ParsedMolecule, None, None]
generate_c_molecule() Generator[ParsedMolecule, None, None]
class molgri.molecules.parsers.ParsedEnergy(energies: ndarray[Any, dtype[ScalarType]], labels, unit)
__init__(energies: ndarray[Any, dtype[ScalarType]], labels, unit)
get_energies(energy_type: str)
class molgri.molecules.parsers.XVGParser(path_xvg: str)
__init__(path_xvg: str)
get_parsed_energy()
get_all_columns() ndarray[Any, dtype[ScalarType]]
get_all_labels() tuple
get_y_unit() str
get_column_index_by_name(column_label) Tuple[str, int]
class molgri.molecules.parsers.ParsedTrajectory(name: str, molecule_generator: Callable, energies: ParsedEnergy, is_pt=False, default_atom_selection=None, dt=1)
__init__(name: str, molecule_generator: Callable, energies: ParsedEnergy, is_pt=False, default_atom_selection=None, dt=1)
get_num_unique_com(energy_type='Potential', atom_selection=None)
assign_coms_2_grid_points(full_grid: FullGrid, atom_selection=None, coms=None, nan_free=False) Tuple[ndarray[Any, dtype[ScalarType]], ndarray[Any, dtype[ScalarType]]]

Given a simulation, select centres of mass of a subset of atoms (eg. one of the molecules and assign them to the Voronoi cells of a selected position grid. This is useful to see what part of position space a classical simulation has covered or to see which molecules moved out of their original grid point area after a short optimisation.

Args:

full_grid: to which full grid the COMs should be fitted atom_selection: used to select the atom belonging to the wished group

Returns:

an array of numbers, length the same as the length of the parsed trajectory, each number represents the index of the point in the flattened position grid of the full_grid that is closest to this COM.

set_c_r(c_num: int, r_num: int)
get_all_energies(energy_type: str)
get_all_COM(atom_selection=None) ndarray[Any, dtype[ScalarType]]
get_name()
get_atom_selection_r()
get_atom_selection_c()
get_unique_com(energy_type: str = 'Potential', atom_selection=None)

Get only the subset of COMs that have unique positions. Among those, select the ones with lowest energy (if energy info is provided)

get_only_lowest_highest(coms: ndarray[Any, dtype[ScalarType]], energies: ndarray[Any, dtype[ScalarType]], lowest_k: int | None = None, highest_j: int | None = None)

After any step that produces a set of COMs and corresponding energies, you may filter out only the (COM, energy) with k lowest and/or j highest energies. This is useful for plotting so that only relevant points are visible.

get_unique_com_till_N(N: int, energy_type: str = 'Potential', atom_selection=None)