Skip to content

Commit 6c460fd

Browse files
authored
Refactor&Docs: Simplify deepks_bandgap realization and add input value checks. (#6241)
* Add value check for deepks_bandgap_range. * Simplify code for deepks_bandgap labels. * Combine deepks_bandgap=1&3. * Correct a mistake in doc.
1 parent 5daf5d9 commit 6c460fd

File tree

19 files changed

+119
-423
lines changed

19 files changed

+119
-423
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
- [bessel\_descriptor\_smooth](#bessel_descriptor_smooth)
196196
- [bessel\_descriptor\_sigma](#bessel_descriptor_sigma)
197197
- [deepks\_bandgap](#deepks_bandgap)
198-
- [deepks\_bandgap\_range](#deepks_bandgap_range)
198+
- [deepks\_band\_range](#deepks_band_range)
199199
- [deepks\_v\_delta](#deepks_v_delta)
200200
- [deepks\_out\_unittest](#deepks_out_unittest)
201201
- [OFDFT: orbital free density functional theory](#ofdft-orbital-free-density-functional-theory)
@@ -2149,20 +2149,19 @@ Warning: this function is not robust enough for the current version. Please try
21492149
- **Availability**: numerical atomic orbital basis and `deepks_scf` is true
21502150
- **Description**: include bandgap label for DeePKS training
21512151
- 0: Don't include bandgap label
2152-
- 1: Include HOMO and LOMO for bandgap label
2153-
- 2: Include multiple bandgap label (see [deepks\_bandgap\_range](#deepks_bandgap_range) for more details)
2154-
- 3: Include target bandgap label (see [deepks\_bandgap\_range](#deepks_bandgap_range) for more details)
2155-
- 4: For systems containing H atoms only, HOMO is defined as the max occupation expect H atoms and the bandgap label is the energy between (HOMO, HOMO + 1)
2152+
- 1: Include target bandgap label (see [deepks\_band\_range](#deepks_band_range) for more details)
2153+
- 2: Include multiple bandgap label (see [deepks\_band\_range](#deepks_band_range) for more details)
2154+
- 3: For systems containing H atoms only, HOMO is defined as the max occupation expect H atoms and the bandgap label is the energy between HOMO and (HOMO + 1)
21562155
- **Default**: 0
21572156

2158-
### deepks_bandgap_range
2157+
### deepks_band_range
21592158

21602159
- **Type**: Int*2
2161-
- **Availability**: numerical atomic orbital basis, `deepks_scf` is true, and `deepks_bandgap` is 2 or 3
2162-
- **Description**:
2163-
- `deepks_bandgap` is 2: Bandgap labels are energies between (LUMO + deepks_bandgap_range[0], HOMO), (LUMO + deepks_bandgap_range[0] + 1, HOMO), ..., (LUMO + deepks_bandgap_range[1], HOMO) except (HOMO, HOMO)
2164-
- `deepks_bandgap` is 3: Bandgap label is the energy between (LUMO + deepks_bandgap_range[0], LUMO + deepks_bandgap_range[1])
2165-
- **Default**: 0 0
2160+
- **Availability**: numerical atomic orbital basis, `deepks_scf` is true, and `deepks_bandgap` is 1 or 2
2161+
- **Description**: The first value should not be larger than the second one and the meaning differs in different cases below
2162+
- `deepks_bandgap` is 1: Bandgap label is the energy between `LUMO + deepks_band_range[0]` and `LUMO + deepks_band_range[1]`. If not set, it will calculate energy between HOMO and LUMO states.
2163+
- `deepks_bandgap` is 2: Bandgap labels are energies between HOMO and all states in range [`LUMO + deepks_band_range[0]`, `LUMO + deepks_band_range[1]`] (Thus there are `deepks_band_range[1] - deepks_band_range[0] + 1` bandgaps in total). If HOMO is included in the setting range, it will be ignored since it will always be zero and has no valuable messages (`deepks_band_range[1] - deepks_band_range[0]` bandgaps in this case). *NOTICE: The set range can be greater than, less than, or include the value of HOMO. In the bandgap label, we always calculate the energy of the state in the set range minus the energy of HOMO state, so the bandgap can be negative if the state is lower than HOMO.*
2164+
- **Default**: -1 0
21662165

21672166
### deepks_v_delta
21682167

source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp

Lines changed: 80 additions & 263 deletions
Large diffs are not rendered by default.

source/module_io/read_input_item_deepks.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ void ReadInput::item_deepks()
1919
read_sync_bool(input.deepks_scf);
2020
item.check_value = [](const Input_Item& item, const Parameter& para) {
2121
#ifndef __DEEPKS
22-
if (PARAM.inp.deepks_scf || PARAM.inp.deepks_out_labels || PARAM.inp.deepks_bandgap
23-
|| PARAM.inp.deepks_v_delta)
22+
if (para.input.deepks_scf || para.input.deepks_out_labels || para.input.deepks_bandgap
23+
|| para.input.deepks_v_delta)
2424
{
2525
ModuleBase::WARNING_QUIT("Input_conv", "please compile with DeePKS");
2626
}
2727
#endif
28-
// if (!PARAM.inp.deepks_scf && PARAM.inp.deepks_out_labels == 1)
28+
// if (!para.input.deepks_scf && para.input.deepks_out_labels == 1)
2929
// {
3030
// ModuleBase::WARNING_QUIT("Input_conv", "deepks_out_labels = 1 requires deepks_scf = 1");
3131
// }
@@ -58,6 +58,29 @@ void ReadInput::item_deepks()
5858
para.input.deepks_band_range[1] = std::stod(item.str_values[1]);
5959
};
6060
sync_intvec(input.deepks_band_range, 2, 0);
61+
item.check_value = [](const Input_Item& item, const Parameter& para) {
62+
if (para.input.deepks_bandgap == 1)
63+
{
64+
if (para.input.deepks_band_range[0] >= para.input.deepks_band_range[1])
65+
{
66+
ModuleBase::WARNING_QUIT("ReadInput", "deepks_band_range[0] must be smaller than deepks_band_range[1] for deepks_bandgap = 1.");
67+
}
68+
}
69+
else if (para.input.deepks_bandgap == 2)
70+
{
71+
if (para.input.deepks_band_range[0] > para.input.deepks_band_range[1])
72+
{
73+
ModuleBase::WARNING_QUIT("ReadInput", "deepks_band_range[0] must be no more than deepks_band_range[1] for deepks_bandgap = 2.");
74+
}
75+
}
76+
else
77+
{
78+
if (para.input.deepks_band_range[0] != -1 || para.input.deepks_band_range[1] != 0)
79+
{
80+
ModuleBase::WARNING("ReadInput", "deepks_band_range is used for deepks_bandgap = 1/2. Ignore its setting for other cases.");
81+
}
82+
}
83+
};
6184
this->add_item(item);
6285
}
6386
{

source/module_parameter/input_parameter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ struct Input_para
265265
bool deepks_scf = false; ///< (need libnpy and libtorch) if set to true, a trained model
266266
///< would be needed to calculate V_delta and F_delta
267267
int deepks_bandgap = 0; ///< for bandgap label. QO added 2021-12-15
268-
std::vector<int> deepks_band_range = {0, 0}; ///< the range of bands to calculate bandgap
268+
std::vector<int> deepks_band_range = {-1, 0}; ///< the range of bands to calculate bandgap
269269
int deepks_v_delta = 0; ///< for v_delta label. xuan added
270270
bool deepks_equiv = false; ///< whether to use equivariant version of DeePKS
271271
bool deepks_out_unittest = false; ///< if set to true, prints intermediate quantities that shall

tests/09_DeePKS/103_NO_GO_deepks_bandgap/INPUT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ deepks_scf 1
2121
deepks_model ../Model_ProjOrb/model_lda_pbe_18.ptg
2222
deepks_out_labels 1
2323
deepks_bandgap 1
24+
deepks_band_range -1 0

tests/09_DeePKS/103_NO_GO_deepks_bandgap_3/INPUT

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ deepks_scf 1
2121
deepks_model ../Model_ProjOrb/model_lda_pbe_18.ptg
2222
deepks_out_labels 1
2323
deepks_bandgap 3
24-
deepks_band_range -1 0

tests/09_DeePKS/103_NO_GO_deepks_bandgap_4/INPUT

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/09_DeePKS/103_NO_GO_deepks_bandgap_4/KPT

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/09_DeePKS/103_NO_GO_deepks_bandgap_4/README

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/09_DeePKS/103_NO_GO_deepks_bandgap_4/STRU

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)