User:Compbiowes/Sandbox

Kabsch Algorithm
The Kabsch algorithm is a method for calculating the rotation that minimizes the RMSD (root mean squared deviation) between two sets of points. It is useful in graphics, and also in bioinformatics for comparing protein structures.

The algorithm calculates only the rotation matrix. Both sets of coordinates must be transformed to their centroid first.

The algorithm starts with two sets of paired points, P and Q. Each set of points can be represented as an N&times;3 matrix. The first row is the coordinates of the first point, the second row is the coordinates of the second point, the Nth row is the coordinates of the Nth point.


 * $$\begin{pmatrix}

x_1 & y_1 & z_1 \\ x_2 & y_2 & z_2 \\ \vdots & \vdots &  \vdots \\ x_N & y_N & z_N \end{pmatrix}$$

The algorithm works by calculating a covariance matrix, A of multiplied coordinates. In matrix notation,


 * $$ A = P^TQ $$

or, using summation notation,


 * $$ A_{ij} = \sum_k^N P_{ki} Q_{kj} $$.

It is possible to calculate the optimal rotation U based on the matrix formula $$ U = (A^t A)^{1/2}A^{-1} $$ but implementing a numerical solution to this formula becomes complicated when all special cases are accounted for.

If singular value decomposition (SVD) routines are available, the optimal rotation, U, can be calculated using the following simple algorithm.

First, calculate the SVD of the covariance matrix A


 * $$ A = VSW^T $$.

Next, decide whether we need to correct our rotation matrix to insure a right-handed coordinate system


 * $$ d = sign(det(A)) $$

Finally, calculate our optimal rotation matrix, U, as


 * $$ U = W \begin{pmatrix}

1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & d \end{pmatrix} V^T $$

This SVD algorithm is described in more detail at http://cnx.org/content/m11608/latest/

C source is available at http://www.personal.leeds.ac.uk/~bgy1mm/Bioinformatics/rmsd.html

A free PyMol plugin easily implementing Kabsch is Cealign.

Bohr - van Leeuwen Theorem
The Bohr - van Leeuwen Theorem concludes that, according to classical mechanics, a gas of charged particles (e.g. electrons) in an external magnetic field will not have a magnetic moment. According to the theorem, classical mechanics can not explain paramagnetism or diamagnetism. That is, paramagentism and diamagnetism are fundementally quantum mechanical phenomena.

The Bohr - van Leeuwen Theorem is typically mentioned in passing in upper level courses on electromagnetism and solid state physics. For example, it is discussed informally in section 34-6 of volume III (quantum mechanics) of "The Feynman Lectures on Physics".

Many features of the theorem were first proved by Niels Bohr in his dissertation in 1911. The theorem was presented in detail in the dissertation of Hendrika-Johanna van Leeuwen in 1919 under the guidance of Hendrik Lorentz and Paul Ehrenfest . H.-J. van Leeuwen gives a comprehensive summary of her dissertation in an article in "Journal de Physique et le Radium" (1921) entitled "Problèmes de la Théorie Électronique du Magnétisme" or, in English, "Problems of the Electronic Theory of Magnetism".

The Bohr - van Leeuwen Theorem was discussed in detail in a book published in 1934 entitled "Theory of Electric and Magnetic Susceptibilities" written by John Hasbrouck van Vleck. In that discussion, two proofs are presented. The first is based on a consideration of the dynamics of the particles and the second is based on more macroscopic thermodynamic arguments.

Proofs for Magnetic Dipoles
Introduction

While a more general proof may be possible, three specific cases are considered here. The first case is a magnetic dipole of constant magnitude that has a fixed (unchanging) orientation. The second and third cases are magnetic dipoles where the orientation changes to remain aligned either parallel or anti-parallel to the field lines of the external magnetic field. In paramagnetic and diamagnetic materials the dipoles are aligned parallel and anti-parallel to the field lines, respectively.

Background

The proofs considered here are based on the following principles.

The energy U of a magnetic dipole M in an external magnetic field B is given by



U = -\mathbf{M}\cdot\mathbf{B} = -(M_x B_x + M_y B_y + M_z B_z) $$

The dipole will only be stably levitated at points where the energy has a minimum. The energy can only have a minimum at points where the Laplacian of the energy is greater than zero. That is, where



\nabla^2 U = {\partial^2 U \over \partial x} + {\partial^2 U \over \partial y} + {\partial^2 U \over \partial z} > 0 $$

Finally, because both the divergence and the curl of a magnetic field are zero (in the absence of current or a changing electric field), the Laplacians of the individual components of a magnetic field are zero. That is



\nabla^2 B_x = 0, \nabla^2 B_y = 0, \nabla^2 B_z = 0 $$

This is proved at the very end of this article as it is central to understanding the overall proof.

Summary of Proofs

For a magnetic dipole of fixed orientation (and constant magnitude) the energy will be given by



U = -\mathbf{M}\cdot\mathbf{B} = -(M_x B_x + M_y B_y + M_z B_z) $$

where $$M_x$$, $$M_y$$ and $$M_z$$ are constant. In this case the Laplacian of the energy is always zero



\nabla^2 U = 0 $$

so the dipole can have neither an energy minimum or an energy maximum. That is, there is no point in free space where the dipole is either stable in all directions or unstable in all directions.

Magnetic dipoles aligned parallel or anti-parallel to an external field with the magnitude of the dipole proportional to the external field will correspond to paramagnetic and diamagnetic materials respectively. In these cases the energy will be given by



U = -\mathbf{M}\cdot\mathbf{B} = -k\mathbf{B}\cdot\mathbf{B} = -k (B_x^2 + B_y^2 + B_z^2) $$

Where k is constant greater than zero for paramagnetic materials and less than zero for diamagnetic materials.

In this case, it will be shown that



\nabla^2 (B_x^2 + B_y^2 + B_z^2) \geq 0 $$

which, combined with the constant k, shows that paramagnetic materials can have energy maxima but not energy minima and diamagnetic materials can have energy minima but not energy maxima. That is, paramagnetic materials can be unstable in all directions but not stable in all directions and diamagnetic materials can be stable in all directions but not unstable in all directions. Of course, both materials can have saddle points.

Finally, the magnetic dipole of a ferromagnetic material (a permanent magnet) that is aligned parallel or anti-parallel to a magnetic field will be given by



\mathbf{M} = k{\mathbf{B} \over |\mathbf{B}|} $$

so the energy will be given by



U = -\mathbf{M}\cdot\mathbf{B} = -k{\mathbf{B} \over |\mathbf{B}|}\cdot\mathbf{B} = -k{(B_x^2 + B_y^2 + B_z^2) \over (B_x^2 + B_y^2 + B_z^2)^{1/2}} = -k(B_x^2 + B_y^2 + B_z^2)^{1/2} $$

but this is just the square root of the energy for the paramagnetic and diamagnetic case discussed above and, since the square root function is monotonically increasing, any minimum or maximum in the paramagnetic and diamagnetic case will be a minimum or maximum here as well.

It should be noted, however, there are no known configurations of permanent magnets that stably levitate so there may be other reasons not discussed here why it is not possible to maintain permanent magnets in orientations anti-parallel to magnetic fields (at least not without rotational motion - see Levitron).

Detailed Proofs

Earnshaw's Theorem was originally formulated for electrostatics (point charges) to show that there is no stable configuration of a collection of point charges. The proofs presented here for individual dipoles should be generalizable to collections of magnetics dipoles because they are formulated in terms of energy which is additive. A rigorous treatment of this topic, however, is currently beyond the scope of this article.

Fixed Orientation Magnetic Dipole

It will be proved that at all points in free space



\nabla \cdot (\nabla U) = \nabla^2 U = {\partial^2 U \over \partial x} + {\partial^2 U \over \partial y} + {\partial^2 U \over \partial z} = 0 $$

The energy U of the magnetic dipole M in the external magnetic field B is given by



U = -\mathbf{M}\cdot\mathbf{B} = -(M_x B_x + M_y B_y + M_z B_z) $$

The Laplacian will be



\nabla^2 U = -[ {\partial^2 (M_x B_x + M_y B_y + M_z B_z) \over \partial x} + {\partial^2 (M_x B_x + M_y B_y + M_z B_z) \over \partial y} + {\partial^2 (M_x B_x + M_y B_y + M_z B_z) \over \partial z} ] $$

Expanding and rearranging the terms (and noting that the dipole M is constant) we have



\nabla^2 U = -( M_x({\partial^2 B_x \over \partial x} + {\partial^2 B_x \over \partial y} + {\partial^2 B_x \over \partial z}) + M_y({\partial^2 B_y \over \partial x} + {\partial^2 B_y \over \partial y} + {\partial^2 B_y \over \partial z}) + M_z({\partial^2 B_z \over \partial x} + {\partial^2 B_z \over \partial y} + {\partial^2 B_z \over \partial z}) ) $$

or



\nabla^2 U = -(M_x \nabla^2 B_x + M_y \nabla^2 B_y + M_z \nabla^2 B_z) $$

but the Laplacians of the individual components of a magnetic field are zero in free space (not counting electromagnetic radiation) so



\nabla^2 U = -(M_x 0 + M_y 0 + M_z 0) = 0 $$

which completes the proof.

Magnetic Dipole Aligned with External Field Lines

The case of a paramagnetic or diamagnetic dipole is considered first. The energy is given by



U = -k (B_x^2 + B_y^2 + B_z^2) $$

Expanding and rearranging terms,



\nabla^2 (B_x^2 + B_y^2 + B_z^2) = 2[ | \nabla B_x |^2 + | \nabla B_y |^2 + | \nabla B_z |^2 + B_x \nabla^2 B_x + B_y \nabla^2 B_y + B_z \nabla^2 B_z ] $$

but since the Laplacian of each individual component of the magnetic field is zero



\nabla^2 (B_x^2 + B_y^2 + B_z^2) = 2[ | \nabla B_x |^2 + | \nabla B_y |^2 + | \nabla B_z |^2 ] $$

and since the square of a magnitude is always positive



\nabla^2 (B_x^2 + B_y^2 + B_z^2) \geq 0 $$

As discussed above, this means that the Laplacian of the energy of a paramagnetic material can never be positive (no stable levitation) and the Laplacian of the energy of a diamagnetic material can never be negative (no instability in all directions).

Further, because the energy for a dipole of fixed magnitude aligned with the external field will be the square root of the energy above, the same analysis applies.

Laplacian of Individual Components of a Magnetic Field

It is proved here that the Laplacian of each individual component of a magnetic field is zero. This shows the need to invoke the properties of magnetic fields that the divergence of a magnetic field is always zero and the curl of a magnetic field is zero in free space (that is, in the absence of current or a changing electric field). See Maxwell's equations for a more detailed discussion of these properties of magnetic fields.

Consider the Laplacian of the x component of the magnetic field



\nabla^2 B_x = {\partial^2 B_x \over \partial x} + {\partial^2 B_x \over \partial y} + {\partial^2 B_x \over \partial z} = {\partial \over \partial x} {\partial \over \partial x} B_x + {\partial \over \partial y} {\partial \over \partial y} B_x + {\partial \over \partial z} {\partial \over \partial z} B_x $$

Because the curl of B is zero,



{\partial B_x \over \partial y} = {\partial B_y \over \partial x} $$

and



{\partial B_x \over \partial z} = {\partial B_z \over \partial x} $$

so we have



\nabla^2 B_x = {\partial \over \partial x} {\partial \over \partial x} B_x + {\partial \over \partial y} {\partial \over \partial x} B_y + {\partial \over \partial z} {\partial \over \partial x} B_z $$

but since $$B_x$$ is continuous the order of differentiation doesn't matter giving



\nabla^2 B_x = {\partial \over \partial x}( {\partial B_x \over \partial x} +  {\partial B_y \over \partial y} +  {\partial B_z \over \partial z} ) = {\partial \over \partial x}(\nabla \cdot \mathbf{B}) $$

The divergence of B is constant (zero, in fact) so



\nabla^2 B_x = {\partial \over \partial x}(\nabla \cdot \mathbf{B} = 0) = 0 $$

The Laplacian of the y component of the magnetic field $$B_y$$ field and the Laplacian of the z component of the magnetic field $$B_z$$ can be calculated analogously.