Skip to content

Commit ab43e04

Browse files
committed
fix bug when reading the second parameter of dmk, dmr, out_chg, out_mat_hs, out_mat_tk, out_mat_l
1 parent e9677b4 commit ab43e04

File tree

3 files changed

+59
-51
lines changed

3 files changed

+59
-51
lines changed

examples/relax/lcao_output/INPUT

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ suffix autotest
55
nbands 8
66
calculation relax #cell-relax
77
ecutwfc 10
8-
scf_nmax 2
8+
scf_nmax 20
99

1010
basis_type lcao
11-
relax_nmax 5
11+
relax_nmax 1
1212

1313
cal_stress 1
1414
stress_thr 1e-6
@@ -25,16 +25,19 @@ relax_method bfgs
2525
pseudo_dir ../../../tests/PP_ORB
2626
orbital_dir ../../../tests/PP_ORB
2727

28-
nspin 4
28+
nspin 1
2929

30-
out_chg 1
31-
out_pot 1
32-
out_dmk 1
33-
out_dmr 1
30+
out_mat_hs 0 // note
31+
out_mat_tk 1 // note
32+
out_mat_l 1 // note
33+
out_chg 0 8 // note
34+
out_pot 0
35+
out_dmk 0 // note
36+
out_dmr 0 // note
3437
#out_wfc_lcao 1 // OK
35-
out_dos 1
36-
out_band 1
37-
out_stru 1
38+
out_dos 0
39+
out_band 0
40+
out_stru 0
3841
out_app_flag 0
3942

4043
out_interval 1

source/source_io/read_input_item_output.cpp

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -197,34 +197,36 @@ void ReadInput::item_output()
197197
{
198198
Input_Item item("out_dmk");
199199
item.annotation = ">0 output density matrix DM(k) for each k-point";
200-
item.read_value = [](const Input_Item& item, Parameter& para) {
201-
const size_t count = item.get_size();
202-
if (count != 1 && count != 2)
203-
{
204-
ModuleBase::WARNING_QUIT("ReadInput", "out_dmk should have 1 or 2 values");
205-
}
206-
para.input.out_dmk[0] = assume_as_boolean(item.str_values[0]);
207-
para.input.out_dmk[1] = (count == 2) ? std::stoi(item.str_values[1]) : 8;
208-
if (para.input.calculation == "get_pchg" || para.input.calculation == "get_wf")
209-
{
210-
para.input.out_dmk[0] = 0;
211-
}
212-
};
213-
200+
item.read_value = [](const Input_Item& item, Parameter& para) {
201+
const size_t count = item.get_size();
202+
if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_dmk needs at least 1 value");
203+
para.input.out_dmk[0] = assume_as_boolean(item.str_values[0]);
204+
para.input.out_dmk[1] = 8;
205+
if (count >= 2) try { para.input.out_dmk[1] = std::stoi(item.str_values[1]); }
206+
catch (const std::invalid_argument&) { /* do nothing */ }
207+
catch (const std::out_of_range&) {/* do nothing */}
208+
// some other case
209+
if (para.input.calculation == "get_pchg" || para.input.calculation == "get_wf")
210+
{
211+
para.input.out_dmk[0] = 0;
212+
}
213+
};
214214
sync_intvec(input.out_dmk, 2, 0);
215215
this->add_item(item);
216216
}
217217
{
218218
Input_Item item("out_dmr");
219219
item.annotation = "output density matrix DM(R) with respect to lattice vector R (with precision 8)";
220-
item.read_value = [](const Input_Item& item, Parameter& para) {
221-
const size_t count = item.get_size();
222-
if (count != 1 && count != 2)
223-
{
224-
ModuleBase::WARNING_QUIT("ReadInput", "out_dmr should have 1 or 2 values");
225-
}
226-
para.input.out_dmr[0] = assume_as_boolean(item.str_values[0]);
227-
para.input.out_dmr[1] = (count == 2) ? std::stoi(item.str_values[1]) : 8;
220+
221+
item.read_value = [](const Input_Item& item, Parameter& para) {
222+
const size_t count = item.get_size();
223+
if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_dmr needs at least 1 value");
224+
para.input.out_dmr[0] = assume_as_boolean(item.str_values[0]);
225+
para.input.out_dmr[1] = 8;
226+
if (count >= 2) try { para.input.out_dmr[1] = std::stoi(item.str_values[1]); }
227+
catch (const std::invalid_argument&) { /* do nothing */ }
228+
catch (const std::out_of_range&) {/* do nothing */}
229+
// some special case
228230
if (para.input.calculation == "get_pchg" || para.input.calculation == "get_wf")
229231
{
230232
para.input.out_dmr[0] = 0;
@@ -271,15 +273,15 @@ void ReadInput::item_output()
271273
}
272274
{
273275
Input_Item item("out_mat_tk");
274-
item.annotation = "output kinetic matrix T(k)";
275-
item.read_value = [](const Input_Item& item, Parameter& para) {
276-
const size_t count = item.get_size();
277-
if (count != 1 && count != 2)
278-
{
279-
ModuleBase::WARNING_QUIT("ReadInput", "out_mat_tk should have 1 or 2 values");
280-
}
281-
para.input.out_mat_tk[0] = assume_as_boolean(item.str_values[0]);
282-
para.input.out_mat_tk[1] = (count == 2) ? std::stoi(item.str_values[1]) : 8;
276+
item.annotation = "output kinetic matrix of electrons T(k)";
277+
item.read_value = [](const Input_Item& item, Parameter& para) {
278+
const size_t count = item.get_size();
279+
if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_mat_tk needs at least 1 value");
280+
para.input.out_mat_tk[0] = assume_as_boolean(item.str_values[0]);
281+
para.input.out_mat_tk[1] = 8;
282+
if (count >= 2) try { para.input.out_mat_tk[1] = std::stoi(item.str_values[1]); }
283+
catch (const std::invalid_argument&) { /* do nothing */ }
284+
catch (const std::out_of_range&) {/* do nothing */}
283285
};
284286
sync_intvec(input.out_mat_tk, 2, 0);
285287
this->add_item(item);
@@ -299,14 +301,14 @@ void ReadInput::item_output()
299301
{
300302
Input_Item item("out_mat_l");
301303
item.annotation = "output the expectation values of angular momentum operators";
302-
item.read_value = [](const Input_Item& item, Parameter& para) {
303-
const size_t count = item.get_size();
304-
if (count != 1 && count != 2)
305-
{
306-
ModuleBase::WARNING_QUIT("ReadInput", "out_mat_l should have 1 or 2 values");
307-
}
308-
para.input.out_mat_l[0] = assume_as_boolean(item.str_values[0]);
309-
para.input.out_mat_l[1] = (count == 2) ? std::stoi(item.str_values[1]) : 8;
304+
item.read_value = [](const Input_Item& item, Parameter& para) {
305+
const size_t count = item.get_size();
306+
if (count < 1) ModuleBase::WARNING_QUIT("ReadInput", "out_mat_l needs at least 1 value");
307+
para.input.out_mat_l[0] = assume_as_boolean(item.str_values[0]);
308+
para.input.out_mat_l[1] = 8;
309+
if (count >= 2) try { para.input.out_mat_l[1] = std::stoi(item.str_values[1]); }
310+
catch (const std::invalid_argument&) { /* do nothing */ }
311+
catch (const std::out_of_range&) {/* do nothing */}
310312
};
311313
sync_intvec(input.out_mat_l, 2, 0);
312314
this->add_item(item);
@@ -521,10 +523,13 @@ void ReadInput::item_output()
521523
item.read_value = [](const Input_Item& item, Parameter& para) {
522524
size_t count = item.get_size();
523525
std::vector<int> out_xc_r(count); // create a placeholder vector
524-
std::transform(item.str_values.begin(), item.str_values.end(), out_xc_r.begin(), [](std::string s) { return std::stoi(s); });
526+
std::transform(item.str_values.begin(),
527+
item.str_values.end(),
528+
out_xc_r.begin(), [](std::string s) { return std::stoi(s); });
525529
// assign non-negative values to para.input.out_xc_r
526530
std::copy(out_xc_r.begin(), out_xc_r.end(), para.input.out_xc_r.begin());
527531
};
532+
// check value
528533
item.check_value = [](const Input_Item& item, const Parameter& para) {
529534
if (para.input.out_xc_r[0] >= 0)
530535
{

tests/02_NAO_Gamma/018_NO_GO_ODM/INPUT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ basis_type lcao
44
calculation scf
55
gamma_only 1
66

7-
out_dmk 1 // file name is dms1_nao.txt
7+
out_dmk 1 // file name is dm_nao.txt
88
nbands 4
99
latname sc
1010
ecutwfc 25.0 // Rydberg

0 commit comments

Comments
 (0)