Repository navigation
Expand file tree
/
Copy pathmatdyn.f90
More file actions
3036 lines (2983 loc) · 105 KB
/
Copy pathmatdyn.f90
File metadata and controls
3036 lines (2983 loc) · 105 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
! Copyright (C) 2001-2012 Quantum ESPRESSO group
! This file is distributed under the terms of the
! GNU General Public License. See the file `License'
! in the root directory of the present distribution,
! or http://www.gnu.org/copyleft/gpl.txt .
!
!
Module ifconstants
!
!! All variables read from file that need dynamical allocation.
!
USE kinds, ONLY: DP
!
REAL(DP), ALLOCATABLE :: frc(:,:,:,:,:,:,:)
!! interatomic force constants in real space
REAL(DP), ALLOCATABLE :: frc_lr(:,:,:,:,:,:,:)
!! long-range part of interatomic force constants in real space
REAL(DP), ALLOCATABLE :: tau_blk(:,:)
!! atomic positions for the original cell
REAL(DP), ALLOCATABLE :: zeu(:,:,:)
!! effective charges for the original cell
REAL(DP), ALLOCATABLE :: m_loc(:,:)
!! the magnetic moments of each atom
INTEGER, ALLOCATABLE :: ityp_blk(:)
!! atomic types for each atom of the original cell
!
CHARACTER(LEN=6), ALLOCATABLE :: atm(:)
!
end Module ifconstants
!
!
!---------------------------------------------------------------------
PROGRAM matdyn
!-----------------------------------------------------------------------
!! This program calculates the phonon frequencies for a list of generic
!! q vectors starting from the interatomic force constants generated
!! from the dynamical matrices as written by DFPT phonon code through
!! the companion program \(\texttt{q2r}\).
!
!! \(\texttt{matdyn}\) can generate a supercell of the original cell for
!! mass approximation calculation. If supercell data are not specified
!! in input, the unit cell, lattice vectors, atom types and positions
!! are read from the force constant file.
!
! Input cards: namelist &input
! flfrc file produced by q2r containing force constants (needed)
! It is the same as in the input of q2r.x (+ the .xml extension
! if the dynamical matrices produced by ph.x were in xml
! format). No default value: must be specified.
! asr (character) indicates the type of Acoustic Sum Rule imposed
! - 'no': no Acoustic Sum Rules imposed (default)
! - 'simple': previous implementation of the asr used
! (3 translational asr imposed by correction of
! the diagonal elements of the force constants matrix)
! - 'crystal': 3 translational asr imposed by optimized
! correction of the force constants (projection).
! - 'all': 3 translational asr + 3 rotational asr + 15 Huang
! conditions for vanishing stress tensor, imposed by
! optimized correction of the force constants (projection).
! Remember to set write_lr to .true. to write long-range
! force constants into file when running q2r and set read_lr
! to .true. when running matdyn for the case of polar system.
! - 'one-dim': 3 translational asr + 1 rotational asr
! imposed by optimized correction of the force constants
! (the rotation axis is the direction of periodicity;
! it will work only if this axis considered is one of
! the cartesian axis).
! - 'zero-dim': 3 translational asr + 3 rotational asr
! imposed by optimized correction of the force constants
! Note that in certain cases, not all the rotational asr
! can be applied (e.g. if there are only 2 atoms in a
! molecule or if all the atoms are aligned, etc.).
! In these cases the supplementary asr are cancelled
! during the orthonormalization procedure (see below).
! huang if .true. (default) Huang conditions for vanishing
! stress tensor are included in asr='all'.
! dos if .true. calculate phonon Density of States (DOS)
! using tetrahedra and a uniform q-point grid (see below)
! NB: may not work properly in noncubic materials
! if .false. calculate phonon bands from the list of q-points
! supplied in input (default)
! nk1,nk2,nk3 uniform q-point grid for DOS calculation (includes q=0)
! (must be specified if dos=.true., ignored otherwise)
! deltaE energy step, in cm^(-1), for DOS calculation: from min
! to max phonon energy (default: 1 cm^(-1) if ndos, see
! below, is not specified)
! ndos number of energy steps for DOS calculations
! (default: calculated from deltaE if not specified)
! degauss DOS broadening (in cm^-1). Default 0 - meaning use tetrahedra
! fldos output file for dos (default: 'matdyn.dos')
! the dos is in states/cm(-1) plotted vs omega in cm(-1)
! and is normalised to 3*nat, i.e. the number of phonons
! flfrq output file for frequencies (default: 'matdyn.freq')
! flvec output file for normalized phonon displacements
! (default: 'matdyn.modes'). The normalized phonon displacements
! are the eigenvectors divided by the square root of the mass,
! then normalized. As such they are not orthogonal.
! fleig output file for phonon eigenvectors (default: 'matdyn.eig')
! The phonon eigenvectors are the eigenvectors of the dynamical
! matrix. They are orthogonal.
! fldyn output file for dynamical matrix (default: ' ' i.e. not written)
! at supercell lattice vectors - must form a superlattice of the
! original lattice (default: use original cell)
! l1,l2,l3 supercell lattice vectors are original cell vectors times
! l1, l2, l3 respectively (default: 1, ignored if at specified)
! ntyp number of atom types in the supercell (default: ntyp of the
! original cell)
! amass masses of atoms in the supercell (a.m.u.), one per atom type
! (default: use masses read from file flfrc)
! readtau read atomic positions of the supercell from input
! (used to specify different masses) (default: .false.)
! fltau write atomic positions of the supercell to file "fltau"
! (default: fltau=' ', do not write)
! la2F if .true. interpolates also the el-ph coefficients.
! q_in_band_form if .true. the q points are given in band form:
! Only the first and last point of one or more lines
! are given. See below. (default: .false.).
! q_in_cryst_coord if .true. input q points are in crystalline
! coordinates (default: .false.)
! eigen_similarity: use similarity of the displacements to order
! frequencies (default: .false.)
! NB: You cannot use this option with the symmetry
! analysis of the modes.
! fd (logical) if .t. the ifc come from the finite displacement calculation
! na_ifc (logical) add non analitic contributions to the interatomic force
! constants if finite displacement method is used (as in Wang et al.
! Phys. Rev. B 85, 224303 (2012)) [to be used in conjunction with fd.x]
! nosym if .true., no symmetry and no time reversal are imposed
! loto_2d set to .true. to activate two-dimensional treatment of LO-TO splitting.
! loto_disable (logical) if .true. do not apply LO-TO splitting for q=0
! (default: .false.)
! read_lr set to .true. to read long-range force constants from file,
! when enforcing asr='all' for polar solids in matdyn.
! write_frc set to .true. to write force constants into file.
! The filename would be flfrc+".matdyn".
!
! if (readtau) atom types and positions in the supercell follow:
! (tau(i,na),i=1,3), ityp(na)
! IF (q_in_band_form.and..not.dos) THEN
! nq ! number of q points
! (q(i,n),i=1,3), nptq nptq is the number of points between this point
! and the next. These points are automatically
! generated. the q points are given in Cartesian
! coordinates, 2pi/a units (a=lattice parameters)
! ELSE, if (.not.dos) :
! nq number of q-points
! (q(i,n), i=1,3) nq q-points in cartesian coordinates, 2pi/a units
! If q = 0, the direction qhat (q=>0) for the non-analytic part
! is extracted from the sequence of q-points as follows:
! qhat = q(n) - q(n-1) or qhat = q(n) - q(n+1)
! depending on which one is available and nonzero.
! For low-symmetry crystals, specify twice q = 0 in the list
! if you want to have q = 0 results for two different directions
!
USE kinds, ONLY : DP
USE mp, ONLY : mp_bcast
USE mp_world, ONLY : world_comm
USE mp_global, ONLY : mp_startup, mp_global_end
USE environment, ONLY : environment_start, environment_end
USE io_global, ONLY : ionode, ionode_id, stdout
USE io_dyn_mat, ONLY : read_dyn_mat_param, read_dyn_mat_header, &
read_ifc_param, read_ifc
USE cell_base, ONLY : at, bg, celldm
USE constants, ONLY : RY_TO_THZ, RY_TO_CMM1, amu_ry
USE symm_base, ONLY : set_sym
USE rap_point_group, ONLY : code_group
USE bz_form, ONLY : transform_label_coord
USE parser, ONLY : read_line
USE rigid, ONLY : dyndiag, nonanal, nonanal_ifc
USE el_phon, ONLY : el_ph_nsigma
USE ifconstants, ONLY : frc, frc_lr, atm, zeu, tau_blk, ityp_blk, m_loc
!
IMPLICIT NONE
!
INTEGER :: gid
!
! variables *_blk refer to the original cell, other variables
! to the (super)cell (which may coincide with the original cell)
!
INTEGER:: nax, nax_blk
INTEGER, PARAMETER:: ntypx=10, nrwsx=200
REAL(DP), PARAMETER :: eps=1.0d-6
INTEGER :: nr1, nr2, nr3, nsc, nk1, nk2, nk3, ibrav
CHARACTER(LEN=256) :: flfrc, flfrq, flvec, fltau, fldos, filename, fldyn, &
fleig, fildyn, fildyn_prefix
CHARACTER(LEN=10) :: asr
LOGICAL :: dos, has_zstar, q_in_cryst_coord, eigen_similarity, loto_disable, &
remove_interaction_blocks
COMPLEX(DP), ALLOCATABLE :: dyn(:,:,:,:), dyn_blk(:,:,:,:), frc_ifc(:,:,:,:)
COMPLEX(DP), ALLOCATABLE :: z(:,:)
REAL(DP), ALLOCATABLE:: tau(:,:), q(:,:), w2(:,:), freq(:,:), wq(:), &
dynq(:,:,:), DOSofE(:), zq(:, :, :)
INTEGER, ALLOCATABLE:: ityp(:), itau_blk(:)
REAL(DP) :: omega,alat, &! cell parameters and volume
at_blk(3,3), bg_blk(3,3), &! original cell
omega_blk, &! original cell volume
epsil(3,3), &! dielectric tensor
amass(ntypx), &! atomic masses
amass_blk(ntypx), &! original atomic masses
atws(3,3), &! lattice vector for WS initialization
rws(0:3,nrwsx) ! nearest neighbor list, rws(0,*) = norm^2
REAL(DP) :: alph ! Ewald coefficient for non-analytical term
!
INTEGER :: nat, nat_blk, ntyp, ntyp_blk, &
l1, l2, l3, &! supercell dimensions
nrws, &! number of nearest neighbor
code_group_old
INTEGER :: nspin_mag, nqs, ios, ipol
!
LOGICAL :: readtau, la2F, xmlifc, lo_to_split, na_ifc, fd, nosym, loto_2d, &
huang, read_lr, write_frc
!
REAL(DP) :: qhat(3), qh, DeltaE, Emin=0._dp, Emax, E, qq, degauss
REAL(DP) :: delta, pathL
REAL(DP), ALLOCATABLE :: xqaux(:,:)
INTEGER, ALLOCATABLE :: nqb(:)
INTEGER :: n, i, j, it, nq, nqx, na, nb, ndos, iout, nqtot, iout_dyn, iout_eig
LOGICAL, EXTERNAL :: has_xml
INTEGER, ALLOCATABLE :: num_rap_mode(:,:)
LOGICAL, ALLOCATABLE :: high_sym(:)
LOGICAL :: q_in_band_form
! .... variables for band plotting based on similarity of eigenvalues
COMPLEX(DP), ALLOCATABLE :: tmp_z(:,:)
REAL(DP), ALLOCATABLE :: abs_similarity(:,:), tmp_w2(:)
COMPLEX(DP), ALLOCATABLE :: f_of_q(:,:,:,:)
INTEGER :: location(1), isig
CHARACTER(LEN=6) :: int_to_char
LOGICAL, ALLOCATABLE :: mask(:)
INTEGER :: npk_label, nch
CHARACTER(LEN=3), ALLOCATABLE :: letter(:)
INTEGER, ALLOCATABLE :: label_list(:)
LOGICAL :: tend, terr
CHARACTER(LEN=256) :: input_line, buffer
CHARACTER(LEN=10) :: point_label_type
CHARACTER(len=80) :: k_points = 'tpiba'
!
REAL(DP), external :: dos_broad, dos_gam
!
NAMELIST /input/ flfrc, amass, asr, flfrq, flvec, fleig, at, dos, &
& fldos, nk1, nk2, nk3, l1, l2, l3, ntyp, readtau, fltau, &
& la2F, ndos, DeltaE, degauss, q_in_band_form, q_in_cryst_coord, &
& eigen_similarity, fldyn, na_ifc, fd, point_label_type, &
& nosym, loto_2d, fildyn, fildyn_prefix, el_ph_nsigma, &
& loto_disable, huang, read_lr, write_frc, remove_interaction_blocks
!
CALL mp_startup()
CALL environment_start('MATDYN')
!
IF (ionode) CALL input_from_file ( )
!
! ... all calculations are done by the first cpu
!
! set namelist default
!
dos = .FALSE.
deltaE = 1.0d0
degauss = 0
ndos = 1
nk1 = 0
nk2 = 0
nk3 = 0
asr ='no'
readtau=.FALSE.
flfrc=' '
fldos='matdyn.dos'
flfrq='matdyn.freq'
flvec='matdyn.modes'
fleig=' '
fldyn=' '
fltau=' '
fildyn = ' '
fildyn_prefix = ' '
amass(:) =0.d0
amass_blk(:) =0.d0
at(:,:) = 0.d0
ntyp = 0
l1=1
l2=1
l3=1
la2F=.false.
q_in_band_form=.FALSE.
eigen_similarity=.FALSE.
q_in_cryst_coord = .FALSE.
na_ifc=.FALSE.
fd=.FALSE.
point_label_type='SC'
nosym = .false.
loto_2d=.false.
el_ph_nsigma=10
loto_disable = .false.
remove_interaction_blocks = .false.
huang = .true.
read_lr = .false.
write_frc = .false.
!
!
IF (ionode) READ (5,input,IOSTAT=ios)
CALL mp_bcast(ios, ionode_id, world_comm)
CALL errore('matdyn', 'reading input namelist', ABS(ios))
CALL mp_bcast(dos,ionode_id, world_comm)
CALL mp_bcast(deltae,ionode_id, world_comm)
CALL mp_bcast(ndos,ionode_id, world_comm)
CALL mp_bcast(degauss,ionode_id, world_comm)
CALL mp_bcast(nk1,ionode_id, world_comm)
CALL mp_bcast(nk2,ionode_id, world_comm)
CALL mp_bcast(nk3,ionode_id, world_comm)
CALL mp_bcast(asr,ionode_id, world_comm)
CALL mp_bcast(readtau,ionode_id, world_comm)
CALL mp_bcast(flfrc,ionode_id, world_comm)
CALL mp_bcast(fldos,ionode_id, world_comm)
CALL mp_bcast(flfrq,ionode_id, world_comm)
CALL mp_bcast(flvec,ionode_id, world_comm)
CALL mp_bcast(fleig,ionode_id, world_comm)
CALL mp_bcast(fldyn,ionode_id, world_comm)
CALL mp_bcast(fltau,ionode_id, world_comm)
CALL mp_bcast(fildyn,ionode_id, world_comm)
CALL mp_bcast(fildyn_prefix,ionode_id, world_comm)
CALL mp_bcast(amass,ionode_id, world_comm)
CALL mp_bcast(amass_blk,ionode_id, world_comm)
CALL mp_bcast(at,ionode_id, world_comm)
CALL mp_bcast(ntyp,ionode_id, world_comm)
CALL mp_bcast(l1,ionode_id, world_comm)
CALL mp_bcast(l2,ionode_id, world_comm)
CALL mp_bcast(l3,ionode_id, world_comm)
CALL mp_bcast(na_ifc,ionode_id, world_comm)
CALL mp_bcast(fd,ionode_id, world_comm)
CALL mp_bcast(la2F,ionode_id, world_comm)
CALL mp_bcast(q_in_band_form,ionode_id, world_comm)
CALL mp_bcast(eigen_similarity,ionode_id, world_comm)
CALL mp_bcast(q_in_cryst_coord,ionode_id, world_comm)
CALL mp_bcast(point_label_type,ionode_id, world_comm)
CALL mp_bcast(loto_2d,ionode_id, world_comm)
CALL mp_bcast(loto_disable,ionode_id, world_comm)
CALL mp_bcast(remove_interaction_blocks, ionode_id, world_comm)
CALL mp_bcast(el_ph_nsigma,ionode_id, world_comm)
CALL mp_bcast(huang,ionode_id, world_comm)
CALL mp_bcast(read_lr,ionode_id, world_comm)
CALL mp_bcast(write_frc,ionode_id, world_comm)
!
IF (loto_2d .AND. loto_disable) CALL errore('matdyn', &
'loto_2d and loto_disable cannot be both true', 1)
!
! read force constants
!
IF ( trim( fildyn ) /= ' ' ) THEN
IF (ionode) THEN
WRITE(stdout, *)
WRITE(stdout, '(4x,a)') ' fildyn has been provided, running q2r...'
END IF
CALL do_q2r(fildyn, flfrc, fildyn_prefix, asr, la2F, loto_2d, read_lr, &
remove_interaction_blocks)
END IF
!
ntyp_blk = ntypx ! avoids fake out-of-bound error
xmlifc=has_xml(flfrc)
IF (xmlifc) THEN
CALL read_dyn_mat_param(flfrc,ntyp_blk,nat_blk)
ALLOCATE (m_loc(3,nat_blk))
ALLOCATE (tau_blk(3,nat_blk))
ALLOCATE (ityp_blk(nat_blk))
ALLOCATE (atm(ntyp_blk))
ALLOCATE (zeu(3,3,nat_blk))
CALL read_dyn_mat_header(ntyp_blk, nat_blk, ibrav, nspin_mag, &
celldm, at_blk, bg_blk, omega_blk, atm, amass_blk, &
tau_blk, ityp_blk, m_loc, nqs, has_zstar, epsil, zeu )
alat=celldm(1)
call volume(alat,at_blk(1,1),at_blk(1,2),at_blk(1,3),omega_blk)
CALL read_ifc_param(nr1,nr2,nr3)
ALLOCATE(frc(nr1,nr2,nr3,3,3,nat_blk,nat_blk))
ALLOCATE(frc_lr(nr1,nr2,nr3,3,3,nat_blk,nat_blk))
frc_lr = 0.d0
if (read_lr) THEN
CALL read_ifc(alph,nr1,nr2,nr3,nat_blk,frc,frc_lr)
else
CALL read_ifc(alph,nr1,nr2,nr3,nat_blk,frc)
end if
ELSE
CALL readfc ( flfrc, nr1, nr2, nr3, epsil, nat_blk, &
ibrav, alat, at_blk, ntyp_blk, &
amass_blk, omega_blk, has_zstar, alph, read_lr)
ENDIF
!
CALL recips ( at_blk(1,1),at_blk(1,2),at_blk(1,3), &
bg_blk(1,1),bg_blk(1,2),bg_blk(1,3) )
!
! set up (super)cell
!
if (ntyp < 0) then
call errore ('matdyn','wrong ntyp ', abs(ntyp))
else if (ntyp == 0) then
ntyp=ntyp_blk
end if
!
! masses (for mass approximation)
!
DO it=1,ntyp
IF (amass(it) < 0.d0) THEN
CALL errore ('matdyn','wrong mass in the namelist',it)
ELSE IF (amass(it) == 0.d0) THEN
IF (it.LE.ntyp_blk) THEN
WRITE (stdout,'(a,i3,a,a)') ' mass for atomic type ',it, &
& ' not given; uses mass from file ',flfrc
amass(it) = amass_blk(it)
ELSE
CALL errore ('matdyn','missing mass in the namelist',it)
END IF
END IF
END DO
!
! lattice vectors
!
IF (SUM(ABS(at(:,:))) == 0.d0) THEN
IF (l1.LE.0 .OR. l2.LE.0 .OR. l3.LE.0) CALL &
& errore ('matdyn',' wrong l1,l2 or l3',1)
at(:,1) = at_blk(:,1)*DBLE(l1)
at(:,2) = at_blk(:,2)*DBLE(l2)
at(:,3) = at_blk(:,3)*DBLE(l3)
END IF
!
CALL check_at(at,bg_blk,alat,omega)
!
! the supercell contains "nsc" times the original unit cell
!
nsc = NINT(omega/omega_blk)
IF (ABS(omega/omega_blk-nsc) > eps) &
CALL errore ('matdyn', 'volume ratio not integer', 1)
!
! read/generate atomic positions of the (super)cell
!
nat = nat_blk * nsc
nax = nat
nax_blk = nat_blk
!
ALLOCATE ( tau (3, nat), ityp(nat), itau_blk(nat) )
!
IF (readtau) THEN
CALL read_tau &
(nat, nat_blk, ntyp, bg_blk, tau, tau_blk, ityp, itau_blk)
ELSE
CALL set_tau &
(nat, nat_blk, at, at_blk, tau, tau_blk, ityp, ityp_blk, itau_blk)
ENDIF
!
IF (fltau.NE.' ') CALL write_tau (fltau, nat, tau, ityp)
!
! reciprocal lattice vectors
!
CALL recips (at(1,1),at(1,2),at(1,3),bg(1,1),bg(1,2),bg(1,3))
!
! build the WS cell corresponding to the force constant grid
!
atws(:,1) = at_blk(:,1)*DBLE(nr1)
atws(:,2) = at_blk(:,2)*DBLE(nr2)
atws(:,3) = at_blk(:,3)*DBLE(nr3)
! initialize WS r-vectors
CALL wsinit(rws,nrwsx,nrws,atws)
!
! end of (super)cell setup
!
IF (dos) THEN
IF (nk1 < 1 .OR. nk2 < 1 .OR. nk3 < 1) &
CALL errore ('matdyn','specify correct q-point grid!',1)
nqx = nk1*nk2*nk3
ALLOCATE ( q(3,nqx), wq(nqx) )
CALL gen_qpoints (ibrav, at, bg, nat, tau, ityp, nk1, nk2, nk3, &
nqx, nq, q, nosym, wq)
ELSE
!
! read q-point list
!
IF (ionode) READ (5,*) nq
CALL mp_bcast(nq, ionode_id, world_comm)
ALLOCATE ( q(3,nq) )
IF (.NOT.q_in_band_form) THEN
ALLOCATE(wq(nq))
wq(:) = 0.0_dp
DO n = 1,nq
IF (ionode) READ (5,*) (q(i,n),i=1,3)
END DO
CALL mp_bcast(q, ionode_id, world_comm)
!
IF (q_in_cryst_coord) CALL cryst_to_cart(nq,q,bg,+1)
ELSE
ALLOCATE( nqb(nq) )
ALLOCATE( xqaux(3,nq) )
ALLOCATE( letter(nq) )
ALLOCATE( label_list(nq) )
npk_label=0
DO n = 1, nq
CALL read_line( input_line, end_of_file = tend, error = terr )
IF (tend) CALL errore('matdyn','Missing lines',1)
IF (terr) CALL errore('matdyn','Error reading q points',1)
DO j=1,256 ! loop over all characters of input_line
IF ( (ICHAR(input_line(j:j)) < 58 .AND. & ! a digit
ICHAR(input_line(j:j)) > 47) &
.OR.ICHAR(input_line(j:j)) == 43 .OR. & ! the + sign
ICHAR(input_line(j:j)) == 45 .OR. & ! the - sign
ICHAR(input_line(j:j)) == 46 ) THEN ! a dot .
!
! This is a digit, therefore this line contains the coordinates of the
! k point. We read it and exit from the loop on characters
!
READ(input_line,*) xqaux(1,n), xqaux(2,n), xqaux(3,n), &
nqb(n)
EXIT
ELSEIF ((ICHAR(input_line(j:j)) < 123 .AND. &
ICHAR(input_line(j:j)) > 64)) THEN
!
! This is a letter, not a space character. We read the next three
! characters and save them in the letter array, save also which k point
! it is
!
npk_label=npk_label+1
READ(input_line(j:),'(a3)') letter(npk_label)
label_list(npk_label)=n
!
! now we remove the letters from input_line and read the number of points
! of the line. The next two line should account for the case in which
! there is only one space between the letter and the number of points.
!
nch=3
IF ( ICHAR(input_line(j+1:j+1))==32 .OR. &
ICHAR(input_line(j+2:j+2))==32 ) nch=2
buffer=input_line(j+nch:)
READ(buffer,*,err=20,iostat=ios) nqb(n)
20 IF (ios /=0) CALL errore('matdyn',&
'problem reading number of points',1)
EXIT
ENDIF
ENDDO
ENDDO
IF (q_in_cryst_coord) k_points='crystal'
IF ( npk_label > 0 ) &
CALL transform_label_coord(ibrav, celldm, xqaux, letter, &
label_list, npk_label, nq, k_points, point_label_type )
DEALLOCATE(letter)
DEALLOCATE(label_list)
CALL mp_bcast(xqaux, ionode_id, world_comm)
CALL mp_bcast(nqb, ionode_id, world_comm)
IF (q_in_cryst_coord) CALL cryst_to_cart(nq,xqaux,bg,+1)
nqtot=SUM(nqb(1:nq-1))+1
DO i=1,nq-1
IF (nqb(i)==0) nqtot=nqtot+1
ENDDO
DEALLOCATE(q)
ALLOCATE(q(3,nqtot))
ALLOCATE(wq(nqtot))
CALL generate_k_along_lines(nq, xqaux, nqb, q, wq, nqtot)
nq=nqtot
DEALLOCATE(xqaux)
DEALLOCATE(nqb)
END IF
!
END IF
!
IF (asr == 'all' .AND. ANY(ABS(zeu) > 1.d-5) .AND. (.NOT. read_lr)) THEN
WRITE(stdout, '(/5x, a )') "WARNING: To use asr = 'all' for infrared-active solids, i.e., solids with nonzero"
WRITE(stdout, '( 5x, a )') "Born effective charge, one must set read_lr = .true. in the matdyn.x input. Also,"
WRITE(stdout, '( 5x, a )') "the flfrc file must have been constructed with write_lr = .true. in the q2r.x input."
WRITE(stdout, '( 5x, a )') "If the system is infrared inactive and you have nonzero Born effective charge due to"
WRITE(stdout, '( 5x, a/)') "numerical noise, you can ignore this warning."
ENDIF
!
IF (asr /= 'no') THEN
CALL set_asr (asr, nr1, nr2, nr3, frc, frc_lr, zeu, &
nat_blk, ibrav, tau_blk, at_blk, huang)
END IF
!
IF (write_frc) THEN
CALL writefc(flfrc, xmlifc, has_zstar, nr1, nr2, nr3, ibrav, alat, at_blk, bg_blk, &
ntyp_blk, nat_blk, amass_blk, omega_blk, epsil, alph, nspin_mag, nqs)
END IF
!
IF (flvec.EQ.' ') THEN
iout=0
ELSE
iout=4
IF (ionode) OPEN (unit=iout,file=flvec,status='unknown',form='formatted')
END IF
IF (fldyn.EQ.' ') THEN
iout_dyn=0
ELSE
iout_dyn=44
OPEN (unit=iout_dyn,file=fldyn,status='unknown',form='formatted')
END IF
IF (fleig.EQ.' ') THEN
iout_eig=0
ELSE
iout_eig=313
IF (ionode) OPEN (unit=iout_eig,file=fleig,status='unknown',form='formatted')
END IF
ALLOCATE ( dyn(3,3,nat,nat), dyn_blk(3,3,nat_blk,nat_blk) )
ALLOCATE ( z(3*nat,3*nat), w2(3*nat,nq), f_of_q(3,3,nat,nat), &
dynq(3*nat,nq,nat), DOSofE(nat), zq(nq, 3*nat, 3*nat) )
ALLOCATE ( tmp_w2(3*nat), abs_similarity(3*nat,3*nat), mask(3*nat) )
if(la2F.and.ionode) open(unit=300,file='dyna2F',status='unknown')
IF (xmlifc) CALL set_sym(nat, tau, ityp, nspin_mag, m_loc )
ALLOCATE(num_rap_mode(3*nat,nq))
ALLOCATE(high_sym(nq))
num_rap_mode=-1
high_sym=.TRUE.
zq(:, :, :) = (0.d0, 0.d0)
DO n=1, nq
dyn(:,:,:,:) = (0.d0, 0.d0)
lo_to_split=.FALSE.
f_of_q(:,:,:,:) = (0.d0,0.d0)
IF(na_ifc) THEN
qq=sqrt(q(1,n)**2+q(2,n)**2+q(3,n)**2)
if(abs(qq) < 1d-8) qq=1.0
qhat(1)=q(1,n)/qq
qhat(2)=q(2,n)/qq
qhat(3)=q(3,n)/qq
CALL nonanal_ifc (nat,nat_blk,itau_blk,epsil,qhat,zeu,omega,dyn, &
nr1, nr2, nr3,f_of_q)
END IF
CALL setupmat (q(1,n), dyn, nat, at, bg, tau, itau_blk, nsc, alat, &
dyn_blk, nat_blk, at_blk, bg_blk, tau_blk, omega_blk, &
loto_2d, epsil, zeu, alph, &
frc, nr1,nr2,nr3, has_zstar, rws, nrws, na_ifc,f_of_q,fd)
IF (.not.loto_2d) THEN
qhat(1) = q(1,n)*at(1,1)+q(2,n)*at(2,1)+q(3,n)*at(3,1)
qhat(2) = q(1,n)*at(1,2)+q(2,n)*at(2,2)+q(3,n)*at(3,2)
qhat(3) = q(1,n)*at(1,3)+q(2,n)*at(2,3)+q(3,n)*at(3,3)
IF ( ABS( qhat(1) - NINT (qhat(1) ) ) <= eps .AND. &
ABS( qhat(2) - NINT (qhat(2) ) ) <= eps .AND. &
ABS( qhat(3) - NINT (qhat(3) ) ) <= eps ) THEN
!
! q = 0 : we need the direction q => 0 for the non-analytic part
!
IF ( n == 1 ) THEN
! if q is the first point in the list
IF ( nq > 1 ) THEN
! one more point
qhat(:) = q(:,n) - q(:,n+1)
ELSE
! no more points
qhat(:) = 0.d0
END IF
ELSE IF ( n > 1 ) THEN
! if q is not the first point in the list
IF ( q(1,n-1)==0.d0 .AND. &
q(2,n-1)==0.d0 .AND. &
q(3,n-1)==0.d0 .AND. n < nq ) THEN
! if the preceding q is also 0 :
qhat(:) = q(:,n) - q(:,n+1)
ELSE
! if the preceding q is npt 0 :
qhat(:) = q(:,n) - q(:,n-1)
END IF
END IF
qh = SQRT(qhat(1)**2+qhat(2)**2+qhat(3)**2)
! write(*,*) ' qh, has_zstar ',qh, has_zstar
IF (qh /= 0.d0) qhat(:) = qhat(:) / qh
IF (qh /= 0.d0 .AND. .NOT. has_zstar) THEN
CALL infomsg &
('matdyn','Z* not found in file '//TRIM(flfrc)// &
', TO-LO splitting at q=0 will be absent!')
ELSEIF (loto_disable) THEN
CALL infomsg('matdyn', &
'loto_disable is true. Disable LO-TO splitting at q=0.')
ELSE
lo_to_split=.TRUE.
ENDIF
!
IF (lo_to_split) CALL nonanal (nat, nat_blk, itau_blk, epsil, qhat, zeu, omega, dyn)
!
END IF
!
END IF
if(iout_dyn.ne.0) THEN
call write_dyn_on_file(q(1,n),dyn,nat, iout_dyn)
if(sum(abs(q(:,n)))==0._dp) call write_epsilon_and_zeu (zeu, epsil, nat, iout_dyn)
endif
CALL dyndiag(nat,ntyp,amass,ityp,dyn,w2(1,n),z)
!
! Convert from displacements to eigenvectors (see rigid.f90 :: dyndiag)
do i = 1, 3*nat
do na = 1, nat
do ipol = 1,3
zq(n, (na-1)*3+ipol,i) = z((na-1)*3+ipol,i) * sqrt(amu_ry * amass(ityp(na)))
end do
end do
end do
!
! Atom projection of dynamical matrix
DO i = 1, 3*nat
DO na = 1, nat
dynq(i, n, na) = DOT_PRODUCT(z(3*(na-1)+1:3*na, i), &
& z(3*(na-1)+1:3*na, i) ) &
& * amu_ry * amass(ityp(na))
END DO
END DO
IF (ionode.and.iout_eig.ne.0) &
& CALL write_eigenvectors(nat,ntyp,amass,ityp,q(1,n),w2(1,n),z,iout_eig)
!
! Cannot use the small group of \Gamma to analize the symmetry
! of the mode if there is an electric field.
!
IF (xmlifc.AND..NOT.lo_to_split) THEN
WRITE(stdout,'(10x,"xq=",3F8.4)') q(:,n)
CALL find_representations_mode_q(nat,ntyp,q(:,n), &
w2(:,n),z,tau,ityp,amass, num_rap_mode(:,n), nspin_mag)
IF (code_group==code_group_old.OR.high_sym(n-1)) high_sym(n)=.FALSE.
code_group_old=code_group
ENDIF
IF (eigen_similarity) THEN
! ... order phonon dispersions using similarity of eigenvalues
! ... Courtesy of Takeshi Nishimatsu, IMR, Tohoku University
IF (.NOT.ALLOCATED(tmp_z)) THEN
ALLOCATE(tmp_z(3*nat,3*nat))
ELSE
abs_similarity = ABS ( MATMUL ( CONJG( TRANSPOSE(z)), tmp_z ) )
mask(:) = .true.
DO na=1,3*nat
location = maxloc( abs_similarity(:,na), mask(:) )
mask(location(1)) = .false.
tmp_w2(na) = w2(location(1),n)
tmp_z(:,na) = z(:,location(1))
END DO
w2(:,n) = tmp_w2(:)
z(:,:) = tmp_z(:,:)
END IF
tmp_z(:,:) = z(:,:)
ENDIF
!
if(la2F.and.ionode) then
write(300,*) n
do na=1,3*nat
write(300,*) (z(na,nb),nb=1,3*nat)
end do ! na
endif
!
IF (ionode.and.iout.ne.0) CALL writemodes(nat,q(1,n),w2(1,n),z,iout)
!
END DO !nq
DEALLOCATE (tmp_w2, abs_similarity, mask)
IF (eigen_similarity) DEALLOCATE(tmp_z)
if(la2F.and.ionode) close(300)
!
IF(iout .NE. 0.and.ionode) CLOSE(unit=iout)
IF(iout_dyn .NE. 0) CLOSE(unit=iout_dyn)
IF(iout_eig .NE. 0) CLOSE(unit=iout_eig)
!
ALLOCATE (freq(3*nat, nq))
DO n=1,nq
! freq(i,n) = frequencies in cm^(-1), with negative sign if omega^2 is negative
DO i=1,3*nat
freq(i,n)= SQRT(ABS(w2(i,n))) * RY_TO_CMM1
IF (w2(i,n) < 0.0d0) freq(i,n) = -freq(i,n)
END DO
END DO
!
IF(flfrq.NE.' '.and.ionode) THEN
OPEN (unit=2,file=flfrq ,status='unknown',form='formatted')
WRITE(2, '(" &plot nbnd=",i4,", nks=",i4," /")') 3*nat, nq
DO n=1, nq
WRITE(2, '(10x,4f10.6)') q(1,n), q(2,n), q(3,n), wq(n)
WRITE(2,'(6f10.4)') (freq(i,n), i=1,3*nat)
END DO
CLOSE(unit=2)
OPEN (unit=2,file=trim(flfrq)//'.gp' ,status='unknown',form='formatted')
pathL = 0._dp
WRITE(2, '(f10.6,3x,999f10.4)') pathL, (freq(i,1), i=1,3*nat)
DO n=2, nq
pathL=pathL+(SQRT(SUM( (q(:,n)-q(:,n-1))**2 )))
WRITE(2, '(f10.6,3x,999f10.4)') pathL, (freq(i,n), i=1,3*nat)
END DO
CLOSE(unit=2)
END IF
!
! If the force constants are in the xml format we write also
! the file with the representations of each mode
!
IF (flfrq.NE.' '.AND.xmlifc.AND.ionode) THEN
filename=TRIM(flfrq)//'.rap'
OPEN (unit=2,file=filename ,status='unknown',form='formatted')
WRITE(2, '(" &plot_rap nbnd_rap=",i4,", nks_rap=",i4," /")') 3*nat, nq
DO n=1, nq
WRITE(2,'(10x,3f10.6,l6)') q(1,n), q(2,n), q(3,n), high_sym(n)
WRITE(2,'(6i10)') (num_rap_mode(i,n), i=1,3*nat)
END DO
CLOSE(unit=2)
END IF
!
IF (dos) THEN
Emin = 0.0d0
Emax = 0.0d0
DO n=1,nq
DO i=1, 3*nat
Emin = MIN (Emin, freq(i,n))
Emax = MAX (Emax, freq(i,n))
END DO
END DO
!
if (ndos > 1) then
DeltaE = (Emax - Emin)/(ndos-1)
else
ndos = NINT ( (Emax - Emin) / DeltaE + 1.51d0 )
end if
IF (ionode) OPEN (unit=2,file=fldos,status='unknown',form='formatted')
IF (ionode) WRITE (2, *) "# Frequency[cm^-1] DOS PDOS"
!
IF (degauss .EQ. 0) THEN
! Use tetrahedra
DO na = 1, nat
dynq(1:3*nat,1:nq,na) = dynq(1:3*nat,1:nq,na) * freq(1:3*nat,1:nq)
END DO
END IF
!
DO n= 1, ndos
E = Emin + (n - 1) * DeltaE
DO na = 1, nat
DOSofE(na) = 0d0
!
IF (degauss .EQ. 0) THEN
! Use tetrahedra
DO i = 1, 3*nat
DOSofE(na) = DOSofE(na) &
& + dos_gam(3*nat, nq, i, dynq(1:3*nat,1:nq,na), freq, E)
END DO
ELSE
! Use broadening
DOSofE(na) = DOSofE(na) &
& + dos_broad(na, 3*nat, nq, freq, zq, wq, E, degauss)
END IF
!
END DO
!
IF (ionode) WRITE (2, '(2ES18.10,1000ES12.4)') E, SUM(DOSofE(1:nat)), DOSofE(1:nat)
END DO
IF (ionode) CLOSE(unit=2)
END IF !dos
DEALLOCATE (z, zq, w2, dyn, dyn_blk)
!
! for a2F
!
IF(la2F) THEN
!
IF (.NOT. dos) THEN
DO isig=1,el_ph_nsigma
OPEN (unit=200+isig,file='elph.gamma.'//&
TRIM(int_to_char(isig)), status='unknown',form='formatted')
WRITE(200+isig, '(" &plot nbnd=",i4,", nks=",i4," /")') 3*nat, nq
END DO
END IF
!
! convert frequencies to Ry
!
freq(:,:)= freq(:,:) / RY_TO_CMM1
Emin = Emin / RY_TO_CMM1
DeltaE=DeltaE/ RY_TO_CMM1
!
call a2Fdos (nat, nq, nr1, nr2, nr3, ibrav, at, bg, tau, alat, &
nsc, nat_blk, at_blk, bg_blk, itau_blk, omega_blk, &
rws, nrws, dos, Emin, DeltaE, ndos, &
asr, q, freq,fd, wq, huang)
!
IF (.NOT.dos) THEN
DO isig=1,el_ph_nsigma
CLOSE(UNIT=200+isig)
ENDDO
ENDIF
END IF
DEALLOCATE ( freq)
DEALLOCATE(num_rap_mode)
DEALLOCATE(high_sym)
DEALLOCATE(frc_lr)
!
CALL environment_end( )
!
CALL mp_global_end()
!
IF (asr == 'all') THEN
WRITE(stdout, '(/A117/)') " You are using asr="//'"all"'//", please consider citing "// &
"C. Lin, S. Ponc\'e and N. Marzari, npj Comput Mater 8, 236 (2022)."
ENDIF
!
STOP
!
END PROGRAM matdyn
!
!-----------------------------------------------------------------------
SUBROUTINE readfc ( flfrc, nr1, nr2, nr3, epsil, nat, &
ibrav, alat, at, ntyp, amass, omega, &
has_zstar, alph, read_lr )
!-----------------------------------------------------------------------
!
USE kinds, ONLY : DP
USE ifconstants,ONLY : tau => tau_blk, ityp => ityp_blk, frc, frc_lr, zeu, atm
USE cell_base, ONLY : celldm
USE io_global, ONLY : ionode, ionode_id, stdout
USE mp, ONLY : mp_bcast
USE mp_world, ONLY : world_comm
USE constants, ONLY : amu_ry
!
IMPLICIT NONE
! I/O variable
CHARACTER(LEN=256) :: flfrc
CHARACTER(LEN=80) :: line
INTEGER :: ibrav, nr1,nr2,nr3,nat, ntyp
REAL(DP) :: alat, at(3,3), epsil(3,3), alph
LOGICAL :: has_zstar, read_lr
! local variables
INTEGER :: i, j, na, nb, m1,m2,m3
INTEGER :: ios, ibid, jbid, nabid, nbbid, m1bid,m2bid,m3bid
REAL(DP) :: amass(ntyp), amass_from_file, omega
INTEGER :: nt
!
!
IF (ionode) OPEN (unit=1,file=flfrc,status='old',form='formatted')
!
! read cell data
!
IF (ionode)THEN
READ(1,*) ntyp,nat,ibrav,(celldm(i),i=1,6)
if (ibrav==0) then
read(1,*) ((at(i,j),i=1,3),j=1,3)
end if
ENDIF
CALL mp_bcast(ntyp, ionode_id, world_comm)
CALL mp_bcast(nat, ionode_id, world_comm)
CALL mp_bcast(ibrav, ionode_id, world_comm)
CALL mp_bcast(celldm, ionode_id, world_comm)
IF (ibrav==0) THEN
CALL mp_bcast(at, ionode_id, world_comm)
ENDIF
!
CALL latgen(ibrav,celldm,at(1,1),at(1,2),at(1,3),omega)
alat = celldm(1)
at = at / alat ! bring at in units of alat
CALL volume(alat,at(1,1),at(1,2),at(1,3),omega)
!
! read atomic types, positions and masses
!
ALLOCATE (atm(ntyp))
DO nt = 1,ntyp
IF (ionode) READ(1,*) i,atm(nt),amass_from_file
CALL mp_bcast(i,ionode_id, world_comm)
CALL mp_bcast(amass_from_file,ionode_id, world_comm)
IF (i.NE.nt) CALL errore ('readfc','wrong data read',nt)
IF (amass(nt).EQ.0.d0) THEN
amass(nt) = amass_from_file/amu_ry
ELSE
WRITE(stdout,*) 'for atomic type',nt,' mass from file not used'
END IF
END DO
CALL mp_bcast(atm,ionode_id, world_comm)
CALL mp_bcast(amass,ionode_id, world_comm)
!
ALLOCATE (tau(3,nat), ityp(nat), zeu(3,3,nat))
!
DO na=1,nat
IF (ionode) READ(1,*) i,ityp(na),(tau(j,na),j=1,3)
CALL mp_bcast(i,ionode_id, world_comm)
IF (i.NE.na) CALL errore ('readfc','wrong data read',na)
END DO
CALL mp_bcast(ityp,ionode_id, world_comm)
CALL mp_bcast(tau,ionode_id, world_comm)
!
! read macroscopic variables
!
alph = 1.0_dp
IF (ionode) THEN
READ (1,'(a)') line
READ(line,*,iostat=ios) has_zstar, alph
IF ( ios /= 0 ) READ(line,*) has_zstar
ENDIF
!
CALL mp_bcast(has_zstar,ionode_id, world_comm)
IF (has_zstar) THEN
CALL mp_bcast(alph,ionode_id, world_comm)
IF (ionode) READ(1,*) ((epsil(i,j),j=1,3),i=1,3)
CALL mp_bcast(epsil,ionode_id, world_comm)
IF (ionode) THEN
DO na=1,nat
READ(1,*)
READ(1,*) ((zeu(i,j,na),j=1,3),i=1,3)