root / src / CalcRmsd.f90 @ 3
Historique | Voir | Annoter | Télécharger (6,84 ko)
| 1 | 1 | pfleura2 | |
|---|---|---|---|
| 2 | 1 | pfleura2 | ! This subroutine calculates RMSD (Root mean square deviation) using quaternions. |
| 3 | 1 | pfleura2 | ! It is baNatsed on the F90 routine bu E. Coutsias |
| 4 | 1 | pfleura2 | ! http://www.math.unm.edu/~vageli/homepage.html |
| 5 | 1 | pfleura2 | ! I (PFL) have just translated it, and I have changed the diagonalization |
| 6 | 1 | pfleura2 | ! subroutine. |
| 7 | 1 | pfleura2 | ! I also made some changes to make it suitable for Cart package. |
| 8 | 1 | pfleura2 | !---------------------------------------------------------------------- |
| 9 | 1 | pfleura2 | !---------------------------------------------------------------------- |
| 10 | 1 | pfleura2 | ! Copyright (C) 2004, 2005 Chaok Seok, Evangelos Coutsias and Ken Dill |
| 11 | 1 | pfleura2 | ! UCSF, Univeristy of New Mexico, Seoul National University |
| 12 | 1 | pfleura2 | ! Witten by Chaok Seok and Evangelos Coutsias 2004. |
| 13 | 1 | pfleura2 | |
| 14 | 1 | pfleura2 | ! This library is free software; you can redistribute it and/or |
| 15 | 1 | pfleura2 | ! modify it under the terms of the GNU Lesser General Public |
| 16 | 1 | pfleura2 | ! License as published by the Free Software Foundation; either |
| 17 | 1 | pfleura2 | ! version 2.1 of the License, or (at your option) any later version. |
| 18 | 1 | pfleura2 | ! |
| 19 | 1 | pfleura2 | |
| 20 | 1 | pfleura2 | ! This library is distributed in the hope that it will be useful, |
| 21 | 1 | pfleura2 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | 1 | pfleura2 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 23 | 1 | pfleura2 | ! Lesser General Public License for more details. |
| 24 | 1 | pfleura2 | ! |
| 25 | 1 | pfleura2 | |
| 26 | 1 | pfleura2 | ! You should have received a copy of the GNU Lesser General Public |
| 27 | 1 | pfleura2 | ! License along with this library; if not, write to the Free Software |
| 28 | 1 | pfleura2 | ! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 29 | 1 | pfleura2 | !---------------------------------------------------------------------------- |
| 30 | 1 | pfleura2 | |
| 31 | 1 | pfleura2 | subroutine CalcRmsd(Nat,x0,y0,z0, x2,y2,z2,U,rmsd,FRot,FAlign) |
| 32 | 1 | pfleura2 | !----------------------------------------------------------------------- |
| 33 | 1 | pfleura2 | ! This subroutine calculates the least square rmsd of two coordinate |
| 34 | 1 | pfleura2 | ! sets coord1(3,n) and coord2(3,n) using a method based on quaternion. |
| 35 | 1 | pfleura2 | ! It then calculate the rotation matrix U and the centers of coord, and uses |
| 36 | 1 | pfleura2 | ! them to align the two molecules. |
| 37 | 1 | pfleura2 | ! x0(Nat), y0(Nat), z0(Nat) are the coordinates of the reference geometry. |
| 38 | 1 | pfleura2 | ! x2(Nat), y2(Nat), z2(Nat) are the coordinates of the geometry which is to |
| 39 | 1 | pfleura2 | ! be aligned with the reference geometry. |
| 40 | 1 | pfleura2 | ! The rotation matrix U has INTENT(OUT) in subroutine rotation_matrix(...), |
| 41 | 1 | pfleura2 | ! which is called in this CalcRmsd(...). |
| 42 | 1 | pfleura2 | ! rmsd: the root mean square deviation and calculated in this subroutine |
| 43 | 1 | pfleura2 | ! CalcRmsd(...). |
| 44 | 1 | pfleura2 | ! FRot: if .TRUE. the rotation matrix is calculated. This is the matrix that rotates |
| 45 | 1 | pfleura2 | ! the first molecule onto the second one. |
| 46 | 1 | pfleura2 | ! FAlgin: if .TRUE. then the second molecule is aligned on the first one. |
| 47 | 1 | pfleura2 | !----------------------------------------------------------------------- |
| 48 | 1 | pfleura2 | |
| 49 | 1 | pfleura2 | use VarTypes |
| 50 | 1 | pfleura2 | |
| 51 | 1 | pfleura2 | IMPLICIT NONE |
| 52 | 1 | pfleura2 | |
| 53 | 1 | pfleura2 | INTEGER(KINT) :: Nat |
| 54 | 1 | pfleura2 | real(KREAL) :: x0(Nat),y0(Nat),z0(Nat) |
| 55 | 1 | pfleura2 | real(KREAL) :: x2(Nat),y2(Nat),z2(Nat) |
| 56 | 1 | pfleura2 | real(KREAL) :: U(3,3), rmsd |
| 57 | 1 | pfleura2 | LOGICAL FRot,FAlign,Debug |
| 58 | 1 | pfleura2 | |
| 59 | 1 | pfleura2 | REAL(KREAL) :: Coord1(3,Nat), Coord2(3,Nat) |
| 60 | 1 | pfleura2 | real(KREAL) :: x0c1,y0c1,z0c1, xc2,yc2,zc2 |
| 61 | 1 | pfleura2 | |
| 62 | 1 | pfleura2 | |
| 63 | 2 | pfleura2 | INTEGER(KINT) :: i, j, ia |
| 64 | 1 | pfleura2 | real(KREAL) :: x_norm, y_norm, lambda |
| 65 | 1 | pfleura2 | real(KREAL) :: Rmatrix(3,3) |
| 66 | 2 | pfleura2 | real(KREAL) :: S(4, 4) |
| 67 | 2 | pfleura2 | real(KREAL) :: EigVec(4, 4), EigVal(4) |
| 68 | 1 | pfleura2 | |
| 69 | 1 | pfleura2 | INTERFACE |
| 70 | 1 | pfleura2 | function valid(string) result (isValid) |
| 71 | 1 | pfleura2 | CHARACTER(*), intent(in) :: string |
| 72 | 1 | pfleura2 | logical :: isValid |
| 73 | 1 | pfleura2 | END function VALID |
| 74 | 1 | pfleura2 | END INTERFACE |
| 75 | 1 | pfleura2 | |
| 76 | 1 | pfleura2 | |
| 77 | 1 | pfleura2 | debug=valid('CalcRmsd').OR.valid('align').OR.valid('alignpartial')
|
| 78 | 1 | pfleura2 | |
| 79 | 1 | pfleura2 | ! calculate the barycenters, centroidal coordinates, and the norms |
| 80 | 1 | pfleura2 | x_norm = 0.0d0 |
| 81 | 1 | pfleura2 | y_norm = 0.0d0 |
| 82 | 1 | pfleura2 | x0c1=0. |
| 83 | 1 | pfleura2 | y0c1=0. |
| 84 | 1 | pfleura2 | z0c1=0. |
| 85 | 1 | pfleura2 | xc2=0. |
| 86 | 1 | pfleura2 | yc2=0. |
| 87 | 1 | pfleura2 | zc2=0. |
| 88 | 1 | pfleura2 | do ia=1,Nat |
| 89 | 1 | pfleura2 | x0c1=x0c1+x0(ia) |
| 90 | 1 | pfleura2 | xc2=xc2+x2(ia) |
| 91 | 1 | pfleura2 | y0c1=y0c1+y0(ia) |
| 92 | 1 | pfleura2 | yc2=yc2+y2(ia) |
| 93 | 1 | pfleura2 | z0c1=z0c1+z0(ia) |
| 94 | 1 | pfleura2 | zc2=zc2+z2(ia) |
| 95 | 1 | pfleura2 | ! if (debug) WRITE(*,'(A,I5,4(1X,F10.4))') 'ia...',ia,x0(ia), |
| 96 | 1 | pfleura2 | ! & x2(ia),x0c1,xc2 |
| 97 | 1 | pfleura2 | END DO |
| 98 | 1 | pfleura2 | x0c1=x0c1/dble(Nat) |
| 99 | 1 | pfleura2 | y0c1=y0c1/dble(Nat) |
| 100 | 1 | pfleura2 | z0c1=z0c1/dble(Nat) |
| 101 | 1 | pfleura2 | xc2=xc2/dble(Nat) |
| 102 | 1 | pfleura2 | yc2=yc2/dble(Nat) |
| 103 | 1 | pfleura2 | zc2=zc2/dble(Nat) |
| 104 | 1 | pfleura2 | |
| 105 | 1 | pfleura2 | IF (debug) WRITE(*,'(1X,A,3(1X,F10.4))') 'Center1',x0c1,y0c1,z0c1 |
| 106 | 1 | pfleura2 | IF (debug) WRITE(*,'(1X,A,3(1X,F10.4))') 'Center2',xc2,yc2,zc2 |
| 107 | 1 | pfleura2 | do i=1,Nat |
| 108 | 1 | pfleura2 | Coord1(1,i)=x0(i)-x0c1 |
| 109 | 1 | pfleura2 | Coord1(2,i)=y0(i)-y0c1 |
| 110 | 1 | pfleura2 | Coord1(3,i)=z0(i)-z0c1 |
| 111 | 1 | pfleura2 | Coord2(1,i)=x2(i)-xc2 |
| 112 | 1 | pfleura2 | Coord2(2,i)=y2(i)-yc2 |
| 113 | 1 | pfleura2 | Coord2(3,i)=z2(i)-zc2 |
| 114 | 1 | pfleura2 | x_norm=x_norm+Coord1(1,i)**2+Coord1(2,i)**2+Coord1(3,i)**2 |
| 115 | 1 | pfleura2 | y_norm=y_norm+Coord2(1,i)**2+Coord2(2,i)**2+Coord2(3,i)**2 |
| 116 | 1 | pfleura2 | end do |
| 117 | 1 | pfleura2 | |
| 118 | 1 | pfleura2 | IF (debug) THEN |
| 119 | 1 | pfleura2 | WRITE(*,*) "R matrix" |
| 120 | 1 | pfleura2 | DO I=1,3 |
| 121 | 1 | pfleura2 | WRITE(*,*) (RMatrix(I,j),j=1,3) |
| 122 | 1 | pfleura2 | END DO |
| 123 | 1 | pfleura2 | END IF |
| 124 | 1 | pfleura2 | |
| 125 | 1 | pfleura2 | ! calculate the R matrix |
| 126 | 1 | pfleura2 | do i = 1, 3 |
| 127 | 1 | pfleura2 | do j = 1, 3 |
| 128 | 1 | pfleura2 | Rmatrix(i,j)=0. |
| 129 | 1 | pfleura2 | do ia=1,Nat |
| 130 | 1 | pfleura2 | Rmatrix(i,j) = Rmatrix(i,j)+Coord1(i,ia)*Coord2(j,ia) |
| 131 | 1 | pfleura2 | END DO |
| 132 | 1 | pfleura2 | end do |
| 133 | 1 | pfleura2 | end do |
| 134 | 1 | pfleura2 | |
| 135 | 1 | pfleura2 | IF (debug) THEN |
| 136 | 1 | pfleura2 | WRITE(*,*) "R matrix" |
| 137 | 1 | pfleura2 | DO I=1,3 |
| 138 | 1 | pfleura2 | WRITE(*,*) (RMatrix(I,j),j=1,3) |
| 139 | 1 | pfleura2 | END DO |
| 140 | 1 | pfleura2 | END IF |
| 141 | 1 | pfleura2 | |
| 142 | 1 | pfleura2 | |
| 143 | 1 | pfleura2 | ! S matrix |
| 144 | 1 | pfleura2 | S(1, 1) = Rmatrix(1, 1) + Rmatrix(2, 2) + Rmatrix(3, 3) |
| 145 | 1 | pfleura2 | S(2, 1) = Rmatrix(2, 3) - Rmatrix(3, 2) |
| 146 | 1 | pfleura2 | S(3, 1) = Rmatrix(3, 1) - Rmatrix(1, 3) |
| 147 | 1 | pfleura2 | S(4, 1) = Rmatrix(1, 2) - Rmatrix(2, 1) |
| 148 | 1 | pfleura2 | |
| 149 | 1 | pfleura2 | S(1, 2) = S(2, 1) |
| 150 | 1 | pfleura2 | S(2, 2) = Rmatrix(1, 1) - Rmatrix(2, 2) - Rmatrix(3, 3) |
| 151 | 1 | pfleura2 | S(3, 2) = Rmatrix(1, 2) + Rmatrix(2, 1) |
| 152 | 1 | pfleura2 | S(4, 2) = Rmatrix(1, 3) + Rmatrix(3, 1) |
| 153 | 1 | pfleura2 | |
| 154 | 1 | pfleura2 | S(1, 3) = S(3, 1) |
| 155 | 1 | pfleura2 | S(2, 3) = S(3, 2) |
| 156 | 1 | pfleura2 | S(3, 3) =-Rmatrix(1, 1) + Rmatrix(2, 2) - Rmatrix(3, 3) |
| 157 | 1 | pfleura2 | S(4, 3) = Rmatrix(2, 3) + Rmatrix(3, 2) |
| 158 | 1 | pfleura2 | |
| 159 | 1 | pfleura2 | S(1, 4) = S(4, 1) |
| 160 | 1 | pfleura2 | S(2, 4) = S(4, 2) |
| 161 | 1 | pfleura2 | S(3, 4) = S(4, 3) |
| 162 | 1 | pfleura2 | S(4, 4) =-Rmatrix(1, 1) - Rmatrix(2, 2) + Rmatrix(3, 3) |
| 163 | 1 | pfleura2 | |
| 164 | 1 | pfleura2 | |
| 165 | 1 | pfleura2 | ! PFL : I use my usual Jacobi diagonalisation |
| 166 | 1 | pfleura2 | ! Calculate eigenvalues and eigenvectors, and |
| 167 | 1 | pfleura2 | ! take the maximum eigenvalue lambda and the corresponding eigenvector q. |
| 168 | 1 | pfleura2 | |
| 169 | 1 | pfleura2 | IF (debug) THEN |
| 170 | 1 | pfleura2 | WRITE(*,*) "S matrix" |
| 171 | 1 | pfleura2 | DO I=1,4 |
| 172 | 1 | pfleura2 | WRITE(*,*) (S(I,j),j=1,4) |
| 173 | 1 | pfleura2 | END DO |
| 174 | 1 | pfleura2 | END IF |
| 175 | 1 | pfleura2 | |
| 176 | 1 | pfleura2 | Call Jacobi(S,4,EigVal,EigVec,4) |
| 177 | 1 | pfleura2 | |
| 178 | 1 | pfleura2 | Call Trie(4,EigVal,EigVec,4) |
| 179 | 1 | pfleura2 | |
| 180 | 1 | pfleura2 | Lambda=EigVal(4) |
| 181 | 1 | pfleura2 | |
| 182 | 1 | pfleura2 | ! RMS Deviation |
| 183 | 1 | pfleura2 | rmsd=sqrt(max(0.0d0,((x_norm+y_norm)-2.0d0*lambda))/dble(Nat)) |
| 184 | 1 | pfleura2 | ! The subroutine rotation_matrix(...) constructs rotation matrix U as output |
| 185 | 1 | pfleura2 | ! from the input quaternion EigVec(1,4). |
| 186 | 1 | pfleura2 | if (FRot.OR.FAlign) Call rotation_matrix(EigVec(1,4),U) |
| 187 | 1 | pfleura2 | IF (FAlign) THEN |
| 188 | 1 | pfleura2 | DO I=1,Nat |
| 189 | 1 | pfleura2 | x2(i)=Coord2(1,i)*U(1,1)+Coord2(2,i)*U(2,1) & |
| 190 | 1 | pfleura2 | +Coord2(3,i)*U(3,1) +x0c1 |
| 191 | 1 | pfleura2 | y2(i)=Coord2(1,i)*U(1,2)+Coord2(2,i)*U(2,2) & |
| 192 | 1 | pfleura2 | +Coord2(3,i)*U(3,2) +y0c1 |
| 193 | 1 | pfleura2 | z2(i)=Coord2(1,i)*U(1,3)+Coord2(2,i)*U(2,3) & |
| 194 | 1 | pfleura2 | +Coord2(3,i)*U(3,3) +z0c1 |
| 195 | 1 | pfleura2 | END DO |
| 196 | 1 | pfleura2 | END IF |
| 197 | 1 | pfleura2 | |
| 198 | 1 | pfleura2 | END |