Skip to content

Commit e444d72

Browse files
committed
Add factoring for the pb solvation
1 parent c702121 commit e444d72

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

src/environment/GPESolver.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -121,24 +121,29 @@ void GPESolver::computeGamma(mrcpp::ComplexFunction &potential, mrcpp::ComplexFu
121121
mrcpp::ComplexFunction GPESolver::solvePoissonEquation(const mrcpp::ComplexFunction &in_gamma, const Density &rho_el) {
122122
mrcpp::ComplexFunction Poisson_func;
123123
mrcpp::ComplexFunction rho_eff;
124-
mrcpp::ComplexFunction first_term;
125124
mrcpp::ComplexFunction Vr_np1;
126125
Vr_np1.alloc(NUMBER::Real);
127126

128-
auto eps_inv_func = mrcpp::AnalyticFunction<3>([this](const mrcpp::Coord<3> &r) { return 1.0 / this->epsilon.evalf(r); });
129127
Density rho_tot(false);
130128
computeDensities(rho_el, rho_tot);
131-
132-
mrcpp::cplxfunc::multiply(first_term, rho_tot, eps_inv_func, this->apply_prec);
133-
134-
mrcpp::cplxfunc::add(rho_eff, 1.0, first_term, -1.0, rho_tot, -1.0);
129+
computeEffectiveDensity(rho_eff, rho_tot);
135130
rho_tot.free(NUMBER::Real);
136131

137132
mrcpp::cplxfunc::add(Poisson_func, 1.0, in_gamma, 1.0, rho_eff, -1.0);
138133
mrcpp::apply(this->apply_prec, Vr_np1.real(), *poisson, Poisson_func.real());
139134
return Vr_np1;
140135
}
141136

137+
void GPESolver::computeEffectiveDensity(mrcpp::ComplexFunction &rho_eff, Density &rho_tot) const {
138+
mrcpp::ComplexFunction rho_eps;
139+
140+
auto eps_inv_func = mrcpp::AnalyticFunction<3>([this](const mrcpp::Coord<3> &r) { return 1.0 / this->epsilon.evalf(r); });
141+
142+
mrcpp::cplxfunc::multiply(rho_eps, rho_tot, eps_inv_func, this->apply_prec);
143+
144+
mrcpp::cplxfunc::add(rho_eff, 1.0, rho_eps, -1.0, rho_tot, -1.0);
145+
}
146+
142147
void GPESolver::accelerateConvergence(mrcpp::ComplexFunction &dfunc, mrcpp::ComplexFunction &func, KAIN &kain) {
143148
OrbitalVector phi_n(0);
144149
OrbitalVector dPhi_n(0);
@@ -190,6 +195,10 @@ void GPESolver::runMicroIterations(const mrcpp::ComplexFunction &V_vac, const De
190195
Vr_np1.free(NUMBER::Real);
191196
mrcpp::cplxfunc::add(Vr_np1, 1.0, Vr_n, 1.0, dVr_n, -1.0);
192197
}
198+
// DEBUG
199+
auto [Er_el, Er_nuc] = computeEnergies(rho_el);
200+
std::cout << "\niter: " << iter << "\nenergy: " << Er_nuc << "\nupdate: " << update << std::endl;
201+
// DEBUG
193202

194203
// set up for next iteration
195204
resetComplexFunction(this->Vr_n);

src/environment/GPESolver.h

+2
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ class GPESolver {
161161
*/
162162
virtual void computeGamma(mrcpp::ComplexFunction &potential, mrcpp::ComplexFunction &out_gamma);
163163

164+
virtual void computeEffectiveDensity(mrcpp::ComplexFunction &rho_eff, Density &rho_tot) const;
165+
164166
/** @brief Iterates once through the Generalized Poisson equation to compute the reaction potential
165167
* @param ingamma the surface charge distribution
166168
* @param Phi the molecular orbitals

src/environment/PBESolver.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,21 @@ void PBESolver::computeGamma(mrcpp::ComplexFunction &potential, mrcpp::ComplexFu
9696
out_gamma.add(-1.0, pb_term);
9797
}
9898

99+
void PBESolver::computeEffectiveDensity(mrcpp::ComplexFunction &rho_eff, Density &rho_tot) const {
100+
mrcpp::ComplexFunction rho_eps;
101+
102+
auto eps_inv_func = mrcpp::AnalyticFunction<3>([this](const mrcpp::Coord<3> &r) { return 1.0 / this->epsilon.evalf(r); });
103+
104+
const double k_b = 1.380649e-23;
105+
const double T = 298.15;
106+
const double J2H = 1 / (4.3597447222071e-18);
107+
double factor = 1 / (k_b * T * J2H);
108+
109+
std::cout << "factor: " << factor << std::endl;
110+
111+
mrcpp::cplxfunc::multiply(rho_eps, rho_tot, eps_inv_func, this->apply_prec);
112+
113+
mrcpp::cplxfunc::add(rho_eff, factor, rho_eps, -1.0, rho_tot, -1.0);
114+
}
115+
99116
} // namespace mrchem

src/environment/PBESolver.h

+2
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,7 @@ class PBESolver : public GPESolver {
9090
* @details The PB term is computed as \f$ \kappa^2 \sinh(V_{tot}) \f$ and returned.
9191
*/
9292
virtual void computePBTerm(mrcpp::ComplexFunction &V_tot, const double salt_factor, mrcpp::ComplexFunction &pb_term);
93+
94+
void computeEffectiveDensity(mrcpp::ComplexFunction &rho_eff, Density &rho_tot) const override;
9395
};
9496
} // namespace mrchem

tests/solventeffect/PB_solver.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace PB_solver {
5353
*/
5454

5555
TEST_CASE("Poisson Boltzmann equation solver standard", "[PB_solver][pb_standard]") {
56-
const double prec = 1.0e-3;
56+
const double prec = 1.0e-5;
5757
const double thrs = 1.0e-4;
5858

5959
auto dyn_thrs = false;
@@ -62,7 +62,7 @@ TEST_CASE("Poisson Boltzmann equation solver standard", "[PB_solver][pb_standard
6262
auto eps_in = 1.0;
6363
auto eps_out = 78.54;
6464
auto kappa_out = 0.054995;
65-
auto slope = 0.1;
65+
auto slope = 0.2;
6666

6767
auto R = std::vector<double>({3.7794522509156563});
6868
auto sph_coords = std::vector<mrcpp::Coord<3>>({{0.0, 0.0, 0.0}});
@@ -103,12 +103,13 @@ TEST_CASE("Poisson Boltzmann equation solver standard", "[PB_solver][pb_standard
103103

104104
auto [Er_el, Er_nuc] = Reo->getSolver()->computeEnergies(rho_el);
105105
Reo->clear();
106+
std::cout << "Er_nuc: " << Er_nuc << std::endl;
106107
REQUIRE((Er_nuc) == Approx(-1.329978908155e-01).epsilon(thrs)); // exact is -0.1373074208 Hartree, though ours is close, i think we are a bit too far away, some parameterization issue
107108
}
108109
}
109110

110111
TEST_CASE("Poisson Boltzmann equation solver linearized", "[PB_solver][pb_linearized]") {
111-
const double prec = 1.0e-3;
112+
const double prec = 1.0e-5;
112113
const double thrs = 1.0e-4;
113114

114115
auto dyn_thrs = false;
@@ -117,7 +118,7 @@ TEST_CASE("Poisson Boltzmann equation solver linearized", "[PB_solver][pb_linear
117118
auto eps_in = 1.0;
118119
auto eps_out = 78.54;
119120
auto kappa_out = 0.054995;
120-
auto slope = 0.1;
121+
auto slope = 0.2;
121122

122123
auto R = std::vector<double>({3.7794522509156563});
123124
auto sph_coords = std::vector<mrcpp::Coord<3>>({{0.0, 0.0, 0.0}});
@@ -160,7 +161,10 @@ TEST_CASE("Poisson Boltzmann equation solver linearized", "[PB_solver][pb_linear
160161

161162
auto [Er_el, Er_nuc] = Reo->getSolver()->computeEnergies(rho_el);
162163
Reo->clear();
164+
std::cout << "Er_nuc: " << Er_nuc << std::endl;
163165
REQUIRE(Er_nuc == Approx(-1.329978908155e-01).epsilon(thrs)); // what we get in standard GPESolver is -1.455145361712e-01, while with PB we get -1.329978908155e-01
166+
// Er_nuc: -1.585665435733e-01
167+
// 50: Er_nuc: -1.585671452611e-01
164168
}
165169
}
166170

0 commit comments

Comments
 (0)