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
fdf9b4ae
"platforms/reference/vscode:/vscode.git/clone" did not exist on "4cd3207e27a4e99cdac0fb12f01c6132eb29bb66"
Commit
fdf9b4ae
authored
Jun 17, 2011
by
Peter Eastman
Browse files
Added flag to Context::getState() to enforce periodic boundary conditions
parent
3ed430c5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
3 deletions
+38
-3
openmmapi/include/openmm/Context.h
openmmapi/include/openmm/Context.h
+4
-1
openmmapi/src/Context.cpp
openmmapi/src/Context.cpp
+34
-2
No files found.
openmmapi/include/openmm/Context.h
View file @
fdf9b4ae
...
@@ -120,8 +120,11 @@ public:
...
@@ -120,8 +120,11 @@ public:
*
*
* @param types the set of data types which should be stored in the State object. This
* @param types the set of data types which should be stored in the State object. This
* should be a union of DataType values, e.g. (State::Positions | State::Velocities).
* should be a union of DataType values, e.g. (State::Positions | State::Velocities).
* @param enforcePeriodicBox if false, the position of each particle will be whatever position
* is stored in the Context, regardless of periodic boundary conditions. If true, particle
* positions will be translated so the center of every molecule lies in the same periodic box.
*/
*/
State
getState
(
int
types
)
const
;
State
getState
(
int
types
,
bool
enforcePeriodicBox
=
false
)
const
;
/**
/**
* Set the current time of the simulation (in picoseconds).
* Set the current time of the simulation (in picoseconds).
*/
*/
...
...
openmmapi/src/Context.cpp
View file @
fdf9b4ae
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include "openmm/Context.h"
#include "openmm/Context.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/OpenMMException.h"
#include "openmm/OpenMMException.h"
#include <cmath>
using
namespace
OpenMM
;
using
namespace
OpenMM
;
using
namespace
std
;
using
namespace
std
;
...
@@ -77,7 +78,7 @@ Platform& Context::getPlatform() {
...
@@ -77,7 +78,7 @@ Platform& Context::getPlatform() {
return
impl
->
getPlatform
();
return
impl
->
getPlatform
();
}
}
State
Context
::
getState
(
int
types
)
const
{
State
Context
::
getState
(
int
types
,
bool
enforcePeriodicBox
)
const
{
State
state
(
impl
->
getTime
(),
impl
->
getSystem
().
getNumParticles
(),
types
);
State
state
(
impl
->
getTime
(),
impl
->
getSystem
().
getNumParticles
(),
types
);
Vec3
periodicBoxSize
[
3
];
Vec3
periodicBoxSize
[
3
];
impl
->
getPeriodicBoxVectors
(
periodicBoxSize
[
0
],
periodicBoxSize
[
1
],
periodicBoxSize
[
2
]);
impl
->
getPeriodicBoxVectors
(
periodicBoxSize
[
0
],
periodicBoxSize
[
1
],
periodicBoxSize
[
2
]);
...
@@ -95,8 +96,39 @@ State Context::getState(int types) const {
...
@@ -95,8 +96,39 @@ State Context::getState(int types) const {
for
(
map
<
string
,
double
>::
const_iterator
iter
=
impl
->
parameters
.
begin
();
iter
!=
impl
->
parameters
.
end
();
iter
++
)
for
(
map
<
string
,
double
>::
const_iterator
iter
=
impl
->
parameters
.
begin
();
iter
!=
impl
->
parameters
.
end
();
iter
++
)
state
.
updParameters
()[
iter
->
first
]
=
iter
->
second
;
state
.
updParameters
()[
iter
->
first
]
=
iter
->
second
;
}
}
if
(
types
&
State
::
Positions
)
if
(
types
&
State
::
Positions
)
{
impl
->
getPositions
(
state
.
updPositions
());
impl
->
getPositions
(
state
.
updPositions
());
if
(
enforcePeriodicBox
)
{
const
vector
<
vector
<
int
>
>&
molecules
=
impl
->
getMolecules
();
vector
<
Vec3
>&
positions
=
state
.
updPositions
();
for
(
int
i
=
0
;
i
<
(
int
)
molecules
.
size
();
i
++
)
{
// Find the molecule center.
Vec3
center
;
for
(
int
j
=
0
;
j
<
(
int
)
molecules
[
i
].
size
();
j
++
)
center
+=
positions
[
molecules
[
i
][
j
]];
center
*=
1.0
/
molecules
[
i
].
size
();
// Find the displacement to move it into the first periodic box.
int
xcell
=
(
int
)
floor
(
center
[
0
]
/
periodicBoxSize
[
0
][
0
]);
int
ycell
=
(
int
)
floor
(
center
[
1
]
/
periodicBoxSize
[
1
][
1
]);
int
zcell
=
(
int
)
floor
(
center
[
2
]
/
periodicBoxSize
[
2
][
2
]);
double
dx
=
xcell
*
periodicBoxSize
[
0
][
0
];
double
dy
=
ycell
*
periodicBoxSize
[
1
][
1
];
double
dz
=
zcell
*
periodicBoxSize
[
2
][
2
];
// Translate all the particles in the molecule.
for
(
int
j
=
0
;
j
<
(
int
)
molecules
[
i
].
size
();
j
++
)
{
Vec3
&
pos
=
positions
[
molecules
[
i
][
j
]];
pos
[
0
]
-=
dx
;
pos
[
1
]
-=
dy
;
pos
[
2
]
-=
dz
;
}
}
}
}
if
(
types
&
State
::
Velocities
)
if
(
types
&
State
::
Velocities
)
impl
->
getVelocities
(
state
.
updVelocities
());
impl
->
getVelocities
(
state
.
updVelocities
());
return
state
;
return
state
;
...
...
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