Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
8269a870
Commit
8269a870
authored
Jun 24, 2020
by
Charlles Abreu
Browse files
Real number comparison tolerance in periodic spline filters
parent
b3176be4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
7 deletions
+8
-7
openmmapi/src/SplineFitter.cpp
openmmapi/src/SplineFitter.cpp
+3
-1
openmmapi/src/TabulatedFunction.cpp
openmmapi/src/TabulatedFunction.cpp
+5
-6
No files found.
openmmapi/src/SplineFitter.cpp
View file @
8269a870
...
@@ -37,6 +37,8 @@
...
@@ -37,6 +37,8 @@
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
#define not_equal(a, b) (abs((a)-(b)) > 1e-15 + 1e-15*abs(b)) // same as scipy.interpolate()
void
SplineFitter
::
createSpline
(
const
vector
<
double
>&
x
,
const
vector
<
double
>&
y
,
bool
periodic
,
vector
<
double
>&
deriv
)
{
void
SplineFitter
::
createSpline
(
const
vector
<
double
>&
x
,
const
vector
<
double
>&
y
,
bool
periodic
,
vector
<
double
>&
deriv
)
{
if
(
periodic
)
if
(
periodic
)
SplineFitter
::
createPeriodicSpline
(
x
,
y
,
deriv
);
SplineFitter
::
createPeriodicSpline
(
x
,
y
,
deriv
);
...
@@ -87,7 +89,7 @@ void SplineFitter::createPeriodicSpline(const vector<double>& x, const vector<do
...
@@ -87,7 +89,7 @@ void SplineFitter::createPeriodicSpline(const vector<double>& x, const vector<do
throw
OpenMMException
(
"createPeriodicSpline: x and y vectors must have same length"
);
throw
OpenMMException
(
"createPeriodicSpline: x and y vectors must have same length"
);
if
(
n
<
3
)
if
(
n
<
3
)
throw
OpenMMException
(
"createPeriodicSpline: the length of the input array must be at least 3"
);
throw
OpenMMException
(
"createPeriodicSpline: the length of the input array must be at least 3"
);
if
(
y
[
0
]
!=
y
[
n
-
1
])
if
(
not_equal
(
y
[
0
]
,
y
[
n
-
1
])
)
throw
OpenMMException
(
"createPeriodicSpline: the first and last points must have the same value"
);
throw
OpenMMException
(
"createPeriodicSpline: the first and last points must have the same value"
);
deriv
.
resize
(
n
);
deriv
.
resize
(
n
);
...
...
openmmapi/src/TabulatedFunction.cpp
View file @
8269a870
...
@@ -57,8 +57,9 @@ void Continuous1DFunction::setFunctionParameters(const vector<double>& values, d
...
@@ -57,8 +57,9 @@ void Continuous1DFunction::setFunctionParameters(const vector<double>& values, d
if
(
periodic
)
{
if
(
periodic
)
{
if
(
n
<
3
)
if
(
n
<
3
)
throw
OpenMMException
(
"Continuous1DFunction: a periodic tabulated function must have at least three points"
);
throw
OpenMMException
(
"Continuous1DFunction: a periodic tabulated function must have at least three points"
);
if
(
values
[
0
]
!=
values
[
n
-
1
])
// Note: value-matching at boundary is eventually checked at spline creation.
throw
OpenMMException
(
"Continuous1DFunction: with periodic=true, the first and last points must have the same value"
);
// if (values[0] != values[n-1])
// throw OpenMMException("Continuous1DFunction: with periodic=true, the first and last points must have the same value");
}
}
else
if
(
n
<
2
)
else
if
(
n
<
2
)
throw
OpenMMException
(
"Continuous1DFunction: a non-periodic tabulated function must have at least two points"
);
throw
OpenMMException
(
"Continuous1DFunction: a non-periodic tabulated function must have at least two points"
);
...
@@ -93,8 +94,7 @@ void Continuous2DFunction::setFunctionParameters(int xsize, int ysize, const vec
...
@@ -93,8 +94,7 @@ void Continuous2DFunction::setFunctionParameters(int xsize, int ysize, const vec
if
(
periodic
)
{
if
(
periodic
)
{
if
(
xsize
<
3
||
ysize
<
3
)
if
(
xsize
<
3
||
ysize
<
3
)
throw
OpenMMException
(
"Continuous2DFunction: must have at least three points along each axis if periodic"
);
throw
OpenMMException
(
"Continuous2DFunction: must have at least three points along each axis if periodic"
);
// Note: value-matching at boundary is eventually checked at 2D-spline creation.
// Note: value-matching at boundary is eventually checked at 2D-spline creation time.
}
}
else
if
(
xsize
<
2
||
ysize
<
2
)
else
if
(
xsize
<
2
||
ysize
<
2
)
throw
OpenMMException
(
"Continuous2DFunction: must have at least two points along each axis"
);
throw
OpenMMException
(
"Continuous2DFunction: must have at least two points along each axis"
);
...
@@ -142,8 +142,7 @@ void Continuous3DFunction::setFunctionParameters(int xsize, int ysize, int zsize
...
@@ -142,8 +142,7 @@ void Continuous3DFunction::setFunctionParameters(int xsize, int ysize, int zsize
if
(
periodic
)
{
if
(
periodic
)
{
if
(
xsize
<
3
||
ysize
<
3
||
zsize
<
3
)
if
(
xsize
<
3
||
ysize
<
3
||
zsize
<
3
)
throw
OpenMMException
(
"Continuous3DFunction: must have at least three points along each axis if periodic"
);
throw
OpenMMException
(
"Continuous3DFunction: must have at least three points along each axis if periodic"
);
// Note: value-matching at boundary is eventually checked at 3D-spline creation.
// Note: value-matching at boundary is eventually checked at 3D-spline creation time.
}
}
else
if
(
xsize
<
2
||
ysize
<
2
||
zsize
<
2
)
else
if
(
xsize
<
2
||
ysize
<
2
||
zsize
<
2
)
throw
OpenMMException
(
"Continuous3DFunction: must have at least two points along each axis"
);
throw
OpenMMException
(
"Continuous3DFunction: must have at least two points along each axis"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment