-
Notifications
You must be signed in to change notification settings - Fork 7
/
InputOutput.f90
727 lines (579 loc) · 24.6 KB
/
InputOutput.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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
!-------------------------------------------------------------------------
! File I/O routines
!-------------------------------------------------------------------------
! Copyright (c) 2017-2018 Daniel C. Elton
!
! This software is licensed under The MIT License (MIT)
! Permission is hereby granted, free of charge, to any person obtaining a copy of this
! software and associated documentation files (the "Software"), to deal in the Software
! without restriction, including without limitation the rights to use, copy, modify, merge,
! publish, distribute, sublicense, and/or sell copies of the Software, and to permit
! persons to whom the Software is furnished to do so, subject to the following conditions:
!
! The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
!
! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
! BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
! NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
! DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
!-------------------------------------------------------------------------------------
module InputOutput
use main_vars
use lun_management
implicit None
contains
!------------------------------------------------------------
!----------- Read input file parameters --------------------
!------------------------------------------------------------
subroutine read_input_files
use dans_timer
implicit none
integer :: luninp, Nlines, EoF
real(8) :: a, c, a1, a2, a3, denom
real(8) :: MC = 12.011000, MN = 14.007200, MO = 15.999430, MH = 1.0080000, MSi=28.0855
real(8) :: MMg = 24.305, MHf = 178.49, MS = 32.065
real(8) :: n(3)
!call io_assign(luninp)
!open(luninp, file="PhononSED.inp", status='old', action='read')
luninp = 5 !read from terminal standard in
read(luninp, *) model
read(luninp, *) fileheader
read(luninp, *) Nunitcells
read(luninp, *) Nk
read(luninp, *) Neig
read(luninp, *) fvel
read(luninp, *) feig
read(luninp, *) C_TYPE_EIGENVECTOR
read(luninp, *) fcoord
read(luninp, *) SUPERCELL_EIGENVECTOR
read(luninp, *) Ntimesteps
read(luninp, *) timestep
read(luninp, *) READALL
read(luninp, *) NPointsOut
read(luninp, *) BTEMD
read(luninp, *) GULPINPUT
read(luninp, *) Ncorrptsout
!call io_close(luninp)
!-------------------- RDX ------------------------------------------------
if (model == 'RDX') then
write(*,*) "Model is RDX"
AtomsPerMolecule = 21
MoleculesPerUnitCell = 8
AtomsPerUnitCell = AtomsPerMolecule*MoleculesPerUnitCell !168
Natoms = Nunitcells*AtomsPerUnitCell
! Assume equal number of PUC tiling in each lattice vector direction
Nx = int(Nunitcells**(1./3.))
Ny = int(Nunitcells**(1./3.))
Nz = int(Nunitcells**(1./3.))
allocate(MassPrefac(Natoms))
allocate(freqs(Nk, Neig))
allocate(eig_vecs(Nk, Neig, Natoms, 3))
!build array of masses for ALL atoms
idx = 1
do i = 1, Nunitcells
do j = 1, MoleculesPerUnitCell
MassPrefac(idx+0:idx+2) = MC ! Carbon
MassPrefac(idx+3:idx+8) = MN ! Nitrogen
MassPrefac(idx+9:idx+14) = MO ! Oxygen
MassPrefac(idx+15:idx+20) = MH ! Hydrogen
idx = idx + AtomsPerMolecule
enddo
enddo
MassPrefac = sqrt(MassPrefac/real(Nunitcells))
a1 = 13.18200 !x
a2 = 11.5741 !y
a3 = 10.709 !z
lattice_vector(1,:) = (/ a1, 0.d0, 0.d0 /)
lattice_vector(2,:) = (/ 0.d0, a2, 0.d0 /)
lattice_vector(3,:) = (/ 0.d0, 0.d0, a3 /)
! Tile lattice vectors such that they are commensurate with the SC used in the MD simulations (this will have knock on effects with regard to the
! reciprocal lattice vectors and wherever they are used)
lattice_vector(1,:) = Nx*lattice_vector(1,:)
lattice_vector(2,:) = Ny*lattice_vector(2,:)
lattice_vector(3,:) = Nz*lattice_vector(3,:)
denom = a1*a2*a3
recip_lat_vec(1,:) = (/ a2*a3 , 0.d0 , 0.d0 /) !! Perpendicularity assumed!!
recip_lat_vec(2,:) = (/ 0.d0 ,a1*a3 , 0.d0 /) !! Perpendicularity assumed!!
recip_lat_vec(3,:) = (/ 0.d0 , 0.d0 , a2*a3 /) !! Perpendicularity assumed!!
recip_lat_vec = TwoPi*recip_lat_vec/denom
!-------------------- Magnesium Oxide (MgO) -------------------------------
else if (model == 'MgO') then
write(*,*) "Model is MgO"
AtomsPerMolecule = 8
MoleculesPerUnitCell = 1
AtomsPerUnitCell = AtomsPerMolecule*MoleculesPerUnitCell !168
Natoms = Nunitcells*AtomsPerUnitCell
! Assume equal number of PUC tiling in each lattice vector direction
Nx = int(Nunitcells**(1./3.))
Ny = int(Nunitcells**(1./3.))
Nz = int(Nunitcells**(1./3.))
allocate(MassPrefac(Natoms))
allocate(freqs(Nk, Neig))
allocate(eig_vecs(Nk, Neig, Natoms, 3))
!build array of masses for ALL atoms
!idx = 1
!do i = 1, Nunitcells
! do j = 1, MoleculesPerUnitCell
! MassPrefac(idx+0:idx+3) = MMg ! Carbon
! MassPrefac(idx+4:idx+7) = MO ! Nitrogen
! idx = idx + AtomsPerMolecule
! enddo
!enddo
MassPrefac(1:int(Natoms/2)) = MMg
MassPrefac(int(Natoms/2)+1:Natoms) = MO
MassPrefac = sqrt(MassPrefac/real(Nunitcells))
a1 = 4.211986 !x
a2 = 4.211986 !y
a3 = 4.211986 !z
lattice_vector(1,:) = (/ a1, 0.d0, 0.d0 /)
lattice_vector(2,:) = (/ 0.d0, a2, 0.d0 /)
lattice_vector(3,:) = (/ 0.d0, 0.d0, a3 /)
! Tile lattice vectors such that they are commensurate with the SC used in the MD simulations (this will have knock on effects with regard to the
! reciprocal lattice vectors and wherever they are used)
lattice_vector(1,:) = Nx*lattice_vector(1,:)
lattice_vector(2,:) = Ny*lattice_vector(2,:)
lattice_vector(3,:) = Nz*lattice_vector(3,:)
denom = a1*a2*a3
recip_lat_vec(1,:) = (/ a2*a3 , 0.d0 , 0.d0 /) !! Perpendicularity assumed!!
recip_lat_vec(2,:) = (/ 0.d0 ,a1*a3 , 0.d0 /) !! Perpendicularity assumed!!
recip_lat_vec(3,:) = (/ 0.d0 , 0.d0 , a2*a3 /) !! Perpendicularity assumed!!
!-------------------- Silicon (Si) -------------------------------
else if (model .eq. 'silicon') then
write(*,*) "Model is silicon"
AtomsPerMolecule = 2
MoleculesPerUnitCell = 1
AtomsPerUnitCell = AtomsPerMolecule*MoleculesPerUnitCell !2
Natoms = Nunitcells*AtomsPerUnitCell !2
! Assume equal number of PUC tiling in each lattice vector direction
Nx = int(Nunitcells**(1./3.))
Ny = int(Nunitcells**(1./3.))
Nz = int(Nunitcells**(1./3.))
allocate(MassPrefac(Natoms))
allocate(freqs(Nk, Neig))
allocate(eig_vecs(Nk, Neig, Natoms, 3))
!build array of masses for ALL atoms
MassPrefac = MSi
MassPrefac = sqrt(MassPrefac/real(Nunitcells))
a1 = 2*2.7285d0 !x
a2 = 2*2.7285d0 !y
a3 = 2*2.7285d0 !z
lattice_vector(1,:) = 0.5*(/ 0.d0, a2, a3 /)
lattice_vector(2,:) = 0.5*(/ a1, 0.d0, a3 /)
lattice_vector(3,:) = 0.5*(/ a1, a2, 0.d0 /)
! Tile lattice vectors such that they are commensurate with the SC used in the MD simulations (this will have knock on effects with regard to the
! reciprocal lattice vectors and wherever they are used)
lattice_vector(1,:) = Nx*lattice_vector(1,:)
lattice_vector(2,:) = Ny*lattice_vector(2,:)
lattice_vector(3,:) = Nz*lattice_vector(3,:)
denom = DOT_PRODUCT(lattice_vector(1,:),CrossProd(lattice_vector(2,:),lattice_vector(3,:)))
recip_lat_vec(1,:) = CrossProd(lattice_vector(2,:),lattice_vector(3,:))
recip_lat_vec(2,:) = CrossProd(lattice_vector(3,:),lattice_vector(1,:))
recip_lat_vec(3,:) = CrossProd(lattice_vector(1,:),lattice_vector(2,:))
recip_lat_vec = TwoPi*recip_lat_vec/denom
!-------------------- Halfnium disulphide (Si) -------------------------------
else if (model .eq. 'HfS2') then
write(*,*) "Model is HfS2 (halfnium disulphide)"
AtomsPerMolecule = 3
MoleculesPerUnitCell = 1
AtomsPerUnitCell = AtomsPerMolecule*MoleculesPerUnitCell !3
Natoms = Nunitcells*AtomsPerUnitCell
! Assume equal number of PUC tiling in each lattice vector direction
Nx = int(Nunitcells**(1./3.))
Ny = int(Nunitcells**(1./3.))
Nz = int(Nunitcells**(1./3.))
allocate(MassPrefac(Natoms))
allocate(freqs(Nk, Neig))
allocate(eig_vecs(Nk, Neig, Natoms, 3))
!build array of masses for ALL atoms
MassPrefac(1:int(Natoms/3)) = MHf
MassPrefac(int(Natoms/3)+1:Natoms) = MS
MassPrefac = sqrt(MassPrefac/real(Nunitcells))
!! Hexagonal closed packed cell parameters must be entered by hand here!!
a = 3.6529
c = 5.6544
lattice_vector(1,:) = (/ a, 0.d0, 0.d0/)
lattice_vector(2,:) = (/ -0.5*a, dsqrt(3.d0)/(2.d0*a), 0.d0 /)
lattice_vector(3,:) = (/ 0.d0, 0.d0, c /)
! Tile lattice vectors such that they are commensurate with the SC used in the MD simulations (this will have knock on effects with regard to the
! reciprocal lattice vectors and wherever they are used)
lattice_vector(1,:) = Nx*lattice_vector(1,:)
lattice_vector(2,:) = Ny*lattice_vector(2,:)
lattice_vector(3,:) = Nz*lattice_vector(3,:)
denom = DOT_PRODUCT(lattice_vector(1,:),CrossProd(lattice_vector(2,:),lattice_vector(3,:)))
recip_lat_vec(1,:) = CrossProd(lattice_vector(2,:),lattice_vector(3,:))
recip_lat_vec(2,:) = CrossProd(lattice_vector(3,:),lattice_vector(1,:))
recip_lat_vec(3,:) = CrossProd(lattice_vector(1,:),lattice_vector(2,:))
recip_lat_vec = TwoPi*recip_lat_vec/denom
else
write(*,*) "ERROR : model not found!!"
endif
!------------- read length of velocities file ------------------------------
if (READALL) then
write(*,*) "Reading size of file ..."
Nlines = 0
call io_assign(lun)
open(lun, file=fvel, status='old', action='read')
do
read(lun, *, iostat=EoF)
if (.not.(EoF .eq. 0)) then
exit
else
Nlines = Nlines + 1
endif
enddo
Ntimesteps = floor(real(Nlines)/real(Natoms+9)) - 1
write(*, *) "There are ", Ntimesteps, " timesteps in the file"
call io_close(lun)
endif
!------------- allocations ----------- ------------------------------
allocate(qdot(Ntimesteps))
allocate(k_vectors(Nk, 3))
allocate(r_eq(Natoms, 3))
allocate(r(Natoms, 3))
!read in eigenvectors we will be working with
if (pid .eq. 0) call start_timer("reading files")
if (pid .eq. 0) write(*, *) "reading eigenvector file... "
call read_eigvector_file
!read in necessary velocities & coordinate data
if (pid .eq. 0) write(*, *) "reading velocities file... "
if (GULPINPUT) then
call read_GULP_trajectory_file
else
call read_LAAMPS_files
endif
!!! PBC correction
! Vectors for PBC mapping
P0(1,:) = (/ 0.d0, 0.d0, 0.d0 /)
P0(2,:) = P0(1,:)
P0(3,:) = P0(2,:)
P0(4,:) = lattice_vector(1,:) + lattice_vector(2,:) + lattice_vector(3,:)
P0(5,:) = P0(4,:)
P0(6,:) = P0(5,:)
normal(1,:) = CrossProd(lattice_vector(3,:),lattice_vector(2,:))
normal(2,:) = CrossProd(lattice_vector(1,:),lattice_vector(3,:))
normal(3,:) = CrossProd(lattice_vector(2,:),lattice_vector(1,:))
normal(4,:) = -normal(1,:)
normal(5,:) = -normal(2,:)
normal(6,:) = -normal(3,:)
boxmap(1,:) = lattice_vector(1,:)
boxmap(2,:) = lattice_vector(2,:)
boxmap(3,:) = lattice_vector(3,:)
boxmap(4,:) = -lattice_vector(1,:)
boxmap(5,:) = -lattice_vector(2,:)
boxmap(6,:) = -lattice_vector(3,:)
do ia = 1,Natoms
do i = 1, 6
r_eq(ia,:) = MapPBC(P0(i,:),normal(i,:),r_eq(ia,:),boxmap(i,:))
end do
end do
if (C_TYPE_EIGENVECTOR) then
write(*,*) "using equilibrium coords from GULP eig file , for use with C-type eigenvector representation ..."
r = r_eq
!do i = 1, Natoms
! write(*,*) r(i, :)
!enddo
!--- deprecated option to read equlibrium coordinates from an external file
!write(*, *) "Since there is no GULP trajectory input, attempting to read equilibrium coords from external file..."
!call io_assign(lun)
!open(lun, file=fcoord, status='old', action='read')
!r = one_frame_xyz(lun)
!call io_close(lun)
else
if (pid .eq. 0) write(*, *) "generating unit cell coordinates for use with D-type eigenvector representation ..."
!---- figure out equilibrium unit cell coordinates
!---- this calculates the coordinate for the corner of the unit cell each atom is in
!----
!---- Here we work under the assumption that our simulation cell is the unit cell and therefore the lattice point is at 0.0
do ia = 1, Natoms
do ix = 1, 3
r(ia, ix) = 0.d0 ! floor(r_eq(ia,ix)/lattice_vector(ix,ix))*lattice_vector(ix,ix)
enddo
enddo
endif
end subroutine read_input_files
!------------------------------------------------------------
!---------------- Read eigenvector file --------------------
!------------------------------------------------------------
subroutine read_eigvector_file()
integer :: Natoms_file, Neig_file, my_iostat
real(8) :: mag
double precision, dimension(3) :: realpart, cmplxpart
character(len=10) :: junk, space
call io_assign(luneig)
open(luneig, file=feig, status='old', action='read')
read(luneig, *) Natoms_file
if ((AtomsPerUnitCell .gt. Natoms_file)) then
write(*,*) "ERROR: N_atoms in eigenvector file ( ", Natoms_file," ) is", &
" less than the expected number of atoms per unit cell (", &
AtomsPerUnitCell, ")"
stop
endif
if (SUPERCELL_EIGENVECTOR) then
if ((Natoms .gt. Natoms_file)) then
write(*, *) "WARNING.. I am looking for eigenvectors for a supercell representation &
in the input .eig file. I don't see enough atoms. Continuing anyway.."
endif
else
if ((AtomsPerUnitCell .lt. Natoms_file)) then
write(*,*) "WARNING: N_atoms in eigenvector file ( ", Natoms_file," ) is", &
" greater than the expected number of atoms per unit cell (", &
AtomsPerUnitCell, "). I assume you know what you are doing &
and will continue to see what happens... You may want to make sure &
supercell representation is set to TRUE in the input file."
endif
endif
write(*,*) "reading equilibrium coordinates from GULP eigenvector file..."
do ia = 1, Natoms_file
read(luneig, *) junk, (r_eq(ia, ix), ix = 1,3)
enddo
read(luneig, *) !int
read(luneig, *) Neig_file
write(*,'(a,i4,a)') "File contains ", Neig_file, " eigenvectors per k-point"
if (Neig .gt. Neig_file) then
write(*,*) "ERROR: Neig specified is larger than the number of &
eigenvectors in the input file."
stop
endif
do ik = 1, Nk
read(luneig, '(a,3f9.6)') junk, (k_vectors(ik, ix), ix = 1,3)
k_vectors(ik, 1) = k_vectors(ik, 1)*recip_lat_vec(1,1)/TwoPi
k_vectors(ik, 2) = k_vectors(ik, 2)*recip_lat_vec(2,2)/TwoPi
k_vectors(ik, 3) = k_vectors(ik, 3)*recip_lat_vec(3,3)/TwoPi
do ie = 1, Neig
read(luneig, *) !Mode x
read(luneig, *) freqs(ik, ie)
mag = 0
do ia = 1, Natoms_file
if (ik .eq. 1) then
read(luneig, *) realpart(1), realpart(2), realpart(3)
do ix = 1, 3
eig_vecs(ik, ie, ia, ix) = dcmplx(realpart(ix), 0)
enddo
else
read(luneig, *, iostat=my_iostat) realpart(1), realpart(2), realpart(3), cmplxpart(1), cmplxpart(2), cmplxpart(3)
if (my_iostat /= 0) then
write(*,*) 'WARNING: missing complex part of eigenvector in k=', ik, ' ieig = ', ie
backspace(luneig)
my_iostat = 0
read(luneig, *, iostat=my_iostat) realpart(1), realpart(2), realpart(3), space, &
cmplxpart(1), cmplxpart(2), cmplxpart(3)
if (my_iostat /= 0) then
write(*,'(a,i3,a,i3)') 'WARNING: error reading cmplx eigenvector for k=', ik, ' mode # = ', ie
read(luneig, *, iostat=my_iostat) realpart(1), realpart(2), realpart(3)
cmplxpart(:) = 0
endif
my_iostat = 0
endif
do ix = 1, 3
eig_vecs(ik, ie, ia, ix) = dcmplx(realpart(ix), cmplxpart(ix))
enddo
endif
mag = mag + real(eig_vecs(ik, ie, ia, 1)*conjg(eig_vecs(ik, ie, ia, 1)) + &
eig_vecs(ik, ie, ia, 2)*conjg(eig_vecs(ik, ie, ia, 2)) + &
eig_vecs(ik, ie, ia, 3)*conjg(eig_vecs(ik, ie, ia, 3)) )
enddo !do ia = 1, Natoms_file
mag = sqrt(mag)
eig_vecs(ik, ie, 1:AtomsPerUnitCell, :) = eig_vecs(ik, ie, 1:AtomsPerUnitCell, :)/mag !make a unit vector (normalization)
if (.not. SUPERCELL_EIGENVECTOR) then
!copy eigenvectors from 0,0,0 unit cell to other unit cells
j = AtomsPerUnitCell
do i = 2, Nunitcells
eig_vecs(ik, ie, (i-1)*j+1 : (i-1)*j+j, :) = eig_vecs(ik, ie, 1:j, :) !fill in rest
enddo
!do j = 2, AtomsPerUnitCell
! do i = 2, Nunitcells
! eig_vecs(ik, ie, (i-1)*j+1 : (i-1)*j+j, :) = eig_vecs(ik, ie, 1:j, :) !fill in rest
!enddo
endif
enddo !do ie = 1, Neig
!do ia = 1, Natoms
! write(*,*) eig_vecs(1, 1, ia, :)
!enddo
! read any remaining eigenvectors ls
do ie = Neig+1, Neig_file
read(luneig, *) !Mode x
read(luneig, *) !freqs
do ia = 1, Natoms_file
read(luneig, *)
enddo
enddo
enddo !ik = 1, Nk
end subroutine read_eigvector_file
!-----------------------------------------------------------------------
!----------------- Read in necessary LAMMPS files ---------------------
!-----------------------------------------------------------------------
subroutine read_LAAMPS_files
implicit none
integer :: lun
!------------- read velocities file ------
call io_assign(lun)
open(lun, file=fvel, status='old', action='read')
allocate(velocities(Ntimesteps, Natoms, 3))
do t = 1, Ntimesteps
if (mod(t,1000).eq.0) write(*,*) t, Ntimesteps
velocities(t, :, :) = one_frame(lun)
enddo
call io_close(lun)
!---------- read in coordinates data for BTEMD --------
if (BTEMD) then
write(*, *) "reading coordinates file... "
call io_assign(lun)
open(lun, file=fcoords, status='old', action='read')
allocate(coordinates(Ntimesteps, Natoms, 3))
do t = 1, Ntimesteps
if (mod(t,1000).eq.0) write(*,*) t, Ntimesteps
coordinates(t, :, :) = one_frame(lun)
enddo
call io_close(lun)
endif !BTEMD
end subroutine read_LAAMPS_files
!-----------------------------------------------------------------------
!----------------- Read in GULP trajectory file -----------------------
!-----------------------------------------------------------------------
subroutine read_GULP_trajectory_file
implicit none
integer :: lun
character(20) :: junk
call io_assign(lun)
open(lun, file=fvel, status='old', action='read')
allocate(velocities(Ntimesteps, Natoms, 3))
read(lun, *)
read(lun, *)
do t = 1, Ntimesteps
if (mod(t,1000).eq.0) write(*,*) "reading", t, Ntimesteps
do i = 1, 3
read(lun, *) junk
enddo
do ia = 1, Natoms
read(lun, *) !coordinates
enddo
read(lun, *)
do ia = 1, Natoms
read(lun, '(3ES26.16E2)') (velocities(t, ia, ix), ix=1,3)
!if (t .eq. 1) then
! write(*,*) velocities(t, ia, :)
!endif
enddo
do ia = 1, 2*Natoms+2
read(lun, *) !skip derivatives & site energies data
enddo
enddo
call io_close(lun)
end subroutine read_GULP_trajectory_file
!-----------------------------------------------------------------------
!----------------- Read in .vel file from Quantum Espresso ------------
!-----------------------------------------------------------------------
subroutine read_quantum_espresso
implicit none
integer :: lun
!------------- read velocities file ------
call io_assign(lun)
open(lun, file=fvel, status='old', action='read')
allocate(velocities(Ntimesteps, Natoms, 3))
do t = 1, Ntimesteps
if (mod(t,1000).eq.0) write(*,*) "reading: ", t, "of", Ntimesteps
velocities(t, :, :) = one_frame_xyz(lun, .false.)
enddo
call io_close(lun)
end subroutine read_quantum_espresso
!-----------------------------------------------------------------------
!----------------- Read one frame of velocities file ------------------
!-----------------------------------------------------------------------
function one_frame(lun)
implicit none
real(8), dimension(Natoms, 3) :: one_frame
integer, intent(in) :: lun
integer :: Natoms_file
read(lun,*) !ITEM: TIMESTEP
read(lun,*) !timestep
read(lun,*) !ITEM: NUMBER OF ATOMS
read(lun,*) Natoms_file
if (.not.(Natoms .eq. Natoms_file)) then
write(*,*) "ERROR: N_atoms in velocity file ( ", Natoms_file," ) does", &
" not match expected total number of atoms (", &
Natoms, ")"
stop
endif
read(lun,*) !ITEM: BOX BOUNDS
read(lun,*) box(1, :) !bounding box
read(lun,*) box(2, :)
read(lun,*) box(3, :)
read(lun,*) !comment line
!read velocities
do ia = 1, Natoms
read(lun,*) (one_frame(ia, ix), ix=1,3)
enddo
end function one_frame
!-----------------------------------------------------------------------
!----------------- Read one frame of a standard .xyz file -------------
!-----------------------------------------------------------------------
function one_frame_xyz(lun, has_comment_line)
implicit none
real(8), dimension(Natoms, 3) :: one_frame_xyz
integer, intent(in) :: lun
logical, optional :: has_comment_line
integer :: Natoms_file
character(2) :: junk
if (.not. present(has_comment_line)) then
has_comment_line = .true.
endif
read(lun,*) Natoms_file
if (has_comment_line) read(lun,*) !comment line
do ia = 1, Natoms
read(lun,*) junk, (one_frame_xyz(ia, ix), ix=1,3)
enddo
end function one_frame_xyz
!---------------------------------------------------------------------
!----------------- Print SED and other outputs ---------------------
!---------------------------------------------------------------------
subroutine print_SED
implicit none
do ik = 1, Nk
call io_open(lunout, filename=trim(fileheader)//"_"//trim(str(ik))//"_SED.dat")
do i = 1, NPointsOut
write(lunout, '(f12.4,1x)', advance='no') freqs_smoothed(i)
do ie = 1, Neig-1
write(lunout, '(e12.6,1x)', advance='no') all_SED_smoothed(ik, ie, i)
enddo
write(lunout, '(e12.6)', advance='yes') all_SED_smoothed(ik, Neig, i)
enddo
call io_close(lunout)
call io_open(lunout, filename=trim(fileheader)//"_"//trim(str(ik))//"_frequencies.dat")
do ie = 1, Neig
write(lunout, '(f12.5,1x)') freqs(ik, ie)
enddo
call io_close(lunout)
enddo !ie = 1, Neig
call io_open(lunout, filename=trim(fileheader)//"_kvectors.dat")
do ik = 1, Nk
write(lunout,'(f5.3,1x,f5.3,1x,f5.3)') (k_vectors(ik, ix), ix = 1,3)
enddo
call io_close(lunout)
end subroutine print_SED
!---------------------------------------------------------------------
!----------------- Print SED ---------------------------------------
!---------------------------------------------------------------------
subroutine print_corr_fns
implicit none
do ik = 1, Nk
call io_open(lunout, filename=trim(fileheader)//"_"//trim(str(ik))//"_cor_fun.dat")
do i = 1, Ncorrptsout
write(lunout, '(f12.4,1x)', advance='no') i*timestep
do ie = 1, Neig-1
write(lunout, '(e12.6,1x)', advance='no') all_corr_fns(ik, ie, i)
enddo
write(lunout, '(e12.6)', advance='yes') all_corr_fns(ik, Neig, i)
enddo
call io_close(lunout)
enddo !ie = 1, Neig
end subroutine print_corr_fns
!---------------------------------------------------------------------
!-----------------Convert an integer to string ----------------------
!---------------------------------------------------------------------
character(len=20) function str(k)
integer, intent(in) :: k
write (str, *) k
str = adjustl(str)
end function str
end module InputOutput