-
Notifications
You must be signed in to change notification settings - Fork 1
/
qs_scf_diagonalization.F
1778 lines (1539 loc) · 80 KB
/
qs_scf_diagonalization.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 Different diagonalization schemes that can be used
!> for the iterative solution of the eigenvalue problem
!> \par History
!> started from routines previously located in the qs_scf module
!> 05.2009
! **************************************************************************************************
MODULE qs_scf_diagonalization
USE cp_array_utils, ONLY: cp_1d_r_p_type
USE cp_cfm_basic_linalg, ONLY: cp_cfm_scale,&
cp_cfm_scale_and_add,&
cp_cfm_scale_and_add_fm
USE cp_cfm_diag, ONLY: cp_cfm_geeig,&
cp_cfm_geeig_canon
USE cp_cfm_types, ONLY: cp_cfm_create,&
cp_cfm_release,&
cp_cfm_to_cfm,&
cp_cfm_to_fm,&
cp_cfm_type
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: &
dbcsr_copy, dbcsr_create, dbcsr_deallocate_matrix, dbcsr_desymmetrize, dbcsr_p_type, &
dbcsr_set, dbcsr_type, dbcsr_type_antisymmetric, dbcsr_type_no_symmetry, &
dbcsr_type_symmetric
USE cp_dbcsr_cp2k_link, ONLY: cp_dbcsr_alloc_block_from_nbl
USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm,&
copy_fm_to_dbcsr,&
cp_dbcsr_sm_fm_multiply,&
dbcsr_allocate_matrix_set
USE cp_fm_basic_linalg, ONLY: cp_fm_symm,&
cp_fm_upper_to_full
USE cp_fm_cholesky, ONLY: cp_fm_cholesky_reduce,&
cp_fm_cholesky_restore
USE cp_fm_diag, ONLY: choose_eigv_solver,&
cp_fm_geeig,&
cp_fm_geeig_canon
USE cp_fm_pool_types, ONLY: cp_fm_pool_p_type,&
fm_pool_create_fm,&
fm_pool_give_back_fm
USE cp_fm_struct, ONLY: cp_fm_struct_create,&
cp_fm_struct_release,&
cp_fm_struct_type
USE cp_fm_types, ONLY: &
copy_info_type, cp_fm_add_to_element, cp_fm_cleanup_copy_general, cp_fm_create, &
cp_fm_finish_copy_general, cp_fm_get_info, cp_fm_release, cp_fm_start_copy_general, &
cp_fm_to_fm, cp_fm_type
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_type
USE cp_output_handling, ONLY: cp_print_key_finished_output,&
cp_print_key_unit_nr
USE input_constants, ONLY: &
cholesky_dbcsr, cholesky_inverse, cholesky_off, cholesky_reduce, cholesky_restore, &
core_guess, general_roks, high_spin_roks, restart_guess
USE input_section_types, ONLY: section_vals_get_subs_vals,&
section_vals_type
USE kinds, ONLY: dp
USE kpoint_methods, ONLY: kpoint_density_matrices,&
kpoint_density_transform,&
kpoint_set_mo_occupation,&
rskp_transform
USE kpoint_types, ONLY: get_kpoint_info,&
kpoint_env_type,&
kpoint_type
USE machine, ONLY: m_flush,&
m_walltime
USE message_passing, ONLY: mp_para_env_type
USE parallel_gemm_api, ONLY: parallel_gemm
USE preconditioner, ONLY: prepare_preconditioner,&
restart_preconditioner
USE qs_density_matrices, ONLY: calculate_density_matrix
USE qs_density_mixing_types, ONLY: direct_mixing_nr,&
gspace_mixing_nr
USE qs_diis, ONLY: qs_diis_b_calc_err_kp,&
qs_diis_b_info_kp,&
qs_diis_b_step,&
qs_diis_b_step_kp
USE qs_energy_types, ONLY: qs_energy_type
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type
USE qs_gspace_mixing, ONLY: gspace_mixing
USE qs_ks_methods, ONLY: qs_ks_update_qs_env
USE qs_ks_types, ONLY: qs_ks_did_change,&
qs_ks_env_type
USE qs_matrix_pools, ONLY: mpools_get,&
qs_matrix_pools_type
USE qs_mixing_utils, ONLY: charge_mixing_init,&
mixing_allocate,&
mixing_init,&
self_consistency_check
USE qs_mo_methods, ONLY: calculate_subspace_eigenvalues
USE qs_mo_occupation, ONLY: set_mo_occupation
USE qs_mo_types, ONLY: get_mo_set,&
mo_set_type
USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
USE qs_ot_eigensolver, ONLY: ot_eigensolver
USE qs_rho_atom_types, ONLY: rho_atom_type
USE qs_rho_methods, ONLY: qs_rho_update_rho
USE qs_rho_types, ONLY: qs_rho_get,&
qs_rho_type
USE qs_scf_block_davidson, ONLY: generate_extended_space,&
generate_extended_space_sparse
USE qs_scf_lanczos, ONLY: lanczos_refinement,&
lanczos_refinement_2v
USE qs_scf_methods, ONLY: combine_ks_matrices,&
eigensolver,&
eigensolver_dbcsr,&
eigensolver_simple,&
eigensolver_symm,&
scf_env_density_mixing
USE qs_scf_types, ONLY: qs_scf_env_type,&
subspace_env_type
USE scf_control_types, ONLY: scf_control_type
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_diagonalization'
PUBLIC :: do_general_diag, do_general_diag_kp, do_roks_diag, &
do_special_diag, do_ot_diag, do_block_davidson_diag, &
do_block_krylov_diag, do_scf_diag_subspace, diag_subspace_allocate, general_eigenproblem
CONTAINS
! **************************************************************************************************
!> \brief the inner loop of scf, specific to diagonalization with S matrix
!> basically, in goes the ks matrix out goes a new p matrix
!> \param scf_env ...
!> \param mos ...
!> \param matrix_ks ...
!> \param matrix_s ...
!> \param scf_control ...
!> \param scf_section ...
!> \param diis_step ...
!> \par History
!> 03.2006 created [Joost VandeVondele]
! **************************************************************************************************
SUBROUTINE general_eigenproblem(scf_env, mos, matrix_ks, &
matrix_s, scf_control, scf_section, &
diis_step)
TYPE(qs_scf_env_type), POINTER :: scf_env
TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
TYPE(scf_control_type), POINTER :: scf_control
TYPE(section_vals_type), POINTER :: scf_section
LOGICAL, INTENT(INOUT) :: diis_step
INTEGER :: ispin, nspin
LOGICAL :: do_level_shift, owns_ortho, use_jacobi
REAL(KIND=dp) :: diis_error, eps_diis
TYPE(cp_fm_type), POINTER :: ortho
TYPE(dbcsr_type), POINTER :: ortho_dbcsr
nspin = SIZE(matrix_ks)
NULLIFY (ortho, ortho_dbcsr)
DO ispin = 1, nspin
CALL copy_dbcsr_to_fm(matrix_ks(ispin)%matrix, &
scf_env%scf_work1(ispin))
END DO
eps_diis = scf_control%eps_diis
IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis) THEN
CALL qs_diis_b_step(scf_env%scf_diis_buffer, mos, scf_env%scf_work1, &
scf_env%scf_work2, scf_env%iter_delta, diis_error, diis_step, &
eps_diis, scf_control%nmixing, &
s_matrix=matrix_s, &
scf_section=scf_section)
ELSE
diis_step = .FALSE.
END IF
do_level_shift = ((scf_control%level_shift /= 0.0_dp) .AND. &
((scf_control%density_guess == core_guess) .OR. &
(scf_env%iter_count > 1)))
IF ((scf_env%iter_count > 1) .AND. &
(scf_env%iter_delta < scf_control%diagonalization%eps_jacobi)) THEN
use_jacobi = .TRUE.
ELSE
use_jacobi = .FALSE.
END IF
IF (diis_step) THEN
scf_env%iter_param = diis_error
IF (use_jacobi) THEN
scf_env%iter_method = "DIIS/Jacobi"
ELSE
scf_env%iter_method = "DIIS/Diag."
END IF
ELSE
IF (scf_env%mixing_method == 0) THEN
scf_env%iter_method = "NoMix/Diag."
ELSE IF (scf_env%mixing_method == 1) THEN
scf_env%iter_param = scf_env%p_mix_alpha
IF (use_jacobi) THEN
scf_env%iter_method = "P_Mix/Jacobi"
ELSE
scf_env%iter_method = "P_Mix/Diag."
END IF
ELSEIF (scf_env%mixing_method > 1) THEN
scf_env%iter_param = scf_env%mixing_store%alpha
IF (use_jacobi) THEN
scf_env%iter_method = TRIM(scf_env%mixing_store%iter_method)//"/Jacobi"
ELSE
scf_env%iter_method = TRIM(scf_env%mixing_store%iter_method)//"/Diag."
END IF
END IF
END IF
IF (scf_env%cholesky_method == cholesky_dbcsr) THEN
ortho_dbcsr => scf_env%ortho_dbcsr
DO ispin = 1, nspin
CALL eigensolver_dbcsr(matrix_ks=matrix_ks(ispin)%matrix, matrix_ks_fm=scf_env%scf_work1(ispin), &
mo_set=mos(ispin), &
ortho_dbcsr=ortho_dbcsr, &
ksbuf1=scf_env%buf1_dbcsr, ksbuf2=scf_env%buf2_dbcsr)
END DO
ELSE IF (scf_env%cholesky_method > cholesky_off) THEN
IF (scf_env%cholesky_method == cholesky_inverse) THEN
ortho => scf_env%ortho_m1
ELSE
ortho => scf_env%ortho
END IF
owns_ortho = .FALSE.
IF (.NOT. ASSOCIATED(ortho)) THEN
ALLOCATE (ortho)
owns_ortho = .TRUE.
END IF
DO ispin = 1, nspin
IF (do_level_shift) THEN
CALL eigensolver(matrix_ks_fm=scf_env%scf_work1(ispin), &
mo_set=mos(ispin), &
ortho=ortho, &
work=scf_env%scf_work2, &
cholesky_method=scf_env%cholesky_method, &
do_level_shift=do_level_shift, &
level_shift=scf_control%level_shift, &
matrix_u_fm=scf_env%ortho, &
use_jacobi=use_jacobi)
ELSE
CALL eigensolver(matrix_ks_fm=scf_env%scf_work1(ispin), &
mo_set=mos(ispin), &
ortho=ortho, &
work=scf_env%scf_work2, &
cholesky_method=scf_env%cholesky_method, &
do_level_shift=do_level_shift, &
level_shift=scf_control%level_shift, &
use_jacobi=use_jacobi)
END IF
END DO
IF (owns_ortho) DEALLOCATE (ortho)
ELSE
ortho => scf_env%ortho
owns_ortho = .FALSE.
IF (.NOT. ASSOCIATED(ortho)) THEN
ALLOCATE (ortho)
owns_ortho = .TRUE.
END IF
IF (do_level_shift) THEN
DO ispin = 1, nspin
CALL eigensolver_symm(matrix_ks_fm=scf_env%scf_work1(ispin), &
mo_set=mos(ispin), &
ortho=ortho, &
work=scf_env%scf_work2, &
do_level_shift=do_level_shift, &
level_shift=scf_control%level_shift, &
matrix_u_fm=scf_env%ortho_m1, &
use_jacobi=use_jacobi, &
jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
END DO
ELSE
DO ispin = 1, nspin
CALL eigensolver_symm(matrix_ks_fm=scf_env%scf_work1(ispin), &
mo_set=mos(ispin), &
ortho=ortho, &
work=scf_env%scf_work2, &
do_level_shift=do_level_shift, &
level_shift=scf_control%level_shift, &
use_jacobi=use_jacobi, &
jacobi_threshold=scf_control%diagonalization%jacobi_threshold)
END DO
END IF
IF (owns_ortho) DEALLOCATE (ortho)
END IF
END SUBROUTINE general_eigenproblem
! **************************************************************************************************
!> \brief ...
!> \param scf_env ...
!> \param mos ...
!> \param matrix_ks ...
!> \param matrix_s ...
!> \param scf_control ...
!> \param scf_section ...
!> \param diis_step ...
! **************************************************************************************************
SUBROUTINE do_general_diag(scf_env, mos, matrix_ks, &
matrix_s, scf_control, scf_section, &
diis_step)
TYPE(qs_scf_env_type), POINTER :: scf_env
TYPE(mo_set_type), DIMENSION(:), INTENT(INOUT) :: mos
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
TYPE(scf_control_type), POINTER :: scf_control
TYPE(section_vals_type), POINTER :: scf_section
LOGICAL, INTENT(INOUT) :: diis_step
INTEGER :: ispin, nspin
REAL(KIND=dp) :: total_zeff_corr
nspin = SIZE(matrix_ks)
CALL general_eigenproblem(scf_env, mos, matrix_ks, &
matrix_s, scf_control, scf_section, diis_step)
total_zeff_corr = 0.0_dp
total_zeff_corr = scf_env%sum_zeff_corr
IF (ABS(total_zeff_corr) > 0.0_dp) THEN
CALL set_mo_occupation(mo_array=mos, &
smear=scf_control%smear, tot_zeff_corr=total_zeff_corr)
ELSE
CALL set_mo_occupation(mo_array=mos, &
smear=scf_control%smear)
END IF
DO ispin = 1, nspin
CALL calculate_density_matrix(mos(ispin), &
scf_env%p_mix_new(ispin, 1)%matrix)
END DO
END SUBROUTINE do_general_diag
! **************************************************************************************************
!> \brief Kpoint diagonalization routine
!> Transforms matrices to kpoint, distributes kpoint groups, performs
!> general diagonalization (no storgae of overlap decomposition), stores
!> MOs, calculates occupation numbers, calculates density matrices
!> in kpoint representation, transforms density matrices to real space
!> \param matrix_ks Kohn-sham matrices (RS indices, global)
!> \param matrix_s Overlap matrices (RS indices, global)
!> \param kpoints Kpoint environment
!> \param scf_env SCF environment
!> \param scf_control SCF control variables
!> \param update_p ...
!> \param diis_step ...
!> \param diis_error ...
!> \param qs_env ...
!> \par History
!> 08.2014 created [JGH]
! **************************************************************************************************
SUBROUTINE do_general_diag_kp(matrix_ks, matrix_s, kpoints, scf_env, scf_control, update_p, &
diis_step, diis_error, qs_env)
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks, matrix_s
TYPE(kpoint_type), POINTER :: kpoints
TYPE(qs_scf_env_type), POINTER :: scf_env
TYPE(scf_control_type), POINTER :: scf_control
LOGICAL, INTENT(IN) :: update_p
LOGICAL, INTENT(INOUT) :: diis_step
REAL(dp), INTENT(INOUT), OPTIONAL :: diis_error
TYPE(qs_environment_type), OPTIONAL, POINTER :: qs_env
CHARACTER(len=*), PARAMETER :: routineN = 'do_general_diag_kp'
COMPLEX(KIND=dp), PARAMETER :: cone = CMPLX(1.0_dp, 0.0_dp, KIND=dp), &
czero = CMPLX(0.0_dp, 0.0_dp, KIND=dp), ione = CMPLX(0.0_dp, 1.0_dp, KIND=dp)
COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:) :: coeffs
INTEGER :: handle, ib, igroup, ik, ikp, indx, &
ispin, jb, kplocal, nb, nkp, &
nkp_groups, nspin
INTEGER, DIMENSION(2) :: kp_range
INTEGER, DIMENSION(:, :), POINTER :: kp_dist
INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
LOGICAL :: do_diis, my_kpgrp, use_real_wfn
REAL(KIND=dp), DIMENSION(:), POINTER :: eigenvalues
REAL(KIND=dp), DIMENSION(:, :), POINTER :: xkp
TYPE(copy_info_type), ALLOCATABLE, DIMENSION(:, :) :: info
TYPE(cp_cfm_type) :: cksmat, cmos, csmat, cwork
TYPE(cp_fm_pool_p_type), DIMENSION(:), POINTER :: ao_ao_fm_pools
TYPE(cp_fm_struct_type), POINTER :: matrix_struct, mo_struct
TYPE(cp_fm_type) :: fmdummy, fmlocal, rksmat, rsmat
TYPE(cp_fm_type), DIMENSION(:), POINTER :: fmwork
TYPE(cp_fm_type), POINTER :: imos, mo_coeff, rmos
TYPE(dbcsr_type), POINTER :: cmatrix, rmatrix, tmpmat
TYPE(kpoint_env_type), POINTER :: kp
TYPE(mp_para_env_type), POINTER :: para_env, para_env_global
TYPE(neighbor_list_set_p_type), DIMENSION(:), &
POINTER :: sab_nl
TYPE(qs_matrix_pools_type), POINTER :: mpools
TYPE(section_vals_type), POINTER :: scf_section
CALL timeset(routineN, handle)
NULLIFY (sab_nl)
CALL get_kpoint_info(kpoints, nkp=nkp, xkp=xkp, use_real_wfn=use_real_wfn, kp_range=kp_range, &
nkp_groups=nkp_groups, kp_dist=kp_dist, sab_nl=sab_nl, &
cell_to_index=cell_to_index)
CPASSERT(ASSOCIATED(sab_nl))
kplocal = kp_range(2) - kp_range(1) + 1
!Whether we use DIIS for k-points
do_diis = .FALSE.
IF (scf_env%iter_count > 1 .AND. .NOT. scf_env%skip_diis .AND. .NOT. use_real_wfn &
.AND. PRESENT(diis_error) .AND. PRESENT(qs_env)) do_diis = .TRUE.
! allocate some work matrices
ALLOCATE (rmatrix, cmatrix, tmpmat)
CALL dbcsr_create(rmatrix, template=matrix_ks(1, 1)%matrix, &
matrix_type=dbcsr_type_symmetric)
CALL dbcsr_create(cmatrix, template=matrix_ks(1, 1)%matrix, &
matrix_type=dbcsr_type_antisymmetric)
CALL dbcsr_create(tmpmat, template=matrix_ks(1, 1)%matrix, &
matrix_type=dbcsr_type_no_symmetry)
CALL cp_dbcsr_alloc_block_from_nbl(rmatrix, sab_nl)
CALL cp_dbcsr_alloc_block_from_nbl(cmatrix, sab_nl)
fmwork => scf_env%scf_work1
! fm pools to be used within a kpoint group
CALL get_kpoint_info(kpoints, mpools=mpools)
CALL mpools_get(mpools, ao_ao_fm_pools=ao_ao_fm_pools)
CALL fm_pool_create_fm(ao_ao_fm_pools(1)%pool, fmlocal)
CALL cp_fm_get_info(fmlocal, matrix_struct=matrix_struct)
IF (use_real_wfn) THEN
CALL cp_fm_create(rksmat, matrix_struct)
CALL cp_fm_create(rsmat, matrix_struct)
ELSE
CALL cp_cfm_create(cksmat, matrix_struct)
CALL cp_cfm_create(csmat, matrix_struct)
CALL cp_cfm_create(cwork, matrix_struct)
kp => kpoints%kp_env(1)%kpoint_env
CALL get_mo_set(kp%mos(1, 1), mo_coeff=mo_coeff)
CALL cp_fm_get_info(mo_coeff, matrix_struct=mo_struct)
CALL cp_cfm_create(cmos, mo_struct)
END IF
para_env => kpoints%blacs_env_all%para_env
nspin = SIZE(matrix_ks, 1)
ALLOCATE (info(kplocal*nspin*nkp_groups, 4))
! Setup and start all the communication
indx = 0
DO ikp = 1, kplocal
DO ispin = 1, nspin
DO igroup = 1, nkp_groups
! number of current kpoint
ik = kp_dist(1, igroup) + ikp - 1
my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
indx = indx + 1
IF (use_real_wfn) THEN
! FT of matrices KS and S, then transfer to FM type
CALL dbcsr_set(rmatrix, 0.0_dp)
CALL rskp_transform(rmatrix=rmatrix, rsmat=matrix_ks, ispin=ispin, &
xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
CALL dbcsr_desymmetrize(rmatrix, tmpmat)
CALL copy_dbcsr_to_fm(tmpmat, fmwork(1))
! s matrix is not spin dependent
CALL dbcsr_set(rmatrix, 0.0_dp)
CALL rskp_transform(rmatrix=rmatrix, rsmat=matrix_s, ispin=1, &
xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
CALL dbcsr_desymmetrize(rmatrix, tmpmat)
CALL copy_dbcsr_to_fm(tmpmat, fmwork(3))
ELSE
! FT of matrices KS and S, then transfer to FM type
CALL dbcsr_set(rmatrix, 0.0_dp)
CALL dbcsr_set(cmatrix, 0.0_dp)
CALL rskp_transform(rmatrix=rmatrix, cmatrix=cmatrix, rsmat=matrix_ks, ispin=ispin, &
xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
CALL dbcsr_desymmetrize(rmatrix, tmpmat)
CALL copy_dbcsr_to_fm(tmpmat, fmwork(1))
CALL dbcsr_desymmetrize(cmatrix, tmpmat)
CALL copy_dbcsr_to_fm(tmpmat, fmwork(2))
! s matrix is not spin dependent, double the work
CALL dbcsr_set(rmatrix, 0.0_dp)
CALL dbcsr_set(cmatrix, 0.0_dp)
CALL rskp_transform(rmatrix=rmatrix, cmatrix=cmatrix, rsmat=matrix_s, ispin=1, &
xkp=xkp(1:3, ik), cell_to_index=cell_to_index, sab_nl=sab_nl)
CALL dbcsr_desymmetrize(rmatrix, tmpmat)
CALL copy_dbcsr_to_fm(tmpmat, fmwork(3))
CALL dbcsr_desymmetrize(cmatrix, tmpmat)
CALL copy_dbcsr_to_fm(tmpmat, fmwork(4))
END IF
! transfer to kpoint group
! redistribution of matrices, new blacs environment
! fmwork -> fmlocal -> rksmat/cksmat
! fmwork -> fmlocal -> rsmat/csmat
IF (use_real_wfn) THEN
IF (my_kpgrp) THEN
CALL cp_fm_start_copy_general(fmwork(1), rksmat, para_env, info(indx, 1))
CALL cp_fm_start_copy_general(fmwork(3), rsmat, para_env, info(indx, 2))
ELSE
CALL cp_fm_start_copy_general(fmwork(1), fmdummy, para_env, info(indx, 1))
CALL cp_fm_start_copy_general(fmwork(3), fmdummy, para_env, info(indx, 2))
END IF
ELSE
IF (my_kpgrp) THEN
CALL cp_fm_start_copy_general(fmwork(1), fmlocal, para_env, info(indx, 1))
CALL cp_fm_start_copy_general(fmwork(2), fmlocal, para_env, info(indx, 2))
CALL cp_fm_start_copy_general(fmwork(3), fmlocal, para_env, info(indx, 3))
CALL cp_fm_start_copy_general(fmwork(4), fmlocal, para_env, info(indx, 4))
ELSE
CALL cp_fm_start_copy_general(fmwork(1), fmdummy, para_env, info(indx, 1))
CALL cp_fm_start_copy_general(fmwork(2), fmdummy, para_env, info(indx, 2))
CALL cp_fm_start_copy_general(fmwork(3), fmdummy, para_env, info(indx, 3))
CALL cp_fm_start_copy_general(fmwork(4), fmdummy, para_env, info(indx, 4))
END IF
END IF
END DO
END DO
END DO
! Finish communication then diagonalise in each group
IF (do_diis) THEN
CALL get_qs_env(qs_env, para_env=para_env_global)
scf_section => section_vals_get_subs_vals(qs_env%input, "DFT%SCF")
CALL qs_diis_b_info_kp(kpoints%scf_diis_buffer, ib, nb)
indx = 0
DO ikp = 1, kplocal
DO ispin = 1, nspin
DO igroup = 1, nkp_groups
! number of current kpoint
ik = kp_dist(1, igroup) + ikp - 1
my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
indx = indx + 1
IF (my_kpgrp) THEN
CALL cp_fm_finish_copy_general(fmlocal, info(indx, 1))
CALL cp_cfm_scale_and_add_fm(czero, cksmat, cone, fmlocal)
CALL cp_fm_finish_copy_general(fmlocal, info(indx, 2))
CALL cp_cfm_scale_and_add_fm(cone, cksmat, ione, fmlocal)
CALL cp_fm_finish_copy_general(fmlocal, info(indx, 3))
CALL cp_cfm_scale_and_add_fm(czero, csmat, cone, fmlocal)
CALL cp_fm_finish_copy_general(fmlocal, info(indx, 4))
CALL cp_cfm_scale_and_add_fm(cone, csmat, ione, fmlocal)
END IF
END DO !igroup
kp => kpoints%kp_env(ikp)%kpoint_env
CALL qs_diis_b_calc_err_kp(kpoints%scf_diis_buffer, ib, kp%mos, cksmat, csmat, &
ispin, ikp, kplocal, scf_section)
END DO !ispin
END DO !ikp
ALLOCATE (coeffs(nb))
CALL qs_diis_b_step_kp(kpoints%scf_diis_buffer, coeffs, ib, nb, scf_env%iter_delta, diis_error, &
diis_step, scf_control%eps_diis, nspin, nkp, kplocal, scf_control%nmixing, &
scf_section, para_env_global)
!build the ks matrices and idagonalize
DO ikp = 1, kplocal
DO ispin = 1, nspin
kp => kpoints%kp_env(ikp)%kpoint_env
CALL cp_cfm_to_cfm(kpoints%scf_diis_buffer%smat(ikp), csmat)
CALL cp_cfm_scale(czero, cksmat)
DO jb = 1, nb
CALL cp_cfm_scale_and_add(cone, cksmat, coeffs(jb), kpoints%scf_diis_buffer%param(jb, ispin, ikp))
END DO
CALL get_mo_set(kp%mos(1, ispin), mo_coeff=rmos, eigenvalues=eigenvalues)
CALL get_mo_set(kp%mos(2, ispin), mo_coeff=imos)
IF (scf_env%cholesky_method == cholesky_off) THEN
CALL cp_cfm_geeig_canon(cksmat, csmat, cmos, eigenvalues, cwork, &
scf_control%eps_eigval)
ELSE
CALL cp_cfm_geeig(cksmat, csmat, cmos, eigenvalues, cwork)
END IF
! copy eigenvalues to imag set (keep them in sync)
kp%mos(2, ispin)%eigenvalues = eigenvalues
! split real and imaginary part of mos
CALL cp_cfm_to_fm(cmos, rmos, imos)
END DO
END DO
ELSE !no DIIS
diis_step = .FALSE.
indx = 0
DO ikp = 1, kplocal
DO ispin = 1, nspin
DO igroup = 1, nkp_groups
! number of current kpoint
ik = kp_dist(1, igroup) + ikp - 1
my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
indx = indx + 1
IF (my_kpgrp) THEN
IF (use_real_wfn) THEN
CALL cp_fm_finish_copy_general(rksmat, info(indx, 1))
CALL cp_fm_finish_copy_general(rsmat, info(indx, 2))
ELSE
CALL cp_fm_finish_copy_general(fmlocal, info(indx, 1))
CALL cp_cfm_scale_and_add_fm(czero, cksmat, cone, fmlocal)
CALL cp_fm_finish_copy_general(fmlocal, info(indx, 2))
CALL cp_cfm_scale_and_add_fm(cone, cksmat, ione, fmlocal)
CALL cp_fm_finish_copy_general(fmlocal, info(indx, 3))
CALL cp_cfm_scale_and_add_fm(czero, csmat, cone, fmlocal)
CALL cp_fm_finish_copy_general(fmlocal, info(indx, 4))
CALL cp_cfm_scale_and_add_fm(cone, csmat, ione, fmlocal)
END IF
END IF
END DO
! Each kpoint group has now information on a kpoint to be diagonalized
! General eigensolver Hermite or Symmetric
kp => kpoints%kp_env(ikp)%kpoint_env
IF (use_real_wfn) THEN
CALL get_mo_set(kp%mos(1, ispin), mo_coeff=mo_coeff, eigenvalues=eigenvalues)
IF (scf_env%cholesky_method == cholesky_off) THEN
CALL cp_fm_geeig_canon(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal, &
scf_control%eps_eigval)
ELSE
CALL cp_fm_geeig(rksmat, rsmat, mo_coeff, eigenvalues, fmlocal)
END IF
ELSE
CALL get_mo_set(kp%mos(1, ispin), mo_coeff=rmos, eigenvalues=eigenvalues)
CALL get_mo_set(kp%mos(2, ispin), mo_coeff=imos)
IF (scf_env%cholesky_method == cholesky_off) THEN
CALL cp_cfm_geeig_canon(cksmat, csmat, cmos, eigenvalues, cwork, &
scf_control%eps_eigval)
ELSE
CALL cp_cfm_geeig(cksmat, csmat, cmos, eigenvalues, cwork)
END IF
! copy eigenvalues to imag set (keep them in sync)
kp%mos(2, ispin)%eigenvalues = eigenvalues
! split real and imaginary part of mos
CALL cp_cfm_to_fm(cmos, rmos, imos)
END IF
END DO
END DO
END IF
! Clean up communication
indx = 0
DO ikp = 1, kplocal
DO ispin = 1, nspin
DO igroup = 1, nkp_groups
! number of current kpoint
ik = kp_dist(1, igroup) + ikp - 1
my_kpgrp = (ik >= kpoints%kp_range(1) .AND. ik <= kpoints%kp_range(2))
indx = indx + 1
IF (use_real_wfn) THEN
CALL cp_fm_cleanup_copy_general(info(indx, 1))
CALL cp_fm_cleanup_copy_general(info(indx, 2))
ELSE
CALL cp_fm_cleanup_copy_general(info(indx, 1))
CALL cp_fm_cleanup_copy_general(info(indx, 2))
CALL cp_fm_cleanup_copy_general(info(indx, 3))
CALL cp_fm_cleanup_copy_general(info(indx, 4))
END IF
END DO
END DO
END DO
! All done
DEALLOCATE (info)
IF (update_p) THEN
! MO occupations
CALL kpoint_set_mo_occupation(kpoints, scf_control%smear)
! density matrices
CALL kpoint_density_matrices(kpoints)
! density matrices in real space
CALL kpoint_density_transform(kpoints, scf_env%p_mix_new, .FALSE., &
matrix_s(1, 1)%matrix, sab_nl, fmwork)
END IF
CALL dbcsr_deallocate_matrix(rmatrix)
CALL dbcsr_deallocate_matrix(cmatrix)
CALL dbcsr_deallocate_matrix(tmpmat)
IF (use_real_wfn) THEN
CALL cp_fm_release(rksmat)
CALL cp_fm_release(rsmat)
ELSE
CALL cp_cfm_release(cksmat)
CALL cp_cfm_release(csmat)
CALL cp_cfm_release(cwork)
CALL cp_cfm_release(cmos)
END IF
CALL fm_pool_give_back_fm(ao_ao_fm_pools(1)%pool, fmlocal)
CALL timestop(handle)
END SUBROUTINE do_general_diag_kp
! **************************************************************************************************
!> \brief inner loop within MOS subspace, to refine occupation and density,
!> before next diagonalization of the Hamiltonian
!> \param qs_env ...
!> \param scf_env ...
!> \param subspace_env ...
!> \param mos ...
!> \param rho ...
!> \param ks_env ...
!> \param scf_section ...
!> \param scf_control ...
!> \par History
!> 09.2009 created [MI]
!> \note it is assumed that when diagonalization is used, also some mixing procedure is active
! **************************************************************************************************
SUBROUTINE do_scf_diag_subspace(qs_env, scf_env, subspace_env, mos, rho, &
ks_env, scf_section, scf_control)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(qs_scf_env_type), POINTER :: scf_env
TYPE(subspace_env_type), POINTER :: subspace_env
TYPE(mo_set_type), DIMENSION(:), INTENT(INOUT) :: mos
TYPE(qs_rho_type), POINTER :: rho
TYPE(qs_ks_env_type), POINTER :: ks_env
TYPE(section_vals_type), POINTER :: scf_section
TYPE(scf_control_type), POINTER :: scf_control
CHARACTER(LEN=*), PARAMETER :: routineN = 'do_scf_diag_subspace'
REAL(KIND=dp), PARAMETER :: rone = 1.0_dp, rzero = 0.0_dp
INTEGER :: handle, i, iloop, ispin, nao, nmo, &
nspin, output_unit
LOGICAL :: converged
REAL(dp) :: ene_diff, ene_old, iter_delta, max_val, &
sum_band, sum_val, t1, t2
REAL(KIND=dp), DIMENSION(:), POINTER :: mo_eigenvalues, mo_occupations
TYPE(cp_1d_r_p_type), ALLOCATABLE, DIMENSION(:) :: eval_first, occ_first
TYPE(cp_fm_type) :: work
TYPE(cp_fm_type), POINTER :: c0, chc, evec, mo_coeff
TYPE(cp_logger_type), POINTER :: logger
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s, rho_ao
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho_ao_kp
TYPE(dft_control_type), POINTER :: dft_control
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(qs_energy_type), POINTER :: energy
TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom
CALL timeset(routineN, handle)
NULLIFY (c0, chc, energy, evec, matrix_ks, mo_coeff, mo_eigenvalues, &
mo_occupations, dft_control, rho_ao, rho_ao_kp)
logger => cp_get_default_logger()
output_unit = cp_print_key_unit_nr(logger, scf_section, "PRINT%DIAG_SUB_SCF", &
extension=".scfLog")
!Extra loop keeping mos unchanged and refining the subspace occupation
nspin = SIZE(mos)
CALL qs_rho_get(rho, rho_ao=rho_ao, rho_ao_kp=rho_ao_kp)
ALLOCATE (eval_first(nspin))
ALLOCATE (occ_first(nspin))
DO ispin = 1, nspin
CALL get_mo_set(mo_set=mos(ispin), &
nmo=nmo, &
eigenvalues=mo_eigenvalues, &
occupation_numbers=mo_occupations)
ALLOCATE (eval_first(ispin)%array(nmo))
ALLOCATE (occ_first(ispin)%array(nmo))
eval_first(ispin)%array(1:nmo) = mo_eigenvalues(1:nmo)
occ_first(ispin)%array(1:nmo) = mo_occupations(1:nmo)
END DO
DO ispin = 1, nspin
! does not yet handle k-points
CALL dbcsr_copy(subspace_env%p_matrix_store(ispin)%matrix, rho_ao(ispin)%matrix)
CALL dbcsr_copy(rho_ao(ispin)%matrix, scf_env%p_mix_new(ispin, 1)%matrix)
END DO
subspace_env%p_matrix_mix => scf_env%p_mix_new
NULLIFY (matrix_ks, energy, para_env, matrix_s)
CALL get_qs_env(qs_env, &
matrix_ks=matrix_ks, &
energy=energy, &
matrix_s=matrix_s, &
para_env=para_env, &
dft_control=dft_control)
! mixing storage allocation
IF (subspace_env%mixing_method >= gspace_mixing_nr) THEN
CALL mixing_allocate(qs_env, subspace_env%mixing_method, scf_env%p_mix_new, &
scf_env%p_delta, nspin, subspace_env%mixing_store)
IF (dft_control%qs_control%gapw) THEN
CALL get_qs_env(qs_env=qs_env, rho_atom_set=rho_atom)
CALL mixing_init(subspace_env%mixing_method, rho, subspace_env%mixing_store, &
para_env, rho_atom=rho_atom)
ELSEIF (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb) THEN
CALL charge_mixing_init(subspace_env%mixing_store)
ELSEIF (dft_control%qs_control%semi_empirical) THEN
CPABORT('SE Code not possible')
ELSE
CALL mixing_init(subspace_env%mixing_method, rho, subspace_env%mixing_store, para_env)
END IF
END IF
ene_old = 0.0_dp
ene_diff = 0.0_dp
IF (output_unit > 0) THEN
WRITE (output_unit, "(/T19,A)") '<<<<<<<<< SUBSPACE ROTATION <<<<<<<<<<'
WRITE (output_unit, "(T4,A,T13,A,T21,A,T38,A,T51,A,T65,A/,T4,A)") &
"In-step", "Time", "Convergence", "Band ene.", "Total ene.", "Energy diff.", REPEAT("-", 74)
END IF
! recalculate density matrix here
! update of density
CALL qs_rho_update_rho(rho, qs_env=qs_env)
DO iloop = 1, subspace_env%max_iter
t1 = m_walltime()
converged = .FALSE.
ene_old = energy%total
CALL qs_ks_did_change(ks_env, rho_changed=.TRUE.)
CALL qs_ks_update_qs_env(qs_env, calculate_forces=.FALSE., &
just_energy=.FALSE., print_active=.FALSE.)
max_val = 0.0_dp
sum_val = 0.0_dp
sum_band = 0.0_dp
DO ispin = 1, SIZE(matrix_ks)
CALL get_mo_set(mo_set=mos(ispin), &
nao=nao, &
nmo=nmo, &
eigenvalues=mo_eigenvalues, &
occupation_numbers=mo_occupations, &
mo_coeff=mo_coeff)
!compute C'HC
chc => subspace_env%chc_mat(ispin)
evec => subspace_env%c_vec(ispin)
c0 => subspace_env%c0(ispin)
CALL cp_fm_to_fm(mo_coeff, c0)
CALL cp_fm_create(work, c0%matrix_struct)
CALL cp_dbcsr_sm_fm_multiply(matrix_ks(ispin)%matrix, c0, work, nmo)
CALL parallel_gemm('T', 'N', nmo, nmo, nao, rone, c0, work, rzero, chc)
CALL cp_fm_release(work)
!diagonalize C'HC
CALL choose_eigv_solver(chc, evec, mo_eigenvalues)
!rotate the mos by the eigenvectors of C'HC
CALL parallel_gemm('N', 'N', nao, nmo, nmo, rone, c0, evec, rzero, mo_coeff)
CALL set_mo_occupation(mo_set=mos(ispin), &
smear=scf_control%smear)
! does not yet handle k-points
CALL calculate_density_matrix(mos(ispin), &
subspace_env%p_matrix_mix(ispin, 1)%matrix)
DO i = 1, nmo
sum_band = sum_band + mo_eigenvalues(i)*mo_occupations(i)
END DO
!check for self consistency
END DO
IF (subspace_env%mixing_method == direct_mixing_nr) THEN
CALL scf_env_density_mixing(subspace_env%p_matrix_mix, &
scf_env%mixing_store, rho_ao_kp, para_env, iter_delta, iloop)
ELSE
CALL self_consistency_check(rho_ao_kp, scf_env%p_delta, para_env, &
subspace_env%p_matrix_mix, delta=iter_delta)
END IF
DO ispin = 1, nspin
! does not yet handle k-points
CALL dbcsr_copy(rho_ao(ispin)%matrix, subspace_env%p_matrix_mix(ispin, 1)%matrix)
END DO
! update of density
CALL qs_rho_update_rho(rho, qs_env=qs_env)
! Mixing in reciprocal space
IF (subspace_env%mixing_method >= gspace_mixing_nr) THEN
CALL gspace_mixing(qs_env, scf_env%mixing_method, subspace_env%mixing_store, &
rho, para_env, scf_env%iter_count)
END IF
ene_diff = energy%total - ene_old
converged = (ABS(ene_diff) < subspace_env%eps_ene .AND. &
iter_delta < subspace_env%eps_adapt*scf_env%iter_delta)
t2 = m_walltime()
IF (output_unit > 0) THEN
WRITE (output_unit, "(T4,I5,T11,F8.3,T18,E14.4,T34,F12.5,T46,F16.8,T62,E14.4)") &
iloop, t2 - t1, iter_delta, sum_band, energy%total, ene_diff
CALL m_flush(output_unit)
END IF
IF (converged) THEN
IF (output_unit > 0) WRITE (output_unit, "(T10,A,I6,A,/)") &
" Reached convergence in ", iloop, " iterations "
EXIT
END IF
END DO ! iloop
NULLIFY (subspace_env%p_matrix_mix)
DO ispin = 1, nspin
! does not yet handle k-points
CALL dbcsr_copy(scf_env%p_mix_new(ispin, 1)%matrix, rho_ao(ispin)%matrix)
CALL dbcsr_copy(rho_ao(ispin)%matrix, subspace_env%p_matrix_store(ispin)%matrix)
DEALLOCATE (eval_first(ispin)%array, occ_first(ispin)%array)
END DO
DEALLOCATE (eval_first, occ_first)
CALL timestop(handle)
END SUBROUTINE do_scf_diag_subspace
! **************************************************************************************************
!> \brief ...
!> \param subspace_env ...
!> \param qs_env ...
!> \param mos ...
! **************************************************************************************************
SUBROUTINE diag_subspace_allocate(subspace_env, qs_env, mos)
TYPE(subspace_env_type), POINTER :: subspace_env
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(mo_set_type), DIMENSION(:), INTENT(IN) :: mos
CHARACTER(LEN=*), PARAMETER :: routineN = 'diag_subspace_allocate'
INTEGER :: handle, i, ispin, nmo, nspin
TYPE(cp_fm_struct_type), POINTER :: fm_struct_tmp
TYPE(cp_fm_type), POINTER :: mo_coeff
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
TYPE(neighbor_list_set_p_type), DIMENSION(:), &
POINTER :: sab_orb
CALL timeset(routineN, handle)
NULLIFY (sab_orb, matrix_s)
CALL get_qs_env(qs_env=qs_env, sab_orb=sab_orb, &
matrix_s=matrix_s)
nspin = SIZE(mos)
! *** allocate p_atrix_store ***
IF (.NOT. ASSOCIATED(subspace_env%p_matrix_store)) THEN
CALL dbcsr_allocate_matrix_set(subspace_env%p_matrix_store, nspin)
DO i = 1, nspin
ALLOCATE (subspace_env%p_matrix_store(i)%matrix)
CALL dbcsr_create(matrix=subspace_env%p_matrix_store(i)%matrix, template=matrix_s(1)%matrix, &
name="DENSITY_STORE", matrix_type=dbcsr_type_symmetric, nze=0)
CALL cp_dbcsr_alloc_block_from_nbl(subspace_env%p_matrix_store(i)%matrix, &
sab_orb)
CALL dbcsr_set(subspace_env%p_matrix_store(i)%matrix, 0.0_dp)
END DO
END IF
ALLOCATE (subspace_env%chc_mat(nspin))
ALLOCATE (subspace_env%c_vec(nspin))
ALLOCATE (subspace_env%c0(nspin))
DO ispin = 1, nspin
CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
CALL cp_fm_create(subspace_env%c0(ispin), mo_coeff%matrix_struct)
NULLIFY (fm_struct_tmp)
CALL cp_fm_struct_create(fm_struct_tmp, nrow_global=nmo, ncol_global=nmo, &
para_env=mo_coeff%matrix_struct%para_env, &
context=mo_coeff%matrix_struct%context)
CALL cp_fm_create(subspace_env%chc_mat(ispin), fm_struct_tmp, "chc")
CALL cp_fm_create(subspace_env%c_vec(ispin), fm_struct_tmp, "vec")
CALL cp_fm_struct_release(fm_struct_tmp)
END DO
CALL timestop(handle)
END SUBROUTINE diag_subspace_allocate
! **************************************************************************************************
!> \brief the inner loop of scf, specific to diagonalization without S matrix
!> basically, in goes the ks matrix out goes a new p matrix
!> \param scf_env ...
!> \param mos ...
!> \param matrix_ks ...
!> \param scf_control ...
!> \param scf_section ...
!> \param diis_step ...
!> \par History