root / src / Calc_baker_allGeomF.f90 @ 2
Historique | Voir | Annoter | Télécharger (7,37 ko)
| 1 | 1 | pfleura2 | SUBROUTINE Calc_baker_allGeomF() |
|---|---|---|---|
| 2 | 1 | pfleura2 | ! |
| 3 | 1 | pfleura2 | ! This subroutine analyses a geometry to construct the baker |
| 4 | 1 | pfleura2 | ! delocalized internal coordinates |
| 5 | 1 | pfleura2 | ! v1.0 |
| 6 | 1 | pfleura2 | ! We use only one geometry |
| 7 | 1 | pfleura2 | ! |
| 8 | 1 | pfleura2 | Use Path_module, only : Pi,a0,BMat_BakerT,Nat,NCoord,XyzGeomI,NGeomI,UMatF, & |
| 9 | 1 | pfleura2 | NPrim,BTransInvF,IntCoordI,Coordinate,CurrentCoord, & |
| 10 | 1 | pfleura2 | ScanCoord,BprimT,BBT,BBT_inv,XprimitiveF,Symmetry_elimination, & |
| 11 | 1 | pfleura2 | NgeomF,XyzGeomF |
| 12 | 1 | pfleura2 | ! BMat_BakerT(3*Nat,NCoord), NCoord=3*Nat or NFree=3*Nat-6-Symmetry_elimination |
| 13 | 1 | pfleura2 | ! depending upon the coordinate choice. IntCoordI(NGeomI,NCoord) where |
| 14 | 1 | pfleura2 | ! UMatF(NGeomI,NPrim,NCoord), NCoord number of vectors in UMat matrix, i.e. NCoord |
| 15 | 1 | pfleura2 | ! Baker coordinates. NPrim is the number of primitive internal coordinates. |
| 16 | 1 | pfleura2 | |
| 17 | 1 | pfleura2 | Use Io_module |
| 18 | 1 | pfleura2 | IMPLICIT NONE |
| 19 | 1 | pfleura2 | |
| 20 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: Geom(:,:) !(3,Nat) |
| 21 | 1 | pfleura2 | ! NPrim is the number of primitive coordinates and NCoord is the number |
| 22 | 1 | pfleura2 | ! of internal coordinates. BMat is actually (NPrim,3*Nat). |
| 23 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: GMat(:,:) !(NPrim,NPrim) |
| 24 | 1 | pfleura2 | ! EigVec(..) contains ALL eigevectors of BMat times BprimT, NOT only Baker Coordinate vectors. |
| 25 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: EigVec(:,:), EigVal(:) ! EigVec(NPrim,NPrim) |
| 26 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: x(:), y(:), z(:) |
| 27 | 1 | pfleura2 | REAL(KREAL), ALLOCATABLE :: XPrimRef(:) ! NPrim |
| 28 | 1 | pfleura2 | INTEGER(KINT) :: IGeom |
| 29 | 1 | pfleura2 | |
| 30 | 1 | pfleura2 | |
| 31 | 2 | pfleura2 | INTEGER(KINT) :: I, J, K |
| 32 | 1 | pfleura2 | |
| 33 | 1 | pfleura2 | |
| 34 | 2 | pfleura2 | LOGICAL :: debug |
| 35 | 1 | pfleura2 | LOGICAL :: DebugPFL |
| 36 | 1 | pfleura2 | |
| 37 | 1 | pfleura2 | INTERFACE |
| 38 | 1 | pfleura2 | function valid(string) result (isValid) |
| 39 | 1 | pfleura2 | CHARACTER(*), intent(in) :: string |
| 40 | 1 | pfleura2 | logical :: isValid |
| 41 | 1 | pfleura2 | END function VALID |
| 42 | 1 | pfleura2 | |
| 43 | 1 | pfleura2 | FUNCTION angle(v1x,v1y,v1z,norm1,v2x,v2y,v2z,norm2) |
| 44 | 1 | pfleura2 | use Path_module, only : Pi,KINT, KREAL |
| 45 | 1 | pfleura2 | real(KREAL) :: v1x,v1y,v1z,norm1 |
| 46 | 1 | pfleura2 | real(KREAL) :: v2x,v2y,v2z,norm2 |
| 47 | 1 | pfleura2 | real(KREAL) :: angle |
| 48 | 1 | pfleura2 | END FUNCTION ANGLE |
| 49 | 1 | pfleura2 | |
| 50 | 1 | pfleura2 | FUNCTION angle_d(v1x,v1y,v1z,norm1,v2x,v2y,v2z,norm2,v3x,v3y,v3z,norm3) |
| 51 | 1 | pfleura2 | use Path_module, only : Pi,KINT, KREAL |
| 52 | 1 | pfleura2 | real(KREAL) :: v1x,v1y,v1z,norm1 |
| 53 | 1 | pfleura2 | real(KREAL) :: v2x,v2y,v2z,norm2 |
| 54 | 1 | pfleura2 | real(KREAL) :: v3x,v3y,v3z,norm3 |
| 55 | 1 | pfleura2 | real(KREAL) :: angle_d,ca,sa |
| 56 | 1 | pfleura2 | END FUNCTION ANGLE_D |
| 57 | 1 | pfleura2 | |
| 58 | 1 | pfleura2 | |
| 59 | 1 | pfleura2 | |
| 60 | 1 | pfleura2 | SUBROUTINE Calc_Xprim(nat,x,y,z,Coordinate,NPrim,XPrimitive,XPrimRef) |
| 61 | 1 | pfleura2 | ! |
| 62 | 1 | pfleura2 | ! This subroutine uses the description of a list of Coordinates |
| 63 | 1 | pfleura2 | ! to compute the values of the coordinates for a given geometry. |
| 64 | 1 | pfleura2 | ! |
| 65 | 1 | pfleura2 | !!!!!!!!!! |
| 66 | 1 | pfleura2 | ! Input: |
| 67 | 1 | pfleura2 | ! Na: INTEGER, Number of atoms |
| 68 | 1 | pfleura2 | ! x,y,z(Na): REAL, cartesian coordinates of the considered geometry |
| 69 | 1 | pfleura2 | ! Coordinate (Pointer(ListCoord)): description of the wanted coordiantes |
| 70 | 1 | pfleura2 | ! NPrim, INTEGER: Number of coordinates to compute |
| 71 | 1 | pfleura2 | ! |
| 72 | 1 | pfleura2 | ! Optional: XPrimRef(NPrim) REAL: array that contains coordinates values for |
| 73 | 1 | pfleura2 | ! a former geometry. Useful for Dihedral angles evolution... |
| 74 | 1 | pfleura2 | |
| 75 | 1 | pfleura2 | !!!!!!!!!!! |
| 76 | 1 | pfleura2 | ! Output: |
| 77 | 1 | pfleura2 | ! XPrimimite(NPrim) REAL: array that will contain the values of the coordinates |
| 78 | 1 | pfleura2 | ! |
| 79 | 1 | pfleura2 | !!!!!!!!! |
| 80 | 1 | pfleura2 | |
| 81 | 1 | pfleura2 | Use VarTypes |
| 82 | 1 | pfleura2 | Use Io_module |
| 83 | 1 | pfleura2 | Use Path_module, only : pi |
| 84 | 1 | pfleura2 | |
| 85 | 1 | pfleura2 | IMPLICIT NONE |
| 86 | 1 | pfleura2 | |
| 87 | 1 | pfleura2 | Type (ListCoord), POINTER :: Coordinate |
| 88 | 1 | pfleura2 | INTEGER(KINT), INTENT(IN) :: Nat,NPrim |
| 89 | 1 | pfleura2 | REAL(KREAL), INTENT(IN) :: x(Nat), y(Nat), z(Nat) |
| 90 | 1 | pfleura2 | REAL(KREAL), INTENT(IN), OPTIONAL :: XPrimRef(NPrim) |
| 91 | 1 | pfleura2 | REAL(KREAL), INTENT(OUT) :: XPrimitive(NPrim) |
| 92 | 1 | pfleura2 | |
| 93 | 1 | pfleura2 | END SUBROUTINE CALC_XPRIM |
| 94 | 1 | pfleura2 | END INTERFACE |
| 95 | 1 | pfleura2 | |
| 96 | 1 | pfleura2 | |
| 97 | 1 | pfleura2 | |
| 98 | 1 | pfleura2 | |
| 99 | 1 | pfleura2 | debug=valid("Calc_baker_allGeomF")
|
| 100 | 1 | pfleura2 | debugPFL=valid("bakerPFL")
|
| 101 | 1 | pfleura2 | if (debug) WRITE(*,*) '============ Entering Calc_baker_allGeomF =============' |
| 102 | 1 | pfleura2 | |
| 103 | 1 | pfleura2 | ALLOCATE(Geom(3,Nat),x(Nat),y(Nat),z(Nat)) |
| 104 | 1 | pfleura2 | ALLOCATE(XPrimRef(NPrim)) |
| 105 | 1 | pfleura2 | |
| 106 | 1 | pfleura2 | ! Now calculating values of all primitive bonds for all final geometries: |
| 107 | 1 | pfleura2 | DO IGeom=1, NGeomF |
| 108 | 1 | pfleura2 | x(1:Nat) = XyzGeomF(IGeom,1,1:Nat) |
| 109 | 1 | pfleura2 | y(1:Nat) = XyzGeomF(IGeom,2,1:Nat) |
| 110 | 1 | pfleura2 | z(1:Nat) = XyzGeomF(IGeom,3,1:Nat) |
| 111 | 1 | pfleura2 | XPrimREf=XPrimitiveF(IGeom,:) |
| 112 | 1 | pfleura2 | Call Calc_XPrim(nat,x,y,z,Coordinate,NPrim,XPrimitiveF(IGeom,:),XPrimRef) |
| 113 | 1 | pfleura2 | END DO ! matches DO IGeom=1, NGeomF |
| 114 | 1 | pfleura2 | |
| 115 | 1 | pfleura2 | ALLOCATE(BprimT(3*Nat,NPrim)) |
| 116 | 1 | pfleura2 | ALLOCATE(Gmat(NPrim,NPrim)) |
| 117 | 1 | pfleura2 | ALLOCATE(EigVal(NPrim),EigVec(NPrim,NPrim)) |
| 118 | 1 | pfleura2 | ALLOCATE(BBT(NCoord,NCoord)) |
| 119 | 1 | pfleura2 | ALLOCATE(BBT_inv(NCoord,NCoord)) |
| 120 | 1 | pfleura2 | BTransInvF = 0.d0 |
| 121 | 1 | pfleura2 | |
| 122 | 1 | pfleura2 | DO IGeom=1, NGeomF |
| 123 | 1 | pfleura2 | Geom(1,:)=XyzGeomF(IGeom,1,1:Nat) ! XyzGeomI(NGeomI,3,Nat) |
| 124 | 1 | pfleura2 | Geom(2,:)=XyzGeomF(IGeom,2,1:Nat) |
| 125 | 1 | pfleura2 | Geom(3,:)=XyzGeomF(IGeom,3,1:Nat) |
| 126 | 1 | pfleura2 | |
| 127 | 1 | pfleura2 | BprimT=0.d0 |
| 128 | 1 | pfleura2 | ScanCoord=>Coordinate |
| 129 | 1 | pfleura2 | I=0 |
| 130 | 1 | pfleura2 | DO WHILE (Associated(ScanCoord%next)) |
| 131 | 1 | pfleura2 | I=I+1 |
| 132 | 1 | pfleura2 | SELECT CASE (ScanCoord%Type) |
| 133 | 1 | pfleura2 | CASE ('BOND')
|
| 134 | 1 | pfleura2 | CALL CONSTRAINTS_BONDLENGTH_DER(Nat,ScanCoord%at1,ScanCoord%AT2, & |
| 135 | 1 | pfleura2 | Geom,BprimT(1,I)) |
| 136 | 1 | pfleura2 | CASE ('ANGLE')
|
| 137 | 1 | pfleura2 | CALL CONSTRAINTS_BONDANGLE_DER(Nat,ScanCoord%At1,ScanCoord%AT2, & |
| 138 | 1 | pfleura2 | ScanCoord%At3,Geom,BprimT(1,I)) |
| 139 | 1 | pfleura2 | CASE ('DIHEDRAL')
|
| 140 | 1 | pfleura2 | CALL CONSTRAINTS_TORSION_DER2(Nat,ScanCoord%At1,ScanCoord%AT2, & |
| 141 | 1 | pfleura2 | ScanCoord%At3,ScanCoord%At4,Geom,BprimT(1,I)) |
| 142 | 1 | pfleura2 | END SELECT |
| 143 | 1 | pfleura2 | ScanCoord => ScanCoord%next |
| 144 | 1 | pfleura2 | END DO |
| 145 | 1 | pfleura2 | |
| 146 | 1 | pfleura2 | ! BprimT(3*Nat,NPrim) |
| 147 | 1 | pfleura2 | ! We now compute G=B(BT) matrix |
| 148 | 1 | pfleura2 | GMat=0.d0 |
| 149 | 1 | pfleura2 | DO I=1,NPrim |
| 150 | 1 | pfleura2 | DO J=1,3*Nat |
| 151 | 1 | pfleura2 | GMat(:,I)=Gmat(:,I)+BprimT(J,:)*BprimT(J,I) !*1.d0/mass(atome(int(K/3.d0))) |
| 152 | 1 | pfleura2 | END DO |
| 153 | 1 | pfleura2 | END DO |
| 154 | 1 | pfleura2 | |
| 155 | 1 | pfleura2 | ! Diagonalize G |
| 156 | 1 | pfleura2 | EigVal=0.d0 |
| 157 | 1 | pfleura2 | EigVec=0.d0 |
| 158 | 1 | pfleura2 | Call Jacobi(GMat,NPrim,EigVal,EigVec,NPrim) |
| 159 | 1 | pfleura2 | Call Trie(NPrim,EigVal,EigVec,NPrim) |
| 160 | 1 | pfleura2 | DO I=1,NPrim |
| 161 | 1 | pfleura2 | !WRITE(*,'(1X,"Vector ",I3,": e=",F8.3)') I,EigVal(i) |
| 162 | 1 | pfleura2 | !WRITE(*,'(20(1X,F8.4))') EigVec(1:min(20,NPrim),I) |
| 163 | 1 | pfleura2 | END DO |
| 164 | 1 | pfleura2 | |
| 165 | 1 | pfleura2 | ! UMatF is nonredundant vector set, i.e. set of eigenvectors of BB^T |
| 166 | 1 | pfleura2 | ! corresponding to eigenvalues > zero. |
| 167 | 1 | pfleura2 | ! BMat_BakerT(3*Nat,NCoord), allocated in Path.f90, |
| 168 | 1 | pfleura2 | ! NCoord=3*Nat-6 |
| 169 | 1 | pfleura2 | BMat_BakerT = 0.d0 |
| 170 | 1 | pfleura2 | J=0 |
| 171 | 1 | pfleura2 | DO I=1,NPrim |
| 172 | 1 | pfleura2 | IF (abs(eigval(I))>=1e-6) THEN |
| 173 | 1 | pfleura2 | J=J+1 |
| 174 | 1 | pfleura2 | DO K=1,NPrim |
| 175 | 1 | pfleura2 | ! BprimT is transpose of B^prim. |
| 176 | 1 | pfleura2 | ! B = UMatF^T B^prim, B^T = (B^prim)^T UMatF |
| 177 | 1 | pfleura2 | BMat_BakerT(:,J)=BMat_BakerT(:,J)+BprimT(:,K)*Eigvec(K,I) |
| 178 | 1 | pfleura2 | END DO |
| 179 | 1 | pfleura2 | IF(J .GT. 3*Nat-6) THEN |
| 180 | 1 | pfleura2 | WRITE(*,*) 'Number of vectors in Eigvec with eigval .GT. 1e-6(=UMatF) (=' & |
| 181 | 1 | pfleura2 | ,J,') exceeded 3*Nat-6=',3*Nat-6, & |
| 182 | 1 | pfleura2 | 'Stopping the calculation.' |
| 183 | 1 | pfleura2 | STOP |
| 184 | 1 | pfleura2 | END IF |
| 185 | 1 | pfleura2 | UMatF(IGeom,:,J) = Eigvec(:,I) |
| 186 | 1 | pfleura2 | END IF |
| 187 | 1 | pfleura2 | END DO |
| 188 | 1 | pfleura2 | |
| 189 | 1 | pfleura2 | !!!!!!!!!!!!!!!!!!!! |
| 190 | 1 | pfleura2 | ! |
| 191 | 1 | pfleura2 | ! Debug purposes |
| 192 | 1 | pfleura2 | ! |
| 193 | 1 | pfleura2 | if (debugPFL) THEN |
| 194 | 1 | pfleura2 | UMatF(IGeom,:,:)=0. |
| 195 | 1 | pfleura2 | DO J=1,3*Nat-6 |
| 196 | 1 | pfleura2 | UMatF(IGeom,J,J)=1. |
| 197 | 1 | pfleura2 | END DO |
| 198 | 1 | pfleura2 | END IF |
| 199 | 1 | pfleura2 | |
| 200 | 1 | pfleura2 | |
| 201 | 1 | pfleura2 | !DO I=1, NPrim ! This loop is not needed because we already have IntCoordF |
| 202 | 1 | pfleura2 | ! from interpolation. |
| 203 | 1 | pfleura2 | ! Transpose of UMatF is needed below, that is why UMatF(IGeom,I,:). |
| 204 | 1 | pfleura2 | ! IntCoordF(IGeom,:) = IntCoordF(IGeom,:) + UMat(IGeom,I,:)*XprimitiveF(IGeom,I) |
| 205 | 1 | pfleura2 | !END DO |
| 206 | 1 | pfleura2 | |
| 207 | 1 | pfleura2 | ! Calculation of BTransInvF starts here: |
| 208 | 1 | pfleura2 | ! Calculation of BBT(3*Nat-6,3*Nat-6)=BB^T: |
| 209 | 1 | pfleura2 | ! BMat_BakerT(3*Nat,NCoord) is Transpose of B = UMatF^TB^prim |
| 210 | 1 | pfleura2 | |
| 211 | 1 | pfleura2 | BBT = 0.d0 |
| 212 | 1 | pfleura2 | DO I=1, NCoord |
| 213 | 1 | pfleura2 | DO J=1, 3*Nat |
| 214 | 1 | pfleura2 | ! BBT(:,I) forms BB^T |
| 215 | 1 | pfleura2 | BBT(:,I) = BBT(:,I) + BMat_BakerT(J,:)*BMat_BakerT(J,I) |
| 216 | 1 | pfleura2 | END DO |
| 217 | 1 | pfleura2 | END DO |
| 218 | 1 | pfleura2 | |
| 219 | 1 | pfleura2 | Call GenInv(NCoord,BBT,BBT_inv,NCoord) ! GenInv is in Mat_util.f90 |
| 220 | 1 | pfleura2 | |
| 221 | 1 | pfleura2 | ! Calculation of (B^T)^-1 = (BB^T)^-1B: |
| 222 | 1 | pfleura2 | DO I=1, 3*Nat |
| 223 | 1 | pfleura2 | DO J=1, NCoord |
| 224 | 1 | pfleura2 | BTransInvF(IGeom,:,I) = BTransInvF(IGeom,:,I) + BBT_inv(:,J)*BMat_BakerT(I,J) |
| 225 | 1 | pfleura2 | END DO |
| 226 | 1 | pfleura2 | END DO |
| 227 | 1 | pfleura2 | |
| 228 | 1 | pfleura2 | END DO !matches DO IGeom=1, NGeomF |
| 229 | 1 | pfleura2 | |
| 230 | 1 | pfleura2 | DEALLOCATE(BBT,BBT_inv,BprimT,GMat,EigVal,EigVec) |
| 231 | 1 | pfleura2 | DEALLOCATE(Geom,x,y,z,XprimRef) |
| 232 | 1 | pfleura2 | |
| 233 | 1 | pfleura2 | IF (debug) WRITE(*,*) "DBG Calc_baker_allGeomF over." |
| 234 | 1 | pfleura2 | END SUBROUTINE Calc_baker_allGeomF |