Skip to content

Commit 9af1445

Browse files
committed
draft of bootstrapping command
1 parent 04b5053 commit 9af1445

File tree

1 file changed

+75
-28
lines changed

1 file changed

+75
-28
lines changed
Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,82 @@
1+
import click
2+
from paths_cli import OPSCommandPlugin
13
from paths_cli.parameters import (
2-
MULTI_INIT_SNAP, MULTI_NETWORK, OUTPUT_FILE, INPUT_FILE
4+
INIT_SNAP, MULTI_NETWORK, OUTPUT_FILE, INPUT_FILE, ENGINE
35
)
6+
from paths_cli.param_core import OPSStorageLoadSingle, Option
47

5-
@MULTI_INIT_SNAP.clicked()
8+
INIT_STATE = OPSStorageLoadSingle(
9+
param=Option("--initial-state", help="initial state"),
10+
store='volumes'
11+
)
12+
FINAL_STATE = OPSStorageLoadSingle(
13+
param=Option("--final-state", help="final state"),
14+
store='volumes'
15+
)
16+
17+
@click.command(
18+
"bootstrap-init",
19+
short_help="TIS interface set initial trajectories from a snapshot",
20+
)
21+
@INIT_STATE.clicked(required=True)
22+
@FINAL_STATE.clicked(required=True)
23+
@INIT_SNAP.clicked()
624
@MULTI_NETWORK.clicked()
25+
@ENGINE.clicked()
726
@OUTPUT_FILE.clicked()
827
@INPUT_FILE.clicked()
9-
def bootstrap_init(init_frame, network, output_file, input_file):
10-
...
11-
12-
def _update_init_frames(transitions, init_frames):
13-
transition_to_init_frame = {}
14-
for transition in transitions:
15-
# raise error if not TIS transition
16-
transition_to_init_frame[transition] = None
17-
for snap in init_frames:
18-
if init_frame.initial_state(snap):
19-
transition_to_init_frame[transition] = snap
20-
break
21-
return transition_to_init_frame
22-
23-
24-
def bootstrap_init_main(init_frames, networks, output_file):
25-
all_transitions = {trans for trans in network.sampling_transitions
26-
for network in networks}
27-
trans_to_init_frame = _update_init_frames(all_transitions, init_frames)
28-
missing = {trans for trans, frame in trans_to_init_frame.items()
29-
if frame is None}
30-
# TODO warn about missing initial frames
31-
found = set(trans_to_init_frame) - missing
32-
completed = set()
33-
for transition in found:
34-
...
28+
def bootstrap_init(init_state, final_state, network, engine, init_snap,
29+
output_file, input_file):
30+
"""Use ``FullBootstrapping`` to create initial conditions for TIS.
31+
32+
This approach starts from a snapshot, runs MD to generate an initial
33+
path for the innermost ensemble, and then performs one-way shooting
34+
moves within each ensemble until the next ensemble as reached. This
35+
continues until all ensembles have valid trajectories.
36+
37+
Note that intermediate sampling in this is not saved to disk.
38+
"""
39+
storage = INPUT_FILE.get(input_file)
40+
network = MULTI_NETWORK.get(storage, network)
41+
init_state = INIT_STATE.get(storage, init_state)
42+
final_state = FINAL_STATE.get(storage, final_stage)
43+
transition = network.transitions[(init_state, final_state)]
44+
bootstrap_init_main(
45+
init_frame=INIT_SNAP.get(storage, init_snap),
46+
network=network,
47+
engine=engine,
48+
transition=transition,
49+
output_storage=OUTPUT_FILE.get(output_file)
50+
)
3551

52+
53+
def bootstrap_init_main(init_frame, network, engine, transition,
54+
output_storage):
55+
all_states = set(network.initial_states) | set(network.final_states)
56+
allowed_states = {transition.initial_state, transition.final_state}
57+
forbidden_states = list(all_states - allowed_states)
58+
try:
59+
extra_ensembles = network.ms_outers
60+
except KeyError:
61+
extra_ensembles = None
62+
63+
bootstrapper = paths.FullBootstrapping(
64+
transition=transition,
65+
snaphot=init_frame,
66+
engine=engine,
67+
forbidden_states=forbidden_states,
68+
extra_ensembles=extra_ensembles,
69+
)
70+
init_conds = bootstrapper.run()
71+
if output_storage:
72+
output_storage.tags['final_conditions'] = init_conds
73+
74+
return init_conds, bootstrapper
75+
76+
77+
PLUGIN = OPSCommandPlugin(
78+
command=bootstrap_init,
79+
section="Simulation",
80+
requires_ops=(1, 0),
81+
requires_cli=(0, 4),
82+
)

0 commit comments

Comments
 (0)