forked from dalcorso/thermo_pw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ph_restart.f90
1380 lines (1299 loc) · 47.2 KB
/
ph_restart.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
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) 2008-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 ph_restart
!----------------------------------------------------------------------------
!
! ... this module contains methods to read and write data saved by the
! phonon code to restart smoothly
!
USE xmltools
!
USE kinds, ONLY : DP
USE io_files, ONLY : prefix
USE control_ph,ONLY : tmp_dir_ph
USE io_global, ONLY : ionode, ionode_id
USE mp_images, ONLY : intra_image_comm
USE mp, ONLY : mp_bcast
!
IMPLICIT NONE
!
SAVE
!
PRIVATE
!
PUBLIC :: ph_writefile, ph_readfile, allocate_grid_variables, &
check_directory_phsave, destroy_status_run, check_available_bands, &
read_disp_pattern_only
!
INTEGER :: iunpun
!
! FIXME: obsolete variables?
CHARACTER(len=256) :: qexml_version = ' '
LOGICAL :: qexml_version_init = .FALSE.
!
CONTAINS
!
!------------------------------------------------------------------------
SUBROUTINE ph_writefile( what, iq, irr, ierr )
!------------------------------------------------------------------------
!
USE global_version, ONLY : version_number
USE control_ph, ONLY : ldisp, epsil, trans, zue, zeu
USE el_phon, ONLY : elph
USE freq_ph, ONLY : fpol, nfs, fiu, current_iu
USE ramanm, ONLY : lraman, elop
USE disp, ONLY : nqs, x_q, nq1, nq2, nq3
!
IMPLICIT NONE
!
CHARACTER(LEN=*), INTENT(IN) :: what
INTEGER, INTENT(IN) :: iq, irr
!
INTEGER, INTENT(OUT) :: ierr
!
CALL ph_restart_set_filename( what, irr, iq, 1, ierr)
!
IF ( ionode ) THEN
!
! ... here we start writing the ph-punch-file
!
!-------------------------------------------------------------------------------
! ... HEADER
!-------------------------------------------------------------------------------
!
IF (what=='init') THEN
!
CALL write_header_ph( "PH", TRIM(version_number) )
!
!
! With what='init' the routine writes the main variables that
! control the main flow of the dispersion calculation:
! The main flags of the phonon code, the mesh of q point, the
! number of q points and their coordinates.
!
!-------------------------------------------------------------------------------
! ... CONTROL
!-------------------------------------------------------------------------------
!
CALL write_control_ph( ldisp, epsil, trans, elph, zue, zeu, &
lraman, elop, fpol )
!
!-------------------------------------------------------------------------------
! ... Q POINTS AND FREQUENCY POINTS
!------------------------------------------------------------------------------
!
CALL write_qu( nqs, nq1, nq2, nq3, x_q, nfs, fiu, fpol )
!
ELSEIF (what=='status_ph') THEN
!
! In this case we save the information on the status of the calculation.
! The current q point, the current frequency, the label and the
! code with the point where the code arrived so far.
! The former is easy to read in the xml file,
! the latter is simpler to use in the code.
!
CALL write_status_ph(iq, current_iu)
!
ELSEIF (what=='data_u') THEN
!
! with what='data_u' this routine writes the information on the irreducible
! representations. Number of irreducible representations, number of modes
! for each representation and displacements u.
!
CALL write_modes(iq)
!
ELSEIF (what=='polarization') THEN
!
! With what='polarization' this routine saves the tensors that contain the
! polarization as a function of frequency.
!
CALL write_polarization(irr)
!
ELSEIF (what=='tensors') THEN
!
! With what='tensors' this routine saves the tensors that contain the
! result of the calculations done so far: epsilon, zstareu, ramtns, eloptns,
! dyn, zstarue.
!
CALL write_tensors()
!
ELSEIF (what=='data_dyn') THEN
!
! with what='data_dyn' this routine writes the information calculated
! separately for each irreducible representation. The contributions
! of the representation to the dynamical matrix and to the Born effective
! charges dP/du.
!
CALL write_ph_dyn(irr)
ELSEIF (what=='el_phon') THEN
! with what='data_dyn' this routine writes the information calculated
! for this irreducible representation to the electron phonon
!
CALL write_el_phon(irr)
END IF
CALL xmlw_closetag ( ) ! Root
CALL xml_closefile ( )
END IF
RETURN
!
CONTAINS
SUBROUTINE write_polarization(iu)
!
USE freq_ph, ONLY : polar, done_iu, fpol, done_fpol, fiu
IMPLICIT NONE
INTEGER :: iu
IF (.NOT.fpol) RETURN
CALL xmlw_opentag( "POLARIZ_IU" )
!
! Save the current flags
!
CALL xmlw_writetag( "DONE_POLARIZ_IU", done_fpol )
!
! Here we save the frequency dependent polarization at this iu
!
CALL xmlw_writetag( "FREQUENCY_IN_RY", fiu(iu) )
CALL xmlw_writetag( "CALCULATED_FREQUENCY", done_iu(iu) )
IF ( done_iu(iu) ) &
CALL xmlw_writetag( "POLARIZATION_IU", polar(:,:,iu) )
!
CALL xmlw_closetag( )
RETURN
END SUBROUTINE write_polarization
SUBROUTINE write_tensors()
!
USE control_ph, ONLY : done_epsil, done_start_zstar, done_zeu, done_zue
USE ramanm, ONLY : lraman, elop, ramtns, eloptns, done_lraman, &
done_elop
USE efield_mod, ONLY : zstareu0, zstareu, zstarue, epsilon
USE ions_base, ONLY : nat
IMPLICIT NONE
INTEGER :: na
!
CALL xmlw_opentag( "EF_TENSORS" )
!
! Save the current flags
!
CALL xmlw_writetag( "DONE_ELECTRIC_FIELD",done_epsil )
CALL xmlw_writetag( "DONE_START_EFFECTIVE_CHARGE",done_start_zstar )
CALL xmlw_writetag( "DONE_EFFECTIVE_CHARGE_EU",done_zeu )
CALL xmlw_writetag( "DONE_EFFECTIVE_CHARGE_PH",done_zue )
CALL xmlw_writetag( "DONE_RAMAN_TENSOR",done_lraman )
CALL xmlw_writetag( "DONE_ELECTRO_OPTIC",done_elop )
!
! save all calculated tensors
!
IF (done_epsil) &
CALL xmlw_writetag( "DIELECTRIC_CONSTANT", epsilon )
IF (done_start_zstar) &
CALL xmlw_writetag( "START_EFFECTIVE_CHARGES", zstareu0)
IF (done_zeu) &
CALL xmlw_writetag( "EFFECTIVE_CHARGES_EU", zstareu )
IF (done_lraman) THEN
DO na = 1, nat
CALL add_attr("atom", na)
CALL xmlw_writetag( "RAMAN_TNS",ramtns(:,:,:,na) )
END DO
END IF
IF (done_elop) &
CALL xmlw_writetag( "ELOP_TNS", eloptns)
IF (done_zue) &
CALL xmlw_writetag( "EFFECTIVE_CHARGES_UE", zstarue )
!
CALL xmlw_closetag( )
RETURN
END SUBROUTINE write_tensors
SUBROUTINE write_modes(iq)
USE modes, ONLY : nirr, npert, u, name_rap_mode, num_rap_mode
USE lr_symm_base, ONLY : nsymq, minus_q
! Workaround
use ions_base, only: nat
IMPLICIT NONE
! Workaround
INTEGER :: imode0, imode, irr, ipert, iq
CALL xmlw_opentag( "IRREPS_INFO" )
!
CALL xmlw_writetag( "QPOINT_NUMBER",iq)
!
CALL xmlw_writetag( "QPOINT_GROUP_RANK",nsymq)
!
CALL xmlw_writetag( "MINUS_Q_SYM",minus_q)
!
CALL xmlw_writetag( "NUMBER_IRR_REP",nirr)
!
imode0=0
DO irr=1,nirr
CALL xmlw_opentag( "REPRESENTION."//i2c(irr) )
CALL xmlw_writetag( "NUMBER_OF_PERTURBATIONS", npert(irr) )
DO ipert=1,npert(irr)
imode=imode0+ipert
CALL xmlw_opentag( "PERTURBATION."//i2c(ipert) )
!CALL xmlw_writetag( "SYMMETRY_TYPE_CODE", num_rap_mode(imode))
!CALL xmlw_writetag( "SYMMETRY_TYPE", name_rap_mode(imode) )
CALL xmlw_writetag( "DISPLACEMENT_PATTERN", u(:,imode) )
CALL xmlw_closetag( )
ENDDO
imode0=imode0+npert(irr)
CALL xmlw_closetag( )
ENDDO
!
CALL xmlw_closetag( )
RETURN
END SUBROUTINE write_modes
SUBROUTINE write_ph_dyn(irr)
USE partial, ONLY : done_irr
USE dynmat, ONLY : dyn_rec
USE efield_mod, ONLY : zstarue0_rec
USE control_ph, ONLY : trans, zue
IMPLICIT NONE
INTEGER, INTENT(IN) :: irr
IF (trans.OR.zeu) THEN
IF (done_irr(irr)) THEN
!
CALL xmlw_opentag( "PM_HEADER")
CALL xmlw_writetag( "DONE_IRR", done_irr(irr))
CALL xmlw_closetag( )
CALL xmlw_opentag( "PARTIAL_MATRIX")
CALL xmlw_writetag( "PARTIAL_DYN", dyn_rec(:,:))
IF ( zue .and. irr>0 ) &
CALL xmlw_writetag( "PARTIAL_ZUE", zstarue0_rec(:,:))
CALL xmlw_closetag( )
ENDIF
ENDIF
RETURN
END SUBROUTINE write_ph_dyn
SUBROUTINE write_el_phon(irr)
USE el_phon, ONLY : done_elph, el_ph_mat_rec_col, elph
USE modes, ONLY : npert
USE klist, ONLY : nks
USE wvfct, ONLY: nbnd
USE qpoint, ONLY : nksqtot, xk_col
USE control_lr, ONLY : lgamma
IMPLICIT NONE
INTEGER, INTENT(IN) :: irr
INTEGER :: ik, ikk, np
IF (.NOT. elph .OR. .NOT. done_elph(irr)) RETURN
!
CALL xmlw_opentag ( "EL_PHON_HEADER")
CALL xmlw_writetag( "DONE_ELPH", done_elph(irr))
CALL xmlw_closetag( ) ! el_phon_header
CALL xmlw_writetag( "NUMBER_OF_K", nksqtot)
CALL xmlw_writetag( "NUMBER_OF_BANDS", nbnd)
DO ik=1,nksqtot
ikk = 2 * ik - 1
IF (lgamma) ikk = ik
CALL xmlw_opentag( "K_POINT." // i2c(ik) )
CALL xmlw_writetag( "COORDINATES_XK", xk_col(:,ikk) )
DO np = 1, npert(irr)
CALL add_attr("perturbation",np)
CALL xmlw_writetag( "PARTIAL_ELPH", el_ph_mat_rec_col(:,:,ik,np) )
END DO
CALL xmlw_closetag( )
ENDDO
CALL xmlw_closetag( )
RETURN
END SUBROUTINE write_el_phon
END SUBROUTINE ph_writefile
!------------------------------------------------------------------------
SUBROUTINE write_header_ph( creator_name, creator_version )
!------------------------------------------------------------------------
!
IMPLICIT NONE
CHARACTER(LEN=*), INTENT(IN) :: creator_name, creator_version
CHARACTER(5), PARAMETER :: fmt_name = "QEXML"
CHARACTER(5), PARAMETER :: fmt_version = "1.4.0"
CALL xmlw_opentag( "HEADER" )
!
CALL add_attr( "NAME", fmt_name )
CALL add_attr( "VERSION", fmt_version )
CALL xmlw_writetag( "FORMAT", "" )
!
CALL add_attr( "NAME", creator_name )
CALL add_attr( "VERSION", creator_version )
CALL xmlw_writetag( "CREATOR", "")
!
CALL xmlw_closetag( )
!
END SUBROUTINE write_header_ph
!
!
SUBROUTINE write_control_ph( ldisp, epsil, trans, elph, zue, zeu, &
lraman, elop, fpol)
!------------------------------------------------------------------------
!
IMPLICIT NONE
LOGICAL, INTENT(IN) :: ldisp, epsil, trans, elph, zue, zeu, &
lraman, elop, fpol
CALL xmlw_opentag( "CONTROL" )
!
CALL xmlw_writetag( "DISPERSION_RUN", ldisp )
CALL xmlw_writetag( "ELECTRIC_FIELD", epsil )
CALL xmlw_writetag( "PHONON_RUN", trans )
CALL xmlw_writetag( "ELECTRON_PHONON", elph )
CALL xmlw_writetag( "EFFECTIVE_CHARGE_EU", zeu )
CALL xmlw_writetag( "EFFECTIVE_CHARGE_PH", zue )
CALL xmlw_writetag( "RAMAN_TENSOR", lraman )
CALL xmlw_writetag( "ELECTRO_OPTIC", elop )
CALL xmlw_writetag( "FREQUENCY_DEP_POL", fpol )
!
CALL xmlw_closetag( )
!
RETURN
END SUBROUTINE write_control_ph
SUBROUTINE write_status_ph(current_iq, current_iu)
!------------------------------------------------------------------------
!
USE control_ph, ONLY : where_rec, rec_code
IMPLICIT NONE
INTEGER, INTENT(IN) :: current_iq, current_iu
CALL xmlw_opentag ( "STATUS_PH" )
CALL xmlw_writetag( "STOPPED_IN", where_rec )
CALL xmlw_writetag( "RECOVER_CODE", rec_code )
CALL xmlw_writetag( "CURRENT_Q", current_iq )
CALL xmlw_writetag( "CURRENT_IU", current_iu )
CALL xmlw_closetag( )
!
RETURN
END SUBROUTINE write_status_ph
!
SUBROUTINE write_qu( nqs, nq1, nq2, nq3, x_q, nfs, fiu, fpol)
!------------------------------------------------------------------------
!
INTEGER, INTENT(IN) :: nqs, nfs, nq1, nq2, nq3
REAL(DP), INTENT(IN) :: x_q(3,nqs), fiu(nfs)
LOGICAL, INTENT(IN) :: fpol
INTEGER :: dim(3)
!
CALL xmlw_opentag( "Q_POINTS" )
!
dim(1) = nqs ! FIXME: workaround for pp.py
CALL xmlw_writetag( "NUMBER_OF_Q_POINTS", dim(1:1) )
IF (nqs > 1) THEN
dim(1) = nq1; dim(2) = nq2; dim(3) = nq3
CALL xmlw_writetag( "MESH_DIMENSIONS", dim )
ENDIF
CALL add_attr( "UNITS", "2 pi / a" )
CALL xmlw_writetag( "UNITS_FOR_Q-POINT", "" )
CALL xmlw_writetag( "Q-POINT_COORDINATES", x_q(:,:) )
!
CALL xmlw_closetag( )
!
IF (fpol) THEN
!
CALL xmlw_opentag( "FREQUENCIES" )
CALL xmlw_writetag( "NUMBER_OF_FREQUENCIES", nfs )
CALL xmlw_writetag( "FREQUENCY_VALUES", fiu(:) )
CALL xmlw_closetag( )
!
ENDIF
!
RETURN
END SUBROUTINE write_qu
!
!
!------------------------------------------------------------------------
SUBROUTINE ph_readfile( what, iq, irr, ierr )
!------------------------------------------------------------------------
!
IMPLICIT NONE
!
CHARACTER(LEN=*), INTENT(IN) :: what
INTEGER, INTENT(IN) :: irr, iq
!
! irreducible representation and q point
!
INTEGER, INTENT(OUT) :: ierr
!
CALL ph_restart_set_filename( what, irr, iq, -1, ierr)
IF (ierr /= 0) RETURN
!
SELECT CASE( what )
CASE( 'init' )
!
CALL read_header( ierr )
IF (ierr /= 0 ) RETURN
CALL read_control_ph( ierr )
IF ( ierr /= 0 ) RETURN
CALL read_qu( ierr )
IF ( ierr /= 0 ) RETURN
!
CASE( 'status_ph')
!
CALL read_status_ph( ierr )
IF ( ierr /= 0 ) RETURN
!
CASE( 'data_u' )
!
CALL read_disp_pattern( iunpun, iq, ierr )
IF ( ierr /= 0 ) RETURN
!
CASE( 'polarization' )
!
CALL read_polarization( irr, ierr )
IF ( ierr /= 0 ) RETURN
!
CASE( 'tensors' )
!
CALL read_tensors( ierr )
IF ( ierr /= 0 ) RETURN
!
CASE( 'data_dyn' )
!
CALL read_partial_ph( irr, ierr )
IF ( ierr /= 0 ) RETURN
!
CASE( 'el_phon' )
!
CALL read_el_phon( irr, ierr )
IF ( ierr /= 0 ) RETURN
!
CASE DEFAULT
!
CALL errore('ph_readfile','called with the wrong what',1)
!
END SELECT
!
IF (ionode) THEN
CALL xmlr_closetag ( ) ! Root
CALL xml_closefile( )
END IF
!
RETURN
!
END SUBROUTINE ph_readfile
!
!------------------------------------------------------------------------
SUBROUTINE read_header( ierr )
!------------------------------------------------------------------------
!
! ... this routine reads the format version of the current xml datafile
!
IMPLICIT NONE
INTEGER, INTENT(OUT) :: ierr
CHARACTER(LEN=1) :: dummy
ierr = 0
IF ( qexml_version_init ) RETURN
!
IF ( ionode ) THEN
!
CALL xmlr_opentag( "HEADER" )
CALL xmlr_readtag( "FORMAT", dummy )
CALL get_attr( "VERSION", qexml_version )
qexml_version_init = .TRUE.
CALL xmlr_closetag( )
!
ENDIF
!
CALL mp_bcast( qexml_version, ionode_id, intra_image_comm )
CALL mp_bcast( qexml_version_init, ionode_id, intra_image_comm )
RETURN
END SUBROUTINE read_header
!------------------------------------------------------------------------
SUBROUTINE read_status_ph( ierr )
!------------------------------------------------------------------------
!
! This routine reads the status of ph. It tells where the code stopped
! There is both a number, to be used within the code, and a label
! that is easier to read within the recover file.
!
! The convention is the following:
!
! rec_code where_rec status description
!
! -1000 Nothing has been read. There is no recover file.
! -40 phq_setup Only the displacements u have been read from file
! -30 phq_init u and dyn(0) read from file
! -25 not yet active. Restart in solve_e_fpol
! -20 solve_e all previous. Stopped within solve_e. There
! should be a recover file.
! -10 solve_e2 epsilon and zstareu are available if requested.
! Within solve_e2. There should be a recover file.
! 2 phescf all previous, raman tenson and elop tensor are
! available if required.
! 10 solve_linter all previous, within solve linter. Recover file
! should be present.
! 20 phqscf all previous dyn_rec(irr) and zstarue0(irr) are
! available.
! 30 dynmatrix all previous, dyn and zstarue are available.
!
!
USE control_ph, ONLY : current_iq, where_rec, rec_code_read
USE freq_ph, ONLY : current_iu
!
IMPLICIT NONE
!
INTEGER, INTENT(OUT) :: ierr
!
! ... then selected tags are read from the other sections
!
ierr=0
IF ( ionode ) THEN
!
CALL xmlr_opentag( "STATUS_PH" )
CALL xmlr_readtag( "STOPPED_IN", where_rec )
CALL xmlr_readtag( "RECOVER_CODE", rec_code_read )
CALL xmlr_readtag( "CURRENT_Q", current_iq )
CALL xmlr_readtag( "CURRENT_IU", current_iu )
CALL xmlr_closetag( )
!
END IF
!
CALL mp_bcast( where_rec, ionode_id, intra_image_comm )
CALL mp_bcast( rec_code_read, ionode_id, intra_image_comm )
CALL mp_bcast( current_iq, ionode_id, intra_image_comm )
CALL mp_bcast( current_iu, ionode_id, intra_image_comm )
!
RETURN
!
END SUBROUTINE read_status_ph
!
!------------------------------------------------------------------------
SUBROUTINE read_control_ph( ierr )
!------------------------------------------------------------------------
USE control_ph, ONLY : ldisp, epsil, trans, zue, zeu
USE el_phon, ONLY : elph
USE ramanm, ONLY : lraman, elop
USE freq_ph, ONLY : fpol
!
IMPLICIT NONE
!
INTEGER, INTENT(OUT) :: ierr
LOGICAL :: ldisp_, epsil_, trans_, zue_, zeu_, elph_, lraman_, elop_, &
fpol_
!
ierr=0
IF ( ionode ) THEN
CALL xmlr_opentag( "CONTROL" )
!
CALL xmlr_readtag( "DISPERSION_RUN", ldisp_ )
CALL xmlr_readtag( "ELECTRIC_FIELD", epsil_ )
CALL xmlr_readtag( "PHONON_RUN", trans_ )
CALL xmlr_readtag( "ELECTRON_PHONON", elph_ )
CALL xmlr_readtag( "EFFECTIVE_CHARGE_EU", zeu_ )
CALL xmlr_readtag( "EFFECTIVE_CHARGE_PH", zue_ )
CALL xmlr_readtag( "RAMAN_TENSOR", lraman_ )
CALL xmlr_readtag( "ELECTRO_OPTIC", elop_ )
CALL xmlr_readtag( "FREQUENCY_DEP_POL", fpol_ )
!
CALL xmlr_closetag( )
!
END IF
CALL mp_bcast( ldisp_, ionode_id, intra_image_comm )
CALL mp_bcast( epsil_, ionode_id, intra_image_comm )
CALL mp_bcast( trans_, ionode_id, intra_image_comm )
CALL mp_bcast( elph_, ionode_id, intra_image_comm )
CALL mp_bcast( zeu_, ionode_id, intra_image_comm )
CALL mp_bcast( zue_, ionode_id, intra_image_comm )
CALL mp_bcast( lraman_, ionode_id, intra_image_comm )
CALL mp_bcast( elop_, ionode_id, intra_image_comm )
CALL mp_bcast( fpol_, ionode_id, intra_image_comm )
!
IF (ldisp_ .neqv. ldisp) CALL errore('read_control_ph','wrong ldisp',1)
IF (epsil_ .neqv. epsil) CALL errore('read_control_ph','wrong epsil',1)
IF (trans_ .neqv. trans) CALL errore('read_control_ph','wrong trans',1)
IF (elph_ .neqv. elph) CALL errore('read_control_ph','wrong elph',1)
IF (zeu_ .neqv. zeu) CALL errore('read_control_ph','wrong zeu',1)
IF (zue_ .neqv. zue) CALL errore('read_control_ph','wrong zue',1)
IF (lraman_ .neqv. lraman) CALL errore('read_control_ph','wrong lraman',1)
IF (elop_ .neqv. elop) CALL errore('read_control_ph','wrong elop',1)
IF (fpol_ .neqv. fpol) CALL errore('read_control_ph','wrong fpol',1)
!
RETURN
!
END SUBROUTINE read_control_ph
!
!------------------------------------------------------------------------
SUBROUTINE read_qu( ierr )
!------------------------------------------------------------------------
!
USE disp, ONLY : nqs, x_q, nq1, nq2, nq3, lgamma_iq
USE freq_ph, ONLY : fpol, nfs, fiu
!
IMPLICIT NONE
!
INTEGER, INTENT(OUT) :: ierr
INTEGER :: nfs_, nq1_, nq2_, nq3_, iq
LOGICAL :: exst
INTEGER :: dim(3)
!
ierr=0
IF (ionode) THEN
CALL xmlr_opentag( "Q_POINTS" )
!
CALL xmlr_readtag( "NUMBER_OF_Q_POINTS", nqs )
dim(3) = 0
IF (nqs > 1) CALL xmlr_readtag( "MESH_DIMENSIONS", dim )
!
ALLOCATE(x_q(3,nqs))
CALL xmlr_readtag( "Q-POINT_COORDINATES", x_q(1:3,1:nqs) )
!
CALL xmlr_closetag( )
!
IF (fpol) THEN
!
CALL xmlr_opentag( "FREQUENCIES" )
!
CALL xmlr_readtag( "NUMBER_OF_FREQUENCIES", nfs_ )
!
CALL xmlr_readtag( "FREQUENCY_VALUES", fiu(1:nfs_) )
!
CALL xmlr_closetag( )
!
ENDIF
ENDIF
CALL mp_bcast( nqs, ionode_id, intra_image_comm )
IF (nqs > 1) THEN
CALL mp_bcast( dim, ionode_id, intra_image_comm )
nq1_ = dim(1); nq2_ = dim(2); nq3_ = dim(3)
IF ( (nq1_ /= nq1 ) .OR. (nq2_ /= nq2) .OR. (nq3_ /= nq3 ) ) &
CALL errore('read_qu','nq1, nq2, or nq3 do not match',1)
!
ENDIF
IF (.NOT. ionode) ALLOCATE(x_q(3,nqs))
CALL mp_bcast( x_q, ionode_id, intra_image_comm )
ALLOCATE(lgamma_iq(nqs))
DO iq=1,nqs
lgamma_iq(iq)=(x_q(1,iq)==0.D0.AND.x_q(2,iq)==0.D0.AND.x_q(3,iq)==0.D0)
END DO
IF (fpol) THEN
CALL mp_bcast( nfs_, ionode_id, intra_image_comm )
IF (nfs_ /= nfs) &
CALL errore('read_qu','wrong number of frequencies',1)
CALL mp_bcast( fiu, ionode_id, intra_image_comm )
END IF
RETURN
!
END SUBROUTINE read_qu
SUBROUTINE read_partial_ph( irr, ierr )
USE partial, ONLY : done_irr
USE efield_mod, ONLY : zstarue0_rec
USE dynmat, ONLY : dyn_rec
USE control_ph, ONLY : trans, zue
IMPLICIT NONE
INTEGER, INTENT(OUT) :: ierr
INTEGER, INTENT(IN) :: irr
!
ierr=0
IF (ionode) THEN
IF (trans) THEN
CALL xmlr_opentag( "PM_HEADER" )
CALL xmlr_readtag( "DONE_IRR",done_irr(irr) )
CALL xmlr_closetag( )
CALL xmlr_opentag( "PARTIAL_MATRIX" )
CALL xmlr_readtag( "PARTIAL_DYN", dyn_rec(:,:) )
IF ( zue .AND. irr>0 ) &
CALL xmlr_readtag( "PARTIAL_ZUE", zstarue0_rec(:,:) )
CALL xmlr_closetag( )
ENDIF
ENDIF
IF (trans) THEN
CALL mp_bcast( done_irr(irr), ionode_id, intra_image_comm )
CALL mp_bcast( dyn_rec, ionode_id, intra_image_comm )
IF (zue) CALL mp_bcast( zstarue0_rec, ionode_id, intra_image_comm )
ENDIF
RETURN
END SUBROUTINE read_partial_ph
SUBROUTINE read_el_phon(irr, ierr)
USE qpoint, ONLY : nksq, nksqtot
USE el_phon, ONLY : el_ph_mat_rec, el_ph_mat_rec_col, done_elph, elph
USE modes, ONLY : npert
USE wvfct, ONLY : nbnd
USE mp_pools, ONLY : npool
IMPLICIT NONE
INTEGER, INTENT(in) :: irr
INTEGER, INTENT(OUT) :: ierr
REAL(DP) :: xkdum(3)
INTEGER :: ik, np, np_, npe, idum
!
ierr=0
IF (.NOT. elph) RETURN
npe=npert(irr)
IF (npool>1) THEN
ALLOCATE(el_ph_mat_rec_col(nbnd,nbnd,nksqtot,npe))
ELSE
el_ph_mat_rec_col => el_ph_mat_rec
ENDIF
IF (ionode) THEN
CALL xmlr_opentag( "EL_PHON_HEADER")
CALL xmlr_readtag( "DONE_ELPH", done_elph(irr) )
CALL xmlr_closetag( )
CALL xmlr_opentag( "PARTIAL_EL_PHON" )
CALL xmlr_readtag( "NUMBER_OF_K", idum )
CALL xmlr_readtag( "NUMBER_OF_BANDS", idum )
DO ik=1,nksqtot
CALL xmlr_opentag( "K_POINT." // i2c(ik) )
CALL xmlr_readtag( "COORDINATES_XK", xkdum(:) )
DO np = 1, npert(irr)
CALL xmlr_readtag( "PARTIAL_ELPH", el_ph_mat_rec_col(:,:,ik,np) )
CALL get_attr("perturbation", np_)
END DO
CALL xmlr_closetag( )
ENDDO
CALL xmlr_closetag( )
ENDIF
CALL mp_bcast(done_elph(irr), ionode_id, intra_image_comm)
CALL mp_bcast(el_ph_mat_rec_col, ionode_id, intra_image_comm)
IF (npool > 1) THEN
CALL el_ph_distribute(npe,el_ph_mat_rec,el_ph_mat_rec_col,&
nksqtot,nksq)
DEALLOCATE(el_ph_mat_rec_col)
ENDIF
RETURN
END SUBROUTINE read_el_phon
!
!---------------------------------------------------------------------------
SUBROUTINE read_disp_pattern_only(iunpun, filename, current_iq, ierr)
!---------------------------------------------------------------------------
!!
!! Wrapper routine used by EPW: open file, calls read_disp_pattern
!!
!
IMPLICIT NONE
!
INTEGER, INTENT(in) :: iunpun
!! Unit
INTEGER, INTENT(in) :: current_iq
!! Current q-point
CHARACTER(LEN=*), INTENT(in) :: filename
!! self-explanatory
INTEGER, INTENT(out) :: ierr
!! Error code
INTEGER :: iun
!
iun = xml_openfile (filename)
IF ( iun == -1 ) then
ierr = 1
return
end if
CALL xmlr_opentag ( 'Root' )
CALL read_disp_pattern(iun, current_iq, ierr)
CALL xmlr_closetag () ! Root
CALL xml_closefile ()
!
END SUBROUTINE read_disp_pattern_only
!
!---------------------------------------------------------------------------
SUBROUTINE read_disp_pattern(iunpun, current_iq, ierr)
!---------------------------------------------------------------------------
!!
!! This routine reads the displacement patterns.
!!
USE modes, ONLY : nirr, npert, u, name_rap_mode, num_rap_mode
USE lr_symm_base, ONLY : minus_q, nsymq
USE io_global, ONLY : ionode, ionode_id
USE mp, ONLY : mp_bcast
!
IMPLICIT NONE
!
INTEGER, INTENT(in) :: current_iq
!! Current q-point
INTEGER, INTENT(in) :: iunpun
!! Current q-point
INTEGER, INTENT(out) :: ierr
!! Error
!
! Local variables
INTEGER :: imode0, imode
!! Counter on modes
INTEGER :: irr
!! Counter on irreducible representations
INTEGER :: ipert
!! Counter on perturbations at each irr
INTEGER :: iq
!! Current q-point
!
ierr = 0
IF (ionode) THEN
CALL xmlr_opentag( "IRREPS_INFO" )
CALL xmlr_readtag( "QPOINT_NUMBER",iq )
ENDIF
CALL mp_bcast(iq, ionode_id, intra_image_comm)
IF (iq /= current_iq) CALL errore('read_disp_pattern', ' Problems with current_iq', 1)
!
IF (ionode) THEN
!
CALL xmlr_readtag( "QPOINT_GROUP_RANK", nsymq )
CALL xmlr_readtag( "MINUS_Q_SYM", minus_q )
CALL xmlr_readtag( "NUMBER_IRR_REP", nirr )
imode0 = 0
DO irr = 1, nirr
CALL xmlr_opentag( "REPRESENTION."// i2c(irr) )
CALL xmlr_readtag( "NUMBER_OF_PERTURBATIONS", npert(irr) )
DO ipert = 1, npert(irr)
imode = imode0 + ipert
CALL xmlr_opentag( "PERTURBATION."// i2c(ipert) )
! not sure why these two lines break epw
!CALL xmlr_readtag( "SYMMETRY_TYPE_CODE", num_rap_mode(imode) )
!CALL xmlr_readtag( "SYMMETRY_TYPE", name_rap_mode(imode) )
CALL xmlr_readtag( "DISPLACEMENT_PATTERN", u(:,imode) )
CALL xmlr_closetag( )
ENDDO
imode0 = imode0 + npert(irr)
CALL xmlr_closetag( )
ENDDO
!
CALL xmlr_closetag( )
!
ENDIF
!
CALL mp_bcast(nirr , ionode_id, intra_image_comm)
CALL mp_bcast(npert , ionode_id, intra_image_comm)
CALL mp_bcast(nsymq , ionode_id, intra_image_comm)
CALL mp_bcast(minus_q, ionode_id, intra_image_comm)
CALL mp_bcast(u , ionode_id, intra_image_comm)
!CALL mp_bcast(name_rap_mode, ionode_id, intra_image_comm)
!CALL mp_bcast(num_rap_mode, ionode_id, intra_image_comm)
!
RETURN
!
END SUBROUTINE read_disp_pattern
!
!---------------------------------------------------------------------------
SUBROUTINE read_tensors( ierr )
!---------------------------------------------------------------------------
!
! This routine reads the tensors that have been already calculated
!
USE ions_base, ONLY : nat
USE control_ph, ONLY : done_epsil, done_start_zstar, done_zeu, done_zue
USE ramanm, ONLY : lraman, elop, ramtns, eloptns, done_lraman, done_elop
USE efield_mod, ONLY : zstareu, zstarue, zstarue0, zstareu0, epsilon
IMPLICIT NONE
INTEGER, INTENT(OUT) :: ierr
INTEGER :: imode0, imode, ipol, irr, ipert, iq, iu, na, na_
!
ierr=0
IF (ionode) THEN
CALL xmlr_opentag( "EF_TENSORS" )
!
CALL xmlr_readtag( "DONE_ELECTRIC_FIELD", done_epsil )
CALL xmlr_readtag( "DONE_START_EFFECTIVE_CHARGE", done_start_zstar )
CALL xmlr_readtag( "DONE_EFFECTIVE_CHARGE_EU", done_zeu )
CALL xmlr_readtag( "DONE_EFFECTIVE_CHARGE_PH", done_zue )
CALL xmlr_readtag( "DONE_RAMAN_TENSOR", done_lraman )
CALL xmlr_readtag( "DONE_ELECTRO_OPTIC", done_elop )
IF (done_epsil) &
CALL xmlr_readtag( "DIELECTRIC_CONSTANT",epsilon )
IF (done_start_zstar) &
CALL xmlr_readtag( "START_EFFECTIVE_CHARGES",zstareu0 )
IF (done_zeu) &
CALL xmlr_readtag( "EFFECTIVE_CHARGES_EU",zstareu )
IF (done_lraman) THEN
DO na = 1, nat
CALL xmlr_readtag( "RAMAN_TNS",ramtns(:,:,:,na) )
CALL get_attr("atom", na_)
END DO
END IF
IF (done_elop) CALL xmlr_readtag( "ELOP_TNS",eloptns )
IF (done_zue) CALL xmlr_readtag( "EFFECTIVE_CHARGES_UE", zstarue )
!
CALL xmlr_closetag( )
!
ENDIF
CALL mp_bcast( done_epsil, ionode_id, intra_image_comm )
CALL mp_bcast( done_start_zstar, ionode_id, intra_image_comm )
CALL mp_bcast( done_zeu, ionode_id, intra_image_comm )
CALL mp_bcast( done_zue, ionode_id, intra_image_comm )
CALL mp_bcast( done_lraman, ionode_id, intra_image_comm )
CALL mp_bcast( done_elop, ionode_id, intra_image_comm )
IF (done_epsil) CALL mp_bcast( epsilon, ionode_id, intra_image_comm )
IF (done_start_zstar) THEN
CALL mp_bcast( zstareu0, ionode_id, intra_image_comm )
DO ipol=1,3
DO imode=1,3*nat
zstarue0(imode,ipol)=zstareu0(ipol,imode)
ENDDO
ENDDO
ENDIF
IF (done_zeu) CALL mp_bcast( zstareu, ionode_id, intra_image_comm )
IF (done_zue) CALL mp_bcast( zstarue, ionode_id, intra_image_comm )
IF (done_lraman) CALL mp_bcast( ramtns, ionode_id, intra_image_comm )
IF (done_elop) CALL mp_bcast( eloptns, ionode_id, intra_image_comm )
RETURN
END SUBROUTINE read_tensors
!----------------------------------------------------------------------------
SUBROUTINE read_polarization( iu, ierr )
!
! This routine reads the tensors that have been already calculated
!
USE ions_base, ONLY : nat
USE freq_ph, ONLY : fpol, done_iu, fiu, polar
IMPLICIT NONE
INTEGER, INTENT(IN) :: iu
INTEGER, INTENT(OUT) :: ierr
!
ierr=0
IF ( .NOT.fpol ) RETURN
IF (ionode) THEN
CALL xmlr_opentag( "POLARIZ_IU" )
!
CALL xmlr_readtag( "FREQUENCY_IN_RY", fiu(iu) )
CALL xmlr_readtag( "CALCULATED_FREQUENCY", &
done_iu(iu))
IF (done_iu(iu)) &
CALL xmlr_readtag( "POLARIZATION_IU", polar(:,:,iu) )
!
CALL xmlr_closetag( )
!
ENDIF