root / src / egrad_turbomole.f90 @ 3
Historique | Voir | Annoter | Télécharger (3,35 ko)
| 1 | 1 | pfleura2 | subroutine egrad_turbomole(e,geomcart,gradcart) |
|---|---|---|---|
| 2 | 1 | pfleura2 | |
| 3 | 1 | pfleura2 | ! This routines calculates the energy and the gradient of |
| 4 | 1 | pfleura2 | ! a molecule, using TurboMole |
| 5 | 1 | pfleura2 | |
| 6 | 1 | pfleura2 | use Path_module, only : Nat, AtName, unit,ProgExe,renum,order,OrderInv |
| 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 | |
| 24 | 1 | pfleura2 | |
| 25 | 2 | pfleura2 | REAL(KREAL) :: Pi |
| 26 | 1 | pfleura2 | |
| 27 | 2 | pfleura2 | INTEGER(KINT) :: iat, i, n3at |
| 28 | 2 | pfleura2 | INTEGER(KINT) :: Idx |
| 29 | 1 | pfleura2 | |
| 30 | 2 | pfleura2 | CHARACTER(132) :: FileIn, FileOut |
| 31 | 1 | pfleura2 | |
| 32 | 2 | 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_TurboMole ====================' |
| 51 | 1 | pfleura2 | |
| 52 | 1 | pfleura2 | |
| 53 | 1 | pfleura2 | gradcart=0. |
| 54 | 1 | pfleura2 | E=0. |
| 55 | 1 | pfleura2 | |
| 56 | 1 | pfleura2 | FileIn="coord" |
| 57 | 1 | pfleura2 | FileOut="gradient" |
| 58 | 1 | pfleura2 | |
| 59 | 1 | pfleura2 | RunCommand=Trim(ProgExe) |
| 60 | 1 | pfleura2 | |
| 61 | 1 | pfleura2 | IF (DEBUG) WRITE(*,*)'RunCommand:',TRIM(RunCommand) |
| 62 | 1 | pfleura2 | |
| 63 | 1 | pfleura2 | ! we create the input file |
| 64 | 1 | pfleura2 | |
| 65 | 1 | pfleura2 | OPEN(IOTMP,File=FileIn) |
| 66 | 1 | pfleura2 | WRITE(IOTMP,'(1X,A)') '$coord' |
| 67 | 1 | pfleura2 | DO I=1,Nat |
| 68 | 1 | pfleura2 | If (renum) THEN |
| 69 | 1 | pfleura2 | Iat=Order(I) |
| 70 | 1 | pfleura2 | WRITE(IOTMP,'(1X,3(1X,F15.8),A5)') GeomCart(Iat,:)*Unit,Trim(AtName(Iat)) |
| 71 | 1 | pfleura2 | ELSE |
| 72 | 1 | pfleura2 | Iat=OrderInv(I) |
| 73 | 1 | pfleura2 | WRITE(IOTMP,'(1X,3(1X,F15.8),A5)') GeomCart(I,:)*Unit,Trim(AtName(Iat)) |
| 74 | 1 | pfleura2 | END IF |
| 75 | 1 | pfleura2 | END DO |
| 76 | 1 | pfleura2 | WRITE(IOTMP,'(1X,A)') '$user-defined bonds' |
| 77 | 1 | pfleura2 | WRITE(IOTMP,'(1X,A)') '$end' |
| 78 | 1 | pfleura2 | CLOSE(IOTMP) |
| 79 | 1 | pfleura2 | |
| 80 | 1 | pfleura2 | IF (debug) THEN |
| 81 | 1 | pfleura2 | WRITE(*,*) 'DBG EGRAD ' // Trim(FileIn) |
| 82 | 1 | pfleura2 | call system('cat ' // Trim(FileIn))
|
| 83 | 1 | pfleura2 | END IF |
| 84 | 1 | pfleura2 | |
| 85 | 1 | pfleura2 | |
| 86 | 1 | pfleura2 | call system(RunCommand) |
| 87 | 1 | pfleura2 | |
| 88 | 1 | pfleura2 | if (debug) WRITE(*,*) 'DBG EGRAD, back from calculation' |
| 89 | 1 | pfleura2 | |
| 90 | 1 | pfleura2 | ! Whatever the coordinate system, we read the cartesian gradient |
| 91 | 1 | pfleura2 | ! and we convert it to Zmat or other if needed |
| 92 | 1 | pfleura2 | |
| 93 | 1 | pfleura2 | OPEN(IOTMP,FILE=FileOut, STATUS='old') |
| 94 | 1 | pfleura2 | ! We check that gradient file is ok |
| 95 | 1 | pfleura2 | READ(IOTMP,'(A)') LINE |
| 96 | 1 | pfleura2 | Line=AdjustL(Line) |
| 97 | 1 | pfleura2 | if (Line(1:5).NE.'$grad') THEN |
| 98 | 1 | pfleura2 | WRITE(*,*) "Error with Turbomole, gradient file does not start with $grad" |
| 99 | 1 | pfleura2 | STOP |
| 100 | 1 | pfleura2 | END IF |
| 101 | 1 | pfleura2 | |
| 102 | 1 | pfleura2 | ! we read the energy |
| 103 | 1 | pfleura2 | READ(IOTMP,'(A)') LINE |
| 104 | 1 | pfleura2 | ! energy is after the second = sign: |
| 105 | 1 | pfleura2 | ! cycle = 1 SCF energy = -2889.2212497430 |dE/dxyz| = 0.064137 |
| 106 | 1 | pfleura2 | Idx=Index(Line,'=') |
| 107 | 1 | pfleura2 | Line=Line(Idx+1:) |
| 108 | 1 | pfleura2 | Idx=Index(Line,'=') |
| 109 | 1 | pfleura2 | Line=Line(Idx+1:) |
| 110 | 1 | pfleura2 | READ(Line,*) E |
| 111 | 1 | pfleura2 | |
| 112 | 1 | pfleura2 | ! We skip the coordinates |
| 113 | 1 | pfleura2 | DO I=1,Nat |
| 114 | 1 | pfleura2 | READ(IOTMP,'(A)') LINE |
| 115 | 1 | pfleura2 | END DO |
| 116 | 1 | pfleura2 | |
| 117 | 1 | pfleura2 | ! We read the gradient |
| 118 | 1 | pfleura2 | DO I=1,Nat |
| 119 | 1 | pfleura2 | Iat=I |
| 120 | 1 | pfleura2 | IF (renum) Iat=Order(I) |
| 121 | 1 | pfleura2 | READ(IOTMP,*) GradCart(3*Iat-2:3*Iat) |
| 122 | 1 | pfleura2 | if (debug) WRITE(*,*) "I,Iat,GradCart:",I,Iat,GradCart(3*Iat-2:3*Iat) |
| 123 | 1 | pfleura2 | END DO |
| 124 | 1 | pfleura2 | |
| 125 | 1 | pfleura2 | ! TurboMole gives the Forces in au/a0, so we convert it into the |
| 126 | 1 | pfleura2 | ! gradient in ua/Angstrom |
| 127 | 1 | pfleura2 | gradCart=gradCart*unit |
| 128 | 1 | pfleura2 | |
| 129 | 1 | pfleura2 | CLOSE(IOTMP) |
| 130 | 1 | pfleura2 | |
| 131 | 1 | pfleura2 | if (debug) WRITE(*,*) '================ Egrad_TurboMole Over ====================' |
| 132 | 1 | pfleura2 | |
| 133 | 1 | pfleura2 | RETURN |
| 134 | 1 | pfleura2 | |
| 135 | 2 | pfleura2 | !999 CONTINUE |
| 136 | 2 | pfleura2 | ! WRITE(*,*) 'We should not be here !!!!' |
| 137 | 2 | pfleura2 | ! STOP |
| 138 | 1 | pfleura2 | ! ====================================================================== |
| 139 | 1 | pfleura2 | end subroutine egrad_TurboMole |