-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathconfig_input_output.f90
252 lines (191 loc) · 7.47 KB
/
config_input_output.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
!begin rubric
!****************************************************************************** *
!* Original Author: Mark Gilbert *
!* mark.gilbert@ukaea.uk
!* copyright, 2015 (first version), 2018 (first git repository), UKAEA *
!******************************************************************************
!end rubric
SUBROUTINE write_cfg_start(filename,natoms,lxx,io_quit,do_velocity)
use accuracy
use file_units
IMPLICIT NONE
INTEGER, intent(in) :: natoms
REAL(KIND=DBL), intent(in) :: lxx(3)
CHARACTER (LEN=500), intent(in) :: filename
INTEGER, intent(inout) :: io_quit
LOGICAL :: do_velocity
CHARACTER (LEN=300) outstr
io_quit=0
print *,TRIM(ADJUSTL(filename))
OPEN(unit=cfg_file,file=TRIM(ADJUSTL(filename)),STATUS='REPLACE',IOSTAT=io_quit)
IF(io_quit==0) THEN
WRITE (cfg_file,'(A22,I10)') 'Number of particles = ',natoms
!WRITE (cfg_file,*) 'A = 1.0 Angstrom (basic length scale)'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(1,1) = ',lxx(1),'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(1,2) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(1,3) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(2,1) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(2,2) = ',lxx(2),'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(2,3) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(3,1) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(3,2) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(3,3) = ',lxx(3),'A'
IF(.not.do_velocity) THEN
WRITE (cfg_file,'(A13)') '.NO_VELOCITY.'
WRITE (cfg_file,'(A18)') 'entry_count = 3'
ELSE
WRITE (cfg_file,'(A18)') 'entry_count = 6'
END IF
END IF
END SUBROUTINE write_cfg_start
SUBROUTINE write_lammps_start(filename,natoms,lxx,io_quit)
use accuracy
use file_units
IMPLICIT NONE
INTEGER, intent(in) :: natoms
REAL(KIND=DBL), intent(in) :: lxx(3)
CHARACTER (LEN=500), intent(in) :: filename
INTEGER, intent(inout) :: io_quit
INTEGER :: noutput
CHARACTER (LEN=100) outstr
io_quit=0
OPEN(unit=lammps_file,file=TRIM(ADJUSTL(filename)),STATUS='REPLACE',IOSTAT=io_quit)
IF(io_quit==0) THEN
WRITE (lammps_file,'(A)') 'lammps configuration output file'
WRITE (lammps_file,'(I10,A10)') natoms,'atoms'
WRITE(lammps_file,'(2e16.8,A15)') 0d0,lxx(1),' xlo xhi'
WRITE(lammps_file,'(2e16.8,A15)') 0d0,lxx(2),' ylo yhi'
WRITE(lammps_file,'(2e16.8,A15)') 0d0,lxx(3),' zlo zhi'
WRITE(lammps_file,'(3e16.8,A15)') 0d0,0d0,0d0,'xy xz yz'
END IF
END SUBROUTINE write_lammps_start
SUBROUTINE write_cfg(filename,xx,natoms,lxx,io_quit,ele_type,ele_mass,xee)
use accuracy
use file_units
IMPLICIT NONE
INTEGER, intent(in) :: natoms
REAL(KIND=DBL), intent(in) :: lxx(3),xx(natoms,3),xee(natoms,3)
CHARACTER (LEN=500), intent(in) :: filename
INTEGER, intent(inout) :: io_quit
LOGICAL :: output(natoms)
CHARACTER (LEN=2), intent(in) :: ele_type(natoms)
INTEGER, intent(in) :: ele_mass(natoms)
INTEGER :: noutput
CHARACTER (LEN=2) :: current_ele
LOGICAL :: newblock
INTEGER :: i,currentistart
CHARACTER (LEN=300) outstr
io_quit=0
output=.false.
!DO i=1,natoms
! PRINT *,i,ele_type(i),ele_mass(i)
!END DO
print *,TRIM(ADJUSTL(filename))
OPEN(unit=cfg_file,file=TRIM(ADJUSTL(filename)),STATUS='REPLACE',IOSTAT=io_quit)
IF(io_quit==0) THEN
WRITE (cfg_file,'(A22,I10)') 'Number of particles = ',natoms
!WRITE (cfg_file,*) 'A = 1.0 Angstrom (basic length scale)'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(1,1) = ',lxx(1),'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(1,2) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(1,3) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(2,1) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(2,2) = ',lxx(2),'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(2,3) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(3,1) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(3,2) = ',0._DBL,'A'
WRITE (cfg_file,'(A10,ES25.10,A2)') 'H0(3,3) = ',lxx(3),'A'
! assume velocities will be given
!WRITE (cfg_file,'(A13)') '.NO_VELOCITY.'
WRITE (cfg_file,'(A18)') 'entry_count = 6'
noutput=0
DO
IF(noutput.GE. natoms) EXIT
IF(io_quit.NE.0) EXIT
newblock=.true.
DO i=1,natoms
IF(output(i)) cycle
IF(io_quit.NE.0) EXIT
IF(newblock) THEN
WRITE(cfg_file,'(I3)') ele_mass(i)
WRITE(cfg_file,'(A2)') ele_type(i)
newblock=.false.
currentistart=i
END IF
!PRINT *,i,currentistart,ele_type(i),ele_type(currentistart),ele_mass(i),ele_mass(currentistart)
IF((ele_mass(i)==ele_mass(currentistart)).AND. &
(TRIM(ADJUSTL(ele_type(i)))==TRIM(ADJUSTL(ele_type(currentistart))))) THEN
WRITE(outstr,'(1x,6(1x,e16.8))') &
xx(i,1)/lxx(1),xx(i,2)/lxx(2),xx(i,3)/lxx(3),&
xee(i,1)/lxx(1),xee(i,2)/lxx(2),xee(i,3)/lxx(3)
WRITE(cfg_file,'(a)',IOSTAT=io_quit) TRIM(ADJUSTL(outstr))
output(i)=.true.
noutput=noutput+1
END IF
END DO
END DO
IF(io_quit==0) CLOSE(cfg_file)
END IF
END SUBROUTINE write_cfg
SUBROUTINE write_lammps(filename,xx,natoms,lxx,io_quit,ele_type,ele_mass,xee)
use accuracy
use file_units
IMPLICIT NONE
INTEGER, intent(in) :: natoms
REAL(KIND=DBL), intent(in) :: lxx(3),xx(natoms,3),xee(natoms,3)
CHARACTER (LEN=500), intent(in) :: filename
INTEGER, intent(inout) :: io_quit
INTEGER :: output(natoms),to_output(natoms)
CHARACTER (LEN=2), intent(in) :: ele_type(natoms)
INTEGER, intent(in) :: ele_mass(natoms)
INTEGER :: noutput
CHARACTER (LEN=2) :: current_ele
LOGICAL :: newblock
INTEGER :: i,currentistart,atom_types,j
CHARACTER (LEN=100) outstr
io_quit=0
!DO i=1,natoms
! PRINT *,i,ele_type(i),ele_mass(i)
!END DO
OPEN(unit=lammps_file,file=TRIM(ADJUSTL(filename)),STATUS='REPLACE',IOSTAT=io_quit)
IF(io_quit==0) THEN
WRITE (lammps_file,'(A)') 'lammps configuration output file'
WRITE (lammps_file,'(I10,A10)') natoms,'atoms'
WRITE(lammps_file,'(2e16.8,A15)') 0d0,lxx(1),' xlo xhi'
WRITE(lammps_file,'(2e16.8,A15)') 0d0,lxx(2),' ylo yhi'
WRITE(lammps_file,'(2e16.8,A15)') 0d0,lxx(3),' zlo zhi'
WRITE(lammps_file,'(3e16.8,A15)') 0d0,0d0,0d0,'xy xz yz'
! count atom types
atom_types=1
to_output(1)=1
outer: DO i=1,natoms
DO j=1,atom_types
IF((ele_mass(i)==ele_mass(to_output(j))).AND. &
(TRIM(ADJUSTL(ele_type(i)))==TRIM(ADJUSTL(ele_type(to_output(j)))))) THEN
output(i)=j
cycle outer
END IF
END DO
! if we get here then we haven't found a match
atom_types=atom_types+1
to_output(atom_types)=i
output(i)=atom_types
END DO outer
WRITE(lammps_file,'(I5,A15)') atom_types,' atom types'
WRITE(lammps_file,'(A10)') 'Masses'
WRITE(lammps_file,*)
DO i=1,atom_types
WRITE(lammps_file,'(I5,I10)') i,ele_mass(to_output(i))
END DO
WRITE(lammps_file,'(A)') 'Atoms'
WRITE(lammps_file,*)
do i=1,natoms
WRITE(lammps_file,'(I10,I5,3e16.8,A15)') i,output(i),xx(i,1),xx(i,2),xx(i,3)
end do
WRITE(lammps_file,'(A)') 'Velocities'
WRITE(lammps_file,*)
do i=1,natoms
WRITE(lammps_file,'(I10,3e16.8)') i,xee(i,1),xee(i,2),xee(i,3)
end do
END IF
IF(io_quit==0) CLOSE(lammps_file,IOSTAT=io_quit)
END SUBROUTINE write_lammps