-
Notifications
You must be signed in to change notification settings - Fork 1
/
qs_scf_post_tb.F
1658 lines (1514 loc) · 80.7 KB
/
qs_scf_post_tb.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 Does all kind of post scf calculations for DFTB
!> \par History
!> Started as a copy from the GPW file
!> - Revise MO information printout (10.05.2021, MK)
!> \author JHU (03.2013)
! **************************************************************************************************
MODULE qs_scf_post_tb
USE atomic_kind_types, ONLY: atomic_kind_type,&
get_atomic_kind
USE cell_types, ONLY: cell_type,&
pbc
USE cp_array_utils, ONLY: cp_1d_r_p_type
USE cp_blacs_env, ONLY: cp_blacs_env_type
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: dbcsr_p_type,&
dbcsr_type
USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm
USE cp_dbcsr_output, ONLY: cp_dbcsr_write_sparse_matrix
USE cp_fm_cholesky, ONLY: cp_fm_cholesky_decompose,&
cp_fm_cholesky_reduce,&
cp_fm_cholesky_restore
USE cp_fm_diag, ONLY: choose_eigv_solver
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_init_random,&
cp_fm_release,&
cp_fm_to_fm_submat,&
cp_fm_type
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_realspace_grid_cube, ONLY: cp_pw_to_cube
USE cp_result_methods, ONLY: cp_results_erase,&
put_results
USE cp_result_types, ONLY: cp_result_type
USE eeq_input, ONLY: eeq_solver_type
USE eeq_method, ONLY: eeq_charges,&
eeq_print
USE input_constants, ONLY: ot_precond_full_all
USE input_section_types, ONLY: section_get_ival,&
section_get_ivals,&
section_get_lval,&
section_get_rval,&
section_vals_get,&
section_vals_get_subs_vals,&
section_vals_type,&
section_vals_val_get
USE kinds, ONLY: default_path_length,&
default_string_length,&
dp
USE kpoint_types, ONLY: kpoint_type
USE machine, ONLY: m_flush
USE mathconstants, ONLY: twopi
USE memory_utilities, ONLY: reallocate
USE message_passing, ONLY: mp_para_env_type
USE molden_utils, ONLY: write_mos_molden
USE moments_utils, ONLY: get_reference_point
USE mulliken, ONLY: mulliken_charges
USE particle_list_types, ONLY: particle_list_type
USE particle_types, ONLY: particle_type
USE physcon, ONLY: debye
USE population_analyses, ONLY: lowdin_population_analysis
USE preconditioner_types, ONLY: preconditioner_type
USE pw_env_methods, ONLY: pw_env_create,&
pw_env_rebuild
USE pw_env_types, ONLY: pw_env_get,&
pw_env_release,&
pw_env_type
USE pw_grid_types, ONLY: pw_grid_type
USE pw_methods, ONLY: pw_axpy,&
pw_copy,&
pw_derive,&
pw_scale,&
pw_transfer,&
pw_zero
USE pw_poisson_types, ONLY: do_ewald_none,&
greens_fn_type,&
pw_green_create,&
pw_green_release,&
pw_poisson_analytic,&
pw_poisson_parameter_type
USE pw_pool_types, ONLY: pw_pool_p_type,&
pw_pool_type
USE pw_types, ONLY: pw_c1d_gs_type,&
pw_r3d_rs_type
USE qs_collocate_density, ONLY: calculate_rho_core,&
calculate_rho_elec,&
calculate_wavefunction
USE qs_dftb_types, ONLY: qs_dftb_atom_type
USE qs_dftb_utils, ONLY: get_dftb_atom_param
USE qs_dos, ONLY: calculate_dos,&
calculate_dos_kp
USE qs_elf_methods, ONLY: qs_elf_calc
USE qs_energy_window, ONLY: energy_windows
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type
USE qs_kind_types, ONLY: get_qs_kind,&
qs_kind_type
USE qs_ks_types, ONLY: get_ks_env,&
qs_ks_env_type,&
set_ks_env
USE qs_mo_methods, ONLY: calculate_subspace_eigenvalues,&
make_mo_eig
USE qs_mo_occupation, ONLY: set_mo_occupation
USE qs_mo_types, ONLY: get_mo_set,&
mo_set_type
USE qs_ot_eigensolver, ONLY: ot_eigensolver
USE qs_pdos, ONLY: calculate_projected_dos
USE qs_rho_methods, ONLY: qs_rho_rebuild
USE qs_rho_types, ONLY: qs_rho_get,&
qs_rho_set,&
qs_rho_type
USE qs_scf_csr_write, ONLY: write_ks_matrix_csr,&
write_s_matrix_csr
USE qs_scf_output, ONLY: qs_scf_write_mos
USE qs_scf_types, ONLY: ot_method_nr,&
qs_scf_env_type
USE qs_scf_wfn_mix, ONLY: wfn_mix
USE qs_subsys_types, ONLY: qs_subsys_get,&
qs_subsys_type
USE scf_control_types, ONLY: scf_control_type
USE stm_images, ONLY: th_stm_image
USE task_list_methods, ONLY: generate_qs_task_list
USE task_list_types, ONLY: allocate_task_list,&
task_list_type
USE xtb_types, ONLY: get_xtb_atom_param,&
xtb_atom_type
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
! Global parameters
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_post_tb'
PUBLIC :: scf_post_calculation_tb, make_lumo_tb
! **************************************************************************************************
CONTAINS
! **************************************************************************************************
!> \brief collects possible post - scf calculations and prints info / computes properties.
!> \param qs_env ...
!> \param tb_type ...
!> \param no_mos ...
!> \par History
!> 03.2013 copy of scf_post_gpw
!> \author JHU
!> \note
! **************************************************************************************************
SUBROUTINE scf_post_calculation_tb(qs_env, tb_type, no_mos)
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(LEN=*) :: tb_type
LOGICAL, INTENT(IN) :: no_mos
CHARACTER(len=*), PARAMETER :: routineN = 'scf_post_calculation_tb'
CHARACTER(LEN=6) :: ana
CHARACTER(LEN=default_string_length) :: aname
INTEGER :: after, enshift_type, handle, homo, iat, iatom, ikind, img, ispin, iw, nat, natom, &
nkind, nlumo_stm, nlumos, nspins, print_level, unit_nr
LOGICAL :: do_cube, do_kpoints, explicit, has_homo, &
omit_headers, print_it, rebuild
REAL(KIND=dp) :: zeff
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: echarge, mcharge
REAL(KIND=dp), DIMENSION(2, 2) :: homo_lumo
REAL(KIND=dp), DIMENSION(:), POINTER :: mo_eigenvalues
REAL(KIND=dp), DIMENSION(:, :), POINTER :: charges
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: cell
TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER :: unoccupied_evals_stm
TYPE(cp_fm_type), DIMENSION(:), POINTER :: unoccupied_orbs_stm
TYPE(cp_fm_type), POINTER :: mo_coeff
TYPE(cp_logger_type), POINTER :: logger
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, mo_derivs
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks, matrix_p, matrix_s
TYPE(dbcsr_type), POINTER :: mo_coeff_deriv
TYPE(dft_control_type), POINTER :: dft_control
TYPE(eeq_solver_type) :: eeq_sparam
TYPE(kpoint_type), POINTER :: kpoints
TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(particle_list_type), POINTER :: particles
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(qs_dftb_atom_type), POINTER :: dftb_kind
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(qs_rho_type), POINTER :: rho
TYPE(qs_scf_env_type), POINTER :: scf_env
TYPE(qs_subsys_type), POINTER :: subsys
TYPE(scf_control_type), POINTER :: scf_control
TYPE(section_vals_type), POINTER :: dft_section, moments_section, print_key, &
print_section, sprint_section, &
wfn_mix_section
TYPE(xtb_atom_type), POINTER :: xtb_kind
CALL timeset(routineN, handle)
logger => cp_get_default_logger()
CPASSERT(ASSOCIATED(qs_env))
NULLIFY (dft_control, rho, para_env, matrix_s, matrix_p)
CALL get_qs_env(qs_env, scf_env=scf_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
dft_control=dft_control, rho=rho, natom=natom, para_env=para_env, &
particle_set=particle_set, do_kpoints=do_kpoints, matrix_s_kp=matrix_s)
nspins = dft_control%nspins
CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
! Mulliken charges
ALLOCATE (charges(natom, nspins), mcharge(natom))
!
CALL mulliken_charges(matrix_p, matrix_s, para_env, charges)
!
nkind = SIZE(atomic_kind_set)
DO ikind = 1, nkind
CALL get_atomic_kind(atomic_kind_set(ikind), natom=nat)
SELECT CASE (TRIM(tb_type))
CASE ("DFTB")
CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind)
CALL get_dftb_atom_param(dftb_kind, zeff=zeff)
CASE ("xTB")
CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
CALL get_xtb_atom_param(xtb_kind, zeff=zeff)
CASE DEFAULT
CPABORT("unknown TB type")
END SELECT
DO iatom = 1, nat
iat = atomic_kind_set(ikind)%atom_list(iatom)
mcharge(iat) = zeff - SUM(charges(iat, 1:nspins))
END DO
END DO
dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
print_section => section_vals_get_subs_vals(dft_section, "PRINT")
! Mulliken
print_key => section_vals_get_subs_vals(print_section, "MULLIKEN")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
unit_nr = cp_print_key_unit_nr(logger, print_section, "MULLIKEN", &
extension=".mulliken", log_filename=.FALSE.)
IF (unit_nr > 0) THEN
WRITE (UNIT=unit_nr, FMT="(/,/,T2,A)") "MULLIKEN POPULATION ANALYSIS"
IF (nspins == 1) THEN
WRITE (UNIT=unit_nr, FMT="(/,T2,A,T70,A)") &
" # Atom Element Kind Atomic population", " Net charge"
DO ikind = 1, nkind
CALL get_atomic_kind(atomic_kind_set(ikind), natom=nat)
aname = ""
SELECT CASE (tb_type)
CASE ("DFTB")
CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind)
CALL get_dftb_atom_param(dftb_kind, name=aname)
CASE ("xTB")
CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
CALL get_xtb_atom_param(xtb_kind, symbol=aname)
CASE DEFAULT
CPABORT("unknown TB type")
END SELECT
ana = ADJUSTR(TRIM(ADJUSTL(aname)))
DO iatom = 1, nat
iat = atomic_kind_set(ikind)%atom_list(iatom)
WRITE (UNIT=unit_nr, &
FMT="(T2,I7,5X,A6,I6,T39,F12.6,T69,F12.6)") &
iat, ADJUSTL(ana), ikind, charges(iat, 1), mcharge(iat)
END DO
END DO
WRITE (UNIT=unit_nr, &
FMT="(T2,A,T39,F12.6,T69,F12.6,/)") &
"# Total charge", SUM(charges(:, 1)), SUM(mcharge(:))
ELSE
WRITE (UNIT=unit_nr, FMT="(/,T2,A)") &
"# Atom Element Kind Atomic population (alpha,beta) Net charge Spin moment"
DO ikind = 1, nkind
CALL get_atomic_kind(atomic_kind_set(ikind), natom=nat)
aname = ""
SELECT CASE (tb_type)
CASE ("DFTB")
CALL get_qs_kind(qs_kind_set(ikind), dftb_parameter=dftb_kind)
CALL get_dftb_atom_param(dftb_kind, name=aname)
CASE ("xTB")
CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
CALL get_xtb_atom_param(xtb_kind, symbol=aname)
CASE DEFAULT
CPABORT("unknown TB type")
END SELECT
ana = ADJUSTR(TRIM(ADJUSTL(aname)))
DO iatom = 1, nat
iat = atomic_kind_set(ikind)%atom_list(iatom)
WRITE (UNIT=unit_nr, &
FMT="(T2,I6,3X,A6,I6,T29,4(1X,F12.6))") &
iat, ADJUSTL(ana), ikind, charges(iat, 1:2), mcharge(iat), &
charges(iat, 1) - charges(iat, 2)
END DO
END DO
WRITE (UNIT=unit_nr, &
FMT="(T2,A,T29,4(1X,F12.6),/)") &
"# Total charge and spin", SUM(charges(:, 1)), SUM(charges(:, 2)), SUM(mcharge(:))
END IF
CALL m_flush(unit_nr)
END IF
CALL cp_print_key_finished_output(unit_nr, logger, print_key)
END IF
! Compute the Lowdin charges
print_key => section_vals_get_subs_vals(print_section, "LOWDIN")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
SELECT CASE (tb_type)
CASE ("DFTB")
CPWARN("Lowdin population analysis not implemented for DFTB method.")
CASE ("xTB")
unit_nr = cp_print_key_unit_nr(logger, print_section, "LOWDIN", extension=".lowdin", &
log_filename=.FALSE.)
print_level = 1
CALL section_vals_val_get(print_key, "PRINT_GOP", l_val=print_it)
IF (print_it) print_level = 2
CALL section_vals_val_get(print_key, "PRINT_ALL", l_val=print_it)
IF (print_it) print_level = 3
IF (do_kpoints) THEN
CPWARN("Lowdin charges not implemented for k-point calculations!")
ELSE
CALL lowdin_population_analysis(qs_env, unit_nr, print_level)
END IF
CALL cp_print_key_finished_output(unit_nr, logger, print_section, "LOWDIN")
CASE DEFAULT
CPABORT("unknown TB type")
END SELECT
END IF
! EEQ Charges
print_key => section_vals_get_subs_vals(print_section, "EEQ_CHARGES")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
unit_nr = cp_print_key_unit_nr(logger, print_section, "EEQ_CHARGES", &
extension=".eeq", log_filename=.FALSE.)
CALL eeq_print(qs_env, unit_nr, print_level)
CALL cp_print_key_finished_output(unit_nr, logger, print_key)
END IF
! Hirshfeld
print_key => section_vals_get_subs_vals(print_section, "HIRSHFELD")
CALL section_vals_get(print_key, explicit=explicit)
IF (explicit) THEN
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
CPWARN("Hirshfeld charges not available for TB methods.")
END IF
END IF
! MAO
print_key => section_vals_get_subs_vals(print_section, "MAO_ANALYSIS")
CALL section_vals_get(print_key, explicit=explicit)
IF (explicit) THEN
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
CPWARN("MAO analysis not available for TB methods.")
END IF
END IF
! ED
print_key => section_vals_get_subs_vals(print_section, "ENERGY_DECOMPOSITION_ANALYSIS")
CALL section_vals_get(print_key, explicit=explicit)
IF (explicit) THEN
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
CPWARN("ED analysis not available for TB methods.")
END IF
END IF
! Dipole Moments
print_key => section_vals_get_subs_vals(print_section, "MOMENTS")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
unit_nr = cp_print_key_unit_nr(logger, print_section, "MOMENTS", &
extension=".data", middle_name="tb_dipole", log_filename=.FALSE.)
moments_section => section_vals_get_subs_vals(print_section, "MOMENTS")
IF (tb_type == "xTB" .AND. dft_control%qs_control%xtb_control%gfn_type == 0) THEN
enshift_type = dft_control%qs_control%xtb_control%enshift_type
IF (enshift_type == 0) THEN
CALL get_qs_env(qs_env, cell=cell)
enshift_type = 1
IF (.NOT. ALL(cell%perd == 0)) enshift_type = 2
END IF
ALLOCATE (echarge(natom))
echarge = 0.0_dp
CALL eeq_charges(qs_env, echarge, eeq_sparam, 1, enshift_type)
CALL tb_dipole(qs_env, moments_section, unit_nr, echarge)
DEALLOCATE (echarge)
ELSE
CALL tb_dipole(qs_env, moments_section, unit_nr, mcharge)
END IF
CALL cp_print_key_finished_output(unit_nr, logger, print_key)
END IF
DEALLOCATE (charges, mcharge)
! MO
IF (.NOT. no_mos) THEN
print_key => section_vals_get_subs_vals(print_section, "MO")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
CALL qs_scf_write_mos(qs_env, scf_env, final_mos=.TRUE.)
IF (.NOT. do_kpoints) THEN
SELECT CASE (tb_type)
CASE ("DFTB")
CASE ("xTB")
sprint_section => section_vals_get_subs_vals(dft_section, "PRINT%MO_MOLDEN")
CALL get_qs_env(qs_env, mos=mos)
CALL write_mos_molden(mos, qs_kind_set, particle_set, sprint_section)
CASE DEFAULT
CPABORT("Unknown TB type")
END SELECT
END IF
END IF
END IF
! Wavefunction mixing
IF (.NOT. no_mos) THEN
wfn_mix_section => section_vals_get_subs_vals(dft_section, "PRINT%WFN_MIX")
CALL section_vals_get(wfn_mix_section, explicit=explicit)
IF (explicit .AND. .NOT. qs_env%run_rtp) CALL wfn_mix_tb(qs_env, dft_section, scf_env)
END IF
IF (.NOT. no_mos) THEN
print_key => section_vals_get_subs_vals(print_section, "DOS")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
IF (do_kpoints) THEN
CALL get_qs_env(qs_env=qs_env, kpoints=kpoints)
CALL calculate_dos_kp(kpoints, qs_env, dft_section)
ELSE
CALL get_qs_env(qs_env, mos=mos)
CALL calculate_dos(mos, dft_section)
END IF
END IF
END IF
! PDOS
IF (.NOT. no_mos) THEN
print_key => section_vals_get_subs_vals(print_section, "PDOS")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
IF (do_kpoints) THEN
CPWARN("Projected density of states not implemented for k-points.")
ELSE
CALL get_qs_env(qs_env, mos=mos, matrix_ks=ks_rmpv)
DO ispin = 1, dft_control%nspins
IF (scf_env%method == ot_method_nr) THEN
CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
eigenvalues=mo_eigenvalues)
IF (ASSOCIATED(qs_env%mo_derivs)) THEN
mo_coeff_deriv => qs_env%mo_derivs(ispin)%matrix
ELSE
mo_coeff_deriv => NULL()
END IF
CALL calculate_subspace_eigenvalues(mo_coeff, ks_rmpv(ispin)%matrix, mo_eigenvalues, &
do_rotation=.TRUE., &
co_rotate_dbcsr=mo_coeff_deriv)
CALL set_mo_occupation(mo_set=mos(ispin))
END IF
IF (dft_control%nspins == 2) THEN
CALL calculate_projected_dos(mos(ispin), atomic_kind_set, &
qs_kind_set, particle_set, qs_env, dft_section, ispin=ispin)
ELSE
CALL calculate_projected_dos(mos(ispin), atomic_kind_set, &
qs_kind_set, particle_set, qs_env, dft_section)
END IF
END DO
END IF
END IF
END IF
! can we do CUBE files?
SELECT CASE (tb_type)
CASE ("DFTB")
do_cube = .FALSE.
rebuild = .FALSE.
CASE ("xTB")
do_cube = .TRUE.
rebuild = .TRUE.
CASE DEFAULT
CPABORT("unknown TB type")
END SELECT
! Energy Windows for LS code
print_key => section_vals_get_subs_vals(print_section, "ENERGY_WINDOWS")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
IF (do_cube) THEN
IF (do_kpoints) THEN
CPWARN("Energy Windows not implemented for k-points.")
ELSE
IF (rebuild) THEN
CALL rebuild_pw_env(qs_env)
rebuild = .FALSE.
END IF
CALL energy_windows(qs_env)
END IF
ELSE
CPWARN("Energy Windows not implemented for TB methods.")
END IF
END IF
! DENSITY CUBE FILE
print_key => section_vals_get_subs_vals(print_section, "E_DENSITY_CUBE")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
IF (do_cube) THEN
IF (rebuild) THEN
CALL rebuild_pw_env(qs_env)
rebuild = .FALSE.
END IF
CALL print_e_density(qs_env, print_key)
ELSE
CPWARN("Electronic density cube file not implemented for TB methods.")
END IF
END IF
! TOTAL DENSITY CUBE FILE
print_key => section_vals_get_subs_vals(print_section, "TOT_DENSITY_CUBE")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
IF (do_cube) THEN
IF (rebuild) THEN
CALL rebuild_pw_env(qs_env)
rebuild = .FALSE.
END IF
CALL print_density_cubes(qs_env, print_key, total_density=.TRUE.)
ELSE
CPWARN("Total density cube file not implemented for TB methods.")
END IF
END IF
! V_Hartree CUBE FILE
print_key => section_vals_get_subs_vals(print_section, "V_HARTREE_CUBE")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
IF (do_cube) THEN
IF (rebuild) THEN
CALL rebuild_pw_env(qs_env)
rebuild = .FALSE.
END IF
CALL print_density_cubes(qs_env, print_key, v_hartree=.TRUE.)
ELSE
CPWARN("Hartree potential cube file not implemented for TB methods.")
END IF
END IF
! EFIELD CUBE FILE
print_key => section_vals_get_subs_vals(print_section, "EFIELD_CUBE")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
IF (do_cube) THEN
IF (rebuild) THEN
CALL rebuild_pw_env(qs_env)
rebuild = .FALSE.
END IF
CALL print_density_cubes(qs_env, print_key, efield=.TRUE.)
ELSE
CPWARN("Efield cube file not implemented for TB methods.")
END IF
END IF
! ELF
print_key => section_vals_get_subs_vals(print_section, "ELF_CUBE")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
IF (do_cube) THEN
IF (rebuild) THEN
CALL rebuild_pw_env(qs_env)
rebuild = .FALSE.
END IF
CALL print_elf(qs_env, print_key)
ELSE
CPWARN("ELF not implemented for TB methods.")
END IF
END IF
! MO CUBES
IF (.NOT. no_mos) THEN
print_key => section_vals_get_subs_vals(print_section, "MO_CUBES")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
IF (do_cube) THEN
IF (rebuild) THEN
CALL rebuild_pw_env(qs_env)
rebuild = .FALSE.
END IF
CALL print_mo_cubes(qs_env, print_key)
ELSE
CPWARN("Printing of MO cube files not implemented for TB methods.")
END IF
END IF
END IF
! STM
IF (.NOT. no_mos) THEN
print_key => section_vals_get_subs_vals(print_section, "STM")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
IF (do_cube) THEN
IF (rebuild) THEN
CALL rebuild_pw_env(qs_env)
rebuild = .FALSE.
END IF
IF (do_kpoints) THEN
CPWARN("STM not implemented for k-point calculations!")
ELSE
nlumo_stm = section_get_ival(print_key, "NLUMO")
CPASSERT(.NOT. dft_control%restricted)
CALL get_qs_env(qs_env, mos=mos, mo_derivs=mo_derivs, &
scf_control=scf_control, matrix_ks=ks_rmpv)
CALL make_mo_eig(mos, dft_control%nspins, ks_rmpv, scf_control, mo_derivs)
DO ispin = 1, dft_control%nspins
CALL get_mo_set(mo_set=mos(ispin), eigenvalues=mo_eigenvalues, homo=homo)
homo_lumo(ispin, 1) = mo_eigenvalues(homo)
END DO
has_homo = .TRUE.
NULLIFY (unoccupied_orbs_stm, unoccupied_evals_stm)
IF (nlumo_stm > 0) THEN
ALLOCATE (unoccupied_orbs_stm(dft_control%nspins))
ALLOCATE (unoccupied_evals_stm(dft_control%nspins))
CALL make_lumo_tb(qs_env, scf_env, unoccupied_orbs_stm, unoccupied_evals_stm, &
nlumo_stm, nlumos)
END IF
CALL get_qs_env(qs_env, subsys=subsys)
CALL qs_subsys_get(subsys, particles=particles)
CALL th_stm_image(qs_env, print_key, particles, unoccupied_orbs_stm, &
unoccupied_evals_stm)
IF (nlumo_stm > 0) THEN
DO ispin = 1, dft_control%nspins
DEALLOCATE (unoccupied_evals_stm(ispin)%array)
END DO
DEALLOCATE (unoccupied_evals_stm)
CALL cp_fm_release(unoccupied_orbs_stm)
END IF
END IF
END IF
END IF
END IF
! Write the density matrix
CALL get_qs_env(qs_env, matrix_ks_kp=matrix_ks)
CALL section_vals_val_get(print_section, "AO_MATRICES%OMIT_HEADERS", l_val=omit_headers)
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_section, &
"AO_MATRICES/DENSITY"), cp_p_file)) THEN
iw = cp_print_key_unit_nr(logger, print_section, "AO_MATRICES/DENSITY", &
extension=".Log")
CALL section_vals_val_get(print_section, "AO_MATRICES%NDIGITS", i_val=after)
after = MIN(MAX(after, 1), 16)
DO ispin = 1, dft_control%nspins
DO img = 1, SIZE(matrix_p, 2)
CALL cp_dbcsr_write_sparse_matrix(matrix_p(ispin, img)%matrix, 4, after, qs_env, &
para_env, output_unit=iw, omit_headers=omit_headers)
END DO
END DO
CALL cp_print_key_finished_output(iw, logger, print_section, "AO_MATRICES/DENSITY")
END IF
! The xTB matrix itself
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_section, &
"AO_MATRICES/KOHN_SHAM_MATRIX"), cp_p_file)) THEN
iw = cp_print_key_unit_nr(logger, print_section, "AO_MATRICES/KOHN_SHAM_MATRIX", &
extension=".Log")
CALL section_vals_val_get(print_section, "AO_MATRICES%NDIGITS", i_val=after)
after = MIN(MAX(after, 1), 16)
DO ispin = 1, dft_control%nspins
DO img = 1, SIZE(matrix_ks, 2)
CALL cp_dbcsr_write_sparse_matrix(matrix_ks(ispin, img)%matrix, 4, after, qs_env, para_env, &
output_unit=iw, omit_headers=omit_headers)
END DO
END DO
CALL cp_print_key_finished_output(iw, logger, print_section, "AO_MATRICES/KOHN_SHAM_MATRIX")
END IF
! these print keys are not supported in TB
! V_XC CUBE FILE
print_key => section_vals_get_subs_vals(print_section, "V_XC_CUBE")
CALL section_vals_get(print_key, explicit=explicit)
IF (explicit) THEN
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
CPWARN("XC potential cube file not available for TB methods.")
END IF
END IF
! Electric field gradients
print_key => section_vals_get_subs_vals(print_section, "ELECTRIC_FIELD_GRADIENT")
CALL section_vals_get(print_key, explicit=explicit)
IF (explicit) THEN
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
CPWARN("Electric field gradient not implemented for TB methods.")
END IF
END IF
! KINETIC ENERGY
print_key => section_vals_get_subs_vals(print_section, "KINETIC_ENERGY")
CALL section_vals_get(print_key, explicit=explicit)
IF (explicit) THEN
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
CPWARN("Kinetic energy not available for TB methods.")
END IF
END IF
! Xray diffraction spectrum
print_key => section_vals_get_subs_vals(print_section, "XRAY_DIFFRACTION_SPECTRUM")
CALL section_vals_get(print_key, explicit=explicit)
IF (explicit) THEN
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
CPWARN("Xray diffraction spectrum not implemented for TB methods.")
END IF
END IF
! EPR Hyperfine Coupling
print_key => section_vals_get_subs_vals(print_section, "HYPERFINE_COUPLING_TENSOR")
CALL section_vals_get(print_key, explicit=explicit)
IF (explicit) THEN
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
CPWARN("Hyperfine Coupling not implemented for TB methods.")
END IF
END IF
! PLUS_U
print_key => section_vals_get_subs_vals(print_section, "PLUS_U")
CALL section_vals_get(print_key, explicit=explicit)
IF (explicit) THEN
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
CPWARN("DFT+U method not implemented for TB methods.")
END IF
END IF
CALL write_ks_matrix_csr(qs_env, qs_env%input)
CALL write_s_matrix_csr(qs_env, qs_env%input)
CALL timestop(handle)
END SUBROUTINE scf_post_calculation_tb
! **************************************************************************************************
!> \brief ...
!> \param qs_env ...
!> \param input ...
!> \param unit_nr ...
!> \param charges ...
! **************************************************************************************************
SUBROUTINE tb_dipole(qs_env, input, unit_nr, charges)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(section_vals_type), POINTER :: input
INTEGER, INTENT(in) :: unit_nr
REAL(KIND=dp), DIMENSION(:), INTENT(in) :: charges
CHARACTER(LEN=default_string_length) :: description, dipole_type
COMPLEX(KIND=dp) :: dzeta, dzphase(3), zeta, zphase(3)
COMPLEX(KIND=dp), DIMENSION(3) :: dggamma, ggamma
INTEGER :: i, iat, ikind, j, nat, reference
LOGICAL :: do_berry
REAL(KIND=dp) :: charge_tot, ci(3), dci(3), dipole(3), dipole_deriv(3), drcc(3), dria(3), &
dtheta, gvec(3), q, rcc(3), ria(3), theta, tmp(3), via(3)
REAL(KIND=dp), DIMENSION(:), POINTER :: ref_point
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: cell
TYPE(cp_result_type), POINTER :: results
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
NULLIFY (atomic_kind_set, cell, results)
CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, &
particle_set=particle_set, cell=cell, results=results)
! Reference point
reference = section_get_ival(input, keyword_name="REFERENCE")
NULLIFY (ref_point)
description = '[DIPOLE]'
CALL section_vals_val_get(input, "REF_POINT", r_vals=ref_point)
CALL section_vals_val_get(input, "PERIODIC", l_val=do_berry)
CALL get_reference_point(rcc, drcc, qs_env=qs_env, reference=reference, ref_point=ref_point)
! Dipole deriv will be the derivative of the Dipole(dM/dt=\sum e_j v_j)
dipole_deriv = 0.0_dp
dipole = 0.0_dp
IF (do_berry) THEN
dipole_type = "periodic (Berry phase)"
rcc = pbc(rcc, cell)
charge_tot = 0._dp
charge_tot = SUM(charges)
ria = twopi*MATMUL(cell%h_inv, rcc)
zphase = CMPLX(COS(ria), SIN(ria), dp)**charge_tot
dria = twopi*MATMUL(cell%h_inv, drcc)
dzphase = charge_tot*CMPLX(-SIN(ria), COS(ria), dp)**(charge_tot - 1.0_dp)*dria
ggamma = CMPLX(1.0_dp, 0.0_dp, KIND=dp)
dggamma = CMPLX(0.0_dp, 0.0_dp, KIND=dp)
DO ikind = 1, SIZE(atomic_kind_set)
CALL get_atomic_kind(atomic_kind_set(ikind), natom=nat)
DO i = 1, nat
iat = atomic_kind_set(ikind)%atom_list(i)
ria = particle_set(iat)%r(:)
ria = pbc(ria, cell)
via = particle_set(iat)%v(:)
q = charges(iat)
DO j = 1, 3
gvec = twopi*cell%h_inv(j, :)
theta = SUM(ria(:)*gvec(:))
dtheta = SUM(via(:)*gvec(:))
zeta = CMPLX(COS(theta), SIN(theta), KIND=dp)**(-q)
dzeta = -q*CMPLX(-SIN(theta), COS(theta), KIND=dp)**(-q - 1.0_dp)*dtheta
dggamma(j) = dggamma(j)*zeta + ggamma(j)*dzeta
ggamma(j) = ggamma(j)*zeta
END DO
END DO
END DO
dggamma = dggamma*zphase + ggamma*dzphase
ggamma = ggamma*zphase
IF (ALL(REAL(ggamma, KIND=dp) /= 0.0_dp)) THEN
tmp = AIMAG(ggamma)/REAL(ggamma, KIND=dp)
ci = -ATAN(tmp)
dci = -(1.0_dp/(1.0_dp + tmp**2))* &
(AIMAG(dggamma)*REAL(ggamma, KIND=dp) - AIMAG(ggamma)*REAL(dggamma, KIND=dp))/(REAL(ggamma, KIND=dp))**2
dipole = MATMUL(cell%hmat, ci)/twopi
dipole_deriv = MATMUL(cell%hmat, dci)/twopi
END IF
ELSE
dipole_type = "non-periodic"
DO i = 1, SIZE(particle_set)
! no pbc(particle_set(i)%r(:),cell) so that the total dipole is the sum of the molecular dipoles
ria = particle_set(i)%r(:)
q = charges(i)
dipole = dipole + q*(ria - rcc)
dipole_deriv(:) = dipole_deriv(:) + q*(particle_set(i)%v(:) - drcc)
END DO
END IF
CALL cp_results_erase(results=results, description=description)
CALL put_results(results=results, description=description, &
values=dipole(1:3))
IF (unit_nr > 0) THEN
WRITE (unit_nr, '(/,T2,A,T31,A50)') &
'TB_DIPOLE| Dipole type', ADJUSTR(TRIM(dipole_type))
WRITE (unit_nr, "(T2,A,T33,3F16.8)") "TB_DIPOLE| Reference Point [Bohr]", rcc
WRITE (unit_nr, '(T2,A,T30,3(1X,F16.8))') &
'TB_DIPOLE| Moment [a.u.]', dipole(1:3)
WRITE (unit_nr, '(T2,A,T30,3(1X,F16.8))') &
'TB_DIPOLE| Moment [Debye]', dipole(1:3)*debye
WRITE (unit_nr, '(T2,A,T30,3(1X,F16.8))') &
'TB_DIPOLE| Derivative [a.u.]', dipole_deriv(1:3)
END IF
END SUBROUTINE tb_dipole
! **************************************************************************************************
!> \brief computes the MOs and calls the wavefunction mixing routine.
!> \param qs_env ...
!> \param dft_section ...
!> \param scf_env ...
!> \author Florian Schiffmann
!> \note
! **************************************************************************************************
SUBROUTINE wfn_mix_tb(qs_env, dft_section, scf_env)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(section_vals_type), POINTER :: dft_section
TYPE(qs_scf_env_type), POINTER :: scf_env
INTEGER :: ispin, nao, nmo, output_unit
REAL(dp), DIMENSION(:), POINTER :: mo_eigenvalues
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cp_fm_struct_type), POINTER :: ao_ao_fmstruct, ao_lumo_struct
TYPE(cp_fm_type) :: KS_tmp, MO_tmp, S_tmp, work
TYPE(cp_fm_type), DIMENSION(:), POINTER :: lumos
TYPE(cp_fm_type), POINTER :: mo_coeff
TYPE(cp_logger_type), POINTER :: logger
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
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(section_vals_type), POINTER :: wfn_mix_section
logger => cp_get_default_logger()
CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s, matrix_ks=matrix_ks, &
particle_set=particle_set, atomic_kind_set=atomic_kind_set, &
qs_kind_set=qs_kind_set, mos=mos, para_env=para_env)
wfn_mix_section => section_vals_get_subs_vals(dft_section, "PRINT%WFN_MIX")
CALL get_mo_set(mos(1), mo_coeff=mo_coeff, nao=nao)
CALL cp_fm_struct_create(fmstruct=ao_ao_fmstruct, nrow_global=nao, ncol_global=nao, &
template_fmstruct=mo_coeff%matrix_struct)
CALL cp_fm_create(S_tmp, matrix_struct=ao_ao_fmstruct)
CALL cp_fm_create(KS_tmp, matrix_struct=ao_ao_fmstruct)
CALL cp_fm_create(MO_tmp, matrix_struct=ao_ao_fmstruct)
CALL cp_fm_create(work, matrix_struct=ao_ao_fmstruct)
ALLOCATE (lumos(SIZE(mos)))
CALL copy_dbcsr_to_fm(matrix_s(1)%matrix, S_tmp)
CALL cp_fm_cholesky_decompose(S_tmp)
DO ispin = 1, SIZE(mos)
CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, eigenvalues=mo_eigenvalues, nmo=nmo)
CALL cp_fm_struct_create(fmstruct=ao_lumo_struct, nrow_global=nao, ncol_global=nao - nmo, &
template_fmstruct=mo_coeff%matrix_struct)
CALL cp_fm_create(lumos(ispin), matrix_struct=ao_lumo_struct)
CALL copy_dbcsr_to_fm(matrix_ks(ispin)%matrix, KS_tmp)
CALL cp_fm_cholesky_reduce(KS_tmp, S_tmp)
CALL choose_eigv_solver(KS_tmp, work, mo_eigenvalues)
CALL cp_fm_cholesky_restore(work, nao, S_tmp, MO_tmp, "SOLVE")
CALL cp_fm_to_fm_submat(MO_tmp, mo_coeff, nao, nmo, 1, 1, 1, 1)
CALL cp_fm_to_fm_submat(MO_tmp, lumos(ispin), nao, nao - nmo, 1, nmo + 1, 1, 1)
CALL cp_fm_struct_release(ao_lumo_struct)
END DO
output_unit = cp_logger_get_default_io_unit(logger)
CALL wfn_mix(mos, particle_set, dft_section, qs_kind_set, para_env, output_unit, &
unoccupied_orbs=lumos, scf_env=scf_env, matrix_s=matrix_s)
CALL cp_fm_release(lumos)
CALL cp_fm_release(S_tmp)
CALL cp_fm_release(MO_tmp)
CALL cp_fm_release(KS_tmp)
CALL cp_fm_release(work)
CALL cp_fm_struct_release(ao_ao_fmstruct)
END SUBROUTINE wfn_mix_tb
! **************************************************************************************************
!> \brief Gets the lumos, and eigenvalues for the lumos
!> \param qs_env ...
!> \param scf_env ...
!> \param unoccupied_orbs ...
!> \param unoccupied_evals ...
!> \param nlumo ...
!> \param nlumos ...
! **************************************************************************************************
SUBROUTINE make_lumo_tb(qs_env, scf_env, unoccupied_orbs, unoccupied_evals, nlumo, nlumos)
TYPE(qs_environment_type), POINTER :: qs_env
TYPE(qs_scf_env_type), POINTER :: scf_env
TYPE(cp_fm_type), DIMENSION(:), POINTER :: unoccupied_orbs
TYPE(cp_1d_r_p_type), DIMENSION(:), INTENT(INOUT) :: unoccupied_evals
INTEGER :: nlumo
INTEGER, INTENT(OUT) :: nlumos
INTEGER :: homo, iounit, ispin, n, nao, nmo
TYPE(cp_blacs_env_type), POINTER :: blacs_env
TYPE(cp_fm_struct_type), POINTER :: fm_struct_tmp
TYPE(cp_fm_type), POINTER :: mo_coeff
TYPE(cp_logger_type), POINTER :: logger
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, matrix_s
TYPE(dft_control_type), POINTER :: dft_control
TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(preconditioner_type), POINTER :: local_preconditioner
TYPE(scf_control_type), POINTER :: scf_control
NULLIFY (mos, ks_rmpv, scf_control, dft_control, para_env, blacs_env)
CALL get_qs_env(qs_env, &
mos=mos, &
matrix_ks=ks_rmpv, &
scf_control=scf_control, &
dft_control=dft_control, &
matrix_s=matrix_s, &
para_env=para_env, &
blacs_env=blacs_env)
logger => cp_get_default_logger()
iounit = cp_logger_get_default_io_unit(logger)
DO ispin = 1, dft_control%nspins
NULLIFY (unoccupied_evals(ispin)%array)
! Always write eigenvalues
IF (iounit > 0) WRITE (iounit, *) " "
IF (iounit > 0) WRITE (iounit, *) " Lowest Eigenvalues of the unoccupied subspace spin ", ispin
IF (iounit > 0) WRITE (iounit, FMT='(1X,A)') "-----------------------------------------------------"
CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, homo=homo, nao=nao, nmo=nmo)
CALL cp_fm_get_info(mo_coeff, nrow_global=n)
nlumos = MAX(1, MIN(nlumo, nao - nmo))
IF (nlumo == -1) nlumos = nao - nmo
ALLOCATE (unoccupied_evals(ispin)%array(nlumos))
CALL cp_fm_struct_create(fm_struct_tmp, para_env=para_env, context=blacs_env, &
nrow_global=n, ncol_global=nlumos)
CALL cp_fm_create(unoccupied_orbs(ispin), fm_struct_tmp, name="lumos")
CALL cp_fm_struct_release(fm_struct_tmp)
CALL cp_fm_init_random(unoccupied_orbs(ispin), nlumos)
! the full_all preconditioner makes not much sense for lumos search
NULLIFY (local_preconditioner)
IF (ASSOCIATED(scf_env%ot_preconditioner)) THEN
local_preconditioner => scf_env%ot_preconditioner(1)%preconditioner
! this one can for sure not be right (as it has to match a given C0)
IF (local_preconditioner%in_use == ot_precond_full_all) THEN
NULLIFY (local_preconditioner)
END IF
END IF
CALL ot_eigensolver(matrix_h=ks_rmpv(ispin)%matrix, matrix_s=matrix_s(1)%matrix, &
matrix_c_fm=unoccupied_orbs(ispin), &