From 2187dc4e3d65c83d12c1d28929ce682aafde24a3 Mon Sep 17 00:00:00 2001 From: gustavor101 Date: Wed, 28 Dec 2022 15:15:14 -0600 Subject: [PATCH 1/8] Update ffs.py Add the possibility for coarse graining ffs https://doi.org/10.1073/pnas.1509267112 --- pysages/methods/ffs.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pysages/methods/ffs.py b/pysages/methods/ffs.py index 5c5945db..a17a2415 100644 --- a/pysages/methods/ffs.py +++ b/pysages/methods/ffs.py @@ -73,6 +73,8 @@ def run( win_l: float, Nw: int, sampling_steps_basin: int, + sampling_steps_flow: int, + sampling_steps_window: int, Nmax_replicas: int, verbose: bool = False, callback: Optional[Callable] = None, @@ -166,7 +168,7 @@ def run( # Calculate initial flow phi_a, snaps_0 = initial_flow( - Nmax_replicas, dt, windows, ini_snapshots, run, sampler, helpers, cv + Nmax_replicas, dt, windows, ini_snapshots, run, sampler, helpers, cv, sampling_steps_flow ) write_to_file(phi_a) @@ -177,7 +179,7 @@ def run( for k in range(1, len(windows)): if k == 1: old_snaps = snaps_0 - prob, w1_snapshots = running_window(windows, k, old_snaps, run, sampler, helpers, cv) + prob, w1_snapshots = running_window(windows, k, old_snaps, run, sampler, helpers, cv, sampling_steps_window) write_to_file(prob) hist = hist.at[k].set(prob) old_snaps = increase_snaps(w1_snapshots, snaps_0) @@ -287,7 +289,7 @@ def basin_sampling( return basin_snapshots -def initial_flow(Num_window0, timestep, grid, initial_snapshots, run, sampler, helpers, cv): +def initial_flow(Num_window0, timestep, grid, initial_snapshots, run, sampler, helpers, cv, sampling_time): """ Selects snapshots from list generated with `basin_sampling`. """ @@ -307,8 +309,8 @@ def initial_flow(Num_window0, timestep, grid, initial_snapshots, run, sampler, h has_reached_A = False while not has_reached_A: # TODO: make the number of timesteps below a parameter of the method. - run(1) - time_count += timestep + run(sampling_time) + time_count += timestep * sampling_time xi = sampler.state.xi.block_until_ready() if np.all(xi >= win_A) and np.all(xi < grid[1]): @@ -327,7 +329,7 @@ def initial_flow(Num_window0, timestep, grid, initial_snapshots, run, sampler, h return phi_a, window0_snaps -def running_window(grid, step, old_snapshots, run, sampler, helpers, cv): +def running_window(grid, step, old_snapshots, run, sampler, helpers, cv, sampling_time): success = 0 new_snapshots = [] win_A = grid[0] @@ -345,7 +347,7 @@ def running_window(grid, step, old_snapshots, run, sampler, helpers, cv): # this can be probably be improved running = True while running: - run(1) + run(sampling_time) xi = sampler.state.xi.block_until_ready() if np.all(xi < win_A): From bbd0e47d40d9a70fc72cb82604448a0c44e99f67 Mon Sep 17 00:00:00 2001 From: gustavor101 Date: Tue, 31 Jan 2023 16:36:34 -0600 Subject: [PATCH 2/8] Update ffs.py check correct sampling time for initial flow --- pysages/methods/ffs.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/pysages/methods/ffs.py b/pysages/methods/ffs.py index a17a2415..ea81f700 100644 --- a/pysages/methods/ffs.py +++ b/pysages/methods/ffs.py @@ -85,6 +85,8 @@ def run( Direct version of the Forward Flux Sampling algorithm. [Phys. Rev. Lett. 94, 018104 (2005)](https://doi.org/10.1103/PhysRevLett.94.018104) [J. Chem. Phys. 124, 024102 (2006)](https://doi.org/10.1063/1.2140273) + Coarse Graining FFS + (https://doi.org/10.1073/pnas.1509267112) Arguments --------- @@ -113,6 +115,12 @@ def run( sampling_steps_basin: int Period for sampling configurations in the basin + + sampling_steps_flow: int + Period for sampling configurations for intial flow + + sampling_steps_window: int + Period for sampling configurations in each window Nmax_replicas: int Number of stored configuration for each window @@ -312,15 +320,16 @@ def initial_flow(Num_window0, timestep, grid, initial_snapshots, run, sampler, h run(sampling_time) time_count += timestep * sampling_time xi = sampler.state.xi.block_until_ready() - - if np.all(xi >= win_A) and np.all(xi < grid[1]): - success += 1 - has_reached_A = True - - if len(window0_snaps) <= Num_window0: - snap = sampler.take_snapshot() - window0_snaps.append(snap) - + + if np.all(xi >= win_A): + if np.all(xi < grid[1]): + success += 1 + has_reached_A = True + if len(window0_snaps) <= Num_window0: + snap = sampler.take_snapshot() + window0_snaps.append(snap) + if np.all(xi > grid[1]): + raise ValueError("Bad sampling time for initial flow, two windows crossed") break print(f"Finish Initial Flow with {success} succeses over {time_count} time\n") From 3943a995507d6cd22f8ec21fc580bf232fb61caf Mon Sep 17 00:00:00 2001 From: gustavor101 Date: Tue, 31 Jan 2023 16:50:05 -0600 Subject: [PATCH 3/8] Update forward_flux_sampling.py update to new CG ffs --- examples/openmm/forward_flux_sampling.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/openmm/forward_flux_sampling.py b/examples/openmm/forward_flux_sampling.py index 1911f3d7..965e41d5 100644 --- a/examples/openmm/forward_flux_sampling.py +++ b/examples/openmm/forward_flux_sampling.py @@ -66,6 +66,8 @@ def main(): ("cv-distance", "d", float, 50, "Distance from the intial to the final dihedral."), ("window-number", "Nw", int, 4, "Number of windows."), ("sampling-steps", "S", int, 20000, "Period for sampling configurations in the basin."), + ("flow-steps", "F", int, 20, "Period for sampling configurations in the initial flow."), + ("window-steps", "W", int, 20, "Period for sampling configurations in the windows."), ("replicas", "R", int, 20, "Number of stored configurations for each window."), ] parser = argparse.ArgumentParser(description="Run forward flux sampling.") @@ -89,6 +91,8 @@ def main(): win_f, args.window_number, args.sampling_steps, + args.flow_steps, + args.window_steps, args.replicas, ) From b8cfc2182862feb299e144a8caafe15bfb7bc64d Mon Sep 17 00:00:00 2001 From: gustavor101 Date: Tue, 31 Jan 2023 16:52:59 -0600 Subject: [PATCH 4/8] Update docker-ci.yml modify ffs section --- .github/workflows/docker-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index f8d48a19..38085c18 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -53,7 +53,7 @@ jobs: run: | SCRIPT="cd PySAGES/examples/openmm &&" SCRIPT="${SCRIPT} python3 forward_flux_sampling.py " - SCRIPT="${SCRIPT} --cv-start=80 --cv-distance=2 --window-number=2 --sampling-steps=50 --replicas=5" + SCRIPT="${SCRIPT} --cv-start=80 --cv-distance=2 --window-number=2 --sampling-steps=50 --flow-steps=5 --window-steps=5 --replicas=5" docker load --input /tmp/pysages.tar docker run -t pysages bash -c "${SCRIPT}" From 2eeaf5887ee4d6d4a06296d0f1c3e38143dfe4e9 Mon Sep 17 00:00:00 2001 From: gustavor101 Date: Mon, 13 Feb 2023 18:31:41 -0600 Subject: [PATCH 5/8] Update ffs.py format --- pysages/methods/ffs.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/pysages/methods/ffs.py b/pysages/methods/ffs.py index ea81f700..f895f95f 100644 --- a/pysages/methods/ffs.py +++ b/pysages/methods/ffs.py @@ -85,7 +85,7 @@ def run( Direct version of the Forward Flux Sampling algorithm. [Phys. Rev. Lett. 94, 018104 (2005)](https://doi.org/10.1103/PhysRevLett.94.018104) [J. Chem. Phys. 124, 024102 (2006)](https://doi.org/10.1063/1.2140273) - Coarse Graining FFS + Coarse Graining FFS (https://doi.org/10.1073/pnas.1509267112) Arguments @@ -115,10 +115,10 @@ def run( sampling_steps_basin: int Period for sampling configurations in the basin - + sampling_steps_flow: int Period for sampling configurations for intial flow - + sampling_steps_window: int Period for sampling configurations in each window @@ -176,7 +176,15 @@ def run( # Calculate initial flow phi_a, snaps_0 = initial_flow( - Nmax_replicas, dt, windows, ini_snapshots, run, sampler, helpers, cv, sampling_steps_flow + Nmax_replicas, + dt, + windows, + ini_snapshots, + run, + sampler, + helpers, + cv, + sampling_steps_flow, ) write_to_file(phi_a) @@ -187,7 +195,9 @@ def run( for k in range(1, len(windows)): if k == 1: old_snaps = snaps_0 - prob, w1_snapshots = running_window(windows, k, old_snaps, run, sampler, helpers, cv, sampling_steps_window) + prob, w1_snapshots = running_window( + windows, k, old_snaps, run, sampler, helpers, cv, sampling_steps_window + ) write_to_file(prob) hist = hist.at[k].set(prob) old_snaps = increase_snaps(w1_snapshots, snaps_0) @@ -297,7 +307,9 @@ def basin_sampling( return basin_snapshots -def initial_flow(Num_window0, timestep, grid, initial_snapshots, run, sampler, helpers, cv, sampling_time): +def initial_flow( + Num_window0, timestep, grid, initial_snapshots, run, sampler, helpers, cv, sampling_time +): """ Selects snapshots from list generated with `basin_sampling`. """ @@ -320,7 +332,7 @@ def initial_flow(Num_window0, timestep, grid, initial_snapshots, run, sampler, h run(sampling_time) time_count += timestep * sampling_time xi = sampler.state.xi.block_until_ready() - + if np.all(xi >= win_A): if np.all(xi < grid[1]): success += 1 From eb1953714d79b3784de09fbeafaf4878d8f36205 Mon Sep 17 00:00:00 2001 From: gustavor101 Date: Mon, 13 Feb 2023 19:41:53 -0600 Subject: [PATCH 6/8] Update docker-ci.yml --- .github/workflows/docker-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index 38085c18..b8c6222c 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -53,7 +53,7 @@ jobs: run: | SCRIPT="cd PySAGES/examples/openmm &&" SCRIPT="${SCRIPT} python3 forward_flux_sampling.py " - SCRIPT="${SCRIPT} --cv-start=80 --cv-distance=2 --window-number=2 --sampling-steps=50 --flow-steps=5 --window-steps=5 --replicas=5" + SCRIPT="${SCRIPT} --cv-start=80 --cv-distance=2 --window-number=2 --sampling-steps=50 --flow-steps=2 --window-steps=2 --replicas=5" docker load --input /tmp/pysages.tar docker run -t pysages bash -c "${SCRIPT}" From 579ee9e92c9fa752a7669c60c47fdc9537cea24c Mon Sep 17 00:00:00 2001 From: gustavor101 Date: Mon, 13 Feb 2023 21:16:05 -0600 Subject: [PATCH 7/8] Update docker-ci.yml --- .github/workflows/docker-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-ci.yml b/.github/workflows/docker-ci.yml index b8c6222c..448052dd 100644 --- a/.github/workflows/docker-ci.yml +++ b/.github/workflows/docker-ci.yml @@ -53,7 +53,7 @@ jobs: run: | SCRIPT="cd PySAGES/examples/openmm &&" SCRIPT="${SCRIPT} python3 forward_flux_sampling.py " - SCRIPT="${SCRIPT} --cv-start=80 --cv-distance=2 --window-number=2 --sampling-steps=50 --flow-steps=2 --window-steps=2 --replicas=5" + SCRIPT="${SCRIPT} --cv-start=80 --cv-distance=2 --window-number=2 --sampling-steps=50 --flow-steps=1 --window-steps=1 --replicas=5" docker load --input /tmp/pysages.tar docker run -t pysages bash -c "${SCRIPT}" From 529c11d24615893f994ea75b7b0850eb63676bea Mon Sep 17 00:00:00 2001 From: gustavor101 Date: Tue, 16 May 2023 16:36:33 -0500 Subject: [PATCH 8/8] Update ffs.py Add warning for multiple windows crossing for same sampling time --- pysages/methods/ffs.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pysages/methods/ffs.py b/pysages/methods/ffs.py index 20aab446..8697e97a 100644 --- a/pysages/methods/ffs.py +++ b/pysages/methods/ffs.py @@ -323,7 +323,6 @@ def initial_flow( has_reached_A = False while not has_reached_A: - # TODO: make the number of timesteps below a parameter of the method. run(sampling_time) time_count += timestep * sampling_time xi = sampler.state.xi.block_until_ready() @@ -336,7 +335,7 @@ def initial_flow( snap = sampler.take_snapshot() window0_snaps.append(snap) if np.all(xi > grid[1]): - raise ValueError("Bad sampling time for initial flow, two windows crossed") + print("WARNING: Two windows crossed for the same sampling time") break print(f"Finish Initial Flow with {success} succeses over {time_count} time\n")