-
Notifications
You must be signed in to change notification settings - Fork 1
/
qs_scf_post_gpw.F
3518 lines (3131 loc) · 177 KB
/
qs_scf_post_gpw.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 GPW/GAPW
!> \par History
!> Started as a copy from the relevant part of qs_scf
!> Start to adapt for k-points [07.2015, JGH]
!> \author Joost VandeVondele (10.2003)
! **************************************************************************************************
MODULE qs_scf_post_gpw
USE admm_types, ONLY: admm_type
USE admm_utils, ONLY: admm_correct_for_eigenvalues,&
admm_uncorrect_for_eigenvalues
USE ai_onecenter, ONLY: sg_overlap
USE atom_kind_orbitals, ONLY: calculate_atomic_density
USE atomic_kind_types, ONLY: atomic_kind_type,&
get_atomic_kind
USE basis_set_types, ONLY: gto_basis_set_p_type,&
gto_basis_set_type
USE cell_types, ONLY: cell_type
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_add,&
dbcsr_p_type,&
dbcsr_type
USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm,&
dbcsr_deallocate_matrix_set
USE cp_dbcsr_output, ONLY: cp_dbcsr_write_sparse_matrix
USE cp_ddapc_util, ONLY: get_ddapc
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,&
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 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 dct, ONLY: pw_shrink
USE ed_analysis, ONLY: edmf_analysis
USE eeq_method, ONLY: eeq_print
USE et_coupling_types, ONLY: set_et_coupling_type
USE hfx_ri, ONLY: print_ri_hfx
USE hirshfeld_methods, ONLY: comp_hirshfeld_charges,&
comp_hirshfeld_i_charges,&
create_shape_function,&
save_hirshfeld_charges,&
write_hirshfeld_charges
USE hirshfeld_types, ONLY: create_hirshfeld_type,&
hirshfeld_type,&
release_hirshfeld_type,&
set_hirshfeld_info
USE iao_analysis, ONLY: iao_wfn_analysis
USE iao_types, ONLY: iao_env_type,&
iao_read_input
USE input_constants, ONLY: &
do_loc_both, do_loc_homo, do_loc_jacobi, do_loc_lumo, do_loc_mixed, do_loc_none, &
ot_precond_full_all, radius_covalent, radius_user, ref_charge_atomic, ref_charge_mulliken
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 lapack, ONLY: lapack_sgesv
USE mao_wfn_analysis, ONLY: mao_analysis
USE mathconstants, ONLY: pi
USE memory_utilities, ONLY: reallocate
USE message_passing, ONLY: mp_para_env_type
USE minbas_wfn_analysis, ONLY: minbas_analysis
USE molden_utils, ONLY: write_mos_molden
USE molecule_types, ONLY: molecule_type
USE mulliken, ONLY: mulliken_charges
USE orbital_pointers, ONLY: indso
USE particle_list_types, ONLY: particle_list_type
USE particle_types, ONLY: particle_type
USE physcon, ONLY: angstrom,&
evolt
USE population_analyses, ONLY: lowdin_population_analysis,&
mulliken_population_analysis
USE preconditioner_types, ONLY: preconditioner_type
USE ps_implicit_types, ONLY: MIXED_BC,&
MIXED_PERIODIC_BC,&
NEUMANN_BC,&
PERIODIC_BC
USE pw_env_types, ONLY: pw_env_get,&
pw_env_type
USE pw_grids, ONLY: get_pw_grid_info
USE pw_methods, ONLY: pw_axpy,&
pw_copy,&
pw_derive,&
pw_integrate_function,&
pw_scale,&
pw_transfer,&
pw_zero
USE pw_poisson_methods, ONLY: pw_poisson_solve
USE pw_poisson_types, ONLY: pw_poisson_implicit,&
pw_poisson_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_chargemol, ONLY: write_wfx
USE qs_collocate_density, ONLY: calculate_rho_resp_all,&
calculate_wavefunction
USE qs_commutators, ONLY: build_com_hr_matrix
USE qs_core_energies, ONLY: calculate_ptrace
USE qs_dos, ONLY: calculate_dos,&
calculate_dos_kp
USE qs_electric_field_gradient, ONLY: qs_efg_calc
USE qs_elf_methods, ONLY: qs_elf_calc
USE qs_energy_types, ONLY: qs_energy_type
USE qs_energy_window, ONLY: energy_windows
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type,&
set_qs_env
USE qs_epr_hyp, ONLY: qs_epr_hyp_calc
USE qs_grid_atom, ONLY: grid_atom_type
USE qs_integral_utils, ONLY: basis_set_list_setup
USE qs_kind_types, ONLY: get_qs_kind,&
qs_kind_type
USE qs_ks_methods, ONLY: calc_rho_tot_gspace,&
qs_ks_update_qs_env
USE qs_ks_types, ONLY: qs_ks_did_change
USE qs_loc_dipole, ONLY: loc_dipole
USE qs_loc_states, ONLY: get_localization_info
USE qs_loc_types, ONLY: qs_loc_env_create,&
qs_loc_env_release,&
qs_loc_env_type
USE qs_loc_utils, ONLY: loc_write_restart,&
qs_loc_control_init,&
qs_loc_env_init,&
qs_loc_init,&
retain_history
USE qs_local_properties, ONLY: qs_local_energy,&
qs_local_stress
USE qs_mo_io, ONLY: write_dm_binary_restart
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_moments, ONLY: qs_moment_berry_phase,&
qs_moment_locop
USE qs_neighbor_list_types, ONLY: get_iterator_info,&
get_neighbor_list_set_p,&
neighbor_list_iterate,&
neighbor_list_iterator_create,&
neighbor_list_iterator_p_type,&
neighbor_list_iterator_release,&
neighbor_list_set_p_type
USE qs_ot_eigensolver, ONLY: ot_eigensolver
USE qs_pdos, ONLY: calculate_projected_dos
USE qs_resp, ONLY: resp_fit
USE qs_rho0_types, ONLY: get_rho0_mpole,&
mpole_rho_atom,&
rho0_mpole_type
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_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 qs_wannier90, ONLY: wannier90_interface
USE s_square_methods, ONLY: compute_s_square
USE scf_control_types, ONLY: scf_control_type
USE stm_images, ONLY: th_stm_image
USE transport, ONLY: qs_scf_post_transport
USE trexio_utils, ONLY: write_trexio
USE virial_types, ONLY: virial_type
USE voronoi_interface, ONLY: entry_voronoi_or_bqb
USE xray_diffraction, ONLY: calculate_rhotot_elec_gspace,&
xray_diffraction_spectrum
#include "./base/base_uses.f90"
IMPLICIT NONE
PRIVATE
! Global parameters
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_post_gpw'
PUBLIC :: scf_post_calculation_gpw, &
qs_scf_post_moments, &
write_mo_dependent_results, &
write_mo_free_results
PUBLIC :: make_lumo_gpw
! **************************************************************************************************
CONTAINS
! **************************************************************************************************
!> \brief collects possible post - scf calculations and prints info / computes properties.
!> \param qs_env the qs_env in which the qs_env lives
!> \param wf_type ...
!> \param do_mp2 ...
!> \par History
!> 02.2003 created [fawzi]
!> 10.2004 moved here from qs_scf [Joost VandeVondele]
!> started splitting out different subroutines
!> 10.2015 added header for wave-function correlated methods [Vladimir Rybkin]
!> \author fawzi
!> \note
!> this function changes mo_eigenvectors and mo_eigenvalues, depending on the print keys.
!> In particular, MO_CUBES causes the MOs to be rotated to make them eigenstates of the KS
!> matrix, and mo_eigenvalues is updated accordingly. This can, for unconverged wavefunctions,
!> change afterwards slightly the forces (hence small numerical differences between MD
!> with and without the debug print level). Ideally this should not happen...
! **************************************************************************************************
SUBROUTINE scf_post_calculation_gpw(qs_env, wf_type, do_mp2)
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(6), OPTIONAL :: wf_type
LOGICAL, OPTIONAL :: do_mp2
CHARACTER(len=*), PARAMETER :: routineN = 'scf_post_calculation_gpw'
INTEGER :: handle, homo, ispin, min_lumos, n_rep, nchk_nmoloc, nhomo, nlumo, nlumo_stm, &
nlumo_tddft, nlumos, nmo, nspins, output_unit, unit_nr
INTEGER, DIMENSION(:, :, :), POINTER :: marked_states
LOGICAL :: check_write, compute_lumos, do_homo, do_kpoints, do_mixed, do_mo_cubes, do_stm, &
do_wannier_cubes, has_homo, has_lumo, loc_explicit, loc_print_explicit, my_do_mp2, &
my_localized_wfn, p_loc, p_loc_homo, p_loc_lumo, p_loc_mixed
REAL(dp) :: e_kin
REAL(KIND=dp) :: gap, homo_lumo(2, 2), total_zeff_corr
REAL(KIND=dp), DIMENSION(:), POINTER :: mo_eigenvalues
TYPE(admm_type), POINTER :: admm_env
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER :: mixed_evals, occupied_evals, &
unoccupied_evals, unoccupied_evals_stm
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: mixed_orbs, occupied_orbs
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:), &
TARGET :: homo_localized, lumo_localized, &
mixed_localized
TYPE(cp_fm_type), DIMENSION(:), POINTER :: lumo_ptr, mo_loc_history, &
unoccupied_orbs, unoccupied_orbs_stm
TYPE(cp_fm_type), POINTER :: mo_coeff
TYPE(cp_logger_type), POINTER :: logger
TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_rmpv, matrix_p_mp2, matrix_s, &
mo_derivs
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: kinetic_m, rho_ao
TYPE(dft_control_type), POINTER :: dft_control
TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
TYPE(molecule_type), POINTER :: molecule_set(:)
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(particle_list_type), POINTER :: particles
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(pw_c1d_gs_type) :: wf_g
TYPE(pw_env_type), POINTER :: pw_env
TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
TYPE(pw_r3d_rs_type) :: wf_r
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(qs_loc_env_type), POINTER :: qs_loc_env_homo, qs_loc_env_lumo, &
qs_loc_env_mixed
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, input, loc_print_section, &
localize_section, print_key, &
stm_section
CALL timeset(routineN, handle)
logger => cp_get_default_logger()
output_unit = cp_logger_get_default_io_unit(logger)
! Print out the type of wavefunction to distinguish between SCF and post-SCF
my_do_mp2 = .FALSE.
IF (PRESENT(do_mp2)) my_do_mp2 = do_mp2
IF (PRESENT(wf_type)) THEN
IF (output_unit > 0) THEN
WRITE (UNIT=output_unit, FMT='(/,(T1,A))') REPEAT("-", 40)
WRITE (UNIT=output_unit, FMT='(/,(T3,A,T19,A,T25,A))') "Properties from ", wf_type, " density"
WRITE (UNIT=output_unit, FMT='(/,(T1,A))') REPEAT("-", 40)
END IF
END IF
! Writes the data that is already available in qs_env
CALL get_qs_env(qs_env, scf_env=scf_env)
my_localized_wfn = .FALSE.
NULLIFY (admm_env, dft_control, pw_env, auxbas_pw_pool, pw_pools, mos, rho, &
mo_coeff, ks_rmpv, matrix_s, qs_loc_env_homo, qs_loc_env_lumo, scf_control, &
unoccupied_orbs, mo_eigenvalues, unoccupied_evals, &
unoccupied_evals_stm, molecule_set, mo_derivs, &
subsys, particles, input, print_key, kinetic_m, marked_states, &
mixed_evals, qs_loc_env_mixed)
NULLIFY (lumo_ptr, rho_ao)
has_homo = .FALSE.
has_lumo = .FALSE.
p_loc = .FALSE.
p_loc_homo = .FALSE.
p_loc_lumo = .FALSE.
p_loc_mixed = .FALSE.
CPASSERT(ASSOCIATED(scf_env))
CPASSERT(ASSOCIATED(qs_env))
! Here we start with data that needs a postprocessing...
CALL get_qs_env(qs_env, &
dft_control=dft_control, &
molecule_set=molecule_set, &
scf_control=scf_control, &
do_kpoints=do_kpoints, &
input=input, &
subsys=subsys, &
rho=rho, &
pw_env=pw_env, &
particle_set=particle_set, &
atomic_kind_set=atomic_kind_set, &
qs_kind_set=qs_kind_set)
CALL qs_subsys_get(subsys, particles=particles)
CALL qs_rho_get(rho, rho_ao_kp=rho_ao)
IF (my_do_mp2) THEN
! Get the HF+MP2 density
CALL get_qs_env(qs_env, matrix_p_mp2=matrix_p_mp2)
DO ispin = 1, dft_control%nspins
CALL dbcsr_add(rho_ao(ispin, 1)%matrix, matrix_p_mp2(ispin)%matrix, 1.0_dp, 1.0_dp)
END DO
CALL qs_rho_update_rho(rho, qs_env=qs_env)
CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.TRUE.)
! In MP2 case update the Hartree potential
CALL update_hartree_with_mp2(rho, qs_env)
END IF
CALL write_available_results(qs_env, scf_env)
! **** the kinetic energy
IF (cp_print_key_should_output(logger%iter_info, input, &
"DFT%PRINT%KINETIC_ENERGY") /= 0) THEN
CALL get_qs_env(qs_env, kinetic_kp=kinetic_m)
CPASSERT(ASSOCIATED(kinetic_m))
CPASSERT(ASSOCIATED(kinetic_m(1, 1)%matrix))
CALL calculate_ptrace(kinetic_m, rho_ao, e_kin, dft_control%nspins)
unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%KINETIC_ENERGY", &
extension=".Log")
IF (unit_nr > 0) THEN
WRITE (unit_nr, '(T3,A,T55,F25.14)') "Electronic kinetic energy:", e_kin
END IF
CALL cp_print_key_finished_output(unit_nr, logger, input, &
"DFT%PRINT%KINETIC_ENERGY")
END IF
! Atomic Charges that require further computation
CALL qs_scf_post_charges(input, logger, qs_env)
! Moments of charge distribution
CALL qs_scf_post_moments(input, logger, qs_env, output_unit)
! Determine if we need to computer properties using the localized centers
dft_section => section_vals_get_subs_vals(input, "DFT")
localize_section => section_vals_get_subs_vals(dft_section, "LOCALIZE")
loc_print_section => section_vals_get_subs_vals(localize_section, "PRINT")
CALL section_vals_get(localize_section, explicit=loc_explicit)
CALL section_vals_get(loc_print_section, explicit=loc_print_explicit)
! Print_keys controlled by localization
IF (loc_print_explicit) THEN
print_key => section_vals_get_subs_vals(loc_print_section, "MOLECULAR_DIPOLES")
p_loc = BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
print_key => section_vals_get_subs_vals(loc_print_section, "TOTAL_DIPOLE")
p_loc = p_loc .OR. BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_CENTERS")
p_loc = p_loc .OR. BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_SPREADS")
p_loc = p_loc .OR. BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_CUBES")
p_loc = p_loc .OR. BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
print_key => section_vals_get_subs_vals(loc_print_section, "MOLECULAR_STATES")
p_loc = p_loc .OR. BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
print_key => section_vals_get_subs_vals(loc_print_section, "MOLECULAR_MOMENTS")
p_loc = p_loc .OR. BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
print_key => section_vals_get_subs_vals(loc_print_section, "WANNIER_STATES")
p_loc = p_loc .OR. BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)
ELSE
p_loc = .FALSE.
END IF
IF (loc_explicit) THEN
p_loc_homo = (section_get_ival(localize_section, "STATES") == do_loc_homo .OR. &
section_get_ival(localize_section, "STATES") == do_loc_both) .AND. p_loc
p_loc_lumo = (section_get_ival(localize_section, "STATES") == do_loc_lumo .OR. &
section_get_ival(localize_section, "STATES") == do_loc_both) .AND. p_loc
p_loc_mixed = (section_get_ival(localize_section, "STATES") == do_loc_mixed) .AND. p_loc
CALL section_vals_val_get(localize_section, "LIST_UNOCCUPIED", n_rep_val=n_rep)
ELSE
p_loc_homo = .FALSE.
p_loc_lumo = .FALSE.
p_loc_mixed = .FALSE.
n_rep = 0
END IF
IF (n_rep == 0 .AND. p_loc_lumo) THEN
CALL cp_abort(__LOCATION__, "No LIST_UNOCCUPIED was specified, "// &
"therefore localization of unoccupied states will be skipped!")
p_loc_lumo = .FALSE.
END IF
! Control for STM
stm_section => section_vals_get_subs_vals(input, "DFT%PRINT%STM")
CALL section_vals_get(stm_section, explicit=do_stm)
nlumo_stm = 0
IF (do_stm) nlumo_stm = section_get_ival(stm_section, "NLUMO")
! check for CUBES (MOs and WANNIERS)
do_mo_cubes = BTEST(cp_print_key_should_output(logger%iter_info, dft_section, "PRINT%MO_CUBES") &
, cp_p_file)
IF (loc_print_explicit) THEN
do_wannier_cubes = BTEST(cp_print_key_should_output(logger%iter_info, loc_print_section, &
"WANNIER_CUBES"), cp_p_file)
ELSE
do_wannier_cubes = .FALSE.
END IF
nlumo = section_get_ival(dft_section, "PRINT%MO_CUBES%NLUMO")
nhomo = section_get_ival(dft_section, "PRINT%MO_CUBES%NHOMO")
nlumo_tddft = 0
IF (dft_control%do_tddfpt_calculation) THEN
nlumo_tddft = section_get_ival(dft_section, "TDDFPT%NLUMO")
END IF
! Setup the grids needed to compute a wavefunction given a vector..
IF (((do_mo_cubes .OR. do_wannier_cubes) .AND. (nlumo /= 0 .OR. nhomo /= 0)) .OR. p_loc) THEN
CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
pw_pools=pw_pools)
CALL auxbas_pw_pool%create_pw(wf_r)
CALL auxbas_pw_pool%create_pw(wf_g)
END IF
IF (dft_control%restricted) THEN
!For ROKS usefull only first term
nspins = 1
ELSE
nspins = dft_control%nspins
END IF
!Some info about ROKS
IF (dft_control%restricted .AND. (do_mo_cubes .OR. p_loc_homo)) THEN
CALL cp_abort(__LOCATION__, "Unclear how we define MOs / localization in the restricted case ... ")
! It is possible to obtain Wannier centers for ROKS without rotations for SINGLE OCCUPIED ORBITALS
END IF
! Makes the MOs eigenstates, computes eigenvalues, write cubes
IF (do_kpoints) THEN
CPWARN_IF(do_mo_cubes, "Print MO cubes not implemented for k-point calculations")
ELSE
CALL get_qs_env(qs_env, &
mos=mos, &
matrix_ks=ks_rmpv)
IF ((do_mo_cubes .AND. nhomo /= 0) .OR. do_stm .OR. dft_control%do_tddfpt_calculation) THEN
CALL get_qs_env(qs_env, mo_derivs=mo_derivs)
IF (dft_control%do_admm) THEN
CALL get_qs_env(qs_env, admm_env=admm_env)
CALL make_mo_eig(mos, nspins, ks_rmpv, scf_control, mo_derivs, admm_env=admm_env)
ELSE
CALL make_mo_eig(mos, nspins, ks_rmpv, scf_control, mo_derivs)
END IF
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.
END IF
IF (do_mo_cubes .AND. nhomo /= 0) THEN
DO ispin = 1, nspins
! Prints the cube files of OCCUPIED ORBITALS
CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
eigenvalues=mo_eigenvalues, homo=homo, nmo=nmo)
CALL qs_scf_post_occ_cubes(input, dft_section, dft_control, logger, qs_env, &
mo_coeff, wf_g, wf_r, particles, homo, ispin)
END DO
END IF
END IF
! Initialize the localization environment, needed e.g. for wannier functions and molecular states
! Gets localization info for the occupied orbs
! - Possibly gets wannier functions
! - Possibly gets molecular states
IF (p_loc_homo) THEN
IF (do_kpoints) THEN
CPWARN("Localization not implemented for k-point calculations!")
ELSEIF (dft_control%restricted &
.AND. (section_get_ival(localize_section, "METHOD") .NE. do_loc_none) &
.AND. (section_get_ival(localize_section, "METHOD") .NE. do_loc_jacobi)) THEN
CPABORT("ROKS works only with LOCALIZE METHOD NONE or JACOBI")
ELSE
ALLOCATE (occupied_orbs(dft_control%nspins))
ALLOCATE (occupied_evals(dft_control%nspins))
ALLOCATE (homo_localized(dft_control%nspins))
DO ispin = 1, dft_control%nspins
CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
eigenvalues=mo_eigenvalues)
occupied_orbs(ispin) = mo_coeff
occupied_evals(ispin)%array => mo_eigenvalues
CALL cp_fm_create(homo_localized(ispin), occupied_orbs(ispin)%matrix_struct)
CALL cp_fm_to_fm(occupied_orbs(ispin), homo_localized(ispin))
END DO
CALL get_qs_env(qs_env, mo_loc_history=mo_loc_history)
do_homo = .TRUE.
ALLOCATE (qs_loc_env_homo)
CALL qs_loc_env_create(qs_loc_env_homo)
CALL qs_loc_control_init(qs_loc_env_homo, localize_section, do_homo=do_homo)
CALL qs_loc_init(qs_env, qs_loc_env_homo, localize_section, homo_localized, do_homo, &
do_mo_cubes, mo_loc_history=mo_loc_history)
CALL get_localization_info(qs_env, qs_loc_env_homo, localize_section, homo_localized, &
wf_r, wf_g, particles, occupied_orbs, occupied_evals, marked_states)
!retain the homo_localized for future use
IF (qs_loc_env_homo%localized_wfn_control%use_history) THEN
CALL retain_history(mo_loc_history, homo_localized)
CALL set_qs_env(qs_env, mo_loc_history=mo_loc_history)
END IF
!write restart for localization of occupied orbitals
CALL loc_write_restart(qs_loc_env_homo, loc_print_section, mos, &
homo_localized, do_homo)
CALL cp_fm_release(homo_localized)
DEALLOCATE (occupied_orbs)
DEALLOCATE (occupied_evals)
! Print Total Dipole if the localization has been performed
IF (qs_loc_env_homo%do_localize) THEN
CALL loc_dipole(input, dft_control, qs_loc_env_homo, logger, qs_env)
END IF
END IF
END IF
! Gets the lumos, and eigenvalues for the lumos, and localize them if requested
IF (do_kpoints) THEN
IF (do_mo_cubes .OR. p_loc_lumo) THEN
! nothing at the moment, not implemented
CPWARN("Localization and MO related output not implemented for k-point calculations!")
END IF
ELSE
IF (nlumo .GT. -1) THEN
nlumo = MAX(nlumo, nlumo_tddft)
END IF
compute_lumos = (do_mo_cubes .OR. dft_control%do_tddfpt_calculation) .AND. nlumo .NE. 0
compute_lumos = compute_lumos .OR. p_loc_lumo
DO ispin = 1, dft_control%nspins
CALL get_mo_set(mo_set=mos(ispin), homo=homo, nmo=nmo)
compute_lumos = compute_lumos .AND. homo == nmo
END DO
IF (do_mo_cubes .AND. .NOT. compute_lumos) THEN
nlumo = section_get_ival(dft_section, "PRINT%MO_CUBES%NLUMO")
DO ispin = 1, dft_control%nspins
CALL get_mo_set(mo_set=mos(ispin), homo=homo, nmo=nmo, eigenvalues=mo_eigenvalues)
IF (nlumo > nmo - homo) THEN
! this case not yet implemented
ELSE
IF (nlumo .EQ. -1) THEN
nlumo = nmo - homo
END IF
IF (output_unit > 0) WRITE (output_unit, *) " "
IF (output_unit > 0) WRITE (output_unit, *) " Lowest eigenvalues of the unoccupied subspace spin ", ispin
IF (output_unit > 0) WRITE (output_unit, *) "---------------------------------------------"
IF (output_unit > 0) WRITE (output_unit, '(4(1X,1F16.8))') mo_eigenvalues(homo + 1:homo + nlumo)
! Prints the cube files of UNOCCUPIED ORBITALS
CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
CALL qs_scf_post_unocc_cubes(input, dft_section, dft_control, logger, qs_env, &
mo_coeff, wf_g, wf_r, particles, nlumo, homo, ispin, lumo=homo + 1)
END IF
END DO
END IF
IF (compute_lumos) THEN
check_write = .TRUE.
min_lumos = nlumo
IF (nlumo == 0) check_write = .FALSE.
IF (p_loc_lumo) THEN
do_homo = .FALSE.
ALLOCATE (qs_loc_env_lumo)
CALL qs_loc_env_create(qs_loc_env_lumo)
CALL qs_loc_control_init(qs_loc_env_lumo, localize_section, do_homo=do_homo)
min_lumos = MAX(MAXVAL(qs_loc_env_lumo%localized_wfn_control%loc_states(:, :)), nlumo)
END IF
ALLOCATE (unoccupied_orbs(dft_control%nspins))
ALLOCATE (unoccupied_evals(dft_control%nspins))
CALL make_lumo_gpw(qs_env, scf_env, unoccupied_orbs, unoccupied_evals, min_lumos, nlumos)
lumo_ptr => unoccupied_orbs
DO ispin = 1, dft_control%nspins
has_lumo = .TRUE.
homo_lumo(ispin, 2) = unoccupied_evals(ispin)%array(1)
CALL get_mo_set(mo_set=mos(ispin), homo=homo)
IF (check_write) THEN
IF (p_loc_lumo .AND. nlumo .NE. -1) nlumos = MIN(nlumo, nlumos)
! Prints the cube files of UNOCCUPIED ORBITALS
CALL qs_scf_post_unocc_cubes(input, dft_section, dft_control, logger, qs_env, &
unoccupied_orbs(ispin), wf_g, wf_r, particles, nlumos, homo, ispin)
END IF
END DO
! Save the info for tddfpt calculation
IF (dft_control%do_tddfpt_calculation) THEN
ALLOCATE (dft_control%tddfpt_control%lumos_eigenvalues(nlumos, dft_control%nspins))
DO ispin = 1, dft_control%nspins
dft_control%tddfpt_control%lumos_eigenvalues(1:nlumos, ispin) = &
unoccupied_evals(ispin)%array(1:nlumos)
END DO
dft_control%tddfpt_control%lumos => unoccupied_orbs
END IF
IF (p_loc_lumo) THEN
ALLOCATE (lumo_localized(dft_control%nspins))
DO ispin = 1, dft_control%nspins
CALL cp_fm_create(lumo_localized(ispin), unoccupied_orbs(ispin)%matrix_struct)
CALL cp_fm_to_fm(unoccupied_orbs(ispin), lumo_localized(ispin))
END DO
CALL qs_loc_init(qs_env, qs_loc_env_lumo, localize_section, lumo_localized, do_homo, do_mo_cubes, &
evals=unoccupied_evals)
CALL qs_loc_env_init(qs_loc_env_lumo, qs_loc_env_lumo%localized_wfn_control, qs_env, &
loc_coeff=unoccupied_orbs)
CALL get_localization_info(qs_env, qs_loc_env_lumo, localize_section, &
lumo_localized, wf_r, wf_g, particles, &
unoccupied_orbs, unoccupied_evals, marked_states)
CALL loc_write_restart(qs_loc_env_lumo, loc_print_section, mos, homo_localized, do_homo, &
evals=unoccupied_evals)
lumo_ptr => lumo_localized
END IF
END IF
IF (has_homo .AND. has_lumo) THEN
IF (output_unit > 0) WRITE (output_unit, *) " "
DO ispin = 1, dft_control%nspins
IF (.NOT. scf_control%smear%do_smear) THEN
gap = homo_lumo(ispin, 2) - homo_lumo(ispin, 1)
IF (output_unit > 0) WRITE (output_unit, '(T2,A,F12.6)') &
"HOMO - LUMO gap [eV] :", gap*evolt
END IF
END DO
END IF
END IF
IF (p_loc_mixed) THEN
IF (do_kpoints) THEN
CPWARN("Localization not implemented for k-point calculations!")
ELSEIF (dft_control%restricted) THEN
IF (output_unit > 0) WRITE (output_unit, *) &
" Unclear how we define MOs / localization in the restricted case... skipping"
ELSE
ALLOCATE (mixed_orbs(dft_control%nspins))
ALLOCATE (mixed_evals(dft_control%nspins))
ALLOCATE (mixed_localized(dft_control%nspins))
DO ispin = 1, dft_control%nspins
CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, &
eigenvalues=mo_eigenvalues)
mixed_orbs(ispin) = mo_coeff
mixed_evals(ispin)%array => mo_eigenvalues
CALL cp_fm_create(mixed_localized(ispin), mixed_orbs(ispin)%matrix_struct)
CALL cp_fm_to_fm(mixed_orbs(ispin), mixed_localized(ispin))
END DO
CALL get_qs_env(qs_env, mo_loc_history=mo_loc_history)
do_homo = .FALSE.
do_mixed = .TRUE.
total_zeff_corr = scf_env%sum_zeff_corr
ALLOCATE (qs_loc_env_mixed)
CALL qs_loc_env_create(qs_loc_env_mixed)
CALL qs_loc_control_init(qs_loc_env_mixed, localize_section, do_homo=do_homo, do_mixed=do_mixed)
CALL qs_loc_init(qs_env, qs_loc_env_mixed, localize_section, mixed_localized, do_homo, &
do_mo_cubes, mo_loc_history=mo_loc_history, tot_zeff_corr=total_zeff_corr, &
do_mixed=do_mixed)
DO ispin = 1, dft_control%nspins
CALL cp_fm_get_info(mixed_localized(ispin), ncol_global=nchk_nmoloc)
END DO
CALL get_localization_info(qs_env, qs_loc_env_mixed, localize_section, mixed_localized, &
wf_r, wf_g, particles, mixed_orbs, mixed_evals, marked_states)
!retain the homo_localized for future use
IF (qs_loc_env_mixed%localized_wfn_control%use_history) THEN
CALL retain_history(mo_loc_history, mixed_localized)
CALL set_qs_env(qs_env, mo_loc_history=mo_loc_history)
END IF
!write restart for localization of occupied orbitals
CALL loc_write_restart(qs_loc_env_mixed, loc_print_section, mos, &
mixed_localized, do_homo, do_mixed=do_mixed)
CALL cp_fm_release(mixed_localized)
DEALLOCATE (mixed_orbs)
DEALLOCATE (mixed_evals)
! Print Total Dipole if the localization has been performed
! Revisit the formalism later
!IF (qs_loc_env_mixed%do_localize) THEN
! CALL loc_dipole(input, dft_control, qs_loc_env_mixed, logger, qs_env)
!END IF
END IF
END IF
! Deallocate grids needed to compute wavefunctions
IF (((do_mo_cubes .OR. do_wannier_cubes) .AND. (nlumo /= 0 .OR. nhomo /= 0)) .OR. p_loc) THEN
CALL auxbas_pw_pool%give_back_pw(wf_r)
CALL auxbas_pw_pool%give_back_pw(wf_g)
END IF
! Destroy the localization environment
IF (.NOT. do_kpoints) THEN
IF (p_loc_homo) THEN
CALL qs_loc_env_release(qs_loc_env_homo)
DEALLOCATE (qs_loc_env_homo)
END IF
IF (p_loc_lumo) THEN
CALL qs_loc_env_release(qs_loc_env_lumo)
DEALLOCATE (qs_loc_env_lumo)
END IF
IF (p_loc_mixed) THEN
CALL qs_loc_env_release(qs_loc_env_mixed)
DEALLOCATE (qs_loc_env_mixed)
END IF
END IF
! generate a mix of wfns, and write to a restart
IF (do_kpoints) THEN
! nothing at the moment, not implemented
ELSE
CALL get_qs_env(qs_env, matrix_s=matrix_s, para_env=para_env)
CALL wfn_mix(mos, particle_set, dft_section, qs_kind_set, para_env, &
output_unit, unoccupied_orbs=lumo_ptr, scf_env=scf_env, &
matrix_s=matrix_s, marked_states=marked_states)
IF (p_loc_lumo) CALL cp_fm_release(lumo_localized)
END IF
IF (ASSOCIATED(marked_states)) THEN
DEALLOCATE (marked_states)
END IF
! This is just a deallocation for printing MO_CUBES or TDDFPT
IF (.NOT. do_kpoints) THEN
IF (compute_lumos) THEN
DO ispin = 1, dft_control%nspins
DEALLOCATE (unoccupied_evals(ispin)%array)
IF (.NOT. dft_control%do_tddfpt_calculation) THEN
CALL cp_fm_release(unoccupied_orbs(ispin))
END IF
END DO
DEALLOCATE (unoccupied_evals)
IF (.NOT. dft_control%do_tddfpt_calculation) THEN
DEALLOCATE (unoccupied_orbs)
END IF
END IF
END IF
!stm images
IF (do_stm) THEN
IF (do_kpoints) THEN
CPWARN("STM not implemented for k-point calculations!")
ELSE
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_gpw(qs_env, scf_env, unoccupied_orbs_stm, unoccupied_evals_stm, &
nlumo_stm, nlumos)
END IF
CALL th_stm_image(qs_env, stm_section, 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
! Print coherent X-ray diffraction spectrum
CALL qs_scf_post_xray(input, dft_section, logger, qs_env, output_unit)
! Calculation of Electric Field Gradients
CALL qs_scf_post_efg(input, logger, qs_env)
! Calculation of ET
CALL qs_scf_post_et(input, qs_env, dft_control)
! Calculation of EPR Hyperfine Coupling Tensors
CALL qs_scf_post_epr(input, logger, qs_env)
! Calculation of properties needed for BASIS_MOLOPT optimizations
CALL qs_scf_post_molopt(input, logger, qs_env)
! Calculate ELF
CALL qs_scf_post_elf(input, logger, qs_env)
! Use Wannier90 interface
CALL wannier90_interface(input, logger, qs_env)
IF (my_do_mp2) THEN
! Get everything back
DO ispin = 1, dft_control%nspins
CALL dbcsr_add(rho_ao(ispin, 1)%matrix, matrix_p_mp2(ispin)%matrix, 1.0_dp, -1.0_dp)
END DO
CALL qs_rho_update_rho(rho, qs_env=qs_env)
CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.TRUE.)
END IF
CALL timestop(handle)
END SUBROUTINE scf_post_calculation_gpw
! **************************************************************************************************
!> \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_gpw(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(:), INTENT(INOUT) :: unoccupied_orbs
TYPE(cp_1d_r_p_type), DIMENSION(:), POINTER :: unoccupied_evals
INTEGER, INTENT(IN) :: nlumo
INTEGER, INTENT(OUT) :: nlumos
CHARACTER(len=*), PARAMETER :: routineN = 'make_lumo_gpw'
INTEGER :: handle, homo, ispin, n, nao, nmo, &
output_unit
TYPE(admm_type), POINTER :: admm_env
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
CALL timeset(routineN, handle)
NULLIFY (mos, ks_rmpv, scf_control, dft_control, admm_env, 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, &
admm_env=admm_env, &
para_env=para_env, &
blacs_env=blacs_env)
logger => cp_get_default_logger()
output_unit = cp_logger_get_default_io_unit(logger)
DO ispin = 1, dft_control%nspins
NULLIFY (unoccupied_evals(ispin)%array)
! Always write eigenvalues
IF (output_unit > 0) WRITE (output_unit, *) " "
IF (output_unit > 0) WRITE (output_unit, *) " Lowest Eigenvalues of the unoccupied subspace spin ", ispin
IF (output_unit > 0) WRITE (output_unit, 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
! ** If we do ADMM, we add have to modify the kohn-sham matrix
IF (dft_control%do_admm) THEN
CALL admm_correct_for_eigenvalues(ispin, admm_env, ks_rmpv(ispin)%matrix)
END IF
CALL ot_eigensolver(matrix_h=ks_rmpv(ispin)%matrix, matrix_s=matrix_s(1)%matrix, &
matrix_c_fm=unoccupied_orbs(ispin), &
matrix_orthogonal_space_fm=mo_coeff, &
eps_gradient=scf_control%eps_lumos, &
preconditioner=local_preconditioner, &
iter_max=scf_control%max_iter_lumos, &
size_ortho_space=nmo)
CALL calculate_subspace_eigenvalues(unoccupied_orbs(ispin), ks_rmpv(ispin)%matrix, &
unoccupied_evals(ispin)%array, scr=output_unit, &
ionode=output_unit > 0)
! ** If we do ADMM, we restore the original kohn-sham matrix
IF (dft_control%do_admm) THEN
CALL admm_uncorrect_for_eigenvalues(ispin, admm_env, ks_rmpv(ispin)%matrix)
END IF
END DO
CALL timestop(handle)
END SUBROUTINE make_lumo_gpw
! **************************************************************************************************
!> \brief Computes and Prints Atomic Charges with several methods
!> \param input ...
!> \param logger ...
!> \param qs_env the qs_env in which the qs_env lives
! **************************************************************************************************
SUBROUTINE qs_scf_post_charges(input, logger, qs_env)
TYPE(section_vals_type), POINTER :: input
TYPE(cp_logger_type), POINTER :: logger
TYPE(qs_environment_type), POINTER :: qs_env
CHARACTER(len=*), PARAMETER :: routineN = 'qs_scf_post_charges'
INTEGER :: handle, print_level, unit_nr
LOGICAL :: do_kpoints, print_it
TYPE(section_vals_type), POINTER :: density_fit_section, print_key
CALL timeset(routineN, handle)
CALL get_qs_env(qs_env=qs_env, do_kpoints=do_kpoints)
! Mulliken charges require no further computation and are printed from write_mo_free_results
! Compute the Lowdin charges
print_key => section_vals_get_subs_vals(input, "DFT%PRINT%LOWDIN")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
unit_nr = cp_print_key_unit_nr(logger, input, "DFT%PRINT%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, input, "DFT%PRINT%LOWDIN")
END IF
! Compute the RESP charges
CALL resp_fit(qs_env)
! Compute the Density Derived Atomic Point charges with the Bloechl scheme
print_key => section_vals_get_subs_vals(input, "PROPERTIES%FIT_CHARGE")
IF (BTEST(cp_print_key_should_output(logger%iter_info, print_key), cp_p_file)) THEN
unit_nr = cp_print_key_unit_nr(logger, input, "PROPERTIES%FIT_CHARGE", extension=".Fitcharge", &
log_filename=.FALSE.)
density_fit_section => section_vals_get_subs_vals(input, "DFT%DENSITY_FITTING")
CALL get_ddapc(qs_env, .FALSE., density_fit_section, iwc=unit_nr)
CALL cp_print_key_finished_output(unit_nr, logger, input, "PROPERTIES%FIT_CHARGE")
END IF
CALL timestop(handle)