moleculekit.projections.metricdistance module#
- class moleculekit.projections.metricdistance.MetricDistance(sel1, sel2, periodic, groupsel1=None, groupsel2=None, metric='distances', threshold=8, truncate=None, groupreduce1='closest', groupreduce2='closest', pairs=False)#
Bases:
ProjectionCreates a MetricDistance object
- Parameters:
sel1 (
str|ndarray) – Atom selection for the first set of atoms (a selection string, boolean mask, or integer index array). See more heresel2 (
str|ndarray) – Atom selection for the second set of atoms (a selection string, boolean mask, or integer index array). If sel1 != sel2, it will calculate inter-set distances. If sel1 == sel2, it will calculate intra-set distances. See more hereperiodic (
str) – If periodic distances should be calculated and between which elements. If set to “chains” it will only calculate periodic distances between different chains. If set to “selections” it will calculate periodic distances between the two selections. If set to None it will not calculate any periodic distances.groupsel1 (
str|None) – Group all atoms in sel1 to the single closest/COM distance. Alternatively can calculate the closest/COM distance of a residue containing the atoms in sel1.metric (
str) – Set to ‘contacts’ to calculate contacts instead of distancesthreshold (
float) – The threshold under which a distance is considered in contact. Units in Angstrom.truncate (
float|None) – Set all distances larger than truncate to truncate. Units in Angstrom.groupreduce1 (
str) – The reduction to apply on group 1 if groupsel1 is used. closest will calculate the closest distance of group 1 to selection 2. com will calculate the distance of the center of mass of group 1 to selection 2.groupreduce2 (
str) – Same as groupreduce1 but for group 2 if groupsel2 is used.pairs (
bool) – If set to True it will match atoms in sel1 to atoms in sel2 in their given order and only calculate distances of those pairs of atoms instead of all-against-all distances
- Returns:
proj
- Return type:
MetricDistance object
Examples
Calculate periodic distances between all protein CA atoms and all atoms of a ligand called MOL >>> metr = MetricDistance(“protein and name CA”, “resname MOL”, periodic=”selections”) >>> data = metr.project(mol)
Calculate the single periodic distance between the closest atom of the protein to the closest atom of the ligand >>> MetricDistance(“protein”, “resname MOL”, “selections”, groupsel1=”all”, groupsel2=”all”)
Calculate the periodic distances between the closest atom of each protein residue to the single closest ligand atom >>> MetricDistance(“protein”, “resname MOL”, “selections”, groupsel1=”residue”, groupsel2=”all”)
Calculate the periodic distance between the COM of the protein to the COM of the ligand >>> MetricDistance(“protein”, “resname MOL”, “selections”, groupsel1=”all”, groupsel2=”all”, groupreduce1=”com”, groupreduce2=”com”)
Calculate the non-periodic distance between a ligand atom and a protein atom >>> MetricDistance(“protein and name CA and resid 10”, “resname MOL and name C7”, periodic=None)
Calculate the distance of two nucleic chains >>> MetricDistance(“nucleic and chain A”, “nucleic and chain B”, periodic=”chains”)
- class moleculekit.projections.metricdistance.MetricSelfDistance(sel, groupsel=None, metric='distances', threshold=8, periodic=None, truncate=None)#
Bases:
MetricDistance
- moleculekit.projections.metricdistance.contactVecToMatrix(vector, atomIndexes)#
Converts a 1D contact/distance vector into a square symmetric matrix.
- Parameters:
- Returns:
matrix (
numpy.ndarray) – A square symmetric 2D matrix of shape(num, num)(wherenumis the number of unique atom groups) containing the values of vector placed at the row/column of each atom-group pair.mapping (
numpy.ndarray) – A square 2D integer matrix of the same shape mapping each matrix cell back to the index in vector it came from (-1where no value exists).uqAtomGroups (
list) – The sorted list of unique atom groups, giving the row/column order of matrix.
- moleculekit.projections.metricdistance.reconstructContactMap(vector, mapping, truecontacts=None, plot=True, figsize=(7, 7), dpi=80, title=None, outfile=None, colors=None)#
Plots a given vector as a contact map
- Parameters:
mapping (
pd.DataFrame) – A pandas DataFrame which describes the dimensions of the projectiontruecontacts (
ndarray|list|None) – A 1D vector of true contactsplot (
bool) – To plot or not to plotfigsize (
tuple) – The size of the final plot in inchesdpi (
int) – Dots per inchoutfile (
str|None) – Path of file in which to save the plotcolors (
ndarray|list|None) – A vector of values or colors used to color the plotted contacts
- Returns:
cm – The input vector converted into a 2D numpy array
- Return type:
Examples
>>> reconstructContactMap(contacts, mapping) To use it with distances instead of contacts pass ones as the concat vector >>> reconstructContactMap(np.ones(dists.shape, dtype=bool), mapping, colors=dists)