Skip to content

Commit 76ea517

Browse files
committed
Prep tests for CVs
1 parent 77fa5ce commit 76ea517

3 files changed

Lines changed: 56 additions & 29 deletions

File tree

‎paths_cli/tests/wizard/conftest.py‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import pytest
2+
3+
import openpathsampling as paths
4+
import mdtraj as md
5+
6+
@pytest.fixture
7+
def ad_openmm(tmpdir):
8+
"""
9+
Provide directory with files to start alanine depeptide sim in OpenMM
10+
"""
11+
mm = pytest.importorskip('simtk.openmm')
12+
u = pytest.importorskip('simtk.unit')
13+
openmmtools = pytest.importorskip('openmmtools')
14+
md = pytest.importorskip('mdtraj')
15+
testsystem = openmmtools.testsystems.AlanineDipeptideVacuum()
16+
integrator = openmmtools.integrators.VVVRIntegrator(
17+
300 * u.kelvin,
18+
1.0 / u.picosecond,
19+
2.0 * u.femtosecond
20+
)
21+
traj = md.Trajectory([testsystem.positions.value_in_unit(u.nanometer)],
22+
topology=testsystem.mdtraj_topology)
23+
files = {'integrator.xml': integrator,
24+
'system.xml': testsystem.system}
25+
with tmpdir.as_cwd():
26+
for fname, obj in files.items():
27+
with open(fname, mode='w') as f:
28+
f.write(mm.XmlSerializer.serialize(obj))
29+
30+
traj.save('ad.pdb')
31+
32+
return tmpdir
33+
34+
@pytest.fixture
35+
def ad_engine(ad_openmm):
36+
with ad_openmm.as_cwd():
37+
pdb = md.load('ad.pdb')
38+
topology = paths.engines.openmm.topology.MDTrajTopology(
39+
pdb.topology
40+
)
41+
engine = paths.engines.openmm.Engine(
42+
system='system.xml',
43+
integrator='integrator.xml',
44+
topology=topology,
45+
options={'n_steps_per_frame': 10,
46+
'n_frames_max': 10000}
47+
).named('ad_engine')
48+
return engine
49+
50+
# TODO: add fixtures for all the AD things: CVs, states

‎paths_cli/tests/wizard/mock_wizard.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ def print(self, content=""):
2828

2929
def input(self, content):
3030
self.input_call_count += 1
31-
user_input = next(self._input_iter)
31+
try:
32+
user_input = next(self._input_iter)
33+
except StopIteration as e:
34+
print(self.log_text)
35+
raise e
36+
3237
self.log.append(content + " " + user_input)
3338
return user_input
3439

‎paths_cli/tests/wizard/test_openmm.py‎

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,6 @@
77
_load_openmm_xml, _load_topology, openmm
88
)
99

10-
@pytest.fixture
11-
def ad_openmm(tmpdir):
12-
"""
13-
Provide directory with files to start alanine depeptide sim in OpenMM
14-
"""
15-
mm = pytest.importorskip('simtk.openmm')
16-
u = pytest.importorskip('simtk.unit')
17-
openmmtools = pytest.importorskip('openmmtools')
18-
md = pytest.importorskip('mdtraj')
19-
testsystem = openmmtools.testsystems.AlanineDipeptideVacuum()
20-
integrator = openmmtools.integrators.VVVRIntegrator(
21-
300 * u.kelvin,
22-
1.0 / u.picosecond,
23-
2.0 * u.femtosecond
24-
)
25-
traj = md.Trajectory([testsystem.positions.value_in_unit(u.nanometer)],
26-
topology=testsystem.mdtraj_topology)
27-
files = {'integrator.xml': integrator,
28-
'system.xml': testsystem.system}
29-
with tmpdir.as_cwd():
30-
for fname, obj in files.items():
31-
with open(fname, mode='w') as f:
32-
f.write(mm.XmlSerializer.serialize(obj))
33-
34-
traj.save('ad.pdb')
35-
36-
return tmpdir
37-
3810

3911
@pytest.mark.parametrize('obj_type', ['system', 'integrator', 'foo'])
4012
def test_load_openmm_xml(ad_openmm, obj_type):

0 commit comments

Comments
 (0)