root / src / egrad_vasp.f90 @ 2
Historique | Voir | Annoter | Télécharger (3,95 ko)
| 1 | 1 | pfleura2 | subroutine egrad_vasp(e,geomcart,gradcart) |
|---|---|---|---|
| 2 | 1 | pfleura2 | |
| 3 | 1 | pfleura2 | ! This routines calculates the energy and the gradient of |
| 4 | 1 | pfleura2 | ! a molecule, using VASP |
| 5 | 1 | pfleura2 | |
| 6 | 1 | pfleura2 | |
| 7 | 1 | pfleura2 | use Path_module, only : Nat, renum,Order,OrderInv,AtName, Coord, dzdc, & |
| 8 | 1 | pfleura2 | indzmat,Nom,Atome, massat, unit,Nfroz,Frozen,ProgExe,Latr,FrozAtoms |
| 9 | 1 | pfleura2 | use Io_module |
| 10 | 1 | pfleura2 | |
| 11 | 1 | pfleura2 | ! |
| 12 | 1 | pfleura2 | IMPLICIT NONE |
| 13 | 1 | pfleura2 | |
| 14 | 1 | pfleura2 | ! Energy (calculated if F300K=.F., else estimated) |
| 15 | 1 | pfleura2 | REAL(KREAL), INTENT (OUT) :: e |
| 16 | 1 | pfleura2 | ! Nb degree of freedom |
| 17 | 1 | pfleura2 | REAL(KREAL), INTENT (IN) :: geomcart(Nat,3) |
| 18 | 1 | pfleura2 | ! Gradient calculated at Geom geometry |
| 19 | 1 | pfleura2 | REAL(KREAL), INTENT (OUT) :: gradcart(3*NAt) |
| 20 | 1 | pfleura2 | |
| 21 | 1 | pfleura2 | ! ====================================================================== |
| 22 | 1 | pfleura2 | |
| 23 | 1 | pfleura2 | character(LCHARS) :: LINE |
| 24 | 1 | pfleura2 | |
| 25 | 2 | pfleura2 | REAL(KREAL) :: Pi |
| 26 | 1 | pfleura2 | |
| 27 | 2 | pfleura2 | INTEGER(KINT) :: iat, i, n3at |
| 28 | 1 | pfleura2 | REAL(KREAL) :: RTmp1, RTmp2, RTmp3 |
| 29 | 1 | pfleura2 | |
| 30 | 1 | pfleura2 | ! |
| 31 | 1 | pfleura2 | CHARACTER(132), PARAMETER :: FileIn='POSCAR', FileOut='OUTCAR' |
| 32 | 1 | pfleura2 | |
| 33 | 1 | pfleura2 | CHARACTER(VLCHARS), SAVE :: RunCommand |
| 34 | 1 | pfleura2 | |
| 35 | 1 | pfleura2 | ! REAL(KREAL), ALLOCATABLE :: GeomTmpC(:), GeomTmp(:) |
| 36 | 1 | pfleura2 | |
| 37 | 1 | pfleura2 | LOGICAL :: Debug |
| 38 | 1 | pfleura2 | |
| 39 | 1 | pfleura2 | INTERFACE |
| 40 | 1 | pfleura2 | function valid(string) result (isValid) |
| 41 | 1 | pfleura2 | CHARACTER(*), intent(in) :: string |
| 42 | 1 | pfleura2 | logical :: isValid |
| 43 | 1 | pfleura2 | END function VALID |
| 44 | 1 | pfleura2 | END INTERFACE |
| 45 | 1 | pfleura2 | |
| 46 | 1 | pfleura2 | Pi=dacos(-1.0d0) |
| 47 | 1 | pfleura2 | debug=valid('EGRAD')
|
| 48 | 1 | pfleura2 | if (debug) Call header('Entering Egrad_VASP')
|
| 49 | 1 | pfleura2 | |
| 50 | 1 | pfleura2 | n3at=3*nat |
| 51 | 1 | pfleura2 | |
| 52 | 1 | pfleura2 | ! ALLOCATE(GeomTmpC(n3at)) |
| 53 | 1 | pfleura2 | |
| 54 | 1 | pfleura2 | |
| 55 | 1 | pfleura2 | gradcart=0. |
| 56 | 1 | pfleura2 | E=0. |
| 57 | 1 | pfleura2 | RunCommand=Trim(ProgExe) |
| 58 | 1 | pfleura2 | |
| 59 | 1 | pfleura2 | IF (DEBUG) WRITE(*,*)'RunCommand:',TRIM(RunCommand) |
| 60 | 1 | pfleura2 | |
| 61 | 1 | pfleura2 | ! we create the input file |
| 62 | 1 | pfleura2 | |
| 63 | 1 | pfleura2 | ! write(*,*) "Coucou 2" |
| 64 | 1 | pfleura2 | |
| 65 | 1 | pfleura2 | OPEN(IOTMP,File=FileIn) |
| 66 | 1 | pfleura2 | |
| 67 | 1 | pfleura2 | ! we convert the coordinates into Cartesian coordinates |
| 68 | 1 | pfleura2 | ! GeomTmpC=Reshape(GeomCart,SHAPE=(/3*Nat/)) |
| 69 | 1 | pfleura2 | |
| 70 | 1 | pfleura2 | Call PrintGeomVasp(Vasp_Title,geomcart,Latr,FrozAtoms,IoTmp) |
| 71 | 1 | pfleura2 | |
| 72 | 1 | pfleura2 | CLOSE(IOTMP) |
| 73 | 1 | pfleura2 | |
| 74 | 1 | pfleura2 | |
| 75 | 1 | pfleura2 | IF (debug) THEN |
| 76 | 1 | pfleura2 | WRITE(*,*) 'DBG EGRAD ' // Trim(FileIn),' COORD=',TRIM(COORD) |
| 77 | 1 | pfleura2 | call system('cat ' // Trim(FileIn))
|
| 78 | 1 | pfleura2 | END IF |
| 79 | 1 | pfleura2 | |
| 80 | 1 | pfleura2 | call system(RunCommand) |
| 81 | 1 | pfleura2 | |
| 82 | 1 | pfleura2 | if (debug) WRITE(*,*) 'DBG EGRAD_VASP, back from calculation' |
| 83 | 1 | pfleura2 | ! if (debug) WRITE(*,*) "DBG EGRAD_VASP Order(I)",Order(1:Nat) |
| 84 | 1 | pfleura2 | |
| 85 | 1 | pfleura2 | ! Whatever the coordinate system, we read the cartesian gradient |
| 86 | 1 | pfleura2 | ! and we convert it to Zmat or other if needed |
| 87 | 1 | pfleura2 | |
| 88 | 1 | pfleura2 | OPEN(IOTMP,FILE=FileOut, STATUS='old') |
| 89 | 1 | pfleura2 | ! We first search for the forces |
| 90 | 1 | pfleura2 | READ(IOTMP,'(A)',END=999,ERR=999) LINE |
| 91 | 1 | pfleura2 | ! We search for the last part of the OUTCAR file, after wavefunction is converged |
| 92 | 1 | pfleura2 | DO WHILE (INDEX(LINE,'EDIFF is reached')==0) |
| 93 | 1 | pfleura2 | READ(IOTMP,'(A)',END=999,ERR=999) LINE |
| 94 | 1 | pfleura2 | END DO |
| 95 | 1 | pfleura2 | READ(IOTMP,'(A)',END=999,ERR=999) LINE |
| 96 | 1 | pfleura2 | DO WHILE (INDEX(LINE,'TOTEN')==0) |
| 97 | 1 | pfleura2 | READ(IOTMP,'(A)',END=999,ERR=999) LINE |
| 98 | 1 | pfleura2 | END DO |
| 99 | 1 | pfleura2 | Line=Line(26:) |
| 100 | 1 | pfleura2 | READ(LINE,*) E |
| 101 | 1 | pfleura2 | if (debug) WRITE(*,'(1X,A,F20.6)') "DBG Egrad_VASP E=",E |
| 102 | 1 | pfleura2 | |
| 103 | 1 | pfleura2 | ! We search for the forces |
| 104 | 1 | pfleura2 | DO WHILE (INDEX(LINE,'TOTAL-FORCE')==0) |
| 105 | 1 | pfleura2 | READ(IOTMP,'(A)',END=999,ERR=999) LINE |
| 106 | 1 | pfleura2 | END DO |
| 107 | 1 | pfleura2 | READ(IOTMP,'(A)',END=999,ERR=999) LINE |
| 108 | 1 | pfleura2 | DO I=1,Nat |
| 109 | 1 | pfleura2 | Iat=I |
| 110 | 1 | pfleura2 | IF (renum) Iat=Order(I) |
| 111 | 1 | pfleura2 | READ(IOTMP,*,END=999,ERR=999) Rtmp1,RTmp2,RTmp3,GradCart(3*Iat-2:3*Iat) |
| 112 | 1 | pfleura2 | END DO |
| 113 | 1 | pfleura2 | |
| 114 | 1 | pfleura2 | |
| 115 | 1 | pfleura2 | if (debug) THEN |
| 116 | 1 | pfleura2 | WRITE(*,*) "DBG EGRAD_VASP - GradCart=FORCES - original order" |
| 117 | 1 | pfleura2 | DO I=1,Nat |
| 118 | 1 | pfleura2 | Iat=Order(I) |
| 119 | 1 | pfleura2 | WRITE(*,'(1X,I5,3(1X,F20.6))') I,GradCart(3*Iat-2:3*Iat) |
| 120 | 1 | pfleura2 | END DO |
| 121 | 1 | pfleura2 | WRITE(*,*) "DBG EGRAD_VASP - GradCart=FORCES - internal order" |
| 122 | 1 | pfleura2 | DO I=1,Nat |
| 123 | 1 | pfleura2 | Iat=Order(I) |
| 124 | 1 | pfleura2 | WRITE(*,'(3(1X,I5),3(1X,F20.6))') I,Iat,OrderInv(I),GradCart(3*I-2:3*I) |
| 125 | 1 | pfleura2 | END DO |
| 126 | 1 | pfleura2 | END IF |
| 127 | 1 | pfleura2 | |
| 128 | 1 | pfleura2 | ! VASP gives the Forces in eV/Angstrom, so we convert it into the |
| 129 | 1 | pfleura2 | ! gradient in ua/Angstrom |
| 130 | 1 | pfleura2 | gradCart=-1.0d0*ev2Au*gradCart |
| 131 | 1 | pfleura2 | |
| 132 | 1 | pfleura2 | ! if (debug.AND.(COORD.EQ.'ZMAT')) THEN |
| 133 | 1 | pfleura2 | ! DO WHILE (INDEX(LINE,'Internal Coordinate Forces')==0) |
| 134 | 1 | pfleura2 | ! READ(IOTMP,'(A)') LINE |
| 135 | 1 | pfleura2 | !! WRITE(*,*) 'Pas bon:' // TRIM(LINE) |
| 136 | 1 | pfleura2 | ! END DO |
| 137 | 1 | pfleura2 | ! WRITE(*,*) TRIM(LINE) |
| 138 | 1 | pfleura2 | ! DO I=1,Nat+2 |
| 139 | 1 | pfleura2 | ! READ(IOTMP,'(A)') LINE |
| 140 | 1 | pfleura2 | ! WRITE(*,*) TRIM(LINE) |
| 141 | 1 | pfleura2 | ! END DO |
| 142 | 1 | pfleura2 | ! END IF |
| 143 | 1 | pfleura2 | |
| 144 | 1 | pfleura2 | CLOSE(IOTMP) |
| 145 | 1 | pfleura2 | |
| 146 | 1 | pfleura2 | ! DeALLOCATE(GeomTmpC) |
| 147 | 1 | pfleura2 | |
| 148 | 1 | pfleura2 | |
| 149 | 1 | pfleura2 | if (debug) Call header('Egrad_VASP Over')
|
| 150 | 1 | pfleura2 | |
| 151 | 1 | pfleura2 | RETURN |
| 152 | 1 | pfleura2 | |
| 153 | 1 | pfleura2 | 999 CONTINUE |
| 154 | 1 | pfleura2 | WRITE(*,*) 'We should not be here !!!!' |
| 155 | 1 | pfleura2 | STOP |
| 156 | 1 | pfleura2 | ! ====================================================================== |
| 157 | 1 | pfleura2 | end subroutine egrad_vasp |
| 158 | 1 | pfleura2 | |
| 159 | 1 | pfleura2 | |
| 160 | 1 | pfleura2 |