data

Auxiliary functions for calculating structural properties data.

Functions

calculate_ramachandran_data(trajectory, topology[, ...])

Calculate a dihedral angles matrix from trajectory and topology files.

calculate_contact_matrix_frame(u, frame_idx, frame_weight)

Calculates a contact matrix for a frame of a trajectory.

calculate_contact_matrix(trajectory, topology[, ...])

Calculate a contact frequency matrix from a trajectory and topology files.

calculate_distance_matrix_frame(u, frame_idx, frame_weight)

Calculates a distance matrix for the alpha carbons of a trajectory frame.

calculate_distance_matrix(trajectory, topology[, ...])

Calculate an alpha carbon average distance matrix from a trajectory and topology files.

calculate_ss_assignment(trajectory, topology[, ...])

Calculate a secondary structure assignment matrix from a trajectory and topology files.

calculate_ss_frequency(trajectory, topology[, ...])

Calculate secondary structure assignment frequencies from a trajectory and topology files.

calc_rg(u)

Calculate the radius of gyration of the current frame.

calc_eed(u)

Calculate the distance from the N- to the C-terminal in the current frame.

calc_dmax(u)

Calculate the maximum of the distances between any two alpha carbons in the current frame.

calc_cm_dist(u, sel1, sel2)

Calculate the distance between the center of mass of two atom selections in current frame.

calculate_metrics_data(trajectory, topology[, rg, ...])

Calculate structural metrics for each frame of a trajectory.

calculate_analysis_data(trajectories, topologies, ...)

Calculate structural data for each given pair of trajectory,topology files.

Module Contents

ensemblify.analysis.data.calculate_ramachandran_data(trajectory, topology, output_path=os.getcwd())

Calculate a dihedral angles matrix from trajectory and topology files.

Phi and Psi dihedral angle values are calculated for each residue in each trajectory frame. Optionally saves the matrix to output directory in .csv format, defaulting to current working directory.

Parameters:
  • trajectory (str) – Path to .xtc trajectory file.

  • topology (str) – Path to .pdb topology file.

  • output_path (str, optional) – Path to output .csv file or output directory. If directory, written file is named ‘ramachandran_data.csv’. Defaults to current working directory.

Returns:

DataFrame with Phi and Psi values of each residue for each frame of the trajectory.

Return type:

pd.DataFrame

ensemblify.analysis.data.calculate_contact_matrix_frame(u, frame_idx, frame_weight)

Calculates a contact matrix for a frame of a trajectory.

Parameters:
  • u (mda.Universe) – MDAnalysis.Universe object containing the trajectory being analyzed.

  • frame_idx (int) – Number of the frame to be analyzed.

  • frame_weight (float) – Contacts found in this frame will be assigned this value in the resulting matrix instead of the default value of 1. In a uniformly weighted matrix, this value will be of 1 / number of trajectory frames.

Returns:

Contact matrix for the current frame.

Return type:

np.ndarray

ensemblify.analysis.data.calculate_contact_matrix(trajectory, topology, weights=None, output_path=os.getcwd())

Calculate a contact frequency matrix from a trajectory and topology files.

The contact frequency of a residue pair is calculated from the number of times they are in contact over all frames in the trajectory. Optionally saves the matrix to output directory in .csv format. Uses multiprocessing whenever possible.

Parameters:
  • trajectory (str) – Path to .xtc trajectory file.

  • topology (str) – Path to .pdb topology file.

  • weights (np.ndarray, optional) – Array of weights to be used when calculating the contact matrix. If None, uniform weights are used.

  • output_path (str, optional) – Path to output .csv file or output directory. If directory, written file is named ‘contact_matrix.csv’. Defaults to current working directory.

Returns:

DataFrame with the frequency of each residue contact in the trajectory.

Return type:

pd.DataFrame

ensemblify.analysis.data.calculate_distance_matrix_frame(u, frame_idx, frame_weight)

Calculates a distance matrix for the alpha carbons of a trajectory frame.

Parameters:
  • u (mda.Universe) – MDAnalysis.Universe object containing the trajectory being analyzed.

  • frame_idx (int) – Number of the frame to be analyzed.

  • frame_weight (float) – Distances calculated for this frame will be multiplied by this value in the resulting frame matrix. In a uniformly weighted matrix, calculated distances will be multiplied by 1 divided by the number of trajectory frames.

Returns:

Distance matrix for the current frame.

Return type:

np.ndarray

ensemblify.analysis.data.calculate_distance_matrix(trajectory, topology, weights=None, output_path=os.getcwd())

Calculate an alpha carbon average distance matrix from a trajectory and topology files.

The distances between different pairs of alpha carbons pair is calculated for each trajectory frame and the values are then averaged to create the final distance matrix.

Optionally save the matrix to output directory in .csv format. Uses multiprocessing whenever possible.

Parameters:
  • trajectory (str) – Path to .xtc trajectory file.

  • topology (str) – Path to .pdb topology file.

  • weights (np.ndarray, optional) – Array of weights to be used when calculating the distance matrix. If None, uniform weights are used.

  • output_path (str, optional) – Path to output .csv file or output directory. If directory, written file is named ‘distance_matrix.csv’. Defaults to current working directory.

Returns:

DataFrame with the average distance between each pair of alpha carbons in the trajectory.

Return type:

pd.DataFrame

ensemblify.analysis.data.calculate_ss_assignment(trajectory, topology, output_path=None)

Calculate a secondary structure assignment matrix from a trajectory and topology files.

For each residue in each frame of the trajectory, calculate its secondary structure assignment using DSSP. The simplified DSSP codes used here are:

‘H’ : Helix. Either of the ‘H’, ‘G’, or ‘I’ codes.

‘E’ : Strand. Either of the ‘E’, or ‘B’ codes.

‘C’ : Coil. Either of the ‘T’, ‘S’ or ‘ ‘ codes.

Optionally save the resulting matrix to output directory in .csv format.

Parameters:
  • trajectory (str) – Path to .xtc trajectory file.

  • topology (str) – Path to .pdb topology file.

  • output_path (str, optional) – Path to output .csv file or output directory. If directory, written file is named ‘ss_assignment.csv’. Defaults to None, and no file is written.

Returns:

DataFrame holding the secondary structure assignment matrix.

Return type:

pd.DataFrame

ensemblify.analysis.data.calculate_ss_frequency(trajectory, topology, weights=None, output_path=os.getcwd())

Calculate secondary structure assignment frequencies from a trajectory and topology files.

Parameters:
  • trajectory (str) – Path to .xtc trajectory file.

  • topology (str) – Path to .pdb topology file.

  • weights (np.ndarray, optional) – Optional array of weight values to be used in secondary structure assignment reweighting. If None, uniform weights are used.

  • output_path (str, optional) – Path to output .csv file or output directory. If directory, written file is named ‘ss_frequency.csv’. Defaults to current working directory.

Returns:

Secondary structure frequencies matrix for trajectory being analyzed.

Return type:

pd.DataFrame

ensemblify.analysis.data.calc_rg(u)

Calculate the radius of gyration of the current frame.

Parameters:

u (mda.Universe) – Universe pointing to the current frame.

Returns:

Radius of gyration of the protein in the current frame.

Return type:

float

ensemblify.analysis.data.calc_eed(u)

Calculate the distance from the N- to the C-terminal in the current frame.

Parameters:

u (mda.Universe) – Universe pointing to the current frame.

Returns:

End-to-end distance of the protein in the current frame.

Return type:

float

ensemblify.analysis.data.calc_dmax(u)

Calculate the maximum of the distances between any two alpha carbons in the current frame.

Parameters:

u (mda.Universe) – Universe pointing to the current frame.

Returns:

Maximum of the distances between any two alpha carbons of the protein in the current frame.

Return type:

float

ensemblify.analysis.data.calc_cm_dist(u, sel1, sel2)

Calculate the distance between the center of mass of two atom selections in current frame.

Parameters:
  • u (mda.Universe) – Universe pointing to the current frame.

  • sel1 (str) – MDAnalysis selection string for selecting an AtomGroup whose center of mass will be calculated.

  • sel2 (str) – MDAnalysis selection string for selecting an AtomGroup whose center of mass will be calculated.

Returns:

Center of mass distance between AtomGroups selected by sel1 and sel2.

Return type:

float

ensemblify.analysis.data.calculate_metrics_data(trajectory, topology, rg=True, dmax=True, eed=True, cm_dist=None, output_path=os.getcwd())

Calculate structural metrics for each frame of a trajectory.

Parameters:
  • trajectory (str) – Path to .xtc trajectory file.

  • topology (str) – Path to .pdb topology file.

  • rg (bool, optional) – Whether to calculate, for each frame in the trajectory, the radius of gyration of the protein.

  • dmax (bool, optional) – Whether to calculate, for each frame in the trajectory, the maximum distance between any two alpha carbons in the protein.

  • eed (bool, optional) – Whether to calculate, for each frame in the trajectory, the distance from the N- to C-terminal of the protein.

  • cm_dist (dict[str,tuple[str,str]], optional) –

    Mapping of arbitrary string identifiers to tuples containing two selection strings for creating MDAnalysis AtomGroups. For each frame in the trajectory, the center mass distance between the two AtomGroups will be calculated. For example, to calculate the distance between the centers of mass of two domains, one comprising residues 1-30 and the other comprising residues 110-140:

    {‘inter_domain’ : (‘resid 1:30’, ‘resid 110:140’)}

    If None, no center mass distances are calculated. See https://userguide.mdanalysis.org/stable/selections.html for more information about MDAnalysis selection strings.

  • output_path (str, optional) – Path to output .csv file or output directory. If directory, written file is named ‘structural_metrics.csv’. Defaults to current working directory.

Returns:

DataFrame where columns are the desired structural metrics and rows are the frames of the trajectory.

Return type:

pd.DataFrame

ensemblify.analysis.data.calculate_analysis_data(trajectories, topologies, trajectory_ids, output_directory=os.getcwd(), ramachandran_data=True, distancematrices=True, contactmatrices=True, ssfrequencies=True, rg=True, dmax=True, eed=True, cm_dist=None)

Calculate structural data for each given pair of trajectory,topology files.

Parameters:
  • trajectories (list[str]) – List of paths to .xtc trajectory files.

  • topologies (list[str]) – List of paths to .pdb topology files.

  • trajectory_ids (list[str]) – Prefix trajectory identifiers to distinguish between calculated data files.

  • output_directory (str, optional) – Path to directory where calculated data will be stored. Defaults to current working directory.

  • ramachandran_data (bool, optional) – Whether to calculate a dihedral angles matrix for each trajectory,topology file pair.

  • distancematrices (bool, optional) – Whether to calculate an alpha carbon distance matrix for each trajectory,topology file pair.

  • contactmatrices (bool, optional) – Whether to calculate a contact frequency matrix for each trajectory,topology file pair.

  • ssfrequencies (bool, optional) – Whether to calculate a secondary structure assignment frequency matrix for each trajectory,topology file pair.

  • rg (bool, optional) – Whether to calculate and plot a probability distribution for the radius of gyration for each trajectory,topology file pair.

  • dmax (bool, optional) – Whether to calculate and plot a probability distribution for the maximum distance between any two alpha carbons for each trajectory,topology file pair.

  • eed (bool) – Whether to calculate and plot a probability distribution for the distance between the N- and C-terminal for each trajectory,topology file pair.

  • cm_dist (dict[str,tuple[str,str]], optional) –

    Mapping of arbitrary string identifiers to tuples containing two selection strings for creating MDAnalysis AtomGroups. A probability distribution for the center mass distance between the two AtomGroups will be calculated and plotted. For example, to calculate the distance between the centers of mass of two domains, one comprising residues 1-30 and the other comprising residues 110-140:

    {‘inter_domain’ : (‘resid 1:30’, ‘resid 110:140’)}

    If None, no center mass distances are calculated. See https://userguide.mdanalysis.org/stable/selections.html for more information about MDAnalysis selection strings.

Returns:

Mapping of data identifiers to lists of DataFrames with the calculated analysis data, one element for each given trajectory,topology,trajectory_id trio. For example, if we calculated analysis data for three trajectory,topology pairs:

data = { ‘DistanceMatrices’ : [DistanceMatrix1,DistanceMatrix2,DistanceMatrix3], ‘ContactMatrices’ : [ContactMatrix1,ContactMatrix2,ContactMatrix3], ‘SecondaryStructureFrequencies’ : [SSFrequency1,SSFrequency2,SSFrequency3], ‘StructuralMetrics’ : [StructuralMetrics1,StructuralMetrics2, StructuralMetrics3]}

Return type:

dict[str,list[pd.DataFrame]]