Skip to content

Commit ee5f852

Browse files
authored
Symmetry: debug and new features (#1904)
* add a new atom_ordering algorithm in module symmetry * fix wrong transpose * add mat_rotate to ibrav=4,12,13 according to euler angles * fix a gtrans=0 bug * add space group analysis * change euler angles according to their defination * delete the duplicated call of point-group functions * rotate the matrix back in k-space * revert the transpose in force_symmetry * remove unused gmatrix_fft * revert to transpose with a special transpose for 60-hexagonal in mat_rotate * fix a typo * revert the double-call with more detailed output * reverte back-rotation * output bravais and point group analysis for input configuration * simplify some variables * add gmat_con and gtrans_con to bring optimized-symm into input config * fix unset-newpos bug * fix inverted-sign bug of gtrans * implement rhog_symm and invmap * add some unittests for trans-funcs in module_symmetry * **implement rhog_symmetry both parallel and serial** * fix some bugs * modify the parallel of rhog_symmetry * add round option in gmatrix_convert * divide the phase factor back to fix space-group bug * modify UT; divide gmatrix_convet_int from gmatrix_convert * checksym: add gtrans firstly and then check_boundary * add an imcomplete pricell * complete pricell * fix pricell bugs * modify algorithm in pricell but still have bug * fix a gtrans-missing bug in checksym * modify pcell-lattice-vector-searching algorithm * fix a bug: change 0-init into -1-init * use pricell onto rhog_symmetry * add get_shortest_latvec * extract get_optlat as a subfunction from lattice_type * add plat_type * call the get_shortest_latvec and plat_type * modify plat-algorithm and deal with collineation * pricell: exclude collinear and coplane when searching b1b2b3 * pcell in rhosym: fix a nan-bug resulting from zero mean-gphase * fix a compile error * pricell: fix the condition searching jplane and iplane * pricel in rhosym: add the missing ncell-division back * comment out some couts * pricell: fix collinear-condition * rhosym: modify rotation * add a space to output for convenient grep * setgroup: change r2yp into r2zp in ibrav=12, fitting to mat_rotate * setgroup: modify cel_const and use mat_rotate in ibrav=11 * improve cel_const for ibrav=12, 13 * standard_lat: strengthen conditions to ibrav-setting and remove mat_rotate * remove redundant output and fix zero-celconst for triclinc * convert ptrans to input configuration * use a new rotate_recip without scaling gmatrix by the number of FFT-grids * retain s1, s2, s3 as input lat-vec * delete a exclamation mark * restrict kvec_d into [0, 1) * rhogsym: deal with error in gphase * fix unittest * fix a type error * remove cel_const dependence from setgroup * ibzkpt: use kgmatrix and row-vector-rotate (vec*mat) * move the output out of lattice_type function * symmetry: change some function into const and remove some useless code * fix the dependence of the test * fix fco-wrong-kgmatrix by changing the condition to modify optlat * ibzkpt: add group-analysis in reciprocal and k-lattice, check and restrict kpoints * pricell: add hermite_normal_form and remove plat_type * fix the include in symmetry_rhog * modify result.ref of some scf cases * fix result.ref * fix ibz_kpoint in unit tests * set OMP_NUM_THREADS=1 in test workflow * set scf_nmax=8 in case 121_PW_KPAR * fix a MPI_Send bug sending to other pools (local to local, rather than global) * rewrite and fix KPAR-bug * do rhog_symmetry respectively in each pool * Revert "set OMP_NUM_THREADS=1 in test workflow" This reverts commit c4719b6. * Revert "set scf_nmax=8 in case 121_PW_KPAR" This reverts commit a1305d2. * fix Makefile * clear ptrans befor every ion step * modify result.ref * add unittest to atom_ordering_new * use EXPECT_LE * delete some useless comments * add introduction to unit test
1 parent 5fe7471 commit ee5f852

File tree

46 files changed

+1768
-580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1768
-580
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ OBJS_SRCPW=H_Ewald_pw.o\
479479
stress_pw.o\
480480
of_stress_pw.o\
481481
symmetry_rho.o\
482+
symmetry_rhog.o\
482483
wavefunc.o\
483484
wf_atomic.o\
484485
wf_igk.o\

source/module_cell/klist.cpp

Lines changed: 104 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void K_Vectors::set(
8989
//if symm_flag is not set, only time-reversal symmetry would be considered.
9090
if(!berryphase::berry_phase_flag && ModuleSymmetry::Symmetry::symm_flag != -1)
9191
{
92-
this->ibz_kpoint(symm, ModuleSymmetry::Symmetry::symm_flag,skpt1);
92+
this->ibz_kpoint(symm, ModuleSymmetry::Symmetry::symm_flag, skpt1, GlobalC::ucell);
9393
if(ModuleSymmetry::Symmetry::symm_flag || is_mp)
9494
{
9595
this->update_use_ibz();
@@ -544,10 +544,21 @@ void K_Vectors::update_use_ibz( void )
544544
return;
545545
}
546546

547-
void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry &symm, bool use_symm,std::string& skpt)
547+
void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry &symm, bool use_symm,std::string& skpt, const UnitCell &ucell)
548548
{
549549
if (GlobalV::MY_RANK!=0) return;
550550
ModuleBase::TITLE("K_Vectors", "ibz_kpoint");
551+
552+
// k-lattice: "pricell" of reciprocal space
553+
// CAUTION: should fit into all k-input method, not only MP !!!
554+
ModuleBase::Vector3<double> gb1(ucell.G.e11, ucell.G.e12, ucell.G.e13);
555+
ModuleBase::Vector3<double> gb2(ucell.G.e21, ucell.G.e22, ucell.G.e23);
556+
ModuleBase::Vector3<double> gb3(ucell.G.e31, ucell.G.e32, ucell.G.e33);
557+
ModuleBase::Vector3<double> gk1(gb1.x / nmp[0], gb1.y / nmp[0], gb1.z / nmp[0]);
558+
ModuleBase::Vector3<double> gk2(gb2.x / nmp[1], gb2.y / nmp[1], gb2.z / nmp[1]);
559+
ModuleBase::Vector3<double> gk3(gb3.x / nmp[2], gb3.y / nmp[2], gb3.z / nmp[2]);
560+
ModuleBase::Matrix3 gk(gk1.x, gk1.y, gk1.z, gk2.x, gk2.y, gk2.z, gk3.x, gk3.y, gk3.z);
561+
551562
//===============================================
552563
// search in all space group operations
553564
// if the operations does not already included
@@ -561,21 +572,71 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry &symm, bool use_symm,s
561572
int nrotkm;
562573
if(use_symm)
563574
{
575+
// bravais type of reciprocal lattice and k-lattice
576+
double b_const[6];
577+
double b0_const[6];
578+
double bk_const[6];
579+
double bk0_const[6];
580+
int bbrav=15;
581+
int bkbrav=15;
582+
std::string bbrav_name;
583+
std::string bkbrav_name;
584+
ModuleBase::Vector3<double> gb01=gb1, gb02=gb2, gb03=gb3, gk01=gk1, gk02=gk2, gk03=gk3;
585+
symm.lattice_type(gb1, gb2, gb3, gb01, gb02, gb03, b_const, b0_const, bbrav, bbrav_name, ucell, false, nullptr);
586+
GlobalV::ofs_running<<"(for reciprocal lattice: )"<<std::endl;
587+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"BRAVAIS TYPE", bbrav);
588+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"BRAVAIS LATTICE NAME", bbrav_name);
589+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"ibrav", bbrav);
590+
591+
symm.lattice_type(gk1, gk2, gk3, gk01, gk02, gk03, bk_const, bk0_const, bkbrav, bkbrav_name, ucell, false, nullptr);
592+
GlobalV::ofs_running<<"(for k-lattice: )"<<std::endl;
593+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"BRAVAIS TYPE", bkbrav);
594+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"BRAVAIS LATTICE NAME", bkbrav_name);
595+
ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"ibrav", bkbrav);
596+
597+
// point-group analysis of reciprocal lattice
598+
ModuleBase::Matrix3 bsymop[48];
599+
int bnop=0;
600+
symm.setgroup(bsymop, bnop, bbrav);
601+
ModuleBase::Matrix3 b_optlat(gb1.x, gb1.y, gb1.z, gb2.x, gb2.y, gb2.z, gb3.x, gb3.y, gb3.z);
602+
//symm.gmatrix_convert_int(bsymop, bsymop, bnop, b_optlat, ucell.G);
603+
symm.gmatrix_convert(bsymop, bsymop, bnop, b_optlat, ucell.G);
604+
//check if all the kgmatrix are in bsymop
605+
auto matequal = [&symm] (ModuleBase::Matrix3 a, ModuleBase::Matrix3 b)
606+
{
607+
return (symm.equal(a.e11, b.e11) && symm.equal(a.e12, b.e12) && symm.equal(a.e13, b.e13) &&
608+
symm.equal(a.e21, b.e21) && symm.equal(a.e22, b.e22) && symm.equal(a.e23, b.e23) &&
609+
symm.equal(a.e31, b.e31) && symm.equal(a.e23, b.e23) && symm.equal(a.e33, b.e33));
610+
};
611+
for(int i=0;i<symm.nrotk;++i)
612+
{
613+
bool match = false;
614+
for(int j=0;j<bnop;++j)
615+
{
616+
if (matequal(symm.kgmatrix[i], bsymop[j])) {match=true; break;}
617+
}
618+
if(!match)
619+
{
620+
std::cout<<"match failed:"<<std::endl;
621+
ModuleBase::WARNING_QUIT("K_Vectors:ibz_kpoint",
622+
"symmetry operation of reciprocal lattice is wrong! ");
623+
}
624+
}
564625
nrotkm = symm.nrotk;// change if inv not included
565626
for (int i = 0; i < nrotkm; ++i)
566627
{
567-
if (symm.gmatrix[i] == inv)
628+
if (symm.kgmatrix[i] == inv)
568629
{
569630
include_inv = true;
570631
}
571-
kgmatrix[i] = symm.gmatrix[i];
632+
kgmatrix[i] = symm.kgmatrix[i];
572633
}
573634

574635
if (!include_inv)
575636
{
576637
for (int i = 0; i<symm.nrotk; ++i)
577638
{
578-
kgmatrix[i + symm.nrotk] = inv * symm.gmatrix[i];
639+
kgmatrix[i + symm.nrotk] = inv * symm.kgmatrix[i];
579640
}
580641
nrotkm = 2 * symm.nrotk;
581642
}
@@ -591,6 +652,13 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry &symm, bool use_symm,s
591652
return;
592653
}
593654

655+
// convert kgmatrix to k-lattice
656+
ModuleBase::Matrix3* kkmatrix = new ModuleBase::Matrix3 [nrotkm];
657+
symm.gmatrix_convert(kgmatrix.data(), kkmatrix, nrotkm, ucell.G, gk);
658+
// direct coordinates of k-points in k-lattice
659+
std::vector<ModuleBase::Vector3<double>> kvec_d_k(nkstot);
660+
for (int i=0;i<nkstot;++i) kvec_d_k[i]=kvec_d[i]*ucell.G*gk.Inverse();
661+
594662
// use operation : kgmatrix to find
595663
// the new set kvec_d : ir_kpt
596664
this->nkstot_ibz = 0;
@@ -604,18 +672,35 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry &symm, bool use_symm,s
604672
const double weight = 1.0 / static_cast<double>(nkstot);
605673

606674
ModuleBase::Vector3<double> kvec_rot;
675+
ModuleBase::Vector3<double> kvec_rot_k;
607676

608677

609678
// for(int i=0; i<nrotkm; i++)
610679
// {
611680
// out.printM3("rot matrix",kgmatrix[i]);
612681
// }
613-
682+
auto restrict_kpt = [&symm](ModuleBase::Vector3<double> &kvec){
683+
// in (-0.5, 0.5]
684+
kvec.x = fmod(kvec.x + 100.5-0.5*symm.epsilon, 1)-0.5+0.5*symm.epsilon;
685+
kvec.y = fmod(kvec.y + 100.5-0.5*symm.epsilon, 1)-0.5+0.5*symm.epsilon;
686+
kvec.z = fmod(kvec.z + 100.5-0.5*symm.epsilon, 1)-0.5+0.5*symm.epsilon;
687+
// in [0, 1)
688+
// kvec.x = fmod(kvec.x + 100 + symm.epsilon, 1) - symm.epsilon;
689+
// kvec.y = fmod(kvec.y + 100 + symm.epsilon, 1) - symm.epsilon;
690+
// kvec.z = fmod(kvec.z + 100 + symm.epsilon, 1) - symm.epsilon;
691+
if(abs(kvec.x) < symm.epsilon) kvec.x = 0.0;
692+
if(abs(kvec.y) < symm.epsilon) kvec.y = 0.0;
693+
if(abs(kvec.z) < symm.epsilon) kvec.z = 0.0;
694+
return;
695+
};
614696
// for output in kpoints file
615697
int ibz_index[nkstot];
616698
// search in all k-poins.
617699
for (int i = 0; i < nkstot; ++i)
618700
{
701+
//restrict to [0, 1)
702+
restrict_kpt(kvec_d[i]);
703+
619704
//std::cout << "\n kpoint = " << i << std::endl;
620705
//std::cout << "\n kvec_d = " << kvec_d[i].x << " " << kvec_d[i].y << " " << kvec_d[i].z;
621706
bool already_exist = false;
@@ -631,13 +716,20 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry &symm, bool use_symm,s
631716
// mohan modify 2010-01-30.
632717
// mohan modify again 2010-01-31
633718
// fix the bug like kvec_d * G; is wrong
634-
//kvec_rot = kvec_d[i] * kgmatrix[j]; //wrong for total energy, but correct for nonlocal force.
635-
kvec_rot = kgmatrix[j] * kvec_d[i]; //correct for total energy, but wrong for nonlocal force.
719+
kvec_rot = kvec_d[i] * kgmatrix[j]; //wrong for total energy, but correct for nonlocal force.
720+
//kvec_rot = kgmatrix[j] * kvec_d[i]; //correct for total energy, but wrong for nonlocal force.
721+
restrict_kpt(kvec_rot);
636722

637-
kvec_rot.x = fmod(kvec_rot.x + 100, 1);
638-
kvec_rot.y = fmod(kvec_rot.y + 100, 1);
639-
kvec_rot.z = fmod(kvec_rot.z + 100, 1);
723+
kvec_rot_k = kvec_d_k[i] * kkmatrix[j]; //k-lattice rotation
724+
kvec_rot_k = kvec_rot_k * gk * ucell.G.Inverse(); //convert to recip lattice
725+
restrict_kpt(kvec_rot_k);
640726

727+
assert(symm.equal(kvec_rot.x, kvec_rot_k.x));
728+
assert(symm.equal(kvec_rot.y, kvec_rot_k.y));
729+
assert(symm.equal(kvec_rot.z, kvec_rot_k.z));
730+
// std::cout << "\n kvec_rot (in recip) = " << kvec_rot.x << " " << kvec_rot.y << " " << kvec_rot.z;
731+
// std::cout << "\n kvec_rot(k to recip)= " << kvec_rot_k.x << " " << kvec_rot_k.y << " " << kvec_rot_k.z;
732+
kvec_rot_k = kvec_rot_k * ucell.G * gk.Inverse(); //convert back to k-latice
641733

642734
// std::cout << "\n kvec_rot = " << kvec_rot.x << " " << kvec_rot.y << " " << kvec_rot.z;
643735

@@ -708,6 +800,7 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry &symm, bool use_symm,s
708800
// BLOCK_HERE("check k point");
709801
}
710802

803+
delete[] kkmatrix;
711804
// output in kpoints file
712805
std::stringstream ss;
713806
ss << " " << std::setw(40) <<"nkstot" << " = " << nkstot

source/module_cell/klist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class K_Vectors
3838
const ModuleBase::Matrix3 &reciprocal_vec,
3939
const ModuleBase::Matrix3 &latvec);
4040

41-
void ibz_kpoint( const ModuleSymmetry::Symmetry &symm, bool use_symm,std::string& skpt);
41+
void ibz_kpoint(const ModuleSymmetry::Symmetry &symm, bool use_symm,std::string& skpt, const UnitCell &ucell);
4242
//LiuXh add 20180515
4343
void set_after_vc(
4444
const ModuleSymmetry::Symmetry &symm,

source/module_cell/module_symmetry/symm_other.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void Symm_Other::print1(const int &ibrav, const double *cel_const, std::ofstream
8888
ModuleBase::GlobalFunc::OUT(ofs_running,"LATTICE CONSTANT A",cel_const[0]);
8989
ModuleBase::GlobalFunc::OUT(ofs_running,"B/A RATIO",cel_const[1]);
9090
ModuleBase::GlobalFunc::OUT(ofs_running,"C/A RATIO",cel_const[2]);
91-
ModuleBase::GlobalFunc::OUT(ofs_running,"COS(BETA)",cel_const[4]);
91+
ModuleBase::GlobalFunc::OUT(ofs_running,"COS(BETA)",cel_const[4]);
9292
}
9393
else if(ibrav==14)
9494
{

0 commit comments

Comments
 (0)