Skip to content

Commit

Permalink
Constant 4*pi*epsilon can now be set by user
Browse files Browse the repository at this point in the history
  • Loading branch information
philippmisof committed May 11, 2023
1 parent 6daeb0b commit 9f320e1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/nnp-predict/H2O_RPBE-D3_4G/input.nn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ random_seed 12346

ewald_truncation_error_method 1
ewald_prec 1.e-5 0.36
four_pi_epsilon 1.0 # Value of 4*pi*epsilon (1/Coulomb constant)

################################################################################
### NN structure of the short-range NN
Expand Down
1 change: 1 addition & 0 deletions examples/nnp-train/H2O_RPBE-D3_4G/input.nn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ random_seed 12346

ewald_truncation_error_method 1
ewald_prec 1.e-5 0.36
four_pi_epsilon 1.0 # Value of 4*pi*epsilon (1/Coulomb constant)

################################################################################
### NN structure of the short-range NN
Expand Down
13 changes: 7 additions & 6 deletions src/libnnp/Mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Mode::Mode() : nnpType (NNPType::HDNNP_2G),
convEnergy (1.0 ),
convLength (1.0 ),
convCharge (1.0 ),
fourPiEps (1.0 ),
ewaldSetup {}
{
}
Expand Down Expand Up @@ -483,6 +484,12 @@ void Mode::setupElectrostatics(bool initialHardness,
ewaldSetup.getMaxCharge());
log << "\n";

// 4 * pi * epsilon
if (settings.keywordExists("four_pi_epsilon"))
fourPiEps = atof(settings["four_pi_epsilon"].c_str());
if (normalize)
fourPiEps *= pow(convCharge, 2) / (convLength * convEnergy);

// Screening function.
if (settings.keywordExists("screen_electrostatics"))
{
Expand Down Expand Up @@ -1753,12 +1760,6 @@ void Mode::chargeEquilibration( Structure& structure,
VectorXd hardness(numElements);
MatrixXd gammaSqrt2(numElements, numElements);
VectorXd sigmaSqrtPi(numElements);
// In case of natural units and no normalization
double fourPiEps = 1;
// In case of natural units but with normalization. Other units currently
// not supported.
if (normalize)
fourPiEps = pow(convCharge, 2) / (convLength * convEnergy);

for (size_t i = 0; i < numElements; ++i)
{
Expand Down
1 change: 1 addition & 0 deletions src/libnnp/Mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ class Mode
double convEnergy;
double convLength;
double convCharge;
double fourPiEps;
EwaldSetup ewaldSetup;
settings::Settings settings;
SymFnc::ScalingType scalingType;
Expand Down
1 change: 1 addition & 0 deletions src/libnnp/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ map<string, shared_ptr<settings::Key>> const createKnownKeywordsMap()
m["ewald_truncation_error_method" ] = "";
m["ewald_prec" ] = "";
m["screen_electrostatics" ] = "";
m["four_pi_epsilon" ] = "";

// Training keywords.
m["random_seed" ] = "";
Expand Down
2 changes: 1 addition & 1 deletion src/libnnp/Structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ double Structure::calculateElectrostaticEnergy(
}

double Structure::calculateScreeningEnergy(
Eigen::MatrixXd gammaSqrt2,
MatrixXd gammaSqrt2,
VectorXd sigmaSqrtPi,
ScreeningFunction const& fs,
double const fourPiEps)
Expand Down

0 comments on commit 9f320e1

Please sign in to comment.