46 std::ofstream stream(path);
48 throw std::runtime_error(
"Cannot write xsf file: " + path);
52 stream <<
"CRYSTAL\n";
53 stream <<
"PRIMVEC\n";
54 stream << std::fixed << std::setprecision(10);
55 for (
int axis = 0; axis < 3; axis++) {
56 for (
int component = 0; component < 3; component++)
57 stream << std::setw(20)
61 stream <<
"PRIMCOORD\n";
63 for (
int atom_index = 0; atom_index < field.
number_of_atoms(); atom_index++) {
66 for (
int component = 0; component < 3; component++)
67 stream << std::setw(20) << position[component] * bohr_to_angstrom;
72 stream <<
"BEGIN_BLOCK_DATAGRID_3D\n";
73 stream <<
" Q3_" << datagrid_name(field) <<
"\n";
74 stream <<
" BEGIN_DATAGRID_3D_Q3_" << datagrid_name(field) <<
"\n";
75 stream <<
" " << dimensions[0] + 1 <<
" " << dimensions[1] + 1 <<
" " << dimensions[2] + 1
77 stream <<
" " << std::setw(20) << 0.0 << std::setw(20) << 0.0 << std::setw(20) << 0.0
79 for (
int axis = 0; axis < 3; axis++) {
81 for (
int component = 0; component < 3; component++)
82 stream << std::setw(20)
87 stream << std::scientific << std::setprecision(10);
88 int values_on_line = 0;
89 for (
int index_3 = 0; index_3 <= dimensions[2]; index_3++) {
90 for (
int index_2 = 0; index_2 <= dimensions[1]; index_2++) {
91 for (
int index_1 = 0; index_1 <= dimensions[0]; index_1++) {
92 stream << std::setw(18)
93 << field.
value(index_1 % dimensions[0],
94 index_2 % dimensions[1],
95 index_3 % dimensions[2]);
96 if (++values_on_line == values_per_line) {
103 if (values_on_line != 0)
106 stream <<
" END_DATAGRID_3D\n";
107 stream <<
"END_BLOCK_DATAGRID_3D\n";
111 throw std::runtime_error(
"Failed while writing xsf file: " + path);