Statistiques
| Révision :

root / src / egrad_ext.f90 @ 8

Historique | Voir | Annoter | Télécharger (2,3 ko)

1
 subroutine egrad_ext(e,geomcart,gradcart)
2

    
3
  ! This routines calculates the energy and the gradient of 
4
  ! a molecule, using an external code
5

    
6

    
7
  use Path_module, only : Nat, renum,Order,OrderInv,AtName, Coord,ProgExe
8
  use Io_module
9

    
10
  !
11
  IMPLICIT NONE
12

    
13
  ! Energy (calculated if F300K=.F., else estimated)
14
  REAL(KREAL), INTENT (OUT) :: e
15
  ! Nb degree of freedom
16
  ! Geometry at which gradient is calculated (cf FActual also)
17
  REAL(KREAL), INTENT (IN) :: geomcart(Nat,3)
18
  ! Gradient calculated at Geom geometry
19
  REAL(KREAL), INTENT (OUT) :: gradcart(3*Nat)
20

    
21
  ! ======================================================================
22

    
23

    
24
  logical           :: debug
25

    
26
  REAL(KREAL) :: Pi
27

    
28
  INTEGER(KINT) :: iat, i, n3at
29

    
30
  !
31
  CHARACTER(132) :: FileIn,FileOut
32

    
33
  CHARACTER(VLCHARS), SAVE :: RunCommand
34
!  LOGICAL, SAVE :: FCopyRstrt=.False., FOrderChecked=.False.
35

    
36

    
37

    
38
  ! ======================================================================
39

    
40
  LOGICAL, EXTERNAL :: valid
41

    
42
  ! ======================================================================
43

    
44

    
45
  Pi=dacos(-1.0d0)
46
  n3at=3*nat
47

    
48
  debug=valid('EGRAD')
49
  if (debug) WRITE(*,*) '================ Entering Egrad_ext ===================='
50

    
51
  RunCommand=Trim(Adjustl(ProgExe))
52
  FileIn=Trim(CalcName) // Trim(ISuffix)
53
  FileOut=Trim(CalcName) // Trim(OSuffix)
54

    
55
  IF (DEBUG) WRITE(*,*)'RunCommand:',TRIM(RunCommand)
56

    
57
  ! we create the input file
58

    
59
  OPEN(IOTMP,File=FileIn)
60

    
61
  WRITE(IOTMP,'(1X,I10)') NAt
62
  WRITE(IOTMP,'(1X,A)') Coord
63

    
64
     DO I=1,Nat
65
        If (renum) THEN
66
           Iat=Order(I)
67
           WRITE(IOTMP,'(1X,A10,3(1X,F15.8),A)') Trim(AtName(I)),GeomCart(Iat,:)
68
        ELSE
69
           Iat=OrderInv(I)
70
           WRITE(IOTMP,'(1X,A10,3(1X,F15.8),A)') Trim(AtName(Iat)),GeomCart(I,:)
71
        END IF
72
     END DO
73

    
74
  call system(RunCommand)
75

    
76
  if (debug) WRITE(*,*) 'DBG EGRAD, back from calculation'
77

    
78
  OPEN(IOTMP,FILE=FileOut, STATUS='old')
79
  ! We first search for the forces
80
  READ(IOTMP,*) e
81
  DO I=1,Nat
82
     Iat=I
83
     IF (renum) Iat=Order(I)
84
     READ(IOTMP,*)  GradCart(3*Iat-2:3*Iat)
85
  END DO
86

    
87
  CLOSE(IOTMP)
88

    
89

    
90
  if (debug) WRITE(*,*) '================  Egrad_ext Over ===================='
91

    
92
  RETURN
93

    
94
!999 CONTINUE
95
!  if (.NOT.Ftmp) WRITE(*,*) 'We should not be here !!!!'
96
!  STOP
97
  ! ======================================================================
98
end subroutine egrad_ext