-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget-allowed-3ph.f90
More file actions
1284 lines (1284 loc) · 43.5 KB
/
get-allowed-3ph.f90
File metadata and controls
1284 lines (1284 loc) · 43.5 KB
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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
program get_allowed
!
! A program to calculate the allowed 3-phonon interactions given
! a set of omega,q (read from a file). The code checks for transitions
! that conserve energy and quasi-momentum. For each mode lambda (where
! lambda combines q point and mode frequency), all pairs of modes that
! correspond to phonon decays or collisions are found.
!
! Following Togo et al PRB 91 094306 (2015), this code aims to find
! the allowed transitions that contribute to the phonon linewidth,
! Eq. 11. In this way, it is possible to see what scattering processes
! should be important in a material without doing the full 3-phonon
! force constants calculation.
!
! *******************
! This version differs in that the mesh.yaml file is read in directly
! to get the q points and frequencies, rather than having it converted
! first using the phonopy-mesh-convert-yaml.sh script
! *******************
!
! For each i, all pairs j,k are found that consist of allowed transitions.
! The output is:
! (1) a 3D set of coordinates of omega_i, omega_j, omega_k (each point
! is an allowed transition)
! (2) The 2 phonon joint DOS (Eq. 19 of Togo's paper)
! (3) The 2 phonon JDOS with occupations (Eqs. 23 and 24 of the paper)
! For this calc a temperature is needed and is requested from the
! user.
!
! Moreover, if a phonon band structure calculation has been performed,
! so that the file band.yaml exists, the code checks if any of the
! transitions correspond to (q,omega) points present in the band calc.
! If so, a file containing lines that can be plotted to show the allowed
! transitions is produced
!
! J. Buckeridge November 2019
!
implicit none
!
integer, parameter :: nmax = 1e5
integer, parameter :: nsmaller = 1e3
integer, parameter :: maxang = 360
real*8, parameter :: tiny = 1.d-12
real*8, parameter :: big = 1.d12
real*8, parameter :: small = 1.d-5
real*8, parameter :: kboltz = 8.617343d-5 ! Boltzmann constant (eV/K)
integer i, j, k, inew1, inew2, jnew1, jnew2, m, n, p, q
integer stat, nqpts, natom, nmode, nlambda, countc, countd
integer ngamma, nzero, idist1, idist2
integer ilbrack, icomma, len1, mesh(3), meshqpts
integer jmin, kmin, jlammin, nomin
integer bznqpts, bznatom, nbzgamma, totequiv
integer memtest, nunique, ibzequiv
integer iqchk, ijval, tmpqpt(3)
integer, allocatable :: bzngamma(:), omin(:,:), nequiv(:), equivqpt(:,:)
integer, allocatable :: idegen(:)
real*8 pi, scale, factor, lattvec(3,3), reclatt(3,3), gvec(3), vol
real*8 brlatt(3,3)
real*8 omegamax, omegamin, distmin, dist, maxqcpt, enertest, qptest
real*8 etestc1, etestc2, etestd
real*8 temperature, occ1, occ2, occ3
real*8 tmpom1(3), tmpom2(3)
real*8, allocatable :: qpt(:,:), qpt_c(:,:), omega(:,:), distg(:)
real*8, allocatable :: bzqpt(:,:), bzqpt_c(:,:), bzomega(:,:), bzdistg(:)
real*8, allocatable :: d21dos(:,:), d22dos(:,:)
real*8, allocatable :: n21dos(:,:), n22dos(:,:)
character*80 str1
character*5 unit
character*1 lbrack, comma, colon
logical checkg, checkq(3), checkqtot, checkomin, checkjdos
logical checkbz, checkrec, checkgam, checkequiv
!
pi = acos(-1.d0)
!
write(*,'(a)') "**************************************************************"
write(*,'(a)')
write(*,'(a)') " 333 PPP H"
write(*,'(a)') " 3 P P H"
write(*,'(a)') " 3 -- PPP HHH OOO NNN OOO NNN "
write(*,'(a)') " 3 P H H O O N N O O N N"
write(*,'(a)') " 333 P H H OOO N N OOO N N"
write(*,'(a)')
write(*,'(a)') " TTTTT SSS T SSS"
write(*,'(a)') " T S T S"
write(*,'(a)') " T RRR AAA NNN SSS I TTT I OOO NNN SSS"
write(*,'(a)') " T R A A N N S I T I O O N N S"
write(*,'(a)') " T R AAAA N N SSS I TT I OOO N N SSS"
write(*,'(a)')
write(*,'(a)')
write(*,'(a)') "j.buckeridge@ucl.ac.uk 2019"
write(*,'(a)') "**************************************************************"
write(*,'(a)')
!
! First check for unit.dat file in which to read in the chosen units.
! If it is not present, default to cm-1
!
write(*,*)
write(*,'(a)') "Checking for unit.dat file to read in units..."
open(unit=11,file="unit.dat",status="old",iostat=stat)
!
if(stat /= 0) then
write(*,'(a)') "WARNING: unit.dat not found. Assuming cm-1..."
scale = 1.d0 / 8065.54429d0
else
!
! Found the file. Change the scale variable accordingly
!
write(*,'(a)') "Found unit.dat file - attempting to read units..."
do
read(11,'(a)') str1
if(str1(1:1) == "#") cycle
read(str1,*,iostat=stat) unit
if(unit(1:1) == "c" .or. unit(1:1) == "C") then
write(*,'(a)') "Found units of cm-1..."
scale = 1.d0 / 8065.54429d0
elseif(unit(1:1) == "m" .or. unit(1:1) == "M") then
write(*,'(a)') "Found units of meV..."
scale = 1.d-3
elseif(unit(1:1) == "t" .or. unit(1:1) == "T") then
write(*,'(a)') "Found units of THz..."
scale = 1.d0 / 241.8d0
elseif(unit(1:1) == "e" .or. unit(1:1) == "E") then
write(*,'(a)') "Found units of eV..."
scale = 1.d0
else
write(*,'(a)') "ERROR: failed to read in units from unit.dat!"
write(*,'(a)') " I will assume cm-1..."
scale = 1.d0 / 8065.54429d0
endif
exit
enddo
close(unit=11)
endif
!
write(*,*)
write(*,'(a)') "Opening mesh.yaml to read input..."
open(unit=11,file="mesh.yaml",status="old",iostat=stat)
!
if(stat /= 0) then
write(*,'(a)') "ERROR: cannot find mesh.yaml file!!"
stop
else
write(*,'(a)') "Found mesh.yaml. Checking q mesh..."
endif
!
! To read in data from yaml, need to extract substrings and remove trailing
! commas. For this we need to define two useful substrings:
!
lbrack = "["
comma = ","
colon = ":"
!
! Read in mesh dimensions - need to separate out strings in order to do
! this and avoid trailing commas
!
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("mesh ",0,0,stat)
len1 = len(trim(str1))
ilbrack = index(str1,lbrack) + 1
str1 = str1(ilbrack:len1)
icomma = index(str1,comma) - 1
read(str1(1:icomma),*,iostat=stat) mesh(1)
if(stat /= 0) call error_read("mesh 1",0,0,stat)
len1 = len(trim(str1))
ilbrack = icomma + 2
str1 = str1(ilbrack:len1)
icomma = index(str1,comma) - 1
read(str1(1:icomma),*,iostat=stat) mesh(2)
if(stat /= 0) call error_read("mesh 2",0,0,stat)
len1 = len(trim(str1)) - 1
ilbrack = icomma + 2
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) mesh(3)
if(stat /= 0) call error_read("mesh 3",0,0,stat)
write(*,'(a16,3(x,i3))') "Mesh dimensions:", (mesh(i),i=1,3)
!
! Now read in number of qpts from file
!
read(11,'(a)') str1
if(stat /= 0) call error_read("qpts ",0,0,stat)
ilbrack = index(str1,colon) + 1
len1 = len(trim(str1))
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) nqpts
if(stat /= 0) call error_read("nqpts ",0,0,stat)
!
! Check that the mesh dimensions and number of qpts are compatible.
! If there are less qpts, then symmetry has been used, which this code
! cannot deal with. If the number of qpts is too large, f knows what
! happened but it's bad
!
meshqpts = 1
do i=1,3
meshqpts = meshqpts * mesh(i)
enddo
if(nqpts < meshqpts) then
write(*,*)
write(*,'(a)') "ERROR: symmetry has been used to reduce number of qpts!!"
write(*,'(a)') " I can't deal with this situation - bye!!"
stop
endif
if(nqpts > meshqpts) then
write(*,*)
write(*,'(a)') "ERROR: number of qpts is greater than what should be in the mesh!!"
write(*,'(a)') " this is too weird - bye!!"
stop
endif
!
! Next read in reciprocal lattice vectors. These must be multiplied
! by 2pi to get the correct units
!
write(*,'(a)') "Reading reciprocal lattice vectors..."
read(11,*,iostat=stat)
if(stat /= 0) call error_read("a line",0,0,stat)
do i=1,3
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("rlatt ",0,0,stat)
len1 = len(trim(str1))
ilbrack = index(str1,lbrack) + 1
str1 = str1(ilbrack:len1)
icomma = index(str1,comma) - 1
read(str1(1:icomma),*,iostat=stat) reclatt(i,1)
if(stat /= 0) call error_read("rlatt1",i,0,stat)
len1 = len(trim(str1))
ilbrack = icomma + 2
str1 = str1(ilbrack:len1)
icomma = index(str1,comma) - 1
read(str1(1:icomma),*,iostat=stat) reclatt(i,2)
if(stat /= 0) call error_read("rlatt2",i,0,stat)
len1 = len(trim(str1)) - 6
ilbrack = icomma + 2
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) reclatt(i,3)
if(stat /= 0) call error_read("rlatt3",i,0,stat)
enddo
!
reclatt(:,:) = reclatt(:,:) * 2.d0 * pi
!
write(*,'(a)') "...done"
!
! Now read in the number of atoms N. There will be 3N modes at each qpt
!
write(*,'(a)') "Checking number of atoms..."
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("natom ",0,0,stat)
ilbrack = index(str1,colon) + 1
len1 = len(trim(str1))
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) natom
if(stat /= 0) call error_read("natom ",0,0,stat)
!
! Report the number of atoms
!
write(*,'(a31,x,i3)') "Number of atoms in your system:", natom
!
! Set the number of modes = 3 * natom
!
nmode = 3 * natom
nlambda = nqpts * nmode
write(*,'(a9,x,i8,x,a16)') "There are", nlambda, "(q,omega) points"
!
! Skip several lines in the yaml file where the lattice type and info on
! the atoms is given. We don't need this info
!
do i=1,5
read(11,*,iostat=stat)
if(stat /= 0) call error_read("a line",0,0,stat)
enddo
do i=1,natom
do j=1,3
read(11,*,iostat=stat)
if(stat /= 0) call error_read("a line",0,0,stat)
enddo
enddo
!
! Look for "phonon" in the next line as sometimes there are blank lines
! before this one
!
do
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("a line",0,0,stat)
if(str1(1:2) == "ph") exit
enddo
!
! Now begin reading in qpt coordinates and phonon frequencies
!
write(*,*)
write(*,'(a)') "Reading in list of q-points and frequencies ..."
!
! Allocate memory to store the qpt and omega arrays
!
allocate( qpt(3,nqpts), stat=memtest)
call mem_test("qpt ",memtest)
allocate( qpt_c(3,nqpts), stat=memtest)
call mem_test("qpt_c ",memtest)
allocate( distg(nqpts), stat=memtest)
call mem_test("distg ",memtest)
allocate( omega(nqpts,nmode), stat=memtest)
call mem_test("omega ",memtest)
do i=1,nqpts
!
! First read in qpt coordinates
!
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("qptsl ",i,0,stat)
len1 = len(trim(str1))
ilbrack = index(str1,lbrack) + 1
str1 = str1(ilbrack:len1)
icomma = index(str1,comma) - 1
read(str1(1:icomma),*,iostat=stat) qpt(1,i)
if(stat /= 0) call error_read("qpts1 ",i,0,stat)
len1 = len(trim(str1))
ilbrack = icomma + 2
str1 = str1(ilbrack:len1)
icomma = index(str1,comma) - 1
read(str1(1:icomma),*,iostat=stat) qpt(2,i)
if(stat /= 0) call error_read("qpts2 ",i,0,stat)
len1 = len(trim(str1)) - 1
ilbrack = icomma + 2
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) qpt(3,i)
if(stat /= 0) call error_read("qpts3 ",i,0,stat)
!
! Convert qpts from fractional to cartesian
!
do j=1,3
qpt_c(j,i) = 0.d0
do k=1,3
qpt_c(j,i) = qpt_c(j,i) + qpt(k,i) * reclatt(k,j)
enddo
enddo
!
! Read in distance from Gamma for each qpt
!
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("distl ",i,0,stat)
ilbrack = index(str1,colon) + 1
len1 = len(trim(str1))
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) distg(i)
if(stat /= 0) call error_read("dist ",i,0,stat)
!
! Now read in frequencies. Skip a couple of lines first
!
do j=1,2
read(11,*,iostat=stat)
if(stat /= 0) call error_read("a line",i,0,stat)
enddo
do j=1,nmode
read(11,*,iostat=stat)
if(stat /= 0) call error_read("a line",i,0,stat)
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("omegal",i,j,stat)
ilbrack = index(str1,colon) + 1
len1 = len(trim(str1))
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) omega(i,j)
if(stat /= 0) call error_read("omega ",i,j,stat)
!
! Convert to eV
!
omega(i,j) = omega(i,j) * scale
enddo
if( i < nqpts) then
read(11,*,iostat=stat)
if(stat /= 0) call error_read("a line",i,0,stat)
endif
enddo
!
close(unit=11)
!
! Check for presence of temperature.dat file. If it is present, then
! the 2 phonon JDOS will be written to file
!
checkjdos = .false.
open(unit=15,file="temperature.dat",status="old",iostat=stat)
if(stat == 0) then
write(*,'(a)') "Found temperature.dat file - attempting to read temperature..."
do
read(15,'(a)') str1
if(str1(1:1) == "#") cycle
read(str1,*,iostat=stat) temperature
if(stat /= 0) then
write(*,'(a)') "WARNING: failed to read in temperature correctly. Skipping JDOS calculation..."
exit
else
write(*,'(a19,x,f13.6,x,a1)') "Found temperature =", temperature, "K"
write(*,'(a)') "JDOS will be calculated and written to file jdos.dat"
write(*,'(a)') "NOTE: JDOS calculated here should be scaled by 1/N"
write(*,*)
checkjdos = .true.
exit
endif
enddo
close(unit=15)
else
write(*,'(a)') "No temperature.dat file present - JDOS not calculated"
write(*,*)
endif
!
! We can now deallocate qpt as it is no longer needed, unless the JDOS is
! calculated, as we will then need it for the output
!
if(checkjdos .eqv. .false.) then
deallocate(qpt,stat=memtest)
call dealloc_test("qpt ",memtest)
endif
!
! Now we need to analyse the qpts list - we need to determine what to use as our
! criteria to decide when energies and wave vectors are close enough together so
! that the delta fns in Eq. 11 (Togo) are equal to one. For wave vectors, we find
! the minimum distance between all pairs and take half that distance as the criterion.
!
! For energies it's a bit trickier. Ideally we would use the value of the three
! acoustic modes at Gamma, but Gamma may not be in our list of qpts. Also, if there
! are imaginary modes at Gamma, it's very difficult to find the zero acoustic modes.
! Also also, those modes need to be set to zero so they won't be included in the
! transitions (as they would have infinite occupation)
!
! What we will do is find the closest qpt to Gamma, find the lowest non-negative
! frequency there, and set all modes with freqs below this at Gamma to zero. We will
! then find the maximum frequency, and set the criterion as small * this frequency
!
omegamax = 0.d0
omegamin = big
ngamma = 0
write(*,*)
write(*,'(a)') "Checking data to establish values for energy and momentum checks..."
!
! Scan through all (q,omega) and check if Gamma is present, find the max omega and
! find the min omega at points away from Gamma
!
do i=1,nqpts
if( abs(distg(i)) < tiny ) then
ngamma = i
else
do j=1,nmode
if(omega(i,j) > tiny .and. omega(i,j) < omegamin) omegamin = omega(i,j)
enddo
endif
do j=1,nmode
if(omega(i,j) > omegamax) omegamax = omega(i,j)
enddo
enddo
write(*,'(a45,x,f13.7,x,a5)') "Minimum frequency in range (away from Gamma):", &
omegamin / (scale), unit
write(*,'(a45,x,f13.7,x,a5)') "Maximum frequency in range :", &
omegamax / (scale), unit
write(*,'(a)') "Energy differences less than 10^-5 times this max frequency will be deemed to be zero..."
write(*,*)
!
! We can now deallocate distg as it is no longer needed
!
deallocate(distg,stat=memtest)
call dealloc_test("distg ",memtest)
!
! If Gamma is present, set all frequencies below omegamin to zero. Report on this,
! and if any more modes beyond the three acoustic were set to zero
!
nzero = 0
if(ngamma > 0) then
write(*,'(a33,x,i6)') "Found Gamma point in list at qpt:", ngamma
write(*,'(a)') "We need to set acoustic modes here to zero..."
do i=1,nmode
if(omega(ngamma,i) < omegamin) then
omega(ngamma,i) = 0.d0
nzero = nzero + 1
endif
enddo
if(nzero == 0) then
write(*,'(a)') "WARNING: Found very unusual dispersion at Gamma. No modes with lower"
write(*,'(a)') " frequency than lowest (non-negative) mode at next closest q pt!!"
write(*,'(a)') " I will continue with the calculation but something is up with"
write(*,'(a)') " your Gamma point frequencies..."
else
write(*,'(a11,x,i3,x,a32)') "Setting the", nzero, "lowest modes to zero at Gamma..."
if(nzero > 3) write(*,'(a23,x,i3,x,a25)') "(i.e. you have at least", nzero - 3, &
"imaginary modes at Gamma)"
endif
endif
!
! Now check for imaginary modes and set them to zero so they will not be included
! in the check for transitions
!
write(*,'(a)') "Now checking for imaginary modes..."
do i=1,nqpts
do j=1,nmode
if(omega(i,j) < 0.d0) then
omega(i,j) = 0.d0
write(*,'(a16,x,i6,x,i6,x,a45)') "(q,omega) number", i, j, &
"has negative frequency and will be omitted..."
endif
enddo
enddo
write(*,'(a)') "...done"
!
! Next look for minimum distance between qpts. When it is found, get the maximum
! difference between components of the two qpts involved. Half of this will be used
! as the check to see if momentum is conserved
!
write(*,*)
write(*,'(a)') "Finding minimum distance between qpts..."
distmin = 1.d6
do i=1,nqpts
do j=1,nqpts
if(abs(qpt_c(1,i) - qpt_c(1,j)) < tiny .and. abs(qpt_c(2,i) - qpt_c(2,j)) < tiny &
.and. abs(qpt_c(3,i) - qpt_c(3,j)) < tiny) cycle
dist = 0
do k=1,3
dist = dist + ( qpt_c(k,i) - qpt_c(k,j) )**2
enddo
dist = sqrt(dist)
if(dist < distmin) then
idist1 = i
idist2 = j
distmin = dist
endif
enddo
enddo
maxqcpt = 0.d0
do i=1,3
if(abs(qpt_c(i,idist1) - qpt_c(i,idist2)) > maxqcpt) then
maxqcpt = abs(qpt_c(i,idist1) - qpt_c(i,idist2))
endif
enddo
write(*,'(a35,x,i6,x,a3,x,i6,x,a2,xf13.7,x,a3)') "Found minimum distance between qpts", &
idist1, "and", idist2, "of", distmin, "A-1"
write(*,'(a)') "Any 2 qpts where the differences between all components are less than half that"
write(*,'(a)') "of these two will be deemed to be equal..."
!
! Set the criteria for energy and momentum
!
enertest = omegamax * small
qptest = 0.5d0 * maxqcpt
!
! Now open band.yaml to read in data
!
checkbz = .false.
write(*,*)
write(*,'(a)') "Looking for band.yaml to read input..."
open(unit=11,file="band.yaml",status="old",iostat=stat)
!
if(stat /= 0) then
write(*,'(a)') "...band.yaml not found..."
else
write(*,'(a)') "Found band.yaml. Reading in data..."
checkbz = .true.
endif
!
if(checkbz) then
!
! Read in number of qpts in BZ path from file
!
read(11,'(a)') str1
if(stat /= 0) call error_read("bzqpts",0,0,stat)
ilbrack = index(str1,colon) + 1
len1 = len(trim(str1))
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) bznqpts
if(stat /= 0) call error_read("bznqpt",0,0,stat)
!
! Report the number of qpts in BZ path
!
write(*,'(a26,x,i6)') "Number of qpts in BZ path:", bznqpts
!
! Next read in reciprocal lattice vectors for the bandstructure calc.
! These must be multiplied by 2pi to get the correct units and should
! be the same as those used for the mesh calc, but if not we can still
! use the data. In some cases the reciprocal lattice may not be in the
! band.yaml file, so check for this
!
write(*,'(a)') "Reading reciprocal lattice vectors from band.yaml..."
i = 1
do
i = i+1
read(11,'(a)',iostat=stat) str1
if(stat < 0) call error_read("line ",i,0,stat)
if(str1(1:5) == "recip" .or. stat < 0) exit
enddo
if (stat >= 0) then
do i=1,3
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("blatt ",0,0,stat)
len1 = len(trim(str1))
ilbrack = index(str1,lbrack) + 1
str1 = str1(ilbrack:len1)
icomma = index(str1,comma) - 1
read(str1(1:icomma),*,iostat=stat) brlatt(i,1)
if(stat /= 0) call error_read("blatt1",i,0,stat)
len1 = len(trim(str1))
ilbrack = icomma + 2
str1 = str1(ilbrack:len1)
icomma = index(str1,comma) - 1
read(str1(1:icomma),*,iostat=stat) brlatt(i,2)
if(stat /= 0) call error_read("blatt2",i,0,stat)
len1 = len(trim(str1)) - 6
ilbrack = icomma + 2
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) brlatt(i,3)
if(stat /= 0) call error_read("blatt3",i,0,stat)
enddo
!
brlatt(:,:) = brlatt(:,:) * 2.d0 * pi
!
write(*,'(a)') "...done"
!
! Check if the reciprocal lattice vectors are different to those in mesh.yaml
!
checkrec = .false.
do i=1,3
do j=1,3
if(abs(brlatt(i,j) - reclatt(i,j)) > small) checkrec = .true.
enddo
enddo
if(checkrec) then
write(*,'(a)') "WARNING: reciprocal lattices in band.yaml and mesh.yaml are different"
write(*,*)
endif
else
write(*,'(a)') "...not found. Using reciprocal lattice vectors from mesh.yaml..."
brlatt(:,:) = reclatt(:,:)
rewind(unit=11)
endif
!
! Look for line starting with "natom" and read the number of atoms
!
do
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("natom ",0,0,stat)
if(str1(1:5) == "natom") then
ilbrack = index(str1,colon) + 1
len1 = len(trim(str1))
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) bznatom
if(stat /= 0) call error_read("natomb",0,0,stat)
exit
endif
enddo
!
! Check that the number of atoms is the same as that in mesh.yaml. If not
! then complain to the user and quit
!
if(natom /= bznatom) then
write(*,*)
write(*,'(a)') "ERROR: the number of atoms in band.yaml is incompatible with that in mesh.yaml!!"
write(*,'(a)') " I can't continue :("
stop
endif
!
! Look for line starting with "phonon"
!
do
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("phonon",0,0,stat)
if(str1(1:2) == "ph") exit
enddo
!
! Now begin reading in qpt coordinates and phonon frequencies
!
write(*,*)
write(*,'(a)') "Reading in BZ path q-points and frequencies ..."
!
! Allocate memory to store the qpt and omega arrays
!
allocate( bzqpt(3,bznqpts), stat=memtest)
call mem_test("bzqpt ",memtest)
allocate( bzqpt_c(3,bznqpts), stat=memtest)
call mem_test("bzqpt_c",memtest)
allocate( bzdistg(bznqpts), stat=memtest)
call mem_test("bzdistg",memtest)
allocate( bzomega(bznqpts,nmode), stat=memtest)
call mem_test("bzomega",memtest)
do i=1,bznqpts
!
! First read in qpt coordinates
!
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("bqptsl",i,0,stat)
len1 = len(trim(str1))
ilbrack = index(str1,lbrack) + 1
str1 = str1(ilbrack:len1)
icomma = index(str1,comma) - 1
read(str1(1:icomma),*,iostat=stat) bzqpt(1,i)
if(stat /= 0) call error_read("bqpts1",i,0,stat)
len1 = len(trim(str1))
ilbrack = icomma + 2
str1 = str1(ilbrack:len1)
icomma = index(str1,comma) - 1
read(str1(1:icomma),*,iostat=stat) bzqpt(2,i)
if(stat /= 0) call error_read("bqpts2",i,0,stat)
len1 = len(trim(str1)) - 1
ilbrack = icomma + 2
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) bzqpt(3,i)
if(stat /= 0) call error_read("bqpts3",i,0,stat)
!
! Convert qpts from fractional to cartesian
!
do j=1,3
bzqpt_c(j,i) = 0.d0
do k=1,3
bzqpt_c(j,i) = bzqpt_c(j,i) + bzqpt(k,i) * brlatt(k,j)
enddo
enddo
!
! Read in distance from Gamma for each qpt
!
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("bdistl",i,0,stat)
ilbrack = index(str1,colon) + 1
len1 = len(trim(str1))
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) bzdistg(i)
if(stat /= 0) call error_read("bdist ",i,0,stat)
!
! Now read in frequencies. Skip the "band" line first
!
read(11,*,iostat=stat)
if(stat /= 0) call error_read("band ",i,0,stat)
do j=1,nmode
read(11,*,iostat=stat)
if(stat /= 0) call error_read("bline ",i,0,stat)
read(11,'(a)',iostat=stat) str1
if(stat /= 0) call error_read("omegal",i,j,stat)
ilbrack = index(str1,colon) + 1
len1 = len(trim(str1))
str1 = str1(ilbrack:len1)
read(str1,*,iostat=stat) bzomega(i,j)
if(stat /= 0) call error_read("omega ",i,j,stat)
!
! Convert to eV
!
bzomega(i,j) = bzomega(i,j) * scale
enddo
if( i < bznqpts) then
read(11,*,iostat=stat)
if(stat /= 0) call error_read("bline ",i,0,stat)
endif
enddo
!
! We can now deallocate bzqpt as it is no longer needed
!
deallocate(bzqpt,stat=memtest)
call dealloc_test("bzqpt ",memtest)
!
! Close file
!
write(*,'(a)') "...done"
close(unit=11)
!
! Check that both mesh and band contain the Gamma point. If so, then
! check if any frequencies are different - if they are, this will be
! due to the inclusion of the non-analytical correction for TO-LO
! splitting. Then change the frequencies in the mesh gamma point to
! those in the band file (as these have the TO-LO splitting interpolated
! at Gamma, while the mesh values do not)
!
! First allocate memory for array to store location of gamma points in
! BZ list
!
allocate( bzngamma(bznqpts), stat=memtest)
call mem_test("bzngam ",memtest)
!
! Of course, if there are only 3 modes (i.e. one atom), then this check
! is not necessary, but we still need to save the locations of the Gamma
! points
!
bzngamma = 0
if(ngamma > 0) then
write(*,*)
write(*,'(a)') "Checking for Gamma point in BZ path in band.yaml..."
nbzgamma = 0
!
! Now try to find all occurrence of Gamma in BZ list and save their locations
!
do i=1,bznqpts
checkq(:) = .false.
do j=1,3
if(abs(bzqpt_c(j,i)) <= small) checkq(j) = .true.
enddo
if(checkq(1) .and. checkq(2) .and. checkq(3)) then
nbzgamma = nbzgamma + 1
bzngamma(nbzgamma) = i
exit
endif
enddo
if(nbzgamma > 0) then
!
! Found it. Check for differences in frequency, but leave out the first few modes
! as these will probably be different even though they are meant to be zero or
! imaginary. nzero was used above to determine how many modes at Gamma were set
! to zero. If all modes at Gamma were set to zero, which could be the case if the
! system has just one atom for example, then skip this check
!
write(*,'(a52,x,i6)') "Gamma point found in BZ list, 1st occurrence at qpt:", &
bzngamma(1)
checkgam = .false.
if(nzero < nmode) then
do i=nzero+1,nmode
if( abs(bzomega(bzngamma(1),i) - omega(ngamma,i)) > enertest ) then
checkgam = .true.
write(*,'(a66,x,i4)') "Different frequency at Gamma b/n band.yaml &
and mesh.yaml for mode:", i
!
! The frequencies that differ must be set the same
!
omega(ngamma,i) = bzomega(bzngamma(1),i)
endif
enddo
endif
if(checkgam) then
write(*,'(a)') "(I am assuming that non-analytical correction has been used!"
write(*,'(a)') "Mesh calcs do not get the LO-TO splitting at Gamma - so we"
write(*,'(a)') "will make the Gamma point frequencies for the mesh equal to"
write(*,'(a)') "those of the band calculation...)"
else
write(*,'(a)') "Frequencies in band.yaml and mesh.yaml are the same at Gamma..."
endif
else
write(*,'(a)') "...Gamma point not found..."
endif
endif
!
! We can now deallocate bzqpt_c as it is no longer needed
!
deallocate(bzqpt_c,stat=memtest)
call dealloc_test("bzqpt_c",memtest)
!
! Go through list of qpts in band.yaml and find which qpts in mesh they are equivalent
! to according to their frequencies. Watch out for Gamma, as the lowest freq modes may
! differ slightly but should still be considered the same
!
! First allocate the arrays
!
allocate( nequiv(nqpts), stat=memtest)
call mem_test("nequiv ",memtest)
allocate( equivqpt(nqpts,nqpts), stat=memtest)
call mem_test("equivqp",memtest)
!
write(*,*)
write(*,'(a)') "Checking for equivalent qpts between BZ list and mesh qpts..."
write(*,'(a)') "(by comparing frequencies, watch out if you have BZ directions"
write(*,'(a)') "that have zero dispersion for ALL bands)"
!
equivqpt = 0
totequiv = 0
do i=1,nqpts
nequiv(i) = 0
!
! First check if this is the Gamma point. If so, then assign it correctly
! if the Gamma point is also in the mesh
!
if(i == ngamma) then
nequiv(i) = nbzgamma
if(nbzgamma > 0) then
do j=1,nequiv(i)
equivqpt(i,j) = bzngamma(j)
enddo
endif
else
!
! This is not the Gamma point, so check for equivalent qpts in full list
! by comparing frequencies
!
do j=1,bznqpts
checkequiv = .true.
do k=1,nmode
if( abs(omega(i,k) - bzomega(j,k)) > enertest ) then
checkequiv = .false.
exit
endif
enddo
!
! If frequencies do not differ, or if we are comparing Gamma points, we have two
! equivalent qpts
!
if(checkequiv) then
nequiv(i) = nequiv(i) + 1
equivqpt(i,nequiv(i)) = j
endif
enddo
endif
totequiv = totequiv + nequiv(i)
enddo
write(*,'(a49,x,i7)') "Total equivalences between BZ qpts and mesh qpts:", totequiv
!
! We can now deallocate bzomega and bzngamma as they are no longer needed
!
deallocate(bzomega,stat=memtest)
call dealloc_test("bzomega",memtest)
deallocate(bzngamma,stat=memtest)
call dealloc_test("bzngam ",memtest)
!
! Close check for presence of band.yaml file
!
endif
!
write(*,*)
!
write(*,'(a)') "Now checking for allowed transitions..."
!
! Open file for output
!
open(unit=20,status="scratch")
if(checkjdos) then
!
! Allocate arrays and set initial contributions to JDOS to zero
!
allocate( d21dos(nqpts,nmode), stat=memtest)
call mem_test("d21dos ",memtest)
allocate( d22dos(nqpts,nmode), stat=memtest)
call mem_test("d22dos ",memtest)
d21dos = 0.d0
d22dos = 0.d0
allocate( n21dos(nqpts,nmode), stat=memtest)
call mem_test("n21dos ",memtest)
allocate( n22dos(nqpts,nmode), stat=memtest)
call mem_test("n22dos ",memtest)
n21dos = 0.d0
n22dos = 0.d0
endif
!
! First check q vectors for quasimomentum conservation. Calculate G vector
! and then check if q - q' - q" = G. If this is true, then so is the collision
! process q' + q" - q = -G. Check each component first, then check if all
! are true together
!
countd = 0
countc = 0
iqchk = 0
do i=1,nqpts
ijval = 0
do j=1,nqpts
ijval = ijval+1
inner_qloop: do k=ijval,nqpts
!
! We sum k from ijval in order to avoid checking cases where j,k = k',j', where
! j',k' is a previously checked case. In this way, we avoid double checking, as
! switching q' and q" in q - q' - q" = G makes no difference. We could also check
! for cases where q'=-q" etc (see labbook 04-11-19), but that would be expensive
! and wouldn't actually save time
!
!
! Initialise checks for q vector components
!
checkq(:) = .false.
checkqtot = .false.
!
! Search through possible G vectors (max value of m or n or p is 3). When a
! viable G vector is found, exit the search to save time. Keep count of number
! of cases found where q vector conservation applies
!
outer_gloop: do m=-3,3
do n=-3,3
do p=-3,3
do q=1,3
gvec(q) = real(m) * reclatt(1,q) + real(n) * reclatt(2,q)&
+ real(p) * reclatt(3,q)
!
! Check for momentum conservation for decay processes
!
if(abs(qpt_c(q,i) - qpt_c(q,j) - qpt_c(q,k) - gvec(q)) <= qptest) then
checkq(q) = .true.
endif
enddo
if(checkq(1) .and. checkq(2) .and. checkq(3)) then
checkqtot = .true.
iqchk = iqchk + 1
exit outer_gloop
endif
enddo
enddo
enddo outer_gloop
!
! If momentum is conserved for decays, check energy conservation:
! omega - omega' - omega" = 0
! Exclude modes with zero frequency from these checks. Also exclude
! cases where omega < omega' or omega", as if this is true then the
! energy conservation condition cannot hold
!
if(checkqtot) then
do m=1,nmode
if(abs(omega(i,m)) <= tiny) cycle
do n=1,nmode
if(abs(omega(j,n)) <= tiny .or. omega(i,m) < omega(j,n)) cycle
do p=1,nmode
if(abs(omega(k,p)) <= tiny .or. omega(i,m) < omega(k,p)) cycle
etestd = omega(i,m) - omega(j,n) - omega(k,p)
if ( abs(etestd) <= enertest ) then
!
! Now we have an allowed phonon decay. Compute relevant occupations
! and write frequencies in decay to scratch. Also write to scratch the
! allowed collision process q' + q" - q = G (omega' + omega" - omega = 0)
!
write(20,'(3(e21.13,3x),3(i10,3x))') omega(i,m) / (scale), &
omega(j,n) / (scale), omega(k,p) / (scale), &
i, j, k
countd = countd + 1
countc = countc + 1
!