public class KabschAlignment extends Object
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
Constructor and Description 

KabschAlignment(IAtom[] al1,
IAtom[] al2)
Sets up variables for the alignment algorithm.

KabschAlignment(IAtom[] al1,
IAtom[] al2,
double[] wts)
Sets up variables for the alignment algorithm.

KabschAlignment(IAtomContainer ac1,
IAtomContainer ac2)
Sets up variables for the alignment algorithm.

KabschAlignment(IAtomContainer ac1,
IAtomContainer ac2,
double[] wts)
Sets up variables for the alignment algorithm.

Modifier and Type  Method and Description 

void 
align()
Perform an alignment.

javax.vecmath.Point3d 
getCenterOfMass()
Returns the center of mass for the first molecule or fragment used in the calculation.

double 
getRMSD()
Returns the RMSD from the alignment.

double[][] 
getRotationMatrix()
Returns the rotation matrix (u).

void 
rotateAtomContainer(IAtomContainer ac)
Rotates the
IAtomContainer coordinates by the rotation matrix. 
public KabschAlignment(IAtom[] al1, IAtom[] al2) throws CDKException
al1
 An array of IAtom
objectsal2
 An array of IAtom
objects. This array will have its coordinates rotated
so that the RMDS is minimized to the coordinates of the first arrayCDKException
 if the number of Atom's are not the same in the two arrayspublic KabschAlignment(IAtom[] al1, IAtom[] al2, double[] wts) throws CDKException
al1
 An array of IAtom
objectsal2
 An array of IAtom
objects. This array will have its coordinates rotated
so that the RMSD is minimized to the coordinates of the first arraywts
 A vector atom weights.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 arrayspublic KabschAlignment(IAtomContainer ac1, IAtomContainer ac2) throws CDKException
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 oneCDKException
 if the number of atom's are not the same in the two AtomContainer'spublic KabschAlignment(IAtomContainer ac1, IAtomContainer ac2, double[] wts) throws CDKException
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 onewts
 A vector atom weights.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.public void align()
public double getRMSD()
align()
public double[][] getRotationMatrix()
align()
public javax.vecmath.Point3d getCenterOfMass()
public void rotateAtomContainer(IAtomContainer ac)
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.ac
 The IAtomContainer
whose coordinates are to be rotatedCopyright © 2022. All rights reserved.