Skip to content

Commit 5a3f77d

Browse files
committed
fix tests for pb solver
1 parent b20a718 commit 5a3f77d

File tree

21 files changed

+12375
-19619
lines changed

21 files changed

+12375
-19619
lines changed

doc/users/user_ref.rst

+6,084-6,083
Large diffs are not rendered by default.

python/mrchem/input_parser/api.py

+17-7,295
Large diffs are not rendered by default.

python/mrchem/input_parser/docs/user_ref.rst

+6,084-6,083
Large diffs are not rendered by default.

src/driver.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ void driver::build_fock_operator(const json &json_fock, Molecule &mol, FockBuild
10701070
dielectric_func.printParameters();
10711071
Density rho_nuc(false);
10721072
rho_nuc = chemistry::compute_nuclear_density(poisson_prec, nuclei, 100);
1073-
std::shared_ptr<GPESolver> scrf_p;
1073+
std::unique_ptr<GPESolver> scrf_p;
10741074
auto solver_type = json_fock["reaction_operator"]["solver_type"];
10751075

10761076
if (solver_type == "Poisson-Boltzmann") {
@@ -1097,7 +1097,7 @@ void driver::build_fock_operator(const json &json_fock, Molecule &mol, FockBuild
10971097
dhscreening.printParameters();
10981098
scrf_p = std::make_unique<LPBESolver>(dielectric_func, dhscreening, rho_nuc, P_p, D_p, kain, max_iter, dynamic_thrs, density_type);
10991099
} else if (solver_type == "Generalized_Poisson") {
1100-
scrf_p = auto scrf_p = std::make_unique<GPESolver>(dielectric_func, rho_nuc, P_p, D_p, kain, max_iter, dynamic_thrs, density_type);
1100+
scrf_p = std::make_unique<GPESolver>(dielectric_func, rho_nuc, P_p, D_p, kain, max_iter, dynamic_thrs, density_type);
11011101
} else {
11021102
MSG_ERROR("Solver type not implemented");
11031103
}

src/environment/GPESolver.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ void GPESolver::runMicroIterations(const mrcpp::ComplexFunction &V_vac, std::sha
195195

196196
// compute new PB term
197197
if (update < this->conv_thrs) break;
198+
iter++;
198199
}
199200

200201
if (iter > max_iter) println(0, "Reaction potential failed to converge after " << iter - 1 << " iterations, residual " << update);
@@ -285,7 +286,7 @@ void GPESolver::printParameters() const {
285286
}
286287

287288
nlohmann::json data = {
288-
{"Method ", "GPE Solver"},
289+
{"Method ", this->solver_name},
289290
{"Density ", this->density_type},
290291
{"Max iterations ", max_iter},
291292
{"KAIN solver ", o_kain.str()},

src/environment/GPESolver.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,12 @@ class GPESolver {
5959

6060
friend class ReactionPotential;
6161
auto computeEnergies(const Density &rho_el) -> std::tuple<double, double>;
62-
void clear();
6362

6463
protected:
6564
void clear();
66-
6765
bool dynamic_thrs;
6866
std::string density_type;
67+
std::string solver_name = "Generalized Poisson";
6968

7069
int max_iter;
7170
int history;
@@ -100,7 +99,7 @@ class GPESolver {
10099

101100
void resetComplexFunction(mrcpp::ComplexFunction &function);
102101

103-
void printParameters() const;
102+
virtual void printParameters() const;
104103
void printConvergenceRow(int i, double norm, double update, double time) const;
105104
};
106105
} // namespace mrchem

src/environment/LPBESolver.cpp

+14-4
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,22 @@ using DerivativeOperator_p = std::shared_ptr<mrcpp::DerivativeOperator<3>>;
4747
using OrbitalVector_p = std::shared_ptr<mrchem::OrbitalVector>;
4848

4949
namespace mrchem {
50-
50+
LPBESolver::LPBESolver(const Permittivity &e,
51+
const DHScreening &k,
52+
const Density &rho_nuc,
53+
std::shared_ptr<mrcpp::PoissonOperator> P,
54+
std::shared_ptr<mrcpp::DerivativeOperator<3>> D,
55+
int kain_hist,
56+
int max_iter,
57+
bool dyn_thrs,
58+
const std::string &density_type)
59+
: PBESolver(e, k, rho_nuc, P, D, kain_hist, max_iter, dyn_thrs, density_type)
60+
, solver_name("Linearized Poisson-Boltzmann") {}
5161
// TODO separate this for the linear and non-linear solver
52-
void computePBTerm(mrcpp::ComplexFunction &V_tot, const double salt_factor, mrcpp::ComplexFunction &pb_term) {
62+
void LPBESolver::computePBTerm(mrcpp::ComplexFunction &V_tot, const double salt_factor, mrcpp::ComplexFunction &pb_term) {
5363
resetComplexFunction(pb_term);
54-
mrcpp::cplxfunc::multiply(pb_term, this->kappa, V_tot, this->apply_prec);
55-
pbe_term.rescale(salt_factor);
64+
mrcpp::cplxfunc::multiply(pb_term, V_tot, this->kappa, this->apply_prec);
65+
pb_term.rescale(salt_factor / (4.0 * mrcpp::pi));
5666
}
5767

5868
} // namespace mrchem

src/environment/LPBESolver.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ class LPBESolver final : public PBESolver {
4747
int kain_hist,
4848
int max_iter,
4949
bool dyn_thrs,
50-
const std::string &density_type)
51-
: PBESolver(e, kappa, N, P, D, orb_prec, kain_hist, max_iter, acc_pot, dyn_thrs, density_type) {}
50+
const std::string &density_type);
5251

5352
friend class ReactionPotential;
5453

5554
protected:
5655
void computePBTerm(mrcpp::ComplexFunction &V_tot, const double salt_factor, mrcpp::ComplexFunction &pb_term) override;
56+
std::string solver_name;
5757
};
5858
} // namespace mrchem

src/environment/PBESolver.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ PBESolver::PBESolver(const Permittivity &e,
5858
bool dyn_thrs,
5959
const std::string &density_type)
6060
: GPESolver(e, rho_nuc, P, D, kain_hist, max_iter, dyn_thrs, density_type)
61-
, kappa(k) {}
61+
, kappa(k)
62+
, solver_name("Poisson-Boltzmann") {}
6263

6364
void PBESolver::computePBTerm(mrcpp::ComplexFunction &V_tot, const double salt_factor, mrcpp::ComplexFunction &pb_term) {
6465
// create a lambda function for the sinh(V) term and multiply it with kappa and salt factor to get the PB term
@@ -68,7 +69,7 @@ void PBESolver::computePBTerm(mrcpp::ComplexFunction &V_tot, const double salt_f
6869
sinhV.alloc(NUMBER::Real);
6970
mrcpp::map(this->apply_prec / 100, sinhV.real(), V_tot.real(), sinh_f);
7071

71-
mrcpp::cplxfunc::multiply(pb_term, this->kappa, sinhV, this->apply_prec);
72+
mrcpp::cplxfunc::multiply(pb_term, sinhV, this->kappa, this->apply_prec);
7273
}
7374

7475
void PBESolver::computeGamma(mrcpp::ComplexFunction &potential, mrcpp::ComplexFunction &out_gamma) {

src/environment/PBESolver.h

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class PBESolver : public GPESolver {
5454
protected:
5555
DHScreening kappa;
5656
mrcpp::ComplexFunction rho_ext;
57+
std::string solver_name;
5758

5859
// FIXME ComputeGamma should not be computing the PB term.
5960
// THe PB term is actually an approximation for an external density, so

src/qmoperators/two_electron/FockBuilder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ SCFEnergy FockBuilder::trace(OrbitalVector &Phi, const Nuclei &nucs) {
173173
Density rho_el(false);
174174
density::compute(this->prec, rho_el, Phi, DensityType::Total);
175175
rho_el.rescale(-1.0);
176-
std::tuple<double, double> Er = this->Ro->getHelper()->computeEnergies(rho_el);
176+
std::tuple<double, double> Er = this->Ro->getSolver()->computeEnergies(rho_el);
177177

178178
Er_el = std::get<0>(Er);
179179
Er_nuc = std::get<1>(Er);

src/qmoperators/two_electron/ReactionOperator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ReactionOperator final : public RankZeroOperator {
5252

5353
ComplexDouble trace(OrbitalVector &Phi) { return RankZeroOperator::trace(Phi); }
5454

55-
SCRF *getSolver() { return this->potential->getSolver(); }
55+
GPESolver *getSolver() { return this->potential->getSolver(); }
5656
std::shared_ptr<ReactionPotential> getPotential() { return this->potential; }
5757
void updateMOResidual(double const err_t) { this->potential->updateMOResidual(err_t); }
5858

src/qmoperators/two_electron/ReactionPotential.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ReactionPotential final : public QMPotential {
4747
ReactionPotential(std::unique_ptr<GPESolver> gpesolver_p, std::shared_ptr<mrchem::OrbitalVector> Phi_p);
4848
~ReactionPotential() override { free(NUMBER::Total); }
4949

50-
SCRF *getSolver() { return this->solver.get(); }
50+
GPESolver *getSolver() { return this->solver.get(); }
5151

5252
/** @brief Updates the solver.mo_residual member variable. This variable is used to set the convergence criterion in
5353
* the dynamic convergence method. */

tests/h_lpb/h.inp

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"SCRF": {
1717
"kain": 6,
1818
"max_iter": 100,
19-
"dynamic_thrs": false,
20-
"optimizer": "potential"
19+
"dynamic_thrs": false
2120
},
2221
"Cavity": {
2322
"spheres": "0 2.645616384 1.0 0.0 0.2"

tests/h_lpb/reference/h.json

+27-28
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
"kain": 6,
109109
"kappa_out": 0.08703231499578493,
110110
"max_iter": 100,
111-
"optimizer": "potential",
112111
"poisson_prec": 0.0001,
113112
"solver_type": "Linearized_Poisson-Boltzmann"
114113
},
@@ -176,7 +175,7 @@
176175
"charge": -1,
177176
"dipole_moment": {
178177
"dip-1": {
179-
"magnitude": 8.17913080064801e-13,
178+
"magnitude": 7.715572311852292e-13,
180179
"r_O": [
181180
0.0,
182181
0.0,
@@ -212,58 +211,58 @@
212211
"multiplicity": 1,
213212
"orbital_energies": {
214213
"energy": [
215-
0.04928658666294078
214+
-0.11654513076836014
216215
],
217216
"occupation": [
218217
2.0
219218
],
220219
"spin": [
221220
"p"
222221
],
223-
"sum_occupied": 0.09857317332588156
222+
"sum_occupied": -0.23309026153672027
224223
},
225224
"scf_energy": {
226-
"E_ee": 1.220280348193974,
225+
"E_ee": 1.220280348193976,
227226
"E_eext": 0.0,
228-
"E_el": -0.618896701038129,
229-
"E_en": -1.9145538948639602,
230-
"E_kin": 0.9258603759485293,
227+
"E_el": -0.7847284165934681,
228+
"E_en": -1.9145538948639653,
229+
"E_kin": 0.9258603759485317,
231230
"E_next": 0.0,
232231
"E_nn": 0.0,
233-
"E_nuc": 0.10754370176892118,
234-
"E_tot": -0.5113529992692079,
235-
"E_x": -0.15252084470528907,
236-
"E_xc": -0.4885331476130991,
237-
"Er_el": -0.20942953799828384,
238-
"Er_nuc": 0.10754370176892118,
239-
"Er_tot": -0.10188583622936287
232+
"E_nuc": 0.19089592768192742,
233+
"E_tot": -0.5938324889115407,
234+
"E_x": -0.15252084470528926,
235+
"E_xc": -0.4885331476131019,
236+
"Er_el": -0.3752612535536192,
237+
"Er_nuc": 0.19089592768192742,
238+
"Er_tot": -0.1843653258716918
240239
}
241240
},
242241
"provenance": {
243242
"creator": "MRChem",
244243
"mpi_processes": 1,
245-
"nthreads": 8,
244+
"nthreads": 1,
246245
"routine": "mrchem.x",
247-
"total_cores": 8,
246+
"total_cores": 1,
248247
"version": "1.2.0-alpha"
249248
},
250249
"rsp_calculations": null,
251250
"scf_calculation": {
252251
"initial_energy": {
253-
"E_ee": 1.220280348193974,
252+
"E_ee": 1.220280348193976,
254253
"E_eext": 0.0,
255-
"E_el": -0.618896701038129,
256-
"E_en": -1.9145538948639602,
257-
"E_kin": 0.9258603759485293,
254+
"E_el": -0.7847284165934681,
255+
"E_en": -1.9145538948639653,
256+
"E_kin": 0.9258603759485317,
258257
"E_next": 0.0,
259258
"E_nn": 0.0,
260-
"E_nuc": 0.10754370176892118,
261-
"E_tot": -0.5113529992692079,
262-
"E_x": -0.15252084470528907,
263-
"E_xc": -0.4885331476130991,
264-
"Er_el": -0.20942953799828384,
265-
"Er_nuc": 0.10754370176892118,
266-
"Er_tot": -0.10188583622936287
259+
"E_nuc": 0.19089592768192742,
260+
"E_tot": -0.5938324889115407,
261+
"E_x": -0.15252084470528926,
262+
"E_xc": -0.4885331476131019,
263+
"Er_el": -0.3752612535536192,
264+
"Er_nuc": 0.19089592768192742,
265+
"Er_tot": -0.1843653258716918
267266
},
268267
"success": true
269268
},

0 commit comments

Comments
 (0)