Class KabschAlignment

java.lang.Object
org.openscience.cdk.geometry.alignment.KabschAlignment

public class KabschAlignment extends Object
Aligns two structures to minimize the RMSD using the Kabsch algorithm.

This class is an implementation of the Kabsch algorithm ([Kabsch, W.. Acta Cryst.. 1976. A32], [Kabsch, W.. Acta Cryst.. 1978. A34]) and evaluates the optimal rotation matrix (U) to minimize the RMSD between the two structures. Since the algorithm assumes that the number of points are the same in the two structures it is the job of the caller to pass the proper number of atoms from the two structures. Constructors which take whole AtomContainer's are provided but they should have the same number of atoms. The algorithm allows for the use of atom weightings and by default all points are given a weight of 1.0

Example usage can be:

 AtomContainer ac1, ac2;

 try {
    KabschAlignment sa = new KabschAlignment(ac1.getAtoms(),ac2.getAtoms());
    sa.align();
    System.out.println(sa.getRMSD());
 } catch (CDKException e){}
 
In many cases, molecules will be aligned based on some common substructure. In this case the center of masses calculated during alignment refer to these substructures rather than the whole molecules. To superimpose the molecules for display, the second molecule must be rotated and translated by calling rotateAtomContainer. However, since this will also translate the second molecule, the first molecule should also be translated to the center of mass of the substructure specified for this molecule. This center of mass can be obtained by a call to getCenterOfMass and then manually translating the coordinates. Thus an example would be
 AtomContainer ac1, ac2;  // whole molecules
 Atom[] a1, a2;           // some subset of atoms from the two molecules
 KabschAlignment sa;

 try {
    sa = new KabschAlignment(a1,a2);
    sa.align();
 } catch (CDKException e){}

 Point3d cm1 = sa.getCenterOfMass();
 for (int i = 0; i < ac1.getAtomCount(); i++) {
    Atom a = ac1.getAtomAt(i);
    a.setX3d( a.getPoint3d().x - cm1.x );
    a.setY3d( a.getPoint3d().y - cm1.y );
    a.setY3d( a.getPoint3d().z - cm1.z );
 }
 sa.rotateAtomContainer(ac2);

 // display the two AtomContainer's
Author:
Rajarshi Guha
Dictionary pointer(s):
alignmentKabsch in the Blue Obelisk Chemoinformatics Dictionary [blue-obelisk:alignmentKabsch]
Source code:
main
Created on:
2004-12-11
  • Constructor Details

    • KabschAlignment

      public KabschAlignment(IAtom[] al1, IAtom[] al2) throws CDKException
      Sets up variables for the alignment algorithm. The algorithm allows for atom weighting and the default is 1.0 for all atoms.
      Parameters:
      al1 - An array of IAtom objects
      al2 - An array of IAtom objects. This array will have its coordinates rotated so that the RMDS is minimized to the coordinates of the first array
      Throws:
      CDKException - if the number of Atom's are not the same in the two arrays
    • KabschAlignment

      public KabschAlignment(IAtom[] al1, IAtom[] al2, double[] wts) throws CDKException
      Sets up variables for the alignment algorithm.
      Parameters:
      al1 - An array of IAtom objects
      al2 - An array of IAtom objects. This array will have its coordinates rotated so that the RMSD is minimized to the coordinates of the first array
      wts - A vector atom weights.
      Throws:
      CDKException - if the number of Atom's are not the same in the two arrays or length of the weight vector is not the same as the Atom arrays
    • KabschAlignment

      public KabschAlignment(IAtomContainer ac1, IAtomContainer ac2) throws CDKException
      Sets up variables for the alignment algorithm. The algorithm allows for atom weighting and the default is 1.0 for all atoms.
      Parameters:
      ac1 - An IAtomContainer
      ac2 - An IAtomContainer. This AtomContainer will have its coordinates rotated so that the RMDS is minimized to the coordinates of the first one
      Throws:
      CDKException - if the number of atom's are not the same in the two AtomContainer's
    • KabschAlignment

      public KabschAlignment(IAtomContainer ac1, IAtomContainer ac2, double[] wts) throws CDKException
      Sets up variables for the alignment algorithm.
      Parameters:
      ac1 - An IAtomContainer
      ac2 - An IAtomContainer. This AtomContainer will have its coordinates rotated so that the RMDS is minimized to the coordinates of the first one
      wts - A vector atom weights.
      Throws:
      CDKException - if the number of atom's are not the same in the two AtomContainer's or length of the weight vector is not the same as number of atoms.
  • Method Details

    • align

      public void align()
      Perform an alignment. This method aligns to set of atoms which should have been specified prior to this call
    • getRMSD

      public double getRMSD()
      Returns the RMSD from the alignment. If align() has not been called the return value is -1.0
      Returns:
      The RMSD for this alignment
      See Also:
    • getRotationMatrix

      public double[][] getRotationMatrix()
      Returns the rotation matrix (u).
      Returns:
      A double[][] representing the rotation matrix
      See Also:
    • getCenterOfMass

      public javax.vecmath.Point3d getCenterOfMass()
      Returns the center of mass for the first molecule or fragment used in the calculation. This method is useful when using this class to align the coordinates of two molecules and them displaying them superimposed. Since the center of mass used during the alignment may not be based on the whole molecule (in general common substructures are aligned), when preparing molecules for display the first molecule should be translated to the center of mass. Then displaying the first molecule and the rotated version of the second one will result in superimposed structures.
      Returns:
      A Point3d containing the coordinates of the center of mass
    • rotateAtomContainer

      public void rotateAtomContainer(IAtomContainer ac)
      Rotates the IAtomContainer coordinates by the rotation matrix. In general if you align a subset of atoms in a AtomContainer this function can be applied to the whole AtomContainer to rotate all atoms. This should be called with the second AtomContainer (or Atom[]) that was passed to the constructor. Note that the AtomContainer coordinates also get translated such that the center of mass of the original fragment used to calculate the alignment is at the origin.
      Parameters:
      ac - The IAtomContainer whose coordinates are to be rotated