@@ -150,12 +150,21 @@ ModuleIO::AngularMomentumCalculator::AngularMomentumCalculator(
150150
151151 // for neighbor list search
152152 double temp = -1.0 ;
153+ if (search_radius < rcut_max)
154+ {
155+ *ofs_ << " Find the `search_radius` from the input file being smaller than the \n "
156+ " `rcut_max` of the orbitals.\n "
157+ << " Reset the `search_radius` (" << search_radius << " ) "
158+ << " to `rcut_max` (" << rcut_max << " )."
159+ << std::endl;
160+ // we don't really set, but use std::max to mask :)
161+ }
153162 temp = atom_arrange::set_sr_NL (*ofs_,
154163 PARAM.inp .out_level ,
155- search_radius,
164+ std::max ( search_radius, rcut_max) ,
156165 ucell.infoNL .get_rcutmax_Beta (),
157166 PARAM.globalv .gamma_only_local );
158- temp = std::max (temp, search_radius);
167+ temp = std::max (temp, std::max ( search_radius, rcut_max) );
159168 this ->neighbor_searcher_ = std::unique_ptr<Grid_Driver>(new Grid_Driver (tdestructor, tgrid));
160169 atom_arrange::search (searchpbc,
161170 *ofs_,
@@ -190,24 +199,29 @@ void ModuleIO::AngularMomentumCalculator::kernel(
190199 fmtstr += " %" + std::to_string (precision*2 ) + " ." + std::to_string (precision) + " e\n " ;
191200 FmtCore fmt (fmtstr);
192201
193- ModuleBase::Vector3<double > ri, rj, dr;
202+ // placeholders
203+ std::complex <double > val = 0 ;
204+ ModuleBase::Vector3<double > taui; // the origin position
205+ ModuleBase::Vector3<double > dtau; // the displacement
206+ AdjacentAtomInfo adjinfo; // adjacent atom information carrier
194207 for (int it = 0 ; it < ucell.ntype ; it++)
195208 {
196209 const Atom& atyp_i = ucell.atoms [it];
197210 for (int ia = 0 ; ia < atyp_i.na ; ia++)
198211 {
199- ri = atyp_i. tau [ia] ;
200- neighbor_searcher_->Find_atom (ucell, ri , it, ia);
201- for (int ia_adj = 0 ; ia_adj < neighbor_searcher_-> getAdjacentNum () ; ia_adj++)
212+ taui = ucell. get_tau (ucell. itia2iat (it, ia)) ;
213+ neighbor_searcher_->Find_atom (ucell, taui , it, ia, &adjinfo );
214+ for (int ia_adj = 0 ; ia_adj < adjinfo. adj_num + 1 ; ia_adj++) // "+1" is to include itself
202215 {
203- rj = neighbor_searcher_-> getAdjacentTau ( ia_adj);
204- int jt = neighbor_searcher_-> getType ( ia_adj);
216+ int jt = adjinfo. ntype [ ia_adj]; // ityp
217+ int ja = adjinfo. natom [ ia_adj]; // iat with in atomtype
205218 const Atom& atyp_j = ucell.atoms [jt];
206- int ja = neighbor_searcher_-> getNatom ( ia_adj) ;
207- dr = (ri - rj) * ucell. lat0 ;
208- const ModuleBase::Vector3< int > iR = neighbor_searcher_-> getBox (ia_adj);
209- // the two-center-integral
219+ const ModuleBase::Vector3< int > iR = adjinfo. box [ ia_adj] ;
220+ dtau = ucell. cal_dtau (ucell. itia2iat (it, ia),
221+ ucell. itia2iat (jt, ja),
222+ iR) * ucell. lat0 ; // convert to unit of Bohr
210223
224+ // nested loop: calculate the two-center-integral
211225 for (int li = 0 ; li < atyp_i.nwl + 1 ; li++)
212226 {
213227 for (int iz = 0 ; iz < atyp_i.l_nchi [li]; iz++)
@@ -220,21 +234,20 @@ void ModuleIO::AngularMomentumCalculator::kernel(
220234 {
221235 for (int mj = -lj; mj <= lj; mj++)
222236 {
223- std::complex <double > val = 0 ;
224237 if (dir == ' x' )
225238 {
226239 val = cal_LxijR (calculator_,
227- it, ia, li, iz, mi, jt, ja, lj, jz, mj, dr );
240+ it, ia, li, iz, mi, jt, ja, lj, jz, mj, dtau );
228241 }
229242 else if (dir == ' y' )
230243 {
231244 val = cal_LyijR (calculator_,
232- it, ia, li, iz, mi, jt, ja, lj, jz, mj, dr );
245+ it, ia, li, iz, mi, jt, ja, lj, jz, mj, dtau );
233246 }
234247 else if (dir == ' z' )
235248 {
236249 val = cal_LzijR (calculator_,
237- it, ia, li, iz, mi, jt, ja, lj, jz, mj, dr );
250+ it, ia, li, iz, mi, jt, ja, lj, jz, mj, dtau );
238251 }
239252
240253 *ofs << fmt.format (
@@ -266,7 +279,7 @@ void ModuleIO::AngularMomentumCalculator::calculate(
266279 }
267280 std::ofstream ofout;
268281 const std::string dir = " xyz" ;
269- const std::string title = " # it ia il iz im iRx iRy iRz jt ja jl jz jm <a|L|b>\n "
282+ const std::string title = " # it ia il iz im iRx iRy iRz jt ja jl jz jm Re[ <a|L|b>] Im[<a|L|b>] \n "
270283 " # it: atomtype index of the first atom\n "
271284 " # ia: atomic index of the first atom within the atomtype\n "
272285 " # il: angular momentum index of the first atom\n "
@@ -278,7 +291,8 @@ void ModuleIO::AngularMomentumCalculator::calculate(
278291 " # jl: angular momentum index of the second atom\n "
279292 " # jz: zeta function index of the second atom\n "
280293 " # jm: magnetic quantum number of the second atom\n "
281- " # <a|L|b>: the value of the matrix element\n " ;
294+ " # Re[<a|L|b>], Im[<a|L|b>]: the real and imaginary parts "
295+ " of the value of the matrix element\n " ;
282296
283297 for (char d : dir)
284298 {
0 commit comments