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
f8c52d1b
Commit
f8c52d1b
authored
Apr 12, 2014
by
John Chodera (MSKCC)
Browse files
Added serialization of more properties, as well as unit test extensions for these additions.
parent
4255709b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
1 deletion
+57
-1
serialization/include/openmm/serialization/SerializationNode.h
...lization/include/openmm/serialization/SerializationNode.h
+22
-0
serialization/src/CustomNonbondedForceProxy.cpp
serialization/src/CustomNonbondedForceProxy.cpp
+1
-1
serialization/src/SerializationNode.cpp
serialization/src/SerializationNode.cpp
+26
-0
serialization/tests/TestSerializeCustomNonbondedForce.cpp
serialization/tests/TestSerializeCustomNonbondedForce.cpp
+8
-0
No files found.
serialization/include/openmm/serialization/SerializationNode.h
View file @
f8c52d1b
...
@@ -152,6 +152,28 @@ public:
...
@@ -152,6 +152,28 @@ public:
* @param value the value to set for the property
* @param value the value to set for the property
*/
*/
SerializationNode
&
setIntProperty
(
const
std
::
string
&
name
,
int
value
);
SerializationNode
&
setIntProperty
(
const
std
::
string
&
name
,
int
value
);
/**
* Get the property with a particular name, specified as an bool. If there is no property with
* the specified name, an exception is thrown.
*
* @param name the name of the property to get
*/
int
getBoolProperty
(
const
std
::
string
&
name
)
const
;
/**
* Get the property with a particular name, specified as a bool. If there is no property with
* the specified name, a default value is returned instead.
*
* @param name the name of the property to get
* @param defaultValue the value to return if the specified property does not exist
*/
int
getBoolProperty
(
const
std
::
string
&
name
,
bool
defaultValue
)
const
;
/**
* Set the value of a property, specified as a bool.
*
* @param name the name of the property to set
* @param value the value to set for the property
*/
SerializationNode
&
setBoolProperty
(
const
std
::
string
&
name
,
bool
value
);
/**
/**
* Get the property with a particular name, specified as a double. If there is no property with
* Get the property with a particular name, specified as a double. If there is no property with
* the specified name, an exception is thrown.
* the specified name, an exception is thrown.
...
...
serialization/src/CustomNonbondedForceProxy.cpp
View file @
f8c52d1b
...
@@ -90,7 +90,7 @@ void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode&
...
@@ -90,7 +90,7 @@ void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode&
for
(
std
::
set
<
int
>::
iterator
it
=
set1
.
begin
();
it
!=
set1
.
end
();
++
it
)
for
(
std
::
set
<
int
>::
iterator
it
=
set1
.
begin
();
it
!=
set1
.
end
();
++
it
)
set1node
.
createChildNode
(
"Particle"
).
setIntProperty
(
"index"
,
*
it
);
set1node
.
createChildNode
(
"Particle"
).
setIntProperty
(
"index"
,
*
it
);
SerializationNode
&
set2node
=
interactionGroup
.
createChildNode
(
"Set2"
);
SerializationNode
&
set2node
=
interactionGroup
.
createChildNode
(
"Set2"
);
for
(
std
::
set
<
int
>::
iterator
it
=
set
1
.
begin
();
it
!=
set
1
.
end
();
++
it
)
for
(
std
::
set
<
int
>::
iterator
it
=
set
2
.
begin
();
it
!=
set
2
.
end
();
++
it
)
set2node
.
createChildNode
(
"Particle"
).
setIntProperty
(
"index"
,
*
it
);
set2node
.
createChildNode
(
"Particle"
).
setIntProperty
(
"index"
,
*
it
);
}
}
}
}
...
...
serialization/src/SerializationNode.cpp
View file @
f8c52d1b
...
@@ -121,6 +121,32 @@ SerializationNode& SerializationNode::setIntProperty(const string& name, int val
...
@@ -121,6 +121,32 @@ SerializationNode& SerializationNode::setIntProperty(const string& name, int val
return
*
this
;
return
*
this
;
}
}
int
SerializationNode
::
getBoolProperty
(
const
string
&
name
)
const
{
map
<
string
,
string
>::
const_iterator
iter
=
properties
.
find
(
name
);
if
(
iter
==
properties
.
end
())
throw
OpenMMException
(
"Unknown property '"
+
name
+
"' in node '"
+
getName
()
+
"'"
);
bool
value
;
stringstream
(
iter
->
second
)
>>
value
;
return
value
;
}
int
SerializationNode
::
getBoolProperty
(
const
string
&
name
,
bool
defaultValue
)
const
{
map
<
string
,
string
>::
const_iterator
iter
=
properties
.
find
(
name
);
if
(
iter
==
properties
.
end
())
return
defaultValue
;
bool
value
;
stringstream
(
iter
->
second
)
>>
value
;
return
value
;
}
SerializationNode
&
SerializationNode
::
setBoolProperty
(
const
string
&
name
,
bool
value
)
{
stringstream
s
;
s
<<
value
;
properties
[
name
]
=
s
.
str
();
return
*
this
;
}
double
SerializationNode
::
getDoubleProperty
(
const
string
&
name
)
const
{
double
SerializationNode
::
getDoubleProperty
(
const
string
&
name
)
const
{
map
<
string
,
string
>::
const_iterator
iter
=
properties
.
find
(
name
);
map
<
string
,
string
>::
const_iterator
iter
=
properties
.
find
(
name
);
if
(
iter
==
properties
.
end
())
if
(
iter
==
properties
.
end
())
...
...
serialization/tests/TestSerializeCustomNonbondedForce.cpp
View file @
f8c52d1b
...
@@ -38,6 +38,12 @@
...
@@ -38,6 +38,12 @@
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
void
show_set
(
std
::
set
<
int
>
&
set
)
{
for
(
std
::
set
<
int
>::
iterator
it
=
set
.
begin
();
it
!=
set
.
end
();
it
++
)
cout
<<
*
it
<<
" "
;
cout
<<
endl
;
}
void
testSerialization
()
{
void
testSerialization
()
{
// Create a Force.
// Create a Force.
...
@@ -124,6 +130,8 @@ void testSerialization() {
...
@@ -124,6 +130,8 @@ void testSerialization() {
ASSERT_EQUAL
(
force
.
getNumInteractionGroups
(),
force2
.
getNumInteractionGroups
());
ASSERT_EQUAL
(
force
.
getNumInteractionGroups
(),
force2
.
getNumInteractionGroups
());
std
::
set
<
int
>
set1c
,
set2c
;
std
::
set
<
int
>
set1c
,
set2c
;
force2
.
getInteractionGroupParameters
(
0
,
set1c
,
set2c
);
force2
.
getInteractionGroupParameters
(
0
,
set1c
,
set2c
);
ASSERT_EQUAL_CONTAINERS
(
set1
,
set1c
);
ASSERT_EQUAL_CONTAINERS
(
set2
,
set2c
);
}
}
int
main
()
{
int
main
()
{
...
...
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