root / src / egrad_mopac.f90 @ 2
Historique | Voir | Annoter | Télécharger (4,58 ko)
| 1 | 1 | pfleura2 | subroutine egrad_mopac(e,geomcart,gradcart) |
|---|---|---|---|
| 2 | 1 | pfleura2 | |
| 3 | 1 | pfleura2 | ! This routines calculates the energy and the gradient of |
| 4 | 1 | pfleura2 | ! a molecule, using mopac |
| 5 | 1 | pfleura2 | |
| 6 | 1 | pfleura2 | use Path_module, only : Nat, renum,Order,OrderInv,AtName, Coord, dzdc, indzmat,Nom,Atome, massat, unit,ProgExe, au2kcal |
| 7 | 1 | pfleura2 | use Io_module |
| 8 | 1 | pfleura2 | |
| 9 | 1 | pfleura2 | IMPLICIT NONE |
| 10 | 1 | pfleura2 | |
| 11 | 1 | pfleura2 | ! Energy (calculated if F300K=.F., else estimated) |
| 12 | 1 | pfleura2 | REAL(KREAL), INTENT (OUT) :: e |
| 13 | 1 | pfleura2 | ! Nb degree of freedom |
| 14 | 1 | pfleura2 | REAL(KREAL), INTENT (IN) :: geomcart(Nat,3) |
| 15 | 1 | pfleura2 | ! Gradient calculated at Geom geometry |
| 16 | 1 | pfleura2 | REAL(KREAL), INTENT (OUT) :: gradcart(3*NAt) |
| 17 | 1 | pfleura2 | |
| 18 | 1 | pfleura2 | ! ====================================================================== |
| 19 | 1 | pfleura2 | |
| 20 | 1 | pfleura2 | character(LCHARS) :: LINE |
| 21 | 1 | pfleura2 | |
| 22 | 1 | pfleura2 | logical :: debug |
| 23 | 1 | pfleura2 | LOGICAL, SAVE :: first=.true. |
| 24 | 1 | pfleura2 | |
| 25 | 2 | pfleura2 | REAL(KREAL) :: Pi |
| 26 | 1 | pfleura2 | |
| 27 | 2 | pfleura2 | INTEGER(KINT) :: iat, i, j, k, n3at |
| 28 | 1 | pfleura2 | INTEGER(KINT) :: ITmp1,ITmp2, Idx |
| 29 | 1 | pfleura2 | |
| 30 | 1 | pfleura2 | CHARACTER(132) :: FileIn, FileOut, FileChk |
| 31 | 1 | pfleura2 | |
| 32 | 1 | pfleura2 | CHARACTER(3) :: SepIn=' < ', SepOut=' > ' |
| 33 | 1 | pfleura2 | CHARACTER(VLCHARS), SAVE :: RunCommand |
| 34 | 1 | pfleura2 | |
| 35 | 1 | pfleura2 | ! ====================================================================== |
| 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 | END INTERFACE |
| 43 | 1 | pfleura2 | |
| 44 | 1 | pfleura2 | ! ====================================================================== |
| 45 | 1 | pfleura2 | |
| 46 | 1 | pfleura2 | Pi=dacos(-1.0d0) |
| 47 | 1 | pfleura2 | n3at=3*nat |
| 48 | 1 | pfleura2 | |
| 49 | 1 | pfleura2 | debug=valid('EGRAD')
|
| 50 | 1 | pfleura2 | if (debug) WRITE(*,*) '================ Entering Egrad_Mopac ====================' |
| 51 | 1 | pfleura2 | |
| 52 | 1 | pfleura2 | if (first) THEN |
| 53 | 1 | pfleura2 | First=.FALSE. |
| 54 | 1 | pfleura2 | SepIn=' ' |
| 55 | 1 | pfleura2 | SepOut=' ' |
| 56 | 1 | pfleura2 | END IF |
| 57 | 1 | pfleura2 | |
| 58 | 1 | pfleura2 | gradcart=0. |
| 59 | 1 | pfleura2 | E=0. |
| 60 | 1 | pfleura2 | |
| 61 | 1 | pfleura2 | FileIn=Trim(CalcName) // "." // Trim(ISuffix) |
| 62 | 1 | pfleura2 | FileOut=Trim(CalcName) // "." // Trim(OSuffix) |
| 63 | 1 | pfleura2 | FileChk=Trim(CalcName) // ".arc" |
| 64 | 1 | pfleura2 | |
| 65 | 1 | pfleura2 | RunCommand=Trim(ProgExe) // SepIn // Trim(FileIn) |
| 66 | 1 | pfleura2 | |
| 67 | 1 | pfleura2 | IF (DEBUG) WRITE(*,*)'RunCommand:',TRIM(RunCommand) |
| 68 | 1 | pfleura2 | |
| 69 | 1 | pfleura2 | ! we create the input file |
| 70 | 1 | pfleura2 | |
| 71 | 1 | pfleura2 | OPEN(IOTMP,File=FileIn) |
| 72 | 1 | pfleura2 | WRITE(IOTMP,'(A)') '* All comments are put at the begining of the file' |
| 73 | 1 | pfleura2 | Current => Mopac_comment |
| 74 | 1 | pfleura2 | DO WHILE (ASSOCIATED(Current%next)) |
| 75 | 1 | pfleura2 | WRITE(IOTMP,'(A)') Trim(current%line) |
| 76 | 1 | pfleura2 | Current => current%next |
| 77 | 1 | pfleura2 | END DO |
| 78 | 1 | pfleura2 | |
| 79 | 1 | pfleura2 | Current => Mopac_root |
| 80 | 1 | pfleura2 | DO WHILE (ASSOCIATED(Current%next)) |
| 81 | 1 | pfleura2 | WRITE(IOTMP,'(1X,A)') Trim(current%line) |
| 82 | 1 | pfleura2 | WRITE(*,'(1X,A)') Trim(current%line) |
| 83 | 1 | pfleura2 | Current => current%next |
| 84 | 1 | pfleura2 | END DO |
| 85 | 1 | pfleura2 | |
| 86 | 1 | pfleura2 | DO I=1,Nat |
| 87 | 1 | pfleura2 | If (renum) THEN |
| 88 | 1 | pfleura2 | Iat=Order(I) |
| 89 | 1 | pfleura2 | WRITE(IOTMP,'(1X,A10,3(1X,F15.8))') Trim(AtName(I)),GeomCart(Iat,:) |
| 90 | 1 | pfleura2 | ELSE |
| 91 | 1 | pfleura2 | Iat=OrderInv(I) |
| 92 | 1 | pfleura2 | WRITE(IOTMP,'(1X,A10,3(1X,F15.8))') Trim(AtName(Iat)),GeomCart(I,:) |
| 93 | 1 | pfleura2 | END IF |
| 94 | 1 | pfleura2 | END DO |
| 95 | 1 | pfleura2 | |
| 96 | 1 | pfleura2 | WRITE(IOTMP,'(1X,A)') Trim(Mopac_EndGeom) |
| 97 | 1 | pfleura2 | |
| 98 | 1 | pfleura2 | Current => Mopac_End |
| 99 | 1 | pfleura2 | DO WHILE (ASSOCIATED(Current%next)) |
| 100 | 1 | pfleura2 | WRITE(IOTMP,'(1X,A)') Trim(current%line) |
| 101 | 1 | pfleura2 | Current => current%next |
| 102 | 1 | pfleura2 | END DO |
| 103 | 1 | pfleura2 | |
| 104 | 1 | pfleura2 | WRITE(IOTMP,*) |
| 105 | 1 | pfleura2 | CLOSE(IOTMP) |
| 106 | 1 | pfleura2 | |
| 107 | 1 | pfleura2 | IF (debug) THEN |
| 108 | 1 | pfleura2 | WRITE(*,*) 'DBG EGRAD ' // Trim(FileIn),' COORD=',TRIM(COORD) |
| 109 | 1 | pfleura2 | call system('cat ' // Trim(FileIn))
|
| 110 | 1 | pfleura2 | END IF |
| 111 | 1 | pfleura2 | |
| 112 | 1 | pfleura2 | |
| 113 | 1 | pfleura2 | call system(RunCommand) |
| 114 | 1 | pfleura2 | |
| 115 | 1 | pfleura2 | if (debug) WRITE(*,*) 'DBG EGRAD, back from calculation' |
| 116 | 1 | pfleura2 | |
| 117 | 1 | pfleura2 | ! Whatever the coordinate system, we read the cartesian gradient |
| 118 | 1 | pfleura2 | ! and we convert it to Zmat or other if needed |
| 119 | 1 | pfleura2 | |
| 120 | 1 | pfleura2 | OPEN(IOTMP,FILE=FileOut, STATUS='old') |
| 121 | 1 | pfleura2 | ! We first search for the forces |
| 122 | 1 | pfleura2 | READ(IOTMP,'(A)') LINE |
| 123 | 1 | pfleura2 | |
| 124 | 1 | pfleura2 | DO WHILE (INDEX(LINE,'FINAL POINT AND DERIVATIVES')==0) |
| 125 | 1 | pfleura2 | IF (INDEX(Line,'FINAL HEAT OF FORMATION').NE.0) THEN |
| 126 | 1 | pfleura2 | Itmp1=Index(Line,"=")+1 |
| 127 | 1 | pfleura2 | ITmp2=Index(Line,"KCAL")-1 |
| 128 | 1 | pfleura2 | Read(Line(Itmp1:Itmp2),*) E |
| 129 | 1 | pfleura2 | E=E/au2kcal |
| 130 | 1 | pfleura2 | END IF |
| 131 | 1 | pfleura2 | READ(IOTMP,'(A)',END=999) LINE |
| 132 | 1 | pfleura2 | END DO |
| 133 | 1 | pfleura2 | |
| 134 | 1 | pfleura2 | if (debug) WRITE(*,*) "GradCart reading - renum=",Renum |
| 135 | 1 | pfleura2 | READ(IOTMP,'(A)') LINE |
| 136 | 1 | pfleura2 | READ(IOTMP,'(A)') LINE |
| 137 | 1 | pfleura2 | DO I=1,Nat |
| 138 | 1 | pfleura2 | Iat=I |
| 139 | 1 | pfleura2 | IF (renum) Iat=Order(I) |
| 140 | 1 | pfleura2 | DO J=1,3 |
| 141 | 1 | pfleura2 | READ(IOTMP,'(A)') Line |
| 142 | 1 | pfleura2 | ! Gradient is on the 7th column |
| 143 | 1 | pfleura2 | DO K=1,6 |
| 144 | 1 | pfleura2 | Line=AdjustL(Line) |
| 145 | 1 | pfleura2 | Idx=Index(Line," ") |
| 146 | 1 | pfleura2 | Line=AdjustL(Line(Idx+1:)) |
| 147 | 1 | pfleura2 | END DO |
| 148 | 1 | pfleura2 | READ(Line,*) GradCart(3*Iat-3+j) |
| 149 | 1 | pfleura2 | END DO |
| 150 | 1 | pfleura2 | if (debug) WRITE(*,*) "I,Iat,GradCart:",I,Iat,GradCart(3*Iat-2:3*Iat) |
| 151 | 1 | pfleura2 | END DO |
| 152 | 1 | pfleura2 | |
| 153 | 1 | pfleura2 | ! Mopac gives the Forces in kcal/angstrom, so we convert it into the |
| 154 | 1 | pfleura2 | ! gradient in ua/Angstrom |
| 155 | 1 | pfleura2 | gradCart=gradCart/au2kcal |
| 156 | 1 | pfleura2 | |
| 157 | 1 | pfleura2 | ! if (debug.AND.(COORD.EQ.'ZMAT')) THEN |
| 158 | 1 | pfleura2 | ! DO WHILE (INDEX(LINE,'Internal Coordinate Forces')==0) |
| 159 | 1 | pfleura2 | ! READ(IOTMP,'(A)') LINE |
| 160 | 1 | pfleura2 | !! WRITE(*,*) 'Pas bon:' // TRIM(LINE) |
| 161 | 1 | pfleura2 | ! END DO |
| 162 | 1 | pfleura2 | ! WRITE(*,*) TRIM(LINE) |
| 163 | 1 | pfleura2 | ! DO I=1,Nat+2 |
| 164 | 1 | pfleura2 | ! READ(IOTMP,'(A)') LINE |
| 165 | 1 | pfleura2 | ! WRITE(*,*) TRIM(LINE) |
| 166 | 1 | pfleura2 | ! END DO |
| 167 | 1 | pfleura2 | ! END IF |
| 168 | 1 | pfleura2 | |
| 169 | 1 | pfleura2 | CLOSE(IOTMP) |
| 170 | 1 | pfleura2 | |
| 171 | 1 | pfleura2 | if (debug) WRITE(*,*) '================ Egrad_Mopac Over ====================' |
| 172 | 1 | pfleura2 | |
| 173 | 1 | pfleura2 | RETURN |
| 174 | 1 | pfleura2 | |
| 175 | 1 | pfleura2 | 999 CONTINUE |
| 176 | 1 | pfleura2 | WRITE(*,*) 'We should not be here !!!!' |
| 177 | 1 | pfleura2 | STOP |
| 178 | 1 | pfleura2 | ! ====================================================================== |
| 179 | 1 | pfleura2 | end subroutine egrad_mopac |