Created
February 1, 2021 19:50
-
-
Save jmbr/f9d12c608a51dbda26557480db4318a7 to your computer and use it in GitHub Desktop.
Compute RMS distances between frames in an mdtraj Trajectory object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import mdtraj as md | |
import tqdm | |
def compute_distance_matrix(trajectory: md.Trajectory) -> np.ndarray: | |
"""Compute distance matrix. | |
""" | |
topology = trajectory.topology | |
CA_indices = [atom.index for atom in topology.atoms_by_name('CA')] | |
num_frames = len(trajectory) | |
distance_matrix = np.zeros((num_frames, num_frames), dtype=float) | |
for i in tqdm.tqdm(range(num_frames)): | |
rmsds = md.rmsd(trajectory, trajectory, frame=i, | |
atom_indices=CA_indices) | |
distance_matrix[i, :] = rmsds | |
return distance_matrix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment