Life is Beautiful
https://linhaiting.wordpress.com
Mon, 11 Dec 2017 05:46:29 +0000enhourly1http://wordpress.com/https://s2.wp.com/i/buttonw-com.pngLife is Beautiful
https://linhaiting.wordpress.com
Disable secret boot for ASUS motherboard
https://linhaiting.wordpress.com/2016/10/18/disable-secret-boot-for-asus-motherboard/
https://linhaiting.wordpress.com/2016/10/18/disable-secret-boot-for-asus-motherboard/#respondTue, 18 Oct 2016 23:57:52 +0000http://linhaiting.wordpress.com/?p=881]]>Reference: http://www.tomshardware.com/answers/id-2225322/asus-uefi-boot-utility-secure-boot.html

How to shut down Secure Boot on ASUS UEFI MB. Credit to romirez for the last clue I needed: set Master password on Main Tab BIOS.
So here are the steps to disable Secure boot in ASUS BIOS; first make sure you have a clean formatted USB I just used an old 2gb and formatted to Fat32 label it PK Keys, put it in a USB port and boot up into BIOS.
Go to Boot tab page down to “Secure boot” select by hitting “Enter”
Should open “Secure Boot menu” should show Secure Boot state as “enabled” and Platform Key (PK) state as “loaded”
Page down to “OS Type” select “Windows UEFI”
Page Down to “Key Management” select by hitting “Enter” select 2nd entry “Save Secure Boot Keys” to USB. AFTER you have saved keys and confirmed on another computer that you have ALL 4 files: db, dbx, KEK, PK should be ~ 15 – 20 kb total.
Page down to PK Management select “Delete PK” look right to info panel and read it, hit “Enter”. This disables Secure Boot in ASUS BIOS.

Hit F10 and reboot into BIOS

Go to Boot tab page down to “Secure boot” select by hitting “Enter”
Should open “Secure Boot menu” should show Secure Boot state as “disabled” and Platform Key (PK) state as “unloaded”

]]>https://linhaiting.wordpress.com/2016/10/18/disable-secret-boot-for-asus-motherboard/feed/0linht122BitBucket Tutorial
https://linhaiting.wordpress.com/2016/10/06/bitbucket-tutorial/
https://linhaiting.wordpress.com/2016/10/06/bitbucket-tutorial/#respondThu, 06 Oct 2016 18:18:12 +0000http://linhaiting.wordpress.com/?p=790]]>

Set up Source Tree

Security Key Set Up
A. Source Tree Side:
Tools -> Create or Import SSH Keys -> Generate (PuTTY Key Generator) -> Copy the generated public key -> (Goto 1.B.a) ->(1.A.a) Save Public key and Save Private Key (to a local folder)
Tools -> Launch SSH Agent (Pageant) -> Add Key (Pageant Key List window) -> Load the saved private key (for listening SSH events)
B. Web Side: [User icon] -> Manage Account Bitbucket settings -> SSH Keys -> Add Key -> (1.B.a) Paste the public key and give it a Label as the name -> Add Key ->(Goto 1.A.a)

Create a repository
A. Web Side: create -> Under “Clone your new repo” copy the origin address something like “ssh://git@bitbucket.org/XXX/[RepoName].git” -> (Goto 2.B.a)B. Source Tree Side: (2.B.a) Clone/New Icon -> Paste Source Path/URL -> Set up Destination Path -> Clone (.git folder will be created in the destination folder)

Add, Submit, and Push Changes to the source
A. Source Tree Side:
Any modified or new files will show up in the “Working Copy Changes” -> Select all changes -> Add -> Commit-> write commit message -> Commit -> Push -> select branch
We can also create New Branch and push it to the source, or create new Label (mile stone) and push it to the source.

check file status, ignored files, if sourcetree is not tracking the changes you just made.

Console interface (MINGW32):

$ cd c:/workspace
$ ls
$ cd [RepoFolder]
$ ls
$ vi file.txt #edit a file
$ git add .
$ git status
$ touch file2.txt #create a new file
$ git add .
$ git status
$ git add -u
$ git status
$ git commit -m “This is a update”
$ git push origin [BranchName]
$ git branch master #may fail
$ git checkout master #current branch name is “master”
$ git push origin master #current branch name is “master”

$ git status –ignored
On branch master
Your branch is up-to-date with ‘origin/master’.
Ignored files:
(use “git add -f <file>…” to include in what will be committed)

$ git add *
The following paths are ignored by one of your .gitignore files:
buildcuda/Gipuma/x64/Release/scripts/makeIgnoredCommitted.txt
Use -f if you really want to add them.

$ git add -f *
How to do it recursively?

]]>https://linhaiting.wordpress.com/2016/10/06/bitbucket-tutorial/feed/0linht122ACCESS MASK AMBIGUOUS SYMBOL
https://linhaiting.wordpress.com/2016/09/02/access-mask-ambiguous-symbol/
https://linhaiting.wordpress.com/2016/09/02/access-mask-ambiguous-symbol/#respondFri, 02 Sep 2016 20:45:02 +0000http://linhaiting.wordpress.com/?p=783]]>This was a problem with having using namespace cv in a header, and then including windows headers. This pulled cv::ACCESS_MASK into global scope where it clashed with the already global Windows-defined ACCESS_MASK. (winn.h that has ACCESS_MASK conflict with the one defined in opencv.)

]]>https://linhaiting.wordpress.com/2016/09/02/access-mask-ambiguous-symbol/feed/0linht122The min/max problem in C++ and Windows
https://linhaiting.wordpress.com/2016/09/02/the-minmax-problem-in-c-and-windows/
https://linhaiting.wordpress.com/2016/09/02/the-minmax-problem-in-c-and-windows/#respondFri, 02 Sep 2016 17:33:52 +0000http://linhaiting.wordpress.com/?p=778]]>Read this: http://www.suodenjoki.dk/us/archive/2010/min-max.htm

]]>https://linhaiting.wordpress.com/2016/09/02/the-minmax-problem-in-c-and-windows/feed/0linht122FlyCapture2 exe running
https://linhaiting.wordpress.com/2016/08/29/flycapture2-exe-running/
https://linhaiting.wordpress.com/2016/08/29/flycapture2-exe-running/#respondMon, 29 Aug 2016 19:25:59 +0000http://linhaiting.wordpress.com/?p=772]]>FlyCapture2 Windows exe example running failed. Try to open the exe or the IDE as administrator. ]]>https://linhaiting.wordpress.com/2016/08/29/flycapture2-exe-running/feed/0linht122Ubuntu Install mve-texturing and Upgrade CMake, gcc & g++
https://linhaiting.wordpress.com/2016/06/01/ubuntu-install-mve-texturing-and-upgrade-cmake-gcc-g/
https://linhaiting.wordpress.com/2016/06/01/ubuntu-install-mve-texturing-and-upgrade-cmake-gcc-g/#respondWed, 01 Jun 2016 05:35:30 +0000http://linhaiting.wordpress.com/?p=539]]>Ubuntu 12.04 Install mve-texturing and Upgrade CMake, gcc & g++

xx:~$ cmake --version
CMake Error: Could not find CMAKE_ROOhttps://github.com/kripken/emscripten/issues/3189T !!!
CMake has most likely not been installed correctly.
Modules directory not found in
/usr/share/cmake-3.5
cmake version 3.5.2
xx:~$ export CMAKE_ROOT=/usr/share/cmake-3.5.2-Linux-x86_6/share/cmake-3.5
(adding this line to ~/.bashrc still does not help)
xx:~$ echo $CMAKE_ROOT

The above method does not work! cmake only runs inside the installed folder /usr/share/cmake-3.5.2-Linux-x86_6/bin without the CMAKE_ROOT error.

Compile it yourself (you need to remove the cmake first if you already have an old one installed by sudo apt-get remove cmake; sudo apt-get autoremove)Currently, the latest version is 3.2.2, the following instructions based on this version. You should therefore check this URL and adjust the file name accordingly.

sudo apt-get install build-essential
wget http://www.cmake.org/files/v3.2/cmake-3.2.2.tar.gz
tar xf cmake-3.2.2.tar.gz
cd cmake-3.2.2
./configure
make

Now you can have to choose an installation type to decide, I recommend installing with checkinstall, as this creates a DEB package.

$ git clone https://github.com/simonfuhrmann/mve.git
$ cd mve
$ make -j8

and umve:

$ cd apps/umve/
$ qmake && make -j8
$ ./umve

Do some modifications:
1. Add c++11 support to Makefile:

2. Modify the original file scrollimage.cc to clear the compiling error.

Q:Function maximumVIewportSize() is abstractly declared in /usr/include/qt4/QtGui/qabstractscrollarea.h, but never defined in concrete classes.

]]>https://linhaiting.wordpress.com/2016/06/01/ubuntu-install-mve-texturing-and-upgrade-cmake-gcc-g/feed/0linht122umve_error.pngumve_makefileumve_scrollimage.png11.4 Ubuntu Realtek Ethernet Fix
https://linhaiting.wordpress.com/2016/05/23/11-4-ubuntu-realtek-ethernet-fix/
https://linhaiting.wordpress.com/2016/05/23/11-4-ubuntu-realtek-ethernet-fix/#respondMon, 23 May 2016 13:31:18 +0000http://linhaiting.wordpress.com/?p=534]]>Original post is here. Copied as following:

Ubuntu 11.04 – the Natty Narwhal

A few weeks back I had my on board Realtek PCI express go out. I thought the onboard chip had fried so I installed another Ethernet card a ENLGA-1320 all was well until around 12:00pm today and then flop, no Internet connection from it either. So I started my decent into Google and finally got it working 5 hours later.

Here’s what didn’t work, but things you may try to get it up and working…for it seemed it was working for some just not for me.

Giving that forum credit by linking it, I will supply the info below:

Cold Start Instructions:

Shut down the machine

Unplug all cables from the tower(The power cable especially)

Hold the power button down for 30 seconds Then Release

Press the button a good time or two for good measure, wait 3 minutes.

Plug all cables back up and press the power button

Internet may or may not be active now.

This didn’t work for me, and if it did not for you lets continue on. This is another post located in the thread linked above, ones again I’ll sum it up. Open a terminal and do the following.

Check the model number of your Ethernet controller:

cd to the directory you downloaded the realtek driver:

:~$ cd Downloads

extract the files:

:~$ tar -xvf r8168-8.020.00.tar.bz2

cd to the newly extracted folder:

:~$ cd r8168-8.020.00

Auto compile the driver:

:~$ sudo ./autorun.sh

I highly doubt this is needed, because at this point my machine restarted its network connection on its own. However I will still include the optional commands to test the driver.

:~$ sudo rmmod r8169

:~$ sudo modprobe r8168

:~$sudo /etc/init.d/networking restart

At this point your network should be up and running, if not do not take the following next two steps.

Blacklist r8169:

:~$ sudo gedit /etc/modprobe.d/blacklist.conf

Append the following lines:

#Blacklist Realtek RTL8111/8169 gigabit driver

blacklist r8169

Save and quit

Update driver cache:

:~$ update-initramfs -u

Reboot, and see if correct driver has loaded:

$ lsmod | grep r816*

r8168 91629 0

Ok so if that worked for you cool, however for me I was ones again met with dismay and had to find another solution. This time around I’m desperate this is my development box, but also sort of mad and just going to do what it takes to get it up and running,

all I saw was lo listed and not eth0, again I was lost but I thought what the hey might as well continue on with the instructions that were provided by the link mentioned above.

Set up manually the /etc/network/interfaces in terminal type:

gksu gedit /etc/network/interfaces

I set up a static IP and even though All that was in the file was

auto lo

iface lo inet loopback

I still appended the following to that file:

auto eth0

iface eth0 inet static

address 192.168.1.10

netmask 255.255.255.0

gateway 192.168.0.1

Change eth0, address, and gateway to your own network values. Save the file and close it.

For the static IP It needed to find the domain name servers(DNS). This is the function of the /etc/resolv.conf file so you need to edit it. If the file doesn’t exist, create it.

In terminal:

gksu gedit /etc/resolv.conf

In that file place the following:

nameserver 208.67.222.222

nameserver 208.67.220.220

Replace these values with your own DNS values. I just used googles DNS

cd to the directory you downloaded the realtek driver:

:~$ cd Downloads

extract the files:

:~$ tar -xvf r8168-8.020.00.tar.bz2

cd to the newly extracted folder:

:~$ cd r8168-8.020.00

Auto compile the driver:

:~$ sudo ./autorun.sh

Now restart the network in terminal :

:~$ sudo /etc/init.d/networking restart

Ok at this point my pc fully black screened after resetting the network, it was on but no body was home. So I shut it down manually by holding the power button cut it back on and eth0 works perfect now, and that’s the built in one that went out on the mother board first.

Last edited by zxkelxz; January 7th, 2011 at 12:30 AM. Reason: Addition

]]>https://linhaiting.wordpress.com/2016/05/23/11-4-ubuntu-realtek-ethernet-fix/feed/0linht122%cd% vs %~dp0 in windows cmd
https://linhaiting.wordpress.com/2016/05/12/%cd-vs-dp0-in-windows-cmd/
https://linhaiting.wordpress.com/2016/05/12/%cd-vs-dp0-in-windows-cmd/#respondThu, 12 May 2016 23:34:10 +0000http://linhaiting.wordpress.com/?p=507]]>

(type in the cmd “Call /?” to check the meaning of %%~dp0)

They are not equivalent.

%cd% is available either to a batch file or at the command prompt and expands to the drive letter and path of the current directory (which can change e.g. by using the CD command)

%~dp0 is only available within a batch file and expands to the drive letter and path in which that batch file is located (which cannot change). It is obtained from %0 which is the batch file’s name.

An experiment like the following shows the difference

C:\>D:\dirshow.bat
this is %cd% C:\
this is %~dp0 D:\

« Last Edit: April 02, 2008, 09:58:10 AM by Dias de verano »

]]>https://linhaiting.wordpress.com/2016/05/12/%cd-vs-dp0-in-windows-cmd/feed/0linht122Run time error
https://linhaiting.wordpress.com/2016/03/17/run-time-error/
https://linhaiting.wordpress.com/2016/03/17/run-time-error/#respondThu, 17 Mar 2016 17:53:55 +0000http://linhaiting.wordpress.com/?p=476]]>The application was unable to start correctly (0xc000007b).

This is usually related to mixing 32bit application with 64bit dlls.

Use dependencywalker to check the dependencies and replace all dlls with correct version.

]]>https://linhaiting.wordpress.com/2016/03/17/run-time-error/feed/0linht122Molecular Distance Measures and Rotation Estimation
https://linhaiting.wordpress.com/2016/02/24/molecular-distance-measures-and-rotation-estimation/
https://linhaiting.wordpress.com/2016/02/24/molecular-distance-measures-and-rotation-estimation/#respondWed, 24 Feb 2016 16:21:26 +0000http://linhaiting.wordpress.com/?p=462]]>(See original post: http://cnx.org/contents/HV-RsdwL@23/Molecular-Distance-Measures)

Comparing Molecular Conformations

Molecules are not rigid. On the contrary, they are highly flexible objects, capable of changing shape dramatically through the rotation of dihedral angles. We need a measure to express how much a molecule changes going from one conformation to another, or alternatively, how different two conformations are from each other. Each distinct shape of a given molecule is called a conformation. Although one could conceivably compute the volume of the intersection of the alpha shapes for two conformations (see Molecular Shapes and Surfaces for an explanation of alpha shapes) to measure the shape change, this is prohibitively computationally expensive. Simpler measures of distance between conformations have been defined, based on variables such as the Cartesian coordinates for each atom, or the bond and torsion angles within the molecule. When working with Cartesian coordinates, one can represent a molecular conformation as a vector whose components are the Cartesian coordinates of the molecule’s atoms. Therefore, a conformation for a molecule with N atoms can be represented as a 3N-dimensional vector of real numbers.

RMSD and lRMSD

One of the most widely accepted difference measures for conformations of a molecule is least root mean square deviation (lRMSD). To calculate the RMSD of a pair of structures (say x and y), each structure must be represented as a 3N-length (assuming N atoms) vector of coordinates. The RMSD is the square root of the average of the squared distances between corresponding atoms of x and y. It is a measure of the average atomic displacement between the two conformations:

However, when molecular conformations are sampled from molecular dynamics or other forms of sampling, it is often the case that the molecule drifts away from the origin and rotates in an arbitrary way. The lRMSD distance aims at compensating for these facts by representing the minimum RMSD over all possible relative positions and orientations of the two conformations under consideration. Calculating the lRMSD consists of first finding an optimal alignment of the two structures, and then calculating their RMSD. Note that aligning two conformations may require both a translation and rotation. In other words, before computing the RMSD distance, it is necessary to remove the translation of the centroid of both conformations and to perform an “optimal alignment” or “optimal rotation” of them, since these two factors artificially increase the RMSD distance between them.

Finding the optimal rotation to minimize the RMSD between two point sets is a well-studied problem, and several algorithms exist. The Kabsch Algorithm [1][2], which is implemented in several molecular modeling packages, solves a matrix equation for the three dimensional rotation matrix corresponding to the optimal rotation. An alternative approach, discussed in detail after the matrix method, uses a compact representation of rotational transformations called quaternions [3][4]. Quaternions are currently the preferred representation for global rotation in calculating lRMSD, since they require less numbers to be stored and are easy to re-normalize. In contrast, re-normalization of orthonormal matrices is quite expensive and potentially numerically unstable. Both quaternions and their application to global alignment of conformations will be presented after the next section.

Optimal Alignment for lRMSD Using Rotation Matrices

This section presents a method for computing the optimal rotation between 2 datasets as an orthonormal rotation matrix. As stated earlier, this approach is slightly more numerically unstable (since guaranteeing the orthonormality of a matrix is harder than the unit length of a quaternion) and requires taking care of the special case when the resulting matrix may not be a proper rotation, as discussed below.

As stated earlier, the optimal alignment requires both a translation and a rotation. The translational part of the alignment is easy to calculate. It can be proven that the optimal alignment is obtained by translating one set so that its centroid coincides with the other set’s centroid (see section 2-C of [3] for proof). The centroid of a point set a is simply the average position of all its points:

We can then redefine each point in two sets A and B as a deviation from the centroid:

Given this notation relative to the centroid, we can explicitly set the centroids to be equal and proceed with the rotational part of the alignment.

One of the first references to the solution of this problem in matrix form is from Kabsch [1][2]. The Kabsch method uses Lagrange multipliers to solve a minimization problem to find the optimal rotation. Here, we present a slightly more intuitive method based on matrix algebra and properties, that achieves the same result. This formulation can be found in [4] and [5]. Imagine we wish to align two conformations composed of N atoms each, whose Cartesian coordinates are given by the vectors x and y. The main idea behind this approach is to find a 3×3 orthonormal matrix U such that the application of U to the atom positions of one of the data vectors, x, aligns it as best as possible with the other data vector, y, in the sense that the quantity to minimize is the distance d(Ux,y), where x and y are assumed to be centered, that is, both their centroids coincide at the origin (centering both conformations is the first step). Mathematically, this problem can be stated as the minimization of the following quantity:

When E is a minimum, the square root of its value becomes the least RMSD (lRMSD) between x and y. Being an orthonormal rotation matrix, U needs to satisfy the orthonormality property UUT=I , where I is the identity matrix. The orthonormality contraint ensures that the rows and columns are mutually orthogonal, and that their length (as vectors) is one. Any orthonormal matrix represents a rigid orientation (transformation) in space. The only problem with this approach as is, is that all orthonormal matrices encode a rigid transformation, but if the rows/columns of the matrix do not constitute a right handed system, then the rotation is said to be improper. In an improper rotation, one of the three directions may be “mirrored”. Fortunately, this case can be detected easily by computing the determinant of the matrix U, and if it is negative, correcting the matrix. Denoting Ux as x’, and moving the constant factor N to the left, the formula for the error becomes:

An alternative way to represent the two point sets, rather than a one-dimensional vector or as separate atom coordinates, is using two 3xN matrices (N atoms, 3 coordinates for each). Using this scheme, x is represented by the matrix X and y is represented by the matrix Y. Note that column 1≤i≤N in these matrices stands for point (atom) xi and yi, respectively. Using this new representation, we can write:

where X’=UX and Tr(A) stands for the trace of matrix A, the sum of its diagonal elements. It is easy to see that that the trace of the matrix to the right amounts precisely to the sum on the left (simply carrying out the multiplication of the first row/column should convince the reader). The right-hand side of the equation can be expanded into:

Which follows from the properties of the trace operator, namely: Tr(A+B)=Tr(A)+Tr(B), Tr(AB)=Tr(BA), Tr(AT)=Tr(A), and Tr(kA)=kTr(A). Furthermore, the first two terms in the expansion above represent the sum of the squares of the components xi and yi, so it can be rewritten as:

Note that the x components do not need to be primed (i.e., x’) since the rotation U around the origin does not change the length of xi. Note that the summation above does not depend on U, so minimizing E is equivalent to maximizing Tr(YTX’). For this reason, the rest of the discussion focuses on finding a proper rotation matrix U that maximizes Tr(YTX’). Remembering that X’=UX, the quantity to maximize is then Tr((YTU)X). From the property of the trace operator, this is equivalent to Tr((XYT)U). Since XYT is a square 3×3 matrix, it can be decomposed through the Singular Value Decomposition technique (SVD) into XYT=VSWT, where V and WT are the matrices of left and right eigenvectors (which are orthonormal matrices), respectively, and S is a diagonal 3×3 matrix containing the eigenvalues s1, s2, s3 in decreasing order. Again from the properties of the trace operator, we obtain that:

If we introduce the 3×3 matrix T as the product T=WTUV , we can rewrite the above expression as:

Since T is the product of orthonormal matrices, it is itself an orthonormal matrix and det(T)=+/-1. This means that the absolute value of each element of this matrix is no more than one, from where the last equality follows. It is obvious that the maximum value of the left hand side of the equation is reached when the diagonal elements of T are equal to 1, and since it is an orthonormal matrix, all other elements must be zero. This results in T=I. Moreover, since T=WTUV , we can write that WTUV=I, and because W and V are orthonormal, WWT=I and VVT=I. Multiplying WTUV by W to the left and VT to the right yields a solution for U:

Where V and WT are the matrices of left and right eigenvectors, respectively, of the covariance matrix C=XYT. This formula ensures that U is orthonormal (the reader should carry out the high-level matrix multiplication and verify this fact).

The only remaining detail to take care of is to make sure that U is a proper rotation, as discussed before. It could indeed happen that det(U)=-1 if its rows/columns do not make up a right-handed system. When this happens, we need to compromise between two goals: maximizing Tr(YTX’) and respecting the constraint that det(U)=+1. Therefore, we need to settle for the second largest value of Tr(YTX’). It is easy to see what the second largest value is; since:

then the second largest value occurs when T11=T22=+1 and T33=-1. Now, we have that T cannot be the identity matrix as before, but instead it has the lower-right corner set to -1. Now we finally have a unified way to represent the solution. If det(C)>0, T is the identity; otherwise, it has a -1 as its last element. Finally, these facts can be expressed in a single formula for the optimal rotation U by stating:

where d=sign(det(C)). In the light of the preceding derivation, all the facts that have been presented as a proof can be succinctly put as an algorithm for computing the optimal rotation to align two data sets x and y:

Optimal rotation

Build the 3xN matrices X and Y containing, for the sets x and y respectively, the coordinates for each of the N atoms after centering the atoms by subtracting the centroids.

Compute the covariance matrix C=XYT

Compute the SVD (Singular Value Decomposition) of C=VSWT

Compute d=sign(det(C))

Compute the optimal rotation U as

Optimal Alignment for lRMSD Using Quaternions

Another way of solving the optimal rotation for the purposes of computing the lRMSD between two conformations is to use quaternions. These provide a very compact way of representing rotations (only 4 numbers as compared to 9 or 16 for a rotation matrix) and are extremely easy to normalize after performing operations on them. Next, a general introduction to quaternions is given, and then they will be used to compute the optimal rotation between two point sets.

Introduction to Quaternions

Quaternions are an extension of complex numbers. Recall that complex numbers are numbers of the form a + bi, where a and b are real numbers and i is the canonical imaginary number, equal to the square root of -1. Quaternions add two more imaginary numbers, j and k. These numbers are related by the set of equalities in the following figure:

These equalities give rise to some unusual properties, especially with respect to multiplication.

Given this definition of i, j, and k, we can now define a quaternion.

Based on the definitions of i, j and k, we can also derive rules for addition and multiplication of quaternions. Assume we have two quaternions, p and q, defined as follows:

Addition of p and q is fairly intuitive:

The dot product and magnitude of a quaternion also closely resemble those operations for vectors. Note that a unit quaternion is a quaternion with magnitude 1 under this definition:

Multiplication, however, is not, due to the definitions of i, j, and k:

Quaternion multiplication also has two equivalent matrix forms which will become relevant later in the derivation of the alignment method:

These useful properties of quaternion multiplication can be derived easily using the matrix form for multiplication, or they can be proved by carrying out the products:

Quaternions and Three-Dimensional Rotations

A number of different methods exist for denoting rotations of rigid objects in three-dimensional space. These are introduced in a module on protein kinematics. Unit quaternions represent a rotation of an angle around an arbitrary axis. A rotation by the angle theta about an axis represented by the unit vector v = [x, y, z] is represented by a unit quaternion:

Like rotation matrices, quaternions may be composed with each other via multiplication. The major advantage of the quaternion representation is that it is more robust to numerical instability than orthonormal matrices. Numerical instability results from the fact that, because computers use a finite number of bits to represent real numbers, most real numbers are actually represented by the nearest number the computer is capable of representing. Over a series of floating point operations, the error caused by this inexact representation accumulates, quite rapidly in the case of repeated multiplications and divisions. In manipulating orthonormal transformation matrices, this can result in matrices that are no longer orthonormal, and therefore not valid rigid transformations. Finding the “nearest” orthonormal matrix to an arbitrary matrix is not a well-defined problem. Unit-length quaternions can accumulate the same kind of a numerical error as rotation matrices, but in the case of quaternions, finding the nearest unit-length quaternion to an arbitrary quaternion is well defined. Additionally, because quaternions correspond more directly to the axis-angle representation of three-dimensional rotations, it could be argued that they have a more intuitive interpretation than rotation matrices. Quaternions, with four parameters, are also more memory efficient than 3×3 matrices. For all of these reasons, quaternions are currently the preferred representation for three-dimensional rotations in most modeling applications.

Vectors can be represented as purely imaginary quaternions, that is, quaternions whose scalar component is 0. The quaternion corresponding to the vector v = [x, y, z] is q = xi + yj + zk.

We can perform rotation of a vector in quaternion notation as follows:

A quaternion rotation can be algebraically manipulated into a quaternion-derived rotation matrix. By simplifying the quaternion multiplications q p q*, they can be rewritten as a rotation matrix given an axis–angle representation:[citation needed]

where s and c are shorthand for sin θ and cos θ, respectively. So to get the rotation of a vector p about an arbitrary axis we get

Although care should be taken (due to degeneracy as the quaternion approaches the identity quaternion (1) or the sine of the angle approaches zero) the axis and angle can be extracted via:

Note that the θ equality holds only when qr is non-negative.

Alternatively, the rotation matrix can be expressed as

As with other schemes to apply rotations, the centre of rotation must be translated to the origin before the rotation is applied and translated back to its original position afterwards.

Optimal Alignment with Quaternions

The method presented here is from Berthold K. P. Holm, “Closed-form solution of absolute orientation using unit quaternions.” Journal of the Optical Society of America A, 4:629-642.

The alignment problem may be stated as follows:

We have two sets of points (atoms) A and B for which we wish to find an optimal alignment, defined as the alignment for which the root mean square difference between each point in A and its corresponding point in B is minimized.

We know which point in A corresponds to which point in B. This is necessary for any RMSD-based method.

As for the case of rotation matrices, the translational part of the alignment consists of making the centroids of the two data sets coincide. To find the optimal rotation using quaternions, recall that the dot product of two vectors is maximized when the vectors are in the same direction. The same is true when the vectors are represented as quaternions. Using this property, we can define a quantity that we want to maximize (proof here):

Equivalently, using the last property from the section “Introduction to quaternions”, we get:

Now, recall that quaternion multiplication can be represented by matrices, and that the quaterions a and b have a 0 real component:

Using these matrices, we can derive a new form for the objective function:

where:

The quaternion that maximizes this product is the eigenvector of N that corresponds to its most positive eigenvalue (proof here). The eigenvalues can be found by solving the following equation, which is quartic in lambda:

This quartic equation can be solved by a number of standard approaches. Finally, given the maximum eigenvalue lambda-max, the quaternion corresponding to the optimal rotation is the eigenvector v:

A closed-form solution to this equation for v can be found by applying techniques from linear algebra. One possible algorithm, based on constructing a matrix of cofactors, is presented in appendix A5 of the source paper [3].

In summary, the alignment algorithm works as follows:

Recalculate atom coordinates as displacements from the centroid of each molecule. The optimal translation superimposes the centroids.

Construct the matrix N based on matrices A and B for each atom.

Find the maximum eigenvalue by solving the quartic eigenvalue equation.

Find the eigenvector corresponding to this eigenvalue. This vector is the quaternion corresponding to the optimal rotation.

This method appears computationally intensive, but has the major advantage over other approaches of being a closed-form, unique solution.

Intramolecular Distance and Related Measures

RMSD and lRMSD are not ideally suited for all applications. For example, consider the case of a given conformation A, and a set S of other conformations generated by some means. The goal is to estimate which conformations in S are closest in potential energy to A, making the assumption that they will be the conformations most structurally similar to A. The lRMSD measure will find the conformations in which the overall average atomic displacement is least. The problem is that if the quantity of interest is the potential energy of conformations, not all atoms can be treated equally. Those on the outside of the protein can often move a fair amount without dramatically affecting the energy. In contrast, the core of the molecule tends to be more compact, and therefore a slight change in the relative positions of a pair of atoms could lead to overlap of the atoms, and therefore a completely infeasible structure and high potential energy. A class of distance measures and pseudo-measures based on intramolecular distances have been developed to address this shortcoming of RMSD-based measures.

Assume we wish to compare two conformations P and Q of a molecule with N atoms. Let pij be the distance between atom i and atom j in conformation P, and let qij be the same distance for conformation Q. Then the intramolecular distance is defined as

One of the main computational advantages of this class of approaches is that we do not have to compute the alignment between P and Q. On the other hand, for this metric we need to sum over a quadratic number of terms, whereas for RMSD the number of terms is linear in the number of atoms. Approximations can be made to speed up this computation, as shown in [7]. Also, the intramolecular distance measure given above, which is sometimes referred to as the dRMSD, is subject to the problem that pairs of atoms most distant from each other are the ones that contribute the greatest amount to their measured difference.

An interesting open problem is to come up with physically meaningful molecular distance metric that allows for fast nearest neighbor computations. This can be useful for, for example, clustering conformations. One proposed method is the contact distance. Contact distance requires constructing a contact map matrix for each conformation indicating which pairs of atoms are less than some threshold separation. The distance measure is then a measure of the difference of the contact maps.

Other distance measures attempt to weight each pair in the dRMSD based on how close the atoms are, with closer pairs given more weight, in keeping with the intuition that small changes in the relative positions of nearby atoms are more likely to result in collisions. One such measure is the normalized Holm and Sander Score.

This score is technically a pseudo-measure rather than a measure because it does not necessarily obey the triangle inequality.

The definition of distance measures remains an open problem. For reference on ongoing work, see articles that compare several methods, such as [5].

Recommended Reading: The first two papers are the original descriptions of the Kabsch Algorithm, and use rotations represented as orthonormal matrices to find the correct rotational transformation. Many software packages use this alignment method. The third and fourth papers use quaternions. The alignment method presented in the previous section comes from the third paper: