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
5d9b6481
Commit
5d9b6481
authored
Sep 22, 2010
by
Peter Eastman
Browse files
Continuing to implement serialization
parent
6ee040ff
Changes
24
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
281 additions
and
2 deletions
+281
-2
serialization/tests/TestSerializeHarmonicBondForce.cpp
serialization/tests/TestSerializeHarmonicBondForce.cpp
+2
-2
serialization/tests/TestSerializeNonbondedForce.cpp
serialization/tests/TestSerializeNonbondedForce.cpp
+105
-0
serialization/tests/TestSerializePeriodicTorsionForce.cpp
serialization/tests/TestSerializePeriodicTorsionForce.cpp
+86
-0
serialization/tests/TestSerializeRBTorsionForce.cpp
serialization/tests/TestSerializeRBTorsionForce.cpp
+88
-0
No files found.
serialization/tests/TestSerializeHarmonicBondForce.cpp
View file @
5d9b6481
...
...
@@ -53,7 +53,7 @@ void testSerialization() {
XmlSerializer
::
serialize
<
HarmonicBondForce
>
(
&
force
,
"Force"
,
buffer
);
HarmonicBondForce
*
copy
=
XmlSerializer
::
deserialize
<
HarmonicBondForce
>
(
buffer
);
// Compare the two
system
s to see if they are identical.
// Compare the two
force
s to see if they are identical.
HarmonicBondForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getNumBonds
(),
force2
.
getNumBonds
());
...
...
@@ -61,7 +61,7 @@ void testSerialization() {
int
a1
,
a2
,
b1
,
b2
;
double
da
,
db
,
ka
,
kb
;
force
.
getBondParameters
(
i
,
a1
,
a2
,
da
,
ka
);
force
.
getBondParameters
(
i
,
b1
,
b2
,
db
,
kb
);
force
2
.
getBondParameters
(
i
,
b1
,
b2
,
db
,
kb
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
da
,
db
);
...
...
serialization/tests/TestSerializeNonbondedForce.cpp
0 → 100644
View file @
5d9b6481
/* -------------------------------------------------------------------------- *
* 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/NonbondedForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
void
testSerialization
()
{
// Create a Force.
NonbondedForce
force
;
force
.
setNonbondedMethod
(
NonbondedForce
::
CutoffPeriodic
);
force
.
setCutoffDistance
(
2.0
);
force
.
setEwaldErrorTolerance
(
1e-3
);
force
.
setReactionFieldDielectric
(
50.0
);
force
.
setUseDispersionCorrection
(
false
);
force
.
addParticle
(
1
,
0.1
,
0.01
);
force
.
addParticle
(
0.5
,
0.2
,
0.02
);
force
.
addParticle
(
-
0.5
,
0.3
,
0.03
);
force
.
addException
(
0
,
1
,
2
,
0.5
,
0.1
);
force
.
addException
(
1
,
2
,
0.2
,
0.4
,
0.2
);
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
NonbondedForce
>
(
&
force
,
"Force"
,
buffer
);
NonbondedForce
*
copy
=
XmlSerializer
::
deserialize
<
NonbondedForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
NonbondedForce
&
force2
=
*
copy
;
ASSERT_EQUAL
(
force
.
getNonbondedMethod
(),
force2
.
getNonbondedMethod
());
ASSERT_EQUAL
(
force
.
getCutoffDistance
(),
force2
.
getCutoffDistance
());
ASSERT_EQUAL
(
force
.
getEwaldErrorTolerance
(),
force2
.
getEwaldErrorTolerance
());
ASSERT_EQUAL
(
force
.
getReactionFieldDielectric
(),
force2
.
getReactionFieldDielectric
());
ASSERT_EQUAL
(
force
.
getUseDispersionCorrection
(),
force2
.
getUseDispersionCorrection
());
ASSERT_EQUAL
(
force
.
getNumParticles
(),
force2
.
getNumParticles
());
for
(
int
i
=
0
;
i
<
force
.
getNumParticles
();
i
++
)
{
double
charge1
,
sigma1
,
epsilon1
;
double
charge2
,
sigma2
,
epsilon2
;
force
.
getParticleParameters
(
i
,
charge1
,
sigma1
,
epsilon1
);
force2
.
getParticleParameters
(
i
,
charge2
,
sigma2
,
epsilon2
);
ASSERT_EQUAL
(
charge1
,
charge2
);
ASSERT_EQUAL
(
sigma1
,
sigma2
);
ASSERT_EQUAL
(
epsilon1
,
epsilon2
);
}
ASSERT_EQUAL
(
force
.
getNumExceptions
(),
force2
.
getNumExceptions
());
for
(
int
i
=
0
;
i
<
force
.
getNumExceptions
();
i
++
)
{
int
a1
,
a2
,
b1
,
b2
;
double
charge1
,
sigma1
,
epsilon1
;
double
charge2
,
sigma2
,
epsilon2
;
force
.
getExceptionParameters
(
i
,
a1
,
b1
,
charge1
,
sigma1
,
epsilon1
);
force2
.
getExceptionParameters
(
i
,
a2
,
b2
,
charge2
,
sigma2
,
epsilon2
);
ASSERT_EQUAL
(
a1
,
a2
);
ASSERT_EQUAL
(
b1
,
b2
);
ASSERT_EQUAL
(
charge1
,
charge2
);
ASSERT_EQUAL
(
sigma1
,
sigma2
);
ASSERT_EQUAL
(
epsilon1
,
epsilon2
);
}
}
int
main
()
{
try
{
testSerialization
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
serialization/tests/TestSerializePeriodicTorsionForce.cpp
0 → 100644
View file @
5d9b6481
/* -------------------------------------------------------------------------- *
* 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/PeriodicTorsionForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
void
testSerialization
()
{
// Create a Force.
PeriodicTorsionForce
force
;
force
.
addTorsion
(
0
,
1
,
2
,
3
,
2
,
1.0
,
2.0
);
force
.
addTorsion
(
0
,
2
,
3
,
4
,
2
,
2.0
,
2.1
);
force
.
addTorsion
(
2
,
3
,
4
,
7
,
1
,
3.0
,
2.2
);
force
.
addTorsion
(
5
,
1
,
2
,
3
,
3
,
4.0
,
2.3
);
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
PeriodicTorsionForce
>
(
&
force
,
"Force"
,
buffer
);
PeriodicTorsionForce
*
copy
=
XmlSerializer
::
deserialize
<
PeriodicTorsionForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
PeriodicTorsionForce
&
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
,
perioda
,
periodb
;
double
phasea
,
phaseb
,
ka
,
kb
;
force
.
getTorsionParameters
(
i
,
a1
,
a2
,
a3
,
a4
,
perioda
,
phasea
,
ka
);
force2
.
getTorsionParameters
(
i
,
b1
,
b2
,
b3
,
b4
,
periodb
,
phaseb
,
kb
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a3
,
b3
);
ASSERT_EQUAL
(
a4
,
b4
);
ASSERT_EQUAL
(
perioda
,
periodb
);
ASSERT_EQUAL
(
phasea
,
phaseb
);
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/TestSerializeRBTorsionForce.cpp
0 → 100644
View file @
5d9b6481
/* -------------------------------------------------------------------------- *
* 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/RBTorsionForce.h"
#include "openmm/serialization/XmlSerializer.h"
#include <iostream>
#include <sstream>
using
namespace
OpenMM
;
using
namespace
std
;
void
testSerialization
()
{
// Create a Force.
RBTorsionForce
force
;
force
.
addTorsion
(
0
,
1
,
2
,
3
,
0.1
,
0.2
,
0.3
,
0.4
,
0.5
,
0.6
);
force
.
addTorsion
(
0
,
2
,
3
,
4
,
0.2
,
0.3
,
0.4
,
0.5
,
0.6
,
0.7
);
force
.
addTorsion
(
2
,
3
,
4
,
7
,
-
1
,
-
2
,
-
3
,
1.1
,
2.2
,
3.3
);
// Serialize and then deserialize it.
stringstream
buffer
;
XmlSerializer
::
serialize
<
RBTorsionForce
>
(
&
force
,
"Force"
,
buffer
);
RBTorsionForce
*
copy
=
XmlSerializer
::
deserialize
<
RBTorsionForce
>
(
buffer
);
// Compare the two forces to see if they are identical.
RBTorsionForce
&
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
;
double
c0a
,
c0b
,
c1a
,
c1b
,
c2a
,
c2b
,
c3a
,
c3b
,
c4a
,
c4b
,
c5a
,
c5b
;
force
.
getTorsionParameters
(
i
,
a1
,
a2
,
a3
,
a4
,
c0a
,
c1a
,
c2a
,
c3a
,
c4a
,
c5a
);
force2
.
getTorsionParameters
(
i
,
b1
,
b2
,
b3
,
b4
,
c0b
,
c1b
,
c2b
,
c3b
,
c4b
,
c5b
);
ASSERT_EQUAL
(
a1
,
b1
);
ASSERT_EQUAL
(
a2
,
b2
);
ASSERT_EQUAL
(
a3
,
b3
);
ASSERT_EQUAL
(
a4
,
b4
);
ASSERT_EQUAL
(
c0a
,
c0b
);
ASSERT_EQUAL
(
c1a
,
c1b
);
ASSERT_EQUAL
(
c2a
,
c2b
);
ASSERT_EQUAL
(
c3a
,
c3b
);
ASSERT_EQUAL
(
c4a
,
c4b
);
ASSERT_EQUAL
(
c5a
,
c5b
);
}
}
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