Slow Rotations API¶
- slow_rotations.analysis.check_states(torsionrepeat)¶
Checks the torsion for missing states
Args: torsionrepeat: TorsionRepeat
- Returns:
list of states that are missing
- Return type:
[int]
- slow_rotations.analysis.check_transitions(torsionrepeat, min_transitions=10)¶
Checks the torsion for missing states
Args: torsionrepeat: TorsionRepeat min_transitions: int; minimum transitions that must be observed in and out of a state to be considered adequately sampled
- Returns:
list of states that are missing
- Return type:
[int]
- class slow_rotations.compare.LigandTorsionComparator(tf_list)¶
- convert_torsion_indices(trajidx, torsion)¶
Converts torsion from first indexing system into indexing system of another trajectory
- Parameters:
trajidx – int; index of the trajectory we are converting to
torsion – [int, int, int, int]; torsion in the indexing system of the first trjaectory, (torsions from get_torsions function)
- Returns
[int, int, int, int]: torsion in the indexing system of the trajectory specified
- plot_all_distributions(torsion, save_path=None, close=False)¶
creates a matplotlib plot of the distribution across all the trajectories passed as well as one for each individual trajectory for comparison to each other and the cumulative distribution :param torsion: [int, int, int, int]; torsion in the indexing system of the first trjaectory, (torsions from get_torsions function) :param save_path: str; path to save :param close: bool; close the figure when done
- Returns:
torsion information for futher analysis
- Return type:
dict
- class slow_rotations.compare.ProteinTorsionComparator(tf_list, a_cutoff=5)¶
- get_torsions()¶
gets all protein sidechain torsions in the system
- Parameters:
None
- Returns:
list of torsions
- Return type:
[[int, int, int, int]]
- plot_all_distributions(torsion, save_path=None, close=False)¶
creates a matplotlib plot of the distribution across all the trajectories passed as well as one for each individual trajectory for comparison to each other and the cumulative distribution :param torsion: [int, int, int, int]; torsion in the indexing system of the first trjaectory, (torsions from get_torsions function) :param save_path: str; path to save :param close: bool; close the figure when done
- Returns:
torsion information for futher analysis
- Return type:
dict
- class slow_rotations.compare.TorsionComparator(tf_list)¶
- convert_torsion_indices(trajidx, torsion)¶
Converts torsion from first indexing system into indexing system of another trajectory
- Parameters:
trajidx – int; index of the trajectory we are converting to
torsion – [int, int, int, int]; torsion in the indexing system of the first trjaectory, (torsions from get_torsions function)
- Returns
[int, int, int, int]: torsion in the indexing system of the trajectory specified
- get_all_angles(torsion)¶
gathers all the angles across all timeseries for the torsion of interest :param torsion: [int, int, int, int]; torsion in the indexing system of the first trjaectory, (torsions from get_torsions function)
- Returns:
timeseries of angles
- Return type:
[float]
- static get_angle_min(angles)¶
gets the minimum angle across all angles provided to shift histogram by such that no peaks are split :param angles: [float]; list of angless
- Returns:
minimum angle
- Return type:
int
- get_cumulative_angles(torsion)¶
gets all angles of the torsion across all trajectors, shifted such that no peaks are split :param torsion: [int, int, int, int]; torsion in the indexing system of the first trjaectory, (torsions from get_torsions function)
- Returns:
minimum angle [float]: shifted angles across all trajectories
- Return type:
int
- get_torsions()¶
Get all small molecule torsions using the indexing system first input LigandTorsionFinder
- Parameters:
None
- Returns:
list of torsions
- Return type:
[[int, int, int, int]]
- plot_cumulative_distribution(torsion, ax=None, save_path=None, close=False)¶
creates a matplotlib plot of the distribution across all the trajectories passed :param torsion: [int, int, int, int]; torsion in the indexing system of the first trjaectory, (torsions from get_torsions function) :param ax: axis; matplot lib axis to put the plot in :param save_path: str; path to save :param close: bool; close the figure when done
- Returns:
angle minimum [float]: angle location of peaks [[float,float]]: bounds of peaks
- Return type:
int
- slow_rotations.mappings.check_symmetry(mol, torsion)¶
Checks symmetry of central bond atoms in a torsion using RDKit.
- Parameters:
mol – RDKit Mol
torsion – (int, int, int, int) - atom indices defining the torsion
- Returns:
True if torsion has symmetry, False otherwise
- Return type:
bool
- slow_rotations.mappings.convert_dihedral(mapping, dihedral)¶
converts indices in dihedral based on the provided mapping
- Parameters:
mapping – dict; mapping dihedral atoms
dihedral
- Returns:
bool
- slow_rotations.mappings.get_atom_by_index(mol, idx)¶
finds RDKit Atom objects of interest based on provided atom
- Parameters:
mol – (Chem.Mol) RDKit Mol
idx – int; index of atom of interest
- Returns:
RDKit Atom
- Return type:
Chem.Atom
- slow_rotations.mappings.map_mols(mol1, mol2)¶
Creates dictionary mapping of indices between atoms of mol1 and mol2
- Parameters:
mol1 – RDKit Mol
mol2 – RDKit Mol
- Returns:
{int: int}; dictionary mapping of indices {mol1: mol2}
- Return type:
dict
- slow_rotations.mappings.rd_map_mols(rdmol1, rdmol2)¶
Given 2 RDKit Mols, determines the mapping based on the MCS
- Parameters:
rdmol1 – Chem.Mol
rdmol2 – Chem.Mol
- Returns:
mapping of atoms
- Return type:
dict
- slow_rotations.mappings.torsions_equivalent(t1, t2)¶
checks if 2 torsions are equivalent
- Parameters:
t1 – (int, int, int, int); indices of atoms in torsion of interest
t2 – (int, int, int, int); indices of atoms in torsion of interest
- Returns:
bool
- slow_rotations.pdb_writer.get_atom_type(atype)¶
- slow_rotations.pdb_writer.make_standard_atmname(pmd_struct)¶
Converts third column pdb atom name from any atom name to atom type naming convention. In gmx to prevent forcefield issues, we rename ligand atom types either as lower case, or with extra characters to prevent clashes with protein and other forcefield naming conventions
- Parameters:
pmd_struct – parmed structure
- Returns:
parmed.structure
- slow_rotations.pdb_writer.rename_lig_pdb_atoms(ilig_pdb, olig_pdb)¶
Renames small molecule/ligand PDB atoms to have standard naming conventions recognized by gromacs
- Parameters:
ilig_pdb – str; input pdb file name
olig_pdb – str; output pdb file name
- Returns:
None
- slow_rotations.rdkit_wrapper.assign_bond_order_from_smiles(smiles, molfile)¶
Assigns the bond order of a rdkit molecule lacking proper bond information based on its smiles
- Parameters:
smiles – str; smiles str representing the correct bond orders
molfile – str; pdb, sdf, or mol2 filename of molecule that lacks correct bond order information
- Returns:
RDKit Mol with
- Return type:
Chem.Mol
- slow_rotations.rdkit_wrapper.get_index_convert(rdmol1, rdmol2)¶
- slow_rotations.rdkit_wrapper.get_mapped_bonds(mol, mapped_atoms)¶
Finds RDKit bonds objects of interest based on mapped_atoms indices list
- Parameters:
mol – (Chem.Mol) RDKit Mol
mapped_atoms – [int]; indices of atoms of interest
- Returns:
list of RDKit bonds
- Return type:
list
- slow_rotations.rdkit_wrapper.get_mapped_heavy_atom_indices(mol, mapped_atoms)¶
Finds RDKit Atom objects of interest based on mapped_atoms indices list
- Parameters:
mol – (Chem.Mol) RDKit Mol
mapped_atoms – [int]; indices of atoms of interest
- Returns:
list of RDKit Atoms
- Return type:
list
- slow_rotations.rdkit_wrapper.get_rotatable_bonds(mol, torsion_smarts=None)¶
Finds rotatable bonds in a molecule.
- BY DEFAULT Flags:
Standard rotatable bonds (R-C-C-R, etc.)
Terminal hetero torsions R-C-X-H (alcohols, amines, thiols)
- Parameters:
mol (Chem.Mol) – RDKit molecule
- Returns:
RDKit bond objects representing rotatable bonds
- Return type:
list of Chem.Bond
- slow_rotations.rdkit_wrapper.highlight_dihedral(mol, mol_wo_H, index_convert, dihedral, save_path=None)¶
Creates an image of the molecule with the dihedral of interest highlighted in red
- Parameters:
mol – Chem.Mol; rdkit molecule
dihedral – (int, int, int, int); 4 consecutive atom indices that represent the torsion of interest
save_path – str; file path to save image to
- Returns:
None
- slow_rotations.rdkit_wrapper.load_rdmol_from_file(molfile, removeHs=False)¶
load molecule in molfile as an RDKit Mol
- Parameters:
molfile – str; sdf or mol2 filename of small molecule
removeHs – bool; strip Hs from the rdkit molecule
- Returns:
rdkit molecule
- Return type:
Chem.Mol
- slow_rotations.rdkit_wrapper.sanitize_rdmol(mol)¶
Checks and corrects the chemical structure of molecule. (Checks valence, aromaticity, kekulization, and stereochemistry)
- Parameters:
mol – Chem.Mol; rdkit molecule
- Returns:
santized rdkit molecule
- Return type:
Chem.Mol
- exception slow_rotations.torsions.BadTorsionError¶
Exception raised when there is a problem with the user input torsion
- class slow_rotations.torsions.LigandTorsionFinder(trajf, topf, ligcode, smiles, torsion_smarts=None)¶
Analyze torsions in the ligand of a system
- convert_idx_to_sysidx(idx)¶
when ligand is not the only molecule in the system converts the ligand indices starting at 0 to indices that are relevant to the system
- Parameters:
idx – int; index to be converted
- Returns:
index of the atom within the context of the system
- Return type:
int
- export_pdb_from_traj(frame, opdb, sel='all')¶
exports the specified selection (sel) from the frame of interest as a pdb
- Parameters:
frame – int; frame of trajectory
opdb – str; name of the output pdb
output (sel; str; MD Analysis selection language of what to)
- Returns:
None
- get_rdmol()¶
return RDKit Mol for the small molecule
- Parameters:
None
- Returns:
Mol
- get_rdmol_by_frame(frame)¶
returns the conformation of the rdkit molecule in the specified frame
- Parameters:
frame – int; frame of trajectory of interest
- Returns:
Mol
- get_torsions()¶
gets a list of all torsions
- Parameters:
None
- Returns:
list of torsions
- Return type:
[[int, int, int, int]]
- highlight_dihedral(dihedral, save_path=None)¶
highlights the dihedral of a protein sidechain
- exports the protein residue as a single AA pdb
loads in the single protein into rdkit with and without Hs
compares the 2 to get atom orderings via MCS
- make_torsion_img(torsion, angle_min=None, save_path=None)¶
create a matplot lib figure of scatter plot
- Parameters:
torsion – [int, int, int, int]: torsions atom indices
angle_min – int; minimum angle of the histogram
save_path – str; path to save image to
- Returns:
torsion state boundaries TransitionMatrixCounter: counts of transitions between states [str]: names of each state bool: True if torison has symmetry, False otherwise float: populations of each state
- Return type:
[[float, float]]
- make_torsion_img_no_shift(torsion, save_path=None)¶
create a matplot lib figure where the histogram is not shifted (bounds are -180 to 180)
- Parameters:
torsion – [int, int, int, int]: torsions atom indices
save_path – str; path to save image to
- Returns:
None
- plot_dihedral_scatter(torsion, ax=None, angle_min=None, title=None, save_path=None)¶
create a matplot lib figure of scatter plot
- Parameters:
torsion – [int, int, int, int]: torsions atom indices
ax – axis; matplotlib axis to use for plot
angle_min – int; minimum angle of the histogram
title – str; title of the figure
save_path – str; path to save image to
- Returns:
None
- class slow_rotations.torsions.ProteinTorsionFinder(trajf, topf, ligcode=None)¶
Class for running analysis on protein sidechain torsions
- determine_chi_angle(torsion)¶
Determine which chi angle (1 to 8) a torsion belongs to in a residue.
- Parameters:
torsion – [int,int,int,int]’’ list of 4 atom indices (integers)
- Returns:
int from 1 to 8, or None if not found
- Return type:
chi_number
- determine_chi_x(torsion)¶
- get_all_chi_x_torsions(sel=None, a_cutoff=5)¶
- get_binding_residues(A_cutoff=5)¶
identify all residues within A_cutoff angstroms of the ligand
- Parameters:
A_cutoff –
float Angstrom cutoff from binding mode
- Returns:
[int]: list of interacting residue IDs
- get_chi1_torsions(resids=None, a_cutoff=None)¶
identify the chi1 torsion atom indices of specified residue ids
- get_chi_x_ags(x, resgrp)¶
returns a list of atom groups inolved in chi x anglebased on the residue group :param resgrp: ResidueGroup; MDAnalysis residue Group
- Returns:
MDAnalysis atom group
- Return type:
[AtomGroup]
- get_chi_x_aid(x, resgrp)¶
returns a list of tuples of atom indices (aid)
- Parameters:
x – int; chi angle (ex. 2 for chi2)
resgrp – ResidueGroup; residues of interest
- Returns
[[int]]; atom indices for each chi X torsion of interest
- get_chi_x_residues(x, sel=None, a_cutoff=5)¶
identify the chi torsion atom indices of specified residue indices at the specified chi angle
- Parameters:
x – int; which chi up to chi8
sel – str; MDAnalysis selection language of residues of interest
a_cutoff – float; Angstrom cutoff from ligand
- Returns:
atom indices of chi1 torsions
- Return type:
[[int, int, int, int]]
- get_chi_x_torsions(x, sel=None, a_cutoff=5)¶
returns a list of chi x torsions atom indices in the protein given the selection (sel) :param x: int; chi angle (ex. 2 for chi2) :param sel: str; MDAnalysis selection string for residues of interest :param a_cutoff: float; Angstrom cutoff
- Returns
[[int]]; atom indices for each chi X torsion of interest
- static get_intersection(list_of_sets)¶
returns a set that is an intersection of all the sets in the list
- Parameters:
list_of_sets – [set]; list of sets to intersect
- Returns:
set that represents the intersection
- Return type:
set
- get_residues_ags(resgrp)¶
given the residues in resgrp, create an atom group of all relevant atoms :param resgrp: ResidueGroup; MDAnalysis residue Group
- Returns:
MDAnalysis atom group
- Return type:
AtomGroup
- highlight_dihedral(torsion, save_path=None)¶
highlights the dihedral of a protein sidechain * exports the protein residue as a single AA pdb * loads in the single protein into rdkit with and
without Hs
compares the 2 to get atom orderings via MCS
- Parameters:
torsion – [int, int, int, int]; atom indices representing torsion of interest
save_path – str; path to save image
- Returns:
None
- make_torsion_img(torsion, angle_min=None, save_path=None)¶
create a matplot lib figure of scatter plot
- Parameters:
torsion – [int, int, int, int]: torsions atom indices
angle_min – int; minimum angle of the histogram
save_path – str; path to save image to
- Returns:
torsion state boundaries TransitionMatrixCounter: counts of transitions between states [str]: names of each state bool: True if torison has symmetry, False otherwise float: populations of each state
- Return type:
[[float, float]]
- save_traj_sel(sel, frames, save_path)¶
saves out the atoms selected in sel as a new file for the purpose of this program meant to save out a single amino acid as a pdb file
- Parameters:
sel – str; selection string using MDAnalysis atom selection language
frames – (int,int); 2 membered tuple with the start and end (not inclusive) frame to save out [start, end)
save_path – str; path to save
- Returns:
None
- class slow_rotations.torsions.TorsionFinder(trajf, topf)¶
Base class for performing analysis on all relevant torsions in a system
- static add_0_to_kde(X, score)¶
shifts torsion angles in histogram to specified angle. if no angle is specified, shifts angle to
- Parameters:
angles – [float]; timeseries of angles
num_bins – int; num bins in the historgram
angle_min – int; force a minimum for the angles if specified otherwise
- Returns:
converted index
- Return type:
int
- convert_idx_to_sysidx(idx)¶
converts the index to 0 based index within molecule to index of the entire system
- Parameters:
idx – int; index to convert
- Returns:
converted index
- Return type:
int
- static get_angle_shift_point(angles, num_bins=40)¶
finds a new angle minimum for histogram so no peaks are split If no bins exist without histogram entries, shifts to the bin with the lowest number of entries.
- Parameters:
angles – [float]; angles timeseries
num_bins – int; number of bins to use for histogram of angles
- Returns:
minimum angle for histogram
- Return type:
int
- get_bounds_gmm()¶
- static get_bounds_knn(X, num_components, peaks, tolerance=40)¶
get the bounds based of each peak using k nearest neighbor algorithm
- Parameters:
X – [[float]]; angles
num_components – int; nubmer of peaks
peaks – [float]; angle locations of peaks
tolerance – int; the largest gap in angles we can have before it is considered not in that peak
- Returns:
angle bounds of each peak
- Return type:
[[float, float]]
- static get_bounds_mindist(X, scores, num_components, peaks, tolerance=50)¶
get the bounds based of each peak by assigning each score value to its closest peak
- Parameters:
X – [[float]]; angles
scores – [float]; kernel density estimator score
num_components – int; nubmer of peaks
peaks – [float]; angle locations of peaks
tolerance – int; the largest gap in angles we can have before it is considered not in that peak
- Returns:
angle bounds of each peak
- Return type:
[[float, float]]
- static get_closest_peak(angle, peaks)¶
calculate the closest peak for that angle
- Parameters:
angle – float; angle to get closest peak for
peaks – [float]; angle locations of peaks
- Returns:
index of peak in peaks that is the minimum
- Return type:
int
- static get_gmm(X, num_components, angle_min)¶
get gaussian mixture model representation the entire distribution
- Parameters:
X – [[float]]; angles
angle_min – int; minimum angle
min_max – [[float, float]] bounds of the peaks
- Returns:
gaussian mixture model object x: pdf: probability distribution function pdf_individual: probability distribution function of the individual peakd
- Return type:
gmm
- static get_individual_gmm(X, angle_min, min_max)¶
get gaussian mixture model representation of a single peak
- Parameters:
X – [[float]]; angles
angle_min – int; minimum angle
min_max – [[float, float]] bounds of the peaks
- Returns:
gaussian mixture model object x: pdf: probability distribution function pdf_individual: probability distribution function of the individual peak [float, float]: minimum and maximum used
- Return type:
gmm
- static get_kde(angles, num_bins=40, angle_min=None)¶
calculates the kernel density estimator
- Parameters:
angles – [float]; timeseries of angles
num_bins – int; num bins in the historgram
angle_min – int; force a minimum for the angles if specified otherwise
- Returns:
X angles [float]: kernel density estimator score int: minimum angle of the distribution
- Return type:
[[float]]
- static get_kde_num_peaks(X, scores, smoothing_window=30, peak_prominence=0.0001, peak_dist=30)¶
counts the number of peaks in the Kernel Density estimator
- Parameters:
X – [[float]] angles
scores – [float] kernel density estimator score
smoothing_window – int width of window to average over
peak_prominence – float how prominent the peak must be in order to be counted
peak_dist – int minimum distance apart peaks must fall
- Returns:
num_peaks peaks: [float] angle location of the peaks
- Return type:
int
- get_residue_from_torsion(torsion)¶
get the residue the torsion atom indices belong to :param torsion: [int, int, int, int] atom indices of atom involved in torsion
- Returns:
MDAnalysis residue that torsion belongs to
- Return type:
Residue
- get_residue_name_from_torsion(torsion)¶
- static get_statistical_inefficiency(angles, num_bins=40, angle_min=None)¶
calculates the statistical inefficiency of the angles timeseries
- Parameters:
angles – [float]; timeseries of angles
num_bins – int; num bins in the historgram
angle_min – int; force a minimum for the angles if specified otherwise
- Returns:
statisitcal inefficiency
- Return type:
float
- get_torsion_angles(torsion)¶
Gets timeseries of torsion angles
- Parameters:
torsion – [int, int, int, int]; list of torsion atom indices
- Returns:
angle timeseries
- Return type:
np.array
- get_torsion_name(torsion)¶
count the transitions in and out each state (matrix)
- Parameters:
[float] – angles
range_of_states – [[float, float]]; bounds of the peaks
- Returns:
string name of torsion based on residue + residue number and indices
- Return type:
str
- get_torsions()¶
- make_torsion_img(torsion, angle_min=None, save_path=None)¶
create a image of all the torsion transitions
- Parameters:
torsion – [int, int, int, int]; indices of the torsion of interest
angle_min – int; minimum angle of the histogram
save_path – str; path to save the image
- Returns:
minimum angle fo the histogram
- Return type:
int
- mindist(X, num_components, peaks)¶
- static plot_dihedral_histogram(angles, angle_min=None, pdf_individual=[], ax=None, title=None, num_bins=40, alpha=0.5, show=True, color=None, pdf_colors=[], save_path=None)¶
- static plot_dihedral_scatter(angles, ax=None, angle_min=None, title=None, show=False, save_path=None)¶
- plot_kde(torsion, smoothing_window=-1, angle_min=None, save_path=None)¶
- static plot_transition_counts(transition_ctr, ax=None, colors=[])¶
- static shift_torsion_angles(angles, num_bins=40, angle_min=None)¶
shifts torsion angles in histogram to specified angle. if no angle is specified, shifts angle to
- Parameters:
angles – [float]; timeseries of angles
num_bins – int; num bins in the historgram
angle_min – int; force a minimum for the angles if specified otherwise
- Returns:
minimum angle of histogram
- Return type:
float
- static state_populations(angles, range_of_states)¶
calculate the transitions between each state
- Parameters:
[float] – angles
range_of_states – [[float, float]]; bounds of the peaks
- Returns:
populations of each state
- Return type:
[float]
- static transition_counter(angles, range_of_states)¶
count the transitions in OR out of each state (less information than transition_matrix())
- Parameters:
[float] – angles
range_of_states – [[float, float]]; bounds of the peaks
- Returns:
TransitionCounter
- static transition_matrix(angles, range_of_states)¶
count the transitions in and out each state (matrix)
- Parameters:
[float] – angles
range_of_states – [[float, float]]; bounds of the peaks
- Returns:
TransitionMatrixCounter
- class slow_rotations.transitions.TransitionCounter(num_states)¶
- increment_in(state)¶
- increment_out(state)¶
- max_transitions()¶
- min_transitions()¶
- num_states()¶
- to_dict()¶
- to_pandas()¶
- total_transitions()¶
- class slow_rotations.transitions.TransitionMatrixCounter(num_states)¶
- count_transitions_into_state(state)¶
- count_transitions_out_of_state(state)¶
- increment_transition(state1, state2)¶
- max_transitions()¶
- min_transitions()¶
- num_states()¶
- to_dict()¶
- to_pandas()¶
- total_transitions()¶
- exception slow_rotations.utils.NoMoleculeError¶
- exception slow_rotations.utils.NotImplementedError¶
- slow_rotations.utils.warn(msg)¶