Skip to content

Commit 5d2ab33

Browse files
committed
Add input parameters
1 parent 2f57e93 commit 5d2ab33

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
@@ -429,6 +429,8 @@
429429
- [vdw\_cutoff\_type](#vdw_cutoff_type)
430430
- [vdw\_cutoff\_radius](#vdw_cutoff_radius)
431431
- [vdw\_radius\_unit](#vdw_radius_unit)
432+
- [vdw\_cutoff\_smooth\_width\_2b](#vdw_cutoff_smooth_width_2b)
433+
- [vdw\_cutoff\_smooth\_width\_3b](#vdw_cutoff_smooth_width_3b)
432434
- [vdw\_cutoff\_period](#vdw_cutoff_period)
433435
- [vdw\_cn\_thr](#vdw_cn_thr)
434436
- [vdw\_cn\_thr\_unit](#vdw_cn_thr_unit)
@@ -4026,6 +4028,24 @@
40264028
- Bohr
40274029
- **Default**: Bohr
40284030

4031+
### vdw_cutoff_smooth_width_2b
4032+
4033+
- **Type**: Real
4034+
- **Availability**: *vdw_method is set to d4*
4035+
- **Description**: Width of the smooth switching region for the two-body pairwise dispersion real-space cutoff.
4036+
A value of zero disables smoothing for the two-body contribution.
4037+
- **Default**: 0.05
4038+
- **Unit**: Bohr
4039+
4040+
### vdw_cutoff_smooth_width_3b
4041+
4042+
- **Type**: Real
4043+
- **Availability**: *vdw_method is set to d4*
4044+
- **Description**: Width of the smooth switching region for the three-body Axilrod-Teller-Muto (ATM) dispersion real-space cutoff.
4045+
A value of zero disables smoothing for the three-body contribution.
4046+
- **Default**: 0.05
4047+
- **Unit**: Bohr
4048+
40294049
### vdw_cutoff_period
40304050

40314051
- **Type**: Integer Integer Integer

docs/parameters.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4158,6 +4158,24 @@ parameters:
41584158
default_value: Bohr
41594159
unit: ""
41604160
availability: vdw_cutoff_type is set to radius
4161+
- name: vdw_cutoff_smooth_width_2b
4162+
category: vdW correction
4163+
type: Real
4164+
description: |
4165+
Width of the smooth switching region for the two-body pairwise dispersion real-space cutoff.
4166+
A value of zero disables smoothing for the two-body contribution.
4167+
default_value: "0.05"
4168+
unit: Bohr
4169+
availability: vdw_method is set to d4
4170+
- name: vdw_cutoff_smooth_width_3b
4171+
category: vdW correction
4172+
type: Real
4173+
description: |
4174+
Width of the smooth switching region for the three-body Axilrod-Teller-Muto (ATM) dispersion real-space cutoff.
4175+
A value of zero disables smoothing for the three-body contribution.
4176+
default_value: "0.05"
4177+
unit: Bohr
4178+
availability: vdw_method is set to d4
41614179
- name: vdw_cutoff_period
41624180
category: vdW correction
41634181
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
@@ -548,6 +548,8 @@ struct Input_para
548548
///< structure, radius or period
549549
std::string vdw_cutoff_radius = "default"; ///< radius cutoff for periodic structure
550550
std::string vdw_radius_unit = "Bohr"; ///< unit of radius cutoff for periodic structure
551+
double vdw_cutoff_smooth_width_2b = 0.05; ///< smooth cutoff width for two-body dispersion, Bohr
552+
double vdw_cutoff_smooth_width_3b = 0.05; ///< smooth cutoff width for three-body dispersion, Bohr
551553
double vdw_cn_thr = 40.0; ///< radius cutoff for cn
552554
std::string vdw_cn_thr_unit = "Bohr"; ///< unit of cn_thr, Bohr or Angstrom
553555
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
@@ -585,6 +585,44 @@ Namely, each line contains the element name and the corresponding parameter.)";
585585
};
586586
this->add_item(item);
587587
}
588+
{
589+
Input_Item item("vdw_cutoff_smooth_width_2b");
590+
item.annotation = "smooth cutoff width for two-body dispersion";
591+
item.category = "vdW correction";
592+
item.type = "Real";
593+
item.description = R"(Width of the smooth switching region for the two-body pairwise dispersion real-space cutoff.
594+
A value of zero disables smoothing for the two-body contribution.)";
595+
item.default_value = "0.05";
596+
item.unit = "Bohr";
597+
item.availability = "vdw_method is set to d4";
598+
read_sync_double(input.vdw_cutoff_smooth_width_2b);
599+
item.check_value = [](const Input_Item& item, const Parameter& para) {
600+
if (para.input.vdw_cutoff_smooth_width_2b < 0.0)
601+
{
602+
ModuleBase::WARNING_QUIT("ReadInput", "vdw_cutoff_smooth_width_2b must be non-negative");
603+
}
604+
};
605+
this->add_item(item);
606+
}
607+
{
608+
Input_Item item("vdw_cutoff_smooth_width_3b");
609+
item.annotation = "smooth cutoff width for three-body dispersion";
610+
item.category = "vdW correction";
611+
item.type = "Real";
612+
item.description = R"(Width of the smooth switching region for the three-body Axilrod-Teller-Muto (ATM) dispersion real-space cutoff.
613+
A value of zero disables smoothing for the three-body contribution.)";
614+
item.default_value = "0.05";
615+
item.unit = "Bohr";
616+
item.availability = "vdw_method is set to d4";
617+
read_sync_double(input.vdw_cutoff_smooth_width_3b);
618+
item.check_value = [](const Input_Item& item, const Parameter& para) {
619+
if (para.input.vdw_cutoff_smooth_width_3b < 0.0)
620+
{
621+
ModuleBase::WARNING_QUIT("ReadInput", "vdw_cutoff_smooth_width_3b must be non-negative");
622+
}
623+
};
624+
this->add_item(item);
625+
}
588626
{
589627
Input_Item item("vdw_cutoff_period");
590628
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)