Skip to content

Commit 3669a02

Browse files
feat(input, kpoints): support shifted kspacing mesh with koffset and kmesh_type (#7247)
* feat(input, kpoints): support shifted kspacing mesh with koffset and kmesh_type * revert input-main.md * Fix headers * Use sync_string instead of sync_string to be case insensitive * add test case for kspacing koffset kmesh_type * add test case for kspacing koffset kmesh_type * clean test case for kspacing koffset kmesh_type * Update CASES_CPU --------- Co-authored-by: Mohan Chen <mohanchen@pku.edu.cn>
1 parent 9683591 commit 3669a02

File tree

10 files changed

+226
-8
lines changed

10 files changed

+226
-8
lines changed

docs/parameters.yaml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ parameters:
224224
default_value: "0.0"
225225
unit: ""
226226
availability: ""
227+
- name: koffset
228+
category: System variables
229+
type: Vector of Real (3 values)
230+
description: |
231+
Set offsets for automatic k-point mesh generated by kspacing, in each reciprocal direction. This parameter is only effective when kspacing > 0.0 and gamma_only is false.
232+
default_value: 0.0 0.0 0.0
233+
unit: ""
234+
availability: ""
235+
- name: kmesh_type
236+
category: System variables
237+
type: String
238+
description: |
239+
Set mesh type used for automatic k-point mesh generated by kspacing. Available options are gamma and mp. This parameter is only effective when kspacing > 0.0 and gamma_only is false.
240+
default_value: gamma
241+
unit: ""
242+
availability: ""
227243
- name: min_dist_coef
228244
category: System variables
229245
type: Real
@@ -1690,10 +1706,14 @@ parameters:
16901706
availability: ""
16911707
- name: cal_syns
16921708
category: Molecular dynamics
1693-
type: Boolean
1709+
type: "Boolean [Integer](optional)"
16941710
description: |
16951711
Whether to calculate and output asynchronous overlap matrix for Hefei-NAMD interface. When enabled, calculates <phi(t-1)|phi(t)> by computing overlap between basis functions at atomic positions from previous time step and current time step. The overlap is calculated by shifting atom positions backward by velocity x md_dt. Output file: OUT.*/syns_nao.csr in CSR format.
16961712
1713+
* 0 or false: disable
1714+
* 1 or true: enable with default precision (8 digits)
1715+
* 1 5: enable with custom precision (5 digits)
1716+
16971717
[NOTE] Only works with LCAO basis and molecular dynamics calculations. Requires atomic velocities. Output starts from the second MD step (istep > 0).
16981718
default_value: "False"
16991719
unit: ""
@@ -1715,6 +1735,7 @@ parameters:
17151735
* vw: von Weizsacker (vW) functional
17161736
* tf+: TF + vW functional
17171737
* wt: Wang-Teter (WT) functional
1738+
* ext-wt: Extended Wang-Teter functional
17181739
* xwm: XWM functional
17191740
* lkt: Luo-Karasiev-Trickey (LKT) functional
17201741
* ml: Machine learning KEDF
@@ -1768,31 +1789,39 @@ parameters:
17681789
Weight of TF KEDF (kinetic energy density functional).
17691790
default_value: "1.0"
17701791
unit: ""
1771-
availability: "OFDFT with of_kinetic=tf, tf+, wt, xwm"
1792+
availability: "OFDFT with of_kinetic=tf, tf+, wt, ext-wt, xwm"
17721793
- name: of_vw_weight
17731794
category: "OFDFT: orbital free density functional theory"
17741795
type: Real
17751796
description: |
17761797
Weight of vW KEDF (kinetic energy density functional).
17771798
default_value: "1.0"
17781799
unit: ""
1779-
availability: "OFDFT with of_kinetic=vw, tf+, wt, lkt, xwm"
1800+
availability: "OFDFT with of_kinetic=vw, tf+, wt, ext-wt, lkt, xwm"
17801801
- name: of_wt_alpha
17811802
category: "OFDFT: orbital free density functional theory"
17821803
type: Real
17831804
description: |
17841805
Parameter alpha of WT KEDF (kinetic energy density functional).
17851806
default_value: ""
17861807
unit: ""
1787-
availability: OFDFT with of_kinetic=wt
1808+
availability: "OFDFT with of_kinetic=wt, ext-wt"
17881809
- name: of_wt_beta
17891810
category: "OFDFT: orbital free density functional theory"
17901811
type: Real
17911812
description: |
17921813
Parameter beta of WT KEDF (kinetic energy density functional).
17931814
default_value: ""
17941815
unit: ""
1795-
availability: OFDFT with of_kinetic=wt
1816+
availability: "OFDFT with of_kinetic=wt, ext-wt"
1817+
- name: of_extwt_kappa
1818+
category: "OFDFT: orbital free density functional theory"
1819+
type: Real
1820+
description: |
1821+
Parameter kappa for EXT-WT KEDF.
1822+
default_value: "1.0 / (2.0 * std::pow(4./3., 1./3.) - 1.0)"
1823+
unit: ""
1824+
availability: OFDFT with of_kinetic=ext-wt
17961825
- name: of_wt_rho0
17971826
category: "OFDFT: orbital free density functional theory"
17981827
type: Real

source/source_cell/klist.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,16 @@ bool K_Vectors::read_kpoints(const UnitCell& ucell,
247247
std::ofstream ofs(fn.c_str());
248248
ofs << "K_POINTS" << std::endl;
249249
ofs << "0" << std::endl;
250-
ofs << "Gamma" << std::endl;
251-
ofs << nk1 << " " << nk2 << " " << nk3 << " 0 0 0" << std::endl;
250+
if (PARAM.inp.kmesh_type == "mp")
251+
{
252+
ofs << "Monkhorst-Pack" << std::endl;
253+
}
254+
else
255+
{
256+
ofs << "Gamma" << std::endl;
257+
}
258+
ofs << nk1 << " " << nk2 << " " << nk3 << " " << PARAM.inp.koffset[0] << " " << PARAM.inp.koffset[1] << " "
259+
<< PARAM.inp.koffset[2] << std::endl;
252260
ofs.close();
253261
}
254262

source/source_cell/test/klist_test.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ TEST_F(KlistTest, ReadKpointsKspacing)
313313
PARAM.input.kspacing[0] = 0.052918; // 0.52918/Bohr = 1/A
314314
PARAM.input.kspacing[1] = 0.052918; // 0.52918/Bohr = 1/A
315315
PARAM.input.kspacing[2] = 0.052918; // 0.52918/Bohr = 1/A
316+
PARAM.input.kmesh_type = "gamma";
317+
PARAM.input.koffset[0] = 0.0;
318+
PARAM.input.koffset[1] = 0.0;
319+
PARAM.input.koffset[2] = 0.0;
316320
setucell();
317321
std::string k_file = "./support/KPT3";
318322
kv->read_kpoints(ucell,k_file);
@@ -328,6 +332,10 @@ TEST_F(KlistTest, ReadKpointsKspacing3values)
328332
PARAM.input.kspacing[0] = 0.052918; // 0.52918/Bohr = 1/A
329333
PARAM.input.kspacing[1] = 0.06; // 0.52918/Bohr = 1/A
330334
PARAM.input.kspacing[2] = 0.07; // 0.52918/Bohr = 1/A
335+
PARAM.input.kmesh_type = "gamma";
336+
PARAM.input.koffset[0] = 0.0;
337+
PARAM.input.koffset[1] = 0.0;
338+
PARAM.input.koffset[2] = 0.0;
331339
setucell();
332340
std::string k_file = "./support/KPT3";
333341
kv->read_kpoints(ucell,k_file);
@@ -343,6 +351,10 @@ TEST_F(KlistTest, ReadKpointsInvalidKspacing3values)
343351
PARAM.input.kspacing[0] = 0.052918; // 0.52918/Bohr = 1/A
344352
PARAM.input.kspacing[1] = 0; // 0.52918/Bohr = 1/A
345353
PARAM.input.kspacing[2] = 0.07; // 0.52918/Bohr = 1/A
354+
PARAM.input.kmesh_type = "gamma";
355+
PARAM.input.koffset[0] = 0.0;
356+
PARAM.input.koffset[1] = 0.0;
357+
PARAM.input.koffset[2] = 0.0;
346358
std::string k_file = "./support/KPT3";
347359
testing::internal::CaptureStdout();
348360
EXPECT_EXIT(kv->read_kpoints(ucell,k_file), ::testing::ExitedWithCode(1), "");
@@ -352,6 +364,72 @@ TEST_F(KlistTest, ReadKpointsInvalidKspacing3values)
352364
PARAM.input.kspacing[2] = 0.0;
353365
}
354366

367+
TEST_F(KlistTest, ReadKpointsKspacingShiftedGamma)
368+
{
369+
kv->nspin = 1;
370+
PARAM.input.kspacing[0] = 0.052918; // 0.52918/Bohr = 1/A
371+
PARAM.input.kspacing[1] = 0.052918;
372+
PARAM.input.kspacing[2] = 0.052918;
373+
PARAM.input.kmesh_type = "gamma";
374+
PARAM.input.koffset[0] = 0.5;
375+
PARAM.input.koffset[1] = 0.5;
376+
PARAM.input.koffset[2] = 0.5;
377+
setucell();
378+
379+
std::string k_file = "./support/KPT3";
380+
kv->read_kpoints(ucell, k_file);
381+
382+
EXPECT_EQ(kv->get_nkstot(), 343);
383+
EXPECT_EQ(kv->get_k_kword(), "Gamma");
384+
EXPECT_DOUBLE_EQ(kv->get_koffset(0), 0.5);
385+
EXPECT_DOUBLE_EQ(kv->get_koffset(1), 0.5);
386+
EXPECT_DOUBLE_EQ(kv->get_koffset(2), 0.5);
387+
EXPECT_NEAR(kv->kvec_d[0].x, 1.0 / 14.0, 1e-12);
388+
EXPECT_NEAR(kv->kvec_d[0].y, 1.0 / 14.0, 1e-12);
389+
EXPECT_NEAR(kv->kvec_d[0].z, 1.0 / 14.0, 1e-12);
390+
391+
PARAM.input.kspacing[0] = 0.0;
392+
PARAM.input.kspacing[1] = 0.0;
393+
PARAM.input.kspacing[2] = 0.0;
394+
PARAM.input.koffset[0] = 0.0;
395+
PARAM.input.koffset[1] = 0.0;
396+
PARAM.input.koffset[2] = 0.0;
397+
PARAM.input.kmesh_type = "gamma";
398+
}
399+
400+
TEST_F(KlistTest, ReadKpointsKspacingShiftedMP)
401+
{
402+
kv->nspin = 1;
403+
PARAM.input.kspacing[0] = 0.052918; // 0.52918/Bohr = 1/A
404+
PARAM.input.kspacing[1] = 0.052918;
405+
PARAM.input.kspacing[2] = 0.052918;
406+
PARAM.input.kmesh_type = "mp";
407+
PARAM.input.koffset[0] = 0.5;
408+
PARAM.input.koffset[1] = 0.5;
409+
PARAM.input.koffset[2] = 0.5;
410+
setucell();
411+
412+
std::string k_file = "./support/KPT3";
413+
kv->read_kpoints(ucell, k_file);
414+
415+
EXPECT_EQ(kv->get_nkstot(), 343);
416+
EXPECT_EQ(kv->get_k_kword(), "Monkhorst-Pack");
417+
EXPECT_DOUBLE_EQ(kv->get_koffset(0), 0.5);
418+
EXPECT_DOUBLE_EQ(kv->get_koffset(1), 0.5);
419+
EXPECT_DOUBLE_EQ(kv->get_koffset(2), 0.5);
420+
EXPECT_NEAR(kv->kvec_d[0].x, -5.5 / 14.0, 1e-12);
421+
EXPECT_NEAR(kv->kvec_d[0].y, -5.5 / 14.0, 1e-12);
422+
EXPECT_NEAR(kv->kvec_d[0].z, -5.5 / 14.0, 1e-12);
423+
424+
PARAM.input.kspacing[0] = 0.0;
425+
PARAM.input.kspacing[1] = 0.0;
426+
PARAM.input.kspacing[2] = 0.0;
427+
PARAM.input.koffset[0] = 0.0;
428+
PARAM.input.koffset[1] = 0.0;
429+
PARAM.input.koffset[2] = 0.0;
430+
PARAM.input.kmesh_type = "gamma";
431+
}
432+
355433
TEST_F(KlistTest, ReadKpointsGamma)
356434
{
357435
std::string k_file = "./support/KPT";

source/source_io/module_parameter/input_parameter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ struct Input_para
6464
int diago_proc = 0; ///< the number of procs used to diag. mohan add 2012-01-13
6565
int nbspline = -1; ///< the order of B-spline basis(>=0) if it is -1 (default)
6666
std::vector<double> kspacing = {0.0, 0.0, 0.0}; ///< kspacing for k-point generation
67+
std::vector<double> koffset = {0.0, 0.0, 0.0}; ///< koffset for kspacing-generated k-point mesh
68+
std::string kmesh_type = "gamma"; ///< k-point mesh type for kspacing-generated k-point mesh: gamma or mp
6769
double min_dist_coef = 0.2; ///< allowed minimum distance between two atoms
6870

6971
std::string device = "auto";

source/source_io/module_parameter/read_input_item_system.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
#include "read_input_tool.h"
55
#include "source_base/module_device/device.h"
66

7-
#include <fstream>
87
#include <unistd.h>
8+
#include <algorithm>
99

1010
namespace ModuleIO
1111
{
@@ -613,6 +613,53 @@ Available options are:
613613
};
614614
this->add_item(item);
615615
}
616+
{
617+
Input_Item item("koffset");
618+
item.annotation = "offset for kspacing-generated automatic k-point mesh";
619+
item.category = "System variables";
620+
item.type = "Vector of Real (3 values)";
621+
item.description = "Set offsets for automatic k-point mesh generated by kspacing, in each reciprocal direction. "
622+
"This parameter is only effective when kspacing > 0.0 and gamma_only is false.";
623+
item.default_value = "0.0 0.0 0.0";
624+
item.read_value = [](const Input_Item& item, Parameter& para) {
625+
if (item.get_size() != 3)
626+
{
627+
ModuleBase::WARNING_QUIT("ReadInput", "koffset must provide three values.");
628+
}
629+
para.input.koffset[0] = std::stod(item.str_values[0]);
630+
para.input.koffset[1] = std::stod(item.str_values[1]);
631+
para.input.koffset[2] = std::stod(item.str_values[2]);
632+
};
633+
sync_doublevec(input.koffset, 3, 0.0);
634+
this->add_item(item);
635+
}
636+
{
637+
Input_Item item("kmesh_type");
638+
item.annotation = "mesh type for kspacing-generated automatic k-point mesh";
639+
item.category = "System variables";
640+
item.type = "String";
641+
item.description = "Set mesh type used for automatic k-point mesh generated by kspacing. "
642+
"Available options are gamma and mp. This parameter is only effective when kspacing > 0.0 "
643+
"and gamma_only is false.";
644+
item.default_value = "gamma";
645+
item.read_value = [](const Input_Item& item, Parameter& para) {
646+
para.input.kmesh_type = strvalue;
647+
std::transform(para.input.kmesh_type.begin(),
648+
para.input.kmesh_type.end(),
649+
para.input.kmesh_type.begin(),
650+
::tolower);
651+
};
652+
sync_string(input.kmesh_type);
653+
item.check_value = [](const Input_Item& item, const Parameter& para) {
654+
std::vector<std::string> avail_list = {"gamma", "mp"};
655+
if (std::find(avail_list.begin(), avail_list.end(), para.input.kmesh_type) == avail_list.end())
656+
{
657+
const std::string warningstr = nofound_str(avail_list, "kmesh_type");
658+
ModuleBase::WARNING_QUIT("ReadInput", warningstr);
659+
}
660+
};
661+
this->add_item(item);
662+
}
616663
{
617664
Input_Item item("min_dist_coef");
618665
item.annotation = "factor related to the allowed minimum distance "
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
INPUT_PARAMETERS
2+
suffix autotest
3+
calculation scf
4+
init_wfc random
5+
6+
symmetry 1
7+
ecutwfc 5
8+
scf_thr 1e-06
9+
scf_nmax 30
10+
basis_type pw
11+
latname bco
12+
13+
mixing_type broyden
14+
mixing_beta 0.4
15+
16+
smearing_method gaussian
17+
smearing_sigma 0.02
18+
19+
kspacing 0.6
20+
koffset 0.5 0.5 0.5
21+
kmesh_type gamma
22+
pseudo_dir ../../PP_ORB
23+
pw_seed 1
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fast integration case for kspacing-generated shifted Gamma mesh
2+
covers new INPUT parameters: koffset and kmesh_type
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#This is the atom file containing all the information
2+
#about the lattice structure.
3+
4+
ATOMIC_SPECIES
5+
H 1.0008 H_ONCV_PBE-1.0.upf
6+
7+
NUMERICAL_ORBITAL
8+
H_gga_6au_60Ry_2s1p.orb
9+
10+
LATTICE_CONSTANT
11+
10.0 #Lattice constant
12+
13+
LATTICE_PARAMETERS
14+
1.5 2.0
15+
16+
ATOMIC_POSITIONS
17+
Cartesian #Cartesian(Unit is LATTICE_CONSTANT)
18+
H #Name of element
19+
0.0 #Magnetic for this element.
20+
2 #Number of atoms
21+
0.00 0.00 -0.0661400 0 0 0 #x,y,z, move_x, move_y, move_z
22+
0.00 0.00 0.0661400 0 0 0 #x,y,z, move_x, move_y, move_z
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
etotref -27.08734962492505
2+
etotperatomref -13.5436748125
3+
pointgroupref D_2h
4+
spacegroupref D_2h
5+
nksibzref 2
6+
totaltimeref 0.28

tests/01_PW/CASES_CPU.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ scf_out_chg_tau
111111
207_PW_skip
112112
208_PW_CG_float
113113
209_PW_DFTHALF
114+
210_PW_kspace_shift
114115
801_PW_LT_sc
115116
802_PW_LT_fcc
116117
803_PW_LT_bcc

0 commit comments

Comments
 (0)