Skip to content

Commit

Permalink
fix: the natom in abacus.json (#3822)
Browse files Browse the repository at this point in the history
  • Loading branch information
pxlxingliang committed Mar 27, 2024
1 parent 6b13a52 commit 2ddb038
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
6 changes: 5 additions & 1 deletion docs/advanced/json/json_para.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

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.

Notice: one need to add the option `-DENABLE_RAPIDJSON=ON` when compiling ABACUS to enable the output of "abacus.json".


## General Information

- `version` - [str] The version number of ABACUS.
Expand Down Expand Up @@ -39,10 +42,11 @@ This JSON template provides input and output configurations for ABACUS. It conta
- `point_group` - [str] the Schoenflies name of the point group.
- `point_group_in_space` - [str] the Schoenflies name of the point group in the space group.
- `nkstot`, `nkstot_ibz` - [int] Total number of k-points and total number of irreducible k-points.
- `nelectron_each_type` - [object(str-int)] The number of electrons for each atom type, e.g., `{"C": 2, "H":1}`.
- `nelectron_each_type` - [object(str-int)] The number of valence electron for each atom type, e.g., `{"C": 2, "H":1}`.
- `nelectron` - [int] Total number of electrons.
- `nband` - [int] Number of bands.
- `natom` - [int] Total number of atoms.
- `natom_each_type` - [object(str-int)] The atom number of each atom type, e.g., `{"C": 2, "H":1}`.
- `label` - [array(str)] An array of atomic labels.
- `element` - [array(object(str:str))] The element of each atom type.
- `cell` - [array(array(double))] The lattice vector. Unit in Angstrom.
Expand Down
5 changes: 4 additions & 1 deletion source/module_io/json_output/init_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void gen_init(UnitCell *ucell){
// Json::AbacusJson::add_Json(pgname,false,"init", "point_group");
// Json::AbacusJson::add_Json(spgname,false,"init","point_group_in_space");

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

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

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


//Json::AbacusJson::add_Json(number,false,"init", "nelectron_each_type",label);
}

Expand Down
27 changes: 19 additions & 8 deletions source/module_io/json_output/test/para_json_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,24 @@ TEST(AbacusJsonTest, InitInfo)
ucell.symm.pgname = "T_d";
ucell.symm.spgname = "O_h";
ucell.atoms =atomlist;
ucell.atoms->na = 100;
ucell.ntype = 3;
GlobalV::NBANDS = 10;


for(int i=0;i<1;i++){
ucell.atoms[i].label = "Si";
ucell.atoms[i].ncpp.zv = 3;


ucell.atoms[0].label = "Si";
ucell.atoms[0].ncpp.zv = 3;
ucell.atoms[0].na = 1;
ucell.atoms[1].label = "C";
ucell.atoms[1].ncpp.zv = 4;
ucell.atoms[1].na = 2;
ucell.atoms[2].label = "O";
ucell.atoms[2].ncpp.zv = 5;
ucell.atoms[2].na = 3;
ucell.nat = 0;
for(int i=0;i<ucell.ntype;i++){
ucell.nat += ucell.atoms[i].na;
}


// init the doc allocator
Json::AbacusJson::doc.Parse("{}");
int Jnkstot=1,Jnkstot_ibz = 2;
Expand All @@ -313,15 +319,20 @@ TEST(AbacusJsonTest, InitInfo)
ASSERT_EQ(Json::AbacusJson::doc["init"]["nkstot"].GetInt(), 1);
ASSERT_EQ(Json::AbacusJson::doc["init"]["nkstot_ibz"].GetInt(), 2);

ASSERT_EQ(Json::AbacusJson::doc["init"]["natom"].GetInt(), 100);
ASSERT_EQ(Json::AbacusJson::doc["init"]["natom"].GetInt(), 6);
ASSERT_EQ(Json::AbacusJson::doc["init"]["nband"].GetInt(), 10);


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

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

ASSERT_EQ(Json::AbacusJson::doc["init"]["natom_each_type"]["Si"].GetInt(), 1);
ASSERT_EQ(Json::AbacusJson::doc["init"]["natom_each_type"]["C"].GetInt(), 2);
ASSERT_EQ(Json::AbacusJson::doc["init"]["natom_each_type"]["O"].GetInt(), 3);
}


Expand Down

0 comments on commit 2ddb038

Please sign in to comment.