Skip to content

Commit 9b7b758

Browse files
mohanchenabacus_fixer
andauthored
Update cell-relaxation output format (#7752)
* fix a bug when init_wfc=nao in pw basis for nspin=4 * update cell-relax output format, including rename the output STRU files * remove useless words * update documents * update STRU output, the final one is named STRU_FINAL * update out_stru command * update * update out_stru options (3 now) * update fix bug in unitcell_test.cpp * remove PARAM in relax_driver.cpp * fix docs * fix docs * update docs --------- Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
1 parent d40a987 commit 9b7b758

23 files changed

Lines changed: 404 additions & 116 deletions

File tree

docs/advanced/input_files/input-main.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@
17821782
### out_freq_ion
17831783

17841784
- **Type**: Integer
1785-
- **Description**: Controls the output interval in ionic steps. When set to a positive integer, information such as charge density, local potential, electrostatic potential, Hamiltonian matrix, overlap matrix, density matrix, and Mulliken population analysis is printed every n ionic steps.
1785+
- **Description**: Controls the output interval in ionic steps. When set to a positive integer, information such as charge density, local potential, electrostatic potential, Hamiltonian matrix, overlap matrix, density matrix, Mulliken population analysis, and structure files (STRU{istep} or STRU{istep}.cif, when out_stru is 1 or 2) is printed every n ionic steps.
17861786

17871787
> Note: In RT-TDDFT calculations, this parameter is inactive; output frequency is instead controlled by out_freq_td.
17881788
- **Default**: 0
@@ -1969,9 +1969,13 @@
19691969

19701970
### out_stru
19711971

1972-
- **Type**: Boolean
1973-
- **Description**: Whether to output structure files per ionic step in geometry relaxation calculations into OUT.{istep}_D, where ${istep} is the ionic step.
1974-
- **Default**: False
1972+
- **Type**: Integer
1973+
- **Description**: Controls the output of structure files per ionic step in geometry relaxation calculations. The files are written to the OUT.{suffix}/ directory. Each file corresponds to the structure at RELAX STEP ${istep}, i.e., the structure for which that step's energy was computed (before the relax move), and includes a header comment with the ABACUS version, timestamp, energy, and stress tensor. When out_freq_ion is positive, the numbered files STRU{istep} (or STRU{istep}.cif) are written every out_freq_ion steps; when out_freq_ion is 0, no numbered files are output.
1974+
- 0: No structure files are output.
1975+
- 1: ABACUS STRU format files are output. The latest structure is written to STRU_NOW (overwritten each step), the numbered file STRU{istep} (e.g., STRU1, STRU2) is written every out_freq_ion steps (when out_freq_ion is positive), and the final converged structure is written to STRU_FINAL. No CIF files are output.
1976+
- 2: CIF format files are output. The latest structure is written to STRU_NOW.cif (overwritten each step), the numbered file STRU{istep}.cif (e.g., STRU1.cif, STRU2.cif) is written every out_freq_ion steps (when out_freq_ion is positive), and the final converged structure is written to STRU_FINAL.cif. No non-CIF files are output.
1977+
> Note: For backward compatibility, true/false (case insensitive) are accepted and converted to 1/0.
1978+
- **Default**: 1
19751979

19761980
### out_level
19771981

docs/advanced/input_files/stru.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ For general usage requirements, the APNSv1.0 pseudopotential and orbital set is
116116

117117
### LATTICE_CONSTANT
118118

119-
The lattice constant of the system in unit of Bohr.
119+
The lattice constant of the system in unit of Bohr. In output structure files (e.g., `STRU`, `STRU1`, `STRU2`), a trailing comment `# in Bohr` is appended to the value line.
120120
### LATTICE_VECTORS
121121

122-
The lattice vectors of the unit cell. It is a 3by3 matrix written in 3 lines. Please note that *the lattice vectors given here are scaled by the lattice constant*. This section must be removed if the type Bravais lattice is specified using the input parameter `latname`. (See [input parameters](input-main.md#latname).)
122+
The lattice vectors of the unit cell. It is a 3by3 matrix written in 3 lines. Please note that *the lattice vectors given here are scaled by the lattice constant*. This section must be removed if the type Bravais lattice is specified using the input parameter `latname`. (See [input parameters](input-main.md#latname).) In output structure files, a trailing comment `# in units of lat0` is appended to the section header.
123123
### LATTICE_PARAMETERS
124124

125125
This section is only relevant when `latname` (see [input parameters](input-main.md#latname)) is used to specify the Bravais lattice type. The example above is a fcc lattice, where no additional information except the lattice constant is required to determine the geometry of the lattice.

docs/parameters.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2816,7 +2816,7 @@ parameters:
28162816
category: Output information
28172817
type: Integer
28182818
description: |
2819-
Controls the output interval in ionic steps. When set to a positive integer, information such as charge density, local potential, electrostatic potential, Hamiltonian matrix, overlap matrix, density matrix, and Mulliken population analysis is printed every n ionic steps.
2819+
Controls the output interval in ionic steps. When set to a positive integer, information such as charge density, local potential, electrostatic potential, Hamiltonian matrix, overlap matrix, density matrix, Mulliken population analysis, and structure files (STRU{istep} or STRU{istep}.cif, when out_stru is 1 or 2) is printed every n ionic steps.
28202820
28212821
[NOTE] In RT-TDDFT calculations, this parameter is inactive; output frequency is instead controlled by out_freq_td.
28222822
default_value: "0"
@@ -3024,10 +3024,14 @@ parameters:
30243024
availability: ""
30253025
- name: out_stru
30263026
category: Output information
3027-
type: Boolean
3027+
type: Integer
30283028
description: |
3029-
Whether to output structure files per ionic step in geometry relaxation calculations into OUT.{istep}_D, where ${istep} is the ionic step.
3030-
default_value: "False"
3029+
Controls the output of structure files per ionic step in geometry relaxation calculations. The files are written to the OUT.{suffix}/ directory. Each file corresponds to the structure at RELAX STEP ${istep}, i.e., the structure for which that step's energy was computed (before the relax move), and includes a header comment with the ABACUS version, timestamp, energy, and stress tensor. When out_freq_ion is positive, the numbered files STRU{istep} (or STRU{istep}.cif) are written every out_freq_ion steps; when out_freq_ion is 0, no numbered files are output.
3030+
- 0: No structure files are output.
3031+
- 1: ABACUS STRU format files are output. The latest structure is written to STRU_NOW (overwritten each step), the numbered file STRU{istep} (e.g., STRU1, STRU2) is written every out_freq_ion steps (when out_freq_ion is positive), and the final converged structure is written to STRU_FINAL. No CIF files are output.
3032+
- 2: CIF format files are output. The latest structure is written to STRU_NOW.cif (overwritten each step), the numbered file STRU{istep}.cif (e.g., STRU1.cif, STRU2.cif) is written every out_freq_ion steps (when out_freq_ion is positive), and the final converged structure is written to STRU_FINAL.cif. No non-CIF files are output.
3033+
[NOTE] For backward compatibility, true/false (case insensitive) are accepted and converted to 1/0.
3034+
default_value: "1"
30313035
unit: ""
30323036
availability: ""
30333037
- name: out_level

docs/quick_start/hands_on.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ stress_thr 5 # the threshold of the stress convergence, in unit of kBar
211211
relax_nmax 100 # the maximal number of ionic iteration steps
212212
out_stru 1
213213
```
214-
Use the same `KPT`, `STRU`, pseudopotential, and orbital files as in the above SCF-LCAO example. The final optimized structure can be found in `STRU_NOW.cif` and `OUT.MgO/running_cell-relax.log`.
214+
Use the same `KPT`, `STRU`, pseudopotential, and orbital files as in the above SCF-LCAO example. The final optimized structure can be found in `STRU_FINAL` and `OUT.MgO/running_cell-relax.log`.
215215

216216
### A quick PW example
217217

@@ -232,4 +232,4 @@ relax_nmax 100 # the maximal number of ionic iteration steps
232232
out_stru 1
233233
```
234234

235-
Use the same `KPT`, `STRU`, and pseudopotential files as in the above SCF-PW examples. The final optimized structure can be found in `STRU_NOW.cif` and `STRU_ION_D` with different format.
235+
Use the same `KPT`, `STRU`, and pseudopotential files as in the above SCF-PW examples. The final optimized structure can be found in `STRU_FINAL` and `STRU` with different format.

examples/17_relax/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ set `relax_method` to `cg`(default value)
1919
(3)`relax_nmax`: number of ion iteration steps; `force_thr_ev`: force threshold, unit: eV/Angstrom; \
2020
`stress_ev`: stress threshold, unit: kBar.
2121

22-
(4)Output file OUT.ABACUS/STRU_NOW.cif contains the optimized atom positions.
22+
(4)Output file OUT.ABACUS/STRU_FINAL contains the optimized atom positions.
2323

source/source_cell/print_cell.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ namespace unitcell
8080
void print_stru_file(const UnitCell& ucell,
8181
const Atom* atoms,
8282
const ModuleBase::Matrix3& latvec,
83-
const std::string& fn,
83+
const std::string& fn,
84+
const std::string& header,
8485
const int& nspin,
8586
const bool& direct,
8687
const bool& vel,
@@ -90,12 +91,18 @@ namespace unitcell
9091
const int& iproc)
9192
{
9293
ModuleBase::TITLE("UnitCell","print_stru_file");
93-
if (iproc != 0)
94+
if (iproc != 0)
9495
{
9596
return; // old: if(GlobalV::MY_RANK != 0) return;
9697
}
98+
// optional header comments
99+
std::string str;
100+
if (!header.empty())
101+
{
102+
str = header;
103+
}
97104
// ATOMIC_SPECIES
98-
std::string str = "ATOMIC_SPECIES\n";
105+
str += "ATOMIC_SPECIES\n";
99106
for(int it=0; it<ucell.ntype; it++)
100107
{
101108
str += FmtCore::format("%s %8.4f %s %s\n",
@@ -119,12 +126,12 @@ namespace unitcell
119126
str += "\nNUMERICAL_DESCRIPTOR\n" + ucell.descriptor_file + "\n";
120127
}
121128
// LATTICE_CONSTANT
122-
str += "\nLATTICE_CONSTANT\n" + FmtCore::format("%-.10f\n", ucell.lat0);
129+
str += "\nLATTICE_CONSTANT\n" + FmtCore::format("%-.10f", ucell.lat0) + " # in Bohr\n";
123130
// LATTICE_VECTORS
124-
str += "\nLATTICE_VECTORS\n";
125-
str += FmtCore::format("%20.10f%20.10f%20.10f\n", latvec.e11, latvec.e12, latvec.e13);
126-
str += FmtCore::format("%20.10f%20.10f%20.10f\n", latvec.e21, latvec.e22, latvec.e23);
127-
str += FmtCore::format("%20.10f%20.10f%20.10f\n", latvec.e31, latvec.e32, latvec.e33);
131+
str += "\nLATTICE_VECTORS # in units of lat0\n";
132+
str += FmtCore::format("%24.16f%24.16f%24.16f\n", latvec.e11, latvec.e12, latvec.e13);
133+
str += FmtCore::format("%24.16f%24.16f%24.16f\n", latvec.e21, latvec.e22, latvec.e23);
134+
str += FmtCore::format("%24.16f%24.16f%24.16f\n", latvec.e31, latvec.e32, latvec.e33);
128135
// ATOMIC_POSITIONS
129136
str += "\nATOMIC_POSITIONS\n";
130137
const std::string scale = direct? "Direct": "Cartesian";

source/source_cell/print_cell.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace unitcell
3434
* @param atoms Atom list [in]
3535
* @param latvec lattice parameter vector [in]
3636
* @param fn STRU file name [in]
37+
* @param header comment lines written at the top of the file [in]
3738
* @param nspin number of spin channels [in]
3839
* @param direct true for direct coords, false for cartesian coords [in]
3940
* @param vel true for printing velocities [in]
@@ -46,6 +47,7 @@ namespace unitcell
4647
const Atom* atoms,
4748
const ModuleBase::Matrix3& latvec,
4849
const std::string& fn,
50+
const std::string& header,
4951
const int& nspin = 1,
5052
const bool& direct = false,
5153
const bool& vel = false,

source/source_cell/test/unitcell_test.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ TEST_F(UcellTest, PrintSTRU)
803803
*
804804
*/
805805
unitcell::print_stru_file(*ucell,ucell->atoms,ucell->latvec,
806-
fn, 1, false, false, false, false, false, 0);
806+
fn, "", 1, false, false, false, false, false, 0);
807807
std::ifstream ifs;
808808
ifs.open("C1H2_STRU");
809809
std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
@@ -813,9 +813,9 @@ TEST_F(UcellTest, PrintSTRU)
813813
EXPECT_THAT(str, testing::HasSubstr("LATTICE_CONSTANT"));
814814
EXPECT_THAT(str, testing::HasSubstr("1.8897261255"));
815815
EXPECT_THAT(str, testing::HasSubstr("LATTICE_VECTORS"));
816-
EXPECT_THAT(str, testing::HasSubstr("10.0000000000 0.0000000000 0.0000000000"));
817-
EXPECT_THAT(str, testing::HasSubstr(" 0.0000000000 10.0000000000 0.0000000000"));
818-
EXPECT_THAT(str, testing::HasSubstr(" 0.0000000000 0.0000000000 10.0000000000"));
816+
EXPECT_THAT(str, testing::HasSubstr("10.0000000000000000 0.0000000000000000 0.0000000000000000"));
817+
EXPECT_THAT(str, testing::HasSubstr("0.0000000000000000 10.0000000000000000 0.0000000000000000"));
818+
EXPECT_THAT(str, testing::HasSubstr("0.0000000000000000 0.0000000000000000 10.0000000000000000"));
819819
EXPECT_THAT(str, testing::HasSubstr("ATOMIC_POSITIONS"));
820820
EXPECT_THAT(str, testing::HasSubstr("Cartesian"));
821821
EXPECT_THAT(str, testing::HasSubstr("C #label"));
@@ -835,7 +835,7 @@ TEST_F(UcellTest, PrintSTRU)
835835
*
836836
*/
837837
unitcell::print_stru_file(*ucell,ucell->atoms,ucell->latvec,
838-
fn, 2, true, true, false, false, false, 0);
838+
fn, "", 2, true, true, false, false, false, 0);
839839
ifs.open("C1H2_STRU");
840840
str = {(std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()};
841841
EXPECT_THAT(str, testing::HasSubstr("ATOMIC_SPECIES"));
@@ -844,9 +844,9 @@ TEST_F(UcellTest, PrintSTRU)
844844
EXPECT_THAT(str, testing::HasSubstr("LATTICE_CONSTANT"));
845845
EXPECT_THAT(str, testing::HasSubstr("1.8897261255"));
846846
EXPECT_THAT(str, testing::HasSubstr("LATTICE_VECTORS"));
847-
EXPECT_THAT(str, testing::HasSubstr("10.0000000000 0.0000000000 0.0000000000"));
848-
EXPECT_THAT(str, testing::HasSubstr(" 0.0000000000 10.0000000000 0.0000000000"));
849-
EXPECT_THAT(str, testing::HasSubstr(" 0.0000000000 0.0000000000 10.0000000000"));
847+
EXPECT_THAT(str, testing::HasSubstr("10.0000000000000000 0.0000000000000000 0.0000000000000000"));
848+
EXPECT_THAT(str, testing::HasSubstr("0.0000000000000000 10.0000000000000000 0.0000000000000000"));
849+
EXPECT_THAT(str, testing::HasSubstr("0.0000000000000000 0.0000000000000000 10.0000000000000000"));
850850
EXPECT_THAT(str, testing::HasSubstr("ATOMIC_POSITIONS"));
851851
EXPECT_THAT(str, testing::HasSubstr("Direct"));
852852
EXPECT_THAT(str, testing::HasSubstr("C #label"));
@@ -877,7 +877,7 @@ TEST_F(UcellTest, PrintSTRU)
877877
ucell->atom_mulliken
878878
= {{-1, 0.5}, {-1, 0.4}, {-1, 0.3}}; // first index is iat, the second is components, starts seems from 1
879879
unitcell::print_stru_file(*ucell,ucell->atoms,ucell->latvec,
880-
fn, 2, true, false, true, true, true, 0);
880+
fn, "", 2, true, false, true, true, true, 0);
881881
ifs.open("C1H2_STRU");
882882
str = {(std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>()};
883883
EXPECT_THAT(str, testing::HasSubstr("ATOMIC_SPECIES"));
@@ -891,9 +891,9 @@ TEST_F(UcellTest, PrintSTRU)
891891
EXPECT_THAT(str, testing::HasSubstr("LATTICE_CONSTANT"));
892892
EXPECT_THAT(str, testing::HasSubstr("1.8897261255"));
893893
EXPECT_THAT(str, testing::HasSubstr("LATTICE_VECTORS"));
894-
EXPECT_THAT(str, testing::HasSubstr("10.0000000000 0.0000000000 0.0000000000"));
895-
EXPECT_THAT(str, testing::HasSubstr(" 0.0000000000 10.0000000000 0.0000000000"));
896-
EXPECT_THAT(str, testing::HasSubstr(" 0.0000000000 0.0000000000 10.0000000000"));
894+
EXPECT_THAT(str, testing::HasSubstr("10.0000000000000000 0.0000000000000000 0.0000000000000000"));
895+
EXPECT_THAT(str, testing::HasSubstr("0.0000000000000000 10.0000000000000000 0.0000000000000000"));
896+
EXPECT_THAT(str, testing::HasSubstr("0.0000000000000000 0.0000000000000000 10.0000000000000000"));
897897
EXPECT_THAT(str, testing::HasSubstr("ATOMIC_POSITIONS"));
898898
EXPECT_THAT(str, testing::HasSubstr("Direct"));
899899
EXPECT_THAT(str, testing::HasSubstr("C #label"));

source/source_esolver/esolver_dp.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "esolver_dp.h"
2121
#include "source_base/parallel_common.h"
2222
#include "source_base/timer.h"
23-
#include "source_io/module_output/cif_io.h"
2423
#include "source_io/module_output/output_log.h"
2524
#include "source_io/module_parameter/parameter.h"
2625

@@ -39,11 +38,6 @@ void ESolver_DP::before_all_runners(BaseCell& basecell, const Input_para& inp)
3938
dp_force.create(ucell.nat, 3);
4039
dp_virial.create(3, 3);
4140

42-
ModuleIO::CifParser::write(PARAM.globalv.global_out_dir + "STRU.cif",
43-
ucell,
44-
"# Generated by ABACUS ModuleIO::CifParser",
45-
"data_?");
46-
4741
atype.resize(ucell.nat);
4842

4943
rescaling = inp.mdp.dp_rescaling;

source/source_esolver/esolver_fp.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#include "source_estate/param_update.h"
77
#include "source_hamilt/module_ewald/H_Ewald_pw.h"
88
#include "source_hamilt/module_vdw/vdw.h"
9-
#include "source_io/module_output/cif_io.h"
109
#include "source_io/module_output/output_log.h"
1110
#include "source_io/module_output/print_info.h"
1211
#include "source_io/module_chgpot/rhog_io.h"
@@ -73,14 +72,10 @@ void ESolver_FP::before_all_runners(BaseCell& basecell, const Input_para& inp)
7372
//! 3) setup structure factors
7473
this->sf.set(this->pw_rhod, inp.nbspline);
7574

76-
//! 4) write geometry file
77-
ModuleIO::CifParser::write(PARAM.globalv.global_out_dir + "STRU.cif",
78-
ucell, "# Generated by ABACUS ModuleIO::CifParser", "data_?");
79-
80-
//! 5) init charge extrapolation
75+
//! 4) init charge extrapolation
8176
this->CE.Init_CE(inp.nspin, ucell.nat, this->pw_rhod->nrxx, inp.chg_extrap);
8277

83-
//! 6) symmetry analysis should be performed every time the cell is changed
78+
//! 5) symmetry analysis should be performed every time the cell is changed
8479
if (ModuleSymmetry::Symmetry::symm_flag == 1)
8580
{
8681
const int cal_symm_repr[2] = {PARAM.inp.cal_symm_repr[0], PARAM.inp.cal_symm_repr[1]};

0 commit comments

Comments
 (0)