Skip to content

Commit 74dcbdf

Browse files
authored
Fix: Correct LCAO real-space wavefunctions and partial-charge handling (deepmodeling#7868)
* Correct LCAO Gint wavefunction band stride * Remove Fermi metadata from LCAO state Cube output * Normalize PW real-space wavefunctions as single-particle states * Include full Bloch phase in PW real-space wavefunction cubes * Remove out_wfc_pw support from LCAO get_wf and align wavefunction documentation * Write LCAO Gamma wavefunction cubes directly from isolated Gint buffers with correct norm, real, and imaginary components * Fix: Rewrite LCAO multi-k and spinor wavefunction cubes with correct complex Bloch phases, component separation, and direct Gint output * Fix: Initialize unused Gamma LCAO Psi workspace after file reads * Build LCAO partial-charge state DMK with cal_dm_psi and explicit state weights * Refactor: Isolate LCAO partial-charge buffers from Charge, apply coupled nspin=4 symmetry, and unify Cube precision * Refactor: Simplify LCAO partial-charge and wavefunction output
1 parent 5fb17a6 commit 74dcbdf

29 files changed

Lines changed: 1160 additions & 1747 deletions

File tree

docs/advanced/elec_properties/wfc.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@ ABACUS is able to output electron wave functions in both PW and LCAO basis calcu
44

55
## Wave Function in G-Space
66

7-
To output wave functions in G-space, add one of the following keywords to the `INPUT` file while performing SCF calculation:
8-
- **PW basis**: Set [`out_wfc_pw`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#out-wfc-pw) to `1`. Output file format: `wfs[spin]k[kpoint]_pw.txt`, where `[spin]` is the spin channel index, and `[kpoint]` the k-point index.
7+
For `basis_type=pw` and `esolver_type=ksdft`, [`out_wfc_pw`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#out-wfc-pw) controls the output of plane-wave Kohn-Sham coefficients:
98

10-
- **LCAO basis**: Set [`out_wfc_lcao`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#out-wfc-lcao) to `1`.
11-
- **Multi-k calculations**: Generates multiple files `wfs[spin]k[kpoint]_nao.txt`.
12-
- **Gamma-only calculations**: `wfs[spin]_nao.txt` instead.
9+
* `0`: Do not write wave-function coefficients.
10+
* `1`: Write text files with the `.txt` suffix.
11+
* `2`: Write binary files with the `.dat` suffix.
12+
13+
The files are stored in `OUT.${suffix}/`. Their pattern is `wfk{k}[s{spin}][g{geometry step}][e{electronic iteration}]_pw.txt` for `out_wfc_pw=1` and `wfk{k}[s{spin}][g{geometry step}][e{electronic iteration}]_pw.dat` for `out_wfc_pw=2`. The `s*` label is omitted for `nspin=1`, is `s1` or `s2` for `nspin=2`, and is `s4` for `nspin=4`. All PW files include the `k*` label, including Gamma-only calculations.
14+
15+
With `out_freq_ion=0`, files are written only when the electronic calculation converges or reaches `scf_nmax`, and the names contain neither `g*` nor `e*`. During structural relaxation or molecular dynamics, each later ionic step overwrites the same files. With `out_freq_ion>0`, output is restricted to the ionic steps selected by `out_freq_ion` and occurs at multiples of `out_freq_elec`, at convergence, or at `scf_nmax`; both `g*` and `e*` are included in the file names. A static `calculation=scf` or `calculation=nscf` run also receives `g1e*` indices when `out_freq_ion>0`.
16+
17+
The normal [`init_wfc=file`](../scf/initialization.md#wave-function) path reads only unindexed binary `wf*_pw.dat` files from `read_file_dir`. Generate directly reusable files with `out_wfc_pw=2` and normally `out_freq_ion=0`. Text `wf*_pw.txt` files and files containing `g*` or `e*` indices are not matched automatically.
18+
19+
For `basis_type=lcao`, set [`out_wfc_lcao=1`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#out-wfc-lcao). Multi-k calculations generate `wfs{spin}k{k-point}_nao.txt`, while Gamma-only calculations generate `wfs{spin}_nao.txt`.
1320

1421
## Wave Function in Real Space
1522

1623
One can also choose to output real-space wave functions with the keyword [`out_wfc_norm`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#out-wfc-norm) or [`out_wfc_re_im`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#out-wfc-re-im).
1724

18-
Notice: When the [`basis_type`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#basis-type) is `lcao`, only `get_wf` [`calculation`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#calculation) is effective. An example is [examples/11_wfc/lcao_ienvelope_Si2](https://github.com/deepmodeling/abacus-develop/tree/develop/examples/11_wfc/lcao_ienvelope_Si2).
25+
Notice: When the [`basis_type`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#basis-type) is `lcao`, only `get_wf` [`calculation`](https://abacus-rtd.readthedocs.io/en/latest/advanced/input_files/input-main.html#calculation) is effective. An example is [examples/11_wfc/lcao_ienvelope_Si2](https://github.com/deepmodeling/abacus-develop/tree/develop/examples/11_wfc/lcao_ienvelope_Si2).

docs/advanced/input_files/input-main.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -731,18 +731,22 @@
731731
### init_wfc
732732

733733
- **Type**: String
734-
- **Description**: The type of the starting wave functions.
734+
- **Description**: The method used to initialize wavefunction coefficients. The available options and behavior depend on `basis_type`.
735735

736-
Available options are:
736+
For `basis_type=pw`, the available options are:
737+
738+
- `atomic`: Use atomic pseudo wavefunctions from `PP_PSWFC`. If no `PP_PSWFC` states are available, all bands are initialized randomly. If the number of atomic states is smaller than `nbands`, the remaining bands are initialized randomly.
739+
- `atomic+random`: If there are at least `nbands` atomic states, apply an approximately 5% multiplicative random perturbation to the atomic initialization. If there are fewer atomic states than `nbands`, use the atomic states and initialize the remaining bands randomly, as for `atomic`.
740+
- `random`: Initialize all bands with random coefficients.
741+
- `nao`: Use numerical atomic orbitals. If the number of NAO states is smaller than `nbands`, the remaining bands are initialized randomly.
742+
- `nao+random`: Apply an approximately 5% multiplicative random perturbation to the NAO initialization; any bands not covered by NAO states are first initialized randomly.
743+
- `file`: Read binary `wf*_pw.dat` files generated with `out_wfc_pw=2` from `read_file_dir`. The files must match the current k points, `nbands`, plane-wave layout, and lattice.
744+
745+
For `basis_type=lcao`, only `file` triggers reading existing wavefunctions. It reads text `wf*_nao.txt` files generated with `out_wfc_lcao=1` from `read_file_dir`; binary files generated with `out_wfc_lcao=2` are not supported. The files must use a compatible NAO basis, match the current k-point and spin setup, and contain enough bands. Normal `init_wfc=file` reading matches files written with the default `out_app_flag=true`, which have no geometry-step index. Files written under `WFC/` with a `g*` geometry-step index when `out_app_flag=false` are not matched automatically.
737746

738-
- atomic: from atomic pseudo wave functions. If they are not enough, other wave functions are initialized with random numbers.
739-
- atomic+random: add small random numbers on atomic pseudo-wavefunctions
740-
- file: from binary files wf*.dat, which are output by setting out_wfc_pw to 2.
741-
- random: random numbers
742-
- nao: from numerical atomic orbitals. If they are not enough, other wave functions are initialized with random numbers.
743-
- nao+random: add small random numbers on numerical atomic orbitals
747+
For `basis_type=lcao_in_pw`, `init_wfc` is automatically set to `nao`.
744748

745-
> Note: Only the file option is useful for the lcao basis set, which is mostly used when calculation is set to get_wf and get_pchg.
749+
> Note: For `calculation=get_wf` or `calculation=get_pchg`, `init_wfc` is automatically set to `file`. If `basis_type=lcao_in_pw` is also used, the final value is `nao`.
746750
- **Default**: atomic
747751

748752
### init_chg
@@ -1937,19 +1941,22 @@
19371941
### out_wfc_pw
19381942

19391943
- **Type**: Integer
1940-
- **Availability**: *[`basis_type`](#basis_type)==pw or ([`basis_type`](#basis_type)==lcao and [`calculation`](#calculation)==get_wf)*
1941-
- **Description**: Whether to output the electronic wavefunction coefficients into files and store them in the folder OUT.${suffix}. The files are named as wf{k}{k-point index}{s}{spin index}{g}{geometry index}{e}{electronic iteration index}{_pw} + {".txt"/".dat"}. Here, the s index refers to spin but the label will not show up for non-spin-polarized calculations, where s1 means spin up channel while s2 means spin down channel, and s4 refers to spinor wave functions that contains both spin channels with spin-orbital coupling or noncollinear calculations enabled. For scf or nscf calculations, g index will not appear, but the g index appears for geometry relaxation and molecular dynamics, where one can use the out_freq_ion command to control. To print out the electroinc wave functions every few SCF iterations, use the out_freq_elec command and the e index will appear in the file name.
1942-
- 0: no output
1943-
- 1: (txt format)
1944-
- non-gamma-only with nspin=1: wfk1_pw.txt, wfk2_pw.txt, ...;
1945-
- non-gamma-only with nspin=2: wfk1s1_pw.txt, wfk1s2_pw.txt, wfk2s1_pw.txt, wfk2s2_pw.txt, ...;
1946-
- non-gamma-only with nspin=4: wfk1s4_pw.txt, wfk2s4_pw.txt, ...;
1947-
- 2: (binary format)
1948-
- non-gamma-only with nspin=1: wfk1_pw.dat, wfk2_pw.dat, ...;
1949-
- non-gamma-only with nspin=2: wfk1s1_pw.dat, wfk1s2_pw.dat, wfk2s1_pw.dat, wfk2s2_pw.dat, ...;
1950-
- non-gamma-only with nspin=4: wfk1s4_pw.dat, wfk2s4_pw.dat, ...;
1944+
- **Availability**: *[`basis_type`](#basis_type)==pw and [`esolver_type`](#esolver_type)==ksdft*
1945+
- **Description**: Controls whether plane-wave Kohn-Sham wavefunction coefficients are written to `OUT.${suffix}/`.
1946+
1947+
Available values are:
1948+
1949+
- `0`: Do not write wavefunction coefficients.
1950+
- `1`: Write text files with the `.txt` suffix.
1951+
- `2`: Write binary files with the `.dat` suffix.
1952+
1953+
The file-name pattern is `wfk{k}[s{spin}][g{geometry step}][e{electronic iteration}]_pw.txt` for `out_wfc_pw=1` and `wfk{k}[s{spin}][g{geometry step}][e{electronic iteration}]_pw.dat` for `out_wfc_pw=2`. All PW output files include a `k*` label, including Gamma-only calculations. Without geometry-step or electronic-iteration indices, representative names are `wfk1_pw.txt` or `wfk1_pw.dat` for `nspin=1`, `wfk1s1_pw.txt` and `wfk1s2_pw.txt` or their `.dat` equivalents for `nspin=2`, and `wfk1s4_pw.txt` or `wfk1s4_pw.dat` for `nspin=4`.
1954+
1955+
With `out_freq_ion=0`, files are written only when the electronic calculation converges or reaches `scf_nmax`; no `g*` or `e*` index is added. During structural relaxation or molecular dynamics, later ionic steps overwrite the same unindexed files. With `out_freq_ion` > 0, output is restricted to the ionic steps selected by `out_freq_ion` and is written when the electronic iteration is a multiple of `out_freq_elec`, when the calculation converges, or when it reaches `scf_nmax`. Both `g*` and `e*` indices are then added, including for a static `calculation=scf` or `calculation=nscf` run.
1956+
1957+
For `init_wfc=file`, ABACUS automatically reads only unindexed binary `wf*_pw.dat` files from `read_file_dir`. Such directly reusable files are normally generated with `out_wfc_pw=2` and `out_freq_ion=0`. Text `wf*_pw.txt` files and files containing `g*` or `e*` indices are not matched automatically.
19511958

1952-
> Note: In the 3.10-LTS version, the file names are WAVEFUNC1.dat, WAVEFUNC2.dat, etc.
1959+
> Note: In the 3.10-LTS version, the binary files are named `WAVEFUNC1.dat`, `WAVEFUNC2.dat`, etc.
19531960
- **Default**: 0
19541961

19551962
### out_wfc_lcao
@@ -2394,14 +2401,14 @@
23942401

23952402
- **Type**: String
23962403
- **Availability**: *[`basis_type`](#basis_type)==pw or ([`basis_type`](#basis_type)==lcao and [`calculation`](#calculation)==get_wf)*
2397-
- **Description**: Selects electronic states for real-space wavefunction-modulus output using the selection syntax and complete-state normalization of `out_pchg`. For `nspin=1`, `s1` contains the wavefunction modulus. For `nspin=2`, `s1` and `s2` contain the spin-up and spin-down wavefunction moduli, respectively. For `nspin=4`, `s1` contains the total spinor modulus. Files are named `wfi[state]s[spin]k[kpoint].cube`.
2404+
- **Description**: Selects electronic states for real-space wavefunction-modulus output using the selection syntax of `out_pchg`. Each wavefunction is normalized as a single-particle state and does not include SCF occupations or spin-degeneracy factors. For `nspin=1`, `s1` contains the wavefunction modulus. For `nspin=2`, `s1` and `s2` contain the spin-up and spin-down wavefunction moduli, respectively. For `nspin=4`, `s1` contains the total spinor modulus. Files are named `wfi[state]s[spin]k[kpoint].cube`.
23982405
- **Default**: none
23992406

24002407
### out_wfc_re_im
24012408

24022409
- **Type**: String
24032410
- **Availability**: *[`basis_type`](#basis_type)==pw or ([`basis_type`](#basis_type)==lcao and [`calculation`](#calculation)==get_wf)*
2404-
- **Description**: Selects electronic states for real-space wavefunction real- and imaginary-part output using the selection syntax and complete-state normalization of `out_pchg`. For `nspin=1`, `s1` contains the wavefunction. For `nspin=2`, `s1` and `s2` contain the spin-up and spin-down wavefunctions, respectively. For `nspin=4`, `s1` and `s2` contain the upper and lower spinor components, respectively. Files are named `wfi[state]s[spin]k[kpoint][re/im].cube`.
2411+
- **Description**: Selects electronic states for real-space wavefunction real- and imaginary-part output using the selection syntax of `out_pchg`. Each wavefunction is normalized as a single-particle state and does not include SCF occupations or spin-degeneracy factors. For `nspin=1`, `s1` contains the wavefunction. For `nspin=2`, `s1` and `s2` contain the spin-up and spin-down wavefunctions, respectively. For `nspin=4`, `s1` and `s2` contain the upper and lower spinor components, respectively. Files are named `wfi[state]s[spin]k[kpoint][re/im].cube`.
24052412
- **Default**: none
24062413

24072414
### if_separate_k

docs/advanced/scf/initialization.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,21 @@ In LCAO basis, wavefunction can be read to calculate initial charge density. The
1313
- `dm` (LCAO only): initial charge density from density matrix files in CSR format. For `nspin=1`, reads `dmrs1_nao.csr`. For `nspin=2` (spin-polarized), reads both `dmrs1_nao.csr` (spin-up) and `dmrs2_nao.csr` (spin-down). These files are generated by previous calculations with [`out_dmr 1`](../elec_properties/density_matrix.md). This method is particularly useful for restarting spin-polarized calculations.
1414
- `hr` (LCAO only): initial charge density from Hamiltonian matrix files in CSR format. The Hamiltonian is read from file, then diagonalized to obtain wavefunctions and charge density. For `nspin=1`, reads `hrs1_nao.csr`. For `nspin=2` (spin-polarized), reads both `hrs1_nao.csr` (spin-up) and `hrs2_nao.csr` (spin-down). These files are generated by previous calculations with [`out_hsr 1`](../input_files/input-main.md#out_hsr).
1515

16-
## Wave function
17-
`init_wfc` is used for choosing the method of wavefunction coefficient initialization.
16+
## Wavefunction
1817

19-
When `basis_type=pw`, setting of `random` and `atomic` are supported.
20-
Atomic wave function is read from pseudopotential file under keyword `PP_PSWFC`, if setting is `atomic` and number of band of atomic wavefunction less than `nbands` in INPUT file, the extra bands will be initialed by random.
18+
`init_wfc` selects how wavefunction coefficients are initialized. The available options and behavior depend on `basis_type`.
2119

22-
When `basis_type=lcao`, we further support reading of initial wavefunction by setting `init_wfc` to `file`.
23-
In LCAO code, wave function is used to initialize density matrix and real-space charge density.
24-
For such purpose, a file containing wavefunction must be prepared. Such files can be generated from previous calculations with [`out_wfc_lcao 1`](../elec_properties/wfc.md).
20+
For `basis_type=pw`, the available options are:
21+
22+
* `atomic`: Use atomic pseudo wavefunctions from `PP_PSWFC`. If no `PP_PSWFC` states are available, all bands are initialized randomly. If the number of atomic states is smaller than `nbands`, the remaining bands are initialized randomly.
23+
* `atomic+random`: If there are at least `nbands` atomic states, apply an approximately 5% multiplicative random perturbation to the atomic initialization. If there are fewer atomic states than `nbands`, use the atomic states and initialize the remaining bands randomly, as for `atomic`.
24+
* `random`: Initialize all bands with random coefficients.
25+
* `nao`: Use numerical atomic orbitals. If the number of NAO states is smaller than `nbands`, the remaining bands are initialized randomly.
26+
* `nao+random`: Apply an approximately 5% multiplicative random perturbation to the NAO initialization; any bands not covered by NAO states are first initialized randomly.
27+
* `file`: Read binary `wf*_pw.dat` files generated with [`out_wfc_pw=2`](../elec_properties/wfc.md) from `read_file_dir`. The files must match the current k points, `nbands`, plane-wave layout, and lattice.
28+
29+
For `basis_type=lcao`, only `init_wfc=file` triggers reading existing wavefunctions. LCAO wavefunctions initialize the density matrix and real-space charge density. ABACUS reads text `wf*_nao.txt` files generated with [`out_wfc_lcao=1`](../elec_properties/wfc.md) from `read_file_dir`; binary files generated with `out_wfc_lcao=2` are not supported. The files must use a compatible NAO basis, match the current k-point and spin setup, and contain enough bands. Normal `init_wfc=file` reading matches files written with the default `out_app_flag=true`, which have no geometry-step index. Files written under `WFC/` with a `g*` geometry-step index when `out_app_flag=false` are not matched automatically.
30+
31+
For `basis_type=lcao_in_pw`, `init_wfc` is automatically set to `nao`.
32+
33+
For `calculation=get_wf` or `calculation=get_pchg`, `init_wfc` is automatically set to `file`. If `basis_type=lcao_in_pw` is also used, the final value is `nao`.

0 commit comments

Comments
 (0)