Skip to content

Commit b2d6634

Browse files
committed
Combine deepks_bandgap=1&3.
1 parent ebceecd commit b2d6634

File tree

19 files changed

+25
-183
lines changed

19 files changed

+25
-183
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,20 +2150,19 @@ Warning: this function is not robust enough for the current version. Please try
21502150
- **Availability**: numerical atomic orbital basis and `deepks_scf` is true
21512151
- **Description**: include bandgap label for DeePKS training
21522152
- 0: Don't include bandgap label
2153-
- 1: Include HOMO and LUMO for bandgap label
2153+
- 1: Include target bandgap label (see [deepks\_bandgap\_range](#deepks_band_range) for more details)
21542154
- 2: Include multiple bandgap label (see [deepks\_bandgap\_range](#deepks_band_range) for more details)
2155-
- 3: Include target bandgap label (see [deepks\_bandgap\_range](#deepks_band_range) for more details)
2156-
- 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 and (HOMO + 1)
2155+
- 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)
21572156
- **Default**: 0
21582157

21592158
### deepks_band_range
21602159

21612160
- **Type**: Int*2
2162-
- **Availability**: numerical atomic orbital basis, `deepks_scf` is true, and `deepks_bandgap` is 2 or 3
2161+
- **Availability**: numerical atomic orbital basis, `deepks_scf` is true, and `deepks_bandgap` is 1 or 2
21632162
- **Description**: The first value should not be larger than the second one and the meaning differs in different cases below
2163+
- `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.
21642164
- `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.*
2165-
- `deepks_bandgap` is 3: Bandgap label is the energy between `LUMO + deepks_band_range[0]` and `LUMO + deepks_band_range[1]`.
2166-
- **Default**: 0 1 (for deepks_bandgap=3), or 0 0 (for other cases)
2165+
- **Default**: -1 0
21672166

21682167
### deepks_v_delta
21692168

source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
206206
// Bandgap Part
207207
if (PARAM.inp.deepks_bandgap > 0)
208208
{
209-
// Get the index of the highest occupied bands
209+
// Get the number of the occupied bands
210+
// Notice that the index of band starts from 0, so actually (nocc - 1) is the index of HOMO state
210211
int nocc = (PARAM.inp.nelec + 1) / 2;
211-
if (PARAM.inp.deepks_bandgap == 4)
212+
if (PARAM.inp.deepks_bandgap == 3)
212213
{
213214
int natom_H = 0;
214215
for (int it = 0; it < ucell.ntype; it++)
@@ -239,9 +240,10 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
239240
for (int iks = 0; iks < nks; ++iks)
240241
{
241242
int ib = 0;
242-
if (PARAM.inp.deepks_bandgap == 1 || PARAM.inp.deepks_bandgap == 4)
243+
if (PARAM.inp.deepks_bandgap == 1 || PARAM.inp.deepks_bandgap == 3)
243244
{
244-
o_tot(iks, ib) = ekb(iks, nocc) - ekb(iks, nocc - 1);
245+
o_tot(iks, ib) = ekb(iks, nocc + PARAM.inp.deepks_band_range[1])
246+
- ekb(iks, nocc + PARAM.inp.deepks_band_range[0]);
245247
}
246248
else if (PARAM.inp.deepks_bandgap == 2)
247249
{
@@ -255,11 +257,6 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
255257
}
256258
assert(ib == range); // ensure that we have filled all the bandgap values
257259
}
258-
else if (PARAM.inp.deepks_bandgap == 3)
259-
{
260-
o_tot(iks, ib) = ekb(iks, nocc + PARAM.inp.deepks_band_range[1])
261-
- ekb(iks, nocc + PARAM.inp.deepks_band_range[0]);
262-
}
263260
}
264261

265262
const std::string file_otot
@@ -282,10 +279,10 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
282279
for (int iks = 0; iks < nks; ++iks)
283280
{
284281
int ib = 0;
285-
if (PARAM.inp.deepks_bandgap == 1 || PARAM.inp.deepks_bandgap == 4)
282+
if (PARAM.inp.deepks_bandgap == 1 || PARAM.inp.deepks_bandgap == 3)
286283
{
287-
wg_hl_range[ib](iks, nocc - 1) = -1.0;
288-
wg_hl_range[ib](iks, nocc) = 1.0;
284+
wg_hl_range[ib](iks, nocc + PARAM.inp.deepks_band_range[0]) = -1.0;
285+
wg_hl_range[ib](iks, nocc + PARAM.inp.deepks_band_range[1]) = 1.0;
289286
}
290287
else if (PARAM.inp.deepks_bandgap == 2)
291288
{
@@ -299,11 +296,6 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
299296
}
300297
}
301298
}
302-
else if (PARAM.inp.deepks_bandgap == 3)
303-
{
304-
wg_hl_range[ib](iks, nocc + PARAM.inp.deepks_band_range[0]) = -1.0;
305-
wg_hl_range[ib](iks, nocc + PARAM.inp.deepks_band_range[1]) = 1.0;
306-
}
307299
}
308300

309301
ModuleBase::matrix o_delta(nks, range);

source/module_io/read_input_item_deepks.cpp

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ void ReadInput::item_deepks()
4949
item.annotation = ">0 for bandgap label";
5050
read_sync_int(input.deepks_bandgap);
5151
this->add_item(item);
52-
item.reset_value = [](const Input_Item& item, Parameter& para) {
53-
if (para.input.deepks_bandgap == 3)
54-
{
55-
para.input.deepks_band_range[1] = 1;
56-
}
57-
};
5852
}
5953
{
6054
Input_Item item("deepks_band_range");
@@ -65,25 +59,25 @@ void ReadInput::item_deepks()
6559
};
6660
sync_intvec(input.deepks_band_range, 2, 0);
6761
item.check_value = [](const Input_Item& item, const Parameter& para) {
68-
if (para.input.deepks_bandgap == 2)
62+
if (para.input.deepks_bandgap == 1)
6963
{
70-
if (para.input.deepks_band_range[0] > para.input.deepks_band_range[1])
64+
if (para.input.deepks_band_range[0] >= para.input.deepks_band_range[1])
7165
{
72-
ModuleBase::WARNING_QUIT("ReadInput", "deepks_band_range[0] must be no more than deepks_band_range[1] for deepks_bandgap = 2.");
66+
ModuleBase::WARNING_QUIT("ReadInput", "deepks_band_range[0] must be smaller than deepks_band_range[1] for deepks_bandgap = 1.");
7367
}
7468
}
75-
else if (para.input.deepks_bandgap == 3)
69+
else if (para.input.deepks_bandgap == 2)
7670
{
77-
if (para.input.deepks_band_range[0] >= para.input.deepks_band_range[1])
71+
if (para.input.deepks_band_range[0] > para.input.deepks_band_range[1])
7872
{
79-
ModuleBase::WARNING_QUIT("ReadInput", "deepks_band_range[0] must be smaller than deepks_band_range[1] for deepks_bandgap = 3.");
73+
ModuleBase::WARNING_QUIT("ReadInput", "deepks_band_range[0] must be no more than deepks_band_range[1] for deepks_bandgap = 2.");
8074
}
8175
}
8276
else
8377
{
84-
if (para.input.deepks_band_range[0] != 0 || para.input.deepks_band_range[1] != 0)
78+
if (para.input.deepks_band_range[0] != -1 || para.input.deepks_band_range[1] != 0)
8579
{
86-
ModuleBase::WARNING("ReadInput", "deepks_band_range is used for deepks_bandgap = 2/3. Ignore its setting for other cases.");
80+
ModuleBase::WARNING("ReadInput", "deepks_band_range is used for deepks_bandgap = 1/2. Ignore its setting for other cases.");
8781
}
8882
}
8983
};

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)