Skip to content

Commit b5572e4

Browse files
author
abacus_fixer
committed
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
1 parent 1f031bf commit b5572e4

11 files changed

Lines changed: 38 additions & 34 deletions

File tree

docs/advanced/elec_properties/band.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ out_chg 1
88
```
99

1010
With this input parameter, the converged charge density will be output in the files such as `chgs1.cube`, `chgs2.cube`, etc.
11-
Then, one can use the same `STRU` file, pseudopotential files and atomic orbital files (and the local density matrix file onsite.dm if DFT+U is used) to do a non-self-consistent (NSCF) calculation. In this example, the potential is constructed from the ground-state charge density from the proceeding calculation. Now the INPUT file is like:
11+
Then, one can use the same `STRU` file, pseudopotential files and atomic orbital files (and the local density matrix file dm_onsite.txt if DFT+U is used) to do a non-self-consistent (NSCF) calculation. In this example, the potential is constructed from the ground-state charge density from the proceeding calculation. Now the INPUT file is like:
1212

1313
```
1414
INPUT_PARAMETERS

docs/advanced/elec_properties/dos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ out_chg 1
1010
```
1111

1212
this will produce the converged charge density, which is contained in the file SPIN1_CHG.cube.
13-
Then, use the same `STRU` file, pseudopotential file and atomic orbital file (and the local density matrix file onsite.dm if DFT+U is used) to do a non-self-consistent calculation. In this example, the potential is constructed from the ground-state charge density from the proceeding calculation. Now the INPUT file is like:
13+
Then, use the same `STRU` file, pseudopotential file and atomic orbital file (and the local density matrix file dm_onsite.txt if DFT+U is used) to do a non-self-consistent calculation. In this example, the potential is constructed from the ground-state charge density from the proceeding calculation. Now the INPUT file is like:
1414

1515
```
1616
INPUT_PARAMETERS

docs/advanced/input_files/input-main.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3736,10 +3736,10 @@
37363736
- **Type**: Integer
37373737
- **Description**: The parameter controls the form of occupation matrix control used.
37383738
- 0: No occupation matrix control is performed, and the onsite density matrix will be calculated from wavefunctions in each SCF step.
3739-
- 1: The first SCF step will use an initial density matrix read from a file named initial_onsite.dm, but for later steps, the onsite density matrix will be updated.
3740-
- 2: The same onsite density matrix from initial_onsite.dm will be used throughout the entire calculation.
3739+
- 1: The first SCF step will use an initial density matrix read from a file named dm_onsite_ini.txt, but for later steps, the onsite density matrix will be updated.
3740+
- 2: The same onsite density matrix from dm_onsite_ini.txt will be used throughout the entire calculation.
37413741

3742-
> Note: The easiest way to create initial_onsite.dm is to run a DFT+U calculation, look for a file named onsite.dm in the OUT.prefix directory, and make replacements there. The format of the file is rather straight-forward.
3742+
> Note: The easiest way to create dm_onsite_ini.txt is to run a DFT+U calculation with out_chg=1, look for a file named dm_onsite.txt in the OUT.prefix directory, copy and rename it to dm_onsite_ini.txt. The file dm_onsite_ini.txt should be placed in the directory specified by read_file_dir. The format of the file is rather straight-forward.
37433743
- **Default**: 0
37443744

37453745
### onsite_radius

docs/parameters.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4387,10 +4387,10 @@ parameters:
43874387
description: |
43884388
The parameter controls the form of occupation matrix control used.
43894389
* 0: No occupation matrix control is performed, and the onsite density matrix will be calculated from wavefunctions in each SCF step.
4390-
* 1: The first SCF step will use an initial density matrix read from a file named initial_onsite.dm, but for later steps, the onsite density matrix will be updated.
4391-
* 2: The same onsite density matrix from initial_onsite.dm will be used throughout the entire calculation.
4390+
* 1: The first SCF step will use an initial density matrix read from a file named dm_onsite_ini.txt, but for later steps, the onsite density matrix will be updated.
4391+
* 2: The same onsite density matrix from dm_onsite_ini.txt will be used throughout the entire calculation.
43924392
4393-
[NOTE] The easiest way to create initial_onsite.dm is to run a DFT+U calculation, look for a file named onsite.dm in the OUT.prefix directory, and make replacements there. The format of the file is rather straight-forward.
4393+
[NOTE] The easiest way to create dm_onsite_ini.txt is to run a DFT+U calculation with out_chg=1, look for a file named dm_onsite.txt in the OUT.prefix directory, copy and rename it to dm_onsite_ini.txt. The file dm_onsite_ini.txt should be placed in the directory specified by read_file_dir. The format of the file is rather straight-forward.
43944394
default_value: "0"
43954395
unit: ""
43964396
availability: ""

source/source_io/module_parameter/read_input_item_exx_dftu.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -834,10 +834,10 @@ void ReadInput::item_dftu()
834834
item.type = "Integer";
835835
item.description = R"(The parameter controls the form of occupation matrix control used.
836836
* 0: No occupation matrix control is performed, and the onsite density matrix will be calculated from wavefunctions in each SCF step.
837-
* 1: The first SCF step will use an initial density matrix read from a file named initial_onsite.dm, but for later steps, the onsite density matrix will be updated.
838-
* 2: The same onsite density matrix from initial_onsite.dm will be used throughout the entire calculation.
837+
* 1: The first SCF step will use an initial density matrix read from a file named dm_onsite_ini.txt, but for later steps, the onsite density matrix will be updated.
838+
* 2: The same onsite density matrix from dm_onsite_ini.txt will be used throughout the entire calculation.
839839
840-
[NOTE] The easiest way to create initial_onsite.dm is to run a DFT+U calculation, look for a file named onsite.dm in the OUT.prefix directory, and make replacements there. The format of the file is rather straight-forward.)";
840+
[NOTE] The easiest way to create dm_onsite_ini.txt is to run a DFT+U calculation with out_chg=1, look for a file named dm_onsite.txt in the OUT.prefix directory, copy and rename it to dm_onsite_ini.txt. The file dm_onsite_ini.txt should be placed in the directory specified by read_file_dir. The format of the file is rather straight-forward.)";
841841
item.default_value = "0";
842842
item.unit = "";
843843
item.availability = "";

source/source_lcao/dftu_lcao.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ void init_dftu_lcao(const int istep,
4343
* @param iter Current SCF iteration
4444
* @param conv_esolver Whether ESolver has converged
4545
* @param dft_plus_u DFT+U mode (0=disabled, 1=old, 2=new)
46-
* @param out_chg Whether to output onsite.dm
46+
* @param out_chg Whether to output dm_onsite.txt
4747
* @param dftu DFT+U object
4848
* @param ucell Unit cell
4949
* @param dm_vec Density matrix vector
5050
* @param kv K-vectors
5151
* @param mixing_beta Mixing beta parameter
5252
* @param hamilt_lcao Hamiltonian LCAO object
53-
* @param global_out_dir Output directory for onsite.dm
53+
* @param global_out_dir Output directory for dm_onsite.txt
5454
* @param nspin Number of spin channels (1, 2, or 4)
5555
* @param npol Number of polarizations
5656
*/

source/source_lcao/module_dftu/dftu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void Plus_U::init(UnitCell& cell, // unitcell class
237237
if (omc != 0)
238238
{
239239
std::stringstream sst;
240-
sst << "initial_onsite.dm";
240+
sst << PARAM.globalv.global_readin_dir << "dm_onsite_ini.txt";
241241
this->read_occup_m(cell, sst.str(), PARAM.inp.init_chg, PARAM.inp.nspin, PARAM.globalv.npol);
242242
#ifdef __MPI
243243
this->local_occup_bcast(cell, PARAM.inp.nspin, PARAM.globalv.npol);
@@ -251,7 +251,7 @@ void Plus_U::init(UnitCell& cell, // unitcell class
251251
if (PARAM.inp.init_chg == "file")
252252
{
253253
std::stringstream sst;
254-
sst << PARAM.globalv.global_readin_dir << "onsite.dm";
254+
sst << PARAM.globalv.global_out_dir << "dm_onsite.txt";
255255
this->read_occup_m(cell, sst.str(), PARAM.inp.init_chg, PARAM.inp.nspin, PARAM.globalv.npol);
256256
#ifdef __MPI
257257
this->local_occup_bcast(cell, PARAM.inp.nspin, PARAM.globalv.npol);

source/source_lcao/module_dftu/dftu_io.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ void Plus_U::output(const UnitCell& ucell,
5959
GlobalV::ofs_running << " Local Occupation Matrices for each atom" << std::endl;
6060
this->write_occup_m(ucell, GlobalV::ofs_running, true, nspin, npol);
6161

62-
// Write onsite.dm
62+
// Write dm_onsite.txt
6363
if (out_chg && GlobalV::MY_RANK == 0)
6464
{
6565
std::ofstream ofdftu;
66-
ofdftu.open(global_out_dir + "onsite.dm");
66+
ofdftu.open(global_out_dir + "dm_onsite.txt");
6767
if (!ofdftu)
6868
{
69-
ModuleBase::WARNING_QUIT("Plus_U::output", "Can't create file onsite.dm");
69+
ModuleBase::WARNING_QUIT("Plus_U::output", "Can't create file dm_onsite.txt");
7070
}
7171
this->write_occup_m(ucell, ofdftu, false, nspin, npol);
7272
ofdftu.close();
@@ -257,16 +257,16 @@ void Plus_U::read_occup_m(const UnitCell& ucell,
257257
{
258258
if (omc > 0)
259259
{
260-
ModuleBase::WARNING_QUIT("Plus_U::read_occup_m", "Can not find the file initial_onsite.dm. Please check your initial_onsite.dm");
260+
ModuleBase::WARNING_QUIT("Plus_U::read_occup_m", "Can not find the file dm_onsite_ini.txt. Please check your dm_onsite_ini.txt");
261261
}
262262
else
263263
{
264264
if (init_chg == "file")
265265
{
266-
ModuleBase::WARNING_QUIT("Plus_U::read_occup_m", "Can not find the file onsite.dm. Please do scf calculation first");
266+
ModuleBase::WARNING_QUIT("Plus_U::read_occup_m", "Can not find the file dm_onsite.txt. Please do scf calculation first");
267267
}
268268
}
269-
ModuleBase::WARNING_QUIT("Plus_U::read_occup_m", "Can not open onsite.dm file");
269+
ModuleBase::WARNING_QUIT("Plus_U::read_occup_m", "Can not open dm_onsite.txt file");
270270
}
271271

272272
ifdftu.clear();

source/source_lcao/module_operator_lcao/dftu_lcao.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::cal_nlm_all(const Parallel_Orbi
190190
* * For nspin=1: occ is scaled by 0.5 (since only one spin channel computed)
191191
* - Subsequent iterations: locale is computed fresh each iteration from updated DMR
192192
*
193-
* Case 2: Locale IS initialized (is_locale_initialized, i.e., read from onsite.dm file)
193+
* Case 2: Locale IS initialized (is_locale_initialized, i.e., read from dm_onsite.txt file)
194194
* - First electronic iteration: uses pre-read locale directly without DMR calculation
195195
* * Skips DMR-based occ calculation entirely
196196
* * Reads locale from stored data via get_locale()
@@ -334,8 +334,8 @@ void hamilt::DFTU<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
334334
// BRANCH 2: Locale IS initialized (use pre-read data)
335335
// ============================================================
336336
// This branch is taken when:
337-
// - is_locale_initialized() == true (locale read from onsite.dm file)
338-
// - OR omc != 0 (occupation matrix control with initial_onsite.dm)
337+
// - is_locale_initialized() == true (locale read from dm_onsite.txt file)
338+
// - OR omc != 0 (occupation matrix control with dm_onsite_ini.txt)
339339
// Typical scenario: first SCF iteration with file input, or restart calculation
340340
else
341341
{

tests/17_DS_DFTU/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ The following test cases are disabled in `CASES_CPU.txt` (commented out with `#`
175175

176176
- 09 (PW DFT+U + noncollinear): Only supports **2-process MPI** execution, `result.ref` reference files provided
177177
- The following test cases set `kpar=2` in INPUT and require at least **2 MPI processes** to run: 11, 12, 14, 15, 16, 18, 19, 21, 37, 39, 41, 43, 45
178-
- 62 (LCAO_DFTU_NSCF_Band_XY): Single-thread and multi-thread results are inconsistent; investigation shows HR, HK, and SK are consistent across threads, but eigenvalues from genelpa differ; switching to scalapack_gvx produces consistent results across thread counts. Note: this test is named "NSCF" but actually runs with `calculation = scf` (`scf_nmax = 1`), using pre-shipped charge density and onsite.dm files as initial guess
178+
- 62 (LCAO_DFTU_NSCF_Band_XY): Single-thread and multi-thread results are inconsistent; investigation shows HR, HK, and SK are consistent across threads, but eigenvalues from genelpa differ; switching to scalapack_gvx produces consistent results across thread counts. Note: this test is named "NSCF" but actually runs with `calculation = scf` (`scf_nmax = 1`), using pre-shipped charge density and dm_onsite.txt files as initial guess
179179
- All NSCF tests (55, 60, 61, 62, 63, 64) have been **converted to SCF+NSCF workflow**:
180-
- Pre-converged `autotest-CHARGE-DENSITY.restart` and `onsite.dm` files have been removed
180+
- Pre-converged `autotest-CHARGE-DENSITY.restart` and `dm_onsite.txt` files have been removed
181181
- Each test directory contains a `scf/` subdirectory with SCF input files
182182
- Run with: `bash ../run_scf_nscf.sh <abacus_path> [mpi_np]`
183183
- These tests are **disabled in CI** (commented out in CASES_CPU.txt)

0 commit comments

Comments
 (0)