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
1877eb67
Commit
1877eb67
authored
Jan 11, 2011
by
Mark Friedrichs
Browse files
edit/add AMOEBA serialization proxies
parent
67971bf4
Changes
28
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
304 additions
and
141 deletions
+304
-141
plugins/amoeba/serialization/tests/TestSerializeAmoebaOutOfPlaneBendForce.cpp
...lization/tests/TestSerializeAmoebaOutOfPlaneBendForce.cpp
+22
-18
plugins/amoeba/serialization/tests/TestSerializeAmoebaPiTorsionForce.cpp
...serialization/tests/TestSerializeAmoebaPiTorsionForce.cpp
+10
-10
plugins/amoeba/serialization/tests/TestSerializeAmoebaStretchBendForce.cpp
...rialization/tests/TestSerializeAmoebaStretchBendForce.cpp
+55
-18
plugins/amoeba/serialization/tests/TestSerializeAmoebaTorsionForce.cpp
...a/serialization/tests/TestSerializeAmoebaTorsionForce.cpp
+16
-15
plugins/amoeba/serialization/tests/TestSerializeAmoebaTorsionTorsionForce.cpp
...lization/tests/TestSerializeAmoebaTorsionTorsionForce.cpp
+29
-29
plugins/amoeba/serialization/tests/TestSerializeAmoebaUreyBradleyForce.cpp
...rialization/tests/TestSerializeAmoebaUreyBradleyForce.cpp
+16
-14
plugins/amoeba/serialization/tests/TestSerializeAmoebaVdwForce.cpp
...moeba/serialization/tests/TestSerializeAmoebaVdwForce.cpp
+48
-37
plugins/amoeba/serialization/tests/TestSerializeAmoebaWcaDispersionForce.cpp
...alization/tests/TestSerializeAmoebaWcaDispersionForce.cpp
+108
-0
No files found.
plugins/amoeba/serialization/tests/TestSerializeAmoebaOutOfPlaneBendForce.cpp
View file @
1877eb67
...
@@ -41,34 +41,38 @@ using namespace std;
...
@@ -41,34 +41,38 @@ using namespace std;
void
testSerialization
()
{
void
testSerialization
()
{
// Create a Force.
// Create a Force.
AmoebaOutOfPlaneBendForce
force
;
AmoebaOutOfPlaneBendForce
force1
;
force
.
setAmoebaGlobalOutOfPlaneBendCubic
(
12.3
);
force
.
setAmoebaGlobalOutOfPlaneBendQuartic
(
98.7
);
force1
.
setAmoebaGlobalOutOfPlaneBendCubic
(
12.3
);
force
.
setAmoebaGlobalOutOfPlaneBendPentic
(
91.7
);
force1
.
setAmoebaGlobalOutOfPlaneBendQuartic
(
98.7
);
force
.
setAmoebaGlobalOutOfPlaneBendSextic
(
93.7
);
force1
.
setAmoebaGlobalOutOfPlaneBendPentic
(
91.7
);
force
.
addOutOfPlaneBend
(
0
,
1
,
3
,
4
,
2.0
);
force1
.
setAmoebaGlobalOutOfPlaneBendSextic
(
93.7
);
force
.
addOutOfPlaneBend
(
0
,
2
,
3
,
5
,
2.1
);
force
.
addOutOfPlaneBend
(
2
,
3
,
5
,
6
,
2.2
);
force1
.
addOutOfPlaneBend
(
0
,
1
,
3
,
4
,
2.0
);
force
.
addOutOfPlaneBend
(
5
,
1
,
8
,
8
,
2.3
);
force1
.
addOutOfPlaneBend
(
0
,
2
,
3
,
5
,
2.1
);
force1
.
addOutOfPlaneBend
(
2
,
3
,
5
,
6
,
2.2
);
force1
.
addOutOfPlaneBend
(
5
,
1
,
8
,
8
,
2.3
);
// Serialize and then deserialize it.
// Serialize and then deserialize it.
stringstream
buffer
;
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaOutOfPlaneBendForce
>
(
&
force
,
"Force"
,
buffer
);
XmlSerializer
::
serialize
<
AmoebaOutOfPlaneBendForce
>
(
&
force
1
,
"Force"
,
buffer
);
AmoebaOutOfPlaneBendForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaOutOfPlaneBendForce
>
(
buffer
);
AmoebaOutOfPlaneBendForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaOutOfPlaneBendForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
// Compare the two forces to see if they are identical.
AmoebaOutOfPlaneBendForce
&
force2
=
*
copy
;
AmoebaOutOfPlaneBendForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getAmoebaGlobalOutOfPlaneBendCubic
(),
force2
.
getAmoebaGlobalOutOfPlaneBendCubic
());
ASSERT_EQUAL
(
force
.
getAmoebaGlobalOutOfPlaneBendQuartic
(),
force2
.
getAmoebaGlobalOutOfPlaneBendQuartic
());
ASSERT_EQUAL
(
force1
.
getAmoebaGlobalOutOfPlaneBendCubic
(),
force2
.
getAmoebaGlobalOutOfPlaneBendCubic
());
ASSERT_EQUAL
(
force
.
getAmoebaGlobalOutOfPlaneBendPentic
(),
force2
.
getAmoebaGlobalOutOfPlaneBendPentic
());
ASSERT_EQUAL
(
force1
.
getAmoebaGlobalOutOfPlaneBendQuartic
(),
force2
.
getAmoebaGlobalOutOfPlaneBendQuartic
());
ASSERT_EQUAL
(
force
.
getAmoebaGlobalOutOfPlaneBendSextic
(),
force2
.
getAmoebaGlobalOutOfPlaneBendSextic
());
ASSERT_EQUAL
(
force1
.
getAmoebaGlobalOutOfPlaneBendPentic
(),
force2
.
getAmoebaGlobalOutOfPlaneBendPentic
());
ASSERT_EQUAL
(
force
.
getNumOutOfPlaneBends
(),
force2
.
getNumOutOfPlaneBends
());
ASSERT_EQUAL
(
force1
.
getAmoebaGlobalOutOfPlaneBendSextic
(),
force2
.
getAmoebaGlobalOutOfPlaneBendSextic
());
for
(
int
i
=
0
;
i
<
force
.
getNumOutOfPlaneBends
();
i
++
)
{
ASSERT_EQUAL
(
force1
.
getNumOutOfPlaneBends
(),
force2
.
getNumOutOfPlaneBends
());
for
(
unsigned
int
ii
=
0
;
ii
<
force1
.
getNumOutOfPlaneBends
();
ii
++
)
{
int
a1
,
a2
,
a3
,
a4
,
b1
,
b2
,
b3
,
b4
;
int
a1
,
a2
,
a3
,
a4
,
b1
,
b2
,
b3
,
b4
;
double
ka
,
kb
;
double
ka
,
kb
;
force
.
getOutOfPlaneBendParameters
(
i
,
a1
,
a2
,
a3
,
a4
,
ka
);
force
1
.
getOutOfPlaneBendParameters
(
i
i
,
a1
,
a2
,
a3
,
a4
,
ka
);
force2
.
getOutOfPlaneBendParameters
(
i
,
b1
,
b2
,
b3
,
b4
,
kb
);
force2
.
getOutOfPlaneBendParameters
(
i
i
,
b1
,
b2
,
b3
,
b4
,
kb
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a3
,
b3
);
ASSERT_EQUAL
(
a3
,
b3
);
...
...
plugins/amoeba/serialization/tests/TestSerializeAmoebaPiTorsionForce.cpp
View file @
1877eb67
...
@@ -41,26 +41,26 @@ using namespace std;
...
@@ -41,26 +41,26 @@ using namespace std;
void
testSerialization
()
{
void
testSerialization
()
{
// Create a Force.
// Create a Force.
AmoebaPiTorsionForce
force
;
AmoebaPiTorsionForce
force
1
;
force
.
addPiTorsion
(
0
,
1
,
3
,
4
,
5
,
6
,
2.0
);
force
1
.
addPiTorsion
(
0
,
1
,
3
,
4
,
5
,
6
,
2.0
);
force
.
addPiTorsion
(
0
,
2
,
3
,
5
,
12
,
13
,
2.1
);
force
1
.
addPiTorsion
(
0
,
2
,
3
,
5
,
12
,
13
,
2.1
);
force
.
addPiTorsion
(
2
,
3
,
5
,
6
,
81
,
91
,
2.2
);
force
1
.
addPiTorsion
(
2
,
3
,
5
,
6
,
81
,
91
,
2.2
);
force
.
addPiTorsion
(
5
,
1
,
8
,
8
,
101
,
102
,
2.3
);
force
1
.
addPiTorsion
(
5
,
1
,
8
,
8
,
101
,
102
,
2.3
);
// Serialize and then deserialize it.
// Serialize and then deserialize it.
stringstream
buffer
;
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaPiTorsionForce
>
(
&
force
,
"Force"
,
buffer
);
XmlSerializer
::
serialize
<
AmoebaPiTorsionForce
>
(
&
force
1
,
"Force"
,
buffer
);
AmoebaPiTorsionForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaPiTorsionForce
>
(
buffer
);
AmoebaPiTorsionForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaPiTorsionForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
// Compare the two forces to see if they are identical.
AmoebaPiTorsionForce
&
force2
=
*
copy
;
AmoebaPiTorsionForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getNumPiTorsions
(),
force2
.
getNumPiTorsions
());
ASSERT_EQUAL
(
force
1
.
getNumPiTorsions
(),
force2
.
getNumPiTorsions
());
for
(
int
i
=
0
;
i
<
force
.
getNumPiTorsions
();
i
++
)
{
for
(
unsigned
int
i
i
=
0
;
i
i
<
force
1
.
getNumPiTorsions
();
i
i
++
)
{
int
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
b1
,
b2
,
b3
,
b4
,
b5
,
b6
;
int
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
b1
,
b2
,
b3
,
b4
,
b5
,
b6
;
double
ka
,
kb
;
double
ka
,
kb
;
force
.
getPiTorsionParameters
(
i
,
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
ka
);
force
1
.
getPiTorsionParameters
(
i
i
,
a1
,
a2
,
a3
,
a4
,
a5
,
a6
,
ka
);
force2
.
getPiTorsionParameters
(
i
,
b1
,
b2
,
b3
,
b4
,
b5
,
b6
,
kb
);
force2
.
getPiTorsionParameters
(
i
i
,
b1
,
b2
,
b3
,
b4
,
b5
,
b6
,
kb
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a3
,
b3
);
ASSERT_EQUAL
(
a3
,
b3
);
...
...
plugins/amoeba/serialization/
include/openmm/serializatio
→
plugins/amoeba/serialization/
tests/TestSerializeAmoebaStretchBendForce.cpp
View file @
1877eb67
#ifndef OPENMM_HARMONICBONDFORCE_PROXY_H_
#define OPENMM_HARMONICBONDFORCE_PROXY_H_
/* -------------------------------------------------------------------------- *
/* -------------------------------------------------------------------------- *
*
OpenMM
*
* OpenMM
Amoeba
*
* -------------------------------------------------------------------------- *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Simbios, the NIH National Center for Physics-Based Simulation of *
...
@@ -32,22 +29,62 @@
...
@@ -32,22 +29,62 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
* -------------------------------------------------------------------------- */
#include "openmm/internal/windowsExport.h"
#include "../../../tests/AssertionUtilities.h"
#include "openmm/serialization/SerializationProxy.h"
#include "openmm/AmoebaStretchBendForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
void
testSerialization
()
{
// Create a Force.
AmoebaStretchBendForce
force1
;
force1
.
addStretchBend
(
0
,
1
,
3
,
1.0
,
1.2
,
150.1
,
83.2
);
force1
.
addStretchBend
(
2
,
4
,
4
,
1.1
,
2.2
,
180.1
,
89.2
);
force1
.
addStretchBend
(
5
,
0
,
1
,
3.1
,
8.2
,
140.1
,
98.2
);
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaStretchBendForce
>
(
&
force1
,
"Force"
,
buffer
);
AmoebaStretchBendForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaStretchBendForce
>
(
buffer
);
namespace OpenMM {
// Compare the two forces to see if they are identical.
AmoebaStretchBendForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force1
.
getNumStretchBends
(),
force2
.
getNumStretchBends
());
for
(
unsigned
int
ii
=
0
;
ii
<
force1
.
getNumStretchBends
();
ii
++
)
{
int
p11
,
p12
,
p13
;
int
p21
,
p22
,
p23
;
double
dAB1
,
dAB2
;
double
dCB1
,
dCB2
;
double
angle1
,
angle2
;
double
k1
,
k2
;
/**
force1
.
getStretchBendParameters
(
ii
,
p11
,
p12
,
p13
,
dAB1
,
dCB1
,
angle1
,
k1
);
* This is a proxy for serializing HarmonicBondForce objects.
force2
.
getStretchBendParameters
(
ii
,
p21
,
p22
,
p23
,
dAB2
,
dCB2
,
angle2
,
k2
);
*/
class OPENMM_EXPORT HarmonicBondForceProxy : public SerializationProxy {
ASSERT_EQUAL
(
p11
,
p21
);
public:
ASSERT_EQUAL
(
p12
,
p22
);
HarmonicBondForceProxy();
ASSERT_EQUAL
(
p13
,
p23
);
void serialize(const void* object, SerializationNode& node) const;
ASSERT_EQUAL
(
dAB1
,
dAB2
);
void* deserialize(const SerializationNode& node) const;
ASSERT_EQUAL
(
dCB1
,
dCB2
);
};
ASSERT_EQUAL
(
angle1
,
angle2
);
ASSERT_EQUAL
(
k1
,
k2
);
}
}
} // namespace OpenMM
int
main
()
{
try
{
testSerialization
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
#endif /*OPENMM_HARMONICBONDFORCE_PROXY_H_*/
plugins/amoeba/serialization/tests/TestSerializeAmoebaTorsionForce.cpp
View file @
1877eb67
...
@@ -47,42 +47,43 @@ void loadTorsion( std::vector<double>& torsion, double offset ){
...
@@ -47,42 +47,43 @@ void loadTorsion( std::vector<double>& torsion, double offset ){
void
compareTorsion
(
std
::
vector
<
double
>
torsionA
,
std
::
vector
<
double
>
torsionB
){
void
compareTorsion
(
std
::
vector
<
double
>
torsionA
,
std
::
vector
<
double
>
torsionB
){
ASSERT_EQUAL
(
torsionA
.
size
(),
torsionB
.
size
());
ASSERT_EQUAL
(
torsionA
.
size
(),
torsionB
.
size
());
for
(
int
i
=
0
;
i
<
torsionA
.
size
();
i
++
)
{
for
(
unsigned
int
i
i
=
0
;
i
i
<
torsionA
.
size
();
i
i
++
)
{
ASSERT_EQUAL
(
torsionA
[
i
],
torsionB
[
i
]);
ASSERT_EQUAL
(
torsionA
[
i
i
],
torsionB
[
i
i
]);
}
}
}
}
void
testSerialization
()
{
void
testSerialization
()
{
// Create a Force.
// Create a Force.
AmoebaTorsionForce
force
;
AmoebaTorsionForce
force
1
;
for
(
int
ii
=
0
;
ii
<
5
;
ii
++
){
for
(
unsigned
int
ii
=
0
;
ii
<
5
;
ii
++
){
std
::
vector
<
double
>
torsion1
;
std
::
vector
<
double
>
torsion1
;
std
::
vector
<
double
>
torsion2
;
std
::
vector
<
double
>
torsion2
;
std
::
vector
<
double
>
torsion3
;
std
::
vector
<
double
>
torsion3
;
loadTorsion
(
torsion1
,
static_cast
<
double
>
(
5
*
ii
)
+
11.1
);
loadTorsion
(
torsion1
,
static_cast
<
double
>
(
5
*
ii
)
+
11.1
);
loadTorsion
(
torsion2
,
static_cast
<
double
>
(
5
*
ii
)
+
21.2
);
loadTorsion
(
torsion2
,
static_cast
<
double
>
(
5
*
ii
)
+
21.2
);
loadTorsion
(
torsion3
,
static_cast
<
double
>
(
5
*
ii
)
+
31.3
);
loadTorsion
(
torsion3
,
static_cast
<
double
>
(
5
*
ii
)
+
31.3
);
force
.
addTorsion
(
ii
,
ii
+
1
,
ii
+
3
,
ii
+
4
,
torsion1
,
torsion2
,
torsion3
);
force
1
.
addTorsion
(
ii
,
ii
+
1
,
ii
+
3
,
ii
+
4
,
torsion1
,
torsion2
,
torsion3
);
}
}
// Serialize and then deserialize it.
// Serialize and then deserialize it.
stringstream
buffer
;
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaTorsionForce
>
(
&
force
,
"Force"
,
buffer
);
XmlSerializer
::
serialize
<
AmoebaTorsionForce
>
(
&
force
1
,
"Force"
,
buffer
);
if
(
0
){
if
(
0
){
FILE
*
filePtr
=
fopen
(
"Torsion.xml"
,
"w"
);
FILE
*
filePtr
=
fopen
(
"Torsion.xml"
,
"w"
);
(
void
)
fprintf
(
filePtr
,
"%s"
,
buffer
.
str
().
c_str
()
);
(
void
)
fprintf
(
filePtr
,
"%s"
,
buffer
.
str
().
c_str
()
);
(
void
)
fclose
(
filePtr
);
(
void
)
fclose
(
filePtr
);
}
}
AmoebaTorsionForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaTorsionForce
>
(
buffer
);
AmoebaTorsionForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaTorsionForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
// Compare the two forces to see if they are identical.
AmoebaTorsionForce
&
force2
=
*
copy
;
AmoebaTorsionForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getNumTorsions
(),
force2
.
getNumTorsions
());
ASSERT_EQUAL
(
force
1
.
getNumTorsions
(),
force2
.
getNumTorsions
());
for
(
int
i
=
0
;
i
<
force
.
getNumTorsions
();
i
++
)
{
for
(
unsigned
int
i
i
=
0
;
i
i
<
force
1
.
getNumTorsions
();
i
i
++
)
{
int
a1
,
a2
,
a3
,
a4
,
b1
,
b2
,
b3
,
b4
;
int
a1
,
a2
,
a3
,
a4
,
b1
,
b2
,
b3
,
b4
;
...
@@ -93,8 +94,8 @@ FILE* filePtr = fopen("Torsion.xml", "w" );
...
@@ -93,8 +94,8 @@ FILE* filePtr = fopen("Torsion.xml", "w" );
std
::
vector
<
double
>
torsion2b
;
std
::
vector
<
double
>
torsion2b
;
std
::
vector
<
double
>
torsion3b
;
std
::
vector
<
double
>
torsion3b
;
force
.
getTorsionParameters
(
i
,
a1
,
a2
,
a3
,
a4
,
torsion1a
,
torsion2a
,
torsion3a
);
force
1
.
getTorsionParameters
(
i
i
,
a1
,
a2
,
a3
,
a4
,
torsion1a
,
torsion2a
,
torsion3a
);
force2
.
getTorsionParameters
(
i
,
b1
,
b2
,
b3
,
b4
,
torsion1b
,
torsion2b
,
torsion3b
);
force2
.
getTorsionParameters
(
i
i
,
b1
,
b2
,
b3
,
b4
,
torsion1b
,
torsion2b
,
torsion3b
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a2
,
b2
);
...
...
plugins/amoeba/serialization/tests/TestSerializeAmoebaTorsionTorsionForce.cpp
View file @
1877eb67
...
@@ -43,11 +43,11 @@ static void loadTorsionTorsionGrid( std::vector< std::vector< std::vector<double
...
@@ -43,11 +43,11 @@ static void loadTorsionTorsionGrid( std::vector< std::vector< std::vector<double
static
const
int
gridSize
=
25
;
static
const
int
gridSize
=
25
;
gridVector
.
resize
(
gridSize
);
gridVector
.
resize
(
gridSize
);
for
(
int
ii
=
0
;
ii
<
gridSize
;
ii
++
){
for
(
unsigned
int
ii
=
0
;
ii
<
gridSize
;
ii
++
){
gridVector
[
ii
].
resize
(
gridSize
);
gridVector
[
ii
].
resize
(
gridSize
);
for
(
int
jj
=
0
;
jj
<
gridSize
;
jj
++
){
for
(
unsigned
int
jj
=
0
;
jj
<
gridSize
;
jj
++
){
gridVector
[
ii
][
jj
].
resize
(
6
);
gridVector
[
ii
][
jj
].
resize
(
6
);
for
(
int
kk
=
0
;
kk
<
6
;
kk
++
){
for
(
unsigned
int
kk
=
0
;
kk
<
6
;
kk
++
){
gridVector
[
ii
][
jj
][
0
]
=
-
180.0
+
15.0
*
static_cast
<
double
>
(
ii
);
gridVector
[
ii
][
jj
][
0
]
=
-
180.0
+
15.0
*
static_cast
<
double
>
(
ii
);
gridVector
[
ii
][
jj
][
1
]
=
-
180.0
+
15.0
*
static_cast
<
double
>
(
jj
);
gridVector
[
ii
][
jj
][
1
]
=
-
180.0
+
15.0
*
static_cast
<
double
>
(
jj
);
gridVector
[
ii
][
jj
][
2
]
=
static_cast
<
double
>
(
rand
());
gridVector
[
ii
][
jj
][
2
]
=
static_cast
<
double
>
(
rand
());
...
@@ -62,12 +62,12 @@ static void loadTorsionTorsionGrid( std::vector< std::vector< std::vector<double
...
@@ -62,12 +62,12 @@ static void loadTorsionTorsionGrid( std::vector< std::vector< std::vector<double
static
void
compareGrids
(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
grid1
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
grid2
)
{
static
void
compareGrids
(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
grid1
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
grid2
)
{
ASSERT_EQUAL
(
grid1
.
size
(),
grid2
.
size
());
ASSERT_EQUAL
(
grid1
.
size
(),
grid2
.
size
());
for
(
int
i
=
0
;
i
<
grid1
.
size
();
i
++
)
{
for
(
unsigned
int
i
i
=
0
;
i
i
<
grid1
.
size
();
i
i
++
)
{
ASSERT_EQUAL
(
grid1
[
i
].
size
(),
grid2
[
i
].
size
());
ASSERT_EQUAL
(
grid1
[
i
i
].
size
(),
grid2
[
i
i
].
size
());
for
(
int
jj
=
0
;
jj
<
grid1
[
i
].
size
();
jj
++
)
{
for
(
int
jj
=
0
;
jj
<
grid1
[
i
i
].
size
();
jj
++
)
{
ASSERT_EQUAL
(
grid1
[
i
][
jj
].
size
(),
grid2
[
i
][
jj
].
size
());
ASSERT_EQUAL
(
grid1
[
i
i
][
jj
].
size
(),
grid2
[
i
i
][
jj
].
size
());
for
(
int
kk
=
0
;
kk
<
grid1
[
i
][
jj
].
size
();
kk
++
)
{
for
(
int
kk
=
0
;
kk
<
grid1
[
i
i
][
jj
].
size
();
kk
++
)
{
ASSERT_EQUAL
(
grid1
[
i
][
jj
][
kk
],
grid2
[
i
][
jj
][
kk
]);
ASSERT_EQUAL
(
grid1
[
i
i
][
jj
][
kk
],
grid2
[
i
i
][
jj
][
kk
]);
}
}
}
}
}
}
...
@@ -76,40 +76,40 @@ static void compareGrids( const std::vector< std::vector< std::vector<double> >
...
@@ -76,40 +76,40 @@ static void compareGrids( const std::vector< std::vector< std::vector<double> >
void
testSerialization
()
{
void
testSerialization
()
{
// Create a Force.
// Create a Force.
AmoebaTorsionTorsionForce
force
;
AmoebaTorsionTorsionForce
force
1
;
for
(
int
ii
=
0
;
ii
<
5
;
ii
++
){
for
(
unsigned
int
ii
=
0
;
ii
<
5
;
ii
++
){
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>
gridVector
;
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>
gridVector
;
loadTorsionTorsionGrid
(
gridVector
);
loadTorsionTorsionGrid
(
gridVector
);
force
.
setTorsionTorsionGrid
(
ii
,
gridVector
);
force
1
.
setTorsionTorsionGrid
(
ii
,
gridVector
);
}
}
for
(
int
ii
=
0
;
ii
<
5
;
ii
++
){
for
(
unsigned
int
ii
=
0
;
ii
<
5
;
ii
++
){
force
.
addTorsionTorsion
(
ii
,
ii
+
1
,
ii
+
3
,
ii
+
4
,
ii
+
5
,
(
(
ii
%
2
)
?
1
:
0
),
(
ii
%
4
)
);
force
1
.
addTorsionTorsion
(
ii
,
ii
+
1
,
ii
+
3
,
ii
+
4
,
ii
+
5
,
(
(
ii
%
2
)
?
1
:
0
),
(
ii
%
4
)
);
}
}
// Serialize and then deserialize it.
// Serialize and then deserialize it.
stringstream
buffer
;
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaTorsionTorsionForce
>
(
&
force
,
"Force"
,
buffer
);
XmlSerializer
::
serialize
<
AmoebaTorsionTorsionForce
>
(
&
force
1
,
"Force"
,
buffer
);
if
(
0
){
if
(
0
){
FILE
*
filePtr
=
fopen
(
"TorsionTorsion.xml"
,
"w"
);
FILE
*
filePtr
=
fopen
(
"TorsionTorsion.xml"
,
"w"
);
(
void
)
fprintf
(
filePtr
,
"%s"
,
buffer
.
str
().
c_str
()
);
(
void
)
fprintf
(
filePtr
,
"%s"
,
buffer
.
str
().
c_str
()
);
(
void
)
fclose
(
filePtr
);
(
void
)
fclose
(
filePtr
);
}
}
AmoebaTorsionTorsionForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaTorsionTorsionForce
>
(
buffer
);
AmoebaTorsionTorsionForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaTorsionTorsionForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
// Compare the two force
1
s to see if they are identical.
AmoebaTorsionTorsionForce
&
force2
=
*
copy
;
AmoebaTorsionTorsionForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getNumTorsionTorsions
(),
force2
.
getNumTorsionTorsions
());
ASSERT_EQUAL
(
force
1
.
getNumTorsionTorsions
(),
force2
.
getNumTorsionTorsions
());
for
(
int
i
=
0
;
i
<
force
.
getNumTorsionTorsions
();
i
++
)
{
for
(
unsigned
int
i
i
=
0
;
i
i
<
force
1
.
getNumTorsionTorsions
();
i
i
++
)
{
int
a1
,
a2
,
a3
,
a4
,
a5
,
aChiral
,
aGridIndex
,
b1
,
b2
,
b3
,
b4
,
b5
,
bChiral
,
bGridIndex
;
int
a1
,
a2
,
a3
,
a4
,
a5
,
aChiral
,
aGridIndex
,
b1
,
b2
,
b3
,
b4
,
b5
,
bChiral
,
bGridIndex
;
force
.
getTorsionTorsionParameters
(
i
,
a1
,
a2
,
a3
,
a4
,
a5
,
aChiral
,
aGridIndex
);
force
1
.
getTorsionTorsionParameters
(
i
i
,
a1
,
a2
,
a3
,
a4
,
a5
,
aChiral
,
aGridIndex
);
force2
.
getTorsionTorsionParameters
(
i
,
b1
,
b2
,
b3
,
b4
,
b5
,
bChiral
,
bGridIndex
);
force2
.
getTorsionTorsionParameters
(
i
i
,
b1
,
b2
,
b3
,
b4
,
b5
,
bChiral
,
bGridIndex
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a2
,
b2
);
...
@@ -120,10 +120,10 @@ FILE* filePtr = fopen("TorsionTorsion.xml", "w" );
...
@@ -120,10 +120,10 @@ FILE* filePtr = fopen("TorsionTorsion.xml", "w" );
ASSERT_EQUAL
(
aGridIndex
,
bGridIndex
);
ASSERT_EQUAL
(
aGridIndex
,
bGridIndex
);
}
}
ASSERT_EQUAL
(
force
.
getNumTorsionTorsionGrids
(),
force2
.
getNumTorsionTorsionGrids
());
ASSERT_EQUAL
(
force
1
.
getNumTorsionTorsionGrids
(),
force2
.
getNumTorsionTorsionGrids
());
for
(
int
i
=
0
;
i
<
force
.
getNumTorsionTorsionGrids
();
i
++
)
{
for
(
unsigned
int
i
i
=
0
;
i
i
<
force
1
.
getNumTorsionTorsionGrids
();
i
i
++
)
{
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
grid1
=
force
.
getTorsionTorsionGrid
(
i
);
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
grid1
=
force
1
.
getTorsionTorsionGrid
(
i
i
);
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
grid2
=
force2
.
getTorsionTorsionGrid
(
i
);
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
grid2
=
force2
.
getTorsionTorsionGrid
(
i
i
);
compareGrids
(
grid1
,
grid2
);
compareGrids
(
grid1
,
grid2
);
}
}
...
...
plugins/amoeba/serialization/tests/TestSerializeAmoebaUreyBradleyForce.cpp
View file @
1877eb67
...
@@ -41,30 +41,32 @@ using namespace std;
...
@@ -41,30 +41,32 @@ using namespace std;
void
testSerialization
()
{
void
testSerialization
()
{
// Create a Force.
// Create a Force.
AmoebaUreyBradleyForce
force
;
AmoebaUreyBradleyForce
force
1
;
force
.
setAmoebaGlobalUreyBradleyCubic
(
12.3
);
force
1
.
setAmoebaGlobalUreyBradleyCubic
(
12.3
);
force
.
setAmoebaGlobalUreyBradleyQuartic
(
98.7
);
force
1
.
setAmoebaGlobalUreyBradleyQuartic
(
98.7
);
force
.
addUreyBradley
(
0
,
1
,
1.0
,
2.0
);
force
1
.
addUreyBradley
(
0
,
1
,
1.0
,
2.0
);
force
.
addUreyBradley
(
0
,
2
,
2.0
,
2.1
);
force
1
.
addUreyBradley
(
0
,
2
,
2.0
,
2.1
);
force
.
addUreyBradley
(
2
,
3
,
3.0
,
2.2
);
force
1
.
addUreyBradley
(
2
,
3
,
3.0
,
2.2
);
force
.
addUreyBradley
(
5
,
1
,
4.0
,
2.3
);
force
1
.
addUreyBradley
(
5
,
1
,
4.0
,
2.3
);
// Serialize and then deserialize it.
// Serialize and then deserialize it.
stringstream
buffer
;
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaUreyBradleyForce
>
(
&
force
,
"Force"
,
buffer
);
XmlSerializer
::
serialize
<
AmoebaUreyBradleyForce
>
(
&
force
1
,
"Force"
,
buffer
);
AmoebaUreyBradleyForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaUreyBradleyForce
>
(
buffer
);
AmoebaUreyBradleyForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaUreyBradleyForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
// Compare the two forces to see if they are identical.
AmoebaUreyBradleyForce
&
force2
=
*
copy
;
AmoebaUreyBradleyForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getAmoebaGlobalUreyBradleyCubic
(),
force2
.
getAmoebaGlobalUreyBradleyCubic
());
ASSERT_EQUAL
(
force
1
.
getAmoebaGlobalUreyBradleyCubic
(),
force2
.
getAmoebaGlobalUreyBradleyCubic
());
ASSERT_EQUAL
(
force
.
getAmoebaGlobalUreyBradleyQuartic
(),
force2
.
getAmoebaGlobalUreyBradleyQuartic
());
ASSERT_EQUAL
(
force
1
.
getAmoebaGlobalUreyBradleyQuartic
(),
force2
.
getAmoebaGlobalUreyBradleyQuartic
());
ASSERT_EQUAL
(
force
.
getNumInteractions
(),
force2
.
getNumInteractions
());
ASSERT_EQUAL
(
force
1
.
getNumInteractions
(),
force2
.
getNumInteractions
());
for
(
int
i
=
0
;
i
<
force
.
getNumInteractions
();
i
++
)
{
for
(
unsigned
int
i
i
=
0
;
i
i
<
force
1
.
getNumInteractions
();
i
i
++
)
{
int
a1
,
a2
,
b1
,
b2
;
int
a1
,
a2
,
b1
,
b2
;
double
da
,
db
,
ka
,
kb
;
double
da
,
db
,
ka
,
kb
;
force
.
getUreyBradleyParameters
(
i
,
a1
,
a2
,
da
,
ka
);
force2
.
getUreyBradleyParameters
(
i
,
b1
,
b2
,
db
,
kb
);
force1
.
getUreyBradleyParameters
(
ii
,
a1
,
a2
,
da
,
ka
);
force2
.
getUreyBradleyParameters
(
ii
,
b1
,
b2
,
db
,
kb
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
da
,
db
);
ASSERT_EQUAL
(
da
,
db
);
...
...
plugins/amoeba/serialization/tests/TestSerializeAmoebaVdwForce.cpp
View file @
1877eb67
...
@@ -41,67 +41,78 @@ using namespace std;
...
@@ -41,67 +41,78 @@ using namespace std;
void
testSerialization
()
{
void
testSerialization
()
{
// Create a Force.
// Create a Force.
AmoebaVdwForce
force
;
AmoebaVdwForce
force
1
;
force
.
setSigmaCombiningRule
(
"GEOMETRIC"
);
force
1
.
setSigmaCombiningRule
(
"GEOMETRIC"
);
force
.
setEpsilonCombiningRule
(
"GEOMETRIC"
);
force
1
.
setEpsilonCombiningRule
(
"GEOMETRIC"
);
force
.
setCutoff
(
0.9
);
force
1
.
setCutoff
(
0.9
);
force
.
setUseNeighborList
(
1
);
force
1
.
setUseNeighborList
(
1
);
force
.
setPBC
(
1
);
force
1
.
setPBC
(
1
);
force
.
addParticle
(
0
,
1
,
1.0
,
2.0
,
0.9
);
force
1
.
addParticle
(
0
,
1
,
1.0
,
2.0
,
0.9
);
force
.
addParticle
(
1
,
0
,
1.1
,
2.1
,
0.9
);
force
1
.
addParticle
(
1
,
0
,
1.1
,
2.1
,
0.9
);
force
.
addParticle
(
2
,
3
,
1.3
,
4.1
,
0.9
);
force
1
.
addParticle
(
2
,
3
,
1.3
,
4.1
,
0.9
);
for
(
unsigned
int
ii
=
0
;
ii
<
3
;
ii
++
){
for
(
unsigned
int
ii
=
0
;
ii
<
3
;
ii
++
){
std
::
vector
<
int
>
exclusions
;
std
::
vector
<
int
>
exclusions
;
exclusions
.
push_back
(
ii
);
exclusions
.
push_back
(
ii
);
exclusions
.
push_back
(
ii
+
1
);
exclusions
.
push_back
(
ii
+
1
);
exclusions
.
push_back
(
ii
+
10
);
exclusions
.
push_back
(
ii
+
10
);
force
.
setParticleExclusions
(
ii
,
exclusions
);
force
1
.
setParticleExclusions
(
ii
,
exclusions
);
}
}
// Serialize and then deserialize it.
// Serialize and then deserialize it.
stringstream
buffer
;
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaVdwForce
>
(
&
force
,
"Force"
,
buffer
);
XmlSerializer
::
serialize
<
AmoebaVdwForce
>
(
&
force1
,
"Force"
,
buffer
);
if
(
1
){
FILE
*
filePtr
=
fopen
(
"Vdw.xml"
,
"w"
);
if
(
0
){
(
void
)
fprintf
(
filePtr
,
"%s"
,
buffer
.
str
().
c_str
()
);
FILE
*
filePtr
=
fopen
(
"Vdw.xml"
,
"w"
);
(
void
)
fclose
(
filePtr
);
(
void
)
fprintf
(
filePtr
,
"%s"
,
buffer
.
str
().
c_str
()
);
}
(
void
)
fclose
(
filePtr
);
}
AmoebaVdwForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaVdwForce
>
(
buffer
);
AmoebaVdwForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaVdwForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
// Compare the two forces to see if they are identical.
AmoebaVdwForce
&
force2
=
*
copy
;
AmoebaVdwForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getSigmaCombiningRule
(),
force2
.
getSigmaCombiningRule
());
ASSERT_EQUAL
(
force
.
getEpsilonCombiningRule
(),
force2
.
getEpsilonCombiningRule
());
ASSERT_EQUAL
(
force1
.
getSigmaCombiningRule
(),
force2
.
getSigmaCombiningRule
());
ASSERT_EQUAL
(
force
.
getCutoff
(),
force2
.
getCutoff
());
ASSERT_EQUAL
(
force1
.
getEpsilonCombiningRule
(),
force2
.
getEpsilonCombiningRule
());
ASSERT_EQUAL
(
force
.
getUseNeighborList
(),
force2
.
getUseNeighborList
());
ASSERT_EQUAL
(
force1
.
getCutoff
(),
force2
.
getCutoff
());
ASSERT_EQUAL
(
force
.
getPBC
(),
force2
.
getPBC
());
ASSERT_EQUAL
(
force1
.
getUseNeighborList
(),
force2
.
getUseNeighborList
());
ASSERT_EQUAL
(
force
.
getNumParticles
(),
force2
.
getNumParticles
());
ASSERT_EQUAL
(
force1
.
getPBC
(),
force2
.
getPBC
());
for
(
int
i
=
0
;
i
<
force
.
getNumParticles
();
i
++
)
{
ASSERT_EQUAL
(
force1
.
getNumParticles
(),
force2
.
getNumParticles
());
for
(
unsigned
int
ii
=
0
;
ii
<
force1
.
getNumParticles
();
ii
++
)
{
int
ivIndex1
,
classIndex1
;
int
ivIndex1
,
classIndex1
;
int
ivIndex2
,
classIndex2
;
int
ivIndex2
,
classIndex2
;
double
sigma1
,
epsilon1
,
reductionFactor1
;
double
sigma1
,
epsilon1
,
reductionFactor1
;
double
sigma2
,
epsilon2
,
reductionFactor2
;
double
sigma2
,
epsilon2
,
reductionFactor2
;
force
.
getParticleParameters
(
i
,
ivIndex1
,
classIndex1
,
sigma1
,
epsilon1
,
reductionFactor1
);
force2
.
getParticleParameters
(
i
,
ivIndex2
,
classIndex2
,
sigma2
,
epsilon2
,
reductionFactor2
);
force1
.
getParticleParameters
(
ii
,
ivIndex1
,
classIndex1
,
sigma1
,
epsilon1
,
reductionFactor1
);
force2
.
getParticleParameters
(
ii
,
ivIndex2
,
classIndex2
,
sigma2
,
epsilon2
,
reductionFactor2
);
ASSERT_EQUAL
(
ivIndex1
,
ivIndex2
);
ASSERT_EQUAL
(
ivIndex1
,
ivIndex2
);
ASSERT_EQUAL
(
classIndex1
,
classIndex2
);
ASSERT_EQUAL
(
classIndex1
,
classIndex2
);
ASSERT_EQUAL
(
sigma1
,
sigma2
);
ASSERT_EQUAL
(
sigma1
,
sigma2
);
ASSERT_EQUAL
(
epsilon1
,
epsilon2
);
ASSERT_EQUAL
(
epsilon1
,
epsilon2
);
ASSERT_EQUAL
(
reductionFactor1
,
reductionFactor2
);
ASSERT_EQUAL
(
reductionFactor1
,
reductionFactor2
);
}
}
for
(
int
i
=
0
;
i
<
force
.
getNumParticles
();
i
++
)
{
for
(
unsigned
int
ii
=
0
;
ii
<
force1
.
getNumParticles
();
ii
++
)
{
std
::
vector
<
int
>
exclusions1
;
std
::
vector
<
int
>
exclusions1
;
std
::
vector
<
int
>
exclusions2
;
std
::
vector
<
int
>
exclusions2
;
force
.
getParticleExclusions
(
i
,
exclusions1
);
force2
.
getParticleExclusions
(
i
,
exclusions2
);
force1
.
getParticleExclusions
(
ii
,
exclusions1
);
force2
.
getParticleExclusions
(
ii
,
exclusions2
);
ASSERT_EQUAL
(
exclusions1
.
size
(),
exclusions2
.
size
());
ASSERT_EQUAL
(
exclusions1
.
size
(),
exclusions2
.
size
());
for
(
unsigned
int
ii
=
0
;
ii
<
exclusions1
.
size
();
ii
++
)
{
for
(
unsigned
int
jj
=
0
;
jj
<
exclusions1
.
size
();
jj
++
)
{
int
hit
=
0
;
int
hit
=
0
;
for
(
unsigned
int
jj
=
0
;
jj
<
exclusions2
.
size
()
&&
hit
==
0
;
jj
++
)
{
for
(
unsigned
int
kk
=
0
;
kk
<
exclusions2
.
size
()
;
kk
++
)
{
if
(
exclusions2
[
jj
]
==
exclusions1
[
ii
]
)
hit
++
;
if
(
exclusions2
[
jj
]
==
exclusions1
[
kk
]
)
hit
++
;
}
}
ASSERT_EQUAL
(
hit
,
1
);
ASSERT_EQUAL
(
hit
,
1
);
}
}
...
...
plugins/amoeba/serialization/tests/TestSerializeAmoebaWcaDispersionForce.cpp
0 → 100644
View file @
1877eb67
/* -------------------------------------------------------------------------- *
* OpenMMAmoeba *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "../../../tests/AssertionUtilities.h"
#include "openmm/AmoebaWcaDispersionForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
void
testSerialization
()
{
// Create a Force.
AmoebaWcaDispersionForce
force1
;
force1
.
setEpso
(
1.0
);
force1
.
setEpsh
(
1.1
);
force1
.
setRmino
(
1.2
);
force1
.
setRminh
(
1.3
);
force1
.
setAwater
(
1.4
);
force1
.
setShctd
(
1.5
);
force1
.
setDispoff
(
1.6
);
force1
.
setSlevy
(
1.7
);
force1
.
addParticle
(
1.0
,
2.0
);
force1
.
addParticle
(
1.1
,
2.1
);
force1
.
addParticle
(
1.2
,
2.2
);
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaWcaDispersionForce
>
(
&
force1
,
"Force"
,
buffer
);
if
(
1
){
FILE
*
filePtr
=
fopen
(
"WcaDispersion.xml"
,
"w"
);
(
void
)
fprintf
(
filePtr
,
"%s"
,
buffer
.
str
().
c_str
()
);
(
void
)
fclose
(
filePtr
);
}
AmoebaWcaDispersionForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaWcaDispersionForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
AmoebaWcaDispersionForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force1
.
getEpso
(),
force2
.
getEpso
());
ASSERT_EQUAL
(
force1
.
getEpsh
(),
force2
.
getEpsh
());
ASSERT_EQUAL
(
force1
.
getRmino
(),
force2
.
getRmino
());
ASSERT_EQUAL
(
force1
.
getRminh
(),
force2
.
getRminh
());
ASSERT_EQUAL
(
force1
.
getAwater
(),
force2
.
getAwater
());
ASSERT_EQUAL
(
force1
.
getShctd
(),
force2
.
getShctd
());
ASSERT_EQUAL
(
force1
.
getDispoff
(),
force2
.
getDispoff
());
ASSERT_EQUAL
(
force1
.
getSlevy
(),
force2
.
getSlevy
());
ASSERT_EQUAL
(
force1
.
getNumParticles
(),
force2
.
getNumParticles
());
for
(
unsigned
int
ii
=
0
;
ii
<
force1
.
getNumParticles
();
ii
++
)
{
double
radius1
,
epsilon1
;
double
radius2
,
epsilon2
;
force1
.
getParticleParameters
(
ii
,
radius1
,
epsilon1
);
force2
.
getParticleParameters
(
ii
,
radius2
,
epsilon2
);
ASSERT_EQUAL
(
radius1
,
radius2
);
ASSERT_EQUAL
(
epsilon1
,
epsilon2
);
}
}
int
main
()
{
try
{
testSerialization
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
Prev
1
2
Next
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