Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions source/source_io/module_json/init_info.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "init_info.h"

#include "source_io/module_parameter/parameter.h"
#include "source_io/module_parameter/input_parameter.h"
#include "para_json.h"
#include "abacusjson.h"

Expand All @@ -10,7 +10,7 @@ namespace Json

#ifdef __RAPIDJSON

void gen_init(UnitCell* ucell)
void gen_init(UnitCell* ucell, const Input_para& inp)
{
std::string pgname = ucell->symm.pgname;
std::string spgname = ucell->symm.spgname;
Expand All @@ -22,7 +22,7 @@ void gen_init(UnitCell* ucell)

int numAtoms = ucell->nat;
AbacusJson::add_json({"init", "natom"}, numAtoms, false);
AbacusJson::add_json({"init", "nband"}, PARAM.inp.nbands, false);
AbacusJson::add_json({"init", "nband"}, inp.nbands, false);

// Json::AbacusJson::add_Json(numAtoms,false,"init", "natom");
// Json::AbacusJson::add_Json(PARAM.inp.nbands,false,"init", "nband");
Expand All @@ -44,6 +44,28 @@ void gen_init(UnitCell* ucell)
AbacusJson::add_json({"init", "nelectron"}, nelec_total, false);

// Json::AbacusJson::add_Json(nelec_total,false,"init", "nelectron");

// energy cutoff for wavefunctions (Ry)
AbacusJson::add_json({"init", "ecutwfc"}, inp.ecutwfc, false);
AbacusJson::add_json({"init", "ecutwfc_unit"}, "Ry", false);

// smearing method and sigma (Ry)
AbacusJson::add_json({"init", "smearing_method"}, inp.smearing_method, false);
AbacusJson::add_json({"init", "smearing_sigma"}, inp.smearing_sigma, false);
AbacusJson::add_json({"init", "smearing_sigma_unit"}, "Ry", false);

// k-point mesh generation parameters
AbacusJson::add_json({"init", "kmesh_type"}, inp.kmesh_type, false);
Json::jsonValue kspacing_array(JarrayType);
kspacing_array.JPushBack(inp.kspacing[0]);
kspacing_array.JPushBack(inp.kspacing[1]);
kspacing_array.JPushBack(inp.kspacing[2]);
AbacusJson::add_json({"init", "kspacing"}, kspacing_array, false);
Json::jsonValue koffset_array(JarrayType);
koffset_array.JPushBack(inp.koffset[0]);
koffset_array.JPushBack(inp.koffset[1]);
koffset_array.JPushBack(inp.koffset[2]);
AbacusJson::add_json({"init", "koffset"}, koffset_array, false);
}

void add_nkstot(int nkstot)
Expand All @@ -54,7 +76,7 @@ void add_nkstot(int nkstot)
// Json::AbacusJson::add_Json(nkstot_ibz,false,"init", "nkstot_ibz");
}

void gen_stru(UnitCell* ucell)
void gen_stru(UnitCell* ucell, const Input_para& inp)
{
AbacusJson::add_json({"comment"},
"Unless otherwise specified, the unit of energy is eV and the unit of length is Angstrom",
Expand All @@ -77,7 +99,7 @@ void gen_stru(UnitCell* ucell)

Json::AbacusJson::add_json({"init", "element", atom_label}, atom_element, false);

std::string orbital_str = PARAM.inp.orbital_dir + orbital_fn[i];
std::string orbital_str = inp.orbital_dir + orbital_fn[i];
if (!orbital_str.compare(""))
{
Json::jsonValue nullValue;
Expand Down
8 changes: 6 additions & 2 deletions source/source_io/module_json/init_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "source_cell/module_symmetry/symmetry.h"
#include "source_cell/unitcell.h"

struct Input_para;

/**
* @brief In this part of the code to complete the init part of the json tree.
*/
Expand All @@ -14,8 +16,9 @@ namespace Json

/**
* @param ucell: ucell for reading json parameters.
* @param inp: input parameters for reading json parameters.
*/
void gen_init(UnitCell* ucell);
void gen_init(UnitCell* ucell, const Input_para& inp);

/**
* @param nkstot,nkstot_ibz: two param in json tree
Expand All @@ -24,8 +27,9 @@ void add_nkstot(int nkstot);

/**
* @param ucell: ucell for reading structure init in abacus.
* @param inp: input parameters for reading orbital directory.
*/
void gen_stru(UnitCell* ucell);
void gen_stru(UnitCell* ucell, const Input_para& inp);
#endif
} // namespace Json
#endif
10 changes: 5 additions & 5 deletions source/source_io/module_json/para_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ void create_Json(UnitCell* ucell, const Parameter& param)
{
#ifdef __RAPIDJSON
gen_general_info(param);
gen_init(ucell);
// gen_stru(ucell);
gen_init(ucell, param.inp);
// gen_stru(ucell, param.inp);
#endif
json_output();
}

void gen_stru_wrapper(UnitCell* ucell)
void gen_stru_wrapper(UnitCell* ucell, const Input_para& inp)
{
#ifdef __RAPIDJSON
#ifdef __MPI
if (GlobalV::MY_RANK == 0)
gen_stru(ucell);
gen_stru(ucell, inp);
#else
gen_stru(ucell);
gen_stru(ucell, inp);
#endif
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion source/source_io/module_json/para_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ void json_output();
void convert_time(std::time_t time_now, std::string& time_str);

// generate struture wrapper function
void gen_stru_wrapper(UnitCell *ucell);
void gen_stru_wrapper(UnitCell *ucell, const Input_para& inp);
} // namespace Json
41 changes: 31 additions & 10 deletions source/source_io/module_json/test/para_json_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,17 @@ TEST(AbacusJsonTest, GeneralInfo)
std::time_t time_now = std::time(nullptr);
std::string start_time_str;
Json::convert_time(time_now, start_time_str);
PARAM.sys.start_time = time_now;

PARAM.input.device = "cpu";
PARAM.input.pseudo_dir = "./abacus/test/pseudo_dir";
PARAM.input.orbital_dir = "./abacus/test/orbital_dir";
PARAM.sys.global_in_stru = "./abacus/test/stru_file";
PARAM.input.kpoint_file = "./abacus/test/kpoint_file";
Parameter param;
param.sys.start_time = time_now;
param.input.device = "cpu";
param.input.pseudo_dir = "./abacus/test/pseudo_dir";
param.input.orbital_dir = "./abacus/test/orbital_dir";
param.sys.global_in_stru = "./abacus/test/stru_file";
param.input.kpoint_file = "./abacus/test/kpoint_file";
// output the json file
Json::AbacusJson::doc.Parse("{}");
Json::gen_general_info(PARAM);
Json::gen_general_info(param);
Json::json_output();

std::string filename = "abacus.json";
Expand Down Expand Up @@ -256,7 +257,14 @@ TEST(AbacusJsonTest, InitInfo)
ucell.symm.spgname = "O_h";
ucell.atoms = atomlist;
ucell.ntype = 3;
PARAM.input.nbands = 10;
Input_para inp;
inp.nbands = 10;
inp.ecutwfc = 50.0;
inp.smearing_method = "gauss";
inp.smearing_sigma = 0.015;
inp.kspacing = {0.04, 0.04, 0.04};
inp.koffset = {0.0, 0.0, 0.0};
inp.kmesh_type = "gamma";

ucell.atoms[0].label = "Si";
ucell.atoms[0].ncpp.zv = 3;
Expand All @@ -277,7 +285,7 @@ TEST(AbacusJsonTest, InitInfo)
int Jnkstot = 1;

Json::add_nkstot(Jnkstot);
Json::gen_init(&ucell);
Json::gen_init(&ucell, inp);

ASSERT_TRUE(Json::AbacusJson::doc.HasMember("init"));
ASSERT_EQ(Json::AbacusJson::doc["init"]["nkstot"].GetInt(), 1);
Expand All @@ -295,6 +303,19 @@ TEST(AbacusJsonTest, InitInfo)
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);

ASSERT_EQ(Json::AbacusJson::doc["init"]["ecutwfc"].GetDouble(), 50.0);
ASSERT_STREQ(Json::AbacusJson::doc["init"]["ecutwfc_unit"].GetString(), "Ry");
ASSERT_STREQ(Json::AbacusJson::doc["init"]["smearing_method"].GetString(), "gauss");
ASSERT_EQ(Json::AbacusJson::doc["init"]["smearing_sigma"].GetDouble(), 0.015);
ASSERT_STREQ(Json::AbacusJson::doc["init"]["smearing_sigma_unit"].GetString(), "Ry");
ASSERT_STREQ(Json::AbacusJson::doc["init"]["kmesh_type"].GetString(), "gamma");
ASSERT_EQ(Json::AbacusJson::doc["init"]["kspacing"][0].GetDouble(), 0.04);
ASSERT_EQ(Json::AbacusJson::doc["init"]["kspacing"][1].GetDouble(), 0.04);
ASSERT_EQ(Json::AbacusJson::doc["init"]["kspacing"][2].GetDouble(), 0.04);
ASSERT_EQ(Json::AbacusJson::doc["init"]["koffset"][0].GetDouble(), 0.0);
ASSERT_EQ(Json::AbacusJson::doc["init"]["koffset"][1].GetDouble(), 0.0);
ASSERT_EQ(Json::AbacusJson::doc["init"]["koffset"][2].GetDouble(), 0.0);
}

TEST(AbacusJsonTest, Init_stru_test)
Expand Down Expand Up @@ -347,7 +368,7 @@ TEST(AbacusJsonTest, Init_stru_test)
ucell.atoms[i].tau[j] = 0.1 * j;
}
}
Json::gen_stru(&ucell);
Json::gen_stru(&ucell, Input_para{});

std::string filename = "readin.json";
Json::AbacusJson::write_to_json(filename);
Expand Down
2 changes: 1 addition & 1 deletion source/source_main/driver_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void Driver::driver_run()

// this Json part should be moved to before_all_runners, mohan 2024-05-12
#ifdef __RAPIDJSON
Json::gen_stru_wrapper(&ucell);
Json::gen_stru_wrapper(&ucell, PARAM.inp);
#endif

const std::string cal = PARAM.inp.calculation;
Expand Down
44 changes: 24 additions & 20 deletions source/source_md/md_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,63 +165,67 @@ void MD_base::print_md(std::ofstream& ofs, const bool& cal_stress)
}

// screen output
std::cout << std::setprecision(8);
std::cout << " ------------------------------------------------------------------------------------------------"
std::cout << " -------------------------------------------------------------------------"
<< std::endl;
std::cout << " " << std::left << std::setw(20) << "Energy (Ry)" << std::left << std::setw(20) << "Potential (Ry)"
<< std::left << std::setw(20) << "Kinetic (Ry)" << std::left << std::setw(20) << "Temperature (K)";
std::cout << " " << std::left << std::setw(24) << "Energy (Ry)" << std::left << std::setw(24) << "Potential (Ry)"
<< std::left << std::setw(24) << "Kinetic (Ry)" << std::endl;
std::cout << std::setprecision(12);
std::cout << " " << std::left << std::setw(24) << 2 * (potential + kinetic) << std::left << std::setw(24)
<< 2 * potential << std::left << std::setw(24) << 2 * kinetic << std::endl;
std::cout << " " << std::left << std::setw(24) << "Temperature (K)";

if (cal_stress)
{
std::cout << std::left << std::setw(20) << "Pressure (kbar)";
std::cout << std::left << std::setw(24) << "Pressure (kbar)";
}

std::cout << std::endl;
std::cout << " " << std::left << std::setw(20) << 2 * (potential + kinetic) << std::left << std::setw(20)
<< 2 * potential << std::left << std::setw(20) << 2 * kinetic << std::left << std::setw(20)
<< t_current * ModuleBase::Hartree_to_K;
std::cout << std::setprecision(6);
std::cout << " " << std::left << std::setw(24) << t_current * ModuleBase::Hartree_to_K;

if (cal_stress)
{
std::cout << std::left << std::setw(20) << press * unit_transform;
std::cout << std::left << std::setw(24) << press * unit_transform;
}

std::cout << std::endl;
std::cout << " ------------------------------------------------------------------------------------------------"
std::cout << " -------------------------------------------------------------------------"
<< std::endl;

// running_log output
ofs.unsetf(std::ios::fixed);
ofs << std::setprecision(8);
ofs << std::setprecision(12);

if (cal_stress)
{
MD_func::print_stress(ofs, virial, stress);
ofs << std::endl;
}

ofs << " ------------------------------------------------------------------------------------------------"
ofs << " -------------------------------------------------------------------------"
<< std::endl;
ofs << " " << std::left << std::setw(20) << "Energy (Ry)" << std::left << std::setw(20) << "Potential (Ry)"
<< std::left << std::setw(20) << "Kinetic (Ry)" << std::left << std::setw(20) << "Temperature (K)";
ofs << " " << std::left << std::setw(24) << "Energy (Ry)" << std::left << std::setw(24) << "Potential (Ry)"
<< std::left << std::setw(24) << "Kinetic (Ry)" << std::endl;
ofs << " " << std::left << std::setw(24) << 2 * (potential + kinetic) << std::left << std::setw(24) << 2 * potential
<< std::left << std::setw(24) << 2 * kinetic << std::endl;
ofs << " " << std::left << std::setw(24) << "Temperature (K)";

if (cal_stress)
{
ofs << std::left << std::setw(20) << "Pressure (kbar)";
ofs << std::left << std::setw(24) << "Pressure (kbar)";
}

ofs << std::endl;
ofs << " " << std::left << std::setw(20) << 2 * (potential + kinetic) << std::left << std::setw(20) << 2 * potential
<< std::left << std::setw(20) << 2 * kinetic << std::left << std::setw(20)
<< t_current * ModuleBase::Hartree_to_K;
ofs << std::setprecision(6);
ofs << " " << std::left << std::setw(24) << t_current * ModuleBase::Hartree_to_K;

if (cal_stress)
{
ofs << std::left << std::setw(20) << press * unit_transform;
ofs << std::left << std::setw(24) << press * unit_transform;
}

ofs << std::endl;
ofs << " ------------------------------------------------------------------------------------------------"
ofs << " -------------------------------------------------------------------------"
<< std::endl;
ofs << std::endl;
return;
Expand Down
22 changes: 14 additions & 8 deletions source/source_md/test/fire_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,32 +185,38 @@ TEST_F(FIREtest, PrintMD)
std::string output_str;

getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992 kbar"));
EXPECT_THAT(output_str, testing::HasSubstr(" ELECTRONIC PART OF STRESS: 0.24609992"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.83853919 kbar"));
EXPECT_THAT(output_str, testing::HasSubstr(" IONIC (KINETIC) PART OF STRESS: 0.838539188441"));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0846391 kbar"));
EXPECT_THAT(output_str, testing::HasSubstr(" MD PRESSURE (ELECTRONS+IONS) : 1.0846391"));
getline(ifs, output_str);
getline(ifs, output_str);
EXPECT_THAT(output_str,
testing::HasSubstr(
" ------------------------------------------------------------------------------------------------"));
" ----------------------------------------"));
getline(ifs, output_str);
EXPECT_THAT(output_str,
testing::HasSubstr(
" Energy (Ry) Potential (Ry) Kinetic (Ry) Temperature (K) Pressure (kbar) "));
" Energy (Ry) Potential (Ry) Kinetic (Ry) "));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr("-0.0153652356062"));
EXPECT_THAT(output_str, testing::HasSubstr("-0.0239156372471"));
EXPECT_THAT(output_str, testing::HasSubstr("0.00855040164087"));
getline(ifs, output_str);
EXPECT_THAT(output_str,
testing::HasSubstr(
" -0.015365236 -0.023915637 0.0085504016 300 1.0846391 "));
" Temperature (K) Pressure (kbar) "));
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr("1.08464"));
getline(ifs, output_str);
EXPECT_THAT(
output_str,
testing::HasSubstr(
" ------------------------------------------------------------------------------------------------"));
" ----------------------------------------"));
getline(ifs, output_str);
getline(ifs, output_str);
EXPECT_THAT(output_str, testing::HasSubstr(" LARGEST FORCE (eV/A) : 0.049479926"));
EXPECT_THAT(output_str, testing::HasSubstr(" LARGEST FORCE (eV/A) : 0.0494799"));

ifs.close();
//remove("running_fire.log");
Expand Down
Loading
Loading