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
fd569d79
Unverified
Commit
fd569d79
authored
Jul 09, 2018
by
peastman
Committed by
GitHub
Jul 09, 2018
Browse files
Merge pull request #2115 from peastman/offsetxml
Serialization of parameter offsets
parents
8f8aa247
6aa09a5a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
4 deletions
+59
-4
serialization/src/NonbondedForceProxy.cpp
serialization/src/NonbondedForceProxy.cpp
+27
-3
serialization/tests/TestSerializeNonbondedForce.cpp
serialization/tests/TestSerializeNonbondedForce.cpp
+32
-1
No files found.
serialization/src/NonbondedForceProxy.cpp
View file @
fd569d79
...
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-201
4
Stanford University and the Authors. *
* Portions copyright (c) 2010-201
8
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -42,7 +42,7 @@ NonbondedForceProxy::NonbondedForceProxy() : SerializationProxy("NonbondedForce"
}
void
NonbondedForceProxy
::
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
{
node
.
setIntProperty
(
"version"
,
2
);
node
.
setIntProperty
(
"version"
,
3
);
const
NonbondedForce
&
force
=
*
reinterpret_cast
<
const
NonbondedForce
*>
(
object
);
node
.
setIntProperty
(
"forceGroup"
,
force
.
getForceGroup
());
node
.
setIntProperty
(
"method"
,
(
int
)
force
.
getNonbondedMethod
());
...
...
@@ -65,6 +65,22 @@ void NonbondedForceProxy::serialize(const void* object, SerializationNode& node)
node
.
setIntProperty
(
"ljny"
,
ny
);
node
.
setIntProperty
(
"ljnz"
,
nz
);
node
.
setIntProperty
(
"recipForceGroup"
,
force
.
getReciprocalSpaceForceGroup
());
SerializationNode
&
particleOffsets
=
node
.
createChildNode
(
"ParticleOffsets"
);
for
(
int
i
=
0
;
i
<
force
.
getNumParticleParameterOffsets
();
i
++
)
{
int
particle
;
double
chargeScale
,
sigmaScale
,
epsilonScale
;
string
parameter
;
force
.
getParticleParameterOffset
(
i
,
parameter
,
particle
,
chargeScale
,
sigmaScale
,
epsilonScale
);
particleOffsets
.
createChildNode
(
"Offset"
).
setStringProperty
(
"parameter"
,
parameter
).
setIntProperty
(
"particle"
,
particle
).
setDoubleProperty
(
"q"
,
chargeScale
).
setDoubleProperty
(
"sig"
,
sigmaScale
).
setDoubleProperty
(
"eps"
,
epsilonScale
);
}
SerializationNode
&
exceptionOffsets
=
node
.
createChildNode
(
"ExceptionOffsets"
);
for
(
int
i
=
0
;
i
<
force
.
getNumExceptionParameterOffsets
();
i
++
)
{
int
exception
;
double
chargeProdScale
,
sigmaScale
,
epsilonScale
;
string
parameter
;
force
.
getExceptionParameterOffset
(
i
,
parameter
,
exception
,
chargeProdScale
,
sigmaScale
,
epsilonScale
);
exceptionOffsets
.
createChildNode
(
"Offset"
).
setStringProperty
(
"parameter"
,
parameter
).
setIntProperty
(
"exception"
,
exception
).
setDoubleProperty
(
"q"
,
chargeProdScale
).
setDoubleProperty
(
"sig"
,
sigmaScale
).
setDoubleProperty
(
"eps"
,
epsilonScale
);
}
SerializationNode
&
particles
=
node
.
createChildNode
(
"Particles"
);
for
(
int
i
=
0
;
i
<
force
.
getNumParticles
();
i
++
)
{
double
charge
,
sigma
,
epsilon
;
...
...
@@ -82,7 +98,7 @@ void NonbondedForceProxy::serialize(const void* object, SerializationNode& node)
void
*
NonbondedForceProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
int
version
=
node
.
getIntProperty
(
"version"
);
if
(
version
<
1
||
version
>
2
)
if
(
version
<
1
||
version
>
3
)
throw
OpenMMException
(
"Unsupported version number"
);
NonbondedForce
*
force
=
new
NonbondedForce
();
try
{
...
...
@@ -107,6 +123,14 @@ void* NonbondedForceProxy::deserialize(const SerializationNode& node) const {
force
->
setLJPMEParameters
(
alpha
,
nx
,
ny
,
nz
);
}
force
->
setReciprocalSpaceForceGroup
(
node
.
getIntProperty
(
"recipForceGroup"
,
-
1
));
if
(
version
>=
3
)
{
const
SerializationNode
&
particleOffsets
=
node
.
getChildNode
(
"ParticleOffsets"
);
for
(
auto
&
offset
:
particleOffsets
.
getChildren
())
force
->
addParticleParameterOffset
(
offset
.
getStringProperty
(
"parameter"
),
offset
.
getIntProperty
(
"particle"
),
offset
.
getDoubleProperty
(
"q"
),
offset
.
getDoubleProperty
(
"sig"
),
offset
.
getDoubleProperty
(
"eps"
));
const
SerializationNode
&
exceptionOffsets
=
node
.
getChildNode
(
"ExceptionOffsets"
);
for
(
auto
&
offset
:
exceptionOffsets
.
getChildren
())
force
->
addExceptionParameterOffset
(
offset
.
getStringProperty
(
"parameter"
),
offset
.
getIntProperty
(
"exception"
),
offset
.
getDoubleProperty
(
"q"
),
offset
.
getDoubleProperty
(
"sig"
),
offset
.
getDoubleProperty
(
"eps"
));
}
const
SerializationNode
&
particles
=
node
.
getChildNode
(
"Particles"
);
for
(
auto
&
particle
:
particles
.
getChildren
())
force
->
addParticle
(
particle
.
getDoubleProperty
(
"q"
),
particle
.
getDoubleProperty
(
"sig"
),
particle
.
getDoubleProperty
(
"eps"
));
...
...
serialization/tests/TestSerializeNonbondedForce.cpp
View file @
fd569d79
...
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-201
4
Stanford University and the Authors. *
* Portions copyright (c) 2010-201
8
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -61,6 +61,8 @@ void testSerialization() {
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
);
force
.
addParticleParameterOffset
(
"scale1"
,
2
,
1.5
,
2.0
,
2.5
);
force
.
addExceptionParameterOffset
(
"scale2"
,
1
,
-
0.1
,
-
0.2
,
-
0.3
);
// Serialize and then deserialize it.
...
...
@@ -80,6 +82,9 @@ void testSerialization() {
ASSERT_EQUAL
(
force
.
getReactionFieldDielectric
(),
force2
.
getReactionFieldDielectric
());
ASSERT_EQUAL
(
force
.
getUseDispersionCorrection
(),
force2
.
getUseDispersionCorrection
());
ASSERT_EQUAL
(
force
.
getNumParticles
(),
force2
.
getNumParticles
());
ASSERT_EQUAL
(
force
.
getNumExceptions
(),
force2
.
getNumExceptions
());
ASSERT_EQUAL
(
force
.
getNumParticleParameterOffsets
(),
force2
.
getNumParticleParameterOffsets
());
ASSERT_EQUAL
(
force
.
getNumExceptionParameterOffsets
(),
force2
.
getNumExceptionParameterOffsets
());
double
alpha2
;
int
nx2
,
ny2
,
nz2
;
force2
.
getPMEParameters
(
alpha2
,
nx2
,
ny2
,
nz2
);
...
...
@@ -94,6 +99,32 @@ void testSerialization() {
ASSERT_EQUAL
(
dnx
,
dnx2
);
ASSERT_EQUAL
(
dny
,
dny2
);
ASSERT_EQUAL
(
dnz
,
dnz2
);
for
(
int
i
=
0
;
i
<
force
.
getNumParticleParameterOffsets
();
i
++
)
{
int
index1
,
index2
;
string
param1
,
param2
;
double
charge1
,
sigma1
,
epsilon1
;
double
charge2
,
sigma2
,
epsilon2
;
force
.
getParticleParameterOffset
(
i
,
param1
,
index1
,
charge1
,
sigma1
,
epsilon1
);
force2
.
getParticleParameterOffset
(
i
,
param2
,
index2
,
charge2
,
sigma2
,
epsilon2
);
ASSERT_EQUAL
(
index1
,
index1
);
ASSERT_EQUAL
(
param1
,
param2
);
ASSERT_EQUAL
(
charge1
,
charge2
);
ASSERT_EQUAL
(
sigma1
,
sigma2
);
ASSERT_EQUAL
(
epsilon1
,
epsilon2
);
}
for
(
int
i
=
0
;
i
<
force
.
getNumExceptionParameterOffsets
();
i
++
)
{
int
index1
,
index2
;
string
param1
,
param2
;
double
charge1
,
sigma1
,
epsilon1
;
double
charge2
,
sigma2
,
epsilon2
;
force
.
getExceptionParameterOffset
(
i
,
param1
,
index1
,
charge1
,
sigma1
,
epsilon1
);
force2
.
getExceptionParameterOffset
(
i
,
param2
,
index2
,
charge2
,
sigma2
,
epsilon2
);
ASSERT_EQUAL
(
index1
,
index1
);
ASSERT_EQUAL
(
param1
,
param2
);
ASSERT_EQUAL
(
charge1
,
charge2
);
ASSERT_EQUAL
(
sigma1
,
sigma2
);
ASSERT_EQUAL
(
epsilon1
,
epsilon2
);
}
for
(
int
i
=
0
;
i
<
force
.
getNumParticles
();
i
++
)
{
double
charge1
,
sigma1
,
epsilon1
;
double
charge2
,
sigma2
,
epsilon2
;
...
...
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