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
c7387612
"vscode:/vscode.git/clone" did not exist on "a9a7f2ccc3d8f00e19a122ca2bf6e070ffe4005c"
Commit
c7387612
authored
Sep 20, 2010
by
Peter Eastman
Browse files
Continuing to implement serialization
parent
88aad28b
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
451 additions
and
8 deletions
+451
-8
CMakeLists.txt
CMakeLists.txt
+5
-0
serialization/CMakeLists.txt
serialization/CMakeLists.txt
+83
-0
serialization/include/openmm/serialization/HarmonicAngleForceProxy.h
...on/include/openmm/serialization/HarmonicAngleForceProxy.h
+53
-0
serialization/src/HarmonicAngleForceProxy.cpp
serialization/src/HarmonicAngleForceProxy.cpp
+70
-0
serialization/src/HarmonicBondForceProxy.cpp
serialization/src/HarmonicBondForceProxy.cpp
+13
-1
serialization/src/SerializationProxyRegistration.cpp
serialization/src/SerializationProxyRegistration.cpp
+58
-0
serialization/tests/CMakeLists.txt
serialization/tests/CMakeLists.txt
+1
-1
serialization/tests/TestSerializeHarmonicAngleForce.cpp
serialization/tests/TestSerializeHarmonicAngleForce.cpp
+85
-0
serialization/tests/TestSerializeHarmonicBondForce.cpp
serialization/tests/TestSerializeHarmonicBondForce.cpp
+83
-0
serialization/tests/TestSerializeSystem.cpp
serialization/tests/TestSerializeSystem.cpp
+0
-6
No files found.
CMakeLists.txt
View file @
c7387612
...
...
@@ -497,4 +497,9 @@ install(FILES ${LICENSE_FILES}
ADD_SUBDIRECTORY
(
tests
)
ADD_SUBDIRECTORY
(
examples
)
SET
(
OPENMM_BUILD_SERIALIZATION_SUPPORT ON CACHE BOOL
"Whether to build the serialization support library"
)
IF
(
OPENMM_BUILD_SERIALIZATION_SUPPORT
)
ADD_SUBDIRECTORY
(
serialization
)
ENDIF
(
OPENMM_BUILD_SERIALIZATION_SUPPORT
)
ENDIF
(
NOT cmv EQUAL
"2.4"
)
# This whole file...
serialization/CMakeLists.txt
0 → 100644
View file @
c7387612
#---------------------------------------------------
# OpenMM Serialization Library
#
# Creates OpenMM serializatin library, base name=OpenMMSerialization.
# Default libraries are shared & optimized. Variants
# are created for static (_static) and debug (_d).
#
# Windows:
# OpenMMSerialization[_d].dll
# OpenMMSerialization[_d].lib
# Unix:
# libOpenMMSerialization[_d].so
#----------------------------------------------------
# The source is organized into subdirectories, but we handle them all from
# this CMakeLists file rather than letting CMake visit them as SUBDIRS.
SET
(
OPENMM_SOURCE_SUBDIRS .
)
# Collect up information about the version of the OpenMM library we're building
# and make it available to the code so it can be built into the binaries.
SET
(
OPENMM_SERIALIZATION_LIBRARY_NAME OpenMMSerialization
)
# Ensure that debug libraries have "_d" appended to their names.
# CMake gets this right on Windows automatically with this definition.
IF
(
${
CMAKE_GENERATOR
}
MATCHES
"Visual Studio"
)
SET
(
CMAKE_DEBUG_POSTFIX
"_d"
CACHE INTERNAL
""
FORCE
)
ENDIF
(
${
CMAKE_GENERATOR
}
MATCHES
"Visual Studio"
)
# But on Unix or Cygwin we have to add the suffix manually
IF
(
UNIX AND CMAKE_BUILD_TYPE MATCHES Debug
)
SET
(
OPENMM_SERIALIZATION_LIBRARY_NAME
${
OPENMM_SERIALIZATION_LIBRARY_NAME
}
_d
)
ENDIF
(
UNIX AND CMAKE_BUILD_TYPE MATCHES Debug
)
# These are all the places to search for header files which are
# to be part of the API.
SET
(
API_INCLUDE_DIRS
)
# start empty
FOREACH
(
subdir
${
OPENMM_SOURCE_SUBDIRS
}
)
# append
SET
(
API_INCLUDE_DIRS
${
API_INCLUDE_DIRS
}
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
subdir
}
/include
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
subdir
}
/include/internal
)
ENDFOREACH
(
subdir
)
# We'll need both *relative* path names, starting with their API_INCLUDE_DIRS,
# and absolute pathnames.
SET
(
API_REL_INCLUDE_FILES
)
# start these out empty
SET
(
API_ABS_INCLUDE_FILES
)
FOREACH
(
dir
${
API_INCLUDE_DIRS
}
)
FILE
(
GLOB fullpaths
${
dir
}
/*.h
)
# returns full pathnames
SET
(
API_ABS_INCLUDE_FILES
${
API_ABS_INCLUDE_FILES
}
${
fullpaths
}
)
FOREACH
(
pathname
${
fullpaths
}
)
GET_FILENAME_COMPONENT
(
filename
${
pathname
}
NAME
)
SET
(
API_REL_INCLUDE_FILES
${
API_REL_INCLUDE_FILES
}
${
dir
}
/
${
filename
}
)
ENDFOREACH
(
pathname
)
ENDFOREACH
(
dir
)
# collect up source files
SET
(
SOURCE_FILES
)
# empty
SET
(
SOURCE_INCLUDE_FILES
)
FOREACH
(
subdir
${
OPENMM_SOURCE_SUBDIRS
}
)
FILE
(
GLOB_RECURSE src_files
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
subdir
}
/src/*.cpp
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
subdir
}
/src/*.c
)
FILE
(
GLOB incl_files
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
subdir
}
/src/*.h
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
subdir
}
/src/*.hpp
)
SET
(
SOURCE_FILES
${
SOURCE_FILES
}
${
src_files
}
)
#append
SET
(
SOURCE_INCLUDE_FILES
${
SOURCE_INCLUDE_FILES
}
${
incl_files
}
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_CURRENT_SOURCE_DIR
}
/
${
subdir
}
/include
)
ENDFOREACH
(
subdir
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_CURRENT_SOURCE_DIR
}
/src
)
# Create the library
ADD_LIBRARY
(
${
OPENMM_SERIALIZATION_LIBRARY_NAME
}
SHARED
${
SOURCE_FILES
}
${
SOURCE_INCLUDE_FILES
}
${
API_ABS_INCLUDE_FILES
}
)
TARGET_LINK_LIBRARIES
(
${
OPENMM_SERIALIZATION_LIBRARY_NAME
}
debug
${
OPENMM_LIBRARY_NAME
}
_d optimized
${
OPENMM_LIBRARY_NAME
}
)
SET_TARGET_PROPERTIES
(
${
OPENMM_SERIALIZATION_LIBRARY_NAME
}
PROPERTIES COMPILE_FLAGS
"-DOPENMM_BUILDING_SHARED_LIBRARY -DTIXML_USE_STL"
)
INSTALL_TARGETS
(
/lib RUNTIME_DIRECTORY /lib
${
OPENMM_SERIALIZATION_LIBRARY_NAME
}
)
ADD_SUBDIRECTORY
(
tests
)
serialization/include/openmm/serialization/HarmonicAngleForceProxy.h
0 → 100644
View file @
c7387612
#ifndef OPENMM_HARMONICANGLEFORCE_PROXY_H_
#define OPENMM_HARMONICANGLEFORCE_PROXY_H_
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* 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 HarmonicAngleForce objects.
*/
class
OPENMM_EXPORT
HarmonicAngleForceProxy
:
public
SerializationProxy
{
public:
HarmonicAngleForceProxy
();
void
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
;
void
*
deserialize
(
const
SerializationNode
&
node
)
const
;
};
}
// namespace OpenMM
#endif
/*OPENMM_HARMONICANGLEFORCE_PROXY_H_*/
serialization/src/HarmonicAngleForceProxy.cpp
0 → 100644
View file @
c7387612
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* 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/HarmonicAngleForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/Force.h"
#include "openmm/HarmonicAngleForce.h"
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
HarmonicAngleForceProxy
::
HarmonicAngleForceProxy
()
:
SerializationProxy
(
"HarmonicAngleForce"
)
{
}
void
HarmonicAngleForceProxy
::
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
{
const
HarmonicAngleForce
&
force
=
*
reinterpret_cast
<
const
HarmonicAngleForce
*>
(
object
);
SerializationNode
&
bonds
=
node
.
createChildNode
(
"Angles"
);
for
(
int
i
=
0
;
i
<
force
.
getNumAngles
();
i
++
)
{
int
particle1
,
particle2
,
particle3
;
double
angle
,
k
;
force
.
getAngleParameters
(
i
,
particle1
,
particle2
,
particle3
,
angle
,
k
);
bonds
.
createChildNode
(
"Angle"
).
setIntProperty
(
"p1"
,
particle1
).
setIntProperty
(
"p2"
,
particle2
).
setIntProperty
(
"p3"
,
particle3
).
setDoubleProperty
(
"a"
,
angle
).
setDoubleProperty
(
"k"
,
k
);
}
}
void
*
HarmonicAngleForceProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
HarmonicAngleForce
*
force
=
new
HarmonicAngleForce
();
try
{
const
SerializationNode
&
bonds
=
node
.
getChildNode
(
"Angles"
);
for
(
int
i
=
0
;
i
<
(
int
)
bonds
.
getChildren
().
size
();
i
++
)
{
const
SerializationNode
&
constraint
=
bonds
.
getChildren
()[
i
];
force
->
addAngle
(
constraint
.
getDoubleProperty
(
"p1"
),
constraint
.
getDoubleProperty
(
"p2"
),
constraint
.
getDoubleProperty
(
"p3"
),
constraint
.
getDoubleProperty
(
"a"
),
constraint
.
getDoubleProperty
(
"k"
));
}
}
catch
(...)
{
delete
force
;
throw
;
}
return
force
;
}
serialization/src/HarmonicBondForceProxy.cpp
View file @
c7387612
...
...
@@ -53,5 +53,17 @@ void HarmonicBondForceProxy::serialize(const void* object, SerializationNode& no
}
void
*
HarmonicBondForceProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
return
new
HarmonicBondForce
();
HarmonicBondForce
*
force
=
new
HarmonicBondForce
();
try
{
const
SerializationNode
&
bonds
=
node
.
getChildNode
(
"Bonds"
);
for
(
int
i
=
0
;
i
<
(
int
)
bonds
.
getChildren
().
size
();
i
++
)
{
const
SerializationNode
&
constraint
=
bonds
.
getChildren
()[
i
];
force
->
addBond
(
constraint
.
getDoubleProperty
(
"p1"
),
constraint
.
getDoubleProperty
(
"p2"
),
constraint
.
getDoubleProperty
(
"d"
),
constraint
.
getDoubleProperty
(
"k"
));
}
}
catch
(...)
{
delete
force
;
throw
;
}
return
force
;
}
serialization/src/SerializationProxyRegistration.cpp
0 → 100644
View file @
c7387612
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* 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/HarmonicAngleForce.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/System.h"
#include "openmm/serialization/SerializationProxy.h"
#include "openmm/serialization/HarmonicAngleForceProxy.h"
#include "openmm/serialization/HarmonicBondForceProxy.h"
#include "openmm/serialization/SystemProxy.h"
#if defined(WIN32)
#include <windows.h>
extern
"C"
void
initOpenMMPlugin
();
BOOL
WINAPI
DllMain
(
HANDLE
hModule
,
DWORD
ul_reason_for_call
,
LPVOID
lpReserved
)
{
if
(
ul_reason_for_call
==
DLL_PROCESS_ATTACH
)
registerSerializationProxies
();
return
TRUE
;
}
#else
extern
"C"
void
__attribute__
((
constructor
))
registerSerializationProxies
();
#endif
using
namespace
OpenMM
;
extern
"C"
void
registerSerializationProxies
()
{
SerializationProxy
::
registerProxy
(
typeid
(
HarmonicAngleForce
),
new
HarmonicAngleForceProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
HarmonicBondForce
),
new
HarmonicBondForceProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
System
),
new
SystemProxy
());
}
\ No newline at end of file
serialization/tests/CMakeLists.txt
View file @
c7387612
...
...
@@ -11,7 +11,7 @@ FOREACH(TEST_PROG ${TEST_PROGS})
# All tests use shared libraries
ADD_EXECUTABLE
(
${
TEST_ROOT
}
${
TEST_PROG
}
)
TARGET_LINK_LIBRARIES
(
${
TEST_ROOT
}
${
OPENMM_S
11
N_LIBRARY_NAME
}
)
TARGET_LINK_LIBRARIES
(
${
TEST_ROOT
}
${
OPENMM_S
ERIALIZATIO
N_LIBRARY_NAME
}
)
ADD_TEST
(
${
TEST_ROOT
}
${
EXECUTABLE_OUTPUT_PATH
}
/
${
TEST_ROOT
}
)
ENDFOREACH
(
TEST_PROG
${
TEST_PROGS
}
)
serialization/tests/TestSerializeHarmonicAngleForce.cpp
0 → 100644
View file @
c7387612
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* 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/HarmonicAngleForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
void
testSerialization
()
{
// Create a Force.
HarmonicAngleForce
force
;
force
.
addAngle
(
0
,
1
,
2
,
1.0
,
2.0
);
force
.
addAngle
(
0
,
2
,
3
,
2.0
,
2.1
);
force
.
addAngle
(
2
,
3
,
4
,
3.0
,
2.2
);
force
.
addAngle
(
5
,
1
,
2
,
4.0
,
2.3
);
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
HarmonicAngleForce
>
(
&
force
,
"Force"
,
buffer
);
HarmonicAngleForce
*
copy
=
XmlSerializer
::
deserialize
<
HarmonicAngleForce
>
(
buffer
);
// Compare the two systems to see if they are identical.
HarmonicAngleForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getNumAngles
(),
force2
.
getNumAngles
());
for
(
int
i
=
0
;
i
<
force
.
getNumAngles
();
i
++
)
{
int
a1
,
a2
,
a3
,
b1
,
b2
,
b3
;
double
da
,
db
,
ka
,
kb
;
force
.
getAngleParameters
(
i
,
a1
,
a2
,
a3
,
da
,
ka
);
force
.
getAngleParameters
(
i
,
b1
,
b2
,
b3
,
db
,
kb
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a3
,
b3
);
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
;
}
serialization/tests/TestSerializeHarmonicBondForce.cpp
0 → 100644
View file @
c7387612
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* 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/HarmonicBondForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
void
testSerialization
()
{
// Create a Force.
HarmonicBondForce
force
;
force
.
addBond
(
0
,
1
,
1.0
,
2.0
);
force
.
addBond
(
0
,
2
,
2.0
,
2.1
);
force
.
addBond
(
2
,
3
,
3.0
,
2.2
);
force
.
addBond
(
5
,
1
,
4.0
,
2.3
);
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
HarmonicBondForce
>
(
&
force
,
"Force"
,
buffer
);
HarmonicBondForce
*
copy
=
XmlSerializer
::
deserialize
<
HarmonicBondForce
>
(
buffer
);
// Compare the two systems to see if they are identical.
HarmonicBondForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getNumBonds
(),
force2
.
getNumBonds
());
for
(
int
i
=
0
;
i
<
force
.
getNumBonds
();
i
++
)
{
int
a1
,
a2
,
b1
,
b2
;
double
da
,
db
,
ka
,
kb
;
force
.
getBondParameters
(
i
,
a1
,
a2
,
da
,
ka
);
force
.
getBondParameters
(
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
;
}
serialization/tests/TestSerializeSystem.cpp
View file @
c7387612
...
...
@@ -32,10 +32,6 @@
#include "../../../tests/AssertionUtilities.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/System.h"
#include "openmm/serialization/HarmonicBondForceProxy.h"
#include "openmm/serialization/SerializationNode.h"
#include "openmm/serialization/SerializationProxy.h"
#include "openmm/serialization/SystemProxy.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
...
...
@@ -91,8 +87,6 @@ void testSerialization() {
int
main
()
{
try
{
SerializationProxy
::
registerProxy
(
typeid
(
System
),
new
SystemProxy
());
SerializationProxy
::
registerProxy
(
typeid
(
HarmonicBondForce
),
new
HarmonicBondForceProxy
());
testSerialization
();
}
catch
(
const
exception
&
e
)
{
...
...
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