normal_modes

Generating normal modes, reading and writing mode data from/to files.

Module Contents

normal_modes.generate_nmd_from_pdb(pdb_path: pathlib.Path | str, nmd_path: pathlib.Path | str, mode_count=10)[source]

Parses a PDB file with a structure and a trajectory and calculates the normal modes of the trajectory. Writes them to an NMD file.

This can be an expensive process, which is why it’s encapsulated in a function that goes from file to file and doesn’t produce an in-memory structure. To work with the resulting normal modes, use NormalModes.from_nmd(), which is a cheap operation.

exception normal_modes.ValidationError[source]

Bases: Exception

Represents a mismatch in normal mode information

Example: the number of coordinates given versus the number of vectors in the mode.

class normal_modes.NormalModes[source]

An object that represents a collection of normal modes

Primarily parsed from an NMD file generated by the generate_nmd_from_pdb() function, but can be constructed manually.

static from_nmd(nmd_path: pathlib.Path | str) NormalModes[source]

Create a NormalModes instance by parsing the given input file. A fast operation.

coordinates = None[source]
atomnames = None[source]
resnames = None[source]
resids = None[source]
modes = [][source]
parse_nmd_file(nmd_path)[source]

Parse the given NMD file and extract atomnames, resnames, resids, coordinates, and modes into a NormalModes object. Expected structure:

atomnames CA CA CA ...
resnames SER ARG LEU ...
resids 0 1 2 3 4 5 6 7 8 11 12 ...
coordinates 54.260 50.940 73.060 ...
mode 1 29.61 -0.008 -0.005 0.012 ...
mode 2 18.28 -0.009 0.004 -0.008 ...
mode 3 17.50 -0.027 -0.025 0.023 ...
mode <N> <magnitude> <x1> <y1> <z1> <x2> <y2> <z2> ...

There may be additional lines that we currently ignore.

generate_trajectory(frame_count=100, vector_scale=2.5, mode_indices=0)[source]

Generate a trajectory that visualises these modes.

The frame count is expected to be an even number. The first frame is the initial coordinates, then the animation applies the vectors forward, then back. The last frame should also be the initial coordinates, provided there are no numerical errors.

By default, the first mode is used, but you can provide the index in self.modes to use by changing mode_indices. If that input is given as a range, the whole range of modes will be used to generate the trajectory.

The vector_scale parameter simply controls how much to scale the vectors to produce a clearly visible trajectory. Setting it too high might result in very large changes to the visualization.

_validate_modes()[source]

Ensure that the modes’ shapes match the coordinates.

_group_in_threes(flat_coordinates)[source]

A utility function that groups sequences of values into triplets.