Skip to content

Commit 29f8b5d

Browse files
author
Roberto Di Remigio
committed
Modify way lenght conversions are handled.
This is an ugly development (since we have to rely on a global object) We should rather rely on Boost.Units, which has the advantage of performing compile-time dimensional analysis
1 parent 5f8ff6a commit 29f8b5d

40 files changed

+325
-297
lines changed

cmake/custom/autogenerated.cmake

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Configure the header with library-wide preprocessor definitions
22
configure_file(${PROJECT_SOURCE_DIR}/include/Config.hpp.in
33
${PROJECT_BINARY_DIR}/include/tmp-config-hpp @ONLY)
4-
#file(STRINGS ${PROJECT_BINARY_DIR}/include/tmp-config-hpp _contents NEWLINE_CONSUME)
54
add_custom_command(
65
OUTPUT
76
${PROJECT_BINARY_DIR}/include/Config.hpp
@@ -10,7 +9,7 @@ add_custom_command(
109
VERBATIM
1110
)
1211
set_source_files_properties(${PROJECT_BINARY_DIR}/include/Config.hpp PROPERTIES GENERATED TRUE)
13-
add_custom_target(generate-config-hpp DEPENDS ${PROJECT_BINARY_DIR}/include/Config.hpp)
12+
add_custom_target(generate-config-hpp ALL DEPENDS ${PROJECT_BINARY_DIR}/include/Config.hpp)
1413
if(BUILD_CUSTOM_BOOST)
1514
add_dependencies(generate-config-hpp custom_boost)
1615
endif()

include/Config.hpp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "Cxx11Workarounds.hpp"
4747
#include "ErrorHandling.hpp"
4848
#include "LoggerInterface.hpp"
49+
#include "PhysicalConstants.hpp"
4950
#include "TimerInterface.hpp"
5051

5152
#endif // CONFIG_HPP

include/PhysicalConstants.hpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* pcmsolver_copyright_start */
2+
/*
3+
* PCMSolver, an API for the Polarizable Continuum Model
4+
* Copyright (C) 2013-2015 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.readthedocs.org/>
23+
*/
24+
/* pcmsolver_copyright_end */
25+
26+
#ifndef PHYSICALCONSTANTS_HPP
27+
#define PHYSICALCONSTANTS_HPP
28+
29+
#include <cmath>
30+
31+
/*! \file PhysicalConstants.hpp
32+
* \brief This header file contains physical constants to be used throughout the module.
33+
* \author Roberto Di Remigio
34+
* \date 2013
35+
*/
36+
37+
struct LengthConversion
38+
{
39+
double operator()() { return BOHR_TO_ANGSTROM; }
40+
double BOHR_TO_ANGSTROM;
41+
};
42+
43+
extern LengthConversion bohrToAngstrom;
44+
45+
void initBohrToAngstrom(LengthConversion & conversion, int year = 2010);
46+
47+
double angstromToBohr();
48+
49+
double bohr2ToAngstrom2();
50+
51+
double angstrom2ToBohr2();
52+
53+
double bohr3ToAngstrom3();
54+
55+
double angstrom3ToBohr3();
56+
57+
#endif // PHYSICALCONSTANTS_HPP

src/bin/plot_green_spherical.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "DerivativeTypes.hpp"
3636
#include "GeneralPurpose.hpp"
3737
#include "OneLayerTanh.hpp"
38-
#include "PhysicalConstants.hpp"
3938
#include "SphericalDiffuse.hpp"
4039
#include "UniformDielectric.hpp"
4140

src/bin/run_pcm.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
#include "utils/Atom.hpp"
5252
#include "Citation.hpp"
5353
#include "utils/cnpy.hpp"
54-
#include "utils/PhysicalConstants.hpp"
5554
#include "utils/Solvent.hpp"
5655
#include "utils/Sphere.hpp"
5756

src/interface/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
list(APPEND headers_list Meddle.hpp Input.hpp)
33

44
# List of sources
5-
list(APPEND sources_list Meddle.cpp Input.cpp)
5+
list(APPEND sources_list Meddle.cpp Input.cpp PhysicalConstants.cpp)
66

77
add_library(interface OBJECT ${sources_list} ${headers_list})
88
set_target_properties(interface PROPERTIES POSITION_INDEPENDENT_CODE 1 INTERPROCEDURAL_OPTIMIZATION 1)

src/interface/Input.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#include "green/GreenData.hpp"
4242
#include "solver/SolverData.hpp"
4343
#include "PCMInput.h"
44-
#include "utils/PhysicalConstants.hpp"
4544
#include "utils/Solvent.hpp"
4645
#include "utils/Sphere.hpp"
4746

@@ -65,6 +64,7 @@ void Input::reader(const std::string & filename)
6564
Getkw input_ = Getkw(filename, false, true);
6665
units_ = input_.getStr("UNITS");
6766
CODATAyear_ = input_.getInt("CODATA");
67+
initBohrToAngstrom(bohrToAngstrom, CODATAyear_);
6868

6969
const Section & mol = input_.getSect("MOLECULE");
7070
if (mol.isDefined()) geometry_ = mol.getDblVec("GEOMETRY");
@@ -149,7 +149,7 @@ void Input::reader(const std::string & filename)
149149
} else {
150150
solvent_ = solvents()[name];
151151
}
152-
probeRadius_ = solvent_.probeRadius * angstromToBohr(CODATAyear_);
152+
probeRadius_ = solvent_.probeRadius * angstromToBohr();
153153
// Specification of the solvent by name means isotropic PCM
154154
// We have to initialize the Green's functions data here, Solvent class
155155
// is an helper class and should not be used in the core classes.
@@ -187,27 +187,29 @@ std::string trim_and_upper(const char * src)
187187
void Input::reader(const PCMInput & host_input)
188188
{
189189
CODATAyear_ = 2010;
190+
std::cout << "Calling initBohrToAngstrom" << std::endl;
191+
initBohrToAngstrom(bohrToAngstrom, CODATAyear_);
190192

191193
type_ = trim_and_upper(host_input.cavity_type);
192-
area_ = host_input.area * angstrom2ToBohr2(CODATAyear_);
194+
area_ = host_input.area * angstrom2ToBohr2();
193195
patchLevel_ = host_input.patch_level;
194-
coarsity_ = host_input.coarsity * angstromToBohr(CODATAyear_);
195-
minDistance_ = host_input.min_distance * angstromToBohr(CODATAyear_);
196+
coarsity_ = host_input.coarsity * angstromToBohr();
197+
minDistance_ = host_input.min_distance * angstromToBohr();
196198
derOrder_ = host_input.der_order;
197199
if (type_ == "RESTART") {
198200
cavFilename_ = trim(host_input.restart_name); // No case conversion here!
199201
}
200202

201203
scaling_ = host_input.scaling;
202204
radiiSet_ = trim_and_upper(host_input.radii_set);
203-
minimalRadius_ = host_input.min_radius * angstromToBohr(CODATAyear_);
205+
minimalRadius_ = host_input.min_radius * angstromToBohr();
204206
mode_ = std::string("IMPLICIT");
205207

206208
std::string name = trim_and_upper(host_input.solvent);
207209
if (name.empty()) {
208210
hasSolvent_ = false;
209211
// Get the probe radius
210-
probeRadius_ = host_input.probe_radius * angstromToBohr(CODATAyear_);
212+
probeRadius_ = host_input.probe_radius * angstromToBohr();
211213
// Get the contents of the Green<inside> section...
212214
// ...and initialize the data members
213215
greenInsideType_ = trim_and_upper(host_input.inside_type);
@@ -223,7 +225,7 @@ void Input::reader(const PCMInput & host_input)
223225
// Just initialize the solvent object in this class
224226
hasSolvent_ = true;
225227
solvent_ = solvents()[name];
226-
probeRadius_ = solvent_.probeRadius* angstromToBohr(CODATAyear_);
228+
probeRadius_ = solvent_.probeRadius* angstromToBohr();
227229
// Specification of the solvent by name means isotropic PCM
228230
// We have to initialize the Green's functions data here, Solvent class
229231
// is an helper class and should not be used in the core classes.
@@ -266,7 +268,7 @@ void Input::initMolecule()
266268
j += 4;
267269
}
268270
// 3. list of atoms and list of spheres
269-
double factor = angstromToBohr(CODATAyear_);
271+
double factor = angstromToBohr();
270272
std::vector<Atom> radiiSet, atoms;
271273
if ( radiiSet_ == "UFF" ) {
272274
radiiSet = initUFF();

src/interface/Meddle.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#include "utils/Atom.hpp"
4646
#include "Citation.hpp"
4747
#include "utils/cnpy.hpp"
48-
#include "utils/PhysicalConstants.hpp"
4948
#include "utils/Solvent.hpp"
5049
#include "utils/Sphere.hpp"
5150

@@ -426,7 +425,7 @@ namespace pcm {
426425
{
427426
bool scaling = inp.scaling();
428427
std::string set = inp.radiiSet();
429-
double factor = angstromToBohr(inp.CODATAyear());
428+
double factor = angstromToBohr();
430429
std::vector<Atom> radiiSet, atoms;
431430
if ( set == "UFF" ) {
432431
radiiSet = initUFF();
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* pcmsolver_copyright_start */
2+
/*
3+
* PCMSolver, an API for the Polarizable Continuum Model
4+
* Copyright (C) 2013-2015 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.readthedocs.org/>
23+
*/
24+
/* pcmsolver_copyright_end */
25+
26+
#include "PhysicalConstants.hpp"
27+
28+
LengthConversion bohrToAngstrom;
29+
30+
void initBohrToAngstrom(LengthConversion & conversion, int year)
31+
{
32+
switch(year) {
33+
case 2010:
34+
/*
35+
* P. J. Mohr, B. N. Taylor, and D. B. Newell, Rev. Mod. Phys. 84(4), 1527-1605 (2012)
36+
*/
37+
conversion.BOHR_TO_ANGSTROM = 0.52917721092;
38+
break;
39+
case 2006:
40+
/*
41+
* P. J. Mohr, B. N. Taylor, and D. B. Newell, Rev. Mod. Phys. 80(2), 633-730 (2008)
42+
*/
43+
conversion.BOHR_TO_ANGSTROM = 0.52917720859;
44+
break;
45+
case 2002:
46+
/* Choose this to match DALTON values for physical constants
47+
* P. J. Mohr and B. N. Taylor, Rev. Mod. Phys. 77(1), 1-107 (2005)
48+
*/
49+
conversion.BOHR_TO_ANGSTROM = 0.5291772108;
50+
break;
51+
case 1998:
52+
/*
53+
* P. J. Mohr and B. N. Taylor, Rev. Mod. Phys. 72(2), 351-495 (2000)
54+
*/
55+
conversion.BOHR_TO_ANGSTROM = 0.5291772083;
56+
break;
57+
default:
58+
/*
59+
* Use latest values by default */
60+
conversion.BOHR_TO_ANGSTROM = 0.52917721092;
61+
break;
62+
}
63+
}
64+
65+
double angstromToBohr()
66+
{
67+
return (1.0 / bohrToAngstrom());
68+
}
69+
70+
double bohr2ToAngstrom2()
71+
{
72+
return std::pow(bohrToAngstrom(), 2);
73+
}
74+
75+
double angstrom2ToBohr2()
76+
{
77+
return (1.0 / bohr2ToAngstrom2());
78+
}
79+
80+
double bohr3ToAngstrom3()
81+
{
82+
return std::pow(bohrToAngstrom(), 3);
83+
}
84+
85+
double angstrom3ToBohr3()
86+
{
87+
return (1.0 / bohr3ToAngstrom3());
88+
}

src/utils/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# List of headers
22
list(APPEND headers_list Atom.hpp Factory.hpp ForId.hpp FortranCUtils.hpp Logger.hpp LoggerImpl.hpp MathUtils.hpp Molecule.hpp
3-
PhysicalConstants.hpp QuadratureRules.hpp Solvent.hpp Sphere.hpp SplineFunction.hpp
4-
Stencils.hpp Symmetry.hpp TestingMolecules.hpp Timer.hpp cnpy.hpp)
3+
QuadratureRules.hpp Solvent.hpp Sphere.hpp SplineFunction.hpp
4+
Stencils.hpp Symmetry.hpp Timer.hpp cnpy.hpp)
55
set_source_files_properties(cnpy.hpp PROPERTIES COMPILE_FLAGS -w)
66

77
# List of sources

0 commit comments

Comments
 (0)