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
3c3df452
"...ssh:/git@developer.sourcefind.cn:2222/tsoc/openmm.git" did not exist on "5499544f97b083ea436237e0f137a0b40e286088"
Commit
3c3df452
authored
Jan 10, 2011
by
Mark Friedrichs
Browse files
More serialization proxies and associated tests
parent
b549b66f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
720 additions
and
18 deletions
+720
-18
plugins/amoeba/serialization/include/openmm/serialization/AmoebaTorsionTorsionForceProxy.h
...ude/openmm/serialization/AmoebaTorsionTorsionForceProxy.h
+53
-0
plugins/amoeba/serialization/include/openmm/serialization/AmoebaUreyBradleyForceProxy.h
...nclude/openmm/serialization/AmoebaUreyBradleyForceProxy.h
+53
-0
plugins/amoeba/serialization/src/AmoebaSerializationProxyRegistration.cpp
...erialization/src/AmoebaSerializationProxyRegistration.cpp
+6
-0
plugins/amoeba/serialization/src/AmoebaTorsionForceProxy.cpp
plugins/amoeba/serialization/src/AmoebaTorsionForceProxy.cpp
+35
-18
plugins/amoeba/serialization/src/AmoebaTorsionTorsionForceProxy.cpp
...oeba/serialization/src/AmoebaTorsionTorsionForceProxy.cpp
+147
-0
plugins/amoeba/serialization/src/AmoebaUreyBradleyForceProxy.cpp
.../amoeba/serialization/src/AmoebaUreyBradleyForceProxy.cpp
+76
-0
plugins/amoeba/serialization/tests/TestSerializeAmoebaTorsionForce.cpp
...a/serialization/tests/TestSerializeAmoebaTorsionForce.cpp
+121
-0
plugins/amoeba/serialization/tests/TestSerializeAmoebaTorsionTorsionForce.cpp
...lization/tests/TestSerializeAmoebaTorsionTorsionForce.cpp
+143
-0
plugins/amoeba/serialization/tests/TestSerializeAmoebaUreyBradleyForce.cpp
...rialization/tests/TestSerializeAmoebaUreyBradleyForce.cpp
+86
-0
No files found.
plugins/amoeba/serialization/include/openmm/serialization/AmoebaTorsionTorsionForceProxy.h
0 → 100644
View file @
3c3df452
#ifndef OPENMM_AMOEBA_TORSION_TORSION_FORCE_PROXY_H_
#define OPENMM_AMOEBA_TORSION_TORSION_FORCE_PROXY_H_
/* -------------------------------------------------------------------------- *
* 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 "openmm/internal/windowsExport.h"
#include "openmm/serialization/SerializationProxy.h"
namespace
OpenMM
{
/**
* This is a proxy for serializing AmoebaTorsionTorsionForce objects.
*/
class
OPENMM_EXPORT
AmoebaTorsionTorsionForceProxy
:
public
SerializationProxy
{
public:
AmoebaTorsionTorsionForceProxy
();
void
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
;
void
*
deserialize
(
const
SerializationNode
&
node
)
const
;
};
}
// namespace OpenMM
#endif
/*OPENMM_AMOEBA_TORSION_TORSION_FORCE_PROXY_H_*/
plugins/amoeba/serialization/include/openmm/serialization/AmoebaUreyBradleyForceProxy.h
0 → 100644
View file @
3c3df452
#ifndef OPENMM_AMOEBA_UREY_BRADLEY_FORCE_PROXY_H_
#define OPENMM_AMOEBA_UREY_BRADLEY_FORCE_PROXY_H_
/* -------------------------------------------------------------------------- *
* 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 "openmm/internal/windowsExport.h"
#include "openmm/serialization/SerializationProxy.h"
namespace
OpenMM
{
/**
* This is a proxy for serializing AmoebaUreyBradleyForce objects.
*/
class
OPENMM_EXPORT
AmoebaUreyBradleyForceProxy
:
public
SerializationProxy
{
public:
AmoebaUreyBradleyForceProxy
();
void
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
;
void
*
deserialize
(
const
SerializationNode
&
node
)
const
;
};
}
// namespace OpenMM
#endif
/*OPENMM_AMOEBA_UREY_BRADLEY_FORCE_PROXY_H_*/
plugins/amoeba/serialization/src/AmoebaSerializationProxyRegistration.cpp
View file @
3c3df452
...
@@ -45,6 +45,8 @@
...
@@ -45,6 +45,8 @@
#include "openmm/AmoebaOutOfPlaneBendForce.h"
#include "openmm/AmoebaOutOfPlaneBendForce.h"
#include "openmm/AmoebaPiTorsionForce.h"
#include "openmm/AmoebaPiTorsionForce.h"
#include "openmm/AmoebaTorsionForce.h"
#include "openmm/AmoebaTorsionForce.h"
#include "openmm/AmoebaTorsionTorsionForce.h"
#include "openmm/AmoebaUreyBradleyForce.h"
#include "openmm/serialization/SerializationProxy.h"
#include "openmm/serialization/SerializationProxy.h"
#include "openmm/serialization/AmoebaHarmonicBondForceProxy.h"
#include "openmm/serialization/AmoebaHarmonicBondForceProxy.h"
...
@@ -53,6 +55,8 @@
...
@@ -53,6 +55,8 @@
#include "openmm/serialization/AmoebaOutOfPlaneBendForceProxy.h"
#include "openmm/serialization/AmoebaOutOfPlaneBendForceProxy.h"
#include "openmm/serialization/AmoebaPiTorsionForceProxy.h"
#include "openmm/serialization/AmoebaPiTorsionForceProxy.h"
#include "openmm/serialization/AmoebaTorsionForceProxy.h"
#include "openmm/serialization/AmoebaTorsionForceProxy.h"
#include "openmm/serialization/AmoebaTorsionTorsionForceProxy.h"
#include "openmm/serialization/AmoebaUreyBradleyForceProxy.h"
#if defined(WIN32)
#if defined(WIN32)
#include <windows.h>
#include <windows.h>
...
@@ -101,4 +105,6 @@ extern "C" void registerAmoebaSerializationProxies() {
...
@@ -101,4 +105,6 @@ extern "C" void registerAmoebaSerializationProxies() {
SerializationProxy
::
registerProxy
(
typeid
(
AmoebaOutOfPlaneBendForce
),
new
AmoebaOutOfPlaneBendForceProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
AmoebaOutOfPlaneBendForce
),
new
AmoebaOutOfPlaneBendForceProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
AmoebaPiTorsionForce
),
new
AmoebaPiTorsionForceProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
AmoebaPiTorsionForce
),
new
AmoebaPiTorsionForceProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
AmoebaTorsionForce
),
new
AmoebaTorsionForceProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
AmoebaTorsionForce
),
new
AmoebaTorsionForceProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
AmoebaTorsionTorsionForce
),
new
AmoebaTorsionTorsionForceProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
AmoebaUreyBradleyForce
),
new
AmoebaUreyBradleyForceProxy
());
}
}
plugins/amoeba/serialization/src/AmoebaTorsionForceProxy.cpp
View file @
3c3df452
...
@@ -41,15 +41,17 @@ using namespace std;
...
@@ -41,15 +41,17 @@ using namespace std;
AmoebaTorsionForceProxy
::
AmoebaTorsionForceProxy
()
:
SerializationProxy
(
"AmoebaTorsionForce"
)
{
AmoebaTorsionForceProxy
::
AmoebaTorsionForceProxy
()
:
SerializationProxy
(
"AmoebaTorsionForce"
)
{
}
}
static
void
addTorsionValues
(
SerializationNode
&
torsion
,
std
::
vector
<
double
>&
torsionValues
){
static
void
addTorsionValues
(
SerializationNode
&
torsion
,
const
std
::
vector
<
double
>&
torsionValues
){
for
(
int
j
=
0
;
j
<
torsionValues
.
size
();
j
++
)
{
for
(
int
j
=
0
;
j
<
torsionValues
.
size
();
j
++
)
{
torsion
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
torsionValues
[
j
]);
torsion
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
torsionValues
[
j
]);
}
}
}
}
static
void
loadTorsionValues
(
SerializationNode
&
torsion
,
std
::
vector
<
double
>&
torsionValues
){
static
void
loadTorsionValues
(
SerializationNode
&
torsion
,
std
::
vector
<
double
>&
torsionValues
){
for
(
int
j
=
0
;
j
<
torsionValues
.
size
();
j
++
)
{
int
size
=
torsion
.
getIntProperty
(
"size"
);
torsion
.
createChildNode
(
"Value"
).
setDoubleProperty
(
"v"
,
torsionValues
[
j
]);
torsionValues
.
resize
(
size
);
for
(
int
j
=
0
;
j
<
size
;
j
++
)
{
torsionValues
[
j
]
=
(
torsion
.
getChildren
()[
j
].
getDoubleProperty
(
"v"
)
);
}
}
}
}
...
@@ -58,39 +60,54 @@ void AmoebaTorsionForceProxy::serialize(const void* object, SerializationNode& n
...
@@ -58,39 +60,54 @@ void AmoebaTorsionForceProxy::serialize(const void* object, SerializationNode& n
const
AmoebaTorsionForce
&
force
=
*
reinterpret_cast
<
const
AmoebaTorsionForce
*>
(
object
);
const
AmoebaTorsionForce
&
force
=
*
reinterpret_cast
<
const
AmoebaTorsionForce
*>
(
object
);
SerializationNode
&
bonds
=
node
.
createChildNode
(
"Torsion"
);
SerializationNode
&
bonds
=
node
.
createChildNode
(
"Torsion"
);
for
(
int
i
=
0
;
i
<
force
.
getNumTorsions
();
i
++
)
{
for
(
int
i
=
0
;
i
<
force
.
getNumTorsions
();
i
++
)
{
int
particle1
,
particle2
,
particle3
,
particle4
;
int
particle1
,
particle2
,
particle3
,
particle4
;
std
::
vector
<
double
>
torsion1
;
std
::
vector
<
double
>
torsion1
;
std
::
vector
<
double
>
torsion2
;
std
::
vector
<
double
>
torsion2
;
std
::
vector
<
double
>
torsion3
;
std
::
vector
<
double
>
torsion3
;
force
.
getTorsionParameters
(
i
,
particle1
,
particle2
,
particle3
,
particle4
,
torsion1
,
torsion2
,
torsion3
);
force
.
getTorsionParameters
(
i
,
particle1
,
particle2
,
particle3
,
particle4
,
torsion1
,
torsion2
,
torsion3
);
bonds
.
createChildNode
(
"Torsion"
).
setIntProperty
(
"p1"
,
particle1
).
setIntProperty
(
"p2"
,
particle2
).
setIntProperty
(
"p3"
,
particle3
).
setIntProperty
(
"p4"
,
particle4
);
SerializationNode
&
torsion
=
bonds
.
createChildNode
(
"Torsion1"
).
setIntProperty
(
"size"
,
torsion1
.
size
());
SerializationNode
&
torsionBond
=
bonds
.
createChildNode
(
"Torsion"
);
addTorsionValues
(
torsion
,
torsion1
);
torsionBond
.
setIntProperty
(
"p1"
,
particle1
).
setIntProperty
(
"p2"
,
particle2
).
setIntProperty
(
"p3"
,
particle3
).
setIntProperty
(
"p4"
,
particle4
);
torsion
=
bonds
.
createChildNode
(
"Torsion2"
).
setIntProperty
(
"size"
,
torsion2
.
size
());
addTorsionValues
(
torsion
,
torsion2
);
SerializationNode
&
torsionVector1
=
torsionBond
.
createChildNode
(
"Torsion1"
).
setIntProperty
(
"size"
,
torsion1
.
size
());
torsion
=
bonds
.
createChildNode
(
"Torsion3"
).
setIntProperty
(
"size"
,
torsion3
.
size
());
addTorsionValues
(
torsionVector1
,
torsion1
);
addTorsionValues
(
torsion
,
torsion3
);
SerializationNode
&
torsionVector2
=
torsionBond
.
createChildNode
(
"Torsion2"
).
setIntProperty
(
"size"
,
torsion2
.
size
());
addTorsionValues
(
torsionVector2
,
torsion2
);
SerializationNode
&
torsionVector3
=
torsionBond
.
createChildNode
(
"Torsion3"
).
setIntProperty
(
"size"
,
torsion3
.
size
());
addTorsionValues
(
torsionVector3
,
torsion3
);
}
}
}
}
void
*
AmoebaTorsionForceProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
void
*
AmoebaTorsionForceProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
if
(
node
.
getIntProperty
(
"version"
)
!=
1
)
if
(
node
.
getIntProperty
(
"version"
)
!=
1
)
throw
OpenMMException
(
"Unsupported version number"
);
throw
OpenMMException
(
"Unsupported version number"
);
AmoebaTorsionForce
*
force
=
new
AmoebaTorsionForce
();
AmoebaTorsionForce
*
force
=
new
AmoebaTorsionForce
();
/*
try
{
try
{
const SerializationNode& bonds = node.getChildNode("Torsion");
const
SerializationNode
&
bonds
=
node
.
getChildNode
(
"Torsion"
);
for (int i = 0; i < (int) bonds.getChildren().size(); i++) {
vector
<
SerializationNode
>
children
=
bonds
.
getChildren
();
const SerializationNode& bond = bonds.getChildren()[i];
for
(
unsigned
int
i
=
0
;
i
<
children
.
size
();
i
++
)
{
//force->addTorsion(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getIntProperty("p3"), bond.getIntProperty("p4") );
SerializationNode
&
bond
=
children
[
i
];
std::vector<double> torsion1, std::vector<double> torsion2, std::vector<double> torsion3;
std
::
vector
<
double
>
torsion1
;
const SerializationNode& torsion = bond.getChildNode("Torsion1");
std
::
vector
<
double
>
torsion2
;
std
::
vector
<
double
>
torsion3
;
SerializationNode
&
torsionNode1
=
bond
.
getChildNode
(
"Torsion1"
);
loadTorsionValues
(
torsionNode1
,
torsion1
);
SerializationNode
&
torsionNode2
=
bond
.
getChildNode
(
"Torsion2"
);
loadTorsionValues
(
torsionNode2
,
torsion2
);
SerializationNode
&
torsionNode3
=
bond
.
getChildNode
(
"Torsion3"
);
loadTorsionValues
(
torsionNode3
,
torsion3
);
force
->
addTorsion
(
bond
.
getIntProperty
(
"p1"
),
bond
.
getIntProperty
(
"p2"
),
bond
.
getIntProperty
(
"p3"
),
bond
.
getIntProperty
(
"p4"
),
torsion1
,
torsion2
,
torsion3
);
}
}
}
}
catch
(...)
{
catch
(...)
{
delete
force
;
delete
force
;
throw
;
throw
;
}
}
*/
return
force
;
return
force
;
}
}
plugins/amoeba/serialization/src/AmoebaTorsionTorsionForceProxy.cpp
0 → 100644
View file @
3c3df452
/* -------------------------------------------------------------------------- *
* 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 "openmm/serialization/AmoebaTorsionTorsionForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/AmoebaTorsionTorsionForce.h"
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
AmoebaTorsionTorsionForceProxy
::
AmoebaTorsionTorsionForceProxy
()
:
SerializationProxy
(
"AmoebaTorsionTorsionForce"
)
{
}
static
void
loadGrid
(
const
SerializationNode
&
grid
,
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
gridVector
){
const
std
::
vector
<
SerializationNode
>&
gridSerializationRows
=
grid
.
getChildren
();
gridVector
.
resize
(
gridSerializationRows
.
size
()
);
for
(
unsigned
int
ii
=
0
;
ii
<
gridSerializationRows
.
size
();
ii
++
)
{
const
std
::
vector
<
SerializationNode
>&
gridSerializationColumns
=
gridSerializationRows
[
ii
].
getChildren
();
gridVector
[
ii
].
resize
(
gridSerializationColumns
.
size
()
);
for
(
unsigned
int
jj
=
0
;
jj
<
gridSerializationColumns
.
size
();
jj
++
)
{
const
SerializationNode
&
gridSerializationColumnNode
=
gridSerializationColumns
[
jj
];
gridVector
[
ii
][
jj
].
resize
(
6
);
gridVector
[
ii
][
jj
][
0
]
=
gridSerializationColumnNode
.
getDoubleProperty
(
"x"
);
gridVector
[
ii
][
jj
][
1
]
=
gridSerializationColumnNode
.
getDoubleProperty
(
"y"
);
gridVector
[
ii
][
jj
][
2
]
=
gridSerializationColumnNode
.
getDoubleProperty
(
"f"
);
gridVector
[
ii
][
jj
][
3
]
=
gridSerializationColumnNode
.
getDoubleProperty
(
"fx"
);
gridVector
[
ii
][
jj
][
4
]
=
gridSerializationColumnNode
.
getDoubleProperty
(
"fy"
);
gridVector
[
ii
][
jj
][
5
]
=
gridSerializationColumnNode
.
getDoubleProperty
(
"fxy"
);
}
}
}
void
AmoebaTorsionTorsionForceProxy
::
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
{
node
.
setIntProperty
(
"version"
,
1
);
const
AmoebaTorsionTorsionForce
&
force
=
*
reinterpret_cast
<
const
AmoebaTorsionTorsionForce
*>
(
object
);
// grid[xIdx][yIdx][6 values]
// value0 = x-Grid value
// value1 = y-Grid value
// value2 = F function value
// value3 = F_x partial f wrt x
// value4 = F_y partial f wrt y
// value5 = F_xy partial f wrt x,y
SerializationNode
&
grids
=
node
.
createChildNode
(
"TorsionTorsionGrids"
);
grids
.
setIntProperty
(
"size"
,
static_cast
<
int
>
(
force
.
getNumTorsionTorsionGrids
()));
for
(
int
i
=
0
;
i
<
force
.
getNumTorsionTorsionGrids
();
i
++
)
{
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>
grid
=
force
.
getTorsionTorsionGrid
(
i
);
unsigned
int
gridCount
=
0
;
unsigned
int
gridYsize
=
grid
[
0
].
size
();
for
(
unsigned
int
ii
=
0
;
ii
<
grid
.
size
();
ii
++
)
{
gridCount
+=
grid
[
ii
].
size
();
}
SerializationNode
&
gridNode
=
grids
.
createChildNode
(
"TorsionTorsionGrid"
).
setIntProperty
(
"size"
,
static_cast
<
int
>
(
gridCount
)
);
for
(
unsigned
int
ii
=
0
;
ii
<
grid
.
size
();
ii
++
)
{
SerializationNode
&
gridSerializationRow
=
gridNode
.
createChildNode
(
"RowNode"
);
gridSerializationRow
.
setIntProperty
(
"dim"
,
ii
);
gridSerializationRow
.
setIntProperty
(
"size"
,
static_cast
<
int
>
(
grid
[
ii
].
size
()
)
);
for
(
unsigned
int
jj
=
0
;
jj
<
grid
[
ii
].
size
();
jj
++
)
{
SerializationNode
&
gridSerializationColumnNode
=
gridSerializationRow
.
createChildNode
(
"ColumnNode"
);
gridSerializationColumnNode
.
setIntProperty
(
"dim"
,
jj
);
unsigned
int
index
=
0
;
gridSerializationColumnNode
.
setDoubleProperty
(
"x"
,
grid
[
ii
][
jj
][
index
++
]
);
gridSerializationColumnNode
.
setDoubleProperty
(
"y"
,
grid
[
ii
][
jj
][
index
++
]
);
gridSerializationColumnNode
.
setDoubleProperty
(
"f"
,
grid
[
ii
][
jj
][
index
++
]
);
gridSerializationColumnNode
.
setDoubleProperty
(
"fx"
,
grid
[
ii
][
jj
][
index
++
]
);
gridSerializationColumnNode
.
setDoubleProperty
(
"fy"
,
grid
[
ii
][
jj
][
index
++
]
);
gridSerializationColumnNode
.
setDoubleProperty
(
"fxy"
,
grid
[
ii
][
jj
][
index
++
]
);
}
}
}
SerializationNode
&
bonds
=
node
.
createChildNode
(
"TorsionTorsion"
);
for
(
int
i
=
0
;
i
<
force
.
getNumTorsionTorsions
();
i
++
)
{
int
particle1
,
particle2
,
particle3
,
particle4
,
particle5
;
int
chiralCheckAtomIndex
,
gridIndex
;
force
.
getTorsionTorsionParameters
(
i
,
particle1
,
particle2
,
particle3
,
particle4
,
particle5
,
chiralCheckAtomIndex
,
gridIndex
);
bonds
.
createChildNode
(
"TorsionTorsion"
).
setIntProperty
(
"p1"
,
particle1
).
setIntProperty
(
"p2"
,
particle2
).
setIntProperty
(
"p3"
,
particle3
).
setIntProperty
(
"p4"
,
particle4
).
setIntProperty
(
"p5"
,
particle5
).
setIntProperty
(
"chiralCheckAtomIndex"
,
chiralCheckAtomIndex
).
setIntProperty
(
"gridIndex"
,
gridIndex
);
}
}
void
*
AmoebaTorsionTorsionForceProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
if
(
node
.
getIntProperty
(
"version"
)
!=
1
)
throw
OpenMMException
(
"Unsupported version number"
);
AmoebaTorsionTorsionForce
*
force
=
new
AmoebaTorsionTorsionForce
();
try
{
const
SerializationNode
&
grids
=
node
.
getChildNode
(
"TorsionTorsionGrids"
);
const
std
::
vector
<
SerializationNode
>&
gridList
=
grids
.
getChildren
();
for
(
unsigned
int
ii
=
0
;
ii
<
gridList
.
size
();
ii
++
)
{
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>
gridVector
;
loadGrid
(
gridList
[
ii
],
gridVector
);
force
->
setTorsionTorsionGrid
(
ii
,
gridVector
);
}
const
SerializationNode
&
bonds
=
node
.
getChildNode
(
"TorsionTorsion"
);
vector
<
SerializationNode
>
children
=
bonds
.
getChildren
();
for
(
unsigned
int
i
=
0
;
i
<
children
.
size
();
i
++
)
{
SerializationNode
&
bond
=
children
[
i
];
force
->
addTorsionTorsion
(
bond
.
getIntProperty
(
"p1"
),
bond
.
getIntProperty
(
"p2"
),
bond
.
getIntProperty
(
"p3"
),
bond
.
getIntProperty
(
"p4"
),
bond
.
getIntProperty
(
"p5"
),
bond
.
getIntProperty
(
"chiralCheckAtomIndex"
),
bond
.
getIntProperty
(
"gridIndex"
));
}
}
catch
(...)
{
delete
force
;
throw
;
}
return
force
;
}
plugins/amoeba/serialization/src/AmoebaUreyBradleyForceProxy.cpp
0 → 100644
View file @
3c3df452
/* -------------------------------------------------------------------------- *
* 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 "openmm/serialization/AmoebaUreyBradleyForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/AmoebaUreyBradleyForce.h"
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
AmoebaUreyBradleyForceProxy
::
AmoebaUreyBradleyForceProxy
()
:
SerializationProxy
(
"AmoebaUreyBradleyForce"
)
{
}
void
AmoebaUreyBradleyForceProxy
::
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
{
node
.
setIntProperty
(
"version"
,
1
);
const
AmoebaUreyBradleyForce
&
force
=
*
reinterpret_cast
<
const
AmoebaUreyBradleyForce
*>
(
object
);
node
.
setDoubleProperty
(
"UreyBradleyCubic"
,
force
.
getAmoebaGlobalUreyBradleyCubic
());
node
.
setDoubleProperty
(
"UreyBradleyQuartic"
,
force
.
getAmoebaGlobalUreyBradleyQuartic
());
SerializationNode
&
bonds
=
node
.
createChildNode
(
"Bonds"
);
for
(
int
i
=
0
;
i
<
force
.
getNumInteractions
();
i
++
)
{
int
particle1
,
particle2
;
double
distance
,
k
;
force
.
getUreyBradleyParameters
(
i
,
particle1
,
particle2
,
distance
,
k
);
bonds
.
createChildNode
(
"Bond"
).
setIntProperty
(
"p1"
,
particle1
).
setIntProperty
(
"p2"
,
particle2
).
setDoubleProperty
(
"d"
,
distance
).
setDoubleProperty
(
"k"
,
k
);
}
}
void
*
AmoebaUreyBradleyForceProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
if
(
node
.
getIntProperty
(
"version"
)
!=
1
)
throw
OpenMMException
(
"Unsupported version number"
);
AmoebaUreyBradleyForce
*
force
=
new
AmoebaUreyBradleyForce
();
try
{
force
->
setAmoebaGlobalUreyBradleyCubic
(
node
.
getDoubleProperty
(
"UreyBradleyCubic"
));
force
->
setAmoebaGlobalUreyBradleyQuartic
(
node
.
getDoubleProperty
(
"UreyBradleyQuartic"
));
const
SerializationNode
&
bonds
=
node
.
getChildNode
(
"Bonds"
);
for
(
int
i
=
0
;
i
<
(
int
)
bonds
.
getChildren
().
size
();
i
++
)
{
const
SerializationNode
&
bond
=
bonds
.
getChildren
()[
i
];
force
->
addUreyBradley
(
bond
.
getIntProperty
(
"p1"
),
bond
.
getIntProperty
(
"p2"
),
bond
.
getDoubleProperty
(
"d"
),
bond
.
getDoubleProperty
(
"k"
));
}
}
catch
(...)
{
delete
force
;
throw
;
}
return
force
;
}
plugins/amoeba/serialization/tests/TestSerializeAmoebaTorsionForce.cpp
0 → 100644
View file @
3c3df452
/* -------------------------------------------------------------------------- *
* 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/AmoebaTorsionForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
void
loadTorsion
(
std
::
vector
<
double
>&
torsion
,
double
offset
){
torsion
.
push_back
(
offset
+
1.0
);
torsion
.
push_back
(
offset
+
2.0
);
// torsion.push_back( offset + 3.0 );
// torsion.push_back( offset + 4.0 );
}
void
compareTorsion
(
std
::
vector
<
double
>
torsionA
,
std
::
vector
<
double
>
torsionB
){
ASSERT_EQUAL
(
torsionA
.
size
(),
torsionB
.
size
());
for
(
int
i
=
0
;
i
<
torsionA
.
size
();
i
++
)
{
ASSERT_EQUAL
(
torsionA
[
i
],
torsionB
[
i
]);
}
}
void
testSerialization
()
{
// Create a Force.
AmoebaTorsionForce
force
;
for
(
int
ii
=
0
;
ii
<
5
;
ii
++
){
std
::
vector
<
double
>
torsion1
;
std
::
vector
<
double
>
torsion2
;
std
::
vector
<
double
>
torsion3
;
loadTorsion
(
torsion1
,
static_cast
<
double
>
(
5
*
ii
)
+
11.1
);
loadTorsion
(
torsion2
,
static_cast
<
double
>
(
5
*
ii
)
+
21.2
);
loadTorsion
(
torsion3
,
static_cast
<
double
>
(
5
*
ii
)
+
31.3
);
force
.
addTorsion
(
ii
,
ii
+
1
,
ii
+
3
,
ii
+
4
,
torsion1
,
torsion2
,
torsion3
);
}
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaTorsionForce
>
(
&
force
,
"Force"
,
buffer
);
if
(
0
){
FILE
*
filePtr
=
fopen
(
"Torsion.xml"
,
"w"
);
(
void
)
fprintf
(
filePtr
,
"%s"
,
buffer
.
str
().
c_str
()
);
(
void
)
fclose
(
filePtr
);
}
AmoebaTorsionForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaTorsionForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
AmoebaTorsionForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getNumTorsions
(),
force2
.
getNumTorsions
());
for
(
int
i
=
0
;
i
<
force
.
getNumTorsions
();
i
++
)
{
int
a1
,
a2
,
a3
,
a4
,
b1
,
b2
,
b3
,
b4
;
std
::
vector
<
double
>
torsion1a
;
std
::
vector
<
double
>
torsion2a
;
std
::
vector
<
double
>
torsion3a
;
std
::
vector
<
double
>
torsion1b
;
std
::
vector
<
double
>
torsion2b
;
std
::
vector
<
double
>
torsion3b
;
force
.
getTorsionParameters
(
i
,
a1
,
a2
,
a3
,
a4
,
torsion1a
,
torsion2a
,
torsion3a
);
force2
.
getTorsionParameters
(
i
,
b1
,
b2
,
b3
,
b4
,
torsion1b
,
torsion2b
,
torsion3b
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a3
,
b3
);
ASSERT_EQUAL
(
a4
,
b4
);
compareTorsion
(
torsion1a
,
torsion1b
);
compareTorsion
(
torsion2a
,
torsion2b
);
compareTorsion
(
torsion3a
,
torsion3b
);
}
}
int
main
()
{
try
{
testSerialization
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
plugins/amoeba/serialization/tests/TestSerializeAmoebaTorsionTorsionForce.cpp
0 → 100644
View file @
3c3df452
/* -------------------------------------------------------------------------- *
* 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/AmoebaTorsionTorsionForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
#include <stdlib.h>
using
namespace
OpenMM
;
using
namespace
std
;
static
void
loadTorsionTorsionGrid
(
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
gridVector
){
static
const
int
gridSize
=
25
;
gridVector
.
resize
(
gridSize
);
for
(
int
ii
=
0
;
ii
<
gridSize
;
ii
++
){
gridVector
[
ii
].
resize
(
gridSize
);
for
(
int
jj
=
0
;
jj
<
gridSize
;
jj
++
){
gridVector
[
ii
][
jj
].
resize
(
6
);
for
(
int
kk
=
0
;
kk
<
6
;
kk
++
){
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
][
2
]
=
static_cast
<
double
>
(
rand
());
gridVector
[
ii
][
jj
][
3
]
=
static_cast
<
double
>
(
rand
());
gridVector
[
ii
][
jj
][
4
]
=
static_cast
<
double
>
(
rand
());
gridVector
[
ii
][
jj
][
5
]
=
static_cast
<
double
>
(
rand
());
}
}
}
}
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
());
for
(
int
i
=
0
;
i
<
grid1
.
size
();
i
++
)
{
ASSERT_EQUAL
(
grid1
[
i
].
size
(),
grid2
[
i
].
size
());
for
(
int
jj
=
0
;
jj
<
grid1
[
i
].
size
();
jj
++
)
{
ASSERT_EQUAL
(
grid1
[
i
][
jj
].
size
(),
grid2
[
i
][
jj
].
size
());
for
(
int
kk
=
0
;
kk
<
grid1
[
i
][
jj
].
size
();
kk
++
)
{
ASSERT_EQUAL
(
grid1
[
i
][
jj
][
kk
],
grid2
[
i
][
jj
][
kk
]);
}
}
}
}
void
testSerialization
()
{
// Create a Force.
AmoebaTorsionTorsionForce
force
;
for
(
int
ii
=
0
;
ii
<
5
;
ii
++
){
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>
gridVector
;
loadTorsionTorsionGrid
(
gridVector
);
force
.
setTorsionTorsionGrid
(
ii
,
gridVector
);
}
for
(
int
ii
=
0
;
ii
<
5
;
ii
++
){
force
.
addTorsionTorsion
(
ii
,
ii
+
1
,
ii
+
3
,
ii
+
4
,
ii
+
5
,
(
(
ii
%
2
)
?
1
:
0
),
(
ii
%
4
)
);
}
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaTorsionTorsionForce
>
(
&
force
,
"Force"
,
buffer
);
if
(
0
){
FILE
*
filePtr
=
fopen
(
"TorsionTorsion.xml"
,
"w"
);
(
void
)
fprintf
(
filePtr
,
"%s"
,
buffer
.
str
().
c_str
()
);
(
void
)
fclose
(
filePtr
);
}
AmoebaTorsionTorsionForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaTorsionTorsionForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
AmoebaTorsionTorsionForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getNumTorsionTorsions
(),
force2
.
getNumTorsionTorsions
());
for
(
int
i
=
0
;
i
<
force
.
getNumTorsionTorsions
();
i
++
)
{
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
);
force2
.
getTorsionTorsionParameters
(
i
,
b1
,
b2
,
b3
,
b4
,
b5
,
bChiral
,
bGridIndex
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a3
,
b3
);
ASSERT_EQUAL
(
a4
,
b4
);
ASSERT_EQUAL
(
a5
,
b5
);
ASSERT_EQUAL
(
aChiral
,
bChiral
);
ASSERT_EQUAL
(
aGridIndex
,
bGridIndex
);
}
ASSERT_EQUAL
(
force
.
getNumTorsionTorsionGrids
(),
force2
.
getNumTorsionTorsionGrids
());
for
(
int
i
=
0
;
i
<
force
.
getNumTorsionTorsionGrids
();
i
++
)
{
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
grid1
=
force
.
getTorsionTorsionGrid
(
i
);
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
double
>
>
>&
grid2
=
force2
.
getTorsionTorsionGrid
(
i
);
compareGrids
(
grid1
,
grid2
);
}
}
int
main
()
{
try
{
testSerialization
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
plugins/amoeba/serialization/tests/TestSerializeAmoebaUreyBradleyForce.cpp
0 → 100644
View file @
3c3df452
/* -------------------------------------------------------------------------- *
* 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/AmoebaUreyBradleyForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
void
testSerialization
()
{
// Create a Force.
AmoebaUreyBradleyForce
force
;
force
.
setAmoebaGlobalUreyBradleyCubic
(
12.3
);
force
.
setAmoebaGlobalUreyBradleyQuartic
(
98.7
);
force
.
addUreyBradley
(
0
,
1
,
1.0
,
2.0
);
force
.
addUreyBradley
(
0
,
2
,
2.0
,
2.1
);
force
.
addUreyBradley
(
2
,
3
,
3.0
,
2.2
);
force
.
addUreyBradley
(
5
,
1
,
4.0
,
2.3
);
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
AmoebaUreyBradleyForce
>
(
&
force
,
"Force"
,
buffer
);
AmoebaUreyBradleyForce
*
copy
=
XmlSerializer
::
deserialize
<
AmoebaUreyBradleyForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
AmoebaUreyBradleyForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getAmoebaGlobalUreyBradleyCubic
(),
force2
.
getAmoebaGlobalUreyBradleyCubic
());
ASSERT_EQUAL
(
force
.
getAmoebaGlobalUreyBradleyQuartic
(),
force2
.
getAmoebaGlobalUreyBradleyQuartic
());
ASSERT_EQUAL
(
force
.
getNumInteractions
(),
force2
.
getNumInteractions
());
for
(
int
i
=
0
;
i
<
force
.
getNumInteractions
();
i
++
)
{
int
a1
,
a2
,
b1
,
b2
;
double
da
,
db
,
ka
,
kb
;
force
.
getUreyBradleyParameters
(
i
,
a1
,
a2
,
da
,
ka
);
force2
.
getUreyBradleyParameters
(
i
,
b1
,
b2
,
db
,
kb
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
da
,
db
);
ASSERT_EQUAL
(
ka
,
kb
);
}
}
int
main
()
{
try
{
testSerialization
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
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