Skip to content

Commit 35a16b5

Browse files
author
Roberto Di Remigio
committed
Fix some inconsistencies and a potential memory leak
1 parent b4ae739 commit 35a16b5

File tree

4 files changed

+57
-47
lines changed

4 files changed

+57
-47
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
### Fixed
1919

20+
- Some inconsistencies in input reading from host and a related memory leak in the radii
21+
initialization.
22+
2023
### Security
2124

2225
## [Version 1.1.5] - 2016-07-19

src/interface/Input.cpp

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void Input::reader(const PCMInput & host_input)
217217
mode_ = std::string("IMPLICIT");
218218

219219
std::string name = trim_and_upper(host_input.solvent);
220-
if (name.empty()) {
220+
if (name.empty() || name == "EXPLICIT") {
221221
hasSolvent_ = false;
222222
// Get the probe radius
223223
probeRadius_ = host_input.probe_radius * angstromToBohr();
@@ -259,6 +259,13 @@ void Input::reader(const PCMInput & host_input)
259259
isDynamic_ = false;
260260

261261
providedBy_ = std::string("host-side");
262+
263+
// Fill the input wrapping structs
264+
insideGreenData_ = greenData(derivativeInsideType_, integratorType_, profileType_, epsilonInside_, integratorScaling_);
265+
outsideStaticGreenData_ = greenData(derivativeOutsideType_,
266+
integratorType_, profileType_, epsilonStaticOutside_, integratorScaling_);
267+
outsideDynamicGreenData_ = greenData(derivativeOutsideType_,
268+
integratorType_, profileType_, epsilonDynamicOutside_, integratorScaling_);
262269
}
263270

264271
void Input::semanticCheck()
@@ -280,9 +287,9 @@ void Input::initMolecule()
280287
j += 4;
281288
}
282289
// 3. list of atoms and list of spheres
283-
double factor = angstromToBohr();
284290
std::vector<Atom> radiiSet;
285291
std::vector<Atom> atoms;
292+
atoms.reserve(nuclei);
286293
if ( radiiSet_ == "UFF" ) {
287294
radiiSet = initUFF();
288295
radiiSetName_ = "UFF";
@@ -296,15 +303,15 @@ void Input::initMolecule()
296303
for (int i = 0; i < charges.size(); ++i) {
297304
int index = int(charges(i)) - 1;
298305
atoms.push_back(radiiSet[index]);
299-
if (scaling_) atoms[index].radiusScaling = 1.2;
306+
if (scaling_) atoms[i].radiusScaling = 1.2;
300307
}
301308
// Based on the creation mode (Implicit or Atoms)
302309
// the spheres list might need postprocessing
303310
if ( mode_ == "IMPLICIT" || mode_ == "ATOMS") {
304311
for (int i = 0; i < charges.size(); ++i) {
305-
int index = int(charges(i)) - 1;
306-
double radius = radiiSet[index].radius * factor;
307-
if (scaling_) radius *= 1.2;
312+
// Convert to Bohr and multiply by scaling factor (alpha)
313+
double radius = atoms[i].radius * angstromToBohr()
314+
* atoms[i].radiusScaling;
308315
spheres_.push_back(Sphere(centers.col(i), radius));
309316
}
310317
if (mode_ == "ATOMS") {
@@ -348,48 +355,45 @@ cavityData Input::cavityParams()
348355
greenData Input::insideGreenParams()
349356
{
350357
if (insideGreenData_.empty) {
351-
int profile = profilePolicy("UNIFORM");
352-
insideGreenData_ = greenData(derivativeInsideType_, integratorType_, profile, epsilonInside_, integratorScaling_);
358+
insideGreenData_ = greenData(derivativeInsideType_, integratorType_, profileType_, epsilonInside_, integratorScaling_);
353359
}
354360
return insideGreenData_;
355361
}
356362

357363
greenData Input::outsideStaticGreenParams()
358364
{
359-
if (outsideStaticGreenData_.empty) {
360-
int profile = profilePolicy("UNIFORM");
361-
outsideStaticGreenData_ = greenData(derivativeOutsideType_,
362-
integratorType_, profile, epsilonStaticOutside_, integratorScaling_);
363-
if (not hasSolvent_) {
364-
outsideStaticGreenData_.howProfile = profileType_;
365-
outsideStaticGreenData_.epsilon1 = epsilonStatic1_;
366-
outsideStaticGreenData_.epsilon2 = epsilonStatic2_;
367-
outsideStaticGreenData_.center = center_;
368-
outsideStaticGreenData_.width = width_;
369-
outsideStaticGreenData_.origin << origin_[0], origin_[1], origin_[2];
370-
outsideStaticGreenData_.maxL = maxL_;
371-
}
365+
if (outsideStaticGreenData_.empty) {
366+
outsideStaticGreenData_ = greenData(derivativeOutsideType_,
367+
integratorType_, profileType_, epsilonStaticOutside_, integratorScaling_);
368+
if (not hasSolvent_) {
369+
outsideStaticGreenData_.howProfile = profileType_;
370+
outsideStaticGreenData_.epsilon1 = epsilonStatic1_;
371+
outsideStaticGreenData_.epsilon2 = epsilonStatic2_;
372+
outsideStaticGreenData_.center = center_;
373+
outsideStaticGreenData_.width = width_;
374+
outsideStaticGreenData_.origin << origin_[0], origin_[1], origin_[2];
375+
outsideStaticGreenData_.maxL = maxL_;
372376
}
373-
return outsideStaticGreenData_;
377+
}
378+
return outsideStaticGreenData_;
374379
}
375380

376381
greenData Input::outsideDynamicGreenParams()
377382
{
378-
if (outsideDynamicGreenData_.empty) {
379-
int profile = profilePolicy("UNIFORM");
380-
outsideDynamicGreenData_ = greenData(derivativeOutsideType_,
381-
integratorType_, profile, epsilonDynamicOutside_, integratorScaling_);
382-
if (not hasSolvent_) {
383-
outsideDynamicGreenData_.howProfile = profileType_;
384-
outsideDynamicGreenData_.epsilon1 = epsilonDynamic1_;
385-
outsideDynamicGreenData_.epsilon2 = epsilonDynamic2_;
386-
outsideDynamicGreenData_.center = center_;
387-
outsideDynamicGreenData_.width = width_;
388-
outsideDynamicGreenData_.origin << origin_[0], origin_[1], origin_[2];
389-
outsideDynamicGreenData_.maxL = maxL_;
390-
}
383+
if (outsideDynamicGreenData_.empty) {
384+
outsideDynamicGreenData_ = greenData(derivativeOutsideType_,
385+
integratorType_, profileType_, epsilonDynamicOutside_, integratorScaling_);
386+
if (not hasSolvent_) {
387+
outsideDynamicGreenData_.howProfile = profileType_;
388+
outsideDynamicGreenData_.epsilon1 = epsilonDynamic1_;
389+
outsideDynamicGreenData_.epsilon2 = epsilonDynamic2_;
390+
outsideDynamicGreenData_.center = center_;
391+
outsideDynamicGreenData_.width = width_;
392+
outsideDynamicGreenData_.origin << origin_[0], origin_[1], origin_[2];
393+
outsideDynamicGreenData_.maxL = maxL_;
391394
}
392-
return outsideDynamicGreenData_;
395+
}
396+
return outsideDynamicGreenData_;
393397
}
394398

395399
solverData Input::solverParams()

src/interface/Meddle.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,6 @@ namespace pcm {
459459
{
460460
bool scaling = inp.scaling();
461461
std::string set = inp.radiiSet();
462-
double factor = angstromToBohr();
463462
std::vector<Atom> radiiSet;
464463
std::vector<Atom> atoms;
465464
if ( set == "UFF" ) {
@@ -470,12 +469,15 @@ namespace pcm {
470469
radiiSet = initAllinger();
471470
}
472471
std::vector<Sphere> spheres;
472+
atoms.reserve(nuclei);
473+
spheres.reserve(nuclei);
473474
for (int i = 0; i < charges.size(); ++i) {
474475
int index = int(charges(i)) - 1;
475476
atoms.push_back(radiiSet[index]);
476-
if (scaling) atoms[index].radiusScaling = 1.2;
477-
double radius = radiiSet[index].radius * factor;
478-
if (scaling) radius *= 1.2;
477+
if (scaling) atoms[i].radiusScaling = 1.2;
478+
// Convert to Bohr and multiply by scaling factor (alpha)
479+
double radius = atoms[i].radius * angstromToBohr()
480+
* atoms[i].radiusScaling;
479481
spheres.push_back(Sphere(centers.col(i), radius));
480482
}
481483
Eigen::VectorXd masses = Eigen::VectorXd::Zero(nuclei);

src/utils/Atom.hpp

Lines changed: 8 additions & 7 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-2016 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.io/>
2323
*/
@@ -57,10 +57,11 @@ struct Atom
5757
/*! Atomic symbol */
5858
std::string symbol;
5959
EIGEN_MAKE_ALIGNED_OPERATOR_NEW /* See http://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html */
60-
Atom() {}
60+
Atom() : charge(0.0), mass(0.0), radius(0.0), radiusScaling(0.0),
61+
position(Eigen::Vector3d::Zero()), element("Dummy"), symbol("Du") {}
6162
Atom(const std::string & elem, const std::string & sym,
6263
double c, double m, double r,
63-
const Eigen::Vector3d & coord, double scal = 1.2)
64+
const Eigen::Vector3d & coord, double scal = 1.0)
6465
: charge(c), mass(m), radius(r), radiusScaling(scal),
6566
position(coord), element(elem), symbol(sym) {}
6667
};

0 commit comments

Comments
 (0)