-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathinitial_read_module.f90
More file actions
3769 lines (3622 loc) · 161 KB
/
initial_read_module.f90
File metadata and controls
3769 lines (3622 loc) · 161 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
! ------------------------------------------------------------------------------
! $Id$
! ------------------------------------------------------------------------------
! Module initial_read
! ------------------------------------------------------------------------------
! Code area 1: initialisation
! ------------------------------------------------------------------------------
!!****h* Conquest/initial_read *
!! NAME
!! initial_read
!! PURPOSE
!! Holds the initial read routines
!! USES
!! atoms, construct_module, datatypes, DiagModule, dimens, fdf, GenComms, global_module,
!! group_module, io_module, maxima_module, numbers, parse, primary_module,
!! pseudopotential_data, species_module
!! AUTHOR
!! D.R.Bowler
!! CREATION DATE
!! 10/05/2002
!! MODIFICATION HISTORY
!! 31/05/2002 dave
!! Bug fix (from TM) for read_and_write
!! 17/06/2002 dave
!! Added read to find solution method - order N or exact diagonalisation
!! 15:55, 25/09/2002 mjg & drb
!! Added flag for initial charge from initial K
!! 10:41, 06/03/2003 drb
!! Added tags for linear mixing for self-consistency in read_input
!! 11:02, 24/03/2003 drb
!! Simplified read_and_write
!! 14:51, 2003/06/09 dave
!! Added new way of reading atomic coordinates, independent of make_prt
!! 2006/11/01 17:01 dave
!! Included MP k-mesh generation from VB
!! 11:40, 10/11/2006 Veronika
!! Added option for reading pdb files
!! 2008/02/01 03:43 dave
!! Changes to give output to file not stdout
!! 2008/05/23 ast
!! Added timers
!! 2010/07/23 Lianheng
!! Added flags for Methfessel-Paxton smearing and associated Ef search method
!! 2011/07/21 16:50 dave
!! Changes for cDFT
!! 2014/09/15 18:30 lat
!! fixed call start/stop_timer to timer_module (not timer_stdlocks_module !)
!! 2014/09/15 18:30 lat
!! fixed call start/stop_timer to timer_module (not timer_stdlocks_module !)
!! 2015/06/10 15:44 cor & dave
!! Input parameters for band output
!! 2015/06/11 16:30 lat
!! Added possibility of user to define filename for PAO/pseudo *ion
!! Fixed EXX variable definitions
!! Try to make blocks of variables clearer
!! Added experimental backtrace
!!
!! SOURCE
!!
module initial_read
use timer_module, only: start_timer, stop_timer, cq_timer
use timer_module, only: start_backtrace, stop_backtrace
use timer_stdclocks_module, only: tmr_std_allocation
implicit none
! Index number for loading DM etc
integer, save :: index_MatrixFile
!!***
contains
! ------------------------------------------------------------------------------
! Subroutine read_and_write
! ------------------------------------------------------------------------------
!!****f* initial_read/read_and_write *
!!
!! NAME
!! read_and_write
!! USAGE
!!
!! PURPOSE
!! Reads the input data and writes out the parameters for the run
!! INPUTS
!! Many and varied - mainly things to be read in
!! USES
!! datatypes, numbers, io_module, group_module, construct_module,
!! maxima_module, global_module, primary_module, atoms, dimens,
!! species_module, GenComms, pseudopotential_data
!! AUTHOR
!! D.R.Bowler
!! CREATION DATE
!! Late 1998, I think
!! MODIFICATION HISTORY
!! 28/05/2001 dave
!! Added ROBODoc header, indented, stripped subroutine calls and
!! overall argument list
!! 08/06/2001 dave
!! Added RCS Id and Log tags and GenComms for my_barrier and cq_abort
!! 13/06/2001 dave
!! Changed call to set_dimensions and to use pseudopotential_data
!! 10/05/2002 dave
!! Incorporated into initial_read module
!! 31/05/2002 dave
!! Bug fix (TM) - changed np to ind_part in loop to build atom
!! positions from make_prt.dat
!! 11:02, 24/03/2003 drb
!! Removed variables associated with old phi initialisation
!! 14:52, 2003/06/09 dave
!! Removed atomic coordinate fiddling
!! 14:59, 02/05/2005 dave
!! Added calculation of number of electrons in cell
!! 2007/05/08 17:00 dave
!! Added net charge on cell to number_of_bands for consistency
!! 2011/09/19 L.Tong
!! Added calculation of ne_up_in_cell and ne_dn_in_cell for spin
!! polarised calculations
!! 2011/09/29 15:06 M. Arita
!! Slight modification is added for DFT-D2
!! 2011/12/11 L.Tong
!! Removed number_of_bands, it is obsolete, and use ne_in_cell
!! instead
!! 2012/03/27 L.Tong
!! - Changed spin implementation
!! 2014/02/04 M.Arita
!! - Added call for initial_read_aux for constraint-MD
!! 2015/05/11 lat
!! - Added optional total spin magnetization
!! 2015/06/08 lat
!! - Added experimental backtrace
!! 2015/06/10 15:44 cor & dave
!! - Input parameters for band output
!! 2016/09/15 17:00 nakata
!! Added automatic setting of flag_one_to_one, atomf and nspin_SF
!! 2017/02/23 dave
!! - Changing location of diagon flag from DiagModule to global and name to flag_diagonalisation
!! 2017/03/09 17:30 nakata
!! Changed to check consistence between flag_one_to_one and flag_Multisite
!! 2017/07/11 16:36 dave
!! Bug fix (GitHub issue #36) to turn off basis optimisation if NSF=NPAO
!! 2018/05/11 10:26 dave
!! Bug fix (GitHub issue #80) to set flag_SFcoeffReuse false if NSF=NPAO
!! 2018/07/13 09:37 dave
!! Added test for missing coordinate file name
!! 2018/09/06 16:45 nakata
!! Changed to allow to use MSSFs larger than single-zeta size (i.e., not minimal)
!! 2019/06/06 17:30 jack poulton and nakata
!! Changed to allow SZP-MSSFs with flag_MSSF_nonminimal when checking the number of MSSFs
!! Added MSSF_nonminimal_species
!! 2019/07/04 zamaan
!! Added bibliography
!! 2019/11/18 tsuyoshi
!! Removed flag_MDold
!! 2020/12/28 18:34 Lionel
!! Added EXX poisson solver and scheme for G=0`
!! 2021/01/14 16:50 Lionel
!! EXX: added gto_file setup and read GTO info
!! SOURCE
!!
subroutine read_and_write(start, start_L, inode, ionode, &
vary_mu, mu, find_chdens)
use datatypes
use numbers
use io_module, only: read_mult, &
read_atomic_positions, &
pdb_template, pdb_format, &
print_process_info, titles
use group_module, only: parts, part_method
use construct_module, only: init_group, init_primary
use maxima_module, only: maxpartsproc, maxatomsproc
use global_module, only: id_glob,x_atom_cell,y_atom_cell, &
z_atom_cell, numprocs, &
iprint_init, nspin, &
flag_fix_spin_population, &
ne_in_cell, ne_spin_in_cell, &
ne_magn_in_cell, &
ni_in_cell, area_moveatoms, &
io_lun, flag_only_dispersion, &
flag_basis_set, blips, PAOs, &
atomf, sf, paof, &
flag_SpinDependentSF, nspin_SF, &
flag_Multisite, &
flag_cdft_atom, flag_local_excitation, &
flag_diagonalisation, flag_vary_basis, &
flag_MDcontinue, flag_SFcoeffReuse, &
flag_exx
use exx_types, only: exx_gto, exx_gto_poisson
!use read_gto_info, only: read_gto
use read_gto_info, only: read_gto_new
!use gto_format, only: gto
use gto_format_new, only: gto
use cdft_data, only: cDFT_NAtoms, &
cDFT_NumberAtomGroups, cDFT_AtomList
use memory_module, only: reg_alloc_mem, type_dbl
use primary_module, only: bundle, make_prim
use dimens, only: set_dimensions, find_grid
use species_module, only: n_species, species, charge, &
non_local_species, &
nsf_species, npao_species, &
natomf_species, charge_up, charge_dn, &
gto_file
use density_module, only: flag_InitialAtomicSpin
use GenComms, only: my_barrier, cq_abort, cq_warn
use pseudopotential_data, only: non_local, read_pseudopotential
use pseudopotential_common, only: core_radius, pseudo_type, OLDPS, &
SIESTA, ABINIT
use pseudo_tm_module, only: init_pseudo_tm
use pseudo_tm_info, only: pseudo
use input_module, only: fdf_string, fdf_out, io_close, leqi
use force_module, only: tot_force
use constraint_module, only: flag_RigidBonds,constraints
use support_spec_format, only: flag_one_to_one, symmetry_breaking, read_option
use multisiteSF_module, only: flag_LFD_ReadTVEC, &
flag_MSSF_nonminimal, & !nonmin_mssf
MSSF_nonminimal_species !nonmin_mssf
use md_control, only: md_position_file
use pao_format
use XC, only: flag_functional_type, flag_different_functional
implicit none
! Passed variables
logical :: vary_mu, start, start_L
logical :: find_chdens
integer :: inode, ionode
real(double) :: mu
! Local variables
character(len=80) :: sub_name = "read_and_write"
type(cq_timer) :: backtrace_timer
character(len=80) :: def
character(len=80) :: atom_coord_file
character(len=80) :: part_coord_file
integer :: i, j, acz, prncpl, prncpl0
integer :: ncf_tmp, stat, i_species
integer :: count_SZ, count_SZP
real(double) :: ecore_tmp
real(double) :: HNL_fac
real(double), dimension(8) :: occ_n
! for checking the sum of electrons of spin channels
real(double) :: sum_elecN_spin
real(double) :: charge_tmp
!****lat<$
call start_backtrace(t=backtrace_timer,who='read_and_write',where=1,level=1)
!****lat>$
! read input data: parameters for run
call read_input(start, start_L, titles, vary_mu, mu,&
find_chdens, HNL_fac)
! Read pseudopotential data
if(pseudo_type == OLDPS) then
call read_pseudopotential(inode, ionode)
elseif(pseudo_type == SIESTA.OR.pseudo_type==ABINIT) then
!just for setting core_radius in pseudopotential_common
! allocation and deallocation will be performed.
call init_pseudo_tm(ecore_tmp, ncf_tmp)
else
call cq_abort(' Pseudotype Error ', pseudo_type)
endif
! Functional consistency check
if(flag_functional_type==0) then ! Not set, so take from pseudopotentials
flag_functional_type = pseudo(1)%functional
if(inode==ionode) then ! Check and warn
do i_species = 2, n_species
if(flag_functional_type/=pseudo(i_species)%functional) &
call cq_abort("Functionals differ between pseudopotential files: ",&
flag_functional_type, pseudo(i_species)%functional)
end do
end if
else if(inode==ionode) then ! Check and warn
do i_species = 1, n_species
if(flag_functional_type/=pseudo(i_species)%functional) then
if(flag_different_functional) then
call cq_warn(sub_name, "Functional in input file differs to pseudopotential but proceeding: ",&
flag_functional_type, pseudo(i_species)%functional)
else
call cq_abort("Functional in input file differs to pseudopotential: ",&
flag_functional_type, pseudo(i_species)%functional)
end if
end if
end do
end if
!if(iprint_init>4) write(io_lun,fmt='(10x,"Proc: ",i4," done pseudo")') inode
!
call my_barrier()
!
! If EXX with GTO open and read species' GTO files
if ( flag_exx .and. (exx_gto .or. exx_gto_poisson) ) then
!
allocate(gto_file(n_species),STAT=stat)
if(stat /= 0) call cq_abort("Error allocating gto_file in read_and_write: ",n_species,stat)
allocate(gto(n_species),STAT=stat)
if(stat /= 0) call cq_abort ("Error allocating gto in read_and_write",stat)
!
call read_gto_new(inode,ionode,n_species)
!call read_gto(inode,ionode,n_species)
!
end if
!
! Initialise group data for partitions and read in partitions and atoms
call my_barrier()
!
def = ' '
atom_coord_file = fdf_string(80,'IO.Coordinates',def)
if(leqi(def,atom_coord_file)) call cq_abort("No coordinate file specified: please set with IO.Coordinates")
if ( pdb_format ) then
pdb_template = fdf_string(80,'IO.PdbTemplate',atom_coord_file)
else
pdb_template = fdf_string(80,'IO.PdbTemplate',' ')
end if
def = 'make_prt.dat'
part_coord_file = fdf_string(80,'IO.Partitions',def)
if (.not. flag_MDcontinue) then
call read_atomic_positions(trim(atom_coord_file))
else
call read_atomic_positions(md_position_file)
end if
if(iprint_init>4) call print_process_info()
! By now, we'll have unit cell sizes and grid cutoff
call find_grid
if(flag_diagonalisation) call readDiagInfo
if (flag_RigidBonds) call read_input_aux(constraints)
! Now that input from Conquest_input is done, we will close the file
call io_close(fdf_out)
if(inode==ionode.AND.iprint_init>1) &
write(io_lun,fmt='(10x,"Partitioning method: ",i2)') part_method
call read_mult(inode-1,parts,part_coord_file)
!if(iprint_init>4) &
! write(io_lun,fmt='(10x,"Proc: ",i4," done read_mult: ",2i5)') &
! inode,maxatomsproc,maxpartsproc
if(allocated(tot_force)) then
write (io_lun,fmt='(10x,"WARNING! Proc: ",i4," tot_force &
&already allocated: ",i7)') &
size(tot_force)
deallocate(tot_force)
end if
allocate(tot_force(3,ni_in_cell))
call reg_alloc_mem(area_moveatoms,3*ni_in_cell,type_dbl)
if(flag_local_excitation) then
allocate(flag_cdft_atom(ni_in_cell), STAT=stat)
flag_cdft_atom = 0
!if(cDFT_NumberAtomGroups==1) flag_cdft_atom = 2
do i=1,cDFT_NumberAtomGroups
do j = 1, cDFT_NAtoms(i)
flag_cdft_atom(cDFT_AtomList(i)%Numbers(j)) = i
end do
end do
end if
call my_barrier
! Create primary set for atoms: bundle of partitions
call init_primary(bundle, maxatomsproc, maxpartsproc, .true.)
call make_prim(parts, bundle, inode-1, id_glob, x_atom_cell, &
y_atom_cell, z_atom_cell, species)
! Skip the following statement if only calculating the dispersion
if (flag_only_dispersion) return
!
!
!
! Set flag_one_to_one and check the number of SFs
if (nspin.eq.1) then
nspin_SF = 1
flag_SpinDependentSF = .false.
endif
if (flag_basis_set==blips) then
flag_one_to_one = .false.
atomf = sf
nspin_SF = 1
flag_SpinDependentSF = .false.
else if (flag_basis_set==PAOs) then
flag_one_to_one = .true. ! primitive SFs
atomf = sf
nspin_SF = 1
! Check PAOs are contracted or not
do i = 1, n_species
if (nsf_species(i).ne.npao_species(i)) flag_one_to_one = .false.
enddo
if (flag_one_to_one .and. read_option) then
call cq_warn(sub_name, "Cannot set 1:1 flag, read coefficients and have NSF==NPAO; setting 1:1 false")
flag_one_to_one = .false.
endif
if (flag_one_to_one .and. flag_Multisite) then
call cq_abort("flag_Multisite is .true., but the number of SFs is the same as the number of PAOs.")
endif
if (flag_one_to_one) then
flag_SpinDependentSF = .false. ! spin-dependent SFs will be available only for contracted SFs
flag_SFcoeffReuse = .false.
else
atomf = paof
end if
if (flag_SpinDependentSF) then
nspin_SF = nspin
if (inode==ionode) write(io_lun,'(2X,A,I1)') 'Support functions are spin-dependent, nspin_SF = ',nspin_SF
endif
if (flag_one_to_one.AND.flag_vary_basis) then
call cq_warn(sub_name, "minE.VaryBasis T is not compatible with NSF==NPAO. Setting flag to F.")
flag_vary_basis = .false.
end if
! Check symmetry-breaking for contracted SFs
if (.not.flag_one_to_one) then
do i = 1, n_species
count_SZ = 0
count_SZP = 0
do j = 0, pao(i)%greatest_angmom
if(pao(i)%angmom(j)%n_zeta_in_angmom>0) then
count_SZP = count_SZP + (2*j+1) ! Accumulate no. of ang. mom. components
occ_n(:) = zero
do acz = 1, pao(i)%angmom(j)%n_zeta_in_angmom
prncpl = pao(i)%angmom(j)%prncpl(acz)
if (acz.ne.1 .and. prncpl.ne.prncpl0) count_SZP = count_SZP + (2*j+1)
occ_n(prncpl) = occ_n(prncpl) + pao(i)%angmom(j)%occ(acz)
prncpl0 = prncpl
enddo
do prncpl = 1, 8
if (occ_n(prncpl).gt.zero) count_SZ = count_SZ + (2*j+1)
enddo
endif
enddo
if (flag_Multisite) then
! multi-site SFs (MSSFs) are symmetry-breaking usually.
! The default of the number of the MSSFs is SingleZeta-size.
! SZP-size MSSFs with flag_MSSF_nonminimal is also available.
! If the user wants to use the other number of MSSFs,
! the user must provide the initial SFcoeffmatrix or the trial vectors for the LFD method.
if (nsf_species(i).eq.count_SZ) then
MSSF_nonminimal_species(i) = 1 ! SZ-size MSSF
else
if (.not.flag_MSSF_nonminimal) then
if(inode==ionode) write(io_lun,'(A/A,I3,A,I3/2A)') &
"You have a major problem with your multi-site support functions.",&
"Number of multi-site SFs", nsf_species(i), &
" is not equal to single-zeta (SZ) size", count_SZ, &
"You need to set Multisite.nonminimal to be .true. or ",&
"set Atom.NumberOfSupports to be SZ size."
call cq_abort("Multi-site support function error for species ",i)
else if (nsf_species(i).eq.count_SZP) then
MSSF_nonminimal_species(i) = 2 ! SZP-size MSSF
else if (nsf_species(i).ne.count_SZP) then
MSSF_nonminimal_species(i) = 3 ! other size
if (.not.flag_LFD_ReadTVEC .and. .not.read_option) then
if (inode==ionode) write(io_lun,'(A/A,I3,A,I3,A,I3/A/A/A/A)') &
"You have a major problem with your multi-site support functions.",&
"Number of multi-site SFs", nsf_species(i), &
" is not equal to single-zeta (SZ) size", count_SZ, &
" nor single-zeta plus polarisation (SZP) size", count_SZP, &
"Since the automatic setting of the trial vectors in the local filter diagonalisation method is ",&
"avaialble only for SZ or SZP size,",&
"you need to provide initial SFcoeffmatrix or trial vectors for the LFD method, ",&
"or change Atom.NumberOfSupports to be SZ or SZP size."
call cq_abort("Multi-site support function error for species ",i)
endif
endif
endif
else
! If number of support functions is less than total number of ang. mom. components (ignoring
! for now multiple zetas) then there is a formal problem with basis set: we require the user
! to set an additional flag to assert that this is really desired
if(count_SZP>nsf_species(i)) then
if(.NOT.symmetry_breaking.OR..NOT.read_option) then
if(inode==ionode) then
write(io_lun,fmt='("You have a major problem with your basis set.")')
write(io_lun,fmt='("There are fewer support functions than the minimal angular momentum")')
write(io_lun,fmt='("components. Either increase number of support functions on species ",i4)') i
write(io_lun,fmt='("to",i4," or set flag BasisSet.SymmetryBreaking to T")') count_SZP
write(io_lun,fmt='("You must also specify the basis set coefficients.")')
write(io_lun,fmt='("Use read_pao_coeffs T and support_pao_file <filename>.")')
end if
call cq_abort("Basis set error for species ",i)
else if(symmetry_breaking.AND.read_option) then
write(io_lun,fmt='("You have a major problem with your basis set.")')
write(io_lun,fmt='("There are ",i4," support functions and",i4," angular momentum")') &
nsf_species(i),count_SZP
write(io_lun,fmt='("components. But as BasisSet.SymmetryBreaking is set T we will continue.")')
end if
end if
end if
enddo ! n_species
endif ! flag_one_to_one
endif ! flag_basis_set
if (atomf==sf) natomf_species(:) = nsf_species(:)
if (atomf==paof) natomf_species(:) = npao_species(:)
if (iprint_init > 3 .and. inode==ionode) &
write(io_lun,fmt='(6x,a,L2)') 'PAO:SF mapping flag is ',flag_one_to_one
if (iprint_init> 3 .and. inode==ionode) then
if(atomf==sf) then
write(io_lun,fmt='(6x,"Primitive atom functions are the support functions"/)')
else if(atomf==paof) then
write(io_lun,fmt='(6x,"Primitive atom functions are the pseudo-atomic orbitals"/)')
endif
end if
!
!
!
! Make number of bands in an astonishingly crude way
! number_of_bands = half * ne_in_cell !zero
do i = 1, ni_in_cell
! number_of_bands = number_of_bands + half * charge(species(i))
ne_in_cell = ne_in_cell + charge(species(i))
end do
!
!
! Removed second condition otherwise variables not set 2022/10/31 08:36 dave
if (nspin == 2) then ! .and. ne_magn_in_cell > zero) then
! Yes but should consider preceding set up via Spin.NeUP/Spin.NeDN
if ( abs(ne_spin_in_cell(1))<RD_ERR .and. abs(ne_spin_in_cell(1))<RD_ERR) then
ne_spin_in_cell(1) = half * (ne_magn_in_cell + ne_in_cell)
ne_spin_in_cell(2) = ne_spin_in_cell(1) - ne_magn_in_cell
end if
!
end if
!
! Calculate the number of electrons in the spin channels
! if (flag_fix_spin_population) then
sum_elecN_spin = ne_spin_in_cell(1) + ne_spin_in_cell(2)
if (abs(sum_elecN_spin - ne_in_cell)>very_small) then
if (nspin == 2 .and. flag_fix_spin_population) then
call cq_abort('read_and_write: sum of number of electrons &
&in spin channels is different from total &
&number of electrons. ', &
sum_elecN_spin, ne_in_cell)
else
ne_spin_in_cell(:) = half * ne_in_cell
end if
end if
!
! IF (flag_InitialAtomicSpin) : atomic spin density will be set
!
if(flag_InitialAtomicSpin) then
do i = 1, n_species
charge_tmp = charge_up(i) + charge_dn(i)
if(charge_tmp < RD_ERR) then !
charge_up(i) = half*charge(i)
charge_dn(i) = half*charge(i)
!if(inode .eq. ionode) write(io_lun,fmt='(6x,a,i3,a,2f15.8)') &
! 'ispecies = ', i,' charge_up, dn = ',charge_up(i), charge_dn(i)
endif
enddo !i = 1, n_species
ne_spin_in_cell(:) = zero
do i = 1, ni_in_cell
! number_of_bands = number_of_bands + half * charge(species(i))
ne_spin_in_cell(1) = ne_spin_in_cell(1) + charge_up(species(i))
ne_spin_in_cell(2) = ne_spin_in_cell(2) + charge_dn(species(i))
end do
!if(inode .eq. ionode) write(io_lun,fmt='(6x,a,2f15.8)') 'ne_spin_in_cell(1:2) = ',ne_spin_in_cell(1),ne_spin_in_cell(2)
endif
!
!
! Set up various lengths, volumes, reciprocals etc. for convenient use
call set_dimensions(inode, ionode,HNL_fac, non_local, n_species, &
non_local_species, core_radius)
!
! write out some information on the run
if (inode == ionode) &
call write_info(titles, mu, vary_mu, HNL_fac, numprocs)
!****lat<$
call stop_backtrace(t=backtrace_timer,who='read_and_write')
!****lat>$
!**** TM 2020.Jul.30
call check_compatibility
call my_barrier()
return
end subroutine read_and_write
!!***
! ------------------------------------------------------------------------------
! Subroutine read_input
! ------------------------------------------------------------------------------
!!****f* initial_read/read_input *
!!
!! NAME
!! read_input
!! USAGE
!!
!! PURPOSE
!! reads the input file
!! INPUTS
!!
!!
!! USES
!! datatypes, global_module, atoms, dimens, species_module,
!! pseudopotential_data, GenComms, fdf, parse
!! AUTHOR
!! E.H.Hernandez
!! CREATION DATE
!! 08/05/95
!! MODIFICATION HISTORY
!! 29/10/97 by Dave Bowler to add chdens reading
!! 19/11/97 by Dave Bowler to add phi reading
!! 28/05/2001 dave
!! Stripped argument list, added ROBODoc header, indented
!! 08/06/2001 dave
!! Added RCS Id and Log tags and GenComms for my_barrier, cq_abort
!! 09/05/2002 drb
!! Converted to fdf formatting
!! 10/05/2002 dave
!! Incorporated into initial_read module
!! 29/05/2002 dave
!! Added scan for SolutionMethod tag
!! 15:54, 25/09/2002 mjg & drb
!! Added scan for make_initial_charge_from_K (which sets find_chdens)
!! 16:31, 2003/02/03 dave
!! Added scans for type of run (e.g. MD, CG etc)
!! 07:49, 2003/02/04 dave
!! Added boolean variables to control run (vary blips, self-consistency)
!! 10:41, 06/03/2003 drb
!! Added tags for linear mixing in self-consistency
!! 10:09, 12/03/2003 drb
!! Added an end tag
!! 14:52, 2003/06/09 dave
!! Added new way to read atomic coordinates and preconditioning flag
!! 08:31, 2003/10/01 dave
!! Changed flag_vary_blips to flag_vary_basis
!! 13:15, 03/10/2003 drb
!! Bug fix - missing .
!! 2004/10/29 drb
!! Added various new flags for self consistency
!! 14:59, 02/05/2005 dave
!! Added call to check for net charge - initialises ne_in_cell
!! 09:14, 11/05/2005 dave
!! Store max_L_iterations in global variable
!! 13:34, 2006/07/09 ast
!! Added flag for functional
!! 2007/04/02 07:53 dave
!! Changed defaults
!! 2007/05/18 15:18 dave
!! Added nullify for bp to stop g95 crash
!! 2007/10/15 Veronika
!! Added keyword MaxEfIter to stop infinite loop in findFermi
!! 2008/01/24 Veronika
!! Changed the default of General.ManyProcessors to .true.
!! 12:18, 14/02/2008 drb
!! Added options for buffer around primary and covering sets
!! 2008/07/16 ast
!! New keywords for timers
!! 2009/07/08 16:47 dave
!! Added keyword for one-to-one PAO to SF assigment
!! 2009/07/23 ast
!! More general routine to name timer files, so that they are not
!! to a maximum number of processes, as it was the case before,
!! with only three figures (max. 999 processes)
!! 2010/06/18 lt
!! Added control flags for Methfessel-Paxton smearing method
!! 2010/07/22 15.53 Lianheng
!! Moved control flags associated with Diagonalisation method from
!! here to readDiagInfo() subroutine. Added Methfessel-Paxton
!! smearing and related control flags. Changed SC.MaxEfIter to
!! Diag.MaxEfIter (moved to readDiagInfo()) for greater consistency
!! 2011/07/21 16:50 dave
!! Added input flags for cDFT
!! 2011/09/16 11:08 dave
!! Bug fix to say when species block not read
!! 2011/09/19 L.Tong
!! - Added flag_spin_polarisation and flag_fix_spin_population
!! - Added ne_up_in_cell and ne_dn_in_cell, for fixed spin pupulation
!! calculations.
!! - Added A_dn as mixing parameter for spin down component (and A is
!! for up) for spin polarised calculations. The default (if A_dn
!! is missing from input) is A_dn = A
!! - Added functional_lsda_pw92 for LSDA
!! 2011/11/17 10:36 dave
!! Changes for new blip data
!! 2011/12/12 17:27 dave
!! Added flag for analytic blip integrals
!! 2012/03/27 L.Tong
!! - Changed spin implementation
!! 2012/05/29 L.Tong
!! - Added Checks for functional types. Makes sure for spin non-
!! polarised calculations only the one that has spin implemented
!! can be used.
!! 2012/06/24 L.Tong
!! - Added input for flag_dump_L, which controls whether matL is
!! dumped or not
!! 2013/02/28 L.Tong
!! - Removed the cq_abort when user choses non-SC calculations
!! with spin polarised PBE functionals. Conquest now will
!! perform the calculations as usual, but will give warnings
!! about non-SC forces and set non-SC forces to zero, and carry
!! on. This allows the user to still perform non-SC single point
!! calculations with spin polarisation, if the forces are not
!! important.
!! 2013/02/08 15:44 dave (with UT)
!! - Flags for DeltaSCF
!! 2013/04/03 L.Tong
!! - Added user input parameters for updated Hilbert curve
!! partitioning method
!! 2013/07/01 M.Arita
!! - Added flags and parameters for the efficient MD scheme
!! 2013/08/20 M.Arita
!! - Add a flag for reusing T-matrix
!! 2014/01/21 lat
!! - Added flags for EXX and iprint_exx
!! 2015/06/08 lat
!! - Added experimental backtrace
!! 2015/06/10 15:47 cor & dave
!! Flags for wavefunction (band) output
!! 2015/06/10 16:01 dave
!! Bug fix: added default value for r_exx when EXX not set (prevents problems)
!! 2015/06/19 14:28 dave
!! Changed index of ChemicalSpeciesLabel to use number read from input file
!! 2015/11/09 17:17 dave with TM and NW (Mizuho)
!! Added read for neutral atom flag
!! 2015/11/24 08:30 dave
!! Removed flag_old_ewald (now redundant)
!! 2016/01/28 16:44 dave
!! Updated module name to ion_electrostatic
!! 2016/02/05 08:31 dave
!! Changed default pseudopotential to Siesta (necessary for now)
!! 2016/08/05 10:08 dave
!! Added gap threshold parameter for initial estimation of partition numbers
!! 2017/02/23 dave
!! - Changing location of diagon flag from DiagModule to global and name to flag_diagonalisation
!! 2017/03/14 SYM (with dave)
!! Fix lack of index on InvSRange when read in
!! 2017/04/05 18:00 nakata
!! Added charge_up, charge_dn and flag_readAtomicSpin to initialise spin from input file
!! 2017/04/24 dave
!! Changed pseudopotential output label to HAMANN (replacing ABINIT)
!! 2017/05/09 dave
!! Removed restriction on L-matrix re-use and spin
!! 2017/08/30 jack baker & dave
!! Adding parameters for simulation cell optimisation
!! 2017/10/15 dave & an
!! Reading atomic spins: small tweak to test on net spin (uses abs and RD_ERR)
!! 2017/10/24 zamaan
!! added thermostat flags for refactored NVT
!! 2017/11/13 18:15 nakata
!! Added flag_normalise to normalise each eigenstate of PDOS
!! 2018/01/19 dave
!! Added test for lmax_ps and NA projector functions
!! 2018/01/22 tsuyoshi (with dave)
!! Added new parameters:
!! - threshold for resetting charge density to atomic density
!! - time_max (General.MaxTime) to stop run after specified number of seconds in check_stop
!! 2018/02/26 12:22 dave
!! Bug fix: turn off mixed L-SCF with diagonalisation (was breaking force tests)
!! Second issue (14:08) set SC.MinIters to 0 as was breaking force tests; also tweaked
!! linear mixing end default
!! 2018/03/09 zamaan
!! Set some flags to true when restarting MD (loading matrices)
!! 2018/04/12 22:00 nakata
!! Bug fix: turn on flag_LFD_MD_UseAtomicDensity only when flag_SFcoeffReuse is .false.
!! 2018/04/24 zamaan
!! Changed AtomMove.FixCentreOfMass default to .true. except when running
!! FIRE qMD. minE.GlobalTolerance now defaults to .false. for MD.
!! 2018/4/25 zamaan
!! added md_tdep flag for TDEP output dump
!! 2018/05/17 12:54 dave with Ayako Nakata
!! flag_InitialAtomicSpin now comes from density_module (not global)
!! 2018/07/16 16:02 dave
!! Bug fix: only read RadiusMS when flag_Multisite is true
!! 2018/07/16 17:09 dave
!! Adding zero T requirement for flag_quench_MD as well as FIRE
!! 2018/09/19 18:30 nakata
!! Added flag_pDOS_angmom for orbital angular momentum resolved PDOS
!! 2018/10/22 14:26 dave & jsb
!! Added flag_PDOS_lm for (l,m) projected DOS
!! 2018/10/30 11:52 dave
!! added flag_PDOS_include_semicore to allow inclusion/exclusion of semi-core states from PDOS
!! 2019/02/28 zamaan
!! added stress and enthalpy tolerances for cell optimisation
!! 2019/03/28 zamaan
!! Added flag_stress and flag_full_stress to toggle calculation of stress
!! and off-diagonal elements respectively
!! 2019/05/21 zamaan
!! Added flag for RNG seed
!! 2019/10/08 nakata
!! Fixed bug for the case when reading only Kmatrix but not SFcoeff (for MSSFs)
!! 2019/11/14 20:00 nakata
!! set flag_SpinDependentSF to be .true. in default
!! 2019/11/18 14:36 dave
!! Added flag_variable_cell set to true for cell optimisation or NPT dynamics
!! 2019/12/04 08:09 dave
!! Made default pseudopotential type Hamann to fit with Conquest ion file generator
!! and made default grid 100Ha; removed check for old input file format; default method diagonalisation
!! 2019/12/26 tsuyoshi (2019/12/29)
!! General.LoadL => General.LoadLorK => General.LoadDM
!! AtomMove.ReuseL => AtomMove.ReuseLorK => AtomMove.ReuseDM
!! 2020/01/06 15:43 dave
!! Keywords for equilibration
!! 2020/01/07 tsuyoshi
!! Default setting of MakeInitialChargeFromK has been changed
!! 2020/12/14 lionel
!! EXX: added filtering option for EXX and cleaning
!! 2020/01/14 lionel
!! EXX: added GTO option
!! 2022/05/19 11:54 dave
!! Add input parameters for surface dipole correction
!! 2022/10/28 15:56 lionel
!! Added ASE output file setup ; default is F
!! 2022/12/14 10:01 dave and tsuyoshi
!! Update test for solution method (diagon vs ordern) following issue #47
!! 2024/12/03 lionel
!! Added grid specification of EXX coarse/standard/fine
!! 2025/02/03 nakata
!! Set flag_out_wf = .true. expricitly when flag_write_projected_DOS is .true.
!! TODO
!! SOURCE
!!
subroutine read_input(start, start_L, titles, vary_mu,&
mu, find_chdens, HNL_fac)
use datatypes
use numbers
use units
use global_module, only: iprint, flag_vary_basis, &
flag_self_consistent, &
flag_precondition_blips, &
flag_fix_spin_population, &
flag_fractional_atomic_coords, &
ne_in_cell, &
max_L_iterations, flag_read_blocks, &
runtype, restart_DM, restart_rho, &
flag_basis_set, blips, PAOs, &
flag_test_forces, UseGemm, &
flag_fractional_atomic_coords, &
ne_spin_in_cell, nspin, spin_factor, &
ne_magn_in_cell, &
max_L_iterations, &
flag_reset_dens_on_atom_move, &
flag_continue_on_SC_fail, iprint_init, &
iprint_mat, iprint_ops, iprint_DM, &
iprint_SC, iprint_minE, iprint_time, &
iprint_MD, iprint_index, iprint_gen, &
iprint_pseudo, iprint_basis, iprint_exx, &
iprint_intgn,iprint_MDdebug, &
global_maxatomspart, load_balance, &
flag_assign_blocks, &
io_ase, write_ase, ase_file, &
io_lun, flag_pulay_simpleStep, &
flag_Becke_weights, &
flag_Becke_atomic_radii, &
flag_global_tolerance, flag_mix_L_SC_min, &
flag_onsite_blip_ana, flag_read_velocity, &
flag_quench_MD, temp_ion, numprocs, &
flag_dft_d2, flag_only_dispersion, &
flag_perform_cDFT, flag_analytic_blip_int,&
flag_vdWDFT, vdW_LDA_functional, &
flag_dump_L, flag_DeltaSCF, dscf_source_level, &
dscf_target_level, dscf_source_spin, &
dscf_target_spin, dscf_source_nfold, &
dscf_target_nfold, flag_local_excitation, dscf_HOMO_thresh, &
dscf_LUMO_thresh, dscf_HOMO_limit, dscf_LUMO_limit, &
flag_MDcontinue,flag_MDdebug, &
flag_thermoDebug, flag_baroDebug, &
flag_LmatrixReuse,flag_TmatrixReuse,flag_SkipEarlyDM,McWFreq, &
restart_T,restart_X,flag_XLBOMD,flag_propagateX, &
flag_propagateL,flag_dissipation,integratorXL, flag_FixCOM, &
flag_exx, exx_alpha, exx_scf, exx_scf_tol, exx_siter, exx_cutoff, &
flag_out_wf,max_wf,out_wf,wf_self_con, flag_fire_qMD, &
flag_write_DOS, flag_write_projected_DOS, &
E_wf_min, E_wf_max, flag_wf_range_Ef, &
mx_temp_matrices, flag_neutral_atom, flag_diagonalisation, &
flag_SpinDependentSF, flag_Multisite, flag_LFD, flag_SFcoeffReuse, &
flag_opt_cell, cell_constraint_flag, flag_variable_cell, &
cell_en_tol, optcell_method, cell_stress_tol, &
flag_stress, flag_full_stress, rng_seed, &
flag_atomic_stress, flag_heat_flux, flag_DumpMatrices, flag_calc_pol, flag_do_pol_calc, &
i_pol_dir, i_pol_dir_st, i_pol_dir_end
use dimens, only: GridCutoff, &
n_grid_x, n_grid_y, n_grid_z, r_c, &
RadiusSupport, RadiusAtomf, RadiusMS, RadiusLD, &
NonLocalFactor, InvSRange, &
min_blip_sp, flag_buffer_old, AtomMove_buffer, &
r_dft_d2, r_exx, r_exxs
use block_module, only: in_block_x, in_block_y, in_block_z, &
blocks_raster, blocks_hilbert
use species_module, only: species_label, charge, mass, n_species, &
charge, charge_up, charge_dn, &
ps_file, &
nsf_species, &
non_local_species, type_species, &
species_file, species_from_files
use GenComms, only: gcopy, my_barrier, cq_abort, inode, ionode, cq_warn
!use DiagModule, only: diagon
!use DiagModule, only: flag_pDOS_include_semicore
use energy, only: flag_check_Diag
use DMMin, only: maxpulayDMM, maxpulaystepDMM, minpulaystepDMM, &
LinTol_DMM, n_dumpL
!TM
use pseudopotential_common, only: pseudo_type, OLDPS, SIESTA, &
ABINIT, flag_angular_new, &
flag_neutral_atom_projector, maxL_neutral_atom_projector, numN_neutral_atom_projector
use SelfCon, only: A, flag_linear_mixing, EndLinearMixing, q0, q1,&
n_exact, maxitersSC, maxearlySC, maxpulaySC, &
atomch_output, flag_Kerker, flag_wdmetric, minitersSC, &
flag_newresidual, flag_newresid_abs, n_dumpSCF
use density_module, only: flag_InitialAtomicSpin, flag_DumpChargeDensity
use density_module, only: flag_surface_dipole_correction, surface_normal, &
flag_output_average_potential, discontinuity_location, flag_dipole_internal
use S_matrix_module, only: InvSTolerance, InvSMaxSteps,&
InvSDeltaOmegaTolerance
use blip, only: blip_info, init_blip_flag, alpha, beta
use maxima_module, only: lmax_ps
use control, only: MDn_steps, MDfreq, XSFfreq, XYZfreq, &
MDcgtol, CGreset, LBFGS_history, sqnm_trust_step
use ion_electrostatic, only: ewald_accuracy
use minimise, only: UsePulay, n_L_iterations, &
n_support_iterations, L_tolerance, &
sc_tolerance, energy_tolerance, &
expected_reduction
use pao_format, only: kcut, del_k
use support_spec_format, only: flag_paos_atoms_in_cell, &
read_option, symmetry_breaking, &
support_pao_file, TestBasisGrads, &
TestTot, TestBoth, TestS, TestH
use read_pao_info, only: pao_info_file, pao_norm_flag
use read_support_spec, only: support_spec_file, &
flag_read_support_spec
use test_force_module, only: flag_test_all_forces, &
flag_which_force, TF_direction, &
TF_atom_moved, TF_delta
use io_module, only: pdb_format, pdb_altloc, append_coords, &
pdb_output, banner, get_file_name, time_max, &
flag_MatrixFile_RankFromZero, flag_MatrixFile_BinaryFormat, &
flag_MatrixFile_BinaryFormat_Grab, flag_MatrixFile_BinaryFormat_Dump, &
flag_MatrixFile_BinaryFormat_Dump_END, atom_output_threshold, flag_coords_xyz
use group_module, only: part_method, HILBERT, PYTHON
use H_matrix_module, only: flag_write_locps, flag_dump_locps
use pao_minimisation, only: InitStep_paomin
use timer_module, only: time_threshold,lun_tmr, TimingOn, &
TimersWriteOut, BackTraceOn
use input_module, only: load_input, input_array, block_start, &
block_end, fdf_boolean, fdf_integer, fdf_double, fdf_string, &
fdf_block, fdf_defined, leqi, io_assign, fdf_endblock
use cdft_data, only: cDFT_Type, cDFT_MaxIterations, cDFT_NAtoms, &
cDFT_Target, cDFT_Tolerance, &
cDFT_NumberAtomGroups, cDFT_AtomList, &
cDFT_BlockLabel
use sfc_partitions_module, only: n_parts_user, average_atomic_diameter, gap_threshold
use XLBOMD_module, only: XLInitFreq,kappa
use mult_module, only: maxiter_Dissipation, InitAtomicDistance_max, &
InitAtomicDistance_min, flag_check_init_atomic_coords
use constraint_module, only: flag_RigidBonds,constraints,SHAKE_tol, &
RATTLE_tol,maxiterSHAKE,maxiterRATTLE, &
const_range,n_bond
use exx_types, only: exx_scheme, exx_mem, exx_overlap, exx_alloc, &
exx_cartesian, exx_radius, exx_grid, exx_hgrid, exx_psolver, ewald_alpha, &
exx_debug, exx_pscheme, exx_filter, exx_filter_thr, exx_filter_extent, &
exx_gto, exx_gto_poisson
use multisiteSF_module, only: flag_MSSF_smear, MSSF_Smear_Type, &
MSSF_Smear_center, MSSF_Smear_shift, MSSF_Smear_width, &
flag_LFD_ReadTVEC, LFD_TVEC_read, &
LFD_kT, LFD_ChemP, flag_LFD_useChemPsub, &
flag_LFD_nonSCF, LFD_ThreshE, LFD_ThreshD, &
LFD_Thresh_EnergyRise, LFD_max_iteration, &
flag_LFD_MD_UseAtomicDensity, flag_MSSF_nonminimal, &
n_dumpSFcoeff, flag_mix_LFD_SCF, &
MSSF_nonminimal_offset ! nonmin_mssf
use md_control, only: md_tau_T, md_n_nhc, md_n_ys, md_n_mts, md_nhc_mass, &
target_pressure, md_baro_type, md_tau_P, &
md_thermo_type, md_bulkmod_est, md_box_mass, &
flag_write_xsf, md_cell_nhc, md_nhc_cell_mass, &
md_calc_xlmass, md_equil_steps, md_equil_press, &
md_tau_T_equil, md_tau_P_equil, md_p_drag, &
md_t_drag, md_cell_constraint, flag_write_extxyz, MDtimestep, md_ensemble, &
flag_variable_temperature, md_variable_temperature_method, &
md_variable_temperature_rate, md_initial_temperature, md_final_temperature
use md_model, only: md_tdep
use move_atoms, only: threshold_resetCD, &
flag_stop_on_empty_bundle, &
enthalpy_tolerance, cg_line_min, safe, backtrack, adapt_backtrack
use Integrators, only: fire_alpha0, fire_f_inc, fire_f_dec, fire_f_alpha, fire_N_min, &
fire_N_max, fire_max_step, fire_N_below_thresh
use XC, only : flag_functional_type, functional_hartree_fock, functional_hyb_pbe0, &
flag_different_functional
use biblio, only: flag_dump_bib
!2019/12/27 tsuyoshi
use density_module, only: method_UpdateChargeDensity,DensityMatrix,AtomicCharge
use force_module, only: mix_input_output_XC_GGA_stress
implicit none
! Passed variables
logical :: vary_mu, find_chdens
logical :: start, start_L
real(double) :: mu, HNL_fac
character(len=80) :: titles
! Local variables
character(len=80) :: sub_name = "read_input"
!type(block), pointer :: bp ! Pointer to a block read by fdf