Skip to content

Commit f1fc5ba

Browse files
committed
change print_stru_file
1 parent 4666a0e commit f1fc5ba

File tree

9 files changed

+142
-135
lines changed

9 files changed

+142
-135
lines changed

source/module_cell/print_cell.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,95 @@ namespace unitcell
4141
GlobalV::ofs_running << table << std::endl;
4242
return;
4343
}
44+
45+
void print_stru_file(const UnitCell& ucell,
46+
const Atom* atoms,
47+
const ModuleBase::Matrix3& latvec,
48+
const std::string& fn,
49+
const int& nspin,
50+
const bool& direct,
51+
const bool& vel,
52+
const bool& magmom,
53+
const bool& orb,
54+
const bool& dpks_desc,
55+
const int& iproc)
56+
{
57+
ModuleBase::TITLE("UnitCell","print_stru_file");
58+
if (iproc != 0)
59+
{
60+
return; // old: if(GlobalV::MY_RANK != 0) return;
61+
}
62+
// ATOMIC_SPECIES
63+
std::string str = "ATOMIC_SPECIES\n";
64+
for(int it=0; it<ucell.ntype; it++)
65+
{
66+
str += FmtCore::format("%s %8.4f %s %s\n",
67+
ucell.atom_label[it],
68+
ucell.atom_mass[it],
69+
ucell.pseudo_fn[it],
70+
ucell.pseudo_type[it]);
71+
}
72+
// NUMERICAL_ORBITAL
73+
if(orb)
74+
{
75+
str += "\nNUMERICAL_ORBITAL\n";
76+
for(int it = 0; it < ucell.ntype; it++)
77+
{
78+
str += ucell.orbital_fn[it] + "\n";
79+
}
80+
}
81+
// NUMERICAL_DESCRIPTOR
82+
if(dpks_desc)
83+
{
84+
str += "\nNUMERICAL_DESCRIPTOR\n" + ucell.descriptor_file + "\n";
85+
}
86+
// LATTICE_CONSTANT
87+
str += "\nLATTICE_CONSTANT\n" + FmtCore::format("%-.10f\n", ucell.lat0);
88+
// LATTICE_VECTORS
89+
str += "\nLATTICE_VECTORS\n";
90+
str += FmtCore::format("%20.10f%20.10f%20.10f\n", latvec.e11, latvec.e12, latvec.e13);
91+
str += FmtCore::format("%20.10f%20.10f%20.10f\n", latvec.e21, latvec.e22, latvec.e23);
92+
str += FmtCore::format("%20.10f%20.10f%20.10f\n", latvec.e31, latvec.e32, latvec.e33);
93+
// ATOMIC_POSITIONS
94+
str += "\nATOMIC_POSITIONS\n";
95+
const std::string scale = direct? "Direct": "Cartesian";
96+
int nat_ = 0; // counter iat, for printing out Mulliken magmom who is indexed by iat
97+
str += scale + "\n";
98+
for(int it = 0; it < ucell.ntype; it++)
99+
{
100+
str += "\n" + ucell.atoms[it].label + " #label\n";
101+
str += FmtCore::format("%-8.4f #magnetism\n", ucell.magnet.start_magnetization[it]);
102+
str += FmtCore::format("%d #number of atoms\n", atoms[it].na);
103+
for(int ia = 0; ia < atoms[it].na; ia++)
104+
{
105+
// output position
106+
const double& x = direct? atoms[it].taud[ia].x: atoms[it].tau[ia].x;
107+
const double& y = direct? atoms[it].taud[ia].y: atoms[it].tau[ia].y;
108+
const double& z = direct? atoms[it].taud[ia].z: atoms[it].tau[ia].z;
109+
str += FmtCore::format("%20.10f%20.10f%20.10f", x, y, z);
110+
str += FmtCore::format(" m%2d%2d%2d", atoms[it].mbl[ia].x, atoms[it].mbl[ia].y, atoms[it].mbl[ia].z);
111+
if (vel) // output velocity
112+
{
113+
str += FmtCore::format(" v%20.10f%20.10f%20.10f", atoms[it].vel[ia].x, atoms[it].vel[ia].y, atoms[it].vel[ia].z);
114+
}
115+
if (nspin == 2 && magmom) // output magnetic information
116+
{
117+
str += FmtCore::format(" mag%8.4f", ucell.atom_mulliken[nat_][1]);
118+
}
119+
else if (nspin == 4 && magmom) // output magnetic information
120+
{
121+
str += FmtCore::format(" mag%8.4f%8.4f%8.4f",
122+
ucell.atom_mulliken[nat_][1],
123+
ucell.atom_mulliken[nat_][2],
124+
ucell.atom_mulliken[nat_][3]);
125+
}
126+
str += "\n";
127+
nat_++;
128+
}
129+
}
130+
std::ofstream ofs(fn.c_str());
131+
ofs << str;
132+
ofs.close();
133+
return;
134+
}
44135
}

source/module_cell/print_cell.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ namespace unitcell
99
const std::string& Coordinate,
1010
const int ntype,
1111
const double lat0);
12+
13+
/**
14+
* @brief UnitCell class is too heavy, this function would be moved
15+
* elsewhere. Print STRU file respect to given setting
16+
*
17+
* @param ucell reference of unitcell
18+
* @param atoms Atom list
19+
* @param latvec lattice const parmater vector
20+
* @param fn STRU file name
21+
* @param nspin PARAM.inp.nspin feed in
22+
* @param direct true for direct coords, false for cartesian coords
23+
* @param vol true for printing velocities
24+
* @param magmom true for printing Mulliken population analysis produced
25+
* magmom
26+
* @param orb true for printing NUMERICAL_ORBITAL section
27+
* @param dpks_desc true for printing NUMERICAL_DESCRIPTOR section
28+
* @param iproc GlobalV::MY_RANK feed in
29+
*/
30+
void print_stru_file(const UnitCell& ucell,
31+
const Atom* atoms,
32+
const ModuleBase::Matrix3& latvec,
33+
const std::string& fn,
34+
const int& nspin = 1,
35+
const bool& direct = false,
36+
const bool& vel = false,
37+
const bool& magmom = false,
38+
const bool& orb = false,
39+
const bool& dpks_desc = false,
40+
const int& iproc = 0);
1241
}
1342

1443
#endif

source/module_cell/read_atoms.cpp

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -564,92 +564,4 @@ bool UnitCell::read_atom_positions(std::ifstream &ifpos, std::ofstream &ofs_runn
564564
}//end read_atom_positions
565565

566566

567-
void UnitCell::print_stru_file(const std::string& fn,
568-
const int& nspin,
569-
const bool& direct,
570-
const bool& vel,
571-
const bool& magmom,
572-
const bool& orb,
573-
const bool& dpks_desc,
574-
const int& iproc) const
575-
{
576-
ModuleBase::TITLE("UnitCell","print_stru_file");
577-
if (iproc != 0) {
578-
return; // old: if(GlobalV::MY_RANK != 0) return;
579-
}
580-
// ATOMIC_SPECIES
581-
std::string str = "ATOMIC_SPECIES\n";
582-
for(int it=0; it<ntype; it++){ str += FmtCore::format("%s %8.4f %s %s\n", atom_label[it], atom_mass[it], pseudo_fn[it], pseudo_type[it]); }
583-
// NUMERICAL_ORBITAL
584-
if(orb)
585-
{
586-
str += "\nNUMERICAL_ORBITAL\n";
587-
for(int it = 0; it < ntype; it++) { str += orbital_fn[it] + "\n"; }
588-
}
589-
// NUMERICAL_DESCRIPTOR
590-
if(dpks_desc) { str += "\nNUMERICAL_DESCRIPTOR\n" + descriptor_file + "\n"; }
591-
// LATTICE_CONSTANT
592-
str += "\nLATTICE_CONSTANT\n" + FmtCore::format("%-.10f\n", lat0);
593-
// LATTICE_VECTORS
594-
str += "\nLATTICE_VECTORS\n";
595-
str += FmtCore::format("%20.10f%20.10f%20.10f\n", latvec.e11, latvec.e12, latvec.e13);
596-
str += FmtCore::format("%20.10f%20.10f%20.10f\n", latvec.e21, latvec.e22, latvec.e23);
597-
str += FmtCore::format("%20.10f%20.10f%20.10f\n", latvec.e31, latvec.e32, latvec.e33);
598-
// ATOMIC_POSITIONS
599-
str += "\nATOMIC_POSITIONS\n";
600-
const std::string scale = direct? "Direct": "Cartesian";
601-
int nat_ = 0; // counter iat, for printing out Mulliken magmom who is indexed by iat
602-
str += scale + "\n";
603-
for(int it = 0; it < ntype; it++)
604-
{
605-
str += "\n" + atoms[it].label + " #label\n";
606-
str += FmtCore::format("%-8.4f #magnetism\n", magnet.start_magnetization[it]);
607-
str += FmtCore::format("%d #number of atoms\n", atoms[it].na);
608-
for(int ia = 0; ia < atoms[it].na; ia++)
609-
{
610-
// output position
611-
const double& x = direct? atoms[it].taud[ia].x: atoms[it].tau[ia].x;
612-
const double& y = direct? atoms[it].taud[ia].y: atoms[it].tau[ia].y;
613-
const double& z = direct? atoms[it].taud[ia].z: atoms[it].tau[ia].z;
614-
str += FmtCore::format("%20.10f%20.10f%20.10f", x, y, z);
615-
str += FmtCore::format(" m%2d%2d%2d", atoms[it].mbl[ia].x, atoms[it].mbl[ia].y, atoms[it].mbl[ia].z);
616-
if (vel) // output velocity
617-
{
618-
str += FmtCore::format(" v%20.10f%20.10f%20.10f", atoms[it].vel[ia].x, atoms[it].vel[ia].y, atoms[it].vel[ia].z);
619-
}
620-
if (nspin == 2 && magmom) // output magnetic information
621-
{
622-
str += FmtCore::format(" mag%8.4f", atom_mulliken[nat_][1]);
623-
}
624-
else if (nspin == 4 && magmom) // output magnetic information
625-
{
626-
str += FmtCore::format(" mag%8.4f%8.4f%8.4f", atom_mulliken[nat_][1], atom_mulliken[nat_][2], atom_mulliken[nat_][3]);
627-
}
628-
str += "\n";
629-
nat_++;
630-
}
631-
}
632-
std::ofstream ofs(fn.c_str());
633-
ofs << str;
634-
ofs.close();
635-
return;
636-
}
637-
638-
639-
/*
640-
int UnitCell::find_type(const std::string &label)
641-
{
642-
if(PARAM.inp.test_pseudo_cell) ModuleBase::TITLE("UnitCell","find_type");
643-
assert(ntype>0);
644-
for(int it=0;it<ntype;it++)
645-
{
646-
if(atoms[it].label == label)
647-
{
648-
return it;
649-
}
650-
}
651-
ModuleBase::WARNING_QUIT("UnitCell::find_type","Can not find the atom type!");
652-
return -1;
653-
}
654-
*/
655567

source/module_cell/test/support/mock_unitcell.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ void UnitCell::update_force(ModuleBase::matrix& fcs) {}
3131
void UnitCell::set_iat2itia() {}
3232
void UnitCell::setup_cell(const std::string& fn, std::ofstream& log) {}
3333
int UnitCell::find_type(const std::string& label) { return 0; }
34-
void UnitCell::print_stru_file(const std::string& fn,
35-
const int& nspin,
36-
const bool& direct,
37-
const bool& vel,
38-
const bool& magmom,
39-
const bool& orb,
40-
const bool& dpks_desc,
41-
const int& iproc) const {}
4234
void UnitCell::cal_nwfc(std::ofstream& log) {}
4335
void UnitCell::cal_meshx() {}
4436
void UnitCell::cal_natomwfc(std::ofstream& log) {}

source/module_cell/test/unitcell_test.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ TEST_F(UcellTest, PrintSTRU)
895895
* CASE: nspin1|Cartesian|no vel|no mag|no orb|no dpks_desc|rank0
896896
*
897897
*/
898-
ucell->print_stru_file(fn, 1, false, false, false, false, false, 0);
898+
unitcell::print_stru_file(*ucell,ucell->atoms,ucell->latvec,
899+
fn, 1, false, false, false, false, false, 0);
899900
std::ifstream ifs;
900901
ifs.open("C1H2_STRU");
901902
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
@@ -926,7 +927,8 @@ TEST_F(UcellTest, PrintSTRU)
926927
* CASE: nspin2|Direct|vel|no mag|no orb|no dpks_desc|rank0
927928
*
928929
*/
929-
ucell->print_stru_file(fn, 2, true, true, false, false, false, 0);
930+
unitcell::print_stru_file(*ucell,ucell->atoms,ucell->latvec,
931+
fn, 1, false, false, false, false, false, 0);
930932
ifs.open("C1H2_STRU");
931933
str = {(std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()};
932934
EXPECT_THAT(str, testing::HasSubstr("ATOMIC_SPECIES"));
@@ -967,7 +969,8 @@ TEST_F(UcellTest, PrintSTRU)
967969
ucell->orbital_fn[1] = "__unittest_orbital_fn_1__";
968970
ucell->atom_mulliken
969971
= {{-1, 0.5}, {-1, 0.4}, {-1, 0.3}}; // first index is iat, the second is components, starts seems from 1
970-
ucell->print_stru_file(fn, 2, true, false, true, true, true, 0);
972+
unitcell::print_stru_file(*ucell,ucell->atoms,ucell->latvec,
973+
fn, 1, false, false, false, false, false, 0);
971974
ifs.open("C1H2_STRU");
972975
str = {(std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()};
973976
EXPECT_THAT(str, testing::HasSubstr("ATOMIC_SPECIES"));

source/module_cell/unitcell.h

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -236,29 +236,7 @@ class UnitCell {
236236
std::ofstream& ofs_warning); // read in atomic positions
237237

238238
int find_type(const std::string& label);
239-
/**
240-
* @brief UnitCell class is too heavy, this function would be moved
241-
* elsewhere. Print STRU file respect to given setting
242-
*
243-
* @param fn STRU file name
244-
* @param nspin PARAM.inp.nspin feed in
245-
* @param direct true for direct coords, false for cartesian coords
246-
* @param vol true for printing velocities
247-
* @param magmom true for printing Mulliken population analysis produced
248-
* magmom
249-
* @param orb true for printing NUMERICAL_ORBITAL section
250-
* @param dpks_desc true for printing NUMERICAL_DESCRIPTOR section
251-
* @param iproc GlobalV::MY_RANK feed in
252-
*/
253-
void print_stru_file(const std::string& fn,
254-
const int& nspin = 1,
255-
const bool& direct = false,
256-
const bool& vel = false,
257-
const bool& magmom = false,
258-
const bool& orb = false,
259-
const bool& dpks_desc = false,
260-
const int& iproc = 0) const;
261-
// void check_dtau();
239+
262240
// for constrained vc-relaxation where type of lattice
263241
// is fixed, adjust the lattice vectors
264242

source/module_md/run_md.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "nhchain.h"
1212
#include "verlet.h"
1313
#include "module_cell/update_cell.h"
14+
#include "module_cell/print_cell.h"
1415
namespace Run_MD
1516
{
1617

@@ -107,7 +108,10 @@ void md_line(UnitCell& unit_in, ModuleESolver::ESolver* p_esolver, const Paramet
107108
need_orb = need_orb && PARAM.inp.init_wfc.substr(0, 3)=="nao";
108109
need_orb = need_orb || PARAM.inp.basis_type=="lcao";
109110
need_orb = need_orb || PARAM.inp.basis_type=="lcao_in_pw";
110-
unit_in.print_stru_file(file.str(),
111+
unitcell::print_stru_file(unit_in,
112+
unit_in.atoms,
113+
unit_in.latvec,
114+
file.str(),
111115
PARAM.inp.nspin,
112116
false, // Cartesian coordinates
113117
PARAM.inp.calculation == "md",

source/module_relax/relax_driver.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "module_io/read_exit_file.h"
1010
#include "module_io/write_wfc_r.h"
1111
#include "module_parameter/parameter.h"
12+
#include "module_cell/print_cell.h"
13+
1214
void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver, UnitCell& ucell)
1315
{
1416
ModuleBase::TITLE("Ions", "opt_ions");
@@ -100,7 +102,10 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver, UnitCell& uce
100102
need_orb = need_orb || PARAM.inp.basis_type == "lcao_in_pw";
101103
std::stringstream ss, ss1;
102104
ss << PARAM.globalv.global_out_dir << "STRU_ION_D";
103-
ucell.print_stru_file(ss.str(),
105+
unitcell::print_stru_file(ucell,
106+
ucell.atoms,
107+
ucell.latvec,
108+
ss.str(),
104109
PARAM.inp.nspin,
105110
true,
106111
PARAM.inp.calculation == "md",
@@ -113,7 +118,10 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver, UnitCell& uce
113118
{
114119
ss1 << PARAM.globalv.global_out_dir << "STRU_ION";
115120
ss1 << istep << "_D";
116-
ucell.print_stru_file(ss1.str(),
121+
unitcell::print_stru_file(ucell,
122+
ucell.atoms,
123+
ucell.latvec,
124+
ss1.str(),
117125
PARAM.inp.nspin,
118126
true,
119127
PARAM.inp.calculation == "md",

source/module_relax/relax_new/test/relax_test.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@ namespace GlobalC
99
UnitCell::UnitCell(){};
1010
UnitCell::~UnitCell(){};
1111

12-
13-
void UnitCell::print_stru_file(const std::string& fn,
14-
const int& nspin,
15-
const bool& direct,
16-
const bool& vel,
17-
const bool& magmom,
18-
const bool& orb,
19-
const bool& dpks_desc,
20-
const int& iproc) const {};
21-
2212
Magnetism::Magnetism(){};
2313
Magnetism::~Magnetism(){};
2414

0 commit comments

Comments
 (0)