Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimStore: Fix issue with internalized snapshot box vectors #1086

Merged
merged 2 commits into from
Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions openpathsampling/engines/features/box_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

dimensions = ['n_spatial']

schema_entries = [
('box_vectors', 'ndarray.float32({n_spatial},{n_spatial})')
]


def netcdfplus_init(store):
store.create_variable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import numpy as np
import openpathsampling as paths
from openpathsampling.integration_tools import unit

from openpathsampling.tests.test_helpers import data_filename

Expand Down Expand Up @@ -48,21 +49,46 @@ def _make_gromacs_snap(self):
)
return snap

def _make_gromacs_int_snap(self):
snap = self._make_gromacs_snap()
return snap.internalize()

def _make_openmm_snap(self):
mm = pytest.importorskip('simtk.openmm')
traj_file = data_filename('ala_small_traj.pdb')
traj = paths.engines.openmm.tools.ops_load_trajectory(traj_file)
snap = traj[0]
return snap

@pytest.mark.parametrize('integration', ['gromacs', 'openmm'])
@pytest.mark.parametrize('integration', ['gromacs', 'openmm',
'gromacs_int'])
def test_integration(self, integration):
make_snap = {
'gromacs': self._make_gromacs_snap,
'openmm': self._make_openmm_snap,
'gromacs_int': self._make_gromacs_int_snap,
}[integration]

snap = make_snap()

def get_velocities(snap):
return snap.velocities

def get_box_vectors(snap):
return snap.box_vectors

if integration == 'openmm':
# already skipping if OpenMM isn't available, so we can use unit
nm = unit.nanometer
ps = unit.picosecond
def extract_unit(func, units):
def inner(snap):
return func(snap).value_in_unit(units)
return inner

get_velocities = extract_unit(get_velocities, nm/ps)
get_box_vectors = extract_unit(get_box_vectors, nm)

storage = self._make_storage(mode='w')
assert not storage.backend.has_table('snapshot0')
storage.save(snap)
Expand All @@ -73,6 +99,9 @@ def test_integration(self, integration):
assert storage.backend.has_table('snapshot0')
snap2 = storage.snapshots.tables['snapshot0'][0]

assert not snap is snap2
np.testing.assert_array_equal(snap.xyz, snap2.xyz)


np.testing.assert_array_equal(get_velocities(snap),
get_velocities(snap2))
np.testing.assert_array_equal(get_box_vectors(snap),
get_box_vectors(snap2))