Transformations

This module defines a class for identifying contacts.

class Transformation(*args)[source]

A class for storing a transformation matrix.

Either 4x4 transformation matrix, or rotation matrix and translation vector must be provided at instantiation.

apply(atoms)[source]

Apply transformation to atoms, see applyTransformation() for details.

getMatrix()[source]

Returns a copy of the 4x4 transformation matrix whose top left is rotation matrix and last column is translation vector.

getRotation()[source]

Returns rotation matrix.

getTranslation()[source]

Returns translation vector.

setRotation(rotation)[source]

Set rotation matrix.

setTranslation(translation)[source]

Set translation vector.

applyTransformation(transformation, atoms)[source]

Returns atoms after applying transformation. If atoms is a Atomic instance, it will be returned after transformation is applied to its active coordinate set. If atoms is an AtomPointer instance, transformation will be applied to the corresponding coordinate set in the associated AtomGroup.

alignCoordsets(atoms, weights=None)[source]

Returns atoms after superposing coordinate sets onto its active coordinate set. Transformations will be calculated for atoms and applied to its AtomGroup, when applicable. Optionally, atomic weights can be passed for weighted superposition.

calcRMSD(reference, target=None, weights=None)[source]

Returns root-mean-square deviation (RMSD) between reference and target coordinates.

In [1]: ens = loadEnsemble('p38_X-ray.ens.npz')

In [2]: ens.getRMSDs()
Out[2]: 
array([0.73474224, 0.73474973, 0.51355223, 0.57411515, 0.59391741,
       0.60322759, 0.72445578, 0.628798  , 0.75402069, 0.66617594,
       0.63392742, 0.47591756, 0.53089044, 0.47109431, 0.75351493,
       0.54259886, 0.73474224, 0.82507878, 0.48425924, 0.69131262,
       0.73487909, 0.68580592, 0.48126602, 0.68501669, 0.59701998,
       0.72760066, 0.64004617, 0.51273575, 0.50907201, 0.63983703,
       0.83831887, 0.79306135, 0.70736654, 0.8287824 , 1.20039598,
       0.609129  , 1.14924803, 0.71780499, 0.63011006, 0.74742698,
       0.57902768, 0.99502772, 0.94676434, 0.85553359, 0.98355747,
       0.57946817, 0.62940767, 0.65264184, 0.91158544, 0.8325053 ,
       0.95228633, 0.88591449, 0.84098934, 0.84540153, 1.11289113,
       0.70673519, 0.72968648, 0.87735911, 0.77511217, 0.82935735,
       0.88494269, 0.96281466, 0.64549003, 0.92997396, 1.08987621,
       0.42741603, 0.41880522, 0.48679376, 0.6552709 , 0.88968326,
       0.7337791 , 0.91618636, 0.97332704, 1.24280621, 0.58837217,
       0.65248909, 0.80794564, 0.79341602])

In [3]: calcRMSD(ens)
Out[3]: 
array([0.73474224, 0.73474973, 0.51355223, 0.57411515, 0.59391741,
       0.60322759, 0.72445578, 0.628798  , 0.75402069, 0.66617594,
       0.63392742, 0.47591756, 0.53089044, 0.47109431, 0.75351493,
       0.54259886, 0.73474224, 0.82507878, 0.48425924, 0.69131262,
       0.73487909, 0.68580592, 0.48126602, 0.68501669, 0.59701998,
       0.72760066, 0.64004617, 0.51273575, 0.50907201, 0.63983703,
       0.83831887, 0.79306135, 0.70736654, 0.8287824 , 1.20039598,
       0.609129  , 1.14924803, 0.71780499, 0.63011006, 0.74742698,
       0.57902768, 0.99502772, 0.94676434, 0.85553359, 0.98355747,
       0.57946817, 0.62940767, 0.65264184, 0.91158544, 0.8325053 ,
       0.95228633, 0.88591449, 0.84098934, 0.84540153, 1.11289113,
       0.70673519, 0.72968648, 0.87735911, 0.77511217, 0.82935735,
       0.88494269, 0.96281466, 0.64549003, 0.92997396, 1.08987621,
       0.42741603, 0.41880522, 0.48679376, 0.6552709 , 0.88968326,
       0.7337791 , 0.91618636, 0.97332704, 1.24280621, 0.58837217,
       0.65248909, 0.80794564, 0.79341602])

In [4]: calcRMSD(ens.getCoords(), ens.getCoordsets(), ens.getWeights())
Out[4]: 
array([0.73474224, 0.73474973, 0.51355223, 0.57411515, 0.59391741,
       0.60322759, 0.72445578, 0.628798  , 0.75402069, 0.66617594,
       0.63392742, 0.47591756, 0.53089044, 0.47109431, 0.75351493,
       0.54259886, 0.73474224, 0.82507878, 0.48425924, 0.69131262,
       0.73487909, 0.68580592, 0.48126602, 0.68501669, 0.59701998,
       0.72760066, 0.64004617, 0.51273575, 0.50907201, 0.63983703,
       0.83831887, 0.79306135, 0.70736654, 0.8287824 , 1.20039598,
       0.609129  , 1.14924803, 0.71780499, 0.63011006, 0.74742698,
       0.57902768, 0.99502772, 0.94676434, 0.85553359, 0.98355747,
       0.57946817, 0.62940767, 0.65264184, 0.91158544, 0.8325053 ,
       0.95228633, 0.88591449, 0.84098934, 0.84540153, 1.11289113,
       0.70673519, 0.72968648, 0.87735911, 0.77511217, 0.82935735,
       0.88494269, 0.96281466, 0.64549003, 0.92997396, 1.08987621,
       0.42741603, 0.41880522, 0.48679376, 0.6552709 , 0.88968326,
       0.7337791 , 0.91618636, 0.97332704, 1.24280621, 0.58837217,
       0.65248909, 0.80794564, 0.79341602])
calcTransformation(mobile, target, weights=None)[source]

Returns a Transformation instance which, when applied to the atoms in mobile, minimizes the weighted RMSD between mobile and target. mobile and target may be NumPy coordinate arrays, or Atomic instances, e.g. AtomGroup, Chain, or Selection.

superpose(mobile, target, weights=None)[source]

Returns mobile, after its RMSD minimizing superposition onto target, and the transformation that minimizes the RMSD.

moveAtoms(atoms, **kwargs)[source]

Move atoms to a new location or by an offset. This method will change the active coordinate set of the atoms. Note that only one of to or by keyword arguments is expected.

Move protein so that its centroid is at the origin, [0., 0., 0.]:

In [1]: from prody import *

In [2]: from numpy import ones, zeros

In [3]: protein = parsePDB('1ubi')

In [4]: calcCenter(protein).round(3)
Out[4]: array([30.173, 28.658, 15.262])

In [5]: moveAtoms(protein, to=zeros(3))

In [6]: calcCenter(protein).round(3)
Out[6]: array([ 0.,  0., -0.])

Move protein so that its mass center is at the origin:

In [7]: protein.setMasses(ones(len(protein)))

In [8]: protein.carbon.setMasses(12)

In [9]: protein.nitrogen.setMasses(14)

In [10]: protein.oxygen.setMasses(16)

In [11]: moveAtoms(protein, to=zeros(3), weights=protein.getMasses())

In [12]: calcCenter(protein, weights=protein.getMasses()).round(3)
Out[12]: array([-0., -0.,  0.])

Move protein so that centroid of Cα atoms is at the origin:

In [13]: moveAtoms(protein.ca, to=zeros(3), ag=True)

In [14]: calcCenter(protein).round(3)
Out[14]: array([-0.268, -0.343, -0.259])

In [15]: calcCenter(protein.ca).round(3)
Out[15]: array([ 0., -0., -0.])

Move protein by 10 A along each direction:

In [16]: moveAtoms(protein, by=ones(3) * 10)

In [17]: calcCenter(protein).round(3)
Out[17]: array([9.732, 9.657, 9.741])

In [18]: calcCenter(protein.ca).round(3)
Out[18]: array([10., 10., 10.])
Parameters:
  • by (numpy.ndarray) – an offset array with shape ([1,] 3) or (n_atoms, 3) or a transformation matrix with shape (4, 4)
  • to (numpy.ndarray) – a point array with shape ([1,] 3)
  • ag (bool) – when atoms is a AtomSubset, apply translation vector (to) or transformation matrix to the AtomGroup, default is False
  • weights (numpy.ndarray) – array of atomic weights with shape (n_atoms[, 1])

When to argument is passed, calcCenter() function is used to calculate centroid or mass center.

wrapAtoms(frame, unitcell=None, center=array([0., 0., 0.]))[source]

Wrap atoms into an image of the system simulated under periodic boundary conditions. When frame is a Frame, unitcell information will be retrieved automatically.

Note

This function will wrap all atoms into the specified periodic image, so covalent bonds will be broken.

Parameters:
  • frame (Frame, AtomGroup, numpy.ndarray) – a frame instance or a coordinate set
  • unitcell (numpy.ndarray) – orthorhombic unitcell array with shape (3,)
  • center (numpy.ndarray) – coordinates of the center of the wrapping cell, default is the origin of the Cartesian coordinate system
printRMSD(reference, target=None, weights=None, log=True, msg=None)[source]

Print RMSD to the screen. If target has multiple coordinate sets, minimum, maximum and mean RMSD values are printed. If log is True (default), RMSD is written to the standard error using package logger, otherwise standard output is used. When msg string is given, it is printed before the RMSD value. See also calcRMSD() function.