Skip to content

Commit 0cea5fa

Browse files
author
Roberto Di Remigio
committed
Solvent is now a POD
1 parent bc6640b commit 0cea5fa

File tree

4 files changed

+52
-66
lines changed

4 files changed

+52
-66
lines changed

src/interface/Input.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,12 @@ void Input::reader(const std::string & filename)
144144
} else { // This part must be reviewed!! Some data members are not initialized...
145145
// Just initialize the solvent object in this class
146146
hasSolvent_ = true;
147-
std::map<std::string, Solvent> solvents = Solvent::initSolventMap();
148-
if (solvents.find(name) == solvents.end()) {
147+
if (solvents().find(name) == solvents().end()) {
149148
PCMSOLVER_ERROR("Solvent " + name + " NOT found!");
150149
} else {
151-
solvent_ = solvents[name];
150+
solvent_ = solvents()[name];
152151
}
153-
probeRadius_ = solvent_.probeRadius() * angstromToBohr(CODATAyear_);
152+
probeRadius_ = solvent_.probeRadius * angstromToBohr(CODATAyear_);
154153
// Specification of the solvent by name means isotropic PCM
155154
// We have to initialize the Green's functions data here, Solvent class
156155
// is an helper class and should not be used in the core classes.
@@ -159,8 +158,8 @@ void Input::reader(const std::string & filename)
159158
epsilonInside_ = 1.0;
160159
greenOutsideType_ = "UNIFORMDIELECTRIC";
161160
derivativeOutsideType_ = derivativeTraits("DERIVATIVE");
162-
epsilonStaticOutside_ = solvent_.epsStatic();
163-
epsilonDynamicOutside_ = solvent_.epsDynamic();
161+
epsilonStaticOutside_ = solvent_.epsStatic;
162+
epsilonDynamicOutside_ = solvent_.epsDynamic;
164163
}
165164
integratorType_ = integratorPolicy("COLLOCATION"); // Currently hardcoded!!!
166165

@@ -223,9 +222,8 @@ void Input::reader(const PCMInput & host_input)
223222
} else { // This part must be reviewed!! Some data members are not initialized...
224223
// Just initialize the solvent object in this class
225224
hasSolvent_ = true;
226-
std::map<std::string, Solvent> solvents = Solvent::initSolventMap();
227-
solvent_ = solvents[name];
228-
probeRadius_ = solvent_.probeRadius() * angstromToBohr(CODATAyear_);
225+
solvent_ = solvents()[name];
226+
probeRadius_ = solvent_.probeRadius* angstromToBohr(CODATAyear_);
229227
// Specification of the solvent by name means isotropic PCM
230228
// We have to initialize the Green's functions data here, Solvent class
231229
// is an helper class and should not be used in the core classes.
@@ -234,8 +232,8 @@ void Input::reader(const PCMInput & host_input)
234232
epsilonInside_ = 1.0;
235233
greenOutsideType_ = std::string("UNIFORMDIELECTRIC");
236234
derivativeOutsideType_ = derivativeTraits("DERIVATIVE");
237-
epsilonStaticOutside_ = solvent_.epsStatic();
238-
epsilonDynamicOutside_ = solvent_.epsDynamic();
235+
epsilonStaticOutside_ = solvent_.epsStatic;
236+
epsilonDynamicOutside_ = solvent_.epsDynamic;
239237
}
240238
integratorType_ = integratorPolicy("COLLOCATION"); // Currently hardcoded!!!
241239

src/utils/Solvent.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
/*
33
* PCMSolver, an API for the Polarizable Continuum Model
44
* Copyright (C) 2013-2015 Roberto Di Remigio, Luca Frediani and contributors
5-
*
5+
*
66
* This file is part of PCMSolver.
7-
*
7+
*
88
* PCMSolver is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published by
1010
* the Free Software Foundation, either version 3 of the License, or
1111
* (at your option) any later version.
12-
*
12+
*
1313
* PCMSolver is distributed in the hope that it will be useful,
1414
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
* GNU Lesser General Public License for more details.
17-
*
17+
*
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
20-
*
20+
*
2121
* For information on the complete list of contributors to the
2222
* PCMSolver API, see: <http://pcmsolver.readthedocs.org/>
2323
*/
@@ -32,7 +32,7 @@
3232
#include "Config.hpp"
3333

3434

35-
Solvent::SolventMap & Solvent::initSolventMap()
35+
SolventMap & solvents()
3636
{
3737
static SolventMap availableSolvents;
3838
// ------------------------------------------------------------
@@ -56,16 +56,15 @@ Solvent::SolventMap & Solvent::initSolventMap()
5656
availableSolvents["DIMETHYLSULFOXIDE"] = Solvent("Dimethylsulfoxide", 46.700, 2.179, 2.455);
5757
availableSolvents["WATER"] = Solvent("Water", 78.390, 1.776, 1.385);
5858
availableSolvents["EXPLICIT"] = Solvent("Explicit", 0.0, 0.0, 0.0);
59-
availableSolvents["E"] = Solvent("Explicit", 0.0, 0.0, 0.0); // This is an hack to avoid a glitch in Getkw (RDR 6 May 2015)
6059
// ------------------------------------------------------------
6160
return availableSolvents;
6261
}
6362

64-
std::ostream & Solvent::printSolvent(std::ostream & os)
63+
std::ostream & operator<<(std::ostream & os, Solvent & solvent)
6564
{
66-
os << "Solvent name: " << name_ << std::endl;
67-
os << "Static permittivity = " << epsStatic_ << std::endl;
68-
os << "Optical permittivity = " << epsDynamic_ << std::endl;
69-
os << "Solvent radius = " << probeRadius_;
65+
os << "Solvent name: " << solvent.name << std::endl;
66+
os << "Static permittivity = " << solvent.epsStatic << std::endl;
67+
os << "Optical permittivity = " << solvent.epsDynamic << std::endl;
68+
os << "Solvent radius = " << solvent.probeRadius << " Ang";
7069
return os;
7170
}

src/utils/Solvent.hpp

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
/*
33
* PCMSolver, an API for the Polarizable Continuum Model
44
* Copyright (C) 2013-2015 Roberto Di Remigio, Luca Frediani and contributors
5-
*
5+
*
66
* This file is part of PCMSolver.
7-
*
7+
*
88
* PCMSolver is free software: you can redistribute it and/or modify
99
* it under the terms of the GNU Lesser General Public License as published by
1010
* the Free Software Foundation, either version 3 of the License, or
1111
* (at your option) any later version.
12-
*
12+
*
1313
* PCMSolver is distributed in the hope that it will be useful,
1414
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1515
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1616
* GNU Lesser General Public License for more details.
17-
*
17+
*
1818
* You should have received a copy of the GNU Lesser General Public License
1919
* along with PCMSolver. If not, see <http://www.gnu.org/licenses/>.
20-
*
20+
*
2121
* For information on the complete list of contributors to the
2222
* PCMSolver API, see: <http://pcmsolver.readthedocs.org/>
2323
*/
@@ -33,52 +33,41 @@
3333
#include "Config.hpp"
3434

3535
/*! \file Solvent.hpp
36-
* \class Solvent
37-
* \brief Class describing a solvent.
36+
* \struct Solvent
37+
* \brief POD describing a solvent.
3838
* \author Roberto Di Remigio
39-
* \date 2011
39+
* \date 2011, 2016
4040
*
4141
* A Solvent object contains all the solvent-related experimental data
4242
* needed to set up the Green's functions and the non-electrostatic
4343
* terms calculations.
4444
*/
4545

46-
class Solvent
46+
struct Solvent
4747
{
48-
public:
49-
/*! \brief typedef for the map between solvent name and Solvent object.
50-
*/
51-
typedef std::map<std::string, Solvent> SolventMap;
48+
Solvent() {}
49+
Solvent(const std::string & n, double es, double ed, double r)
50+
: name(n), epsStatic(es), epsDynamic(ed), probeRadius(r) {}
51+
/*! Solvent name */
52+
std::string name;
53+
/*! Static permittivity, in AU*/
54+
double epsStatic;
55+
/*! Optical permittivity, in AU */
56+
double epsDynamic;
57+
/*! Radius of the spherical probe mimicking the solvent, in Angstrom */
58+
double probeRadius;
59+
friend std::ostream & operator<<(std::ostream & os, Solvent & solvent);
60+
};
5261

53-
Solvent() {}
54-
Solvent(const std::string & name, double epsStatic, double epsDynamic,
55-
double radius )
56-
: name_(name), epsStatic_(epsStatic), epsDynamic_(epsDynamic),
57-
probeRadius_(radius) {}
58-
~Solvent() {}
5962

60-
std::string name() const { return name_; }
61-
double epsStatic() const { return epsStatic_; }
62-
double epsDynamic() const { return epsDynamic_; }
63-
// The built-in probe radii are in Angstrom
64-
double probeRadius() const { return probeRadius_; }
65-
void probeRadius(double radius) { probeRadius_ = radius; }
63+
/*! \brief typedef for the map between solvent name and Solvent object. */
64+
typedef std::map<std::string, Solvent> SolventMap;
6665

67-
/*! \brief Returns the map between solvent names and Solvent objects.
68-
*
69-
* This map contains solvent data taken from the DALTON2011 internal
70-
* implementation of the Polarizable Continuum Model.
71-
*/
72-
static SolventMap & initSolventMap();
73-
friend std::ostream & operator<<(std::ostream & os, Solvent & solvent) {
74-
return solvent.printSolvent(os);
75-
}
76-
private:
77-
std::string name_;
78-
double epsStatic_;
79-
double epsDynamic_;
80-
double probeRadius_;
81-
std::ostream & printSolvent(std::ostream & os);
82-
};
66+
/*! \brief Returns the map between solvent names and Solvent objects.
67+
*
68+
* This map contains solvent data taken from the DALTON2011 internal
69+
* implementation of the Polarizable Continuum Model.
70+
*/
71+
SolventMap & solvents();
8372

8473
#endif // SOLVENT_HPP

tests/input/input.cpp.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ SCENARIO("Input reading using GetKw", "[input]")
8989
REQUIRE(atoms[i] == parsedInput.atoms(i));
9090
REQUIRE(radii[i] == Approx(parsedInput.radii(i)));
9191
}
92-
REQUIRE(solvent == parsedInput.solvent().name());
92+
REQUIRE(solvent == parsedInput.solvent().name);
9393
REQUIRE(solverType == parsedInput.solverType());
9494
REQUIRE(correction == Approx(parsedInput.correction()));
9595
REQUIRE(hermitivitize == parsedInput.hermitivitize());
@@ -146,7 +146,7 @@ SCENARIO("Input reading using GetKw", "[input]")
146146
REQUIRE(radiiSet == parsedInput.radiiSet());
147147
REQUIRE(minimalRadius == Approx(parsedInput.cavityParams().minimalRadius));
148148
REQUIRE(mode == parsedInput.mode());
149-
REQUIRE(solvent == parsedInput.solvent().name());
149+
REQUIRE(solvent == parsedInput.solvent().name);
150150
REQUIRE(solverType == parsedInput.solverType());
151151
REQUIRE(equationType == parsedInput.equationType());
152152
REQUIRE(correction == Approx(parsedInput.correction()));

0 commit comments

Comments
 (0)