-
Notifications
You must be signed in to change notification settings - Fork 1
/
hfx_admm_utils.F
2563 lines (2271 loc) · 129 KB
/
hfx_admm_utils.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 !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief Utilities for hfx and admm methods
!>
!>
!> \par History
!> refactoring 03-2011 [MI]
!> Made GAPW compatible 12.2019 (A. Bussy)
!> \author MI
! **************************************************************************************************
MODULE hfx_admm_utils
USE admm_dm_types, ONLY: admm_dm_create
USE admm_methods, ONLY: kpoint_calc_admm_matrices,&
scale_dm
USE admm_types, ONLY: admm_env_create,&
admm_gapw_r3d_rs_type,&
admm_type,&
get_admm_env,&
set_admm_env
USE atomic_kind_types, ONLY: atomic_kind_type
USE basis_set_container_types, ONLY: add_basis_set_to_container
USE basis_set_types, ONLY: copy_gto_basis_set,&
get_gto_basis_set,&
gto_basis_set_type
USE cell_types, ONLY: cell_type,&
plane_distance
USE cp_blacs_env, ONLY: cp_blacs_env_type
USE cp_control_types, ONLY: admm_control_type,&
dft_control_type
USE cp_dbcsr_api, ONLY: dbcsr_add,&
dbcsr_copy,&
dbcsr_create,&
dbcsr_init_p,&
dbcsr_p_type,&
dbcsr_set,&
dbcsr_type,&
dbcsr_type_no_symmetry
USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_alloc_block_from_nbl
USE cp_dbcsr_operations, ONLY: cp_dbcsr_m_by_n_from_row_template,&
dbcsr_allocate_matrix_set
USE cp_fm_pool_types, ONLY: cp_fm_pool_p_type
USE cp_fm_struct, ONLY: cp_fm_struct_create,&
cp_fm_struct_release,&
cp_fm_struct_type
USE cp_fm_types, ONLY: cp_fm_create,&
cp_fm_get_info,&
cp_fm_type
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_get_default_io_unit,&
cp_logger_type,&
cp_to_string
USE distribution_1d_types, ONLY: distribution_1d_type
USE distribution_2d_types, ONLY: distribution_2d_type
USE external_potential_types, ONLY: copy_potential
USE hfx_derivatives, ONLY: derivatives_four_center
USE hfx_energy_potential, ONLY: integrate_four_center
USE hfx_pw_methods, ONLY: pw_hfx
USE hfx_ri, ONLY: hfx_ri_update_forces,&
hfx_ri_update_ks
USE hfx_ri_kp, ONLY: hfx_ri_update_forces_kp,&
hfx_ri_update_ks_kp
USE hfx_types, ONLY: hfx_type
USE input_constants, ONLY: &
do_admm_aux_exch_func_bee, do_admm_aux_exch_func_bee_libxc, do_admm_aux_exch_func_default, &
do_admm_aux_exch_func_default_libxc, do_admm_aux_exch_func_none, &
do_admm_aux_exch_func_opt, do_admm_aux_exch_func_opt_libxc, do_admm_aux_exch_func_pbex, &
do_admm_aux_exch_func_pbex_libxc, do_admm_aux_exch_func_sx_libxc, &
do_admm_basis_projection, do_admm_charge_constrained_projection, do_admm_purify_none, &
do_potential_coulomb, do_potential_id, do_potential_long, do_potential_mix_cl, &
do_potential_mix_cl_trunc, do_potential_short, do_potential_truncated, &
xc_funct_no_shortcut, xc_none
USE input_section_types, ONLY: section_vals_duplicate,&
section_vals_get,&
section_vals_get_subs_vals,&
section_vals_get_subs_vals2,&
section_vals_remove_values,&
section_vals_type,&
section_vals_val_get,&
section_vals_val_set
USE kinds, ONLY: dp
USE kpoint_methods, ONLY: kpoint_initialize_mos
USE kpoint_transitional, ONLY: kpoint_transitional_release,&
set_2d_pointer
USE kpoint_types, ONLY: get_kpoint_info,&
kpoint_type
USE libint_2c_3c, ONLY: cutoff_screen_factor
USE mathlib, ONLY: erfc_cutoff
USE message_passing, ONLY: mp_para_env_type
USE molecule_types, ONLY: molecule_type
USE particle_types, ONLY: particle_type
USE paw_proj_set_types, ONLY: get_paw_proj_set,&
paw_proj_set_type
USE pw_env_types, ONLY: pw_env_get,&
pw_env_type
USE pw_poisson_types, ONLY: pw_poisson_type
USE pw_pool_types, ONLY: pw_pool_type
USE pw_types, ONLY: pw_r3d_rs_type
USE qs_energy_types, ONLY: qs_energy_type
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type,&
set_qs_env
USE qs_interactions, ONLY: init_interaction_radii
USE qs_kind_types, ONLY: get_qs_kind,&
get_qs_kind_set,&
init_gapw_basis_set,&
init_gapw_nlcc,&
qs_kind_type
USE qs_ks_types, ONLY: qs_ks_env_type
USE qs_local_rho_types, ONLY: local_rho_set_create
USE qs_matrix_pools, ONLY: mpools_get
USE qs_mo_types, ONLY: allocate_mo_set,&
get_mo_set,&
init_mo_set,&
mo_set_type
USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type,&
release_neighbor_list_sets
USE qs_neighbor_lists, ONLY: atom2d_build,&
atom2d_cleanup,&
build_neighbor_lists,&
local_atoms_type,&
pair_radius_setup,&
write_neighbor_lists
USE qs_oce_methods, ONLY: build_oce_matrices
USE qs_oce_types, ONLY: allocate_oce_set,&
create_oce_set
USE qs_overlap, ONLY: build_overlap_matrix
USE qs_rho_atom_methods, ONLY: init_rho_atom
USE qs_rho_methods, ONLY: qs_rho_rebuild
USE qs_rho_types, ONLY: qs_rho_create,&
qs_rho_get,&
qs_rho_type
USE rt_propagation_types, ONLY: rt_prop_type
USE task_list_methods, ONLY: generate_qs_task_list
USE task_list_types, ONLY: allocate_task_list,&
deallocate_task_list
USE virial_types, ONLY: virial_type
USE xc_adiabatic_utils, ONLY: rescale_xc_potential
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
! *** Public subroutines ***
PUBLIC :: hfx_ks_matrix, hfx_admm_init, aux_admm_init, create_admm_xc_section, &
tddft_hfx_matrix, hfx_ks_matrix_kp
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'hfx_admm_utils'
CONTAINS
! **************************************************************************************************
!> \brief ...
!> \param qs_env ...
!> \param calculate_forces ...
! **************************************************************************************************
SUBROUTINE hfx_admm_init(qs_env, calculate_forces)
TYPE(qs_environment_type), POINTER :: qs_env
LOGICAL, INTENT(IN), OPTIONAL :: calculate_forces
CHARACTER(LEN=*), PARAMETER :: routineN = 'hfx_admm_init'
INTEGER :: handle, ispin, n_rep_hf, nao_aux_fit, &
natoms, nelectron, nmo
LOGICAL :: calc_forces, do_kpoints, &
s_mstruct_changed, use_virial
REAL(dp) :: maxocc
TYPE(admm_type), POINTER :: admm_env
TYPE(cp_blacs_env_type), POINTER :: blacs_env
TYPE(cp_fm_struct_type), POINTER :: aux_fit_fm_struct
TYPE(cp_fm_type), POINTER :: mo_coeff_aux_fit
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s_aux_fit_kp
TYPE(dbcsr_type), POINTER :: mo_coeff_b
TYPE(dft_control_type), POINTER :: dft_control
TYPE(mo_set_type), DIMENSION(:), POINTER :: mos, mos_aux_fit
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(qs_ks_env_type), POINTER :: ks_env
TYPE(section_vals_type), POINTER :: hfx_sections, input, xc_section
TYPE(virial_type), POINTER :: virial
CALL timeset(routineN, handle)
NULLIFY (admm_env, hfx_sections, mos, mos_aux_fit, para_env, virial, &
mo_coeff_aux_fit, xc_section, ks_env, dft_control, input, &
qs_kind_set, mo_coeff_b, aux_fit_fm_struct, blacs_env)
CALL get_qs_env(qs_env, &
mos=mos, &
admm_env=admm_env, &
para_env=para_env, &
blacs_env=blacs_env, &
s_mstruct_changed=s_mstruct_changed, &
ks_env=ks_env, &
dft_control=dft_control, &
input=input, &
virial=virial, &
do_kpoints=do_kpoints)
calc_forces = .FALSE.
IF (PRESENT(calculate_forces)) calc_forces = .TRUE.
hfx_sections => section_vals_get_subs_vals(input, "DFT%XC%HF")
CALL section_vals_get(hfx_sections, n_repetition=n_rep_hf)
IF (n_rep_hf > 1) &
CPABORT("ADMM can handle only one HF section.")
IF (.NOT. ASSOCIATED(admm_env)) THEN
! setup admm environment
CALL get_qs_env(qs_env, input=input, natom=natoms, qs_kind_set=qs_kind_set)
CALL get_qs_kind_set(qs_kind_set, nsgf=nao_aux_fit, basis_type="AUX_FIT")
CALL admm_env_create(admm_env, dft_control%admm_control, mos, para_env, natoms, nao_aux_fit)
CALL set_qs_env(qs_env, admm_env=admm_env)
xc_section => section_vals_get_subs_vals(input, "DFT%XC")
CALL create_admm_xc_section(x_data=qs_env%x_data, xc_section=xc_section, &
admm_env=admm_env)
! Initialize the GAPW data types
IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc) &
CALL init_admm_gapw(qs_env)
! ADMM neighbor lists and overlap matrices
CALL admm_init_hamiltonians(admm_env, qs_env, "AUX_FIT")
!The aux_fit task list and densities
ALLOCATE (admm_env%rho_aux_fit)
CALL qs_rho_create(admm_env%rho_aux_fit)
ALLOCATE (admm_env%rho_aux_fit_buffer)
CALL qs_rho_create(admm_env%rho_aux_fit_buffer)
CALL admm_update_s_mstruct(admm_env, qs_env, "AUX_FIT")
IF (admm_env%do_gapw) CALL update_admm_gapw(qs_env)
!The ADMM KS matrices
CALL admm_alloc_ks_matrices(admm_env, qs_env)
!The aux_fit MOs and derivatives
ALLOCATE (mos_aux_fit(dft_control%nspins))
DO ispin = 1, dft_control%nspins
CALL get_mo_set(mo_set=mos(ispin), nmo=nmo, nelectron=nelectron, maxocc=maxocc)
CALL allocate_mo_set(mo_set=mos_aux_fit(ispin), &
nao=nao_aux_fit, &
nmo=nmo, &
nelectron=nelectron, &
n_el_f=REAL(nelectron, dp), &
maxocc=maxocc, &
flexible_electron_count=dft_control%relax_multiplicity)
END DO
admm_env%mos_aux_fit => mos_aux_fit
DO ispin = 1, dft_control%nspins
CALL get_mo_set(mo_set=mos(ispin), nmo=nmo)
CALL cp_fm_struct_create(aux_fit_fm_struct, context=blacs_env, para_env=para_env, &
nrow_global=nao_aux_fit, ncol_global=nmo)
CALL get_mo_set(mos_aux_fit(ispin), mo_coeff=mo_coeff_aux_fit, mo_coeff_b=mo_coeff_b)
IF (.NOT. ASSOCIATED(mo_coeff_aux_fit)) THEN
CALL init_mo_set(mos_aux_fit(ispin), fm_struct=aux_fit_fm_struct, &
name="qs_env%mo_aux_fit"//TRIM(ADJUSTL(cp_to_string(ispin))))
END IF
CALL cp_fm_struct_release(aux_fit_fm_struct)
IF (.NOT. ASSOCIATED(mo_coeff_b)) THEN
CALL cp_fm_get_info(mos_aux_fit(ispin)%mo_coeff, ncol_global=nmo)
CALL dbcsr_init_p(mos_aux_fit(ispin)%mo_coeff_b)
CALL get_admm_env(admm_env, matrix_s_aux_fit_kp=matrix_s_aux_fit_kp)
CALL cp_dbcsr_m_by_n_from_row_template(mos_aux_fit(ispin)%mo_coeff_b, &
template=matrix_s_aux_fit_kp(1, 1)%matrix, &
n=nmo, sym=dbcsr_type_no_symmetry)
END IF
END DO
IF (qs_env%requires_mo_derivs) THEN
ALLOCATE (admm_env%mo_derivs_aux_fit(dft_control%nspins))
DO ispin = 1, dft_control%nspins
CALL get_mo_set(admm_env%mos_aux_fit(ispin), mo_coeff=mo_coeff_aux_fit)
CALL cp_fm_create(admm_env%mo_derivs_aux_fit(ispin), mo_coeff_aux_fit%matrix_struct)
END DO
END IF
IF (do_kpoints) THEN
BLOCK
TYPE(kpoint_type), POINTER :: kpoints
TYPE(mo_set_type), DIMENSION(:, :), POINTER :: mos_aux_fit_kp
TYPE(cp_fm_pool_p_type), DIMENSION(:), POINTER :: ao_mo_fm_pools_aux_fit
TYPE(cp_fm_struct_type), POINTER :: ao_ao_fm_struct
INTEGER :: ic, ik, ikk, is
INTEGER, PARAMETER :: nwork1 = 4
LOGICAL :: use_real_wfn
NULLIFY (ao_mo_fm_pools_aux_fit, mos_aux_fit_kp)
CALL get_qs_env(qs_env=qs_env, kpoints=kpoints)
CALL get_kpoint_info(kpoints, use_real_wfn=use_real_wfn)
!Test combinations of input values. So far, only ADMM2 is availavle
IF (.NOT. admm_env%purification_method == do_admm_purify_none) &
CPABORT("Only ADMM_PURIFICATION_METHOD NONE implemeted for ADMM K-points")
IF (.NOT. (dft_control%admm_control%method == do_admm_basis_projection &
.OR. dft_control%admm_control%method == do_admm_charge_constrained_projection)) &
CPABORT("Only BASIS_PROJECTION and CHARGE_CONSTRAINED_PROJECTION implemented for KP")
IF (admm_env%do_admms .OR. admm_env%do_admmp .OR. admm_env%do_admmq) THEN
IF (use_real_wfn) CPABORT("Only KP-HFX ADMM2 is implemented with REAL wavefunctions")
END IF
CALL kpoint_initialize_mos(kpoints, admm_env%mos_aux_fit, for_aux_fit=.TRUE.)
CALL mpools_get(kpoints%mpools_aux_fit, ao_mo_fm_pools=ao_mo_fm_pools_aux_fit)
DO ik = 1, SIZE(kpoints%kp_aux_env)
mos_aux_fit_kp => kpoints%kp_aux_env(ik)%kpoint_env%mos
ikk = kpoints%kp_range(1) + ik - 1
DO ispin = 1, SIZE(mos_aux_fit_kp, 2)
DO ic = 1, SIZE(mos_aux_fit_kp, 1)
CALL get_mo_set(mos_aux_fit_kp(ic, ispin), mo_coeff=mo_coeff_aux_fit, mo_coeff_b=mo_coeff_b)
! no sparse matrix representation of kpoint MO vectors
CPASSERT(.NOT. ASSOCIATED(mo_coeff_b))
IF (.NOT. ASSOCIATED(mo_coeff_aux_fit)) THEN
CALL init_mo_set(mos_aux_fit_kp(ic, ispin), &
fm_pool=ao_mo_fm_pools_aux_fit(ispin)%pool, &
name="kpoints_"//TRIM(ADJUSTL(cp_to_string(ikk)))// &
"%mo_aux_fit"//TRIM(ADJUSTL(cp_to_string(ispin))))
END IF
END DO
END DO
END DO
ALLOCATE (admm_env%scf_work_aux_fit(nwork1))
! create an ao_ao parallel matrix structure
CALL cp_fm_struct_create(ao_ao_fm_struct, context=blacs_env, para_env=para_env, &
nrow_global=nao_aux_fit, &
ncol_global=nao_aux_fit)
DO is = 1, nwork1
CALL cp_fm_create(admm_env%scf_work_aux_fit(is), &
matrix_struct=ao_ao_fm_struct, &
name="SCF-WORK_MATRIX-AUX-"//TRIM(ADJUSTL(cp_to_string(is))))
END DO
CALL cp_fm_struct_release(ao_ao_fm_struct)
! Create and populate the internal ADMM overlap matrices at each KP
CALL kpoint_calc_admm_matrices(qs_env, calc_forces)
END BLOCK
END IF
ELSE IF (s_mstruct_changed) THEN
CALL admm_init_hamiltonians(admm_env, qs_env, "AUX_FIT")
CALL admm_update_s_mstruct(admm_env, qs_env, "AUX_FIT")
CALL admm_alloc_ks_matrices(admm_env, qs_env)
IF (admm_env%do_gapw) CALL update_admm_gapw(qs_env)
IF (do_kpoints) CALL kpoint_calc_admm_matrices(qs_env, calc_forces)
END IF
IF (admm_env%do_gapw .AND. dft_control%do_admm_dm) THEN
CPABORT("GAPW ADMM not implemented for MCWEENY or NONE_DM purification.")
END IF
!ADMMS and ADMMP stress tensors only available for close-shell systesms, because virial cannot
!be scaled by gsi spin component wise
use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
IF (use_virial .AND. admm_env%do_admms .AND. dft_control%nspins == 2) THEN
CPABORT("ADMMS stress tensor is only available for closed-shell systems")
END IF
IF (use_virial .AND. admm_env%do_admmp .AND. dft_control%nspins == 2) THEN
CPABORT("ADMMP stress tensor is only available for closed-shell systems")
END IF
IF (dft_control%do_admm_dm .AND. .NOT. ASSOCIATED(admm_env%admm_dm)) THEN
CALL admm_dm_create(admm_env%admm_dm, dft_control%admm_control, nspins=dft_control%nspins, natoms=natoms)
END IF
CALL timestop(handle)
END SUBROUTINE hfx_admm_init
! **************************************************************************************************
!> \brief Minimal setup routine for admm_env
!> No forces
!> No k-points
!> No DFT correction terms
!> \param qs_env ...
!> \param mos ...
!> \param admm_env ...
!> \param admm_control ...
!> \param basis_type ...
! **************************************************************************************************
SUBROUTINE aux_admm_init(qs_env, mos, admm_env, admm_control, basis_type)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
TYPE(admm_type), POINTER :: admm_env
TYPE(admm_control_type), POINTER :: admm_control
CHARACTER(LEN=*) :: basis_type
CHARACTER(LEN=*), PARAMETER :: routineN = 'aux_admm_init'
INTEGER :: handle, ispin, nao_aux_fit, natoms, &
nelectron, nmo
LOGICAL :: do_kpoints
REAL(dp) :: maxocc
TYPE(cp_blacs_env_type), POINTER :: blacs_env
TYPE(cp_fm_struct_type), POINTER :: aux_fit_fm_struct
TYPE(cp_fm_type), POINTER :: mo_coeff_aux_fit
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s_aux_fit_kp
TYPE(dbcsr_type), POINTER :: mo_coeff_b
TYPE(dft_control_type), POINTER :: dft_control
TYPE(mo_set_type), DIMENSION(:), POINTER :: mos_aux_fit
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(qs_ks_env_type), POINTER :: ks_env
CALL timeset(routineN, handle)
CPASSERT(.NOT. ASSOCIATED(admm_env))
CALL get_qs_env(qs_env, &
para_env=para_env, &
blacs_env=blacs_env, &
ks_env=ks_env, &
dft_control=dft_control, &
do_kpoints=do_kpoints)
CPASSERT(.NOT. do_kpoints)
IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc) THEN
CPABORT("AUX ADMM not possible with GAPW")
END IF
! setup admm environment
CALL get_qs_env(qs_env, natom=natoms, qs_kind_set=qs_kind_set)
CALL get_qs_kind_set(qs_kind_set, nsgf=nao_aux_fit, basis_type=basis_type)
!
CALL admm_env_create(admm_env, admm_control, mos, para_env, natoms, nao_aux_fit)
! no XC correction used
NULLIFY (admm_env%xc_section_aux, admm_env%xc_section_primary)
! ADMM neighbor lists and overlap matrices
CALL admm_init_hamiltonians(admm_env, qs_env, basis_type)
NULLIFY (admm_env%rho_aux_fit, admm_env%rho_aux_fit_buffer)
!The ADMM KS matrices
CALL admm_alloc_ks_matrices(admm_env, qs_env)
!The aux_fit MOs and derivatives
ALLOCATE (mos_aux_fit(dft_control%nspins))
DO ispin = 1, dft_control%nspins
CALL get_mo_set(mo_set=mos(ispin), nmo=nmo, nelectron=nelectron, maxocc=maxocc)
CALL allocate_mo_set(mo_set=mos_aux_fit(ispin), nao=nao_aux_fit, nmo=nmo, &
nelectron=nelectron, n_el_f=REAL(nelectron, dp), &
maxocc=maxocc, flexible_electron_count=0.0_dp)
END DO
admm_env%mos_aux_fit => mos_aux_fit
DO ispin = 1, dft_control%nspins
CALL get_mo_set(mo_set=mos(ispin), nmo=nmo)
CALL cp_fm_struct_create(aux_fit_fm_struct, context=blacs_env, para_env=para_env, &
nrow_global=nao_aux_fit, ncol_global=nmo)
CALL get_mo_set(mos_aux_fit(ispin), mo_coeff=mo_coeff_aux_fit, mo_coeff_b=mo_coeff_b)
IF (.NOT. ASSOCIATED(mo_coeff_aux_fit)) THEN
CALL init_mo_set(mos_aux_fit(ispin), fm_struct=aux_fit_fm_struct, &
name="mo_aux_fit"//TRIM(ADJUSTL(cp_to_string(ispin))))
END IF
CALL cp_fm_struct_release(aux_fit_fm_struct)
IF (.NOT. ASSOCIATED(mo_coeff_b)) THEN
CALL cp_fm_get_info(mos_aux_fit(ispin)%mo_coeff, ncol_global=nmo)
CALL dbcsr_init_p(mos_aux_fit(ispin)%mo_coeff_b)
CALL get_admm_env(admm_env, matrix_s_aux_fit_kp=matrix_s_aux_fit_kp)
CALL cp_dbcsr_m_by_n_from_row_template(mos_aux_fit(ispin)%mo_coeff_b, &
template=matrix_s_aux_fit_kp(1, 1)%matrix, &
n=nmo, sym=dbcsr_type_no_symmetry)
END IF
END DO
CALL timestop(handle)
END SUBROUTINE aux_admm_init
! **************************************************************************************************
!> \brief Sets up the admm_gapw env
!> \param qs_env ...
! **************************************************************************************************
SUBROUTINE init_admm_gapw(qs_env)
TYPE(qs_environment_type), POINTER :: qs_env
INTEGER :: ikind, nkind
TYPE(admm_gapw_r3d_rs_type), POINTER :: admm_gapw_env
TYPE(admm_type), POINTER :: admm_env
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(dft_control_type), POINTER :: dft_control
TYPE(gto_basis_set_type), POINTER :: aux_fit_basis, aux_fit_soft_basis, &
orb_basis, soft_basis
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(qs_kind_type), DIMENSION(:), POINTER :: admm_kind_set, qs_kind_set
TYPE(section_vals_type), POINTER :: input
NULLIFY (admm_kind_set, aux_fit_basis, atomic_kind_set, aux_fit_soft_basis, &
dft_control, input, orb_basis, para_env, qs_kind_set, soft_basis)
CALL get_qs_env(qs_env, admm_env=admm_env, &
atomic_kind_set=atomic_kind_set, &
dft_control=dft_control, &
input=input, &
para_env=para_env, &
qs_kind_set=qs_kind_set)
admm_env%do_gapw = .TRUE.
ALLOCATE (admm_env%admm_gapw_env)
admm_gapw_env => admm_env%admm_gapw_env
NULLIFY (admm_gapw_env%local_rho_set)
NULLIFY (admm_gapw_env%admm_kind_set)
NULLIFY (admm_gapw_env%task_list)
!Create a new kind set for the ADMM stuff (paw_proj soft AUX_FIT basis, etc)
nkind = SIZE(qs_kind_set)
ALLOCATE (admm_gapw_env%admm_kind_set(nkind))
admm_kind_set => admm_gapw_env%admm_kind_set
!In this new kind set, we want the AUX_FIT basis to be known as ORB, such that GAPW routines work
DO ikind = 1, nkind
!copying over simple data of interest from qs_kind_set
admm_kind_set(ikind)%name = qs_kind_set(ikind)%name
admm_kind_set(ikind)%element_symbol = qs_kind_set(ikind)%element_symbol
admm_kind_set(ikind)%natom = qs_kind_set(ikind)%natom
admm_kind_set(ikind)%hard_radius = qs_kind_set(ikind)%hard_radius
admm_kind_set(ikind)%max_rad_local = qs_kind_set(ikind)%max_rad_local
admm_kind_set(ikind)%gpw_type_forced = qs_kind_set(ikind)%gpw_type_forced
admm_kind_set(ikind)%ngrid_rad = qs_kind_set(ikind)%ngrid_rad
admm_kind_set(ikind)%ngrid_ang = qs_kind_set(ikind)%ngrid_ang
!copying potentials of interest from qs_kind_set
IF (ASSOCIATED(qs_kind_set(ikind)%all_potential)) THEN
CALL copy_potential(qs_kind_set(ikind)%all_potential, admm_kind_set(ikind)%all_potential)
END IF
IF (ASSOCIATED(qs_kind_set(ikind)%gth_potential)) THEN
CALL copy_potential(qs_kind_set(ikind)%gth_potential, admm_kind_set(ikind)%gth_potential)
END IF
IF (ASSOCIATED(qs_kind_set(ikind)%sgp_potential)) THEN
CALL copy_potential(qs_kind_set(ikind)%sgp_potential, admm_kind_set(ikind)%sgp_potential)
END IF
NULLIFY (orb_basis)
CALL get_qs_kind(qs_kind_set(ikind), basis_set=aux_fit_basis, basis_type="AUX_FIT")
CALL copy_gto_basis_set(aux_fit_basis, orb_basis)
CALL add_basis_set_to_container(admm_kind_set(ikind)%basis_sets, orb_basis, "ORB")
END DO
!Create the corresponding soft basis set (and projectors)
CALL init_gapw_basis_set(admm_kind_set, dft_control%qs_control, input, &
modify_qs_control=.FALSE.)
!Make sure the basis and the projectors are well initialized
CALL init_interaction_radii(dft_control%qs_control, admm_kind_set)
!We also init the atomic grids and harmonics
CALL local_rho_set_create(admm_gapw_env%local_rho_set)
CALL init_rho_atom(admm_gapw_env%local_rho_set%rho_atom_set, &
atomic_kind_set, admm_kind_set, dft_control, para_env)
!Make sure that any NLCC potential is well initialized
CALL init_gapw_nlcc(admm_kind_set)
!Need to have access to the soft AUX_FIT basis from the qs_env => add it to the qs_kinds
DO ikind = 1, nkind
NULLIFY (aux_fit_soft_basis)
CALL get_qs_kind(admm_kind_set(ikind), basis_set=soft_basis, basis_type="ORB_SOFT")
CALL copy_gto_basis_set(soft_basis, aux_fit_soft_basis)
CALL add_basis_set_to_container(qs_kind_set(ikind)%basis_sets, aux_fit_soft_basis, "AUX_FIT_SOFT")
END DO
END SUBROUTINE init_admm_gapw
! **************************************************************************************************
!> \brief Builds the ADMM nmeighbor lists and overlap matrix on the model of qs_energies_init_hamiltonians()
!> \param admm_env ...
!> \param qs_env ...
!> \param aux_basis_type ...
! **************************************************************************************************
SUBROUTINE admm_init_hamiltonians(admm_env, qs_env, aux_basis_type)
TYPE(admm_type), POINTER :: admm_env
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(len=*) :: aux_basis_type
CHARACTER(len=*), PARAMETER :: routineN = 'admm_init_hamiltonians'
INTEGER :: handle, hfx_pot, ikind, nkind
LOGICAL :: do_kpoints, mic, molecule_only
LOGICAL, ALLOCATABLE, DIMENSION(:) :: aux_fit_present, orb_present
REAL(dp) :: eps_schwarz, omega, pdist, roperator, &
subcells
REAL(dp), ALLOCATABLE, DIMENSION(:) :: aux_fit_radius, orb_radius
REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: pair_radius
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: cell
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s_aux_fit_kp, &
matrix_s_aux_fit_vs_orb_kp
TYPE(dft_control_type), POINTER :: dft_control
TYPE(distribution_1d_type), POINTER :: distribution_1d
TYPE(distribution_2d_type), POINTER :: distribution_2d
TYPE(gto_basis_set_type), POINTER :: aux_fit_basis_set, orb_basis_set
TYPE(kpoint_type), POINTER :: kpoints
TYPE(local_atoms_type), ALLOCATABLE, DIMENSION(:) :: atom2d
TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
TYPE(mp_para_env_type), POINTER :: para_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(section_vals_type), POINTER :: hfx_sections, neighbor_list_section
NULLIFY (particle_set, cell, kpoints, distribution_1d, distribution_2d, molecule_set, &
atomic_kind_set, dft_control, neighbor_list_section, aux_fit_basis_set, orb_basis_set, &
ks_env, para_env, qs_kind_set, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb_kp)
CALL timeset(routineN, handle)
CALL get_qs_env(qs_env, nkind=nkind, particle_set=particle_set, cell=cell, kpoints=kpoints, &
local_particles=distribution_1d, distribution_2d=distribution_2d, &
molecule_set=molecule_set, atomic_kind_set=atomic_kind_set, do_kpoints=do_kpoints, &
dft_control=dft_control, para_env=para_env, qs_kind_set=qs_kind_set)
ALLOCATE (orb_present(nkind), aux_fit_present(nkind))
ALLOCATE (orb_radius(nkind), aux_fit_radius(nkind), pair_radius(nkind, nkind))
aux_fit_radius(:) = 0.0_dp
molecule_only = .FALSE.
IF (dft_control%qs_control%do_kg) molecule_only = .TRUE.
mic = molecule_only
IF (kpoints%nkp > 0) THEN
mic = .FALSE.
ELSEIF (dft_control%qs_control%semi_empirical) THEN
mic = .TRUE.
END IF
pdist = dft_control%qs_control%pairlist_radius
CALL section_vals_val_get(qs_env%input, "DFT%SUBCELLS", r_val=subcells)
neighbor_list_section => section_vals_get_subs_vals(qs_env%input, "DFT%PRINT%NEIGHBOR_LISTS")
ALLOCATE (atom2d(nkind))
CALL atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, &
molecule_set, molecule_only, particle_set=particle_set)
DO ikind = 1, nkind
CALL get_qs_kind(qs_kind_set(ikind), basis_set=orb_basis_set, basis_type="ORB")
IF (ASSOCIATED(orb_basis_set)) THEN
orb_present(ikind) = .TRUE.
CALL get_gto_basis_set(gto_basis_set=orb_basis_set, kind_radius=orb_radius(ikind))
ELSE
orb_present(ikind) = .FALSE.
END IF
CALL get_qs_kind(qs_kind_set(ikind), basis_set=aux_fit_basis_set, basis_type=aux_basis_type)
IF (ASSOCIATED(aux_fit_basis_set)) THEN
aux_fit_present(ikind) = .TRUE.
CALL get_gto_basis_set(gto_basis_set=aux_fit_basis_set, kind_radius=aux_fit_radius(ikind))
ELSE
aux_fit_present(ikind) = .FALSE.
END IF
END DO
IF (pdist < 0.0_dp) THEN
pdist = MAX(plane_distance(1, 0, 0, cell), &
plane_distance(0, 1, 0, cell), &
plane_distance(0, 0, 1, cell))
END IF
!In case of K-points, we need to add the HFX potential range to sab_aux_fit, because it is used
!to populate AUX density and KS matrices
roperator = 0.0_dp
IF (do_kpoints) THEN
hfx_sections => section_vals_get_subs_vals(qs_env%input, "DFT%XC%HF")
CALL section_vals_val_get(hfx_sections, "INTERACTION_POTENTIAL%POTENTIAL_TYPE", i_val=hfx_pot)
SELECT CASE (hfx_pot)
CASE (do_potential_id)
roperator = 0.0_dp
CASE (do_potential_truncated)
CALL section_vals_val_get(hfx_sections, "INTERACTION_POTENTIAL%CUTOFF_RADIUS", r_val=roperator)
CASE (do_potential_short)
CALL section_vals_val_get(hfx_sections, "INTERACTION_POTENTIAL%OMEGA", r_val=omega)
CALL section_vals_val_get(hfx_sections, "SCREENING%EPS_SCHWARZ", r_val=eps_schwarz)
CALL erfc_cutoff(eps_schwarz, omega, roperator)
CASE DEFAULT
CPABORT("HFX potential not available for K-points (NYI)")
END SELECT
END IF
CALL pair_radius_setup(aux_fit_present, aux_fit_present, aux_fit_radius, aux_fit_radius, pair_radius, pdist)
pair_radius = pair_radius + cutoff_screen_factor*roperator
CALL build_neighbor_lists(admm_env%sab_aux_fit, particle_set, atom2d, cell, pair_radius, &
mic=mic, molecular=molecule_only, subcells=subcells, nlname="sab_aux_fit")
CALL build_neighbor_lists(admm_env%sab_aux_fit_asymm, particle_set, atom2d, cell, pair_radius, &
mic=mic, symmetric=.FALSE., molecular=molecule_only, subcells=subcells, &
nlname="sab_aux_fit_asymm")
CALL pair_radius_setup(aux_fit_present, orb_present, aux_fit_radius, orb_radius, pair_radius)
CALL build_neighbor_lists(admm_env%sab_aux_fit_vs_orb, particle_set, atom2d, cell, pair_radius, &
mic=mic, symmetric=.FALSE., molecular=molecule_only, subcells=subcells, &
nlname="sab_aux_fit_vs_orb")
CALL write_neighbor_lists(admm_env%sab_aux_fit, particle_set, cell, para_env, neighbor_list_section, &
"/SAB_AUX_FIT", "sab_aux_fit", "AUX_FIT_ORBITAL AUX_FIT_ORBITAL")
CALL write_neighbor_lists(admm_env%sab_aux_fit_vs_orb, particle_set, cell, para_env, neighbor_list_section, &
"/SAB_AUX_FIT_VS_ORB", "sab_aux_fit_vs_orb", "ORBITAL AUX_FIT_ORBITAL")
CALL atom2d_cleanup(atom2d)
!The ADMM overlap matrices (initially in qs_core_hamiltonian.F)
CALL get_qs_env(qs_env, ks_env=ks_env)
CALL kpoint_transitional_release(admm_env%matrix_s_aux_fit)
CALL build_overlap_matrix(ks_env, matrixkp_s=matrix_s_aux_fit_kp, &
matrix_name="AUX_FIT_OVERLAP", &
basis_type_a=aux_basis_type, &
basis_type_b=aux_basis_type, &
sab_nl=admm_env%sab_aux_fit)
CALL set_2d_pointer(admm_env%matrix_s_aux_fit, matrix_s_aux_fit_kp)
CALL kpoint_transitional_release(admm_env%matrix_s_aux_fit_vs_orb)
CALL build_overlap_matrix(ks_env, matrixkp_s=matrix_s_aux_fit_vs_orb_kp, &
matrix_name="MIXED_OVERLAP", &
basis_type_a=aux_basis_type, &
basis_type_b="ORB", &
sab_nl=admm_env%sab_aux_fit_vs_orb)
CALL set_2d_pointer(admm_env%matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp)
CALL timestop(handle)
END SUBROUTINE admm_init_hamiltonians
! **************************************************************************************************
!> \brief Updates the ADMM task_list and density based on the model of qs_env_update_s_mstruct()
!> \param admm_env ...
!> \param qs_env ...
!> \param aux_basis_type ...
! **************************************************************************************************
SUBROUTINE admm_update_s_mstruct(admm_env, qs_env, aux_basis_type)
TYPE(admm_type), POINTER :: admm_env
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(len=*) :: aux_basis_type
CHARACTER(len=*), PARAMETER :: routineN = 'admm_update_s_mstruct'
INTEGER :: handle
LOGICAL :: skip_load_balance_distributed
TYPE(dft_control_type), POINTER :: dft_control
TYPE(qs_ks_env_type), POINTER :: ks_env
NULLIFY (ks_env, dft_control)
CALL timeset(routineN, handle)
CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
!The aux_fit task_list
skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
IF (ASSOCIATED(admm_env%task_list_aux_fit)) CALL deallocate_task_list(admm_env%task_list_aux_fit)
CALL allocate_task_list(admm_env%task_list_aux_fit)
CALL generate_qs_task_list(ks_env, admm_env%task_list_aux_fit, &
reorder_rs_grid_ranks=.FALSE., soft_valid=.FALSE., &
basis_type=aux_basis_type, &
skip_load_balance_distributed=skip_load_balance_distributed, &
sab_orb_external=admm_env%sab_aux_fit)
!The aux_fit densities
CALL qs_rho_rebuild(admm_env%rho_aux_fit, qs_env=qs_env, admm=.TRUE.)
CALL qs_rho_rebuild(admm_env%rho_aux_fit_buffer, qs_env=qs_env, admm=.TRUE.)
CALL timestop(handle)
END SUBROUTINE admm_update_s_mstruct
! **************************************************************************************************
!> \brief Update the admm_gapw_env internals to the current qs_env (i.e. atomic positions)
!> \param qs_env ...
! **************************************************************************************************
SUBROUTINE update_admm_gapw(qs_env)
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(len=*), PARAMETER :: routineN = 'update_admm_gapw'
INTEGER :: handle, ikind, nkind
LOGICAL :: paw_atom
LOGICAL, ALLOCATABLE, DIMENSION(:) :: aux_present, oce_present
REAL(dp) :: subcells
REAL(dp), ALLOCATABLE, DIMENSION(:) :: aux_radius, oce_radius
REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: pair_radius
TYPE(admm_gapw_r3d_rs_type), POINTER :: admm_gapw_env
TYPE(admm_type), POINTER :: admm_env
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: cell
TYPE(dft_control_type), POINTER :: dft_control
TYPE(distribution_1d_type), POINTER :: distribution_1d
TYPE(distribution_2d_type), POINTER :: distribution_2d
TYPE(gto_basis_set_type), POINTER :: aux_fit_basis
TYPE(local_atoms_type), ALLOCATABLE, DIMENSION(:) :: atom2d
TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
TYPE(neighbor_list_set_p_type), DIMENSION(:), &
POINTER :: sap_oce
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(paw_proj_set_type), POINTER :: paw_proj
TYPE(qs_kind_type), DIMENSION(:), POINTER :: admm_kind_set, qs_kind_set
TYPE(qs_ks_env_type), POINTER :: ks_env
NULLIFY (ks_env, qs_kind_set, admm_kind_set, aux_fit_basis, cell, distribution_1d)
NULLIFY (distribution_2d, paw_proj, particle_set, molecule_set, admm_env, admm_gapw_env)
NULLIFY (dft_control, atomic_kind_set, sap_oce)
CALL timeset(routineN, handle)
CALL get_qs_env(qs_env, ks_env=ks_env, qs_kind_set=qs_kind_set, admm_env=admm_env, &
dft_control=dft_control)
admm_gapw_env => admm_env%admm_gapw_env
admm_kind_set => admm_gapw_env%admm_kind_set
nkind = SIZE(qs_kind_set)
!Update the task lisft for the AUX_FIT_SOFT basis
IF (ASSOCIATED(admm_gapw_env%task_list)) CALL deallocate_task_list(admm_gapw_env%task_list)
CALL allocate_task_list(admm_gapw_env%task_list)
!note: we set soft_valid to .FALSE. want to use AUX_FIT_SOFT and not the normal ORB SOFT basis
CALL generate_qs_task_list(ks_env, admm_gapw_env%task_list, reorder_rs_grid_ranks=.FALSE., &
soft_valid=.FALSE., basis_type="AUX_FIT_SOFT", &
skip_load_balance_distributed=dft_control%qs_control%skip_load_balance_distributed, &
sab_orb_external=admm_env%sab_aux_fit)
!Update the precomputed oce integrals
!a sap_oce neighbor list is required => build it here
ALLOCATE (aux_present(nkind), oce_present(nkind))
aux_present = .FALSE.; oce_present = .FALSE.
ALLOCATE (aux_radius(nkind), oce_radius(nkind))
aux_radius = 0.0_dp; oce_radius = 0.0_dp
DO ikind = 1, nkind
CALL get_qs_kind(qs_kind_set(ikind), basis_set=aux_fit_basis, basis_type="AUX_FIT")
IF (ASSOCIATED(aux_fit_basis)) THEN
aux_present(ikind) = .TRUE.
CALL get_gto_basis_set(aux_fit_basis, kind_radius=aux_radius(ikind))
END IF
!note: get oce info from admm_kind_set
CALL get_qs_kind(admm_kind_set(ikind), paw_atom=paw_atom, paw_proj_set=paw_proj)
IF (paw_atom) THEN
oce_present(ikind) = .TRUE.
CALL get_paw_proj_set(paw_proj, rcprj=oce_radius(ikind))
END IF
END DO
ALLOCATE (pair_radius(nkind, nkind))
pair_radius = 0.0_dp
CALL pair_radius_setup(aux_present, oce_present, aux_radius, oce_radius, pair_radius)
CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, cell=cell, &
distribution_2d=distribution_2d, local_particles=distribution_1d, &
particle_set=particle_set, molecule_set=molecule_set)
CALL section_vals_val_get(qs_env%input, "DFT%SUBCELLS", r_val=subcells)
ALLOCATE (atom2d(nkind))
CALL atom2d_build(atom2d, distribution_1d, distribution_2d, atomic_kind_set, &
molecule_set, .FALSE., particle_set)
CALL build_neighbor_lists(sap_oce, particle_set, atom2d, cell, pair_radius, &
subcells=subcells, operator_type="ABBA", nlname="AUX_PAW-PRJ")
CALL atom2d_cleanup(atom2d)
!actually compute the oce matrices
CALL create_oce_set(admm_gapw_env%oce)
CALL allocate_oce_set(admm_gapw_env%oce, nkind)
!always compute the derivative, cheap anyways
CALL build_oce_matrices(admm_gapw_env%oce%intac, calculate_forces=.TRUE., nder=1, &
qs_kind_set=admm_kind_set, particle_set=particle_set, &
sap_oce=sap_oce, eps_fit=dft_control%qs_control%gapw_control%eps_fit)
CALL release_neighbor_list_sets(sap_oce)
CALL timestop(handle)
END SUBROUTINE update_admm_gapw
! **************************************************************************************************
!> \brief Allocates the various ADMM KS matrices
!> \param admm_env ...
!> \param qs_env ...
! **************************************************************************************************
SUBROUTINE admm_alloc_ks_matrices(admm_env, qs_env)
TYPE(admm_type), POINTER :: admm_env
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(len=*), PARAMETER :: routineN = 'admm_alloc_ks_matrices'
INTEGER :: handle, ic, ispin
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks_aux_fit_dft_kp, &
matrix_ks_aux_fit_hfx_kp, &
matrix_ks_aux_fit_kp, &
matrix_s_aux_fit_kp
TYPE(dft_control_type), POINTER :: dft_control
NULLIFY (dft_control, matrix_s_aux_fit_kp, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp)
CALL timeset(routineN, handle)
CALL get_qs_env(qs_env, dft_control=dft_control)
CALL get_admm_env(admm_env, matrix_s_aux_fit_kp=matrix_s_aux_fit_kp)
CALL kpoint_transitional_release(admm_env%matrix_ks_aux_fit)
CALL kpoint_transitional_release(admm_env%matrix_ks_aux_fit_dft)
CALL kpoint_transitional_release(admm_env%matrix_ks_aux_fit_hfx)
CALL dbcsr_allocate_matrix_set(matrix_ks_aux_fit_kp, dft_control%nspins, dft_control%nimages)
CALL dbcsr_allocate_matrix_set(matrix_ks_aux_fit_dft_kp, dft_control%nspins, dft_control%nimages)
CALL dbcsr_allocate_matrix_set(matrix_ks_aux_fit_hfx_kp, dft_control%nspins, dft_control%nimages)
DO ispin = 1, dft_control%nspins
DO ic = 1, dft_control%nimages
ALLOCATE (matrix_ks_aux_fit_kp(ispin, ic)%matrix)
CALL dbcsr_create(matrix_ks_aux_fit_kp(ispin, ic)%matrix, template=matrix_s_aux_fit_kp(1, ic)%matrix, &
name="KOHN-SHAM_MATRIX for ADMM")
CALL cp_dbcsr_alloc_block_from_nbl(matrix_ks_aux_fit_kp(ispin, ic)%matrix, admm_env%sab_aux_fit)
CALL dbcsr_set(matrix_ks_aux_fit_kp(ispin, ic)%matrix, 0.0_dp)
ALLOCATE (matrix_ks_aux_fit_dft_kp(ispin, ic)%matrix)
CALL dbcsr_create(matrix_ks_aux_fit_dft_kp(ispin, ic)%matrix, template=matrix_s_aux_fit_kp(1, 1)%matrix, &
name="KOHN-SHAM_MATRIX for ADMM")
CALL cp_dbcsr_alloc_block_from_nbl(matrix_ks_aux_fit_dft_kp(ispin, ic)%matrix, admm_env%sab_aux_fit)
CALL dbcsr_set(matrix_ks_aux_fit_dft_kp(ispin, ic)%matrix, 0.0_dp)
ALLOCATE (matrix_ks_aux_fit_hfx_kp(ispin, ic)%matrix)
CALL dbcsr_create(matrix_ks_aux_fit_hfx_kp(ispin, ic)%matrix, template=matrix_s_aux_fit_kp(1, 1)%matrix, &
name="KOHN-SHAM_MATRIX for ADMM")
CALL cp_dbcsr_alloc_block_from_nbl(matrix_ks_aux_fit_hfx_kp(ispin, ic)%matrix, admm_env%sab_aux_fit)
CALL dbcsr_set(matrix_ks_aux_fit_hfx_kp(ispin, ic)%matrix, 0.0_dp)
END DO
END DO
CALL set_admm_env(admm_env, &
matrix_ks_aux_fit_kp=matrix_ks_aux_fit_kp, &
matrix_ks_aux_fit_dft_kp=matrix_ks_aux_fit_dft_kp, &
matrix_ks_aux_fit_hfx_kp=matrix_ks_aux_fit_hfx_kp)
CALL timestop(handle)
END SUBROUTINE admm_alloc_ks_matrices
! **************************************************************************************************
!> \brief Add the HFX K-point contribution to the real-space Hamiltonians
!> \param qs_env ...
!> \param matrix_ks ...
!> \param energy ...
!> \param calculate_forces ...
! **************************************************************************************************
SUBROUTINE hfx_ks_matrix_kp(qs_env, matrix_ks, energy, calculate_forces)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks
TYPE(qs_energy_type), POINTER :: energy
LOGICAL, INTENT(in) :: calculate_forces
CHARACTER(LEN=*), PARAMETER :: routineN = 'hfx_ks_matrix_kp'
INTEGER :: handle, img, irep, ispin, n_rep_hf, &
nimages, nspins
LOGICAL :: do_adiabatic_rescaling, &
s_mstruct_changed, use_virial
REAL(dp) :: eh1, ehfx, eold
REAL(dp), ALLOCATABLE, DIMENSION(:) :: hf_energy
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks_aux_fit_im, matrix_ks_im
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrix_ks_aux_fit_hfx_kp, &
matrix_ks_aux_fit_kp, matrix_ks_orb, &
rho_ao_orb
TYPE(dft_control_type), POINTER :: dft_control
TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(pw_env_type), POINTER :: pw_env
TYPE(pw_poisson_type), POINTER :: poisson_env
TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
TYPE(qs_rho_type), POINTER :: rho_orb
TYPE(section_vals_type), POINTER :: adiabatic_rescaling_section, &
hfx_sections, input
TYPE(virial_type), POINTER :: virial
CALL timeset(routineN, handle)
NULLIFY (auxbas_pw_pool, dft_control, hfx_sections, input, &
para_env, poisson_env, pw_env, virial, matrix_ks_im, &
matrix_ks_orb, rho_ao_orb, matrix_h, matrix_ks_aux_fit_kp, &
matrix_ks_aux_fit_im, matrix_ks_aux_fit_hfx_kp)
CALL get_qs_env(qs_env=qs_env, &
dft_control=dft_control, &
input=input, &
matrix_h_kp=matrix_h, &
para_env=para_env, &
pw_env=pw_env, &
virial=virial, &