Statistics
| Revision:

root / src / ReadInput_gaussian.f90 @ 10

History | View | Annotate | Download (6 kB)

1
 SUBROUTINE ReadInput_gaussian
2

    
3
! This routine reads an input template for Gaussian
4

    
5
  use VarTypes
6
  use Path_module
7
  use Io_module
8

    
9
  IMPLICIT NONE
10

    
11
  INTERFACE
12
     function valid(string) result (isValid)
13
       CHARACTER(*), intent(in) :: string
14
       logical                  :: isValid
15
     END function VALID
16

    
17

    
18
    SUBROUTINE die(routine, msg, file, line, unit)
19

    
20
      Use VarTypes
21
      Use io_module
22

    
23
      implicit none
24
      character(len=*), intent(in)           :: routine, msg
25
      character(len=*), intent(in), optional :: file
26
      integer(KINT), intent(in), optional      :: line, unit
27

    
28
    END SUBROUTINE die
29

    
30

    
31
  END INTERFACE
32

    
33

    
34
  CHARACTER(132) ::  Line,LineUp
35
  INTEGER(KINT) :: LineL, Idx, Iat
36
  INTEGER(KINT) :: I,NTmp
37
  REAL(KREAL) :: Lat(3,3)
38
  
39
  LOGICAL :: Debug
40

    
41

    
42
  Debug=Valid("readinput").OR.Valid("readinput_gaussian")
43

    
44
 if (debug) Call Header("Entering ReadInput_Gaussian")
45

    
46
  ! We read the Gaussian input file
47
  ! First, the root
48
     IF (DEBUG) WRITE(*,*) "Reading Gauss Root"
49
     ALLOCATE(Gauss_Root)
50
     NULLIFY(Gauss_Root%next)
51
     Current => Gauss_root
52
     LineL=1
53
     DO WHILE (LineL.NE.0)
54
        READ(IOIN,'(A)') Line
55
        Line=AdjustL(Line)
56
        LineL=len_Trim(Line)
57
! we do not read the %chk line
58
        Idx=INDEX(Line,"chk")
59
        IF ((LineL.NE.0).AND.(Idx.EQ.0)) THEN
60
           current%Line=TRIM(Line)
61
           ALLOCATE(current%next)
62
           Current => Current%next
63
           Nullify(Current%next)
64
        END IF
65
     END DO
66

    
67
!     Current => Gauss_root
68
!     DO WHILE (ASSOCIATED(Current%next))
69
!        WRITE(*,'(1X,A)') Trim(current%line)
70
!        Current => current%next
71
!     END DO
72

    
73
     ! Now the comment... 
74
     IF (DEBUG) WRITE(*,*) "Reading Gauss Comment"
75
     ALLOCATE(Gauss_Comment)
76
     NuLLIFY(Gauss_Comment%Next)
77
     Current => Gauss_comment
78
     LineL=1
79
     DO WHILE (LineL.NE.0)
80
        READ(IOIN,'(A)') Line
81
        Line=AdjustL(Line)
82
        LineL=len(Trim(Line))
83
        IF (LineL.NE.0) THEN
84
           current%Line=TRIM(Line)
85
           ALLOCATE(current%next)
86
           Current => Current%next
87
           Nullify(Current%next)
88
        END IF
89
     END DO
90

    
91
 !    Current => Gauss_comment
92
 !    DO WHILE (ASSOCIATED(Current%next))
93
 !       WRITE(*,'(1X,A)') Trim(current%line)
94
 !       Current => current%next
95
 !    END DO
96

    
97
     ! Now the charge
98
     IF (DEBUG) WRITE(*,*) "Reading Gauss Charge"
99
     READ(IOIN,'(A)') Gauss_Charge
100
     if (debug) WRITE(*,*) "Gauss_charge=",TRIM(Gauss_charge)
101
     ! We now read the Paste part...
102
     ALLOCATE(Gauss_Paste(NAt))
103
     LineL=1
104
     Iat=0
105
     IPer=0
106
     FPBC=.FALSE.
107
     Gauss_paste=" "
108
     DO While (LineL.GT.0)
109
        READ(IOIN,'(A)') Line
110
        Line=AdjustL(Line)
111
        LineL=Len_TRIM(Line)
112
        IF (LineL.GT.0) THEN
113
           LineUp=Line
114
           Call UpCase(LineUp)
115
           if (LineUp(1:2)=="TV") THEN
116
              FPBC=.TRUE.
117
              IPer=IPer+1
118
              If (Iper>3) THEN
119
                 Call Die("ReadInput Gaussian","Iper>3",Unit=IOOUT)
120
              END IF
121
              NTmp=Index(LineUp," ")
122
              LineUp=LineUp(NTmp:)
123
              Read(LineUp,*) Lat(IPer,1:3)
124
           ELSE
125
              Iat=Iat+1
126
! we search for additional information at the end of the line
127
! for example ONIOM layers
128
! TO detect the end of the line, we use the fact that all reals
129
! should contain a '.', and that we have 3 reals/line.
130
              Idx=Index(Line,'.')
131
              Line=ADJUSTL(Line(Idx+1:))
132
              Idx=Index(Line,'.')
133
              Line=ADJUSTL(Line(Idx+1:))
134
              Idx=Index(Line,'.')
135
              Line=ADJUSTL(Line(Idx+1:))
136
              Idx=Index(Line,' ')
137
              If (Idx>0) THEN
138
                 Line=ADJUSTL(Line(Idx:))
139
                 IF (LEN_TRIM(Line).GT.0) THEN 
140
                    Gauss_paste(Iat)=ADJUSTL(TRIM(Line))
141
                 END IF
142
              ELSE
143
                 Gauss_paste(Iat)=""
144
              END IF
145
           END IF
146
        END IF
147
           
148
     END DO
149

    
150

    
151
     IF (Iat.NE.Nat) THEN
152
        WRITE(Line,*) "I found ", Iat," lines for the geometry instead of ",Nat
153
        Call Die("ReadInput Gaussian","Line",UNIT=IOOUT)
154
     END IF
155

    
156
  IF (FPBC) THEN
157
     Lat_a(1:3)=Lat(1,1:3)
158
     Lat_b(1:3)=Lat(2,1:3)
159
     Lat_c(1:3)=Lat(3,1:3)
160
     If (IPer>=1) THEN
161
        kaBeg=-1
162
        kaEnd=1
163
     END IF
164
     If (IPer>=2) THEN
165
        kbBeg=-1
166
        kbEnd=1
167
     END IF
168
     If (IPer==3) THEN
169
        kcBeg=-1
170
        kcEnd=1
171
     END IF
172
     If (IPer>3) THEN
173
        Call Die("Readinput_gaussian","Found too many Tv lines !",Unit=IOOUT)
174
     END IF
175
  END IF
176

    
177

    
178
     ! We now read the last part
179
     IF (DEBUG) WRITE(*,*) "Reading Gauss End"
180
     !     READ(IOIN,'(A)') Line
181
     ALLOCATE(Gauss_End)
182
     NuLLIFY(Gauss_End%Next)
183
     Current => Gauss_End
184
     LineL=1
185
     DO WHILE (1.EQ.1)
186
        READ(IOIN,'(A)',END=999) Line
187
        Line=AdjustL(Line)
188
        LineL=len(Trim(Line))
189
        current%Line=TRIM(Line)
190
        ALLOCATE(current%next)
191
        Current => Current%next
192
        Nullify(Current%next)
193
     END DO
194
999  CONTINUE
195

    
196
     IF (Debug) THEN
197
        ! Write the gaussian input file for testing purposes
198
        Current => Gauss_root
199
        DO WHILE (ASSOCIATED(Current%next))
200
           WRITE(*,'(1X,A)') Trim(current%line)
201
           Current => current%next
202
        END DO
203
        
204
        WRITE(*,*) 
205
!        WRITE(*,*) '//INFO// Comment original:'
206
        
207
        Current => Gauss_comment
208
        DO WHILE (ASSOCIATED(Current%next))
209
           WRITE(*,'(1X,A)') Trim(current%line)
210
           Current => current%next
211
        END DO
212
        
213
        WRITE(*,*) 
214
        WRITE(*,*) Trim(Gauss_charge)
215
        
216
        DO I=1,Nat
217
           WRITE(*,'(1X,A10,3(1X,F15.8),1X,A)') Trim(AtName(I)),XyzGeomI(1,1:3,I), TRIM(Gauss_Paste(I))
218
        END DO
219
        
220
        WRITE(*,*) 
221
        Current => Gauss_End
222
        DO WHILE (ASSOCIATED(Current%next))
223
           WRITE(*,'(1X,A)') Trim(current%line)
224
           Current => current%next
225
        END DO
226
        
227
        WRITE(*,*) 
228

    
229
        Call Header("Exiting ReadInput_Gaussian")
230

    
231
     END IF
232

    
233

    
234

    
235
   END SUBROUTINE READINPUT_GAUSSIAN