Skip to content

Commit 9e24afb

Browse files
authored
Merge pull request #5 from dwhswenson/example_plugins
Example plugins
2 parents c31f280 + b4903af commit 9e24afb

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

example_plugins/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Example Plugins
2+
3+
This directory includes a few example plugins for the OpenPathSampling CLI.
4+
There are various reasons these are not included in the default CLI, including:
5+
6+
* they reproduce existing functionality, and would add confusion to the user
7+
experience (`tps.py`)
8+
* they don't fit into the overall philosophy of the CLI, which intends to
9+
provide individual tools instead of "one pot cooking" scripts that do
10+
everything in one go (`one_pot_tps.py`).
11+
12+
13+
We distribute them here mainly to provide additional examples so
14+
users/developers can write their own plugins. Distributing these also makes it
15+
easy for users to use these specific workflows, without adding confusion for
16+
all users by making too many commands.
17+
18+
To install a plugin, all you need to do is to copy (or symlink) the file here
19+
into your `~/.openpathsampling/cli-plugins/` directory.

example_plugins/one_pot_tps.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import click
2+
from paths_cli.parameters import (INPUT_FILE, OUTPUT_FILE, ENGINE, STATES,
3+
N_STEPS_MC, INIT_SNAP)
4+
from paths_cli.commands.visit_all import visit_all_main
5+
from paths_cli.commands.equilibrate import equilibrate_main
6+
from paths_cli.commands.pathsampling import path_sampling_main
7+
8+
9+
@click.command("one-pot-tps",
10+
short_help="Start from a single frame and end with full TPS")
11+
@INPUT_FILE.clicked(required=True)
12+
@OUTPUT_FILE.clicked(required=True)
13+
@STATES.clicked(required=True)
14+
@ENGINE.clicked(required=False)
15+
@click.option("--engine-hot", required=False,
16+
help="high temperature engine for initial trajectory")
17+
@INIT_SNAP.clicked(required=False)
18+
@N_STEPS_MC
19+
def one_pot_tps(input_file, output_file, state, nsteps, engine, engine_hot,
20+
init_frame):
21+
storage = INPUT_FILE.get(input_file)
22+
engine = ENGINE.get(storage, engine)
23+
engine_hot = engine if engine_hot is None else ENGINE.get(storage,
24+
engine_hot)
25+
one_pot_tps_main(output_storage=OUTPUT_FILE.get(output_file),
26+
states=STATES.get(storage, state),
27+
engine=engine,
28+
engine_hot=engine_hot,
29+
initial_frame=INIT_SNAP.get(storage, init_frame),
30+
nsteps=nsteps)
31+
32+
33+
def one_pot_tps_main(output_storage, states, engine, engine_hot,
34+
initial_frame, nsteps):
35+
import openpathsampling as paths
36+
network = paths.TPSNetwork.from_states_all_to_all(states)
37+
scheme = paths.OneWayShootingMoveScheme(network=network,
38+
selector=paths.UniformSelector(),
39+
engine=engine)
40+
trajectory, _ = visit_all_main(None, states, engine_hot, initial_frame)
41+
equil_multiplier = 1
42+
equil_extra = 0
43+
equil_set, _ = equilibrate_main(None, scheme, trajectory,
44+
equil_multiplier, equil_extra)
45+
return path_sampling_main(output_storage, scheme, equil_set, nsteps)
46+
47+
CLI = one_pot_tps
48+
SECTION = "Workflow"
49+
REQUIRES_OPS = (1, 2)

example_plugins/tps.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import click
2+
from paths_cli.parameters import (
3+
INPUT_FILE, OUTPUT_FILE, ENGINE, STATES, INIT_CONDS, N_STEPS_MC
4+
)
5+
6+
import openpathsampling as paths
7+
8+
@click.command(
9+
"tps",
10+
short_help="Run transition path sampling simulations",
11+
)
12+
@INPUT_FILE.clicked(required=True)
13+
@OUTPUT_FILE.clicked(required=True)
14+
@STATES.clicked(required=True)
15+
@ENGINE.clicked(required=False)
16+
@INIT_CONDS.clicked(required=False)
17+
@N_STEPS_MC
18+
def tps(input_file, engine, state, init_traj, output_file, nsteps):
19+
"""Run transition path sampling using setup in INPUT_FILE."""
20+
storage = INPUT_FILE.get(input_file)
21+
tps_main(engine=ENGINE.get(storage, engine),
22+
states=[STATES.get(storage, s) for s in state],
23+
init_traj=INIT_CONDS.get(storage, init_traj),
24+
output_storage=OUTPUT_FILE.get(output_file),
25+
n_steps=nsteps)
26+
27+
28+
def tps_main(engine, states, init_traj, output_storage, n_steps):
29+
network = paths.TPSNetwork(initial_states=states, final_states=states)
30+
scheme = paths.OneWayShootingMoveScheme(network, engine=engine)
31+
initial_conditions = \
32+
scheme.initial_conditions_from_trajectories(init_traj)
33+
simulation = paths.PathSampling(
34+
storage=output_storage,
35+
move_scheme=scheme,
36+
sample_set=initial_conditions
37+
)
38+
simulation.run(n_steps)
39+
output_storage.tags['final_conditions'] = simulation.sample_set
40+
return simulation.sample_set, simulation
41+
42+
43+
CLI = tps
44+
SECTION = "Simulation"
45+
46+
if __name__ == "__main__":
47+
tps()

0 commit comments

Comments
 (0)