Skip to content

Commit

Permalink
Merge pull request #484 from jhprinz/fixboxvectors
Browse files Browse the repository at this point in the history
fix setting box_vectors
  • Loading branch information
dwhswenson committed May 19, 2016
2 parents efe4149 + c2d94b4 commit 5e03a00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion openpathsampling/engines/openmm/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,19 @@ def _changed(self):

@current_snapshot.setter
def current_snapshot(self, snapshot):

self.check_snapshot_type(snapshot)

if snapshot is not self._current_snapshot:
if snapshot.coordinates is not None:
self.simulation.context.setPositions(snapshot.coordinates)

if snapshot.box_vectors is not None:
self.simulation.context.setPeriodicBoxVectors(
snapshot.box_vectors[0],
snapshot.box_vectors[1],
snapshot.box_vectors[2]
)

if snapshot.velocities is not None:
self.simulation.context.setVelocities(snapshot.velocities)

Expand Down
6 changes: 5 additions & 1 deletion openpathsampling/tests/testopenmmengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,21 @@ def test_snapshot_set(self):
)
testvel.append([0.1*i, 0.1*i, 0.1*i])

testbvecs = 5.0 * np.identity(3)

self.engine.current_snapshot = peng.Snapshot.construct(
coordinates=np.array(testpos) * u.nanometers,
box_vectors=np.zeros((3, 3)),
box_vectors=np.array(testbvecs) * u.nanometers,
velocities=np.array(testvel) * u.nanometers / u.picoseconds
)
state = self.engine.simulation.context.getState(getPositions=True,
getVelocities=True)
sim_coords = state.getPositions(asNumpy=True) / u.nanometers
sim_bvecs = state.getPeriodicBoxVectors(asNumpy=True) / u.nanometers
sim_vels = state.getVelocities(asNumpy=True) / (u.nanometers/u.picoseconds)

np.testing.assert_almost_equal(testpos, sim_coords, decimal=5)
np.testing.assert_almost_equal(testbvecs, sim_bvecs, decimal=5)
np.testing.assert_almost_equal(testvel, sim_vels, decimal=5)

def test_generate_next_frame(self):
Expand Down

0 comments on commit 5e03a00

Please sign in to comment.