Skip to content

Commit f7cc88c

Browse files
committed
steps toward testing compile command
Currently, we don't seem to actually register the parsers, so it isn't working at all. But I think the basic outline of the test is in place.
1 parent 2bd0eea commit f7cc88c

7 files changed

Lines changed: 171 additions & 7 deletions

File tree

‎paths_cli/commands/compile.py‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from paths_cli.parsing.root_parser import parse
44
from paths_cli.parameters import OUTPUT_FILE
55
from paths_cli.errors import MissingIntegrationError
6+
from paths_cli import OPSCommandPlugin
67
import importlib
78

89
def import_module(module_name, format_type=None, install=None):
@@ -65,6 +66,9 @@ def compile_(input_file, output_file):
6566
storage = OUTPUT_FILE.get(output_file)
6667
storage.save(objs)
6768

68-
69-
CLI = compile_
70-
SECTION = "Debug"
69+
PLUGIN = OPSCommandPlugin(
70+
command=compile_,
71+
section="Debug",
72+
requires_ops=(1, 0),
73+
requires_cli=(0, 3)
74+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from paths_cli.tests.wizard.conftest import ad_openmm

‎paths_cli/tests/commands/test_compile.py‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from click.testing import CliRunner
33

44
import json
5+
import shutil
56

67
from paths_cli.commands.compile import *
78

@@ -46,11 +47,34 @@ def test_select_loader(ext):
4647
expected = load_yaml
4748

4849
assert select_loader("filename." + ext) is expected
49-
pass
5050

5151
def test_select_loader_error():
5252
with pytest.raises(RuntimeError, match="Unknown file extension"):
5353
select_loader('foo.bar')
5454

55-
def test_compile():
56-
pass
55+
def test_compile(ad_openmm, test_data_dir):
56+
runner = CliRunner()
57+
setup = test_data_dir / "setup.yml"
58+
shutil.copy2(str(setup), ad_openmm)
59+
with runner.isolated_filesystem(temp_dir=ad_openmm):
60+
import os
61+
cwd = os.getcwd()
62+
files = [setup, ad_openmm / "ad.pdb", ad_openmm / "system.xml",
63+
ad_openmm / "integrator.xml"]
64+
for filename in files:
65+
shutil.copy2(str(filename), cwd)
66+
pytest.skip() # TODO: right now we're not building the parsers
67+
result = runner.invoke(
68+
compile_,
69+
['setup.yml', '-o', str(ad_openmm / 'setup.db')]
70+
)
71+
assert result.exit_code == 0
72+
from openpathsampling.experimental.storage import (
73+
Storage, monkey_patch_all)
74+
st = Storage('setup.db', mode='r')
75+
76+
# smoke tests that we can reload things
77+
engine = st.engines['engine']
78+
phi = st.cvs['phi']
79+
C_7eq = st.volumes['C_7eq']
80+
pytest.skip()

‎paths_cli/tests/conftest.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
import openpathsampling as paths
44
import pytest
55

6+
import pathlib
7+
8+
@pytest.fixture
9+
def test_data_dir():
10+
tests = pathlib.Path(__file__).parent / "testdata"
11+
return tests
12+
13+
614
@pytest.fixture
715
def flat_engine():
816
pes = toys.LinearSlope([0, 0, 0], 0)

‎paths_cli/tests/testdata/setup.yml‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
engines:
2+
- type: openmm
3+
name: engine
4+
system: system.xml
5+
integrator: integrator.xml
6+
topology: ad.pdb
7+
n_steps_per_frame: 10
8+
n_frames_max: 10000
9+
10+
cvs:
11+
- name: phi
12+
type: mdtraj
13+
topology: ad.pdb
14+
period_min: -np.pi
15+
period_max: np.pi
16+
func: compute_dihedrals
17+
kwargs:
18+
atom_indices: [[4, 6, 8, 14]]
19+
- name: psi
20+
type: mdtraj
21+
topology: ad.pdb
22+
period_min: -np.pi
23+
period_max: np.pi
24+
func: compute_dihedrals
25+
kwargs:
26+
atom_indices: [[6, 8, 14, 16]]
27+
28+
states:
29+
- name: alpha_R
30+
type: intersection
31+
subvolumes:
32+
- type: cv-volume
33+
cv: psi
34+
lambda_min: -100 * np.pi / 180
35+
lambda_max: 0.0
36+
- type: cv-volume
37+
cv: phi
38+
lambda_min: -np.pi
39+
lambda_max: 0
40+
- name: C_7eq
41+
type: intersection
42+
subvolumes:
43+
- type: cv-volume
44+
cv: psi
45+
lambda_min: 100 * np.pi / 180
46+
lambda_max: 200 * np.pi / 180
47+
- type: cv-volume
48+
cv: phi
49+
lambda_min: -np.pi
50+
lambda_max: 0
51+
52+
#simulations:
53+
#- type: tps
54+
#name: tps-sim
55+
#initial_states:
56+
#- C_7eq
57+
#final_states:
58+
#- alpha_R
59+
##movescheme: # default scheme; doesn't need to be explicit
60+
##strategies:
61+
##- type: one-way-shooting
62+
##group: shooting
63+
##selector:
64+
##type: uniform
65+
#- type: tis
66+
#name: tis-sim
67+
#initial_state:
68+
#- alpha_R
69+
#final_state:
70+
#- C_7eq
71+
#interface_set:
72+
#cv: psi
73+
#min_lambdas: -100.0 * np.pi / 180
74+
#max_lambdas: np.array([0.0, 25.0, 50.0]) * np.pi / 180
75+
76+
networks:
77+
- type: tps
78+
name: tps-network
79+
initial_states:
80+
- C_7eq
81+
final_states:
82+
- alpha_R
83+
84+
#- type: tis
85+
#name: tis-network
86+
#initial_state: C_7eq
87+
#final_state: alpha_R
88+
#interface_set:
89+
#cv: psi
90+
#min_lambdas: -100.0 * np.pi / 180
91+
#max_lambdas: np.array([0.0, 25.0, 50.0]) * np.pi / 180
92+
93+
#- type: mistis
94+
#name: mistis-network
95+
#transitions:
96+
#- initial_state: C_7eq
97+
#final_state: alpha_R
98+
#interface_set:
99+
#cv: psi
100+
#min_lambdas: -100.0 * np.pi / 180
101+
#max_lambdas: np.array([0.0, 25.0, 50.0]) * np.pi / 180
102+
103+
#- type: mstis
104+
#name: mstis-network
105+
#transitions:
106+
#- initial_state: C_7eq
107+
#interface_set:
108+
#cv: psi
109+
#min_lambdas: -100.0 * np.pi / 180
110+
#max_lambdas: np.array([0.0, 25.0, 50.0]) * np.pi / 180
111+
#- initial_state: alpha_R
112+
#interface_set:
113+
#cv: psi
114+
## TODO need a negative psi here or allow decreasing transitions
115+
116+
117+
#moveschemes:
118+
#- type: scheme
119+
#name: tps-sim
120+
#network: tps-network
121+
#strategies:
122+
#- type: one-way
123+
#selector:
124+
#type: uniform
125+
#engine: engine
126+

‎paths_cli/tests/utils.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ def assert_url(url):
1616
# nice to give some better output to the user here.
1717
resp = urllib.request.urlopen(url)
1818
assert resp.status == 200
19-

‎paths_cli/tests/wizard/conftest.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
else:
1919
HAS_OPENMM = True
2020

21+
# TODO: this isn't wizard-specific, and should be moved somwhere more
22+
# generally useful (like, oh, maybe openpathsampling.tests.fixtures?)
2123
@pytest.fixture
2224
def ad_openmm(tmpdir):
2325
"""

0 commit comments

Comments
 (0)