Skip to content

Commit 49bf6c9

Browse files
author
Roberto Di Remigio
committed
Add executable to test the cavity read from Maharavo's files
1 parent d6167f4 commit 49bf6c9

File tree

4 files changed

+138
-6
lines changed

4 files changed

+138
-6
lines changed

src/bin/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ target_link_libraries(profile_pwc.x solver green bi_operators cavity wemFiles we
99

1010
add_executable(profile_pwl.x profile_pwl.cpp)
1111
target_link_libraries(profile_pwl.x solver green bi_operators cavity wemFiles wemSolvers wavcav utils ${ZLIB_LIBRARY})
12+
13+
include(TestingMacros) # imports add_reference
14+
15+
add_executable(benzene_wavelet.x benzene_wavelet.cpp)
16+
target_link_libraries(benzene_wavelet.x solver green bi_operators cavity wemFiles wemSolvers wavcav utils ${ZLIB_LIBRARY})
17+
add_reference(${CMAKE_SOURCE_DIR}/examples/benzene2.dat ${CMAKE_CURRENT_BINARY_DIR})

src/bin/benzene_wavelet.cpp

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/* pcmsolver_copyright_start */
2+
/*
3+
* PCMSolver, an API for the Polarizable Continuum Model
4+
* Copyright (C) 2013 Roberto Di Remigio, Luca Frediani and contributors
5+
*
6+
* This file is part of PCMSolver.
7+
*
8+
* PCMSolver is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* PCMSolver is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
20+
*
21+
* For information on the complete list of contributors to the
22+
* PCMSolver API, see: <http://pcmsolver.github.io/pcmsolver-doc>
23+
*/
24+
/* pcmsolver_copyright_end */
25+
26+
#include <iostream>
27+
#include <iomanip>
28+
#include <fstream>
29+
#include <string>
30+
31+
#include "Config.hpp"
32+
33+
#include <Eigen/Dense>
34+
35+
#include "DerivativeTypes.hpp"
36+
#include "PWCSolver.hpp"
37+
#include "UniformDielectric.hpp"
38+
#include "Vacuum.hpp"
39+
#include "WaveletCavity.hpp"
40+
#include "PhysicalConstants.hpp"
41+
42+
void pwc_C6H6();
43+
44+
int main() {
45+
pwc_C6H6();
46+
}
47+
48+
void pwc_C6H6()
49+
{
50+
// Molecular geometry. These coordinates are in Angstrom!
51+
Eigen::Vector3d C1( 5.274, 1.999, -8.568);
52+
Eigen::Vector3d C2( 6.627, 2.018, -8.209);
53+
Eigen::Vector3d C3( 7.366, 0.829, -8.202);
54+
Eigen::Vector3d C4( 6.752, -0.379, -8.554);
55+
Eigen::Vector3d C5( 5.399, -0.398, -8.912);
56+
Eigen::Vector3d C6( 4.660, 0.791, -8.919);
57+
Eigen::Vector3d H1( 4.704, 2.916, -8.573);
58+
Eigen::Vector3d H2( 7.101, 2.950, -7.938);
59+
Eigen::Vector3d H3( 8.410, 0.844, -7.926);
60+
Eigen::Vector3d H4( 7.322, -1.296, -8.548);
61+
Eigen::Vector3d H5( 4.925, -1.330, -9.183);
62+
Eigen::Vector3d H6( 3.616, 0.776, -9.196);
63+
// Set up cavity, read it from Maharavo's file benzene2.dat
64+
WaveletCavity cavity("benzene2.dat");
65+
cavity.scaleCavity(1./convertBohrToAngstrom);
66+
67+
double permittivity = 78.39;
68+
double Hcharge = 1.0;
69+
double Ccharge = 6.0;
70+
double totalASC = - (6 * Ccharge + 6 * Hcharge) * ( permittivity - 1) / permittivity;
71+
72+
Vacuum<AD_directional> * gfInside = new Vacuum<AD_directional>();
73+
UniformDielectric<AD_directional> * gfOutside = new
74+
UniformDielectric<AD_directional>(permittivity);
75+
int firstKind = 0;
76+
#ifdef DEBUG
77+
FILE* debugFile = fopen("debug.out","w");
78+
fclose(debugFile);
79+
#endif
80+
PWCSolver solver(gfInside, gfOutside, firstKind);
81+
solver.buildSystemMatrix(cavity);
82+
cavity.uploadPoints(solver.getQuadratureLevel(), solver.getT_());
83+
84+
int size = cavity.size();
85+
Eigen::VectorXd fake_mep = Eigen::VectorXd::Zero(size);
86+
for (int i = 0; i < size; ++i) {
87+
Eigen::Vector3d center = cavity.elementCenter(i);
88+
double C1mep = Ccharge/(center - C1/convertBohrToAngstrom).norm();
89+
double C2mep = Ccharge/(center - C2/convertBohrToAngstrom).norm();
90+
double C3mep = Ccharge/(center - C3/convertBohrToAngstrom).norm();
91+
double C4mep = Ccharge/(center - C4/convertBohrToAngstrom).norm();
92+
double C5mep = Ccharge/(center - C5/convertBohrToAngstrom).norm();
93+
double C6mep = Ccharge/(center - C6/convertBohrToAngstrom).norm();
94+
95+
double H1mep = Hcharge/(center - H1/convertBohrToAngstrom).norm();
96+
double H2mep = Hcharge/(center - H2/convertBohrToAngstrom).norm();
97+
double H3mep = Hcharge/(center - H3/convertBohrToAngstrom).norm();
98+
double H4mep = Hcharge/(center - H4/convertBohrToAngstrom).norm();
99+
double H5mep = Hcharge/(center - H5/convertBohrToAngstrom).norm();
100+
double H6mep = Hcharge/(center - H6/convertBohrToAngstrom).norm();
101+
fake_mep(i) = C1mep + C2mep + C3mep + C4mep + C5mep + C6mep +
102+
H1mep + H2mep + H3mep + H4mep + H5mep + H6mep;
103+
}
104+
// The total ASC for a dielectric is -Q*[(epsilon-1)/epsilon]
105+
Eigen::VectorXd fake_asc = Eigen::VectorXd::Zero(size);
106+
solver.compCharge(fake_mep, fake_asc);
107+
double totalFakeASC = fake_asc.sum();
108+
109+
double energy = 0.5 * (fake_mep.dot(fake_asc));
110+
111+
std::ofstream report;
112+
report.open("pwc_C6H6_report.out", std::ios::out);
113+
report << " Piecewise constant wavelet solver, C6H6 molecule " << std::endl;
114+
report << cavity << std::endl;
115+
report << "------------------------------------------------------------" << std::endl;
116+
report << "totalASC = " << std::setprecision(20) << totalASC << std::endl;
117+
report << "totalFakeASC = " << std::setprecision(20) << totalFakeASC << std::endl;
118+
report << "Delta = " << std::setprecision(20) << totalASC - totalFakeASC << std::endl;
119+
report << "Energy = " << std::setprecision(20) << energy << std::endl;
120+
report << "------------------------------------------------------------" << std::endl;
121+
report.close();
122+
}

src/cavity/Cavity.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Cavity
7070
virtual std::ostream & printCavity(std::ostream & os) = 0;
7171
public:
7272
//! Default constructor
73-
Cavity() : nElements_(0), built(false) {}
73+
Cavity() : nElements_(0), built(false), nSpheres_(0) {}
7474
/*! \brief Constructor from spheres
7575
* \param[in] _spheres an STL vector containing the spheres making up the cavity.
7676
*

src/cavity/WaveletCavity.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@
3333

3434
#include <Eigen/Dense>
3535

36-
extern "C"
37-
{
38-
//#include "vector3.h"
39-
}
40-
4136
#include "Vector3.hpp"
4237
#include "Interpolation.hpp"
4338

@@ -60,6 +55,15 @@ class WaveletCavity : public Cavity
6055
{
6156
public:
6257
WaveletCavity() {}
58+
/// CTOR from wavcav text file output
59+
WaveletCavity(const std::string & filename) : Cavity() {
60+
readCavity(filename);
61+
// These values do not make "physical" sense.
62+
// Reading the cavity from file doesn't provide them so...
63+
probeRadius_ = 0.0;
64+
coarsity_ = 0.0;
65+
patchLevel_ = 0;
66+
}
6367
WaveletCavity(const std::vector<Sphere> & s, double pr, int pl, double c) :
6468
Cavity(s), probeRadius_(pr), patchLevel_(pl), coarsity_(c) {
6569
uploadedDyadic_ = false;

0 commit comments

Comments
 (0)