@@ -54,90 +54,86 @@ void Relax_Driver::relax_driver(ModuleESolver::ESolver* p_esolver, UnitCell& uce
5454 time_t fstart = time (nullptr );
5555 ModuleBase::matrix force;
5656 ModuleBase::matrix stress;
57- if (PARAM.inp .calculation == " scf" || PARAM.inp .calculation == " relax" || PARAM.inp .calculation == " cell-relax" )
58- {
59- // I'm considering putting force and stress
60- // as part of ucell and use ucell to pass information
61- // back and forth between esolver and relaxation
62- // but I'll use force and stress explicitly here for now
6357
64- // calculate the total energy
65- this ->etot = p_esolver->cal_energy ();
58+ // I'm considering putting force and stress
59+ // as part of ucell and use ucell to pass information
60+ // back and forth between esolver and relaxation
61+ // but I'll use force and stress explicitly here for now
62+
63+ // calculate the total energy
64+ this ->etot = p_esolver->cal_energy ();
65+
66+ // calculate and gather all parts of total ionic forces
67+ if (PARAM.inp .cal_force )
68+ {
69+ p_esolver->cal_force (ucell, force);
70+ }
71+ // calculate and gather all parts of stress
72+ if (PARAM.inp .cal_stress )
73+ {
74+ p_esolver->cal_stress (ucell, stress);
75+ }
6676
67- // calculate and gather all parts of total ionic forces
68- if (PARAM.inp .cal_force )
77+ if (PARAM.inp .calculation == " relax" || PARAM.inp .calculation == " cell-relax" )
78+ {
79+ if (PARAM.inp .relax_new )
6980 {
70- p_esolver-> cal_force (ucell, force);
81+ stop = rl. relax_step (ucell, force, stress, this -> etot );
7182 }
72- // calculate and gather all parts of stress
73- if (PARAM.inp .cal_stress )
83+ else
7484 {
75- p_esolver->cal_stress (ucell, stress);
85+ stop = rl_old.relax_step (istep,
86+ this ->etot ,
87+ ucell,
88+ force,
89+ stress,
90+ force_step,
91+ stress_step); // pengfei Li 2018-05-14
7692 }
77-
78- if (PARAM.inp .calculation == " relax" || PARAM.inp .calculation == " cell-relax" )
93+ // print structure
94+ // changelog 20240509
95+ // because I move out the dependence on GlobalV from UnitCell::print_stru_file
96+ // so its parameter is calculated here
97+ bool need_orb = PARAM.inp .basis_type == " pw" ;
98+ need_orb = need_orb && PARAM.inp .psi_initializer ;
99+ need_orb = need_orb && PARAM.inp .init_wfc .substr (0 , 3 ) == " nao" ;
100+ need_orb = need_orb || PARAM.inp .basis_type == " lcao" ;
101+ need_orb = need_orb || PARAM.inp .basis_type == " lcao_in_pw" ;
102+ std::stringstream ss, ss1;
103+ ss << PARAM.globalv .global_out_dir << " STRU_ION_D" ;
104+ ucell.print_stru_file (ss.str (),
105+ PARAM.inp .nspin ,
106+ true ,
107+ PARAM.inp .calculation == " md" ,
108+ PARAM.inp .out_mul ,
109+ need_orb,
110+ PARAM.globalv .deepks_setorb ,
111+ GlobalV::MY_RANK);
112+
113+ if (Ions_Move_Basic::out_stru)
79114 {
80- if (PARAM.inp .relax_new )
81- {
82- stop = rl.relax_step (ucell,force, stress, this ->etot );
83- }
84- else
85- {
86- stop = rl_old.relax_step (istep,
87- this ->etot ,
88- ucell,
89- force,
90- stress,
91- force_step,
92- stress_step); // pengfei Li 2018-05-14
93- }
94- // print structure
95- // changelog 20240509
96- // because I move out the dependence on GlobalV from UnitCell::print_stru_file
97- // so its parameter is calculated here
98- bool need_orb = PARAM.inp .basis_type == " pw" ;
99- need_orb = need_orb && PARAM.inp .psi_initializer ;
100- need_orb = need_orb && PARAM.inp .init_wfc .substr (0 , 3 ) == " nao" ;
101- need_orb = need_orb || PARAM.inp .basis_type == " lcao" ;
102- need_orb = need_orb || PARAM.inp .basis_type == " lcao_in_pw" ;
103- std::stringstream ss, ss1;
104- ss << PARAM.globalv .global_out_dir << " STRU_ION_D" ;
105- ucell.print_stru_file (ss.str (),
115+ ss1 << PARAM.globalv .global_out_dir << " STRU_ION" ;
116+ ss1 << istep << " _D" ;
117+ ucell.print_stru_file (ss1.str (),
106118 PARAM.inp .nspin ,
107119 true ,
108120 PARAM.inp .calculation == " md" ,
109121 PARAM.inp .out_mul ,
110122 need_orb,
111123 PARAM.globalv .deepks_setorb ,
112124 GlobalV::MY_RANK);
113-
114- if (Ions_Move_Basic::out_stru)
115- {
116- ss1 << PARAM.globalv .global_out_dir << " STRU_ION" ;
117- ss1 << istep << " _D" ;
118- ucell.print_stru_file (ss1.str (),
119- PARAM.inp .nspin ,
120- true ,
121- PARAM.inp .calculation == " md" ,
122- PARAM.inp .out_mul ,
123- need_orb,
124- PARAM.globalv .deepks_setorb ,
125- GlobalV::MY_RANK);
126- ModuleIO::CifParser::write (PARAM.globalv .global_out_dir + " STRU_NOW.cif" ,
127- ucell,
128- " # Generated by ABACUS ModuleIO::CifParser" ,
129- " data_?" );
130- }
131-
132- ModuleIO::output_after_relax (stop, p_esolver->conv_esolver , GlobalV::ofs_running);
125+ ModuleIO::CifParser::write (PARAM.globalv .global_out_dir + " STRU_NOW.cif" ,
126+ ucell,
127+ " # Generated by ABACUS ModuleIO::CifParser" ,
128+ " data_?" );
133129 }
134130
135- #ifdef __RAPIDJSON
136- // add the energy to outout
137- Json::add_output_energy (p_esolver->cal_energy () * ModuleBase::Ry_to_eV);
138- #endif
131+ ModuleIO::output_after_relax (stop, p_esolver->conv_esolver , GlobalV::ofs_running);
139132 }
133+
140134#ifdef __RAPIDJSON
135+ // add the energy to outout
136+ Json::add_output_energy (p_esolver->cal_energy () * ModuleBase::Ry_to_eV);
141137 // add Json of cell coo stress force
142138 double unit_transform = ModuleBase::RYDBERG_SI / pow (ModuleBase::BOHR_RADIUS_SI, 3 ) * 1.0e-8 ;
143139 double fac = ModuleBase::Ry_to_eV / 0.529177 ;
0 commit comments