@@ -337,9 +337,11 @@ void projectors::OnsiteProjector<T, Device>::tabulate_atomic(const int ik, const
337337}
338338
339339template <typename T, typename Device>
340- void projectors::OnsiteProjector<T, Device>::overlap_proj_psi(
340+ void projectors::OnsiteProjector<T, Device>::overlap_proj_psi(
341341 const int npm,
342- const std::complex <double >* ppsi)
342+ const std::complex <double >* ppsi,
343+ int npwx
344+ )
343345{
344346 ModuleBase::timer::tick (" OnsiteProj" , " overlap" );
345347 // STAGE 3 - cal_becp
@@ -384,6 +386,7 @@ void projectors::OnsiteProjector<T, Device>::overlap_proj_psi(
384386 // std::cout << "at " << __FILE__ << ": " << __LINE__ << " output npm: " << npm << std::endl;
385387 // std::cout << "at " << __FILE__ << ": " << __LINE__ << " ik_: " << ik_ << std::endl;
386388 int npol = this ->ucell ->get_npol ();
389+ if (npwx == 0 ) npwx = this ->npwx_ ;
387390 if (this ->becp == nullptr || this ->size_becp < npm*this ->tot_nproj )
388391 {
389392 this ->size_becp = npm*this ->tot_nproj ;
@@ -397,7 +400,7 @@ void projectors::OnsiteProjector<T, Device>::overlap_proj_psi(
397400 this ->h_becp = this ->becp ;
398401 }
399402 }
400- this ->fs_tools ->cal_becp (ik_, npm/npol, this ->becp , ppsi); // in cal_becp, npm should be the one not multiplied by npol
403+ this ->fs_tools ->cal_becp (ik_, npm/npol, this ->becp , ppsi, npwx ); // in cal_becp, npm should be the one not multiplied by npol
401404 if (this ->device == base_device::GpuDevice)
402405 {
403406 syncmem_complex_d2h_op ()(h_becp, this ->becp , this ->size_becp );
@@ -522,8 +525,9 @@ void projectors::OnsiteProjector<T, Device>::read_abacus_orb(std::ifstream& ifs,
522525
523526template <typename T, typename Device>
524527void projectors::OnsiteProjector<T, Device>::cal_occupations(
525- const psi::Psi<std::complex <T>, Device>* psi_in,
526- const ModuleBase::matrix& wg_in)
528+ const psi::Psi<std::complex <T>, Device>* psi_in,
529+ const ModuleBase::matrix& wg_in,
530+ const int * isk_in)
527531{
528532 ModuleBase::timer::tick (" OnsiteProj" , " cal_occupation" );
529533 this ->tabulate_atomic (0 );
@@ -534,6 +538,7 @@ void projectors::OnsiteProjector<T, Device>::cal_occupations(
534538 for (int ik = 0 ; ik < psi_in->get_nk (); ik++)
535539 {
536540 psi_in->fix_k (ik);
541+ const int sign = isk_in[ik] == 0 ? 1 : -1 ;
537542 if (ik != 0 )
538543 {
539544 this ->tabulate_atomic (ik);
@@ -556,6 +561,7 @@ void projectors::OnsiteProjector<T, Device>::cal_occupations(
556561 for (int iat = 0 ; iat < this ->iat_nh .size (); iat++)
557562 {
558563 const int nh = this ->get_nh (iat);
564+ if (this ->ucell ->get_npol () == 2 )
559565 for (int ih = 0 ; ih < nh; ih++)
560566 {
561567 const int occ_index = (begin_ih + ih) * 4 ;
@@ -565,6 +571,16 @@ void projectors::OnsiteProjector<T, Device>::cal_occupations(
565571 occs[occ_index + 2 ] += weight * conj (becp_p[index + nkb]) * becp_p[index];
566572 occs[occ_index + 3 ] += weight * conj (becp_p[index + nkb]) * becp_p[index + nkb];
567573 }
574+ else if (this ->ucell ->get_npol () == 1 )
575+ {
576+ for (int ih = 0 ; ih < nh; ih++)
577+ {
578+ const int occ_index = (begin_ih + ih) * 4 ;
579+ const int index = ib*nkb + begin_ih + ih;
580+ occs[occ_index] += weight * conj (becp_p[index]) * becp_p[index];
581+ occs[occ_index + 3 ] += sign * weight * conj (becp_p[index]) * becp_p[index];
582+ }
583+ }
568584 begin_ih += nh;
569585 }
570586 }
@@ -608,10 +624,18 @@ void projectors::OnsiteProjector<T, Device>::cal_occupations(
608624 std::vector<double > charge_mag (4 , 0.0 );
609625 for (int ih=0 ;ih<this ->iat_nh [iat];ih++)
610626 {
611- charge_mag[3 ] += (occs[occ_index] - occs[occ_index + 3 ]).real ();
612- charge_mag[1 ] += (occs[occ_index + 1 ] + occs[occ_index + 2 ]).real ();
613- charge_mag[2 ] += (occs[occ_index + 1 ] - occs[occ_index + 2 ]).imag ();
614- charge_mag[0 ] += (occs[occ_index] + occs[occ_index + 3 ]).real ();
627+ if (this ->ucell ->get_npol () == 2 )
628+ {
629+ charge_mag[3 ] += (occs[occ_index] - occs[occ_index + 3 ]).real ();
630+ charge_mag[1 ] += (occs[occ_index + 1 ] + occs[occ_index + 2 ]).real ();
631+ charge_mag[2 ] += (occs[occ_index + 1 ] - occs[occ_index + 2 ]).imag ();
632+ charge_mag[0 ] += (occs[occ_index] + occs[occ_index + 3 ]).real ();
633+ }
634+ else if (this ->ucell ->get_npol () == 1 )
635+ {
636+ charge_mag[0 ] += occs[occ_index].real ();
637+ charge_mag[3 ] += occs[occ_index + 3 ].real ();
638+ }
615639 if (ih == current_l * current_l - 1 )
616640 {
617641 sum[0 ] += charge_mag[0 ];
0 commit comments