root / src / AlignPartial.f90 @ 2
Historique | Voir | Annoter | Télécharger (5,26 ko)
| 1 | 1 | pfleura2 | subroutine AlignPartial(na, x,y,z,x2,y2,z2,ListAt,U) |
|---|---|---|---|
| 2 | 1 | pfleura2 | !----------------------------------------------------------------------- |
| 3 | 1 | pfleura2 | ! This subroutine calculates the least square rmsd of two coordinate |
| 4 | 1 | pfleura2 | ! sets coord1(3,n) and coord2(3,n) using a method based on quaternion. |
| 5 | 1 | pfleura2 | ! It then calculate the rotation matrix U and the centers of coord, and uses |
| 6 | 1 | pfleura2 | ! them to align the two molecules. |
| 7 | 1 | pfleura2 | ! This new version does not use all atoms to calculate the RMSD and rotation matrix |
| 8 | 1 | pfleura2 | ! but only those which are 'true' in ListAt |
| 9 | 1 | pfleura2 | !----------------------------------------------------------------------- |
| 10 | 1 | pfleura2 | ! Input parameters: |
| 11 | 1 | pfleura2 | ! Na : number of atoms |
| 12 | 1 | pfleura2 | ! x,y,z : coordinates of the first geometry |
| 13 | 1 | pfleura2 | ! x2,y2,z2 : coordinates of the second geometry |
| 14 | 1 | pfleura2 | ! ListAt : Logical, T if this atom should be considered in the RMSD calc and |
| 15 | 1 | pfleura2 | ! alignment. |
| 16 | 1 | pfleura2 | ! Debug : True if additionnal printing is requiered |
| 17 | 1 | pfleura2 | ! |
| 18 | 1 | pfleura2 | ! output parameters: |
| 19 | 1 | pfleura2 | ! U : Real, (3x3) matrix for rotation |
| 20 | 1 | pfleura2 | ! Rmsd : Read, the rmsd |
| 21 | 1 | pfleura2 | ! x2,y2,z2 : coordinates of the second geometry ALIGNED to the first one |
| 22 | 1 | pfleura2 | !----------------------------------------------------------------------- |
| 23 | 1 | pfleura2 | |
| 24 | 1 | pfleura2 | Use VarTypes |
| 25 | 1 | pfleura2 | IMPLICIT NONE |
| 26 | 1 | pfleura2 | |
| 27 | 1 | pfleura2 | |
| 28 | 1 | pfleura2 | integer(KINT) :: na, NaT |
| 29 | 1 | pfleura2 | Real(KREAL) :: x(na),y(Na),z(Na) |
| 30 | 1 | pfleura2 | Real(KREAL) :: x2(Na),y2(Na),z2(Na) |
| 31 | 1 | pfleura2 | Real(KREAL) :: U(3,3), rmsd |
| 32 | 1 | pfleura2 | LOGICAL Debug, ListAt(Na) |
| 33 | 1 | pfleura2 | |
| 34 | 1 | pfleura2 | REAL(KREAL) :: Coord1(3,Na), Coord2(3,Na) |
| 35 | 1 | pfleura2 | Real(KREAL) :: xc1,yc1,zc1, xc2,yc2,zc2 |
| 36 | 1 | pfleura2 | |
| 37 | 1 | pfleura2 | |
| 38 | 2 | pfleura2 | integer(KINT) :: i, j, ia |
| 39 | 1 | pfleura2 | Real(KREAL) :: x_norm, y_norm, lambda |
| 40 | 1 | pfleura2 | Real(KREAL) :: Rmatrix(3,3) |
| 41 | 2 | pfleura2 | Real(KREAL) :: S(4, 4) |
| 42 | 2 | pfleura2 | Real(KREAL) :: EigVec(4, 4), EigVal(4) |
| 43 | 1 | pfleura2 | |
| 44 | 1 | pfleura2 | INTERFACE |
| 45 | 1 | pfleura2 | function valid(string) result (isValid) |
| 46 | 1 | pfleura2 | CHARACTER(*), intent(in) :: string |
| 47 | 1 | pfleura2 | logical :: isValid |
| 48 | 1 | pfleura2 | END function VALID |
| 49 | 1 | pfleura2 | END INTERFACE |
| 50 | 1 | pfleura2 | |
| 51 | 1 | pfleura2 | |
| 52 | 1 | pfleura2 | debug=valid('CalcRmsd').OR.valid('align').OR.valid('alignpartial')
|
| 53 | 1 | pfleura2 | |
| 54 | 1 | pfleura2 | ! calculate the barycenters, centroidal coordinates, and the norms |
| 55 | 1 | pfleura2 | x_norm = 0.0d0 |
| 56 | 1 | pfleura2 | y_norm = 0.0d0 |
| 57 | 1 | pfleura2 | xc1=0. |
| 58 | 1 | pfleura2 | yc1=0. |
| 59 | 1 | pfleura2 | zc1=0. |
| 60 | 1 | pfleura2 | xc2=0. |
| 61 | 1 | pfleura2 | yc2=0. |
| 62 | 1 | pfleura2 | zc2=0. |
| 63 | 1 | pfleura2 | |
| 64 | 1 | pfleura2 | if (debug) THEN |
| 65 | 1 | pfleura2 | WRITE(*,*) "DBG AlignPartial X2,Y2,Z2 before align" |
| 66 | 1 | pfleura2 | DO Ia=1,na |
| 67 | 1 | pfleura2 | WRITE(*,*) x2(ia),y2(ia),z2(ia) |
| 68 | 1 | pfleura2 | END DO |
| 69 | 1 | pfleura2 | END IF |
| 70 | 1 | pfleura2 | |
| 71 | 1 | pfleura2 | NAt=0 |
| 72 | 1 | pfleura2 | do ia=1,na |
| 73 | 1 | pfleura2 | IF (listat(ia)) THEN |
| 74 | 1 | pfleura2 | Nat=NAt+1 |
| 75 | 1 | pfleura2 | xc1=xc1+x(ia) |
| 76 | 1 | pfleura2 | xc2=xc2+x2(ia) |
| 77 | 1 | pfleura2 | yc1=yc1+y(ia) |
| 78 | 1 | pfleura2 | yc2=yc2+y2(ia) |
| 79 | 1 | pfleura2 | zc1=zc1+z(ia) |
| 80 | 1 | pfleura2 | zc2=zc2+z2(ia) |
| 81 | 1 | pfleura2 | ! if (debug) WRITE(*,'(A,I5,4(1X,F10.4))') 'ia...',ia,x(ia), |
| 82 | 1 | pfleura2 | ! & x2(ia),xc1,xc2 |
| 83 | 1 | pfleura2 | END IF |
| 84 | 1 | pfleura2 | END DO |
| 85 | 1 | pfleura2 | |
| 86 | 1 | pfleura2 | if (Nat.EQ.0) THEN |
| 87 | 1 | pfleura2 | WRITE(*,*) "ERROR, AlignPartial: ListAt is empty :-)" |
| 88 | 1 | pfleura2 | END IF |
| 89 | 1 | pfleura2 | xc1=xc1/dble(nat) |
| 90 | 1 | pfleura2 | yc1=yc1/dble(nat) |
| 91 | 1 | pfleura2 | zc1=zc1/dble(nat) |
| 92 | 1 | pfleura2 | xc2=xc2/dble(nat) |
| 93 | 1 | pfleura2 | yc2=yc2/dble(nat) |
| 94 | 1 | pfleura2 | zc2=zc2/dble(nat) |
| 95 | 1 | pfleura2 | |
| 96 | 1 | pfleura2 | IF (Debug) WRITE(*,*) 'Found :', Nat, ' atoms' |
| 97 | 1 | pfleura2 | IF (debug) WRITE(*,*) (ListAt(I),I=1,Na) |
| 98 | 1 | pfleura2 | IF (debug) WRITE(*,'(1X,A,3(1X,F10.4))') 'Center1',xc1,yc1,zc1 |
| 99 | 1 | pfleura2 | IF (debug) WRITE(*,'(1X,A,3(1X,F10.4))') 'Center2',xc2,yc2,zc2 |
| 100 | 1 | pfleura2 | do i=1,na |
| 101 | 1 | pfleura2 | Coord1(1,i)=x(i)-xc1 |
| 102 | 1 | pfleura2 | Coord1(2,i)=y(i)-yc1 |
| 103 | 1 | pfleura2 | Coord1(3,i)=z(i)-zc1 |
| 104 | 1 | pfleura2 | Coord2(1,i)=x2(i)-xc2 |
| 105 | 1 | pfleura2 | Coord2(2,i)=y2(i)-yc2 |
| 106 | 1 | pfleura2 | Coord2(3,i)=z2(i)-zc2 |
| 107 | 1 | pfleura2 | IF (ListAt(I)) THEN |
| 108 | 1 | pfleura2 | x_norm=x_norm+Coord1(1,i)**2+Coord1(2,i)**2+Coord1(3,i)**2 |
| 109 | 1 | pfleura2 | y_norm=y_norm+Coord2(1,i)**2+Coord2(2,i)**2+Coord2(3,i)**2 |
| 110 | 1 | pfleura2 | END IF |
| 111 | 1 | pfleura2 | end do |
| 112 | 1 | pfleura2 | |
| 113 | 1 | pfleura2 | ! calculate the R matrix |
| 114 | 1 | pfleura2 | do i = 1, 3 |
| 115 | 1 | pfleura2 | do j = 1, 3 |
| 116 | 1 | pfleura2 | Rmatrix(i,j)=0. |
| 117 | 1 | pfleura2 | do ia=1,na |
| 118 | 1 | pfleura2 | If (ListAt(ia)) Rmatrix(i,j) = Rmatrix(i,j)+Coord1(i,ia)*Coord2(j,ia) |
| 119 | 1 | pfleura2 | END DO |
| 120 | 1 | pfleura2 | end do |
| 121 | 1 | pfleura2 | end do |
| 122 | 1 | pfleura2 | |
| 123 | 1 | pfleura2 | IF (debug) THEN |
| 124 | 1 | pfleura2 | WRITE(*,*) "R matrix" |
| 125 | 1 | pfleura2 | DO I=1,3 |
| 126 | 1 | pfleura2 | WRITE(*,*) (RMatrix(I,j),j=1,3) |
| 127 | 1 | pfleura2 | END DO |
| 128 | 1 | pfleura2 | END IF |
| 129 | 1 | pfleura2 | |
| 130 | 1 | pfleura2 | |
| 131 | 1 | pfleura2 | ! S matrix |
| 132 | 1 | pfleura2 | S(1, 1) = Rmatrix(1, 1) + Rmatrix(2, 2) + Rmatrix(3, 3) |
| 133 | 1 | pfleura2 | S(2, 1) = Rmatrix(2, 3) - Rmatrix(3, 2) |
| 134 | 1 | pfleura2 | S(3, 1) = Rmatrix(3, 1) - Rmatrix(1, 3) |
| 135 | 1 | pfleura2 | S(4, 1) = Rmatrix(1, 2) - Rmatrix(2, 1) |
| 136 | 1 | pfleura2 | |
| 137 | 1 | pfleura2 | S(1, 2) = S(2, 1) |
| 138 | 1 | pfleura2 | S(2, 2) = Rmatrix(1, 1) - Rmatrix(2, 2) - Rmatrix(3, 3) |
| 139 | 1 | pfleura2 | S(3, 2) = Rmatrix(1, 2) + Rmatrix(2, 1) |
| 140 | 1 | pfleura2 | S(4, 2) = Rmatrix(1, 3) + Rmatrix(3, 1) |
| 141 | 1 | pfleura2 | |
| 142 | 1 | pfleura2 | S(1, 3) = S(3, 1) |
| 143 | 1 | pfleura2 | S(2, 3) = S(3, 2) |
| 144 | 1 | pfleura2 | S(3, 3) =-Rmatrix(1, 1) + Rmatrix(2, 2) - Rmatrix(3, 3) |
| 145 | 1 | pfleura2 | S(4, 3) = Rmatrix(2, 3) + Rmatrix(3, 2) |
| 146 | 1 | pfleura2 | |
| 147 | 1 | pfleura2 | S(1, 4) = S(4, 1) |
| 148 | 1 | pfleura2 | S(2, 4) = S(4, 2) |
| 149 | 1 | pfleura2 | S(3, 4) = S(4, 3) |
| 150 | 1 | pfleura2 | S(4, 4) =-Rmatrix(1, 1) - Rmatrix(2, 2) + Rmatrix(3, 3) |
| 151 | 1 | pfleura2 | |
| 152 | 1 | pfleura2 | |
| 153 | 1 | pfleura2 | ! PFL : I use my usual Jacobi diagonalisation |
| 154 | 1 | pfleura2 | ! Calculate eigenvalues and eigenvectors, and |
| 155 | 1 | pfleura2 | ! take the maximum eigenvalue lambda and the corresponding eigenvector q. |
| 156 | 1 | pfleura2 | |
| 157 | 1 | pfleura2 | IF (debug) THEN |
| 158 | 1 | pfleura2 | WRITE(*,*) "S matrix" |
| 159 | 1 | pfleura2 | DO I=1,4 |
| 160 | 1 | pfleura2 | WRITE(*,*) (S(I,j),j=1,4) |
| 161 | 1 | pfleura2 | END DO |
| 162 | 1 | pfleura2 | END IF |
| 163 | 1 | pfleura2 | |
| 164 | 1 | pfleura2 | Call Jacobi(S,4,EigVal,EigVec,4) |
| 165 | 1 | pfleura2 | |
| 166 | 1 | pfleura2 | Call Trie(4,EigVal,EigVec,4) |
| 167 | 1 | pfleura2 | |
| 168 | 1 | pfleura2 | Lambda=EigVal(4) |
| 169 | 1 | pfleura2 | |
| 170 | 1 | pfleura2 | ! RMS Deviation |
| 171 | 1 | pfleura2 | rmsd=sqrt(max(0.0d0,((x_norm+y_norm)-2.0d0*lambda))/dble(nat)) |
| 172 | 1 | pfleura2 | if (debug) WRITE(*,*) "AlignPartial rmsd:",rmsd |
| 173 | 1 | pfleura2 | Call rotation_matrix(EigVec(1,4),U) |
| 174 | 1 | pfleura2 | |
| 175 | 1 | pfleura2 | |
| 176 | 1 | pfleura2 | IF (debug) THEN |
| 177 | 1 | pfleura2 | WRITE(*,*) "U matrix" |
| 178 | 1 | pfleura2 | DO I=1,3 |
| 179 | 1 | pfleura2 | WRITE(*,*) (U(I,j),j=1,3) |
| 180 | 1 | pfleura2 | END DO |
| 181 | 1 | pfleura2 | END IF |
| 182 | 1 | pfleura2 | |
| 183 | 1 | pfleura2 | DO I=1,na |
| 184 | 1 | pfleura2 | x2(i)=Coord2(1,i)*U(1,1)+Coord2(2,i)*U(2,1) + Coord2(3,i)*U(3,1) +xc1 |
| 185 | 1 | pfleura2 | y2(i)=Coord2(1,i)*U(1,2)+Coord2(2,i)*U(2,2) + Coord2(3,i)*U(3,2) +yc1 |
| 186 | 1 | pfleura2 | z2(i)=Coord2(1,i)*U(1,3)+Coord2(2,i)*U(2,3) + Coord2(3,i)*U(3,3) +zc1 |
| 187 | 1 | pfleura2 | END DO |
| 188 | 1 | pfleura2 | |
| 189 | 1 | pfleura2 | if (debug) THEN |
| 190 | 1 | pfleura2 | WRITE(*,*) "DBG AlignPartial X2,Y2,Z2 after align" |
| 191 | 1 | pfleura2 | DO Ia=1,na |
| 192 | 1 | pfleura2 | WRITE(*,*) x2(ia),y2(ia),z2(ia) |
| 193 | 1 | pfleura2 | END DO |
| 194 | 1 | pfleura2 | END IF |
| 195 | 1 | pfleura2 | |
| 196 | 1 | pfleura2 | |
| 197 | 1 | pfleura2 | END subroutine AlignPartial |