Skip to content

Commit 2ddb038

Browse files
authored
fix: the natom in abacus.json (#3822)
1 parent 6b13a52 commit 2ddb038

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

docs/advanced/json/json_para.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212

1313
This JSON template provides input and output configurations for ABACUS. It contains parameters for the execution of the program and the output of results, primarily for recording computational processes and outcomes for post processing.
1414

15+
Notice: one need to add the option `-DENABLE_RAPIDJSON=ON` when compiling ABACUS to enable the output of "abacus.json".
16+
17+
1518
## General Information
1619

1720
- `version` - [str] The version number of ABACUS.
@@ -39,10 +42,11 @@ This JSON template provides input and output configurations for ABACUS. It conta
3942
- `point_group` - [str] the Schoenflies name of the point group.
4043
- `point_group_in_space` - [str] the Schoenflies name of the point group in the space group.
4144
- `nkstot`, `nkstot_ibz` - [int] Total number of k-points and total number of irreducible k-points.
42-
- `nelectron_each_type` - [object(str-int)] The number of electrons for each atom type, e.g., `{"C": 2, "H":1}`.
45+
- `nelectron_each_type` - [object(str-int)] The number of valence electron for each atom type, e.g., `{"C": 2, "H":1}`.
4346
- `nelectron` - [int] Total number of electrons.
4447
- `nband` - [int] Number of bands.
4548
- `natom` - [int] Total number of atoms.
49+
- `natom_each_type` - [object(str-int)] The atom number of each atom type, e.g., `{"C": 2, "H":1}`.
4650
- `label` - [array(str)] An array of atomic labels.
4751
- `element` - [array(object(str:str))] The element of each atom type.
4852
- `cell` - [array(array(double))] The lattice vector. Unit in Angstrom.

source/module_io/json_output/init_info.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ void gen_init(UnitCell *ucell){
2121
// Json::AbacusJson::add_Json(pgname,false,"init", "point_group");
2222
// Json::AbacusJson::add_Json(spgname,false,"init","point_group_in_space");
2323

24-
int numAtoms = ucell->atoms->na;
24+
int numAtoms = ucell->nat;
2525
AbacusJson::add_json({"init", "natom"}, numAtoms,false);
2626
AbacusJson::add_json({"init", "nband"}, GlobalV::NBANDS,false);
2727

@@ -32,11 +32,14 @@ void gen_init(UnitCell *ucell){
3232
for (int it = 0; it < ntype; it++)
3333
{
3434
std::string label = ucell->atoms[it].label;
35+
int atom_number = ucell->atoms[it].na;
3536
int number = ucell->atoms[it].ncpp.zv;
3637

3738
nelec_total+=ucell->atoms[it].ncpp.zv * ucell->atoms[it].na;
39+
AbacusJson::add_json({"init", "natom_each_type",label}, atom_number,false);
3840
AbacusJson::add_json({"init", "nelectron_each_type",label}, number,false);
3941

42+
4043
//Json::AbacusJson::add_Json(number,false,"init", "nelectron_each_type",label);
4144
}
4245

source/module_io/json_output/test/para_json_test.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,18 +289,24 @@ TEST(AbacusJsonTest, InitInfo)
289289
ucell.symm.pgname = "T_d";
290290
ucell.symm.spgname = "O_h";
291291
ucell.atoms =atomlist;
292-
ucell.atoms->na = 100;
293292
ucell.ntype = 3;
294293
GlobalV::NBANDS = 10;
295294

296295

297-
for(int i=0;i<1;i++){
298-
ucell.atoms[i].label = "Si";
299-
ucell.atoms[i].ncpp.zv = 3;
300-
296+
297+
ucell.atoms[0].label = "Si";
298+
ucell.atoms[0].ncpp.zv = 3;
299+
ucell.atoms[0].na = 1;
300+
ucell.atoms[1].label = "C";
301+
ucell.atoms[1].ncpp.zv = 4;
302+
ucell.atoms[1].na = 2;
303+
ucell.atoms[2].label = "O";
304+
ucell.atoms[2].ncpp.zv = 5;
305+
ucell.atoms[2].na = 3;
306+
ucell.nat = 0;
307+
for(int i=0;i<ucell.ntype;i++){
308+
ucell.nat += ucell.atoms[i].na;
301309
}
302-
303-
304310
// init the doc allocator
305311
Json::AbacusJson::doc.Parse("{}");
306312
int Jnkstot=1,Jnkstot_ibz = 2;
@@ -313,15 +319,20 @@ TEST(AbacusJsonTest, InitInfo)
313319
ASSERT_EQ(Json::AbacusJson::doc["init"]["nkstot"].GetInt(), 1);
314320
ASSERT_EQ(Json::AbacusJson::doc["init"]["nkstot_ibz"].GetInt(), 2);
315321

316-
ASSERT_EQ(Json::AbacusJson::doc["init"]["natom"].GetInt(), 100);
322+
ASSERT_EQ(Json::AbacusJson::doc["init"]["natom"].GetInt(), 6);
317323
ASSERT_EQ(Json::AbacusJson::doc["init"]["nband"].GetInt(), 10);
318324

319325

320326
ASSERT_STREQ(Json::AbacusJson::doc["init"]["point_group"].GetString(), "T_d");
321327
ASSERT_STREQ(Json::AbacusJson::doc["init"]["point_group_in_space"].GetString(), "O_h");
322328

323329
ASSERT_EQ(Json::AbacusJson::doc["init"]["nelectron_each_type"]["Si"].GetInt(), 3);
330+
ASSERT_EQ(Json::AbacusJson::doc["init"]["nelectron_each_type"]["C"].GetInt(), 4);
331+
ASSERT_EQ(Json::AbacusJson::doc["init"]["nelectron_each_type"]["O"].GetInt(), 5);
324332

333+
ASSERT_EQ(Json::AbacusJson::doc["init"]["natom_each_type"]["Si"].GetInt(), 1);
334+
ASSERT_EQ(Json::AbacusJson::doc["init"]["natom_each_type"]["C"].GetInt(), 2);
335+
ASSERT_EQ(Json::AbacusJson::doc["init"]["natom_each_type"]["O"].GetInt(), 3);
325336
}
326337

327338

0 commit comments

Comments
 (0)