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.74354467, 0.74177711, 0.51452365, 0.57683171, 0.59351512,
       0.60326603, 0.72442463, 0.62888165, 0.75408408, 0.66629   ,
       0.63495136, 0.4759429 , 0.53120074, 0.4715239 , 0.75473416,
       0.54244114, 0.74354467, 0.82549383, 0.48591313, 0.69182138,
       0.73675363, 0.69019142, 0.48220989, 0.68723799, 0.59729582,
       0.73109411, 0.64283447, 0.5154584 , 0.50789232, 0.6396268 ,
       0.83721704, 0.79361416, 0.70873424, 0.82886869, 1.20057159,
       0.60931426, 1.14960267, 0.71798048, 0.63006386, 0.74770913,
       0.57971084, 0.99552692, 0.94704321, 0.8556385 , 0.98372194,
       0.57996381, 0.6316779 , 0.65283986, 1.03949721, 0.83261935,
       0.9538368 , 0.88620135, 0.84155565, 0.84619283, 1.11300172,
       0.7067304 , 0.7298382 , 0.87744088, 0.77526691, 0.82946276,
       0.88502934, 0.96286777, 0.64562836, 0.93211344, 1.09081052,
       0.42740444, 0.42044091, 0.48651594, 0.66881305, 0.88965909,
       0.73610848, 0.91680663, 0.97386864, 1.24281269, 0.58818171,
       0.65482108, 0.80890973, 0.7943292 ])

In [3]: calcRMSD(ens)
Out[3]: 
array([0.74354467, 0.74177711, 0.51452365, 0.57683171, 0.59351512,
       0.60326603, 0.72442463, 0.62888165, 0.75408408, 0.66629   ,
       0.63495136, 0.4759429 , 0.53120074, 0.4715239 , 0.75473416,
       0.54244114, 0.74354467, 0.82549383, 0.48591313, 0.69182138,
       0.73675363, 0.69019142, 0.48220989, 0.68723799, 0.59729582,
       0.73109411, 0.64283447, 0.5154584 , 0.50789232, 0.6396268 ,
       0.83721704, 0.79361416, 0.70873424, 0.82886869, 1.20057159,
       0.60931426, 1.14960267, 0.71798048, 0.63006386, 0.74770913,
       0.57971084, 0.99552692, 0.94704321, 0.8556385 , 0.98372194,
       0.57996381, 0.6316779 , 0.65283986, 1.03949721, 0.83261935,
       0.9538368 , 0.88620135, 0.84155565, 0.84619283, 1.11300172,
       0.7067304 , 0.7298382 , 0.87744088, 0.77526691, 0.82946276,
       0.88502934, 0.96286777, 0.64562836, 0.93211344, 1.09081052,
       0.42740444, 0.42044091, 0.48651594, 0.66881305, 0.88965909,
       0.73610848, 0.91680663, 0.97386864, 1.24281269, 0.58818171,
       0.65482108, 0.80890973, 0.7943292 ])

In [4]: calcRMSD(ens.getCoords(), ens.getCoordsets(), ens.getWeights())
Out[4]: 
array([0.74354467, 0.74177711, 0.51452365, 0.57683171, 0.59351512,
       0.60326603, 0.72442463, 0.62888165, 0.75408408, 0.66629   ,
       0.63495136, 0.4759429 , 0.53120074, 0.4715239 , 0.75473416,
       0.54244114, 0.74354467, 0.82549383, 0.48591313, 0.69182138,
       0.73675363, 0.69019142, 0.48220989, 0.68723799, 0.59729582,
       0.73109411, 0.64283447, 0.5154584 , 0.50789232, 0.6396268 ,
       0.83721704, 0.79361416, 0.70873424, 0.82886869, 1.20057159,
       0.60931426, 1.14960267, 0.71798048, 0.63006386, 0.74770913,
       0.57971084, 0.99552692, 0.94704321, 0.8556385 , 0.98372194,
       0.57996381, 0.6316779 , 0.65283986, 1.03949721, 0.83261935,
       0.9538368 , 0.88620135, 0.84155565, 0.84619283, 1.11300172,
       0.7067304 , 0.7298382 , 0.87744088, 0.77526691, 0.82946276,
       0.88502934, 0.96286777, 0.64562836, 0.93211344, 1.09081052,
       0.42740444, 0.42044091, 0.48651594, 0.66881305, 0.88965909,
       0.73610848, 0.91680663, 0.97386864, 1.24281269, 0.58818171,
       0.65482108, 0.80890973, 0.7943292 ])
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.