-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcplib.f90
2125 lines (1895 loc) · 65.2 KB
/
cplib.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) 2002-2010 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 .
!=----------------------------------------------------------------------------=!
SUBROUTINE ecutoffs_setup( ecutwfc_, ecutrho_, ecfixed_, qcutz_, &
q2sigma_, refg_ )
!------------------------------------------------------------------------------!
USE kinds, ONLY: DP
USE constants, ONLY: eps8
USE gvecw, ONLY: ecutwfc
USE gvecw, ONLY: ecfixed, qcutz, q2sigma
USE gvect, ONLY: ecutrho
USE gvecs, ONLY: ecuts, dual, doublegrid
USE pseudopotential, only: tpstab
USE io_global, only: stdout, ionode
USE uspp, only: okvan
use betax, only: mmx, refg
IMPLICIT NONE
REAL(DP), INTENT(IN) :: ecutwfc_, ecutrho_, ecfixed_, qcutz_, &
q2sigma_, refg_
ecutwfc = ecutwfc_
IF ( ecutrho_ <= 0.D0 ) THEN
!
dual = 4.D0
!
ELSE
!
dual = ecutrho_ / ecutwfc
!
IF ( dual <= 1.D0 ) &
CALL errore( ' ecutoffs_setup ', ' invalid dual? ', 1 )
!
END IF
doublegrid = ( dual > 4.D0 )
IF ( doublegrid .AND. .NOT. okvan ) &
CALL errore( 'setup', 'No USPP: set ecutrho=4*ecutwfc', 1 )
ecutrho = dual * ecutwfc
!
IF ( doublegrid ) THEN
!
ecuts = 4.D0 * ecutwfc
!
ELSE
!
ecuts = ecutrho
!
END IF
!
ecfixed = ecfixed_
qcutz = qcutz_
q2sigma = q2sigma_
IF( refg_ < 0.0001d0 ) THEN
tpstab = .FALSE.
refg = 0.05d0
ELSE
refg = refg_
END IF
CALL set_interpolation_table_size( mmx, refg, ecutrho )
RETURN
END SUBROUTINE ecutoffs_setup
SUBROUTINE set_interpolation_table_size( mmx, refg, gmax )
USE control_flags, only: thdyn
USE kinds, only: DP
IMPLICIT NONE
INTEGER, INTENT(OUT) :: mmx
REAL(DP), INTENT(IN) :: refg
REAL(DP), INTENT(IN) :: gmax
IF( thdyn ) THEN
! ... a larger table is used when cell is moving to allow
! ... large volume fluctuation
mmx = NINT( 2.0d0 * gmax / refg )
ELSE
mmx = NINT( 1.2d0 * gmax / refg )
END IF
RETURN
END SUBROUTINE set_interpolation_table_size
SUBROUTINE gcutoffs_setup( alat, tk_inp, nk_inp, kpoints_inp )
! (describe briefly what this routine does...)
! ----------------------------------------------
USE kinds, ONLY: DP
USE gvecw, ONLY: ecutwfc, gcutw
USE gvect, ONLY: ecutrho, gcutm
USE gvecs, ONLY: ecuts, gcutms
USE gvecw, ONLY: ekcut, gkcut
USE constants, ONLY: eps8, pi
IMPLICIT NONE
! ... declare subroutine arguments
REAL(DP), INTENT(IN) :: alat
LOGICAL, INTENT(IN) :: tk_inp
INTEGER, INTENT(IN) :: nk_inp
REAL(DP), INTENT(IN) :: kpoints_inp(3,*)
! ... declare other variables
INTEGER :: i
REAL(DP) :: kcut, ksq
REAL(DP) :: tpiba
! end of declarations
! ----------------------------------------------
! ... Set Values for the cutoff
IF( alat < eps8 ) THEN
CALL errore(' cut-off setup ', ' alat too small ', 0)
END IF
tpiba = 2.0d0 * pi / alat
! ... Constant cutoff simulation parameters
gcutw = ecutwfc / tpiba**2 ! wave function cut-off
gcutm = ecutrho / tpiba**2 ! potential cut-off
gcutms= ecuts / tpiba**2 ! smooth mesh cut-off
kcut = 0.0_DP
IF ( tk_inp ) THEN
! ... augment plane wave cutoff to include all k+G's
DO i = 1, nk_inp
! ... calculate modulus
ksq = kpoints_inp( 1, i ) ** 2 + kpoints_inp( 2, i ) ** 2 + kpoints_inp( 3, i ) ** 2
IF ( ksq > kcut ) kcut = ksq
END DO
END IF
gkcut = ( sqrt( kcut ) + sqrt( gcutw ) ) ** 2
ekcut = gkcut * tpiba ** 2
RETURN
END SUBROUTINE gcutoffs_setup
! ----------------------------------------------
SUBROUTINE cutoffs_print_info()
! Print out information about different cut-offs
USE gvecw, ONLY: ecutwfc, gcutw
USE gvect, ONLY: ecutrho, gcutm
USE gvecw, ONLY: ecfixed, qcutz, q2sigma
USE gvecw, ONLY: ekcut, gkcut
USE gvecs, ONLY: ecuts, gcutms
use betax, only: mmx, refg
USE io_global, ONLY: stdout
USE input_parameters, ONLY: ref_cell, ref_alat
WRITE( stdout, 100 ) ecutwfc, ecutrho, ecuts, sqrt(gcutw), &
sqrt(gcutm), sqrt(gcutms)
IF(ref_cell) WRITE( stdout,'(3X,"Reference Cell alat is",F14.8,1X,"A.U is used to Compute Gcutoffs:")') ref_alat ! BS : debug
IF( qcutz > 0.0d0 ) THEN
WRITE( stdout, 150 ) qcutz, q2sigma, ecfixed
END IF
WRITE( stdout,200) refg, mmx
100 FORMAT(/,3X,'Energy Cut-offs',/ &
,3X,'---------------',/ &
,3X,'Ecutwfc = ',F6.1,' Ry, ', 3X,'Ecutrho = ',F6.1,' Ry, ', 3X,'Ecuts = ',F6.1,' Ry',/ &
,3X,'Gcutwfc = ',F6.1,' , ', 3X,'Gcutrho = ',F6.1,' ', 3X,'Gcuts = ',F6.1)
150 FORMAT( 3X,'modified kinetic energy functional, with parameters:',/, &
3X,'ecutz = ',f8.4,' ecsig = ', f7.4,' ecfix = ',f6.2)
200 FORMAT( 3X,'NOTA BENE: refg, mmx = ', f10.6,I6 )
RETURN
END SUBROUTINE cutoffs_print_info
! ----------------------------------------------
SUBROUTINE orthogonalize_info( )
USE control_flags, ONLY: ortho_eps, ortho_max
USE io_global, ONLY: stdout
IMPLICIT NONE
WRITE(stdout, 585)
WRITE(stdout, 511) ortho_eps, ortho_max
511 FORMAT( 3X,'Orthog. with lagrange multipliers : eps = ',E10.2, ', max = ',I3)
585 FORMAT( 3X,'Eigenvalues calculated without the kinetic term contribution')
RETURN
END SUBROUTINE orthogonalize_info
! ----------------------------------------------
SUBROUTINE electrons_print_info( )
USE kinds, ONLY: DP
USE electrons_base, ONLY: nbnd, nspin, nel, nelt, nupdwn, iupdwn, &
f, qbac
USE io_global, ONLY: stdout
USE ions_base, ONLY: zv, nsp, na
IMPLICIT NONE
INTEGER :: i,is
IF( nspin == 1) THEN
WRITE(stdout,6) nelt, nbnd
WRITE(stdout,7) ( f( i ), i = 1, nbnd )
ELSE
WRITE(stdout,8) nelt
WRITE(stdout,9) nel(1)
WRITE(stdout,7) ( f( i ), i = 1, nupdwn(1))
WRITE(stdout,10) nel(2)
WRITE(stdout,7) ( f( i ), i = iupdwn(2), ( iupdwn(2) + nupdwn(2) - 1 ) )
END IF
qbac=0.
do is=1,nsp
qbac=qbac+na(is)*zv(is)
end do
qbac=qbac-nelt
if(qbac.ne.0) write(stdout,11) qbac
6 FORMAT(/,3X,'Electronic states',/ &
,3X,'-----------------',/ &
,3X,'Number of Electrons= ',I5,', of States = ',I5,/ &
,3X,'Occupation numbers :')
7 FORMAT(2X,10F5.2)
8 FORMAT(/,3X,'Electronic states',/ &
,3X,'-----------------',/ &
,3X,'Local Spin Density calculation',/ &
,3X,'Number of Electrons= ',I5)
9 FORMAT( 3X,'Spins up = ', I5, ', occupations: ')
10 FORMAT( 3X,'Spins down = ', I5, ', occupations: ')
11 FORMAT(/,3X,'WARNING: system charge = ',F12.6)
RETURN
END SUBROUTINE electrons_print_info
! ----------------------------------------------
SUBROUTINE exch_corr_print_info()
USE funct, ONLY: write_dft_name
USE io_global, ONLY: stdout
IMPLICIT NONE
WRITE(stdout,800)
call write_dft_name ( )
800 FORMAT(//,3X,'Exchange and correlations functionals',/ &
,3X,'-------------------------------------')
RETURN
END SUBROUTINE exch_corr_print_info
! ----------------------------------------------
SUBROUTINE ions_print_info( )
! Print info about input parameter for ion dynamic
USE io_global, ONLY: ionode, stdout
USE control_flags, ONLY: tranp, amprp, tnosep, tolp, tfor, tsdp, &
tzerop, tv0rd, taurdr, nbeg, tcp, tcap
USE ions_base, ONLY: tau_srt, if_pos, ind_srt, nsp, na, &
amass, nat, fricp, greasp, rcmax
USE ions_nose, ONLY: tempw, ndega
USE constants, ONLY: amu_au
IMPLICIT NONE
integer is, ia, k, ic, isa
LOGICAL :: ismb( 3 )
WRITE( stdout, 50 )
IF( .NOT. tfor ) THEN
WRITE( stdout, 518 )
ELSE
WRITE( stdout, 520 )
IF( tsdp ) THEN
WRITE( stdout, 521 )
ELSE
WRITE( stdout, 522 )
END IF
WRITE( stdout, 523 ) ndega
WRITE( stdout, 524 ) fricp, greasp
IF( tv0rd ) THEN
WRITE( stdout, 850 )
ELSE IF ( tzerop ) THEN
WRITE( stdout, 635 )
ENDIF
END IF
DO is = 1, nsp
IF( tranp(is) ) THEN
WRITE( stdout,510)
WRITE( stdout,512) is, amprp(is)
END IF
END DO
WRITE(stdout,660)
isa = 0
DO IS = 1, nsp
WRITE(stdout,1000) is, na(is), amass(is)*amu_au, amass(is), rcmax(is)
DO IA = 1, na(is)
isa = isa + 1
WRITE(stdout,1010) ( tau_srt(k,isa), K = 1,3 )
END DO
END DO
IF ( ( nbeg > -1 ) .AND. ( .NOT. taurdr ) ) THEN
WRITE(stdout,661)
ELSE
WRITE(stdout,662)
ENDIF
IF( tfor ) THEN
IF( ANY( ( if_pos( 1:3, 1:nat ) == 0 ) ) ) THEN
WRITE(stdout,1020)
WRITE(stdout,1022)
DO isa = 1, nat
ia = ind_srt( isa )
ismb( 1 ) = ( if_pos(1,ia) /= 0 )
ismb( 2 ) = ( if_pos(2,ia) /= 0 )
ismb( 3 ) = ( if_pos(3,ia) /= 0 )
IF( .NOT. ALL( ismb ) ) THEN
WRITE( stdout, 1023 ) isa, ( ismb(k), K = 1, 3 )
END IF
END DO
ELSE
WRITE(stdout,1021)
END IF
END IF
IF( tfor ) THEN
if( ( tcp .or. tcap .or. tnosep ) .and. tsdp ) then
call errore(' ions_print_info', &
' Temperature control not allowed with steepest descent',1)
endif
IF(.not. tcp .and. .not. tcap .and. .not. tnosep ) THEN
WRITE( stdout,550)
ELSE IF( tcp .and. tcap ) then
call errore(' ions_print_info', ' Velocity rescaling not' &
//' compatible with random velocity initialization',1)
ELSE IF( tcp .and. tnosep ) then
call errore(' ions_print_info', ' Velocity rescaling and' &
//' Nose thermostat are incompatible',1)
ELSE IF(tcap .and. tnosep ) then
call errore(' ions_print_info', ' Nose thermostat not' &
//' compatible with random velocity initialization',1)
ELSE IF(tcp) THEN
WRITE( stdout,555) tempw,tolp
ELSE IF(tcap) THEN
WRITE( stdout,560) tempw,tolp
ELSE IF(tnosep) THEN
WRITE( stdout,595)
ELSE
WRITE( stdout,550)
END IF
END IF
50 FORMAT(//,3X,'Ions Simulation Parameters',/ &
,3X,'--------------------------')
510 FORMAT( 3X,'Initial random displacement of ionic coordinates',/, &
3X,' specie amplitude')
512 FORMAT( 3X,I7,2X,F9.6)
518 FORMAT( 3X,'Ions are not allowed to move')
520 FORMAT( 3X,'Ions are allowed to move')
521 FORMAT( 3X,'Ions dynamics with steepest descent')
522 FORMAT( 3X,'Ions dynamics with newton equations')
523 format( 3X,'the temperature is computed for ',i5,' degrees of freedom')
524 format( 3X,'ion dynamics with fricp = ',f7.4,' and greasp = ',f7.4)
550 FORMAT( 3X,'Ionic temperature is not controlled')
555 FORMAT( 3X,'Ionic temperature control via ', &
'rescaling of velocities :',/ &
,3X,'temperature required = ',F10.5,'K, ', &
'tolerance = ',F10.5,'K')
560 FORMAT( 3X,'Ionic temperature control via ', &
'canonical velocities rescaling :',/ &
,3X,'temperature required = ',F10.5,'K, ', &
'tolerance = ',F10.5,'K')
595 FORMAT( 3X,'Ionic temperature control via nose thermostat')
635 FORMAT( 3X,'Zero initial momentum for ions')
660 FORMAT( 3X,'Ionic position (from input)', /, &
3X,'sorted by specie, and converted to real a.u. coordinates')
661 FORMAT( 3X,'Ionic position will be re-read from restart file')
662 FORMAT( 3X,'Ionic position read from input file')
850 FORMAT( 3X,'Initial ion velocities read from input')
1000 FORMAT(3X,'Species ',I3,' atoms = ',I4,' mass = ',F12.2, ' (a.u.), ', &
& F12.2, ' (amu)', ' rcmax = ', F6.2, ' (a.u.)' )
1010 FORMAT(3X,3(1X,F12.6))
1020 FORMAT(/,3X,'NOT all atoms are allowed to move ')
1021 FORMAT(/,3X,'All atoms are allowed to move')
1022 FORMAT( 3X,' indx ..x.. ..y.. ..z..')
1023 FORMAT( 3X,I4,3(1X,L5))
RETURN
END SUBROUTINE ions_print_info
! ----------------------------------------------
subroutine cell_print_info( )
USE constants, ONLY: au_gpa
USE control_flags, ONLY: thdyn, tsdc, tzeroc, tbeg, nbeg, tpre
USE control_flags, ONLY: tnoseh
USE io_global, ONLY: stdout
USE cell_base, ONLY: press, frich, greash, wmass
IMPLICIT NONE
WRITE(stdout,545 )
IF ( tpre ) WRITE( stdout, 600 )
IF ( tbeg ) THEN
WRITE(stdout,546)
ELSE
WRITE(stdout,547)
IF( nbeg > -1 ) WRITE( stdout, 548 )
END IF
IF( .NOT. thdyn ) THEN
WRITE( stdout,525)
WRITE( stdout,606)
ELSE
IF( tsdc ) THEN
WRITE( stdout,526)
ELSE
IF( frich /= 0.0d0 ) THEN
WRITE( stdout,602) frich, greash
ELSE
WRITE( stdout,527)
END IF
IF( tnoseh ) then
WRITE( stdout,604)
ELSE
WRITE( stdout,565)
END IF
IF( tzeroc ) THEN
WRITE( stdout,563)
ENDIF
END IF
WRITE( stdout,530) press * au_gpa, wmass
END IF
545 FORMAT(//,3X,'Cell Dynamics Parameters (from STDIN)',/ &
,3X,'-------------------------------------')
546 FORMAT( 3X,'Simulation cell read from STDIN')
547 FORMAT( 3X,'Starting cell generated from CELLDM')
548 FORMAT( 3X,'Cell parameters will be re-read from restart file')
525 FORMAT( 3X,'Constant VOLUME Molecular dynamics')
606 format( 3X,'cell parameters are not allowed to move')
526 FORMAT( 3X,'Volume dynamics with steepest descent')
527 FORMAT( 3X,'Volume dynamics with newton equations')
530 FORMAT( 3X,'Constant PRESSURE Molecular dynamics:',/ &
,3X,'External pressure (GPa) = ',F11.2,/ &
,3X,'Volume mass = ',F11.2)
563 FORMAT( 3X,'Zero initial momentum for cell variables')
565 FORMAT( 3X,'Volume dynamics: the temperature is not controlled')
604 format( 3X,'cell parameters dynamics with nose` temp. control' )
600 format( 3X, 'internal stress tensor calculated')
602 format( 3X, 'cell parameters dynamics with frich = ',f7.4, &
& 3X, 'and greash = ',f7.4 )
return
end subroutine cell_print_info
!----------------------------------------------
SUBROUTINE gmeshinfo( )
!----------------------------------------------
!
! Print out the number of g vectors for the different mesh
!
USE kinds, ONLY: DP
USE mp_global, ONLY: nproc_bgrp, intra_bgrp_comm
USE io_global, ONLY: ionode, ionode_id, stdout
USE mp, ONLY: mp_max, mp_gather
use smallbox_gvec, only: ngb
USE gvecw, only: ngw_g, ngw, ngwx
USE gvecs, only: ngms_g, ngms, ngsx
USE gvect, only: ngm, ngm_g, ngmx
IMPLICIT NONE
INTEGER :: ip, ng_snd(3), ng_rcv( 3, nproc_bgrp )
INTEGER :: ierr, min_val, max_val, i
REAL(DP) :: avg_val
IF(ionode) THEN
WRITE( stdout,*)
WRITE( stdout,*) ' Reciprocal Space Mesh'
WRITE( stdout,*) ' ---------------------'
END IF
ng_snd(1) = ngm_g
ng_snd(2) = ngm
ng_snd(3) = ngmx
CALL mp_gather(ng_snd, ng_rcv, ionode_id, intra_bgrp_comm)
!
IF(ionode) THEN
min_val = MINVAL( ng_rcv(2,:) )
max_val = MAXVAL( ng_rcv(2,:) )
avg_val = REAL(SUM( ng_rcv(2,:) ))/nproc_bgrp
WRITE( stdout,1000)
WRITE( stdout,1011) ng_snd(1), min_val, max_val, avg_val
END IF
!
ng_snd(1) = ngms_g
ng_snd(2) = ngms
ng_snd(3) = ngsx
CALL mp_gather(ng_snd, ng_rcv, ionode_id, intra_bgrp_comm)
!
ierr = 0
!
IF(ionode) THEN
WRITE( stdout,1001)
min_val = MINVAL( ng_rcv(2,:) )
max_val = MAXVAL( ng_rcv(2,:) )
avg_val = REAL(SUM( ng_rcv(2,:) ))/nproc_bgrp
WRITE( stdout,1011) ng_snd(1), min_val, max_val, avg_val
IF( min_val < 1 ) ierr = ip
END IF
!
CALL mp_max( ierr, intra_bgrp_comm )
!
IF( ierr > 0 ) &
CALL errore( " gmeshinfo ", " Wow! some processors have no G-vectors ", ierr )
!
ng_snd(1) = ngw_g
ng_snd(2) = ngw
ng_snd(3) = ngwx
CALL mp_gather(ng_snd, ng_rcv, ionode_id, intra_bgrp_comm)
!
IF(ionode) THEN
WRITE( stdout,1002)
min_val = MINVAL( ng_rcv(2,:) )
max_val = MAXVAL( ng_rcv(2,:) )
avg_val = REAL(SUM( ng_rcv(2,:) ))/nproc_bgrp
WRITE( stdout,1011) ng_snd(1), min_val, max_val, avg_val
IF( min_val < 1 ) ierr = ip
END IF
!
CALL mp_max( ierr, intra_bgrp_comm )
!
IF( ierr > 0 ) &
CALL errore( " gmeshinfo ", " Wow! some processors have no G-vectors ", ierr )
!
IF(ionode .AND. ngb > 0 ) THEN
WRITE( stdout,1050)
WRITE( stdout,1060) ngb
END IF
1000 FORMAT(3X,'Large Mesh',/, &
' Global(ngm_g) MinLocal MaxLocal Average')
1001 FORMAT(3X,'Smooth Mesh',/, &
' Global(ngms_g) MinLocal MaxLocal Average')
1002 FORMAT(3X,'Wave function Mesh',/, &
' Global(ngw_g) MinLocal MaxLocal Average')
1011 FORMAT( 3I15, F15.2 )
1050 FORMAT(/,3X,'Small box Mesh')
1060 FORMAT( 3X, 'ngb = ', I12, ' not distributed to processors' )
RETURN
END SUBROUTINE gmeshinfo
!----------------------------------------------
SUBROUTINE constraint_info()
!----------------------------------------------
USE kinds, ONLY: DP
USE constraints_module, ONLY: nconstr, constr_tol, &
constr_type, constr, constr_target
USE io_global, ONLY: ionode, stdout
USE control_flags, ONLY: lconstrain
!
IMPLICIT NONE
!
INTEGER :: ic
!
IF( lconstrain .AND. ionode ) THEN
!
WRITE( stdout, 10 )
WRITE( stdout, 20 ) nconstr, constr_tol
!
DO ic = 1, nconstr
!
IF( constr_type( ic ) == 3 ) THEN
!
! distance
!
WRITE( stdout, 30 ) ic
WRITE( stdout, 40 ) NINT( constr(1,ic) ), &
NINT( constr(2,ic) ), constr_target(ic)
!
END IF
!
END DO
!
END IF
!
10 FORMAT( 3X, "Using constrained dynamics")
20 FORMAT( 3X, "number of constrain and tolerance: ", I5, D10.2)
30 FORMAT( 3X, "constrain ", I5, " type distance ")
40 FORMAT( 3X, " atoms ", I5, I5, " target dist ", F10.5)
!
END SUBROUTINE constraint_info
SUBROUTINE new_atomind_constraints()
!
USE kinds, ONLY: DP
USE constraints_module, ONLY: constr
USE ions_base, ONLY: ind_bck
!
IMPLICIT NONE
!
INTEGER :: ic, ia
INTEGER :: iaa
REAL(DP) :: aa
!
! Substitute the atom index given in the input file
! with the new atom index, after the sort in the
! atomic coordinates.
!
DO ic = 1, SIZE( constr, 2 )
DO ia = 1, SIZE( constr, 1 )
IF( constr( ia, ic ) > 0.0d0 ) THEN
iaa = NINT( constr( ia, ic ) )
aa = DBLE( ind_bck( iaa ) )
constr( ia, ic ) = aa
END IF
END DO
END DO
!
RETURN
!
END SUBROUTINE new_atomind_constraints
SUBROUTINE compute_stress_x( stress, detot, h, omega )
USE kinds, ONLY : DP
IMPLICIT NONE
REAL(DP), INTENT(OUT) :: stress(3,3)
REAL(DP), INTENT(IN) :: detot(3,3), h(3,3), omega
integer :: i, j
do i=1,3
do j=1,3
stress(i,j)=-1.d0/omega*(detot(i,1)*h(j,1)+ &
& detot(i,2)*h(j,2)+detot(i,3)*h(j,3))
enddo
enddo
return
END SUBROUTINE compute_stress_x
!-----------------------------------------------------------------------
subroutine formf( tfirst, eself )
!-----------------------------------------------------------------------
!computes (a) the self-energy eself of the ionic pseudocharges;
! (b) the form factors of: (i) pseudopotential (vps),
! (ii) ionic pseudocharge (rhops)
! also calculated the derivative of vps with respect to
! g^2 (dvps)
!
USE kinds, ONLY : DP
use mp, ONLY : mp_sum
use control_flags, ONLY : iprint, tpre, iverbosity
use io_global, ONLY : stdout
use mp_global, ONLY : intra_bgrp_comm
use gvecs, ONLY : ngms
use cell_base, ONLY : omega, tpiba2, tpiba
use ions_base, ONLY : rcmax, zv, nsp, na
use local_pseudo, ONLY : vps, vps0, rhops, dvps, drhops
use atom, ONLY : rgrid
use uspp_param, ONLY : upf, oldvan
use pseudo_base, ONLY : compute_rhops, formfn, formfa, compute_eself
use pseudopotential, ONLY : tpstab, vps_sp, dvps_sp
use splines, ONLY : spline
use gvect, ONLY : gstart, gg
use constants, ONLY : autoev
!
implicit none
logical :: tfirst
real(DP) :: eself, DeltaV0
!
real(DP) :: vpsum, rhopsum
integer :: is, ig
REAL(DP) :: cost1, xg
call start_clock( 'formf' )
!
IF( .NOT. ALLOCATED( rgrid ) ) &
CALL errore( ' formf ', ' rgrid not allocated ', 1 )
IF( .NOT. ALLOCATED( upf ) ) &
CALL errore( ' formf ', ' upf not allocated ', 1 )
!
! calculation of gaussian selfinteraction
!
eself = compute_eself( na, zv, rcmax, nsp )
if( tfirst .or. ( iverbosity > 2 ) )then
WRITE( stdout, 1200 ) eself
endif
!
1200 format(/,3x,'formf: eself=',f12.5)
!
do is = 1, nsp
IF( tpstab ) THEN
!
! Use interpolation table, with cubic spline
!
cost1 = 1.0d0/omega
!
IF( gstart == 2 ) THEN
vps (1,is) = vps_sp(is)%y(1) * cost1
dvps(1,is) = dvps_sp(is)%y(1) * cost1
END IF
!
DO ig = gstart, ngms
xg = SQRT( gg(ig) ) * tpiba
vps (ig,is) = spline( vps_sp(is), xg ) * cost1
dvps(ig,is) = spline( dvps_sp(is), xg ) * cost1
END DO
!
ELSE
call formfn( rgrid(is)%r, rgrid(is)%rab, &
upf(is)%vloc(1:rgrid(is)%mesh), zv(is), rcmax(is), gg, &
omega, tpiba2, rgrid(is)%mesh, ngms, oldvan(is), tpre, &
vps(:,is), vps0(is), dvps(:,is) )
! obsolete BHS form
! call formfa( vps(:,is), dvps(:,is), rc1(is), rc2(is), wrc1(is), wrc2(is), &
! rcl(:,is,lloc(is)), al(:,is,lloc(is)), bl(:,is,lloc(is)), &
! zv(is), rcmax(is), g, omega, tpiba2, ngms, gstart, tpre )
END IF
!
! fourier transform of local pp and gaussian nuclear charge
!
call compute_rhops( rhops(:,is), drhops(:,is), zv(is), rcmax(is), gg, &
omega, tpiba2, ngms, tpre )
if( tfirst .or. ( iverbosity > 2 ) )then
vpsum = SUM( vps( 1:ngms, is ) )
rhopsum = SUM( rhops( 1:ngms, is ) )
call mp_sum( vpsum, intra_bgrp_comm )
call mp_sum( rhopsum, intra_bgrp_comm )
WRITE( stdout,1250) vps(1,is),rhops(1,is)
WRITE( stdout,1300) vpsum,rhopsum
endif
!
end do
!
! ... DeltaV0 is the shift to be applied to eigenvalues
! ... in order to align them to other plane wave codes
!
DeltaV0 = 0.0_dp
DO is = 1, nsp
!
! ... na(is)/omega is the structure factor at G=0
!
DeltaV0 = DeltaV0 + na(is) / omega * vps0(is)
END DO
!
IF ( tfirst .or. ( iverbosity > 2 ) ) THEN
write(6,'(" Delta V(G=0): ",f10.6,"Ry, ",f11.6,"eV")') &
deltaV0, deltaV0*autoev
END IF
!
call stop_clock( 'formf' )
!
1250 format(3x,'formf: vps(g=0)=',f12.7,' rhops(g=0)=',f12.7)
1300 format(3x,'formf: sum_g vps(g)=',f12.7,' sum_g rhops(g)=',f12.7)
!
return
end subroutine formf
!
!-----------------------------------------------------------------------
SUBROUTINE newnlinit()
!-----------------------------------------------------------------------
!
! ... this routine calculates arrays beta, qq, qgb, rhocb
! ... and derivatives w.r.t. cell parameters dbeta
! ... See also comments in nlinit
!
use control_flags, ONLY : tpre
use pseudopotential, ONLY : tpstab
use cp_interfaces, ONLY : interpolate_beta, interpolate_qradb, compute_qradx, compute_betagx, &
exact_beta, check_tables, exact_qradb, build_pstab, build_cctab
use betax, only : mmx, refg
use kinds, only : dp
use io_global, only : ionode, stdout
!
IMPLICIT NONE
!
LOGICAL :: recompute_table
REAL(DP) :: gmax
!
! ... initialization for vanderbilt species
!
CALL start_clock( 'newnlinit' )
IF( tpstab ) THEN
recompute_table = tpre .AND. check_tables( gmax )
!
IF ( recompute_table ) THEN
IF( ionode ) &
WRITE( stdout, * ) "newnliinit: recomputing the pseudopotentials tables"
!"!
CALL set_interpolation_table_size( mmx, refg, gmax )
CALL compute_qradx( tpre )
call compute_betagx( tpre )
call build_pstab()
!
call build_cctab()
END IF
!
! initialization that is common to all species
!
CALL interpolate_beta( tpre )
!
CALL interpolate_qradb( tpre )
!
ELSE
!
! ... this is mainly for testing
!
CALL exact_beta( tpre )
!
CALL exact_qradb( tpre )
!
END IF
!
! ... non-linear core-correction ( rhocb(ig,is) )
!
CALL core_charge_ftr( tpre )
CALL stop_clock( 'newnlinit' )
!
RETURN
!
END SUBROUTINE newnlinit
!
!-----------------------------------------------------------------------
subroutine nlfh_x( stress, bec_bgrp, dbec, lambda, descla )
!-----------------------------------------------------------------------
!
! contribution to the internal stress tensor due to the constraints
!
USE kinds, ONLY : DP
use uspp, ONLY : nkb, qq
use uspp_param, ONLY : nh, nhm, nvb, ish
use ions_base, ONLY : na
use electrons_base, ONLY : nbspx, nbsp, nudx, nspin, nupdwn, iupdwn, ibgrp_g2l
use cell_base, ONLY : omega, h
use constants, ONLY : pi, fpi, au_gpa
use io_global, ONLY : stdout
use control_flags, ONLY : iverbosity
USE descriptors, ONLY : la_descriptor
USE mp, ONLY : mp_sum
USE mp_global, ONLY : intra_bgrp_comm, inter_bgrp_comm
!
implicit none
TYPE(la_descriptor), INTENT(IN) :: descla(:)
REAL(DP), INTENT(INOUT) :: stress(3,3)
REAL(DP), INTENT(IN) :: bec_bgrp( :, : ), dbec( :, :, :, : )
REAL(DP), INTENT(IN) :: lambda( :, :, : )
!
INTEGER :: i, j, ii, jj, inl, iv, jv, ia, is, iss, nss, istart
INTEGER :: jnl, ir, ic, nr, nc, ibgrp_i, nrcx
REAL(DP) :: fpre(3,3), TT, T1, T2
!
REAL(DP), ALLOCATABLE :: tmpbec(:,:), tmpdh(:,:), temp(:,:), bec(:,:,:)
!
nrcx = MAXVAL( descla( : )%nrcx )
!
ALLOCATE( bec( nkb, nrcx, nspin ) )
!
DO iss = 1, nspin
IF( descla( iss )%active_node > 0 ) THEN
nss = nupdwn( iss )
istart = iupdwn( iss )
ic = descla( iss )%ic
nc = descla( iss )%nc
DO i=1,nc
ibgrp_i = ibgrp_g2l( i+istart-1+ic-1 )
IF( ibgrp_i > 0 ) THEN
bec( :, i, iss ) = bec_bgrp( :, ibgrp_i )
ELSE
bec( :, i, iss ) = 0.0d0
END IF
END DO
ELSE
bec(:,:,iss) = 0.0d0
END IF
END DO
CALL mp_sum( bec, inter_bgrp_comm )
!
IF (nspin == 1) THEN
IF( ( descla( 1 )%active_node > 0 ) ) THEN
ALLOCATE ( tmpbec(nhm,nrcx), tmpdh(nrcx,nhm), temp(nrcx,nrcx) )
ENDIF
ELSEIF (nspin == 2) THEN
IF( ( descla( 1 )%active_node > 0 ) .OR. ( descla( 2 )%active_node > 0 ) ) THEN
ALLOCATE ( tmpbec(nhm,nrcx), tmpdh(nrcx,nhm), temp(nrcx,nrcx) )
END IF
ENDIF
!
fpre = 0.d0
!
do ii=1,3
do jj=1,3
do is=1,nvb
do ia=1,na(is)
do iss = 1, nspin
!
istart = iupdwn( iss )
nss = nupdwn( iss )
!
IF( descla( iss )%active_node > 0 ) THEN
nr = descla( iss )%nr
nc = descla( iss )%nc
ir = descla( iss )%ir
ic = descla( iss )%ic
tmpbec = 0.d0
tmpdh = 0.d0
!
do iv=1,nh(is)
do jv=1,nh(is)
inl=ish(is)+(jv-1)*na(is)+ia
if(abs(qq(iv,jv,is)).gt.1.e-5) then
do i = 1, nc
tmpbec(iv,i) = tmpbec(iv,i) + qq(iv,jv,is) * bec( inl, i, iss )
end do
endif
end do
end do
do iv=1,nh(is)
inl=ish(is)+(iv-1)*na(is)+ia
do i = 1, nr
tmpdh(i,iv) = dbec( inl, i + (iss-1)*nrcx, ii, jj )
end do
end do
if(nh(is).gt.0)then
CALL dgemm &