Repository navigation
Expand file tree
/
Copy pathtest_features.py
More file actions
71 lines (54 loc) · 2.33 KB
/
Copy pathtest_features.py
File metadata and controls
71 lines (54 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from __future__ import absolute_import
from builtins import hex
from builtins import object
import pytest
from .test_helpers import u
import logging
import numpy as np
import numpy.testing as npt
try:
import openmmtools as omt
except ImportError:
omt = None
import openpathsampling as paths
import openpathsampling.engines.toy as toy_engine
import openpathsampling.engines.openmm as omm_engine
quiet_loggers = ["initialization", "ensemble", "netcdfplus.objects",
"netcdfplus.netcdfplus", "pathmover", "netcdfplus.base"]
for logger in quiet_loggers:
logging.getLogger("openpathsampling."+logger).setLevel(logging.CRITICAL)
class TestFeatures(object):
def test_copy_with_replacement_toy(self):
# test a toy snapshot
init_coord = np.array([1.0, 2.0])
init_vel = np.array([3.0, 4.0])
rep_vel = np.array([3.0, 1.0])
toy_snap = toy_engine.Snapshot(
coordinates=init_coord, velocities=init_vel)
toy_copy = toy_snap.copy_with_replacement(velocities=rep_vel)
assert(toy_snap.velocities[1] == 4.0)
assert(toy_copy.velocities[1] == 1.0)
def test_copy_with_replacement_openmm(self):
if not paths.integration_tools.HAS_OPENMM or omt is None:
pytest.skip()
# test an openmm snapshot
sys = omt.testsystems.AlanineDipeptideVacuum()
omm_snap = omm_engine.snapshot_from_testsystem(sys)
rep_vel = omm_snap.velocities * 2.0
omm_copy = omm_snap.copy_with_replacement(
velocities=rep_vel)
npt.assert_allclose(omm_copy.velocities, rep_vel)
assert(hex(id(omm_snap.kinetics)) != hex(id(omm_copy.kinetics)))
assert(hex(id(omm_snap.statics)) == hex(id(omm_copy.statics)))
omm_copy = omm_snap.copy_with_replacement(
coordinates=[1.0, 2.0, 3.0] * u.nanometer,
box_vectors=[1.0, 1.0, 1.0] * u.nanometer)
assert(hex(id(omm_snap.kinetics)) == hex(id(omm_copy.kinetics)))
assert(hex(id(omm_snap.statics)) != hex(id(omm_copy.statics)))
def test_parameter_error(self):
init_coord = np.array([1.0, 2.0])
init_vel = np.array([3.0, 4.0])
toy_snap = toy_engine.Snapshot(
coordinates=init_coord, velocities=init_vel)
with pytest.raises(TypeError):
toy_snap.copy_with_replacement(dummy=0)