Commit fa14bdd
DFT+U Refactor (#7538)
* format dftu_io.cpp
* update output formats of DFT+U
* update dftu, remove PARAM
* fix read_occup_m function
* DFT+U I/O: Fix multiple issues with onsite.dm format, precision, and MPI
This commit addresses several issues in the DFT+U I/O code related to the
onsite.dm file handling:
1. Format compatibility fix: Updated read_occup_m() to parse the new output format
with labels Atom=, L=, ORBITAL=, and spin= instead of the old tokens atoms, L,
zeta, and spin. The writer was already using the new format but the reader
was not updated, causing new onsite.dm files to be unreadable.
2. Off-by-one fix: The writer outputs 1-based indices (iat+1, is+1) for human
readability, but read_occup_m() was using these values directly as array
indices. Added iat -= 1 and spin -= 1 to convert back to 0-based indices.
3. Precision fix: Added std::setprecision(8) << std::fixed for the collinear
(nspin=1,2) diag=false output path in write_occup_m(). The eigenvalues path
and SOC path already had this, but the matrix values path was missing it.
This ensures stable numeric precision for restart data.
4. out_chg logic fix: The out_chg parameter is supposed to control whether
onsite.dm is written, but the implementation was still checking if(!ofdftu)
even when out_chg == false. Moved the file-open check and write operations
inside the out_chg && MY_RANK == 0 block.
5. MPI fix: Only rank 0 opens the onsite.dm file, but all ranks were executing
the if(!ofdftu) check and write_occup_m() call. Non-root ranks would see an
unopened stream and potentially fail. Now all file operations are rank-0-only.
6. Header fix: Added missing #include <string> and #include <vector> to
dftu_lcao.h. The header was using std::string and std::vector in function
signatures but relying on transitive includes.
7. Documentation fix: Updated stale comments in dftu_lcao.h:
- Changed @PARAM inp to @PARAM dft_plus_u in init_dftu_lcao()
- Added documentation for global_out_dir, nspin, and npol parameters in
finish_dftu_lcao()
8. Error handling: Replaced all exit(0) calls with ModuleBase::WARNING_QUIT()
for consistent error handling across the codebase.
Files modified:
- source/source_lcao/module_dftu/dftu_io.cpp
- source/source_lcao/dftu_lcao.h
- source/source_lcao/dftu_lcao.cpp
* DFT+U I/O: Rename onsite.dm to dm_onsite.txt and adjust file paths
This commit renames the DFT+U occupation matrix files and adjusts their read/write paths:
1. File name changes:
- onsite.dm → dm_onsite.txt (output from DFT+U calculations)
- initial_onsite.dm → dm_onsite_ini.txt (user-provided initial occupation matrix)
2. Path adjustments:
- dm_onsite.txt: Both written and read from global_out_dir (OUT.prefix)
- Previously read from global_readin_dir
- This ensures the file is always in the output directory
- dm_onsite_ini.txt: Read from global_readin_dir (set via read_file_dir parameter)
- Previously read from global_out_dir
- This allows users to place initial files in any directory
3. Code changes:
- dftu_io.cpp: Updated output filename and error messages
- dftu.cpp: Updated read paths for both files
- dftu_lcao.h and module_operator_lcao/dftu_lcao.cpp: Updated comments
4. Documentation updates:
- read_input_item_exx_dftu.cpp: Updated omc parameter description
- parameters.yaml: Updated omc parameter description
- input-main.md: Updated omc parameter description
- band.md and dos.md: Updated file references
- tests/17_DS_DFTU/README.md: Updated test documentation
- tests/17_DS_DFTU/run_scf_nscf.sh: Updated copy logic for dm_onsite.txt
5. Backward compatibility:
- The new format with labels Atom=, L=, ORBITAL=, spin= was already in the writer
- This commit updates the reader to parse the new format
- 1-based indices in output are converted to 0-based when reading
Files modified:
- source/source_lcao/module_dftu/dftu_io.cpp
- source/source_lcao/module_dftu/dftu.cpp
- source/source_lcao/dftu_lcao.h
- source/source_lcao/module_operator_lcao/dftu_lcao.cpp
- source/source_io/module_parameter/read_input_item_exx_dftu.cpp
- docs/parameters.yaml
- docs/advanced/input_files/input-main.md
- docs/advanced/elec_properties/band.md
- docs/advanced/elec_properties/dos.md
- tests/17_DS_DFTU/README.md
- tests/17_DS_DFTU/run_scf_nscf.sh
* remove some usage of PARAM
* remove C++17 codes, reduce PARAM usage in dftu
* update
* remove all PARAM in dftu modules
* fix a bug
* fix bug about Yukawa potential
* update
* try fixing the bug?
* update the directory
---------
Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>1 parent ff5f570 commit fa14bdd
32 files changed
Lines changed: 613 additions & 498 deletions
File tree
- docs
- advanced
- elec_properties
- input_files
- interfaces/ASE_interface/abacuslite
- source
- source_esolver
- source_io
- module_hs
- module_parameter
- source_lcao
- module_dftu
- module_operator_lcao
- source_pw/module_pwdft
- tests/17_DS_DFTU
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3737 | 3737 | | |
3738 | 3738 | | |
3739 | 3739 | | |
3740 | | - | |
3741 | | - | |
| 3740 | + | |
| 3741 | + | |
3742 | 3742 | | |
3743 | | - | |
| 3743 | + | |
3744 | 3744 | | |
3745 | 3745 | | |
3746 | 3746 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4389 | 4389 | | |
4390 | 4390 | | |
4391 | 4391 | | |
4392 | | - | |
4393 | | - | |
| 4392 | + | |
| 4393 | + | |
4394 | 4394 | | |
4395 | | - | |
| 4395 | + | |
4396 | 4396 | | |
4397 | 4397 | | |
4398 | 4398 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
529 | 529 | | |
530 | 530 | | |
531 | 531 | | |
532 | | - | |
| 532 | + | |
| 533 | + | |
533 | 534 | | |
534 | 535 | | |
535 | 536 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
| 375 | + | |
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
| |||
483 | 483 | | |
484 | 484 | | |
485 | 485 | | |
486 | | - | |
| 486 | + | |
487 | 487 | | |
488 | 488 | | |
489 | 489 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
216 | 215 | | |
217 | 216 | | |
218 | 217 | | |
| |||
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
834 | 834 | | |
835 | 835 | | |
836 | 836 | | |
837 | | - | |
838 | | - | |
| 837 | + | |
| 838 | + | |
839 | 839 | | |
840 | | - | |
| 840 | + | |
841 | 841 | | |
842 | 842 | | |
843 | 843 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
420 | 420 | | |
421 | 421 | | |
422 | 422 | | |
423 | | - | |
| 423 | + | |
424 | 424 | | |
425 | 425 | | |
426 | 426 | | |
| |||
0 commit comments