libmda

Functions that wrap around MDAnalysis library.

Functions contained in this module operate with MDAnalysis (MDA) functionalities, either by using MDA to access Molecular Dynamics data or by receiving MDA data structures and parsing them in some way.

When using functions contained in this library you should cite both taurenmd and MDAnalysis.

taurenmd.libs.libmda.convert_time_or_frame_to_frame(s, u)[source]

Convert a time or frame string to frame.

Parameters
  • s (str or int or float) – A string defining the time (‘12ns’) or frame.

  • u (mda.Universe)

Returns

int – see convert_time_to_frame()

taurenmd.libs.libmda.convert_time_to_frame(x, dt, base_unit='ps')[source]

Convert a string x into a frame number based on given dt.

If x does not contain any units its assumed to be a frame number already.

Original function taken from MDAnalysis.mdacli project, from commit: https://github.com/MDAnalysis/mdacli/blob/15f6981df7b14ef5d52d64b56953d276291068ab/src/mdacli/utils.py#L25-L66 The original function was modified internally without modifying its API.

See also: https://github.com/MDAnalysis/mdacli/pull/81

Note that in case of decimal values, for example, 10.3ps, the integer division between the value and dt remains.

Parameters
  • x (str, int or float) – the input string

  • dt (float) – the time step in ps

Returns

int – frame number

Raises

ValueError – The input does not contain any units but is not an integer.

taurenmd.libs.libmda.create_x_data(u, xdata_in_time, frame_list)[source]

Create X data for plotting.

Create a frame list given a time or else return the frame_list given.

Parameters
  • u (mda.Universe)

  • xdata_in_time (bool) – Whether to select frames based on a time duration.

  • frame_list (list of int) – A list of integers referring to the number of frames in the trajectory.

taurenmd.libs.libmda.draw_atom_label_from_atom_group(atom_group)[source]

Translate MDAnalysis Atom Group to list of strings for each atom.

Strings represent each atom by SEGID.RESNUM|RESNAME.NAME, for example carbon alpha of Cys 18 of chain A would:

>>> A.18Cys.CA

This function is used by taurenmd for data representation purporses.

Parameters

atom_group (Atom Group obj) – MDAnalysis Atom group.

Returns

list of strings – Containing the atom string representation for each atom in the Atom Group.

taurenmd.libs.libmda.get_frame_list_from_slice(u, frame_slice)[source]

Create a frame number list from a slice for a Universe.

Parameters
  • u (mda.Universe) – The MDAnalysis universe.

  • frame_slice (slice object)

Returns

list of ints – A list with the number of frames corresponding to that Universe and slice.

taurenmd.libs.libmda.get_frame_slices(u, start=None, stop=None, step=None)[source]

Make a frame slice for a universe given start, stop, and step.

Parameters

start, stop, step (None or int or str.) – If string, accepts libutil.split_time_unit().

Returns

slice object

taurenmd.libs.libmda.get_timestep(u, i0=0, i1=1)[source]

Get time step between two trajectory frames in picoseconds.

Parameters

it0, it1 (int) – The initial and end frame, respectively.

taurenmd.libs.libmda.load_universe(topology, *trajectories, insort=False, **universe_args)[source]

Load MDAnalysis universe.

Accepts MDAnalysis compatible topology formats and trajectory formats. Read further on the MDAnalysis Universe.

Examples

>>> libmda.load_universe('topology.pdb', 'trajectory.dcd')
>>> libmda.load_universe(
        'topology.pdb',
        'traj_part_1.xtc',
        'traj_part_2.xtc',
        Path('my', 'md', 'folder', 'traj_part_3.xtc'),
        )
Parameters
  • topology (str or Path object) – Path to topology file.

  • trajectories* (str of Path objects) – Paths to trajectory file(s). Trajectory files will be used sequentially to create the Universe.

  • insort (bool) – Whether to sort trajectory files by suffix number. See libio.sort_numbered_input().

  • universe_args (any) – Other arguments to be passed to MDAnalysis Universe.

Returns

MDAnalysis Universe

taurenmd.libs.libmda.mdaalignto(universe, reference, selection='all')[source]

Align universe to reference.

Uses MDAnalysis.analysis.align.alignto.

Parameters

universe, reference, selection – Same as in MDAnalysis.analysis.align.alignto function.

Raises

ZeroDivisionError – If selection gives empty selection.

taurenmd.libs.libmda.report(universe)[source]

Report information about the Universe.

Example

>>> u = libmda.load_universe('topology.pdb', 'trajectory.xtc')
>>> libmda.report(u)
Parameters

universe (MDAnalysis Universe) – MDAnalysis universe.

Returns

None