-
Notifications
You must be signed in to change notification settings - Fork 1
/
qs_environment.F
1955 lines (1786 loc) · 96.7 KB
/
qs_environment.F
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
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \par History
!> - Merged with the Quickstep MODULE method_specification (17.01.2002,MK)
!> - USE statements cleaned, added
!> (25.09.2002,MK)
!> - Added more LSD structure (01.2003,Joost VandeVondele)
!> - New molecule data types introduced (Sep. 2003,MK)
!> - Cleaning; getting rid of pnode (02.10.2003,MK)
!> - Sub-system setup added (08.10.2003,MK)
!> \author MK (18.05.2000)
! **************************************************************************************************
MODULE qs_environment
USE almo_scf_env_methods, ONLY: almo_scf_env_create
USE atom_kind_orbitals, ONLY: calculate_atomic_relkin
USE atomic_kind_types, ONLY: atomic_kind_type
USE auto_basis, ONLY: create_lri_aux_basis_set,&
create_ri_aux_basis_set
USE basis_set_container_types, ONLY: add_basis_set_to_container
USE basis_set_types, ONLY: basis_sort_zet,&
create_primitive_basis_set,&
deallocate_gto_basis_set,&
gto_basis_set_type
USE bibliography, ONLY: Iannuzzi2006,&
Iannuzzi2007,&
cite_reference,&
cp2kqs2020
USE cell_types, ONLY: cell_type
USE cp_blacs_env, ONLY: cp_blacs_env_create,&
cp_blacs_env_release,&
cp_blacs_env_type
USE cp_control_types, ONLY: dft_control_type,&
dftb_control_type,&
gapw_control_type,&
qs_control_type,&
semi_empirical_control_type,&
xtb_control_type
USE cp_control_utils, ONLY: &
read_ddapc_section, read_dft_control, read_mgrid_section, read_qs_section, &
read_tddfpt2_control, read_tddfpt_control, write_admm_control, write_dft_control, &
write_qs_control
USE cp_ddapc_types, ONLY: cp_ddapc_ewald_create
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_get_default_io_unit,&
cp_logger_type
USE cp_output_handling, ONLY: cp_p_file,&
cp_print_key_finished_output,&
cp_print_key_should_output,&
cp_print_key_unit_nr
USE cp_subsys_types, ONLY: cp_subsys_type
USE cp_symmetry, ONLY: write_symmetry
USE distribution_1d_types, ONLY: distribution_1d_release,&
distribution_1d_type
USE distribution_methods, ONLY: distribute_molecules_1d
USE ec_env_types, ONLY: energy_correction_type
USE ec_environment, ONLY: ec_env_create,&
ec_write_input
USE et_coupling_types, ONLY: et_coupling_create
USE ewald_environment_types, ONLY: ewald_env_create,&
ewald_env_get,&
ewald_env_set,&
ewald_environment_type,&
read_ewald_section,&
read_ewald_section_tb
USE ewald_pw_methods, ONLY: ewald_pw_grid_update
USE ewald_pw_types, ONLY: ewald_pw_create,&
ewald_pw_type
USE exstates_types, ONLY: excited_energy_type,&
exstate_create
USE external_potential_types, ONLY: get_potential,&
init_potential,&
set_potential
USE fist_nonbond_env_types, ONLY: fist_nonbond_env_create,&
fist_nonbond_env_type
USE gamma, ONLY: init_md_ftable
USE global_types, ONLY: global_environment_type
USE hartree_local_methods, ONLY: init_coulomb_local
USE header, ONLY: dftb_header,&
qs_header,&
se_header,&
xtb_header
USE hfx_types, ONLY: compare_hfx_sections,&
hfx_create
USE input_constants, ONLY: &
dispersion_d2, dispersion_d3, dispersion_d3bj, do_et_ddapc, do_method_am1, do_method_dftb, &
do_method_gapw, do_method_gapw_xc, do_method_gpw, do_method_lrigpw, do_method_mndo, &
do_method_mndod, do_method_ofgpw, do_method_pdg, do_method_pm3, do_method_pm6, &
do_method_pm6fm, do_method_pnnl, do_method_rigpw, do_method_rm1, do_method_xtb, &
do_qmmm_gauss, do_qmmm_swave, general_roks, hden_atomic, kg_tnadd_embed_ri, rel_none, &
rel_trans_atom, vdw_pairpot_dftd2, vdw_pairpot_dftd3, vdw_pairpot_dftd3bj, &
vdw_pairpot_dftd4, wfi_aspc_nr, wfi_linear_ps_method_nr, wfi_linear_wf_method_nr, &
wfi_ps_method_nr, wfi_use_guess_method_nr, xc_vdw_fun_none, xc_vdw_fun_nonloc, &
xc_vdw_fun_pairpot, xtb_vdw_type_d3, xtb_vdw_type_d4, xtb_vdw_type_none
USE input_section_types, ONLY: section_vals_get,&
section_vals_get_subs_vals,&
section_vals_type,&
section_vals_val_get
USE kg_environment, ONLY: kg_env_create
USE kinds, ONLY: default_string_length,&
dp
USE kpoint_methods, ONLY: kpoint_env_initialize,&
kpoint_initialize,&
kpoint_initialize_mos
USE kpoint_types, ONLY: get_kpoint_info,&
kpoint_create,&
kpoint_type,&
read_kpoint_section,&
write_kpoint_info
USE lri_environment_init, ONLY: lri_env_basis,&
lri_env_init
USE lri_environment_types, ONLY: lri_environment_type
USE machine, ONLY: m_flush
USE mathconstants, ONLY: pi
USE message_passing, ONLY: mp_para_env_type
USE molecule_kind_types, ONLY: molecule_kind_type,&
write_molecule_kind_set
USE molecule_types, ONLY: molecule_type
USE mp2_setup, ONLY: read_mp2_section
USE mp2_types, ONLY: mp2_env_create,&
mp2_type
USE multipole_types, ONLY: do_multipole_none
USE orbital_pointers, ONLY: init_orbital_pointers
USE orbital_transformation_matrices, ONLY: init_spherical_harmonics
USE particle_methods, ONLY: write_particle_distances,&
write_qs_particle_coordinates,&
write_structure_data
USE particle_types, ONLY: particle_type
USE pw_env_types, ONLY: pw_env_type
USE qmmm_types_low, ONLY: qmmm_env_qm_type
USE qs_basis_rotation_methods, ONLY: qs_basis_rotation
USE qs_dftb_parameters, ONLY: qs_dftb_param_init
USE qs_dftb_types, ONLY: qs_dftb_pairpot_type
USE qs_dispersion_nonloc, ONLY: qs_dispersion_nonloc_init
USE qs_dispersion_pairpot, ONLY: qs_dispersion_pairpot_init
USE qs_dispersion_types, ONLY: qs_dispersion_type
USE qs_dispersion_utils, ONLY: qs_dispersion_env_set,&
qs_write_dispersion
USE qs_energy_types, ONLY: allocate_qs_energy,&
qs_energy_type
USE qs_environment_methods, ONLY: qs_env_setup
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type,&
set_qs_env
USE qs_force_types, ONLY: qs_force_type
USE qs_gcp_types, ONLY: qs_gcp_type
USE qs_gcp_utils, ONLY: qs_gcp_env_set,&
qs_gcp_init
USE qs_harris_types, ONLY: harris_rhoin_init,&
harris_type
USE qs_harris_utils, ONLY: harris_env_create,&
harris_write_input
USE qs_interactions, ONLY: init_interaction_radii,&
init_se_nlradius,&
write_core_charge_radii,&
write_paw_radii,&
write_pgf_orb_radii,&
write_ppl_radii,&
write_ppnl_radii
USE qs_kind_types, ONLY: &
check_qs_kind_set, get_qs_kind, get_qs_kind_set, init_gapw_basis_set, init_gapw_nlcc, &
init_qs_kind_set, qs_kind_type, set_qs_kind, write_gto_basis_sets, write_qs_kind_set
USE qs_ks_types, ONLY: qs_ks_env_create,&
qs_ks_env_type,&
set_ks_env
USE qs_local_rho_types, ONLY: local_rho_type
USE qs_mo_types, ONLY: allocate_mo_set,&
mo_set_type
USE qs_rho0_ggrid, ONLY: rho0_s_grid_create
USE qs_rho0_methods, ONLY: init_rho0
USE qs_rho0_types, ONLY: rho0_mpole_type
USE qs_rho_atom_methods, ONLY: init_rho_atom
USE qs_rho_atom_types, ONLY: rho_atom_type
USE qs_subsys_methods, ONLY: qs_subsys_create
USE qs_subsys_types, ONLY: qs_subsys_get,&
qs_subsys_set,&
qs_subsys_type
USE qs_wf_history_methods, ONLY: wfi_create,&
wfi_create_for_kp
USE qs_wf_history_types, ONLY: qs_wf_history_type,&
wfi_release
USE rel_control_types, ONLY: rel_c_create,&
rel_c_read_parameters,&
rel_control_type
USE scf_control_types, ONLY: scf_c_create,&
scf_c_read_parameters,&
scf_c_write_parameters,&
scf_control_type
USE semi_empirical_expns3_methods, ONLY: semi_empirical_expns3_setup
USE semi_empirical_int_arrays, ONLY: init_se_intd_array
USE semi_empirical_mpole_methods, ONLY: nddo_mpole_setup
USE semi_empirical_mpole_types, ONLY: nddo_mpole_type
USE semi_empirical_store_int_types, ONLY: semi_empirical_si_create,&
semi_empirical_si_type
USE semi_empirical_types, ONLY: se_taper_create,&
se_taper_type
USE semi_empirical_utils, ONLY: se_cutoff_compatible
USE transport, ONLY: transport_env_create
USE xtb_parameters, ONLY: init_xtb_basis,&
xtb_parameters_init,&
xtb_parameters_set
USE xtb_potentials, ONLY: xtb_pp_radius
USE xtb_types, ONLY: allocate_xtb_atom_param
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
! *** Global parameters ***
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_environment'
! *** Public subroutines ***
PUBLIC :: qs_init
CONTAINS
! **************************************************************************************************
!> \brief Read the input and the database files for the setup of the
!> QUICKSTEP environment.
!> \param qs_env ...
!> \param para_env ...
!> \param root_section ...
!> \param globenv ...
!> \param cp_subsys ...
!> \param kpoint_env ...
!> \param cell ...
!> \param cell_ref ...
!> \param qmmm ...
!> \param qmmm_env_qm ...
!> \param force_env_section ...
!> \param subsys_section ...
!> \param use_motion_section ...
!> \param silent ...
!> \author Creation (22.05.2000,MK)
! **************************************************************************************************
SUBROUTINE qs_init(qs_env, para_env, root_section, globenv, cp_subsys, kpoint_env, cell, cell_ref, &
qmmm, qmmm_env_qm, force_env_section, subsys_section, &
use_motion_section, silent)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(section_vals_type), OPTIONAL, POINTER :: root_section
TYPE(global_environment_type), OPTIONAL, POINTER :: globenv
TYPE(cp_subsys_type), OPTIONAL, POINTER :: cp_subsys
TYPE(kpoint_type), OPTIONAL, POINTER :: kpoint_env
TYPE(cell_type), OPTIONAL, POINTER :: cell, cell_ref
LOGICAL, INTENT(IN), OPTIONAL :: qmmm
TYPE(qmmm_env_qm_type), OPTIONAL, POINTER :: qmmm_env_qm
TYPE(section_vals_type), POINTER :: force_env_section, subsys_section
LOGICAL, INTENT(IN) :: use_motion_section
LOGICAL, INTENT(IN), OPTIONAL :: silent
CHARACTER(LEN=default_string_length) :: basis_type
INTEGER :: ikind, method_id, nelectron_total, &
nkind, nkp_grid(3)
LOGICAL :: do_admm_rpa, do_ec_hfx, do_et, do_exx, do_hfx, do_kpoints, is_identical, is_semi, &
mp2_present, my_qmmm, qmmm_decoupl, same_except_frac, use_ref_cell
REAL(KIND=dp), DIMENSION(:, :), POINTER :: rtmat
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: my_cell, my_cell_ref
TYPE(cp_blacs_env_type), POINTER :: blacs_env
TYPE(dft_control_type), POINTER :: dft_control
TYPE(distribution_1d_type), POINTER :: local_particles
TYPE(energy_correction_type), POINTER :: ec_env
TYPE(excited_energy_type), POINTER :: exstate_env
TYPE(harris_type), POINTER :: harris_env
TYPE(kpoint_type), POINTER :: kpoints
TYPE(lri_environment_type), POINTER :: lri_env
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(qs_ks_env_type), POINTER :: ks_env
TYPE(qs_subsys_type), POINTER :: subsys
TYPE(qs_wf_history_type), POINTER :: wf_history
TYPE(rel_control_type), POINTER :: rel_control
TYPE(scf_control_type), POINTER :: scf_control
TYPE(section_vals_type), POINTER :: dft_section, ec_hfx_section, ec_section, &
et_coupling_section, hfx_section, kpoint_section, mp2_section, rpa_hfx_section, &
transport_section
NULLIFY (my_cell, my_cell_ref, atomic_kind_set, particle_set, &
qs_kind_set, kpoint_section, dft_section, ec_section, &
subsys, ks_env, dft_control, blacs_env)
CALL set_qs_env(qs_env, input=force_env_section)
IF (.NOT. ASSOCIATED(subsys_section)) THEN
subsys_section => section_vals_get_subs_vals(force_env_section, "SUBSYS")
END IF
! QMMM
my_qmmm = .FALSE.
IF (PRESENT(qmmm)) my_qmmm = qmmm
qmmm_decoupl = .FALSE.
IF (PRESENT(qmmm_env_qm)) THEN
IF (qmmm_env_qm%qmmm_coupl_type == do_qmmm_gauss .OR. &
qmmm_env_qm%qmmm_coupl_type == do_qmmm_swave) THEN
! For GAUSS/SWAVE methods there could be a DDAPC decoupling requested
qmmm_decoupl = my_qmmm .AND. qmmm_env_qm%periodic .AND. qmmm_env_qm%multipole
END IF
qs_env%qmmm_env_qm => qmmm_env_qm
END IF
CALL set_qs_env(qs_env=qs_env, qmmm=my_qmmm)
! Possibly initialize arrays for SE
CALL section_vals_val_get(force_env_section, "DFT%QS%METHOD", i_val=method_id)
SELECT CASE (method_id)
CASE (do_method_rm1, do_method_am1, do_method_mndo, do_method_pdg, &
do_method_pm3, do_method_pm6, do_method_pm6fm, do_method_mndod, do_method_pnnl)
CALL init_se_intd_array()
is_semi = .TRUE.
CASE (do_method_xtb, do_method_dftb)
is_semi = .TRUE.
CASE DEFAULT
is_semi = .FALSE.
END SELECT
ALLOCATE (subsys)
CALL qs_subsys_create(subsys, para_env, &
force_env_section=force_env_section, &
subsys_section=subsys_section, &
use_motion_section=use_motion_section, &
root_section=root_section, &
cp_subsys=cp_subsys, cell=cell, cell_ref=cell_ref, &
elkind=is_semi, silent=silent)
ALLOCATE (ks_env)
CALL qs_ks_env_create(ks_env)
CALL set_ks_env(ks_env, subsys=subsys)
CALL set_qs_env(qs_env, ks_env=ks_env)
CALL qs_subsys_get(subsys, &
cell=my_cell, &
cell_ref=my_cell_ref, &
use_ref_cell=use_ref_cell, &
atomic_kind_set=atomic_kind_set, &
qs_kind_set=qs_kind_set, &
particle_set=particle_set)
CALL set_ks_env(ks_env, para_env=para_env)
IF (PRESENT(globenv)) THEN
CALL cp_blacs_env_create(blacs_env, para_env, globenv%blacs_grid_layout, &
globenv%blacs_repeatable)
ELSE
CALL cp_blacs_env_create(blacs_env, para_env)
END IF
CALL set_ks_env(ks_env, blacs_env=blacs_env)
CALL cp_blacs_env_release(blacs_env)
! *** Setup the grids for the G-space Interpolation if any
CALL cp_ddapc_ewald_create(qs_env%cp_ddapc_ewald, qmmm_decoupl, my_cell, &
force_env_section, subsys_section, para_env)
! kpoints
IF (PRESENT(kpoint_env)) THEN
kpoints => kpoint_env
CALL set_qs_env(qs_env=qs_env, kpoints=kpoints)
CALL kpoint_initialize(kpoints, particle_set, my_cell)
ELSE
NULLIFY (kpoints)
CALL kpoint_create(kpoints)
CALL set_qs_env(qs_env=qs_env, kpoints=kpoints)
kpoint_section => section_vals_get_subs_vals(qs_env%input, "DFT%KPOINTS")
CALL read_kpoint_section(kpoints, kpoint_section, my_cell%hmat)
CALL kpoint_initialize(kpoints, particle_set, my_cell)
dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
CALL write_kpoint_info(kpoints, dft_section)
END IF
CALL qs_init_subsys(qs_env, para_env, subsys, my_cell, my_cell_ref, use_ref_cell, &
subsys_section, silent=silent)
CALL get_qs_env(qs_env, dft_control=dft_control)
IF (method_id == do_method_lrigpw .OR. dft_control%qs_control%lri_optbas) THEN
CALL get_qs_env(qs_env=qs_env, lri_env=lri_env)
CALL lri_env_basis("LRI", qs_env, lri_env, qs_kind_set)
ELSE IF (method_id == do_method_rigpw) THEN
CALL cp_warn(__LOCATION__, "Experimental code: "// &
"RIGPW should only be used for testing.")
CALL get_qs_env(qs_env=qs_env, lri_env=lri_env)
CALL lri_env_basis("RI", qs_env, lri_env, qs_kind_set)
END IF
IF (my_qmmm .AND. PRESENT(qmmm_env_qm) .AND. .NOT. dft_control%qs_control%commensurate_mgrids) THEN
IF (qmmm_env_qm%qmmm_coupl_type == do_qmmm_gauss .OR. qmmm_env_qm%qmmm_coupl_type == do_qmmm_swave) THEN
CALL cp_abort(__LOCATION__, "QM/MM with coupling GAUSS or S-WAVE requires "// &
"keyword FORCE_EVAL/DFT/MGRID/COMMENSURATE to be enabled.")
END IF
END IF
! more kpoint stuff
CALL get_qs_env(qs_env=qs_env, do_kpoints=do_kpoints, blacs_env=blacs_env)
IF (do_kpoints) THEN
CALL kpoint_env_initialize(kpoints, para_env, blacs_env, with_aux_fit=dft_control%do_admm)
CALL kpoint_initialize_mos(kpoints, qs_env%mos)
CALL get_qs_env(qs_env=qs_env, wf_history=wf_history)
CALL wfi_create_for_kp(wf_history)
END IF
! basis set symmetry rotations
IF (do_kpoints) THEN
CALL qs_basis_rotation(qs_env, kpoints)
END IF
do_hfx = .FALSE.
hfx_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%HF")
CALL section_vals_get(hfx_section, explicit=do_hfx)
CALL get_qs_env(qs_env, dft_control=dft_control, scf_control=scf_control, nelectron_total=nelectron_total)
IF (do_hfx) THEN
! Retrieve particle_set and atomic_kind_set (needed for both kinds of initialization)
nkp_grid = 1
IF (do_kpoints) CALL get_kpoint_info(kpoints, nkp_grid=nkp_grid)
IF (dft_control%do_admm) THEN
basis_type = 'AUX_FIT'
ELSE
basis_type = 'ORB'
END IF
CALL hfx_create(qs_env%x_data, para_env, hfx_section, atomic_kind_set, &
qs_kind_set, particle_set, dft_control, my_cell, orb_basis=basis_type, &
nelectron_total=nelectron_total, nkp_grid=nkp_grid)
END IF
mp2_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%WF_CORRELATION")
CALL section_vals_get(mp2_section, explicit=mp2_present)
IF (mp2_present) THEN
CPASSERT(ASSOCIATED(qs_env%mp2_env))
CALL read_mp2_section(qs_env%input, qs_env%mp2_env)
! create the EXX section if necessary
do_exx = .FALSE.
rpa_hfx_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%WF_CORRELATION%RI_RPA%HF")
CALL section_vals_get(rpa_hfx_section, explicit=do_exx)
IF (do_exx) THEN
! do_exx in call of hfx_create decides whether to go without ADMM (do_exx=.TRUE.) or with
! ADMM (do_exx=.FALSE.)
CALL section_vals_val_get(mp2_section, "RI_RPA%ADMM", l_val=do_admm_rpa)
! Reuse the HFX integrals from the qs_env if applicable
qs_env%mp2_env%ri_rpa%reuse_hfx = .TRUE.
IF (.NOT. do_hfx) qs_env%mp2_env%ri_rpa%reuse_hfx = .FALSE.
CALL compare_hfx_sections(hfx_section, rpa_hfx_section, is_identical, same_except_frac)
IF (.NOT. (is_identical .OR. same_except_frac)) qs_env%mp2_env%ri_rpa%reuse_hfx = .FALSE.
IF (dft_control%do_admm .AND. .NOT. do_admm_rpa) qs_env%mp2_env%ri_rpa%reuse_hfx = .FALSE.
IF (.NOT. qs_env%mp2_env%ri_rpa%reuse_hfx) THEN
IF (do_admm_rpa) THEN
basis_type = 'AUX_FIT'
ELSE
basis_type = 'ORB'
END IF
CALL hfx_create(qs_env%mp2_env%ri_rpa%x_data, para_env, rpa_hfx_section, atomic_kind_set, &
qs_kind_set, particle_set, dft_control, my_cell, orb_basis=basis_type, &
nelectron_total=nelectron_total)
ELSE
qs_env%mp2_env%ri_rpa%x_data => qs_env%x_data
END IF
END IF
END IF
IF (dft_control%qs_control%do_kg) THEN
CALL cite_reference(Iannuzzi2006)
CALL kg_env_create(qs_env, qs_env%kg_env, qs_kind_set, qs_env%input)
END IF
dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
CALL section_vals_val_get(dft_section, "EXCITED_STATES%_SECTION_PARAMETERS_", &
l_val=qs_env%excited_state)
NULLIFY (exstate_env)
CALL exstate_create(exstate_env, qs_env%excited_state, dft_section)
CALL set_qs_env(qs_env, exstate_env=exstate_env)
et_coupling_section => section_vals_get_subs_vals(qs_env%input, &
"PROPERTIES%ET_COUPLING")
CALL section_vals_get(et_coupling_section, explicit=do_et)
IF (do_et) CALL et_coupling_create(qs_env%et_coupling)
transport_section => section_vals_get_subs_vals(qs_env%input, "DFT%TRANSPORT")
CALL section_vals_get(transport_section, explicit=qs_env%do_transport)
IF (qs_env%do_transport) THEN
CALL transport_env_create(qs_env)
END IF
CALL get_qs_env(qs_env, harris_env=harris_env)
IF (qs_env%harris_method) THEN
! initialize the Harris input density and potential integrals
CALL get_qs_env(qs_env, local_particles=local_particles)
CALL harris_rhoin_init(harris_env%rhoin, "RHOIN", qs_kind_set, atomic_kind_set, &
local_particles, dft_control%nspins)
! Print information of the HARRIS section
CALL harris_write_input(harris_env)
END IF
NULLIFY (ec_env)
dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
CALL section_vals_val_get(dft_section, "ENERGY_CORRECTION%_SECTION_PARAMETERS_", &
l_val=qs_env%energy_correction)
ec_section => section_vals_get_subs_vals(qs_env%input, "DFT%ENERGY_CORRECTION")
CALL ec_env_create(qs_env, ec_env, dft_section, ec_section)
CALL set_qs_env(qs_env, ec_env=ec_env)
IF (qs_env%energy_correction) THEN
! Energy correction with Hartree-Fock exchange
ec_hfx_section => section_vals_get_subs_vals(ec_section, "XC%HF")
CALL section_vals_get(ec_hfx_section, explicit=do_ec_hfx)
IF (ec_env%do_ec_hfx) THEN
! Hybrid functionals require same basis
IF (ec_env%basis_inconsistent) THEN
CALL cp_abort(__LOCATION__, &
"Energy correction methods with hybrid functionals: "// &
"correction and ground state need to use the same basis. "// &
"Checked by comparing basis set names only.")
END IF
! Similar to RPA_HFX we can check if HFX integrals from the qs_env can be reused
IF (ec_env%do_ec_admm .AND. .NOT. dft_control%do_admm) THEN
CALL cp_abort(__LOCATION__, "Need an ADMM input section for ADMM EC to work")
END IF
ec_env%reuse_hfx = .TRUE.
IF (.NOT. do_hfx) ec_env%reuse_hfx = .FALSE.
CALL compare_hfx_sections(hfx_section, ec_hfx_section, is_identical, same_except_frac)
IF (.NOT. (is_identical .OR. same_except_frac)) ec_env%reuse_hfx = .FALSE.
IF (dft_control%do_admm .AND. .NOT. ec_env%do_ec_admm) ec_env%reuse_hfx = .FALSE.
IF (.NOT. ec_env%reuse_hfx) THEN
IF (ec_env%do_ec_admm) THEN
basis_type = 'AUX_FIT'
ELSE
basis_type = 'ORB'
END IF
CALL hfx_create(ec_env%x_data, para_env, ec_hfx_section, atomic_kind_set, &
qs_kind_set, particle_set, dft_control, my_cell, orb_basis=basis_type, &
nelectron_total=nelectron_total)
ELSE
ec_env%x_data => qs_env%x_data
END IF
END IF
! Print information of the EC section
CALL ec_write_input(ec_env)
END IF
IF (dft_control%qs_control%do_almo_scf) THEN
CALL almo_scf_env_create(qs_env)
END IF
! see if we have atomic relativistic corrections
CALL get_qs_env(qs_env, rel_control=rel_control)
IF (rel_control%rel_method /= rel_none) THEN
IF (rel_control%rel_transformation == rel_trans_atom) THEN
nkind = SIZE(atomic_kind_set)
DO ikind = 1, nkind
NULLIFY (rtmat)
CALL calculate_atomic_relkin(atomic_kind_set(ikind), qs_kind_set(ikind), rel_control, rtmat)
IF (ASSOCIATED(rtmat)) CALL set_qs_kind(qs_kind_set(ikind), reltmat=rtmat)
END DO
END IF
END IF
END SUBROUTINE qs_init
! **************************************************************************************************
!> \brief Initialize the qs environment (subsys)
!> \param qs_env ...
!> \param para_env ...
!> \param subsys ...
!> \param cell ...
!> \param cell_ref ...
!> \param use_ref_cell ...
!> \param subsys_section ...
!> \param silent ...
!> \author Creation (22.05.2000,MK)
! **************************************************************************************************
SUBROUTINE qs_init_subsys(qs_env, para_env, subsys, cell, cell_ref, use_ref_cell, subsys_section, &
silent)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(qs_subsys_type), POINTER :: subsys
TYPE(cell_type), POINTER :: cell, cell_ref
LOGICAL, INTENT(in) :: use_ref_cell
TYPE(section_vals_type), POINTER :: subsys_section
LOGICAL, INTENT(in), OPTIONAL :: silent
CHARACTER(len=*), PARAMETER :: routineN = 'qs_init_subsys'
CHARACTER(len=2) :: element_symbol
INTEGER :: gfn_type, handle, ikind, ispin, iw, lmax_sphere, maxl, maxlgto, maxlgto_lri, &
maxlppl, maxlppnl, method_id, multiplicity, my_ival, n_ao, n_mo_add, natom, nelectron, &
ngauss, nkind, output_unit, sort_basis, tnadd_method
INTEGER, DIMENSION(2) :: n_mo, nelectron_spin
LOGICAL :: all_potential_present, be_silent, do_kpoints, do_ri_hfx, do_ri_mp2, do_ri_rpa, &
do_ri_sos_mp2, do_rpa_ri_exx, do_wfc_im_time, e1terms, has_unit_metric, lribas, &
mp2_present, orb_gradient
REAL(KIND=dp) :: alpha, ccore, ewald_rcut, fxx, maxocc, &
rcut, total_zeff_corr, verlet_skin, &
zeff_correction
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cp_logger_type), POINTER :: logger
TYPE(dft_control_type), POINTER :: dft_control
TYPE(dftb_control_type), POINTER :: dftb_control
TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
TYPE(ewald_environment_type), POINTER :: ewald_env
TYPE(ewald_pw_type), POINTER :: ewald_pw
TYPE(fist_nonbond_env_type), POINTER :: se_nonbond_env
TYPE(gapw_control_type), POINTER :: gapw_control
TYPE(gto_basis_set_type), POINTER :: aux_fit_basis, lri_aux_basis, &
rhoin_basis, ri_aux_basis_set, &
ri_hfx_basis, ri_xas_basis, &
tmp_basis_set
TYPE(harris_type), POINTER :: harris_env
TYPE(local_rho_type), POINTER :: local_rho_set
TYPE(lri_environment_type), POINTER :: lri_env
TYPE(mo_set_type), DIMENSION(:), POINTER :: mos, mos_last_converged
TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
TYPE(mp2_type), POINTER :: mp2_env
TYPE(nddo_mpole_type), POINTER :: se_nddo_mpole
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(pw_env_type), POINTER :: pw_env
TYPE(qs_control_type), POINTER :: qs_control
TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), &
POINTER :: dftb_potential
TYPE(qs_dispersion_type), POINTER :: dispersion_env
TYPE(qs_energy_type), POINTER :: energy
TYPE(qs_force_type), DIMENSION(:), POINTER :: force
TYPE(qs_gcp_type), POINTER :: gcp_env
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(qs_kind_type), POINTER :: qs_kind
TYPE(qs_ks_env_type), POINTER :: ks_env
TYPE(qs_wf_history_type), POINTER :: wf_history
TYPE(rho0_mpole_type), POINTER :: rho0_mpole
TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
TYPE(scf_control_type), POINTER :: scf_control
TYPE(se_taper_type), POINTER :: se_taper
TYPE(section_vals_type), POINTER :: dft_section, et_coupling_section, et_ddapc_section, &
ewald_section, harris_section, lri_section, mp2_section, nl_section, poisson_section, &
pp_section, print_section, qs_section, se_section, tddfpt_section, xc_section
TYPE(semi_empirical_control_type), POINTER :: se_control
TYPE(semi_empirical_si_type), POINTER :: se_store_int_env
TYPE(xtb_control_type), POINTER :: xtb_control
CALL timeset(routineN, handle)
NULLIFY (logger)
logger => cp_get_default_logger()
output_unit = cp_logger_get_default_io_unit(logger)
be_silent = .FALSE.
IF (PRESENT(silent)) be_silent = silent
CALL cite_reference(cp2kqs2020)
! Initialise the Quickstep environment
NULLIFY (mos, se_taper)
NULLIFY (dft_control)
NULLIFY (energy)
NULLIFY (force)
NULLIFY (local_molecules)
NULLIFY (local_particles)
NULLIFY (scf_control)
NULLIFY (dft_section)
NULLIFY (et_coupling_section)
NULLIFY (ks_env)
NULLIFY (mos_last_converged)
dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
qs_section => section_vals_get_subs_vals(dft_section, "QS")
et_coupling_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%ET_COUPLING")
! reimplemented TDDFPT
tddfpt_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%TDDFPT")
CALL qs_subsys_get(subsys, particle_set=particle_set, &
qs_kind_set=qs_kind_set, &
atomic_kind_set=atomic_kind_set, &
molecule_set=molecule_set, &
molecule_kind_set=molecule_kind_set)
! *** Read the input section with the DFT control parameters ***
CALL read_dft_control(dft_control, dft_section)
! original implementation of TDDFPT
IF (dft_control%do_tddfpt_calculation) THEN
CALL read_tddfpt_control(dft_control%tddfpt_control, dft_section)
END IF
! set periodicity flag
dft_control%qs_control%periodicity = SUM(cell%perd)
! Read the input section with the Quickstep control parameters
CALL read_qs_section(dft_control%qs_control, qs_section)
! *** Print the Quickstep program banner (copyright and version number) ***
IF (.NOT. be_silent) THEN
iw = cp_print_key_unit_nr(logger, dft_section, "PRINT%PROGRAM_BANNER", extension=".Log")
CALL section_vals_val_get(qs_section, "METHOD", i_val=method_id)
SELECT CASE (method_id)
CASE DEFAULT
CALL qs_header(iw)
CASE (do_method_rm1, do_method_am1, do_method_mndo, do_method_pdg, &
do_method_pm3, do_method_pm6, do_method_pm6fm, do_method_mndod, do_method_pnnl)
CALL se_header(iw)
CASE (do_method_dftb)
CALL dftb_header(iw)
CASE (do_method_xtb)
gfn_type = dft_control%qs_control%xtb_control%gfn_type
CALL xtb_header(iw, gfn_type)
END SELECT
CALL cp_print_key_finished_output(iw, logger, dft_section, &
"PRINT%PROGRAM_BANNER")
END IF
IF (dft_control%do_sccs .AND. dft_control%qs_control%gapw) THEN
CPABORT("SCCS is not yet implemented with GAPW")
END IF
CALL get_qs_env(qs_env=qs_env, do_kpoints=do_kpoints)
IF (do_kpoints) THEN
! reset some of the settings for wfn extrapolation for kpoints
SELECT CASE (dft_control%qs_control%wf_interpolation_method_nr)
CASE (wfi_linear_wf_method_nr, wfi_linear_ps_method_nr, wfi_ps_method_nr, wfi_aspc_nr)
dft_control%qs_control%wf_interpolation_method_nr = wfi_use_guess_method_nr
END SELECT
END IF
! ******* check if any kind of electron transfer calculation has to be performed
CALL section_vals_val_get(et_coupling_section, "TYPE_OF_CONSTRAINT", i_val=my_ival)
dft_control%qs_control%et_coupling_calc = .FALSE.
IF (my_ival == do_et_ddapc) THEN
et_ddapc_section => section_vals_get_subs_vals(et_coupling_section, "DDAPC_RESTRAINT_A")
dft_control%qs_control%et_coupling_calc = .TRUE.
dft_control%qs_control%ddapc_restraint = .TRUE.
CALL read_ddapc_section(dft_control%qs_control, ddapc_restraint_section=et_ddapc_section)
END IF
CALL read_mgrid_section(dft_control%qs_control, dft_section)
! reimplemented TDDFPT
CALL read_tddfpt2_control(dft_control%tddfpt2_control, tddfpt_section, dft_control%qs_control)
! Create relativistic control section
BLOCK
TYPE(rel_control_type), POINTER :: rel_control
ALLOCATE (rel_control)
CALL rel_c_create(rel_control)
CALL rel_c_read_parameters(rel_control, dft_section)
CALL set_qs_env(qs_env, rel_control=rel_control)
END BLOCK
! *** Read DFTB parameter files ***
IF (dft_control%qs_control%method_id == do_method_dftb) THEN
NULLIFY (ewald_env, ewald_pw, dftb_potential)
dftb_control => dft_control%qs_control%dftb_control
CALL qs_dftb_param_init(atomic_kind_set, qs_kind_set, dftb_control, dftb_potential, &
subsys_section=subsys_section, para_env=para_env)
CALL set_qs_env(qs_env, dftb_potential=dftb_potential)
! check for Ewald
IF (dftb_control%do_ewald) THEN
ALLOCATE (ewald_env)
CALL ewald_env_create(ewald_env, para_env)
poisson_section => section_vals_get_subs_vals(dft_section, "POISSON")
CALL ewald_env_set(ewald_env, poisson_section=poisson_section)
ewald_section => section_vals_get_subs_vals(poisson_section, "EWALD")
print_section => section_vals_get_subs_vals(qs_env%input, "PRINT%GRID_INFORMATION")
CALL get_qs_kind_set(qs_kind_set, basis_rcut=ewald_rcut)
CALL read_ewald_section_tb(ewald_env, ewald_section, cell_ref%hmat)
ALLOCATE (ewald_pw)
CALL ewald_pw_create(ewald_pw, ewald_env, cell, cell_ref, print_section=print_section)
CALL set_qs_env(qs_env, ewald_env=ewald_env, ewald_pw=ewald_pw)
END IF
ELSEIF (dft_control%qs_control%method_id == do_method_xtb) THEN
! *** Read xTB parameter file ***
xtb_control => dft_control%qs_control%xtb_control
NULLIFY (ewald_env, ewald_pw)
CALL get_qs_env(qs_env, nkind=nkind)
DO ikind = 1, nkind
qs_kind => qs_kind_set(ikind)
! Setup proper xTB parameters
CPASSERT(.NOT. ASSOCIATED(qs_kind%xtb_parameter))
CALL allocate_xtb_atom_param(qs_kind%xtb_parameter)
! Set default parameters
gfn_type = dft_control%qs_control%xtb_control%gfn_type
CALL get_qs_kind(qs_kind, element_symbol=element_symbol)
CALL xtb_parameters_init(qs_kind%xtb_parameter, gfn_type, element_symbol, &
xtb_control%parameter_file_path, xtb_control%parameter_file_name, &
para_env)
! set dependent parameters
CALL xtb_parameters_set(qs_kind%xtb_parameter)
! Generate basis set
NULLIFY (tmp_basis_set)
IF (qs_kind%xtb_parameter%z == 1) THEN
! special case hydrogen
ngauss = xtb_control%h_sto_ng
ELSE
ngauss = xtb_control%sto_ng
END IF
IF (qs_kind%xtb_parameter%defined) THEN
CALL init_xtb_basis(qs_kind%xtb_parameter, tmp_basis_set, ngauss)
CALL add_basis_set_to_container(qs_kind%basis_sets, tmp_basis_set, "ORB")
ELSE
CALL set_qs_kind(qs_kind, ghost=.TRUE.)
IF (ASSOCIATED(qs_kind%all_potential)) THEN
DEALLOCATE (qs_kind%all_potential%elec_conf)
DEALLOCATE (qs_kind%all_potential)
END IF
END IF
! potential
IF (qs_kind%xtb_parameter%defined) THEN
zeff_correction = 0.0_dp
CALL init_potential(qs_kind%all_potential, itype="BARE", &
zeff=qs_kind%xtb_parameter%zeff, zeff_correction=zeff_correction)
CALL get_potential(qs_kind%all_potential, alpha_core_charge=alpha)
ccore = qs_kind%xtb_parameter%zeff*SQRT((alpha/pi)**3)
CALL set_potential(qs_kind%all_potential, ccore_charge=ccore)
qs_kind%xtb_parameter%zeff = qs_kind%xtb_parameter%zeff - zeff_correction
END IF
END DO
!
! set repulsive potential range
!
ALLOCATE (xtb_control%rcpair(nkind, nkind))
CALL xtb_pp_radius(qs_kind_set, xtb_control%rcpair, xtb_control%eps_pair, xtb_control%kf)
! check for Ewald
IF (xtb_control%do_ewald) THEN
ALLOCATE (ewald_env)
CALL ewald_env_create(ewald_env, para_env)
poisson_section => section_vals_get_subs_vals(dft_section, "POISSON")
CALL ewald_env_set(ewald_env, poisson_section=poisson_section)
ewald_section => section_vals_get_subs_vals(poisson_section, "EWALD")
print_section => section_vals_get_subs_vals(qs_env%input, "PRINT%GRID_INFORMATION")
IF (gfn_type == 0) THEN
CALL read_ewald_section_tb(ewald_env, ewald_section, cell_ref%hmat, &
silent=silent, pset="EEQ")
ELSE
CALL read_ewald_section_tb(ewald_env, ewald_section, cell_ref%hmat, &
silent=silent)
END IF
ALLOCATE (ewald_pw)
CALL ewald_pw_create(ewald_pw, ewald_env, cell, cell_ref, print_section=print_section)
CALL set_qs_env(qs_env, ewald_env=ewald_env, ewald_pw=ewald_pw)
END IF
END IF
! lri or ri env initialization
lri_section => section_vals_get_subs_vals(qs_section, "LRIGPW")
IF (dft_control%qs_control%method_id == do_method_lrigpw .OR. &
dft_control%qs_control%lri_optbas .OR. &
dft_control%qs_control%method_id == do_method_rigpw) THEN
CALL lri_env_init(lri_env, lri_section)
CALL set_qs_env(qs_env, lri_env=lri_env)
END IF
! *** Check basis and fill in missing parts ***
CALL check_qs_kind_set(qs_kind_set, dft_control, subsys_section=subsys_section)
! *** Check that no all-electron potential is present if GPW or GAPW_XC
CALL get_qs_kind_set(qs_kind_set, all_potential_present=all_potential_present)
IF ((dft_control%qs_control%method_id == do_method_gpw) .OR. &
(dft_control%qs_control%method_id == do_method_gapw_xc) .OR. &
(dft_control%qs_control%method_id == do_method_ofgpw)) THEN
IF (all_potential_present) THEN
CPABORT("All-electron calculations with GPW, GAPW_XC, and OFGPW are not implemented")
END IF
END IF
! DFT+U
CALL get_qs_kind_set(qs_kind_set, dft_plus_u_atom_present=dft_control%dft_plus_u)
IF (dft_control%do_admm) THEN
! Check if ADMM basis is available
CALL get_qs_env(qs_env, nkind=nkind)
DO ikind = 1, nkind
NULLIFY (aux_fit_basis)
qs_kind => qs_kind_set(ikind)
CALL get_qs_kind(qs_kind, basis_set=aux_fit_basis, basis_type="AUX_FIT")
IF (.NOT. (ASSOCIATED(aux_fit_basis))) THEN
! AUX_FIT basis set is not available
CPABORT("AUX_FIT basis set is not defined. ")
END IF
END DO
END IF
lribas = .FALSE.
e1terms = .FALSE.
IF (dft_control%qs_control%method_id == do_method_lrigpw) THEN
lribas = .TRUE.
CALL get_qs_env(qs_env, lri_env=lri_env)
e1terms = lri_env%exact_1c_terms
END IF
IF (dft_control%qs_control%do_kg) THEN
CALL section_vals_val_get(dft_section, "KG_METHOD%TNADD_METHOD", i_val=tnadd_method)
IF (tnadd_method == kg_tnadd_embed_ri) lribas = .TRUE.
END IF
IF (lribas) THEN
! Check if LRI_AUX basis is available, auto-generate if needed
CALL get_qs_env(qs_env, nkind=nkind)
DO ikind = 1, nkind
NULLIFY (lri_aux_basis)
qs_kind => qs_kind_set(ikind)
CALL get_qs_kind(qs_kind, basis_set=lri_aux_basis, basis_type="LRI_AUX")
IF (.NOT. (ASSOCIATED(lri_aux_basis))) THEN
! LRI_AUX basis set is not yet loaded
CALL cp_warn(__LOCATION__, "Automatic Generation of LRI_AUX basis. "// &
"This is experimental code.")
! Generate a default basis
CALL create_lri_aux_basis_set(lri_aux_basis, qs_kind, dft_control%auto_basis_lri_aux, e1terms)
CALL add_basis_set_to_container(qs_kind%basis_sets, lri_aux_basis, "LRI_AUX")
END IF
END DO
END IF
CALL section_vals_val_get(qs_env%input, "DFT%XC%HF%RI%_SECTION_PARAMETERS_", l_val=do_ri_hfx)
CALL section_vals_val_get(qs_env%input, "DFT%XC%WF_CORRELATION%RI_RPA%HF%RI%_SECTION_PARAMETERS_", &
l_val=do_rpa_ri_exx)
IF (do_ri_hfx .OR. do_rpa_ri_exx) THEN
CALL get_qs_env(qs_env, nkind=nkind)
CALL section_vals_val_get(qs_env%input, "DFT%SORT_BASIS", i_val=sort_basis)
DO ikind = 1, nkind
NULLIFY (ri_hfx_basis)
qs_kind => qs_kind_set(ikind)
CALL get_qs_kind(qs_kind=qs_kind, basis_set=ri_hfx_basis, &
basis_type="RI_HFX")
IF (.NOT. (ASSOCIATED(ri_hfx_basis))) THEN
CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto)
IF (dft_control%do_admm) THEN
CALL create_ri_aux_basis_set(ri_hfx_basis, qs_kind, dft_control%auto_basis_ri_hfx, &
basis_type="AUX_FIT", basis_sort=sort_basis)
ELSE
CALL create_ri_aux_basis_set(ri_hfx_basis, qs_kind, dft_control%auto_basis_ri_hfx, &
basis_sort=sort_basis)
END IF
CALL add_basis_set_to_container(qs_kind%basis_sets, ri_hfx_basis, "RI_HFX")
END IF
END DO
END IF
IF (dft_control%qs_control%method_id == do_method_rigpw) THEN
! Check if RI_HXC basis is available, auto-generate if needed
CALL get_qs_env(qs_env, nkind=nkind)
DO ikind = 1, nkind
NULLIFY (ri_hfx_basis)
qs_kind => qs_kind_set(ikind)
CALL get_qs_kind(qs_kind, basis_set=ri_hfx_basis, basis_type="RI_HXC")
IF (.NOT. (ASSOCIATED(ri_hfx_basis))) THEN
! Generate a default basis
CALL create_ri_aux_basis_set(ri_hfx_basis, qs_kind, dft_control%auto_basis_ri_hxc)
CALL add_basis_set_to_container(qs_kind%basis_sets, ri_hfx_basis, "RI_HXC")
END IF
END DO
END IF
! Harris method
NULLIFY (harris_env)
CALL section_vals_val_get(dft_section, "HARRIS_METHOD%_SECTION_PARAMETERS_", &
l_val=qs_env%harris_method)
harris_section => section_vals_get_subs_vals(dft_section, "HARRIS_METHOD")
CALL harris_env_create(qs_env, harris_env, harris_section)
CALL set_qs_env(qs_env, harris_env=harris_env)
!
IF (qs_env%harris_method) THEN
CALL get_qs_env(qs_env, nkind=nkind)
! Check if RI_HXC basis is available, auto-generate if needed
DO ikind = 1, nkind
NULLIFY (tmp_basis_set)
qs_kind => qs_kind_set(ikind)
CALL get_qs_kind(qs_kind, basis_set=rhoin_basis, basis_type="RHOIN")
IF (.NOT. (ASSOCIATED(rhoin_basis))) THEN
! Generate a default basis
CALL create_ri_aux_basis_set(tmp_basis_set, qs_kind, dft_control%auto_basis_ri_hxc)
IF (qs_env%harris_env%density_source == hden_atomic) THEN
CALL create_primitive_basis_set(tmp_basis_set, rhoin_basis, lmax=0)
CALL deallocate_gto_basis_set(tmp_basis_set)
ELSE
rhoin_basis => tmp_basis_set
END IF
CALL add_basis_set_to_container(qs_kind%basis_sets, rhoin_basis, "RHOIN")
END IF
END DO
END IF
mp2_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%WF_CORRELATION")
CALL section_vals_get(mp2_section, explicit=mp2_present)
IF (mp2_present) THEN
! basis should be sorted for imaginary time RPA/GW
CALL section_vals_val_get(qs_env%input, "DFT%SORT_BASIS", i_val=sort_basis)
CALL section_vals_val_get(qs_env%input, "DFT%XC%WF_CORRELATION%LOW_SCALING%_SECTION_PARAMETERS_", &
l_val=do_wfc_im_time)
IF (do_wfc_im_time .AND. sort_basis /= basis_sort_zet) THEN
CALL cp_warn(__LOCATION__, &
"Low-scaling RPA requires SORT_BASIS EXP keyword (in DFT input section) for good performance")
END IF
! Check if RI_AUX basis (for MP2/RPA) is given, auto-generate if not
CALL mp2_env_create(qs_env%mp2_env)
CALL get_qs_env(qs_env, mp2_env=mp2_env, nkind=nkind)
CALL section_vals_val_get(qs_env%input, "DFT%XC%WF_CORRELATION%RI_MP2%_SECTION_PARAMETERS_", l_val=do_ri_mp2)