Skip to content

Commit 2126618

Browse files
committed
Add input parameters
1 parent dfc9437 commit 2126618

8 files changed

Lines changed: 102 additions & 5 deletions

File tree

docs/advanced/input_files/input-main.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@
431431
- [vdw\_cutoff\_type](#vdw_cutoff_type)
432432
- [vdw\_cutoff\_radius](#vdw_cutoff_radius)
433433
- [vdw\_radius\_unit](#vdw_radius_unit)
434+
- [vdw\_cutoff\_smooth\_width\_2b](#vdw_cutoff_smooth_width_2b)
435+
- [vdw\_cutoff\_smooth\_width\_3b](#vdw_cutoff_smooth_width_3b)
434436
- [vdw\_cutoff\_period](#vdw_cutoff_period)
435437
- [vdw\_cn\_thr](#vdw_cn_thr)
436438
- [vdw\_cn\_thr\_unit](#vdw_cn_thr_unit)
@@ -4062,6 +4064,24 @@
40624064
- Bohr
40634065
- **Default**: Bohr
40644066

4067+
### vdw_cutoff_smooth_width_2b
4068+
4069+
- **Type**: Real
4070+
- **Availability**: *vdw_method is set to d4*
4071+
- **Description**: Width of the smooth switching region for the two-body pairwise dispersion real-space cutoff.
4072+
A value of zero disables smoothing for the two-body contribution.
4073+
- **Default**: 0.05
4074+
- **Unit**: Bohr
4075+
4076+
### vdw_cutoff_smooth_width_3b
4077+
4078+
- **Type**: Real
4079+
- **Availability**: *vdw_method is set to d4*
4080+
- **Description**: Width of the smooth switching region for the three-body Axilrod-Teller-Muto (ATM) dispersion real-space cutoff.
4081+
A value of zero disables smoothing for the three-body contribution.
4082+
- **Default**: 0.05
4083+
- **Unit**: Bohr
4084+
40654085
### vdw_cutoff_period
40664086

40674087
- **Type**: Integer Integer Integer

docs/parameters.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4312,6 +4312,24 @@ parameters:
43124312
default_value: Bohr
43134313
unit: ""
43144314
availability: vdw_cutoff_type==radius
4315+
- name: vdw_cutoff_smooth_width_2b
4316+
category: vdW correction
4317+
type: Real
4318+
description: |
4319+
Width of the smooth switching region for the two-body pairwise dispersion real-space cutoff.
4320+
A value of zero disables smoothing for the two-body contribution.
4321+
default_value: "0.05"
4322+
unit: Bohr
4323+
availability: vdw_method is set to d4
4324+
- name: vdw_cutoff_smooth_width_3b
4325+
category: vdW correction
4326+
type: Real
4327+
description: |
4328+
Width of the smooth switching region for the three-body Axilrod-Teller-Muto (ATM) dispersion real-space cutoff.
4329+
A value of zero disables smoothing for the three-body contribution.
4330+
default_value: "0.05"
4331+
unit: Bohr
4332+
availability: vdw_method is set to d4
43154333
- name: vdw_cutoff_period
43164334
category: vdW correction
43174335
type: Integer Integer Integer

source/source_hamilt/module_vdw/vdwd4.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ namespace vdw
2323
namespace
2424
{
2525

26-
constexpr double d4_smooth_cutoff_width_2 = 0.05; // Bohr
27-
constexpr double d4_smooth_cutoff_width_3 = 0.05; // Bohr
28-
2926
std::string to_lower(std::string value)
3027
{
3128
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char c) {
@@ -89,6 +86,8 @@ Vdwd4::Vdwd4(const UnitCell& unit_in, const std::string& xc_name, const Input_pa
8986
cutoff_disp2_ = cutoff_to_bohr(input.vdw_cutoff_radius, input.vdw_radius_unit);
9087
cutoff_disp3_ = std::min(40.0, cutoff_disp2_);
9188
cutoff_cn_ = length_to_bohr(input.vdw_cn_thr, input.vdw_cn_thr_unit);
89+
smooth_width_2b_ = input.vdw_cutoff_smooth_width_2b;
90+
smooth_width_3b_ = input.vdw_cutoff_smooth_width_3b;
9291

9392
double valence_charge = 0.0;
9493
for (int it = 0; it < ucell_.ntype; ++it)
@@ -199,8 +198,8 @@ void Vdwd4::compute(double& energy_ha,
199198
cutoff_disp2_,
200199
cutoff_disp3_,
201200
cutoff_cn_,
202-
d4_smooth_cutoff_width_2,
203-
d4_smooth_cutoff_width_3);
201+
smooth_width_2b_,
202+
smooth_width_3b_);
204203
check_dftd4_error(error, "dftd4_set_model_realspace_cutoff_smooth");
205204

206205
std::vector<char> method(xc_name_.begin(), xc_name_.end());

source/source_hamilt/module_vdw/vdwd4.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class Vdwd4 : public Vdw
2323
double cutoff_disp2_ = 0.0; // Bohr, two-body dispersion cutoff
2424
double cutoff_disp3_ = 0.0; // Bohr, three-body ATM cutoff
2525
double cutoff_cn_ = 0.0; // Bohr, coordination-number cutoff
26+
double smooth_width_2b_ = 0.0; // Bohr, two-body cutoff smoothing width
27+
double smooth_width_3b_ = 0.0; // Bohr, three-body cutoff smoothing width
2628
double total_charge_ = 0.0; // e, total system charge (sum zv*na - nelec)
2729

2830
void evaluate_impl(const VdwRequest& request, VdwResult& result) override;

source/source_io/module_parameter/input_parameter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ struct Input_para
569569
///< structure, radius or period
570570
std::string vdw_cutoff_radius = "default"; ///< radius cutoff for periodic structure
571571
std::string vdw_radius_unit = "Bohr"; ///< unit of radius cutoff for periodic structure
572+
double vdw_cutoff_smooth_width_2b = 0.05; ///< smooth cutoff width for two-body dispersion, Bohr
573+
double vdw_cutoff_smooth_width_3b = 0.05; ///< smooth cutoff width for three-body dispersion, Bohr
572574
double vdw_cn_thr = 40.0; ///< radius cutoff for cn
573575
std::string vdw_cn_thr_unit = "Bohr"; ///< unit of cn_thr, Bohr or Angstrom
574576
std::string vdw_d4_xc = "default"; ///< functional name passed to DFT-D4

source/source_io/module_parameter/read_inp_model.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,44 @@ Namely, each line contains the element name and the corresponding parameter.)";
572572
};
573573
this->add_item(item);
574574
}
575+
{
576+
Input_Item item("vdw_cutoff_smooth_width_2b");
577+
item.annotation = "smooth cutoff width for two-body dispersion";
578+
item.category = "vdW correction";
579+
item.type = "Real";
580+
item.description = R"(Width of the smooth switching region for the two-body pairwise dispersion real-space cutoff.
581+
A value of zero disables smoothing for the two-body contribution.)";
582+
item.default_value = "0.05";
583+
item.unit = "Bohr";
584+
item.set_availability("vdw_method==d4");
585+
read_sync_double(input.vdw_cutoff_smooth_width_2b);
586+
item.check_value = [](const Input_Item& item, const Parameter& para) {
587+
if (para.input.vdw_cutoff_smooth_width_2b < 0.0)
588+
{
589+
ModuleBase::WARNING_QUIT("ReadInput", "vdw_cutoff_smooth_width_2b must be non-negative");
590+
}
591+
};
592+
this->add_item(item);
593+
}
594+
{
595+
Input_Item item("vdw_cutoff_smooth_width_3b");
596+
item.annotation = "smooth cutoff width for three-body dispersion";
597+
item.category = "vdW correction";
598+
item.type = "Real";
599+
item.description = R"(Width of the smooth switching region for the three-body Axilrod-Teller-Muto (ATM) dispersion real-space cutoff.
600+
A value of zero disables smoothing for the three-body contribution.)";
601+
item.default_value = "0.05";
602+
item.unit = "Bohr";
603+
item.set_availability("vdw_method==d4");
604+
read_sync_double(input.vdw_cutoff_smooth_width_3b);
605+
item.check_value = [](const Input_Item& item, const Parameter& para) {
606+
if (para.input.vdw_cutoff_smooth_width_3b < 0.0)
607+
{
608+
ModuleBase::WARNING_QUIT("ReadInput", "vdw_cutoff_smooth_width_3b must be non-negative");
609+
}
610+
};
611+
this->add_item(item);
612+
}
575613
{
576614
Input_Item item("vdw_cutoff_period");
577615
item.annotation = "periods of periodic structure";

source/source_io/test/read_input_ptest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ TEST_F(InputParaTest, ParaRead)
274274
EXPECT_FALSE(param.inp.vdw_abc);
275275
EXPECT_EQ(std::stod(param.inp.vdw_cutoff_radius), 56.6918);
276276
EXPECT_EQ(param.inp.vdw_radius_unit, "Bohr");
277+
EXPECT_DOUBLE_EQ(param.inp.vdw_cutoff_smooth_width_2b, 0.05);
278+
EXPECT_DOUBLE_EQ(param.inp.vdw_cutoff_smooth_width_3b, 0.05);
277279
EXPECT_DOUBLE_EQ(param.inp.vdw_cn_thr, 40.0);
278280
EXPECT_EQ(param.inp.vdw_cn_thr_unit, "Bohr");
279281
EXPECT_EQ(param.inp.vdw_C6_file, "default");

source/source_io/test_serial/read_input_item_test.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,6 +1440,22 @@ TEST_F(InputTest, Item_test2)
14401440
output = testing::internal::GetCapturedStdout();
14411441
EXPECT_THAT(output, testing::HasSubstr("NOTICE"));
14421442
}
1443+
{ // vdw_cutoff_smooth_width_2b
1444+
auto it = find_label("vdw_cutoff_smooth_width_2b", readinput.input_lists);
1445+
param.input.vdw_cutoff_smooth_width_2b = -1.0;
1446+
testing::internal::CaptureStdout();
1447+
EXPECT_EXIT(it->second.check_value(it->second, param), ::testing::ExitedWithCode(1), "");
1448+
output = testing::internal::GetCapturedStdout();
1449+
EXPECT_THAT(output, testing::HasSubstr("NOTICE"));
1450+
}
1451+
{ // vdw_cutoff_smooth_width_3b
1452+
auto it = find_label("vdw_cutoff_smooth_width_3b", readinput.input_lists);
1453+
param.input.vdw_cutoff_smooth_width_3b = -1.0;
1454+
testing::internal::CaptureStdout();
1455+
EXPECT_EXIT(it->second.check_value(it->second, param), ::testing::ExitedWithCode(1), "");
1456+
output = testing::internal::GetCapturedStdout();
1457+
EXPECT_THAT(output, testing::HasSubstr("NOTICE"));
1458+
}
14431459
{ // vdw_cn_thr
14441460
auto it = find_label("vdw_cn_thr", readinput.input_lists);
14451461
param.input.vdw_cn_thr = -1;

0 commit comments

Comments
 (0)