11#include " sltk_atom_arrange.h"
2- #include " sltk_atom_input.h"
2+
3+ #include " module_base/timer.h"
34#include " module_parameter/parameter.h"
45#include " sltk_grid.h"
56#include " sltk_grid_driver.h"
6- #include " module_base/timer.h"
77
8- // update the followig class in near future
8+ // update the followig class in near future
99#include " module_cell/unitcell.h"
1010
1111atom_arrange::atom_arrange ()
@@ -16,126 +16,92 @@ atom_arrange::~atom_arrange()
1616{
1717}
1818
19- double atom_arrange::set_sr_NL (
20- std::ofstream &ofs_in,
21- const std::string &output_level,
22- const double &rcutmax_Phi,
23- const double &rcutmax_Beta,
24- const bool gamma_only_local)
19+ double atom_arrange::set_sr_NL (std::ofstream& ofs_in,
20+ const std::string& output_level,
21+ const double & rcutmax_Phi,
22+ const double & rcutmax_Beta,
23+ const bool gamma_only_local)
2524{
26- ModuleBase::TITLE (" atom_arrange" ," set_sr_NL" );
27-
28- if (output_level != " m" ) // xiaohui add 'output_level', 2015-09-16
29- {
30- ofs_in << " \n\n\n\n " ;
31- ofs_in << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
32- ofs_in << " | |" << std::endl;
33- ofs_in << " | Search adjacent atoms: |" << std::endl;
34- ofs_in << " | Set the adjacent atoms for each atom and set the periodic boundary |" << std::endl;
35- ofs_in << " | condition for the atoms on real space FFT grid. For k-dependent |" << std::endl;
36- ofs_in << " | algorithm, we also need to set the sparse H and S matrix element |" << std::endl;
37- ofs_in << " | for each atom. |" << std::endl;
38- ofs_in << " | |" << std::endl;
39- ofs_in << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
40- ofs_in << " \n\n\n\n " ;
41- }
25+ ModuleBase::TITLE (" atom_arrange" , " set_sr_NL" );
26+ // check in use_overlap_matrix,
27+ double sr = 0.0 ;
28+ if (gamma_only_local)
29+ {
30+ sr = 2 * rcutmax_Phi + 0.001 ;
31+ }
32+ else
33+ {
34+ sr = 2 * (rcutmax_Phi + rcutmax_Beta) + 0.001 ; // 0.001 is added to make safe.
35+ // sr = 2 * longest_orb_rcut + 0.001;
36+ }
4237
43-
44- // xiaohui add 'output_level' line, 2015-09-16
45- if (output_level != " m" ) { ofs_in << " \n SETUP SEARCHING RADIUS FOR PROGRAM TO SEARCH ADJACENT ATOMS" << std::endl;
46- }
47- if (output_level != " m" ) { ofs_in << std::setprecision (3 );
48- }
49- if (output_level != " m" ) { ModuleBase::GlobalFunc::OUT (ofs_in," longest orb rcut (Bohr)" ,rcutmax_Phi);
38+ if (output_level != " m" ) // xiaohui add 'output_level', 2015-09-16
39+ {
40+ ofs_in << " \n\n\n\n " ;
41+ ofs_in << " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std::endl;
42+ ofs_in << " | |" << std::endl;
43+ ofs_in << " | Search adjacent atoms: |" << std::endl;
44+ ofs_in << " | Set the adjacent atoms for each atom and set the periodic boundary |" << std::endl;
45+ ofs_in << " | condition for the atoms on real space FFT grid. For k-dependent |" << std::endl;
46+ ofs_in << " | algorithm, we also need to set the sparse H and S matrix element |" << std::endl;
47+ ofs_in << " | for each atom. |" << std::endl;
48+ ofs_in << " | |" << std::endl;
49+ ofs_in << " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
50+ ofs_in << " \n\n\n\n " ;
51+
52+ ofs_in << " \n SETUP SEARCHING RADIUS FOR PROGRAM TO SEARCH ADJACENT ATOMS" << std::endl;
53+ ofs_in << std::setprecision (3 );
54+ ModuleBase::GlobalFunc::OUT (ofs_in, " longest orb rcut (Bohr)" , rcutmax_Phi);
55+ ModuleBase::GlobalFunc::OUT (ofs_in, " longest nonlocal projector rcut (Bohr)" , rcutmax_Beta);
56+ ModuleBase::GlobalFunc::OUT (ofs_in, " search radius (Bohr)" , sr);
57+ }
58+ return sr;
5059}
5160
52- // std::cout << " LONGEST NL PROJ RCUT : " << longest_nl_proj_rcut << std::endl;
53- if (output_level != " m" ) { ModuleBase::GlobalFunc::OUT (ofs_in," longest nonlocal projector rcut (Bohr)" , rcutmax_Beta);
54- }
61+ void atom_arrange::search (const bool pbc_flag,
62+ std::ofstream& ofs_in,
63+ Grid_Driver& grid_d,
64+ const UnitCell& ucell,
65+ const double & search_radius_bohr,
66+ const int & test_atom_in,
67+ const bool test_only)
68+ {
69+ ModuleBase::TITLE (" atom_arrange" , " search" );
70+ ModuleBase::timer::tick (" atom_arrange" , " search" );
5571
56- // check in use_overlap_matrix,
57- double sr = 0.0 ;
58- if (gamma_only_local)
59- {
60- sr = 2 * rcutmax_Phi + 0.01 ;
61- }
62- else
63- {
64- sr = 2 * (rcutmax_Phi +rcutmax_Beta) + 0.01 ; // 0.01 is added to make safe.
65- // sr = 2 * longest_orb_rcut + 0.01;
66- }
72+ if (search_radius_bohr < 0.0 )
73+ {
74+ ModuleBase::WARNING_QUIT (" atom_arrange::search" , " search_radius_bohr < 0,forbidden" );
75+ }
6776
68- return sr;
69- }
77+ ModuleBase::GlobalFunc::OUT (ofs_in, " searching radius is (Bohr)) " , search_radius_bohr);
78+ ModuleBase::GlobalFunc::OUT (ofs_in, " searching radius unit is (Bohr)) " , ucell. lat0 );
7079
71- void atom_arrange::search (
72- const bool pbc_flag,
73- std::ofstream &ofs_in,
74- Grid_Driver &grid_d,
75- const UnitCell &ucell,
76- const double &search_radius_bohr,
77- const int &test_atom_in,
78- const bool test_only)
79- {
80- ModuleBase::TITLE (" atom_arrange" , " search" );
81- ModuleBase::timer::tick (" atom_arrange" ," search" );
82- /* std::cout << "pbc_flag = " << pbc_flag << std::endl;
83- std::cout << "search_radius_bohr = " << search_radius_bohr << std::endl;
84- std::cout << "test_atom_in = " << test_atom_in << std::endl;
85- std::cout << "test_only = " << test_only << std::endl;
86- */
87- assert ( search_radius_bohr > 0.0 );
88-
89- // OUT(ofs_in,"Atom coordinates reading from",PARAM.inp.stru_file);
90- // OUT(ofs_in,"The coordinate type",ucell.Coordinate);
91- // OUT(ofs_in,"Use cartesian(unit:lat0) coordinate","TRUE");
92- // if(PARAM.inp.out_level != "m") OUT(ofs_in,"searching radius is (Bohr))", search_radius_bohr);
93- // if(PARAM.inp.out_level != "m") OUT(ofs_in,"searching radius unit is (Bohr))",ucell.lat0);
94-
95- ModuleBase::GlobalFunc::OUT (ofs_in," searching radius is (Bohr))" , search_radius_bohr);
96- ModuleBase::GlobalFunc::OUT (ofs_in," searching radius unit is (Bohr))" ,ucell.lat0 );
97-
98- assert (ucell.nat > 0 );
99- // =============================
100- // Initial Atom information
101- // =============================
102-
103- const double radius_lat0unit = search_radius_bohr / ucell.lat0 ;
104- ModuleBase::timer::tick (" atom_arrange" , " Atom_input" );
105-
106- Atom_input at (
107- ofs_in,
108- ucell,
109- ucell.nat ,
110- ucell.ntype ,
111- pbc_flag,
112- radius_lat0unit,
113- test_atom_in);
114- ModuleBase::timer::tick (" atom_arrange" , " Atom_input" );
115-
116- // ===========================================
117- // Print important information in Atom_input
118- // ===========================================
119- // at.print(std::cout);
120- // at.print_xyz_format("1.xyz");
121- // =========================================
122- // Construct Grid , Cells , Adjacent atoms
123- // =========================================
124-
125- ModuleBase::timer::tick (" atom_arrange" , " grid_d.init" );
126-
127- grid_d.init (ofs_in, ucell, at);
128- ModuleBase::timer::tick (" atom_arrange" , " grid_d.init" );
80+ assert (ucell.nat > 0 );
12981
82+ /*
83+ 2024-12-04 Zhang Haochong
84+ The neighboring atom search module has been completely rewritten.
85+ The new algorithm places atoms into boxes with an edge length of twice the atomic radius. The neighboring
86+ atom list stores the data using the atom's type and its index within that type.
87+ By setting pbc_flag = false, periodic boundary conditions can be forcibly disabled. In this case, the search
88+ process will not expand the supercell, and the neighboring atoms will only consider those within the original unit cell.
89+ */
90+ const double radius_lat0unit = search_radius_bohr / ucell.lat0 ;
91+
92+ // Atom_input at(ofs_in, ucell, pbc_flag, radius_lat0unit, test_atom_in);
93+
94+ grid_d.init (ofs_in, ucell, radius_lat0unit, pbc_flag);
95+
96+ // The screen output is very time-consuming. To avoid interfering with the timing, we will insert logging here earlier.
13097 ModuleBase::timer::tick (" atom_arrange" , " search" );
13198
132- // test the adjacent atoms and the box.
133- if (test_only)
134- {
135- std::cout << " radius_lat0unit = " << radius_lat0unit << std::endl;
136- std::cout << " search_radius_bohr = " << search_radius_bohr << std::endl;
99+ if (test_only)
100+ {
101+ std::cout << " radius_lat0unit = " << radius_lat0unit << std::endl;
102+ std::cout << " search_radius_bohr = " << search_radius_bohr << std::endl;
137103
138- ofs_in << " " << std::setw (5 ) << " Type" << std::setw (5 ) << " Atom" << std::setw (8 ) << " AdjNum" << std::endl;
104+ ofs_in << " " << std::setw (5 ) << " Type" << std::setw (5 ) << " Atom" << std::setw (8 ) << " AdjNum" << std::endl;
139105 std::cout << std::setw (8 ) << " Labels" << std::setw (15 ) << " tau.x" << std::setw (15 ) << " tau.y" << std::setw (15 )
140106 << " tau.z" << std::setw (8 ) << " box.x" << std::setw (8 ) << " box.y" << std::setw (8 ) << " box.z"
141107 << std::endl;
@@ -147,19 +113,21 @@ void atom_arrange::search(
147113
148114 ofs_in << " " << std::setw (5 ) << it << std::setw (5 ) << ia << std::setw (8 ) << grid_d.getAdjacentNum () + 1
149115 << std::endl;
150-
116+ std::cout << " adjacent atoms of " << ucell.atoms [it].label + std::to_string (ia + 1 ) << " :" << std::endl;
117+ std::cout << " getAdjacentNum: " << grid_d.getAdjacentNum () + 1 << std::endl;
118+ /*
151119 for (int ad = 0; ad < grid_d.getAdjacentNum() + 1; ad++)
152120 {
153121 ModuleBase::Vector3<double> tau = grid_d.getAdjacentTau(ad);
154122 ModuleBase::Vector3<int> box = grid_d.getBox(ad);
155123 std::cout << std::setw(8) << ucell.atoms[it].label + std::to_string(ia + 1) << std::setw(15)
156124 << tau.x << " " << std::setw(15) << tau.y << " " << std::setw(15) << tau.z << " "
157125 << std::setw(8) << box.x << std::setw(8) << box.y << std::setw(8) << box.z << std::endl;
158- }
126+ }*/
159127 }
160128 }
161129 ofs_in << " search neighboring atoms done." << std::endl;
162130 }
163131
164132 return ;
165- }
133+ }
0 commit comments