Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: output mag in polar coordinates #4600

Merged
merged 1 commit into from
Jul 8, 2024
Merged
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
18 changes: 15 additions & 3 deletions source/module_io/output_mulliken.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,18 +450,30 @@ void Output_Mulliken<TK>::print_atom_mag(const std::vector<std::vector<double>>&
}
else if (this->nspin_ == 4)
{
const std::vector<std::string> title = {"Total Magnetism (uB)", "", "", ""};
const std::vector<std::string> fmts = {"%-26s", "%20.10f", "%20.10f", "%20.10f"};
FmtTable table(title, nat, fmts, {FmtTable::Align::RIGHT, FmtTable::Align::LEFT});
std::vector<double> magnitude(nat, 0.0);
std::vector<double> polar(nat, 0.0);
std::vector<double> azimuth(nat, 0.0);
const std::vector<std::string> title = {"Total Magnetism (uB)", "x", "y", "z"};
const std::vector<std::string> fmts = {"%26s", "%20.10f", "%20.10f", "%20.10f"};
FmtTable table(title, nat, fmts, {FmtTable::Align::RIGHT, FmtTable::Align::RIGHT});
for (int iat = 0; iat < nat; ++iat)
{
atom_label.push_back(this->cell_index_->get_atom_label(iat, true));
mag_x[iat] = atom_chg[iat][1];
mag_y[iat] = atom_chg[iat][2];
mag_z[iat] = atom_chg[iat][3];
magnitude[iat] = std::sqrt(mag_x[iat] * mag_x[iat] + mag_y[iat] * mag_y[iat] + mag_z[iat] * mag_z[iat]);
polar[iat] = std::acos(mag_z[iat] / magnitude[iat]) * 180.0 / ModuleBase::PI;
azimuth[iat] = std::atan2(mag_y[iat], mag_x[iat]) * 180.0 / ModuleBase::PI;
}
table << atom_label << mag_x << mag_y << mag_z;
os << table.str() << std::endl;
/// output mag in polar coordinates
const std::vector<std::string> title_polar = {"Total Magnetism (uB)", "Magnitude (uB)", "Polar (degree)", "Azimuth (degree)"};
const std::vector<std::string> fmts_polar = {"%26s", "%20.10f", "%20.10f", "%20.10f"};
FmtTable table_polar(title_polar, nat, fmts_polar, {FmtTable::Align::RIGHT, FmtTable::Align::RIGHT});
table_polar << atom_label << magnitude << polar << azimuth;
os << table_polar.str() << std::endl;
}
else if (this->nspin_ == 1)
{
Expand Down
Loading